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 static enum route_map_cmd_result_t
1088 route_set_evpn_gateway_ip(void *rule
, const struct prefix
*prefix
, void *object
)
1090 struct ipaddr
*gw_ip
= rule
;
1091 struct bgp_path_info
*path
;
1092 struct prefix_evpn
*evp
;
1094 if (prefix
->family
!= AF_EVPN
)
1097 evp
= (struct prefix_evpn
*)prefix
;
1098 if (evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
)
1101 if ((is_evpn_prefix_ipaddr_v4(evp
) && IPADDRSZ(gw_ip
) != 4)
1102 || (is_evpn_prefix_ipaddr_v6(evp
) && IPADDRSZ(gw_ip
) != 16))
1107 /* Set gateway-ip value. */
1108 path
->attr
->evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1109 memcpy(&path
->attr
->evpn_overlay
.gw_ip
, &gw_ip
->ip
.addr
,
1116 * Route map `evpn gateway-ip' compile function.
1117 * Given string is converted to struct ipaddr structure
1119 static void *route_set_evpn_gateway_ip_compile(const char *arg
)
1121 struct ipaddr
*gw_ip
= NULL
;
1124 gw_ip
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct ipaddr
));
1126 ret
= str2ipaddr(arg
, gw_ip
);
1128 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1134 /* Free route map's compiled `evpn gateway_ip' value. */
1135 static void route_set_evpn_gateway_ip_free(void *rule
)
1137 struct ipaddr
*gw_ip
= rule
;
1139 XFREE(MTYPE_ROUTE_MAP_COMPILED
, gw_ip
);
1142 /* Route map commands for set evpn gateway-ip ipv4. */
1143 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv4_cmd
= {
1144 "evpn gateway-ip ipv4", route_set_evpn_gateway_ip
,
1145 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1147 /* Route map commands for set evpn gateway-ip ipv6. */
1148 struct route_map_rule_cmd route_set_evpn_gateway_ip_ipv6_cmd
= {
1149 "evpn gateway-ip ipv6", route_set_evpn_gateway_ip
,
1150 route_set_evpn_gateway_ip_compile
, route_set_evpn_gateway_ip_free
};
1152 /* Route map commands for VRF route leak with source vrf matching */
1153 static enum route_map_cmd_result_t
1154 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1157 struct bgp_path_info
*path
;
1161 path
= (struct bgp_path_info
*)object
;
1163 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1164 return RMAP_NOMATCH
;
1166 if (path
->extra
== NULL
)
1167 return RMAP_NOMATCH
;
1169 if (strncmp(vrf_name
, vrf_id_to_name(path
->extra
->bgp_orig
->vrf_id
),
1174 return RMAP_NOMATCH
;
1177 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1179 uint8_t *vrf_name
= NULL
;
1181 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1186 /* Free route map's compiled `route-type' value. */
1187 static void route_match_vrl_source_vrf_free(void *rule
)
1189 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1192 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1194 route_match_vrl_source_vrf
,
1195 route_match_vrl_source_vrf_compile
,
1196 route_match_vrl_source_vrf_free
1199 /* `match local-preference LOCAL-PREF' */
1201 /* Match function return 1 if match is success else return zero. */
1202 static enum route_map_cmd_result_t
1203 route_match_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
1205 uint32_t *local_pref
;
1206 struct bgp_path_info
*path
;
1211 if (path
->attr
->local_pref
== *local_pref
)
1214 return RMAP_NOMATCH
;
1218 * Route map `match local-preference' match statement.
1219 * `arg' is local-pref value
1221 static void *route_match_local_pref_compile(const char *arg
)
1223 uint32_t *local_pref
;
1224 char *endptr
= NULL
;
1225 unsigned long tmpval
;
1227 /* Locpref value shoud be integer. */
1228 if (!all_digit(arg
))
1232 tmpval
= strtoul(arg
, &endptr
, 10);
1233 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1236 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1238 *local_pref
= tmpval
;
1242 /* Free route map's compiled `match local-preference' value. */
1243 static void route_match_local_pref_free(void *rule
)
1245 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1248 /* Route map commands for metric matching. */
1249 static const struct route_map_rule_cmd route_match_local_pref_cmd
= {
1251 route_match_local_pref
,
1252 route_match_local_pref_compile
,
1253 route_match_local_pref_free
1256 /* `match metric METRIC' */
1258 /* Match function return 1 if match is success else return zero. */
1259 static enum route_map_cmd_result_t
1260 route_match_metric(void *rule
, const struct prefix
*prefix
, void *object
)
1262 struct rmap_value
*rv
;
1263 struct bgp_path_info
*path
;
1267 return route_value_match(rv
, path
->attr
->med
);
1270 /* Route map commands for metric matching. */
1271 static const struct route_map_rule_cmd route_match_metric_cmd
= {
1274 route_value_compile
,
1278 /* `match as-path ASPATH' */
1280 /* Match function for as-path match. I assume given object is */
1281 static enum route_map_cmd_result_t
1282 route_match_aspath(void *rule
, const struct prefix
*prefix
, void *object
)
1285 struct as_list
*as_list
;
1286 struct bgp_path_info
*path
;
1288 as_list
= as_list_lookup((char *)rule
);
1289 if (as_list
== NULL
)
1290 return RMAP_NOMATCH
;
1294 /* Perform match. */
1295 return ((as_list_apply(as_list
, path
->attr
->aspath
) == AS_FILTER_DENY
)
1300 /* Compile function for as-path match. */
1301 static void *route_match_aspath_compile(const char *arg
)
1303 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1306 /* Compile function for as-path match. */
1307 static void route_match_aspath_free(void *rule
)
1309 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1312 /* Route map commands for aspath matching. */
1313 static const struct route_map_rule_cmd route_match_aspath_cmd
= {
1316 route_match_aspath_compile
,
1317 route_match_aspath_free
1320 /* `match community COMMUNIY' */
1321 struct rmap_community
{
1327 /* Match function for community match. */
1328 static enum route_map_cmd_result_t
1329 route_match_community(void *rule
, const struct prefix
*prefix
, void *object
)
1331 struct community_list
*list
;
1332 struct bgp_path_info
*path
;
1333 struct rmap_community
*rcom
= rule
;
1338 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1339 COMMUNITY_LIST_MASTER
);
1341 return RMAP_NOMATCH
;
1344 if (community_list_exact_match(path
->attr
->community
, list
))
1347 if (community_list_match(path
->attr
->community
, list
))
1351 return RMAP_NOMATCH
;
1354 /* Compile function for community match. */
1355 static void *route_match_community_compile(const char *arg
)
1357 struct rmap_community
*rcom
;
1361 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1363 p
= strchr(arg
, ' ');
1366 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1367 memcpy(rcom
->name
, arg
, len
);
1370 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1374 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1378 /* Compile function for community match. */
1379 static void route_match_community_free(void *rule
)
1381 struct rmap_community
*rcom
= rule
;
1383 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1384 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1388 * In routemap processing there is a need to add the
1389 * name as a rule_key in the dependency table. Routemap
1390 * lib is unaware of rule_key when exact-match clause
1391 * is in use. routemap lib uses the compiled output to
1392 * get the rule_key value.
1394 static void *route_match_get_community_key(void *rule
)
1396 struct rmap_community
*rcom
;
1403 /* Route map commands for community matching. */
1404 static const struct route_map_rule_cmd route_match_community_cmd
= {
1406 route_match_community
,
1407 route_match_community_compile
,
1408 route_match_community_free
,
1409 route_match_get_community_key
1412 /* Match function for lcommunity match. */
1413 static enum route_map_cmd_result_t
1414 route_match_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1416 struct community_list
*list
;
1417 struct bgp_path_info
*path
;
1418 struct rmap_community
*rcom
= rule
;
1422 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1423 LARGE_COMMUNITY_LIST_MASTER
);
1425 return RMAP_NOMATCH
;
1428 if (lcommunity_list_exact_match(path
->attr
->lcommunity
, list
))
1431 if (lcommunity_list_match(path
->attr
->lcommunity
, list
))
1435 return RMAP_NOMATCH
;
1438 /* Compile function for community match. */
1439 static void *route_match_lcommunity_compile(const char *arg
)
1441 struct rmap_community
*rcom
;
1445 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1447 p
= strchr(arg
, ' ');
1450 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1451 memcpy(rcom
->name
, arg
, len
);
1454 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1458 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1462 /* Compile function for community match. */
1463 static void route_match_lcommunity_free(void *rule
)
1465 struct rmap_community
*rcom
= rule
;
1467 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1468 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1471 /* Route map commands for community matching. */
1472 static const struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1474 route_match_lcommunity
,
1475 route_match_lcommunity_compile
,
1476 route_match_lcommunity_free
,
1477 route_match_get_community_key
1481 /* Match function for extcommunity match. */
1482 static enum route_map_cmd_result_t
1483 route_match_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
1485 struct community_list
*list
;
1486 struct bgp_path_info
*path
;
1487 struct rmap_community
*rcom
= rule
;
1491 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
1492 EXTCOMMUNITY_LIST_MASTER
);
1494 return RMAP_NOMATCH
;
1496 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1499 return RMAP_NOMATCH
;
1502 /* Compile function for extcommunity match. */
1503 static void *route_match_ecommunity_compile(const char *arg
)
1505 struct rmap_community
*rcom
;
1507 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1508 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1509 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1514 /* Compile function for extcommunity match. */
1515 static void route_match_ecommunity_free(void *rule
)
1517 struct rmap_community
*rcom
= rule
;
1519 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1520 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1523 /* Route map commands for community matching. */
1524 static const struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1526 route_match_ecommunity
,
1527 route_match_ecommunity_compile
,
1528 route_match_ecommunity_free
1531 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1532 and `address-family vpnv4'. */
1534 /* `match origin' */
1535 static enum route_map_cmd_result_t
1536 route_match_origin(void *rule
, const struct prefix
*prefix
, void *object
)
1539 struct bgp_path_info
*path
;
1544 if (path
->attr
->origin
== *origin
)
1547 return RMAP_NOMATCH
;
1550 static void *route_match_origin_compile(const char *arg
)
1554 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1556 if (strcmp(arg
, "igp") == 0)
1558 else if (strcmp(arg
, "egp") == 0)
1566 /* Free route map's compiled `ip address' value. */
1567 static void route_match_origin_free(void *rule
)
1569 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1572 /* Route map commands for origin matching. */
1573 static const struct route_map_rule_cmd route_match_origin_cmd
= {
1576 route_match_origin_compile
,
1577 route_match_origin_free
1580 /* match probability { */
1582 static enum route_map_cmd_result_t
1583 route_match_probability(void *rule
, const struct prefix
*prefix
, void *object
)
1585 long r
= frr_weak_random();
1587 switch (*(long *)rule
) {
1593 if (r
< *(long *)rule
) {
1598 return RMAP_NOMATCH
;
1601 static void *route_match_probability_compile(const char *arg
)
1607 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1617 *lobule
= RAND_MAX
/ 100 * perc
;
1623 static void route_match_probability_free(void *rule
)
1625 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1628 static const struct route_map_rule_cmd route_match_probability_cmd
= {
1630 route_match_probability
,
1631 route_match_probability_compile
,
1632 route_match_probability_free
1635 /* `match interface IFNAME' */
1636 /* Match function should return 1 if match is success else return
1638 static enum route_map_cmd_result_t
1639 route_match_interface(void *rule
, const struct prefix
*prefix
, void *object
)
1641 struct interface
*ifp
;
1642 struct bgp_path_info
*path
;
1647 return RMAP_NOMATCH
;
1649 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1651 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1652 return RMAP_NOMATCH
;
1657 /* Route map `interface' match statement. `arg' should be
1659 static void *route_match_interface_compile(const char *arg
)
1661 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1664 /* Free route map's compiled `interface' value. */
1665 static void route_match_interface_free(void *rule
)
1667 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1670 /* Route map commands for ip address matching. */
1671 static const struct route_map_rule_cmd route_match_interface_cmd
= {
1673 route_match_interface
,
1674 route_match_interface_compile
,
1675 route_match_interface_free
1680 /* `set ip next-hop IP_ADDRESS' */
1682 /* Match function return 1 if match is success else return zero. */
1683 static enum route_map_cmd_result_t
1684 route_match_tag(void *rule
, const struct prefix
*prefix
, void *object
)
1687 struct bgp_path_info
*path
;
1692 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1696 /* Route map commands for tag matching. */
1697 static const struct route_map_rule_cmd route_match_tag_cmd
= {
1700 route_map_rule_tag_compile
,
1701 route_map_rule_tag_free
,
1704 static enum route_map_cmd_result_t
1705 route_set_srte_color(void *rule
, const struct prefix
*prefix
, void *object
)
1707 uint32_t *srte_color
= rule
;
1708 struct bgp_path_info
*path
;
1712 path
->attr
->srte_color
= *srte_color
;
1713 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR
);
1718 /* Route map `sr-te color' compile function */
1719 static void *route_set_srte_color_compile(const char *arg
)
1723 color
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1729 /* Free route map's compiled `sr-te color' value. */
1730 static void route_set_srte_color_free(void *rule
)
1732 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1735 /* Route map commands for sr-te color set. */
1736 struct route_map_rule_cmd route_set_srte_color_cmd
= {
1737 "sr-te color", route_set_srte_color
, route_set_srte_color_compile
,
1738 route_set_srte_color_free
};
1740 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1741 struct rmap_ip_nexthop_set
{
1742 struct in_addr
*address
;
1747 static enum route_map_cmd_result_t
1748 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
1750 struct rmap_ip_nexthop_set
*rins
= rule
;
1751 struct bgp_path_info
*path
;
1754 if (prefix
->family
== AF_INET6
)
1760 if (rins
->unchanged
) {
1761 SET_FLAG(path
->attr
->rmap_change_flags
,
1762 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1763 } else if (rins
->peer_address
) {
1764 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1765 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1767 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1768 path
->attr
->nexthop
.s_addr
=
1769 sockunion2ip(peer
->su_remote
);
1770 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1771 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1772 /* The next hop value will be set as part of
1773 * packet rewrite. Set the flags here to indicate
1774 * that rewrite needs to be done.
1775 * Also, clear the value.
1777 SET_FLAG(path
->attr
->rmap_change_flags
,
1778 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1779 path
->attr
->nexthop
.s_addr
= INADDR_ANY
;
1782 /* Set next hop value. */
1783 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1784 path
->attr
->nexthop
= *rins
->address
;
1785 SET_FLAG(path
->attr
->rmap_change_flags
,
1786 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1787 /* case for MP-BGP : MPLS VPN */
1788 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1789 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1795 /* Route map `ip nexthop' compile function. Given string is converted
1796 to struct in_addr structure. */
1797 static void *route_set_ip_nexthop_compile(const char *arg
)
1799 struct rmap_ip_nexthop_set
*rins
;
1800 struct in_addr
*address
= NULL
;
1801 int peer_address
= 0;
1805 if (strcmp(arg
, "peer-address") == 0)
1807 else if (strcmp(arg
, "unchanged") == 0)
1810 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1811 sizeof(struct in_addr
));
1812 ret
= inet_aton(arg
, address
);
1815 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1820 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1821 sizeof(struct rmap_ip_nexthop_set
));
1823 rins
->address
= address
;
1824 rins
->peer_address
= peer_address
;
1825 rins
->unchanged
= unchanged
;
1830 /* Free route map's compiled `ip nexthop' value. */
1831 static void route_set_ip_nexthop_free(void *rule
)
1833 struct rmap_ip_nexthop_set
*rins
= rule
;
1835 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1837 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1840 /* Route map commands for ip nexthop set. */
1841 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1843 route_set_ip_nexthop
,
1844 route_set_ip_nexthop_compile
,
1845 route_set_ip_nexthop_free
1848 /* `set local-preference LOCAL_PREF' */
1850 /* Set local preference. */
1851 static enum route_map_cmd_result_t
1852 route_set_local_pref(void *rule
, const struct prefix
*prefix
, void *object
)
1854 struct rmap_value
*rv
;
1855 struct bgp_path_info
*path
;
1856 uint32_t locpref
= 0;
1858 /* Fetch routemap's rule information. */
1862 /* Set local preference value. */
1863 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1864 locpref
= path
->attr
->local_pref
;
1866 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1867 path
->attr
->local_pref
= route_value_adjust(rv
, locpref
, path
->peer
);
1872 /* Set local preference rule structure. */
1873 static const struct route_map_rule_cmd route_set_local_pref_cmd
= {
1875 route_set_local_pref
,
1876 route_value_compile
,
1880 /* `set weight WEIGHT' */
1883 static enum route_map_cmd_result_t
1884 route_set_weight(void *rule
, const struct prefix
*prefix
, void *object
)
1886 struct rmap_value
*rv
;
1887 struct bgp_path_info
*path
;
1889 /* Fetch routemap's rule information. */
1893 /* Set weight value. */
1894 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1899 /* Set local preference rule structure. */
1900 static const struct route_map_rule_cmd route_set_weight_cmd
= {
1903 route_value_compile
,
1907 /* `set distance DISTANCE */
1908 static enum route_map_cmd_result_t
1909 route_set_distance(void *rule
, const struct prefix
*prefix
, void *object
)
1911 struct bgp_path_info
*path
= object
;
1912 struct rmap_value
*rv
= rule
;
1914 path
->attr
->distance
= rv
->value
;
1919 /* set distance rule structure */
1920 static const struct route_map_rule_cmd route_set_distance_cmd
= {
1923 route_value_compile
,
1927 /* `set metric METRIC' */
1929 /* Set metric to attribute. */
1930 static enum route_map_cmd_result_t
1931 route_set_metric(void *rule
, const struct prefix
*prefix
, void *object
)
1933 struct rmap_value
*rv
;
1934 struct bgp_path_info
*path
;
1937 /* Fetch routemap's rule information. */
1941 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1942 med
= path
->attr
->med
;
1944 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1945 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1950 /* Set metric rule structure. */
1951 static const struct route_map_rule_cmd route_set_metric_cmd
= {
1954 route_value_compile
,
1958 /* `set table (1-4294967295)' */
1960 static enum route_map_cmd_result_t
1961 route_set_table_id(void *rule
, const struct prefix
*prefix
,
1965 struct rmap_value
*rv
;
1966 struct bgp_path_info
*path
;
1968 /* Fetch routemap's rule information. */
1972 path
->attr
->rmap_table_id
= rv
->value
;
1977 /* Set table_id rule structure. */
1978 static const struct route_map_rule_cmd route_set_table_id_cmd
= {
1981 route_value_compile
,
1985 /* `set as-path prepend ASPATH' */
1987 /* For AS path prepend mechanism. */
1988 static enum route_map_cmd_result_t
1989 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
, void *object
)
1991 struct aspath
*aspath
;
1993 struct bgp_path_info
*path
;
1997 if (path
->attr
->aspath
->refcnt
)
1998 new = aspath_dup(path
->attr
->aspath
);
2000 new = path
->attr
->aspath
;
2002 if ((uintptr_t)rule
> 10) {
2004 aspath_prepend(aspath
, new);
2006 as_t as
= aspath_leftmost(new);
2008 as
= path
->peer
->as
;
2009 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
2012 path
->attr
->aspath
= new;
2017 static void *route_set_aspath_prepend_compile(const char *arg
)
2021 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
2022 return (void *)(uintptr_t)num
;
2024 return route_aspath_compile(arg
);
2027 static void route_set_aspath_prepend_free(void *rule
)
2029 if ((uintptr_t)rule
> 10)
2030 route_aspath_free(rule
);
2034 /* Set as-path prepend rule structure. */
2035 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
2037 route_set_aspath_prepend
,
2038 route_set_aspath_prepend_compile
,
2039 route_set_aspath_prepend_free
,
2042 /* `set as-path exclude ASn' */
2044 /* For ASN exclude mechanism.
2045 * Iterate over ASns requested and filter them from the given AS_PATH one by
2047 * Make a deep copy of existing AS_PATH, but for the first ASn only.
2049 static enum route_map_cmd_result_t
2050 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
, void *object
)
2052 struct aspath
*new_path
, *exclude_path
;
2053 struct bgp_path_info
*path
;
2055 exclude_path
= rule
;
2057 if (path
->attr
->aspath
->refcnt
)
2058 new_path
= aspath_dup(path
->attr
->aspath
);
2060 new_path
= path
->attr
->aspath
;
2061 path
->attr
->aspath
= aspath_filter_exclude(new_path
, exclude_path
);
2066 /* Set ASn exlude rule structure. */
2067 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
2069 route_set_aspath_exclude
,
2070 route_aspath_compile
,
2074 /* `set community COMMUNITY' */
2075 struct rmap_com_set
{
2076 struct community
*com
;
2081 /* For community set mechanism. */
2082 static enum route_map_cmd_result_t
2083 route_set_community(void *rule
, const struct prefix
*prefix
, void *object
)
2085 struct rmap_com_set
*rcs
;
2086 struct bgp_path_info
*path
;
2088 struct community
*new = NULL
;
2089 struct community
*old
;
2090 struct community
*merge
;
2095 old
= attr
->community
;
2099 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
2100 attr
->community
= NULL
;
2101 /* See the longer comment down below. */
2102 if (old
&& old
->refcnt
== 0)
2103 community_free(&old
);
2107 /* "additive" case. */
2108 if (rcs
->additive
&& old
) {
2109 merge
= community_merge(community_dup(old
), rcs
->com
);
2111 new = community_uniq_sort(merge
);
2112 community_free(&merge
);
2114 new = community_dup(rcs
->com
);
2116 /* HACK: if the old community is not intern'd,
2117 * we should free it here, or all reference to it may be
2119 * Really need to cleanup attribute caching sometime.
2121 if (old
&& old
->refcnt
== 0)
2122 community_free(&old
);
2124 /* will be interned by caller if required */
2125 attr
->community
= new;
2127 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2132 /* Compile function for set community. */
2133 static void *route_set_community_compile(const char *arg
)
2135 struct rmap_com_set
*rcs
;
2136 struct community
*com
= NULL
;
2141 if (strcmp(arg
, "none") == 0)
2144 sp
= strstr(arg
, "additive");
2146 if (sp
&& sp
> arg
) {
2147 /* "additive" keyword is included. */
2152 com
= community_str2com(arg
);
2161 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2163 rcs
->additive
= additive
;
2169 /* Free function for set community. */
2170 static void route_set_community_free(void *rule
)
2172 struct rmap_com_set
*rcs
= rule
;
2175 community_free(&rcs
->com
);
2176 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2179 /* Set community rule structure. */
2180 static const struct route_map_rule_cmd route_set_community_cmd
= {
2182 route_set_community
,
2183 route_set_community_compile
,
2184 route_set_community_free
,
2187 /* `set community COMMUNITY' */
2188 struct rmap_lcom_set
{
2189 struct lcommunity
*lcom
;
2195 /* For lcommunity set mechanism. */
2196 static enum route_map_cmd_result_t
2197 route_set_lcommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2199 struct rmap_lcom_set
*rcs
;
2200 struct bgp_path_info
*path
;
2202 struct lcommunity
*new = NULL
;
2203 struct lcommunity
*old
;
2204 struct lcommunity
*merge
;
2209 old
= attr
->lcommunity
;
2213 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
2214 attr
->lcommunity
= NULL
;
2216 /* See the longer comment down below. */
2217 if (old
&& old
->refcnt
== 0)
2218 lcommunity_free(&old
);
2222 if (rcs
->additive
&& old
) {
2223 merge
= lcommunity_merge(lcommunity_dup(old
), rcs
->lcom
);
2225 new = lcommunity_uniq_sort(merge
);
2226 lcommunity_free(&merge
);
2228 new = lcommunity_dup(rcs
->lcom
);
2230 /* HACK: if the old large-community is not intern'd,
2231 * we should free it here, or all reference to it may be
2233 * Really need to cleanup attribute caching sometime.
2235 if (old
&& old
->refcnt
== 0)
2236 lcommunity_free(&old
);
2238 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2239 attr
->lcommunity
= new;
2241 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2246 /* Compile function for set community. */
2247 static void *route_set_lcommunity_compile(const char *arg
)
2249 struct rmap_lcom_set
*rcs
;
2250 struct lcommunity
*lcom
= NULL
;
2255 if (strcmp(arg
, "none") == 0)
2258 sp
= strstr(arg
, "additive");
2260 if (sp
&& sp
> arg
) {
2261 /* "additive" keyworkd is included. */
2266 lcom
= lcommunity_str2com(arg
);
2275 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2277 rcs
->additive
= additive
;
2283 /* Free function for set lcommunity. */
2284 static void route_set_lcommunity_free(void *rule
)
2286 struct rmap_lcom_set
*rcs
= rule
;
2289 lcommunity_free(&rcs
->lcom
);
2291 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2294 /* Set community rule structure. */
2295 static const struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2297 route_set_lcommunity
,
2298 route_set_lcommunity_compile
,
2299 route_set_lcommunity_free
,
2302 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2304 /* For large community set mechanism. */
2305 static enum route_map_cmd_result_t
2306 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
, void *object
)
2308 struct community_list
*list
;
2309 struct lcommunity
*merge
;
2310 struct lcommunity
*new;
2311 struct lcommunity
*old
;
2312 struct bgp_path_info
*path
;
2313 struct rmap_community
*rcom
= rule
;
2319 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2320 LARGE_COMMUNITY_LIST_MASTER
);
2321 old
= path
->attr
->lcommunity
;
2324 merge
= lcommunity_list_match_delete(lcommunity_dup(old
), list
);
2325 new = lcommunity_uniq_sort(merge
);
2326 lcommunity_free(&merge
);
2328 /* HACK: if the old community is not intern'd,
2329 * we should free it here, or all reference to it may be
2331 * Really need to cleanup attribute caching sometime.
2333 if (old
->refcnt
== 0)
2334 lcommunity_free(&old
);
2336 if (new->size
== 0) {
2337 path
->attr
->lcommunity
= NULL
;
2339 ~ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2340 lcommunity_free(&new);
2342 path
->attr
->lcommunity
= new;
2344 ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2351 /* Compile function for set lcommunity. */
2352 static void *route_set_lcommunity_delete_compile(const char *arg
)
2354 struct rmap_community
*rcom
;
2358 frrstr_split(arg
, " ", &splits
, &num
);
2360 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2361 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2362 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2364 for (int i
= 0; i
< num
; i
++)
2365 XFREE(MTYPE_TMP
, splits
[i
]);
2366 XFREE(MTYPE_TMP
, splits
);
2371 /* Free function for set lcommunity. */
2372 static void route_set_lcommunity_delete_free(void *rule
)
2374 struct rmap_community
*rcom
= rule
;
2376 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2377 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2380 /* Set lcommunity rule structure. */
2381 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2383 route_set_lcommunity_delete
,
2384 route_set_lcommunity_delete_compile
,
2385 route_set_lcommunity_delete_free
,
2389 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2391 /* For community set mechanism. */
2392 static enum route_map_cmd_result_t
2393 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2396 struct community_list
*list
;
2397 struct community
*merge
;
2398 struct community
*new;
2399 struct community
*old
;
2400 struct bgp_path_info
*path
;
2401 struct rmap_community
*rcom
= rule
;
2407 list
= community_list_lookup(bgp_clist
, rcom
->name
, rcom
->name_hash
,
2408 COMMUNITY_LIST_MASTER
);
2409 old
= path
->attr
->community
;
2412 merge
= community_list_match_delete(community_dup(old
), list
);
2413 new = community_uniq_sort(merge
);
2414 community_free(&merge
);
2416 /* HACK: if the old community is not intern'd,
2417 * we should free it here, or all reference to it may be
2419 * Really need to cleanup attribute caching sometime.
2421 if (old
->refcnt
== 0)
2422 community_free(&old
);
2424 if (new->size
== 0) {
2425 path
->attr
->community
= NULL
;
2427 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2428 community_free(&new);
2430 path
->attr
->community
= new;
2431 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2438 /* Compile function for set community. */
2439 static void *route_set_community_delete_compile(const char *arg
)
2441 struct rmap_community
*rcom
;
2445 frrstr_split(arg
, " ", &splits
, &num
);
2447 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2448 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2449 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2451 for (int i
= 0; i
< num
; i
++)
2452 XFREE(MTYPE_TMP
, splits
[i
]);
2453 XFREE(MTYPE_TMP
, splits
);
2458 /* Free function for set community. */
2459 static void route_set_community_delete_free(void *rule
)
2461 struct rmap_community
*rcom
= rule
;
2463 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2464 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2467 /* Set community rule structure. */
2468 static const struct route_map_rule_cmd route_set_community_delete_cmd
= {
2470 route_set_community_delete
,
2471 route_set_community_delete_compile
,
2472 route_set_community_delete_free
,
2475 /* `set extcommunity rt COMMUNITY' */
2477 /* For community set mechanism. Used by _rt and _soo. */
2478 static enum route_map_cmd_result_t
2479 route_set_ecommunity(void *rule
, const struct prefix
*prefix
, void *object
)
2481 struct ecommunity
*ecom
;
2482 struct ecommunity
*new_ecom
;
2483 struct ecommunity
*old_ecom
;
2484 struct bgp_path_info
*path
;
2492 /* We assume additive for Extended Community. */
2493 old_ecom
= path
->attr
->ecommunity
;
2496 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
), ecom
);
2498 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2499 * bgp_update_receive()
2500 * ->refcnt = 0 => set by a previous route-map
2502 if (!old_ecom
->refcnt
)
2503 ecommunity_free(&old_ecom
);
2505 new_ecom
= ecommunity_dup(ecom
);
2507 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2508 path
->attr
->ecommunity
= new_ecom
;
2510 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2515 /* Compile function for set community. */
2516 static void *route_set_ecommunity_rt_compile(const char *arg
)
2518 struct ecommunity
*ecom
;
2520 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2523 return ecommunity_intern(ecom
);
2526 /* Free function for set community. Used by _rt and _soo */
2527 static void route_set_ecommunity_free(void *rule
)
2529 struct ecommunity
*ecom
= rule
;
2530 ecommunity_unintern(&ecom
);
2533 /* Set community rule structure. */
2534 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2536 route_set_ecommunity
,
2537 route_set_ecommunity_rt_compile
,
2538 route_set_ecommunity_free
,
2541 /* `set extcommunity soo COMMUNITY' */
2543 /* Compile function for set community. */
2544 static void *route_set_ecommunity_soo_compile(const char *arg
)
2546 struct ecommunity
*ecom
;
2548 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2552 return ecommunity_intern(ecom
);
2555 /* Set community rule structure. */
2556 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2558 route_set_ecommunity
,
2559 route_set_ecommunity_soo_compile
,
2560 route_set_ecommunity_free
,
2563 /* `set extcommunity bandwidth' */
2565 struct rmap_ecomm_lb_set
{
2567 #define RMAP_ECOMM_LB_SET_VALUE 1
2568 #define RMAP_ECOMM_LB_SET_CUMUL 2
2569 #define RMAP_ECOMM_LB_SET_NUM_MPATH 3
2574 static enum route_map_cmd_result_t
2575 route_set_ecommunity_lb(void *rule
, const struct prefix
*prefix
, void *object
)
2577 struct rmap_ecomm_lb_set
*rels
= rule
;
2578 struct bgp_path_info
*path
;
2580 struct ecommunity ecom_lb
= {0};
2581 struct ecommunity_val lb_eval
;
2582 uint32_t bw_bytes
= 0;
2583 uint16_t mpath_count
= 0;
2584 struct ecommunity
*new_ecom
;
2585 struct ecommunity
*old_ecom
;
2590 if (!peer
|| !peer
->bgp
)
2593 /* Build link bandwidth extended community */
2594 as
= (peer
->bgp
->as
> BGP_AS_MAX
) ? BGP_AS_TRANS
: peer
->bgp
->as
;
2595 if (rels
->lb_type
== RMAP_ECOMM_LB_SET_VALUE
) {
2596 bw_bytes
= ((uint64_t)rels
->bw
* 1000 * 1000) / 8;
2597 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_CUMUL
) {
2598 /* process this only for the best path. */
2599 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2602 bw_bytes
= (uint32_t)bgp_path_info_mpath_cumbw(path
);
2606 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_NUM_MPATH
) {
2608 /* process this only for the best path. */
2609 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2612 bw_bytes
= ((uint64_t)peer
->bgp
->lb_ref_bw
* 1000 * 1000) / 8;
2613 mpath_count
= bgp_path_info_mpath_count(path
) + 1;
2614 bw_bytes
*= mpath_count
;
2617 encode_lb_extcomm(as
, bw_bytes
, rels
->non_trans
, &lb_eval
);
2619 /* add to route or merge with existing */
2620 old_ecom
= path
->attr
->ecommunity
;
2622 new_ecom
= ecommunity_dup(old_ecom
);
2623 ecommunity_add_val(new_ecom
, &lb_eval
, true, true);
2624 if (!old_ecom
->refcnt
)
2625 ecommunity_free(&old_ecom
);
2628 ecom_lb
.unit_size
= ECOMMUNITY_SIZE
;
2629 ecom_lb
.val
= (uint8_t *)lb_eval
.val
;
2630 new_ecom
= ecommunity_dup(&ecom_lb
);
2633 /* new_ecom will be intern()'d or attr_flush()'d in call stack */
2634 path
->attr
->ecommunity
= new_ecom
;
2635 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2637 /* Mark that route-map has set link bandwidth; used in attribute
2638 * setting decisions.
2640 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_LINK_BW_SET
);
2645 static void *route_set_ecommunity_lb_compile(const char *arg
)
2647 struct rmap_ecomm_lb_set
*rels
;
2650 char bw_str
[40] = {0};
2652 bool non_trans
= false;
2655 p
= strchr(arg
, ' ');
2660 memcpy(bw_str
, arg
, len
);
2665 if (strcmp(str
, "cumulative") == 0)
2666 lb_type
= RMAP_ECOMM_LB_SET_CUMUL
;
2667 else if (strcmp(str
, "num-multipaths") == 0)
2668 lb_type
= RMAP_ECOMM_LB_SET_NUM_MPATH
;
2672 bw
= strtoul(str
, &end
, 10);
2675 lb_type
= RMAP_ECOMM_LB_SET_VALUE
;
2678 rels
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2679 sizeof(struct rmap_ecomm_lb_set
));
2680 rels
->lb_type
= lb_type
;
2682 rels
->non_trans
= non_trans
;
2687 static void route_set_ecommunity_lb_free(void *rule
)
2689 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2692 /* Set community rule structure. */
2693 struct route_map_rule_cmd route_set_ecommunity_lb_cmd
= {
2694 "extcommunity bandwidth",
2695 route_set_ecommunity_lb
,
2696 route_set_ecommunity_lb_compile
,
2697 route_set_ecommunity_lb_free
,
2700 /* `set origin ORIGIN' */
2702 /* For origin set. */
2703 static enum route_map_cmd_result_t
2704 route_set_origin(void *rule
, const struct prefix
*prefix
, void *object
)
2707 struct bgp_path_info
*path
;
2712 path
->attr
->origin
= *origin
;
2717 /* Compile function for origin set. */
2718 static void *route_set_origin_compile(const char *arg
)
2722 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2724 if (strcmp(arg
, "igp") == 0)
2726 else if (strcmp(arg
, "egp") == 0)
2734 /* Compile function for origin set. */
2735 static void route_set_origin_free(void *rule
)
2737 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2740 /* Set origin rule structure. */
2741 static const struct route_map_rule_cmd route_set_origin_cmd
= {
2744 route_set_origin_compile
,
2745 route_set_origin_free
,
2748 /* `set atomic-aggregate' */
2750 /* For atomic aggregate set. */
2751 static enum route_map_cmd_result_t
2752 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
, void *object
)
2754 struct bgp_path_info
*path
;
2757 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2762 /* Compile function for atomic aggregate. */
2763 static void *route_set_atomic_aggregate_compile(const char *arg
)
2768 /* Compile function for atomic aggregate. */
2769 static void route_set_atomic_aggregate_free(void *rule
)
2774 /* Set atomic aggregate rule structure. */
2775 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2777 route_set_atomic_aggregate
,
2778 route_set_atomic_aggregate_compile
,
2779 route_set_atomic_aggregate_free
,
2782 /* `set aggregator as AS A.B.C.D' */
2785 struct in_addr address
;
2788 static enum route_map_cmd_result_t
2789 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
, void *object
)
2791 struct bgp_path_info
*path
;
2792 struct aggregator
*aggregator
;
2797 path
->attr
->aggregator_as
= aggregator
->as
;
2798 path
->attr
->aggregator_addr
= aggregator
->address
;
2799 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2804 static void *route_set_aggregator_as_compile(const char *arg
)
2806 struct aggregator
*aggregator
;
2812 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2813 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2814 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2818 aggregator
->as
= strtoul(as
, NULL
, 10);
2819 ret
= inet_aton(address
, &aggregator
->address
);
2821 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2827 static void route_set_aggregator_as_free(void *rule
)
2829 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2832 static const struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2834 route_set_aggregator_as
,
2835 route_set_aggregator_as_compile
,
2836 route_set_aggregator_as_free
,
2839 /* Set tag to object. object must be pointer to struct bgp_path_info */
2840 static enum route_map_cmd_result_t
2841 route_set_tag(void *rule
, const struct prefix
*prefix
, void *object
)
2844 struct bgp_path_info
*path
;
2850 path
->attr
->tag
= *tag
;
2855 /* Route map commands for tag set. */
2856 static const struct route_map_rule_cmd route_set_tag_cmd
= {
2859 route_map_rule_tag_compile
,
2860 route_map_rule_tag_free
,
2863 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2864 static enum route_map_cmd_result_t
2865 route_set_label_index(void *rule
, const struct prefix
*prefix
, void *object
)
2867 struct rmap_value
*rv
;
2868 struct bgp_path_info
*path
;
2869 uint32_t label_index
;
2871 /* Fetch routemap's rule information. */
2875 /* Set label-index value. */
2876 label_index
= rv
->value
;
2878 path
->attr
->label_index
= label_index
;
2879 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2885 /* Route map commands for label-index set. */
2886 static const struct route_map_rule_cmd route_set_label_index_cmd
= {
2888 route_set_label_index
,
2889 route_value_compile
,
2893 /* `match ipv6 address IP_ACCESS_LIST' */
2895 static enum route_map_cmd_result_t
2896 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
, void *object
)
2898 struct access_list
*alist
;
2900 if (prefix
->family
== AF_INET6
) {
2901 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2903 return RMAP_NOMATCH
;
2905 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2909 return RMAP_NOMATCH
;
2912 static void *route_match_ipv6_address_compile(const char *arg
)
2914 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2917 static void route_match_ipv6_address_free(void *rule
)
2919 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2922 /* Route map commands for ip address matching. */
2923 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2925 route_match_ipv6_address
,
2926 route_match_ipv6_address_compile
,
2927 route_match_ipv6_address_free
2930 /* `match ipv6 next-hop IP_ADDRESS' */
2932 static enum route_map_cmd_result_t
2933 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
2935 struct in6_addr
*addr
= rule
;
2936 struct bgp_path_info
*path
;
2940 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2943 if (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2944 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2947 return RMAP_NOMATCH
;
2950 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2952 struct in6_addr
*address
;
2955 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2957 ret
= inet_pton(AF_INET6
, arg
, address
);
2959 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2966 static void route_match_ipv6_next_hop_free(void *rule
)
2968 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2971 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2973 route_match_ipv6_next_hop
,
2974 route_match_ipv6_next_hop_compile
,
2975 route_match_ipv6_next_hop_free
2978 /* `match ip next-hop IP_ADDRESS' */
2980 static enum route_map_cmd_result_t
2981 route_match_ipv4_next_hop(void *rule
, const struct prefix
*prefix
, void *object
)
2983 struct in_addr
*addr
= rule
;
2984 struct bgp_path_info
*path
;
2988 if (path
->attr
->nexthop
.s_addr
== addr
->s_addr
2989 || (path
->attr
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV4
2990 && IPV4_ADDR_SAME(&path
->attr
->mp_nexthop_global_in
, addr
)))
2993 return RMAP_NOMATCH
;
2996 static void *route_match_ipv4_next_hop_compile(const char *arg
)
2998 struct in_addr
*address
;
3001 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3003 ret
= inet_pton(AF_INET
, arg
, address
);
3005 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3012 static void route_match_ipv4_next_hop_free(void *rule
)
3014 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3017 static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd
= {
3018 "ip next-hop address",
3019 route_match_ipv4_next_hop
,
3020 route_match_ipv4_next_hop_compile
,
3021 route_match_ipv4_next_hop_free
3024 /* `match ipv6 address prefix-list PREFIX_LIST' */
3026 static enum route_map_cmd_result_t
3027 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
3030 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, object
);
3033 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
3035 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3038 static void route_match_ipv6_address_prefix_list_free(void *rule
)
3040 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3043 static const struct route_map_rule_cmd
3044 route_match_ipv6_address_prefix_list_cmd
= {
3045 "ipv6 address prefix-list",
3046 route_match_ipv6_address_prefix_list
,
3047 route_match_ipv6_address_prefix_list_compile
,
3048 route_match_ipv6_address_prefix_list_free
3051 /* `match ipv6 next-hop type <TYPE>' */
3053 static enum route_map_cmd_result_t
3054 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
3057 struct bgp_path_info
*path
;
3058 struct in6_addr
*addr
= rule
;
3060 if (prefix
->family
== AF_INET6
) {
3061 path
= (struct bgp_path_info
*)object
;
3063 return RMAP_NOMATCH
;
3065 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
3066 && !path
->attr
->nh_ifindex
)
3070 return RMAP_NOMATCH
;
3073 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
3075 struct in6_addr
*address
;
3078 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3080 ret
= inet_pton(AF_INET6
, "::0", address
);
3082 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3089 static void route_match_ipv6_next_hop_type_free(void *rule
)
3091 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3094 static const struct route_map_rule_cmd
3095 route_match_ipv6_next_hop_type_cmd
= {
3096 "ipv6 next-hop type",
3097 route_match_ipv6_next_hop_type
,
3098 route_match_ipv6_next_hop_type_compile
,
3099 route_match_ipv6_next_hop_type_free
3102 /* `set ipv6 nexthop global IP_ADDRESS' */
3104 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3105 static enum route_map_cmd_result_t
3106 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
, void *object
)
3108 struct in6_addr
*address
;
3109 struct bgp_path_info
*path
;
3111 /* Fetch routemap's rule information. */
3115 /* Set next hop value. */
3116 path
->attr
->mp_nexthop_global
= *address
;
3118 /* Set nexthop length. */
3119 if (path
->attr
->mp_nexthop_len
== 0)
3120 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3122 SET_FLAG(path
->attr
->rmap_change_flags
,
3123 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
3128 /* Route map `ip next-hop' compile function. Given string is converted
3129 to struct in_addr structure. */
3130 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
3133 struct in6_addr
*address
;
3135 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3137 ret
= inet_pton(AF_INET6
, arg
, address
);
3140 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3147 /* Free route map's compiled `ip next-hop' value. */
3148 static void route_set_ipv6_nexthop_global_free(void *rule
)
3150 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3153 /* Route map commands for ip nexthop set. */
3154 static const struct route_map_rule_cmd
3155 route_set_ipv6_nexthop_global_cmd
= {
3156 "ipv6 next-hop global",
3157 route_set_ipv6_nexthop_global
,
3158 route_set_ipv6_nexthop_global_compile
,
3159 route_set_ipv6_nexthop_global_free
3162 /* Set next-hop preference value. */
3163 static enum route_map_cmd_result_t
3164 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
3167 struct bgp_path_info
*path
;
3170 /* Fetch routemap's rule information. */
3174 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3175 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
3176 /* Set next hop preference to global */
3177 path
->attr
->mp_nexthop_prefer_global
= true;
3178 SET_FLAG(path
->attr
->rmap_change_flags
,
3179 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3181 path
->attr
->mp_nexthop_prefer_global
= false;
3182 SET_FLAG(path
->attr
->rmap_change_flags
,
3183 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3189 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
3193 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3199 /* Free route map's compiled `ip next-hop' value. */
3200 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
3202 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3205 /* Route map commands for ip nexthop set preferred. */
3206 static const struct route_map_rule_cmd
3207 route_set_ipv6_nexthop_prefer_global_cmd
= {
3208 "ipv6 next-hop prefer-global",
3209 route_set_ipv6_nexthop_prefer_global
,
3210 route_set_ipv6_nexthop_prefer_global_compile
,
3211 route_set_ipv6_nexthop_prefer_global_free
3214 /* `set ipv6 nexthop local IP_ADDRESS' */
3216 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3217 static enum route_map_cmd_result_t
3218 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
, void *object
)
3220 struct in6_addr
*address
;
3221 struct bgp_path_info
*path
;
3223 /* Fetch routemap's rule information. */
3227 /* Set next hop value. */
3228 path
->attr
->mp_nexthop_local
= *address
;
3230 /* Set nexthop length. */
3231 if (path
->attr
->mp_nexthop_len
!= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3232 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3234 SET_FLAG(path
->attr
->rmap_change_flags
,
3235 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
3240 /* Route map `ip nexthop' compile function. Given string is converted
3241 to struct in_addr structure. */
3242 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
3245 struct in6_addr
*address
;
3247 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3249 ret
= inet_pton(AF_INET6
, arg
, address
);
3252 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3259 /* Free route map's compiled `ip nexthop' value. */
3260 static void route_set_ipv6_nexthop_local_free(void *rule
)
3262 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3265 /* Route map commands for ip nexthop set. */
3266 static const struct route_map_rule_cmd
3267 route_set_ipv6_nexthop_local_cmd
= {
3268 "ipv6 next-hop local",
3269 route_set_ipv6_nexthop_local
,
3270 route_set_ipv6_nexthop_local_compile
,
3271 route_set_ipv6_nexthop_local_free
3274 /* `set ipv6 nexthop peer-address' */
3276 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3277 static enum route_map_cmd_result_t
3278 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
, void *object
)
3280 struct in6_addr peer_address
;
3281 struct bgp_path_info
*path
;
3284 /* Fetch routemap's rule information. */
3288 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3289 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
3291 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
3292 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
3293 /* Set next hop value and length in attribute. */
3294 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
3295 path
->attr
->mp_nexthop_local
= peer_address
;
3296 if (path
->attr
->mp_nexthop_len
3297 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3298 path
->attr
->mp_nexthop_len
=
3299 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3301 path
->attr
->mp_nexthop_global
= peer_address
;
3302 if (path
->attr
->mp_nexthop_len
== 0)
3303 path
->attr
->mp_nexthop_len
=
3304 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3307 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
3308 /* The next hop value will be set as part of packet
3310 * Set the flags here to indicate that rewrite needs to
3312 * Also, clear the value - we clear both global and
3314 * nexthops, whether we send one or both is determined
3317 SET_FLAG(path
->attr
->rmap_change_flags
,
3318 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3319 /* clear next hop value. */
3320 memset(&(path
->attr
->mp_nexthop_global
), 0,
3321 sizeof(struct in6_addr
));
3322 memset(&(path
->attr
->mp_nexthop_local
), 0,
3323 sizeof(struct in6_addr
));
3329 /* Route map `ip next-hop' compile function. Given string is converted
3330 to struct in_addr structure. */
3331 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3335 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3341 /* Free route map's compiled `ip next-hop' value. */
3342 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3344 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3347 /* Route map commands for ip nexthop set. */
3348 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3349 "ipv6 next-hop peer-address",
3350 route_set_ipv6_nexthop_peer
,
3351 route_set_ipv6_nexthop_peer_compile
,
3352 route_set_ipv6_nexthop_peer_free
3355 /* `set ipv4 vpn next-hop A.B.C.D' */
3357 static enum route_map_cmd_result_t
3358 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3360 struct in_addr
*address
;
3361 struct bgp_path_info
*path
;
3363 /* Fetch routemap's rule information. */
3367 /* Set next hop value. */
3368 path
->attr
->mp_nexthop_global_in
= *address
;
3369 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3374 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3377 struct in_addr
*address
;
3379 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3381 ret
= inet_aton(arg
, address
);
3384 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3391 /* `set ipv6 vpn next-hop A.B.C.D' */
3393 static enum route_map_cmd_result_t
3394 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
, void *object
)
3396 struct in6_addr
*address
;
3397 struct bgp_path_info
*path
;
3399 /* Fetch routemap's rule information. */
3403 /* Set next hop value. */
3404 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3405 sizeof(struct in6_addr
));
3406 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3411 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3414 struct in6_addr
*address
;
3416 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3417 ret
= inet_pton(AF_INET6
, arg
, address
);
3420 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3427 static void route_set_vpn_nexthop_free(void *rule
)
3429 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3432 /* Route map commands for ipv4 next-hop set. */
3433 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3434 "ipv4 vpn next-hop",
3435 route_set_vpnv4_nexthop
,
3436 route_set_vpnv4_nexthop_compile
,
3437 route_set_vpn_nexthop_free
3440 /* Route map commands for ipv6 next-hop set. */
3441 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3442 "ipv6 vpn next-hop",
3443 route_set_vpnv6_nexthop
,
3444 route_set_vpnv6_nexthop_compile
,
3445 route_set_vpn_nexthop_free
3448 /* `set originator-id' */
3450 /* For origin set. */
3451 static enum route_map_cmd_result_t
3452 route_set_originator_id(void *rule
, const struct prefix
*prefix
, void *object
)
3454 struct in_addr
*address
;
3455 struct bgp_path_info
*path
;
3460 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3461 path
->attr
->originator_id
= *address
;
3466 /* Compile function for originator-id set. */
3467 static void *route_set_originator_id_compile(const char *arg
)
3470 struct in_addr
*address
;
3472 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3474 ret
= inet_aton(arg
, address
);
3477 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3484 /* Compile function for originator_id set. */
3485 static void route_set_originator_id_free(void *rule
)
3487 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3490 /* Set originator-id rule structure. */
3491 static const struct route_map_rule_cmd route_set_originator_id_cmd
= {
3493 route_set_originator_id
,
3494 route_set_originator_id_compile
,
3495 route_set_originator_id_free
,
3499 * This is the workhorse routine for processing in/out routemap
3502 static void bgp_route_map_process_peer(const char *rmap_name
,
3503 struct route_map
*map
, struct peer
*peer
,
3504 int afi
, int safi
, int route_update
)
3506 struct bgp_filter
*filter
;
3508 if (!peer
|| !rmap_name
)
3511 filter
= &peer
->filter
[afi
][safi
];
3513 * in is for non-route-server clients,
3514 * out is for all peers
3516 if (filter
->map
[RMAP_IN
].name
3517 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3518 filter
->map
[RMAP_IN
].map
= map
;
3520 if (route_update
&& peer_established(peer
)) {
3521 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3522 PEER_FLAG_SOFT_RECONFIG
)) {
3523 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3525 "Processing route_map %s(%s:%s) update on peer %s (inbound, soft-reconfig)",
3526 rmap_name
, afi2str(afi
),
3527 safi2str(safi
), peer
->host
);
3529 bgp_soft_reconfig_in(peer
, afi
, safi
);
3530 } else if (CHECK_FLAG(peer
->cap
,
3531 PEER_CAP_REFRESH_OLD_RCV
)
3532 || CHECK_FLAG(peer
->cap
,
3533 PEER_CAP_REFRESH_NEW_RCV
)) {
3534 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3536 "Processing route_map %s(%s:%s) update on peer %s (inbound, route-refresh)",
3537 rmap_name
, afi2str(afi
),
3538 safi2str(safi
), peer
->host
);
3539 bgp_route_refresh_send(
3540 peer
, afi
, safi
, 0, 0, 0,
3541 BGP_ROUTE_REFRESH_NORMAL
);
3547 * For outbound, unsuppress and default-originate map change (content or
3548 * map created), merely update the "config" here, the actual route
3549 * announcement happens at the group level.
3551 if (filter
->map
[RMAP_OUT
].name
3552 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3553 filter
->map
[RMAP_OUT
].map
= map
;
3555 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3556 filter
->usmap
.map
= map
;
3558 if (filter
->advmap
.aname
3559 && (strcmp(rmap_name
, filter
->advmap
.aname
) == 0)) {
3560 filter
->advmap
.amap
= map
;
3563 if (filter
->advmap
.cname
3564 && (strcmp(rmap_name
, filter
->advmap
.cname
) == 0)) {
3565 filter
->advmap
.cmap
= map
;
3568 if (peer
->default_rmap
[afi
][safi
].name
3569 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3570 peer
->default_rmap
[afi
][safi
].map
= map
;
3572 /* Notify BGP conditional advertisement scanner percess */
3573 peer
->advmap_config_change
[afi
][safi
] = true;
3576 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3577 struct route_map
*map
,
3580 struct peer_group
*group
;
3581 struct listnode
*node
, *nnode
;
3582 struct bgp_filter
*filter
;
3589 /* All the peers have been updated correctly already. This is
3590 * just updating the placeholder data. No real update required.
3592 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3593 FOREACH_AFI_SAFI (afi
, safi
) {
3594 filter
= &group
->conf
->filter
[afi
][safi
];
3596 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3597 if ((filter
->map
[direct
].name
)
3598 && (strcmp(rmap_name
,
3599 filter
->map
[direct
].name
)
3601 filter
->map
[direct
].map
= map
;
3604 if (filter
->usmap
.name
3605 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3606 filter
->usmap
.map
= map
;
3612 * Note that if an extreme number (tens of thousands) of route-maps are in use
3613 * and if bgp has an extreme number of peers, network statements, etc then this
3614 * function can consume a lot of cycles. This is due to this function being
3615 * called for each route-map and within this function we walk the list of peers,
3616 * network statements, etc looking to see if they use this route-map.
3618 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3626 struct bgp_dest
*bn
;
3627 struct bgp_static
*bgp_static
;
3628 struct bgp_aggregate
*aggregate
;
3629 struct listnode
*node
, *nnode
;
3630 struct route_map
*map
;
3631 char buf
[INET6_ADDRSTRLEN
];
3633 map
= route_map_lookup_by_name(rmap_name
);
3635 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3637 /* Ignore dummy peer-group structure */
3638 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3641 FOREACH_AFI_SAFI (afi
, safi
) {
3642 /* process in/out/import/export/default-orig
3644 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3645 safi
, route_update
);
3649 /* for outbound/default-orig route-maps, process for groups */
3650 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3653 /* update peer-group config (template) */
3654 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3656 FOREACH_AFI_SAFI (afi
, safi
) {
3657 /* For table route-map updates. */
3658 if (!bgp_fibupd_safi(safi
))
3661 if (bgp
->table_map
[afi
][safi
].name
3662 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3665 /* bgp->table_map[afi][safi].map is NULL.
3666 * i.e Route map creation event.
3667 * So update applied_counter.
3668 * If it is not NULL, i.e It may be routemap updation or
3669 * deletion. so no need to update the counter.
3671 if (!bgp
->table_map
[afi
][safi
].map
)
3672 route_map_counter_increment(map
);
3673 bgp
->table_map
[afi
][safi
].map
= map
;
3675 if (BGP_DEBUG(zebra
, ZEBRA
))
3677 "Processing route_map %s(%s:%s) update on table map",
3678 rmap_name
, afi2str(afi
),
3681 bgp_zebra_announce_table(bgp
, afi
, safi
);
3684 /* For network route-map updates. */
3685 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3686 bn
= bgp_route_next(bn
)) {
3687 bgp_static
= bgp_dest_get_bgp_static_info(bn
);
3691 if (!bgp_static
->rmap
.name
3692 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3695 if (!bgp_static
->rmap
.map
)
3696 route_map_counter_increment(map
);
3698 bgp_static
->rmap
.map
= map
;
3700 if (route_update
&& !bgp_static
->backdoor
) {
3701 const struct prefix
*bn_p
=
3702 bgp_dest_get_prefix(bn
);
3704 if (bgp_debug_zebra(bn_p
))
3706 "Processing route_map %s(%s:%s) update on static route %s",
3707 rmap_name
, afi2str(afi
),
3709 inet_ntop(bn_p
->family
,
3710 &bn_p
->u
.prefix
, buf
,
3712 bgp_static_update(bgp
, bn_p
, bgp_static
, afi
,
3717 /* For aggregate-address route-map updates. */
3718 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
3719 bn
= bgp_route_next(bn
)) {
3720 aggregate
= bgp_dest_get_bgp_aggregate_info(bn
);
3726 /* Update suppress map pointer. */
3727 if (aggregate
->suppress_map_name
3728 && strmatch(aggregate
->suppress_map_name
,
3730 if (aggregate
->rmap
.map
== NULL
)
3731 route_map_counter_increment(map
);
3733 aggregate
->suppress_map
= map
;
3735 bgp_aggregate_toggle_suppressed(
3736 aggregate
, bgp
, bgp_dest_get_prefix(bn
),
3742 if (aggregate
->rmap
.name
3743 && strmatch(rmap_name
, aggregate
->rmap
.name
)) {
3744 if (aggregate
->rmap
.map
== NULL
)
3745 route_map_counter_increment(map
);
3747 aggregate
->rmap
.map
= map
;
3752 if (matched
&& route_update
) {
3753 const struct prefix
*bn_p
=
3754 bgp_dest_get_prefix(bn
);
3756 if (bgp_debug_zebra(bn_p
))
3758 "Processing route_map %s(%s:%s) update on aggregate-address route %s",
3759 rmap_name
, afi2str(afi
),
3761 inet_ntop(bn_p
->family
,
3762 &bn_p
->u
.prefix
, buf
,
3764 bgp_aggregate_route(bgp
, bn_p
, afi
, safi
,
3770 /* For redistribute route-map updates. */
3771 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3772 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3773 struct list
*red_list
;
3774 struct bgp_redist
*red
;
3776 red_list
= bgp
->redist
[afi
][i
];
3780 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3782 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3786 route_map_counter_increment(map
);
3788 red
->rmap
.map
= map
;
3793 if (BGP_DEBUG(zebra
, ZEBRA
))
3795 "Processing route_map %s(%s:%s) update on redistributed routes",
3796 rmap_name
, afi2str(afi
),
3799 bgp_redistribute_resend(bgp
, afi
, i
,
3804 /* for type5 command route-maps */
3805 FOREACH_AFI_SAFI (afi
, safi
) {
3806 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3807 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3811 /* Make sure the route-map is populated here if not already done */
3812 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3814 if (BGP_DEBUG(zebra
, ZEBRA
))
3816 "Processing route_map %s(%s:%s) update on advertise type5 route command",
3817 rmap_name
, afi2str(afi
), safi2str(safi
));
3819 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3820 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3821 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3826 static void bgp_route_map_process_update_cb(char *rmap_name
)
3828 struct listnode
*node
, *nnode
;
3831 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3832 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3834 #ifdef ENABLE_BGP_VNC
3835 vnc_routemap_update(bgp
, __func__
);
3839 vpn_policy_routemap_event(rmap_name
);
3842 int bgp_route_map_update_timer(struct thread
*thread
)
3844 bm
->t_rmap_update
= NULL
;
3846 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3851 static void bgp_route_map_mark_update(const char *rmap_name
)
3853 struct listnode
*node
, *nnode
;
3856 /* If new update is received before the current timer timed out,
3857 * turn it off and start a new timer.
3859 THREAD_OFF(bm
->t_rmap_update
);
3861 /* rmap_update_timer of 0 means don't do route updates */
3862 if (bm
->rmap_update_timer
) {
3863 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3864 NULL
, bm
->rmap_update_timer
,
3865 &bm
->t_rmap_update
);
3867 /* Signal the groups that a route-map update event has
3869 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3870 update_group_policy_update(bgp
,
3871 BGP_POLICY_ROUTE_MAP
,
3874 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3875 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3876 #ifdef ENABLE_BGP_VNC
3877 vnc_routemap_update(bgp
, __func__
);
3881 vpn_policy_routemap_event(rmap_name
);
3885 static void bgp_route_map_add(const char *rmap_name
)
3887 if (route_map_mark_updated(rmap_name
) == 0)
3888 bgp_route_map_mark_update(rmap_name
);
3890 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3893 static void bgp_route_map_delete(const char *rmap_name
)
3895 if (route_map_mark_updated(rmap_name
) == 0)
3896 bgp_route_map_mark_update(rmap_name
);
3898 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3901 static void bgp_route_map_event(const char *rmap_name
)
3903 if (route_map_mark_updated(rmap_name
) == 0)
3904 bgp_route_map_mark_update(rmap_name
);
3906 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3909 DEFUN_YANG (match_mac_address
,
3910 match_mac_address_cmd
,
3911 "match mac address WORD",
3914 "Match address of route\n"
3915 "MAC Access-list name\n")
3918 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
3919 char xpath_value
[XPATH_MAXLEN
];
3921 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
3922 snprintf(xpath_value
, sizeof(xpath_value
),
3923 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
3924 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
3926 return nb_cli_apply_changes(vty
, NULL
);
3929 DEFUN_YANG (no_match_mac_address
,
3930 no_match_mac_address_cmd
,
3931 "no match mac address WORD",
3935 "Match address of route\n"
3936 "MAC acess-list name\n")
3939 "./match-condition[condition='frr-bgp-route-map:mac-address-list']";
3941 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
3942 return nb_cli_apply_changes(vty
, NULL
);
3946 * Helper to handle the case of the user passing in a number or type string
3948 static const char *parse_evpn_rt_type(const char *num_rt_type
)
3950 switch (num_rt_type
[0]) {
3965 /* Was already full type string */
3969 DEFUN_YANG (match_evpn_route_type
,
3970 match_evpn_route_type_cmd
,
3971 "match evpn route-type <macip|2|multicast|3|prefix|5>",
3975 EVPN_TYPE_2_HELP_STR
3976 EVPN_TYPE_2_HELP_STR
3977 EVPN_TYPE_3_HELP_STR
3978 EVPN_TYPE_3_HELP_STR
3979 EVPN_TYPE_5_HELP_STR
3980 EVPN_TYPE_5_HELP_STR
)
3983 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
3984 char xpath_value
[XPATH_MAXLEN
];
3986 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
3987 snprintf(xpath_value
, sizeof(xpath_value
),
3988 "%s/rmap-match-condition/frr-bgp-route-map:evpn-route-type",
3990 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
3991 parse_evpn_rt_type(argv
[3]->arg
));
3993 return nb_cli_apply_changes(vty
, NULL
);
3996 DEFUN_YANG (no_match_evpn_route_type
,
3997 no_match_evpn_route_type_cmd
,
3998 "no match evpn route-type <macip|2|multicast|3|prefix|5>",
4003 EVPN_TYPE_2_HELP_STR
4004 EVPN_TYPE_2_HELP_STR
4005 EVPN_TYPE_3_HELP_STR
4006 EVPN_TYPE_3_HELP_STR
4007 EVPN_TYPE_5_HELP_STR
4008 EVPN_TYPE_5_HELP_STR
)
4011 "./match-condition[condition='frr-bgp-route-map:evpn-route-type']";
4013 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4015 return nb_cli_apply_changes(vty
, NULL
);
4019 DEFUN_YANG (match_evpn_vni
,
4021 "match evpn vni " CMD_VNI_RANGE
,
4028 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4029 char xpath_value
[XPATH_MAXLEN
];
4031 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4032 snprintf(xpath_value
, sizeof(xpath_value
),
4033 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4034 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4036 return nb_cli_apply_changes(vty
, NULL
);
4039 DEFUN_YANG (no_match_evpn_vni
,
4040 no_match_evpn_vni_cmd
,
4041 "no match evpn vni " CMD_VNI_RANGE
,
4049 "./match-condition[condition='frr-bgp-route-map:evpn-vni']";
4050 char xpath_value
[XPATH_MAXLEN
];
4052 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4053 snprintf(xpath_value
, sizeof(xpath_value
),
4054 "%s/rmap-match-condition/frr-bgp-route-map:evpn-vni", xpath
);
4055 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
, argv
[3]->arg
);
4057 return nb_cli_apply_changes(vty
, NULL
);
4060 DEFUN_YANG (match_evpn_default_route
,
4061 match_evpn_default_route_cmd
,
4062 "match evpn default-route",
4065 "default EVPN type-5 route\n")
4068 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4069 char xpath_value
[XPATH_MAXLEN
];
4071 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4073 snprintf(xpath_value
, sizeof(xpath_value
),
4074 "%s/rmap-match-condition/frr-bgp-route-map:evpn-default-route",
4076 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
4078 return nb_cli_apply_changes(vty
, NULL
);
4081 DEFUN_YANG (no_match_evpn_default_route
,
4082 no_match_evpn_default_route_cmd
,
4083 "no match evpn default-route",
4087 "default EVPN type-5 route\n")
4090 "./match-condition[condition='frr-bgp-route-map:evpn-default-route']";
4092 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4094 return nb_cli_apply_changes(vty
, NULL
);
4097 DEFUN_YANG (match_evpn_rd
,
4099 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4102 "Route Distinguisher\n"
4103 "ASN:XX or A.B.C.D:XX\n")
4106 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4107 char xpath_value
[XPATH_MAXLEN
];
4109 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4111 xpath_value
, sizeof(xpath_value
),
4112 "%s/rmap-match-condition/frr-bgp-route-map:route-distinguisher",
4114 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
4116 return nb_cli_apply_changes(vty
, NULL
);
4119 DEFUN_YANG (no_match_evpn_rd
,
4120 no_match_evpn_rd_cmd
,
4121 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4125 "Route Distinguisher\n"
4126 "ASN:XX or A.B.C.D:XX\n")
4129 "./match-condition[condition='frr-bgp-route-map:evpn-rd']";
4131 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4132 return nb_cli_apply_changes(vty
, NULL
);
4135 DEFUN_YANG (set_evpn_gw_ip_ipv4
,
4136 set_evpn_gw_ip_ipv4_cmd
,
4137 "set evpn gateway-ip ipv4 A.B.C.D",
4140 "Set gateway IP for prefix advertisement route\n"
4142 "Gateway IP address in IPv4 format\n")
4147 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4148 char xpath_value
[XPATH_MAXLEN
];
4150 ret
= str2sockunion(argv
[4]->arg
, &su
);
4152 vty_out(vty
, "%% Malformed gateway IP\n");
4153 return CMD_WARNING_CONFIG_FAILED
;
4156 if (su
.sin
.sin_addr
.s_addr
== 0
4157 || IPV4_CLASS_DE(ntohl(su
.sin
.sin_addr
.s_addr
))) {
4159 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4160 return CMD_WARNING_CONFIG_FAILED
;
4163 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4165 snprintf(xpath_value
, sizeof(xpath_value
),
4166 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv4",
4169 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4170 return nb_cli_apply_changes(vty
, NULL
);
4173 DEFUN_YANG (no_set_evpn_gw_ip_ipv4
,
4174 no_set_evpn_gw_ip_ipv4_cmd
,
4175 "no set evpn gateway-ip ipv4 A.B.C.D",
4179 "Set gateway IP for prefix advertisement route\n"
4181 "Gateway IP address in IPv4 format\n")
4186 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv4']";
4188 ret
= str2sockunion(argv
[5]->arg
, &su
);
4190 vty_out(vty
, "%% Malformed gateway IP\n");
4191 return CMD_WARNING_CONFIG_FAILED
;
4194 if (su
.sin
.sin_addr
.s_addr
== 0
4195 || IPV4_CLASS_DE(ntohl(su
.sin
.sin_addr
.s_addr
))) {
4197 "%% Gateway IP cannot be 0.0.0.0, multicast or reserved\n");
4198 return CMD_WARNING_CONFIG_FAILED
;
4201 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4203 return nb_cli_apply_changes(vty
, NULL
);
4206 DEFUN_YANG (set_evpn_gw_ip_ipv6
,
4207 set_evpn_gw_ip_ipv6_cmd
,
4208 "set evpn gateway-ip ipv6 X:X::X:X",
4211 "Set gateway IP for prefix advertisement route\n"
4213 "Gateway IP address in IPv6 format\n")
4218 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4219 char xpath_value
[XPATH_MAXLEN
];
4221 ret
= str2sockunion(argv
[4]->arg
, &su
);
4223 vty_out(vty
, "%% Malformed gateway IP\n");
4224 return CMD_WARNING_CONFIG_FAILED
;
4227 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4228 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4230 "%% Gateway IP cannot be a linklocal or multicast address\n");
4231 return CMD_WARNING_CONFIG_FAILED
;
4234 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4236 snprintf(xpath_value
, sizeof(xpath_value
),
4237 "%s/rmap-set-action/frr-bgp-route-map:evpn-gateway-ip-ipv6",
4240 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
4241 return nb_cli_apply_changes(vty
, NULL
);
4244 DEFUN_YANG (no_set_evpn_gw_ip_ipv6
,
4245 no_set_evpn_gw_ip_ipv6_cmd
,
4246 "no set evpn gateway-ip ipv6 X:X::X:X",
4250 "Set gateway IP for prefix advertisement route\n"
4252 "Gateway IP address in IPv4 format\n")
4257 "./set-action[action='frr-bgp-route-map:set-evpn-gateway-ip-ipv6']";
4259 ret
= str2sockunion(argv
[5]->arg
, &su
);
4261 vty_out(vty
, "%% Malformed gateway IP\n");
4262 return CMD_WARNING_CONFIG_FAILED
;
4265 if (IN6_IS_ADDR_LINKLOCAL(&su
.sin6
.sin6_addr
)
4266 || IN6_IS_ADDR_MULTICAST(&su
.sin6
.sin6_addr
)) {
4268 "%% Gateway IP cannot be a linklocal or multicast address\n");
4269 return CMD_WARNING_CONFIG_FAILED
;
4272 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4274 return nb_cli_apply_changes(vty
, NULL
);
4277 DEFPY_YANG(match_vrl_source_vrf
,
4278 match_vrl_source_vrf_cmd
,
4279 "match source-vrf NAME$vrf_name",
4285 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4286 char xpath_value
[XPATH_MAXLEN
];
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:source-vrf", xpath
);
4291 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, vrf_name
);
4293 return nb_cli_apply_changes(vty
, NULL
);
4296 DEFPY_YANG(no_match_vrl_source_vrf
,
4297 no_match_vrl_source_vrf_cmd
,
4298 "no match source-vrf NAME$vrf_name",
4304 "./match-condition[condition='frr-bgp-route-map:source-vrf']";
4306 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4307 return nb_cli_apply_changes(vty
, NULL
);
4310 DEFPY_YANG (match_peer
,
4312 "match peer <A.B.C.D$addrv4|X:X::X:X$addrv6|WORD$intf>",
4314 "Match peer address\n"
4315 "IP address of peer\n"
4316 "IPv6 address of peer\n"
4317 "Interface name of peer\n")
4320 "./match-condition[condition='frr-bgp-route-map:peer']";
4321 char xpath_value
[XPATH_MAXLEN
];
4323 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4327 xpath_value
, sizeof(xpath_value
),
4328 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv4-address",
4330 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4332 } else if (addrv6_str
) {
4334 xpath_value
, sizeof(xpath_value
),
4335 "%s/rmap-match-condition/frr-bgp-route-map:peer-ipv6-address",
4337 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4341 xpath_value
, sizeof(xpath_value
),
4342 "%s/rmap-match-condition/frr-bgp-route-map:peer-interface",
4344 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, intf
);
4347 return nb_cli_apply_changes(vty
, NULL
);
4350 DEFUN_YANG (match_peer_local
,
4351 match_peer_local_cmd
,
4354 "Match peer address\n"
4355 "Static or Redistributed routes\n")
4358 "./match-condition[condition='frr-bgp-route-map:peer']";
4359 char xpath_value
[XPATH_MAXLEN
];
4361 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4363 snprintf(xpath_value
, sizeof(xpath_value
),
4364 "%s/rmap-match-condition/frr-bgp-route-map:peer-local", xpath
);
4365 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
4367 return nb_cli_apply_changes(vty
, NULL
);
4370 DEFUN_YANG (no_match_peer
,
4372 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
4375 "Match peer address\n"
4376 "Static or Redistributed routes\n"
4377 "IP address of peer\n"
4378 "IPv6 address of peer\n"
4379 "Interface name of peer\n")
4382 "./match-condition[condition='frr-bgp-route-map:peer']";
4384 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4386 return nb_cli_apply_changes(vty
, NULL
);
4389 #ifdef HAVE_SCRIPTING
4390 DEFUN_YANG (match_script
,
4392 "[no] match script WORD",
4395 "Execute script to determine match\n"
4396 "The script name to run, without .lua; e.g. 'myroutemap' to run myroutemap.lua\n")
4398 bool no
= strmatch(argv
[0]->text
, "no");
4400 argv_find(argv
, argc
, "WORD", &i
);
4401 const char *script
= argv
[i
]->arg
;
4403 "./match-condition[condition='frr-bgp-route-map:match-script']";
4404 char xpath_value
[XPATH_MAXLEN
];
4407 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4408 snprintf(xpath_value
, sizeof(xpath_value
),
4409 "%s/rmap-match-condition/frr-bgp-route-map:script",
4411 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4414 return nb_cli_apply_changes(vty
, NULL
);
4417 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4418 snprintf(xpath_value
, sizeof(xpath_value
),
4419 "%s/rmap-match-condition/frr-bgp-route-map:script",
4421 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4424 return nb_cli_apply_changes(vty
, NULL
);
4426 #endif /* HAVE_SCRIPTING */
4428 /* match probability */
4429 DEFUN_YANG (match_probability
,
4430 match_probability_cmd
,
4431 "match probability (0-100)",
4433 "Match portion of routes defined by percentage value\n"
4434 "Percentage of routes\n")
4439 "./match-condition[condition='frr-bgp-route-map:probability']";
4440 char xpath_value
[XPATH_MAXLEN
];
4442 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4443 snprintf(xpath_value
, sizeof(xpath_value
),
4444 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4446 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4447 argv
[idx_number
]->arg
);
4449 return nb_cli_apply_changes(vty
, NULL
);
4453 DEFUN_YANG (no_match_probability
,
4454 no_match_probability_cmd
,
4455 "no match probability [(1-99)]",
4458 "Match portion of routes defined by percentage value\n"
4459 "Percentage of routes\n")
4463 "./match-condition[condition='frr-bgp-route-map:probability']";
4464 char xpath_value
[XPATH_MAXLEN
];
4466 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4468 if (argc
<= idx_number
)
4469 return nb_cli_apply_changes(vty
, NULL
);
4471 snprintf(xpath_value
, sizeof(xpath_value
),
4472 "%s/rmap-match-condition/frr-bgp-route-map:probability",
4474 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4475 argv
[idx_number
]->arg
);
4477 return nb_cli_apply_changes(vty
, NULL
);
4481 DEFPY_YANG (match_ip_route_source
,
4482 match_ip_route_source_cmd
,
4483 "match ip route-source <(1-199)|(1300-2699)|WORD>",
4486 "Match advertising source address of route\n"
4487 "IP access-list number\n"
4488 "IP access-list number (expanded range)\n"
4489 "IP standard access-list name\n")
4492 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4493 char xpath_value
[XPATH_MAXLEN
+ 32];
4496 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4497 snprintf(xpath_value
, sizeof(xpath_value
),
4498 "%s/rmap-match-condition/frr-bgp-route-map:list-name",
4500 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4501 argv
[idx_acl
]->arg
);
4503 return nb_cli_apply_changes(vty
, NULL
);
4507 DEFUN_YANG (no_match_ip_route_source
,
4508 no_match_ip_route_source_cmd
,
4509 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
4513 "Match advertising source address of route\n"
4514 "IP access-list number\n"
4515 "IP access-list number (expanded range)\n"
4516 "IP standard access-list name\n")
4519 "./match-condition[condition='frr-bgp-route-map:ip-route-source']";
4521 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4522 return nb_cli_apply_changes(vty
, NULL
);
4525 DEFUN_YANG (match_ip_route_source_prefix_list
,
4526 match_ip_route_source_prefix_list_cmd
,
4527 "match ip route-source prefix-list WORD",
4530 "Match advertising source address of route\n"
4531 "Match entries of prefix-lists\n"
4532 "IP prefix-list name\n")
4536 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4537 char xpath_value
[XPATH_MAXLEN
+ 32];
4539 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4540 snprintf(xpath_value
, sizeof(xpath_value
),
4541 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4542 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4543 argv
[idx_word
]->arg
);
4545 return nb_cli_apply_changes(vty
, NULL
);
4549 DEFUN_YANG (no_match_ip_route_source_prefix_list
,
4550 no_match_ip_route_source_prefix_list_cmd
,
4551 "no match ip route-source prefix-list [WORD]",
4555 "Match advertising source address of route\n"
4556 "Match entries of prefix-lists\n"
4557 "IP prefix-list name\n")
4560 "./match-condition[condition='frr-bgp-route-map:ip-route-source-prefix-list']";
4562 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4563 return nb_cli_apply_changes(vty
, NULL
);
4566 DEFUN_YANG (match_local_pref
,
4567 match_local_pref_cmd
,
4568 "match local-preference (0-4294967295)",
4570 "Match local-preference of route\n"
4576 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
4577 char xpath_value
[XPATH_MAXLEN
];
4579 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4580 snprintf(xpath_value
, sizeof(xpath_value
),
4581 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
4583 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4584 argv
[idx_number
]->arg
);
4586 return nb_cli_apply_changes(vty
, NULL
);
4590 DEFUN_YANG (no_match_local_pref
,
4591 no_match_local_pref_cmd
,
4592 "no match local-preference [(0-4294967295)]",
4595 "Match local preference of route\n"
4596 "Local preference value\n")
4598 int idx_localpref
= 3;
4600 "./match-condition[condition='frr-bgp-route-map:match-local-preference']";
4601 char xpath_value
[XPATH_MAXLEN
];
4603 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4605 if (argc
<= idx_localpref
)
4606 return nb_cli_apply_changes(vty
, NULL
);
4608 snprintf(xpath_value
, sizeof(xpath_value
),
4609 "%s/rmap-match-condition/frr-bgp-route-map:local-preference",
4611 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_DESTROY
,
4612 argv
[idx_localpref
]->arg
);
4614 return nb_cli_apply_changes(vty
, NULL
);
4618 DEFPY_YANG (match_community
,
4619 match_community_cmd
,
4620 "match community <(1-99)|(100-500)|WORD> [exact-match]",
4622 "Match BGP community list\n"
4623 "Community-list number (standard)\n"
4624 "Community-list number (expanded)\n"
4625 "Community-list name\n"
4626 "Do exact matching of communities\n")
4629 "./match-condition[condition='frr-bgp-route-map:match-community']";
4630 char xpath_value
[XPATH_MAXLEN
];
4631 char xpath_match
[XPATH_MAXLEN
];
4632 int idx_comm_list
= 2;
4634 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4637 xpath_value
, sizeof(xpath_value
),
4638 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
4640 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
4644 xpath_match
, sizeof(xpath_match
),
4645 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4647 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
4651 xpath_match
, sizeof(xpath_match
),
4652 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4654 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
4658 return nb_cli_apply_changes(vty
, NULL
);
4661 DEFUN_YANG (no_match_community
,
4662 no_match_community_cmd
,
4663 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
4666 "Match BGP community list\n"
4667 "Community-list number (standard)\n"
4668 "Community-list number (expanded)\n"
4669 "Community-list name\n"
4670 "Do exact matching of communities\n")
4673 "./match-condition[condition='frr-bgp-route-map:match-community']";
4675 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4676 return nb_cli_apply_changes(vty
, NULL
);
4679 DEFPY_YANG (match_lcommunity
,
4680 match_lcommunity_cmd
,
4681 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
4683 "Match BGP large community list\n"
4684 "Large Community-list number (standard)\n"
4685 "Large Community-list number (expanded)\n"
4686 "Large Community-list name\n"
4687 "Do exact matching of communities\n")
4690 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
4691 char xpath_value
[XPATH_MAXLEN
];
4692 char xpath_match
[XPATH_MAXLEN
];
4693 int idx_lcomm_list
= 2;
4695 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4698 xpath_value
, sizeof(xpath_value
),
4699 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
4701 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_lcomm_list
]->arg
);
4705 xpath_match
, sizeof(xpath_match
),
4706 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4708 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
4712 xpath_match
, sizeof(xpath_match
),
4713 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match",
4715 nb_cli_enqueue_change(vty
, xpath_match
, NB_OP_MODIFY
,
4719 return nb_cli_apply_changes(vty
, NULL
);
4722 DEFUN_YANG (no_match_lcommunity
,
4723 no_match_lcommunity_cmd
,
4724 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
4727 "Match BGP large community list\n"
4728 "Large Community-list number (standard)\n"
4729 "Large Community-list number (expanded)\n"
4730 "Large Community-list name\n"
4731 "Do exact matching of communities\n")
4734 "./match-condition[condition='frr-bgp-route-map:match-large-community']";
4736 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4737 return nb_cli_apply_changes(vty
, NULL
);
4740 DEFPY_YANG (match_ecommunity
,
4741 match_ecommunity_cmd
,
4742 "match extcommunity <(1-99)|(100-500)|WORD>",
4744 "Match BGP/VPN extended community list\n"
4745 "Extended community-list number (standard)\n"
4746 "Extended community-list number (expanded)\n"
4747 "Extended community-list name\n")
4750 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
4751 char xpath_value
[XPATH_MAXLEN
];
4752 int idx_comm_list
= 2;
4754 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4757 xpath_value
, sizeof(xpath_value
),
4758 "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name",
4760 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[idx_comm_list
]->arg
);
4762 return nb_cli_apply_changes(vty
, NULL
);
4766 DEFUN_YANG (no_match_ecommunity
,
4767 no_match_ecommunity_cmd
,
4768 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
4771 "Match BGP/VPN extended community list\n"
4772 "Extended community-list number (standard)\n"
4773 "Extended community-list number (expanded)\n"
4774 "Extended community-list name\n")
4777 "./match-condition[condition='frr-bgp-route-map:match-extcommunity']";
4779 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4780 return nb_cli_apply_changes(vty
, NULL
);
4784 DEFUN_YANG (match_aspath
,
4786 "match as-path WORD",
4788 "Match BGP AS path list\n"
4789 "AS path access-list name\n")
4794 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
4795 char xpath_value
[XPATH_MAXLEN
];
4797 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4798 snprintf(xpath_value
, sizeof(xpath_value
),
4799 "%s/rmap-match-condition/frr-bgp-route-map:list-name", xpath
);
4800 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4801 argv
[idx_word
]->arg
);
4803 return nb_cli_apply_changes(vty
, NULL
);
4807 DEFUN_YANG (no_match_aspath
,
4808 no_match_aspath_cmd
,
4809 "no match as-path [WORD]",
4812 "Match BGP AS path list\n"
4813 "AS path access-list name\n")
4816 "./match-condition[condition='frr-bgp-route-map:as-path-list']";
4818 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4820 return nb_cli_apply_changes(vty
, NULL
);
4823 DEFUN_YANG (match_origin
,
4825 "match origin <egp|igp|incomplete>",
4830 "unknown heritage\n")
4833 const char *origin_type
;
4835 "./match-condition[condition='frr-bgp-route-map:match-origin']";
4836 char xpath_value
[XPATH_MAXLEN
];
4838 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4839 origin_type
= "igp";
4840 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4841 origin_type
= "egp";
4842 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4843 origin_type
= "incomplete";
4845 vty_out(vty
, "%% Invalid match origin type\n");
4846 return CMD_WARNING_CONFIG_FAILED
;
4849 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4850 snprintf(xpath_value
, sizeof(xpath_value
),
4851 "%s/rmap-match-condition/frr-bgp-route-map:origin", xpath
);
4852 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
4854 return nb_cli_apply_changes(vty
, NULL
);
4858 DEFUN_YANG (no_match_origin
,
4859 no_match_origin_cmd
,
4860 "no match origin [<egp|igp|incomplete>]",
4866 "unknown heritage\n")
4869 "./match-condition[condition='frr-bgp-route-map:match-origin']";
4870 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4871 return nb_cli_apply_changes(vty
, NULL
);
4874 DEFUN_YANG (set_table_id
,
4876 "set table (1-4294967295)",
4878 "export route to non-main kernel table\n"
4879 "Kernel routing table id\n")
4882 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
4883 char xpath_value
[XPATH_MAXLEN
];
4885 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4886 snprintf(xpath_value
, sizeof(xpath_value
),
4887 "%s/rmap-set-action/frr-bgp-route-map:table", xpath
);
4888 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4889 argv
[idx_number
]->arg
);
4890 return nb_cli_apply_changes(vty
, NULL
);
4893 DEFUN_YANG (no_set_table_id
,
4894 no_set_table_id_cmd
,
4898 "export route to non-main kernel table\n")
4900 const char *xpath
= "./set-action[action='frr-bgp-route-map:table']";
4901 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4902 return nb_cli_apply_changes(vty
, NULL
);
4905 DEFUN_YANG (set_ip_nexthop_peer
,
4906 set_ip_nexthop_peer_cmd
,
4907 "[no] set ip next-hop peer-address",
4911 "Next hop address\n"
4912 "Use peer address (for BGP only)\n")
4914 char xpath_value
[XPATH_MAXLEN
];
4916 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
4918 if (strmatch(argv
[0]->text
, "no"))
4919 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4921 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4922 snprintf(xpath_value
, sizeof(xpath_value
),
4923 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
4925 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4928 return nb_cli_apply_changes(vty
, NULL
);
4931 DEFUN_YANG (set_ip_nexthop_unchanged
,
4932 set_ip_nexthop_unchanged_cmd
,
4933 "[no] set ip next-hop unchanged",
4937 "Next hop address\n"
4938 "Don't modify existing Next hop address\n")
4940 char xpath_value
[XPATH_MAXLEN
];
4942 "./set-action[action='frr-bgp-route-map:set-ipv4-nexthop']";
4944 if (strmatch(argv
[0]->text
, "no"))
4945 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4947 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4948 snprintf(xpath_value
, sizeof(xpath_value
),
4949 "%s/rmap-set-action/frr-bgp-route-map:ipv4-nexthop",
4951 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4954 return nb_cli_apply_changes(vty
, NULL
);
4957 DEFUN_YANG (set_distance
,
4959 "set distance (0-255)",
4961 "BGP Administrative Distance to use\n"
4965 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
4966 char xpath_value
[XPATH_MAXLEN
];
4968 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
4969 snprintf(xpath_value
, sizeof(xpath_value
),
4970 "%s/rmap-set-action/frr-bgp-route-map:distance", xpath
);
4971 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
4972 argv
[idx_number
]->arg
);
4973 return nb_cli_apply_changes(vty
, NULL
);
4976 DEFUN_YANG (no_set_distance
,
4977 no_set_distance_cmd
,
4978 "no set distance [(0-255)]",
4980 "BGP Administrative Distance to use\n"
4983 const char *xpath
= "./set-action[action='frr-bgp-route-map:distance']";
4985 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
4986 return nb_cli_apply_changes(vty
, NULL
);
4989 DEFUN_YANG (set_local_pref
,
4991 "set local-preference WORD",
4993 "BGP local preference path attribute\n"
4994 "Preference value (0-4294967295)\n")
4998 "./set-action[action='frr-bgp-route-map:set-local-preference']";
4999 char xpath_value
[XPATH_MAXLEN
];
5001 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5002 snprintf(xpath_value
, sizeof(xpath_value
),
5003 "%s/rmap-set-action/frr-bgp-route-map:local-pref", xpath
);
5004 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5005 argv
[idx_number
]->arg
);
5006 return nb_cli_apply_changes(vty
, NULL
);
5009 DEFUN_YANG (no_set_local_pref
,
5010 no_set_local_pref_cmd
,
5011 "no set local-preference [WORD]",
5014 "BGP local preference path attribute\n"
5015 "Preference value (0-4294967295)\n")
5018 "./set-action[action='frr-bgp-route-map:set-local-preference']";
5020 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5021 return nb_cli_apply_changes(vty
, NULL
);
5024 DEFUN_YANG (set_weight
,
5026 "set weight (0-4294967295)",
5028 "BGP weight for routing table\n"
5032 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5033 char xpath_value
[XPATH_MAXLEN
];
5035 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5036 snprintf(xpath_value
, sizeof(xpath_value
),
5037 "%s/rmap-set-action/frr-bgp-route-map:weight", xpath
);
5038 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5039 argv
[idx_number
]->arg
);
5040 return nb_cli_apply_changes(vty
, NULL
);
5043 DEFUN_YANG (no_set_weight
,
5045 "no set weight [(0-4294967295)]",
5048 "BGP weight for routing table\n"
5051 const char *xpath
= "./set-action[action='frr-bgp-route-map:weight']";
5053 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5054 return nb_cli_apply_changes(vty
, NULL
);
5057 DEFUN_YANG (set_label_index
,
5058 set_label_index_cmd
,
5059 "set label-index (0-1048560)",
5061 "Label index to associate with the prefix\n"
5062 "Label index value\n")
5066 "./set-action[action='frr-bgp-route-map:label-index']";
5067 char xpath_value
[XPATH_MAXLEN
];
5069 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5070 snprintf(xpath_value
, sizeof(xpath_value
),
5071 "%s/rmap-set-action/frr-bgp-route-map:label-index", xpath
);
5072 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5073 argv
[idx_number
]->arg
);
5074 return nb_cli_apply_changes(vty
, NULL
);
5077 DEFUN_YANG (no_set_label_index
,
5078 no_set_label_index_cmd
,
5079 "no set label-index [(0-1048560)]",
5082 "Label index to associate with the prefix\n"
5083 "Label index value\n")
5086 "./set-action[action='frr-bgp-route-map:label-index']";
5088 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5089 return nb_cli_apply_changes(vty
, NULL
);
5092 DEFUN_YANG (set_aspath_prepend_asn
,
5093 set_aspath_prepend_asn_cmd
,
5094 "set as-path prepend (1-4294967295)...",
5096 "Transform BGP AS_PATH attribute\n"
5097 "Prepend to the as-path\n"
5104 str
= argv_concat(argv
, argc
, idx_asn
);
5107 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5108 char xpath_value
[XPATH_MAXLEN
];
5110 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5111 snprintf(xpath_value
, sizeof(xpath_value
),
5112 "%s/rmap-set-action/frr-bgp-route-map:prepend-as-path", xpath
);
5113 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5114 ret
= nb_cli_apply_changes(vty
, NULL
);
5115 XFREE(MTYPE_TMP
, str
);
5119 DEFUN_YANG (set_aspath_prepend_lastas
,
5120 set_aspath_prepend_lastas_cmd
,
5121 "set as-path prepend last-as (1-10)",
5123 "Transform BGP AS_PATH attribute\n"
5124 "Prepend to the as-path\n"
5125 "Use the peer's AS-number\n"
5126 "Number of times to insert\n")
5131 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5132 char xpath_value
[XPATH_MAXLEN
];
5134 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5135 snprintf(xpath_value
, sizeof(xpath_value
),
5136 "%s/rmap-set-action/frr-bgp-route-map:last-as", xpath
);
5137 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5138 argv
[idx_num
]->arg
);
5139 return nb_cli_apply_changes(vty
, NULL
);
5142 DEFUN_YANG (no_set_aspath_prepend
,
5143 no_set_aspath_prepend_cmd
,
5144 "no set as-path prepend [(1-4294967295)]",
5147 "Transform BGP AS_PATH attribute\n"
5148 "Prepend to the as-path\n"
5152 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5154 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5155 return nb_cli_apply_changes(vty
, NULL
);
5158 DEFUN_YANG (no_set_aspath_prepend_lastas
,
5159 no_set_aspath_prepend_lastas_cmd
,
5160 "no set as-path prepend last-as [(1-10)]",
5163 "Transform BGP AS_PATH attribute\n"
5164 "Prepend to the as-path\n"
5165 "Use the peers AS-number\n"
5166 "Number of times to insert\n")
5169 "./set-action[action='frr-bgp-route-map:as-path-prepend']";
5171 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5172 return nb_cli_apply_changes(vty
, NULL
);
5175 DEFUN_YANG (set_aspath_exclude
,
5176 set_aspath_exclude_cmd
,
5177 "set as-path exclude (1-4294967295)...",
5179 "Transform BGP AS-path attribute\n"
5180 "Exclude from the as-path\n"
5187 str
= argv_concat(argv
, argc
, idx_asn
);
5190 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5191 char xpath_value
[XPATH_MAXLEN
];
5193 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5194 snprintf(xpath_value
, sizeof(xpath_value
),
5195 "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", xpath
);
5196 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5197 ret
= nb_cli_apply_changes(vty
, NULL
);
5198 XFREE(MTYPE_TMP
, str
);
5202 DEFUN_YANG (no_set_aspath_exclude
,
5203 no_set_aspath_exclude_cmd
,
5204 "no set as-path exclude (1-4294967295)...",
5207 "Transform BGP AS_PATH attribute\n"
5208 "Exclude from the as-path\n"
5212 "./set-action[action='frr-bgp-route-map:as-path-exclude']";
5214 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5215 return nb_cli_apply_changes(vty
, NULL
);
5218 ALIAS_YANG (no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
5219 "no set as-path exclude",
5221 "Transform BGP AS_PATH attribute\n"
5222 "Exclude from the as-path\n")
5224 DEFUN_YANG (set_community
,
5226 "set community AA:NN...",
5228 "BGP community attribute\n"
5236 struct community
*com
= NULL
;
5238 char *argstr
= NULL
;
5242 "./set-action[action='frr-bgp-route-map:set-community']";
5243 char xpath_value
[XPATH_MAXLEN
];
5245 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5246 snprintf(xpath_value
, sizeof(xpath_value
),
5247 "%s/rmap-set-action/frr-bgp-route-map:community-string",
5250 b
= buffer_new(1024);
5252 for (i
= idx_aa_nn
; i
< argc
; i
++) {
5253 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
5260 buffer_putc(b
, ' ');
5264 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
5266 buffer_putstr(b
, "internet");
5269 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
5271 buffer_putstr(b
, "local-AS");
5274 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
5275 && strncmp(argv
[i
]->arg
, "no-advertise",
5276 strlen(argv
[i
]->arg
))
5278 buffer_putstr(b
, "no-advertise");
5281 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
5282 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
5284 buffer_putstr(b
, "no-export");
5287 if (strncmp(argv
[i
]->arg
, "blackhole", strlen(argv
[i
]->arg
))
5289 buffer_putstr(b
, "blackhole");
5292 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
5293 strlen(argv
[i
]->arg
))
5295 buffer_putstr(b
, "graceful-shutdown");
5298 buffer_putstr(b
, argv
[i
]->arg
);
5300 buffer_putc(b
, '\0');
5302 /* Fetch result string then compile it to communities attribute. */
5303 str
= buffer_getstr(b
);
5307 com
= community_str2com(str
);
5308 XFREE(MTYPE_TMP
, str
);
5311 /* Can't compile user input into communities attribute. */
5313 vty_out(vty
, "%% Malformed communities attribute\n");
5314 return CMD_WARNING_CONFIG_FAILED
;
5317 /* Set communites attribute string. */
5318 str
= community_str(com
, false);
5321 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
5322 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
5323 strlcpy(argstr
, str
, argstr_sz
);
5324 strlcat(argstr
, " additive", argstr_sz
);
5325 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argstr
);
5327 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5329 ret
= nb_cli_apply_changes(vty
, NULL
);
5332 XFREE(MTYPE_TMP
, argstr
);
5333 community_free(&com
);
5338 DEFUN_YANG (set_community_none
,
5339 set_community_none_cmd
,
5340 "set community none",
5342 "BGP community attribute\n"
5343 "No community attribute\n")
5346 "./set-action[action='frr-bgp-route-map:set-community']";
5347 char xpath_value
[XPATH_MAXLEN
];
5349 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5351 snprintf(xpath_value
, sizeof(xpath_value
),
5352 "%s/rmap-set-action/frr-bgp-route-map:community-none", xpath
);
5353 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5354 return nb_cli_apply_changes(vty
, NULL
);
5357 DEFUN_YANG (no_set_community
,
5358 no_set_community_cmd
,
5359 "no set community AA:NN...",
5362 "BGP community attribute\n"
5366 "./set-action[action='frr-bgp-route-map:set-community']";
5368 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5369 return nb_cli_apply_changes(vty
, NULL
);
5372 ALIAS_YANG (no_set_community
,
5373 no_set_community_short_cmd
,
5377 "BGP community attribute\n")
5379 DEFPY_YANG (set_community_delete
,
5380 set_community_delete_cmd
,
5381 "set comm-list <(1-99)|(100-500)|WORD> delete",
5383 "set BGP community list (for deletion)\n"
5384 "Community-list number (standard)\n"
5385 "Community-list number (expanded)\n"
5386 "Community-list name\n"
5387 "Delete matching communities\n")
5390 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5391 char xpath_value
[XPATH_MAXLEN
];
5392 int idx_comm_list
= 2;
5394 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5396 snprintf(xpath_value
, sizeof(xpath_value
),
5397 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
5399 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5400 argv
[idx_comm_list
]->arg
);
5402 return nb_cli_apply_changes(vty
, NULL
);
5406 DEFUN_YANG (no_set_community_delete
,
5407 no_set_community_delete_cmd
,
5408 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
5411 "set BGP community list (for deletion)\n"
5412 "Community-list number (standard)\n"
5413 "Community-list number (expanded)\n"
5414 "Community-list name\n"
5415 "Delete matching communities\n")
5418 "./set-action[action='frr-bgp-route-map:comm-list-delete']";
5420 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5421 return nb_cli_apply_changes(vty
, NULL
);
5424 DEFUN_YANG (set_lcommunity
,
5426 "set large-community AA:BB:CC...",
5428 "BGP large community attribute\n"
5429 "Large Community number in aa:bb:cc format or additive\n")
5434 "./set-action[action='frr-bgp-route-map:set-large-community']";
5435 char xpath_value
[XPATH_MAXLEN
];
5437 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5439 snprintf(xpath_value
, sizeof(xpath_value
),
5440 "%s/rmap-set-action/frr-bgp-route-map:large-community-string",
5442 str
= argv_concat(argv
, argc
, 2);
5443 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5444 ret
= nb_cli_apply_changes(vty
, NULL
);
5445 XFREE(MTYPE_TMP
, str
);
5449 DEFUN_YANG (set_lcommunity_none
,
5450 set_lcommunity_none_cmd
,
5451 "set large-community none",
5453 "BGP large community attribute\n"
5454 "No large community attribute\n")
5457 "./set-action[action='frr-bgp-route-map:set-large-community']";
5458 char xpath_value
[XPATH_MAXLEN
];
5460 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5462 snprintf(xpath_value
, sizeof(xpath_value
),
5463 "%s/rmap-set-action/frr-bgp-route-map:large-community-none",
5465 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5466 return nb_cli_apply_changes(vty
, NULL
);
5469 DEFUN_YANG (no_set_lcommunity
,
5470 no_set_lcommunity_cmd
,
5471 "no set large-community none",
5474 "BGP large community attribute\n"
5475 "No community attribute\n")
5478 "./set-action[action='frr-bgp-route-map:set-large-community']";
5480 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5481 return nb_cli_apply_changes(vty
, NULL
);
5484 DEFUN_YANG (no_set_lcommunity1
,
5485 no_set_lcommunity1_cmd
,
5486 "no set large-community AA:BB:CC...",
5489 "BGP large community attribute\n"
5490 "Large community in AA:BB:CC... format or additive\n")
5493 "./set-action[action='frr-bgp-route-map:set-large-community']";
5495 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5496 return nb_cli_apply_changes(vty
, NULL
);
5499 ALIAS_YANG (no_set_lcommunity1
,
5500 no_set_lcommunity1_short_cmd
,
5501 "no set large-community",
5504 "BGP large community attribute\n")
5506 DEFPY_YANG (set_lcommunity_delete
,
5507 set_lcommunity_delete_cmd
,
5508 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
5510 "set BGP large community list (for deletion)\n"
5511 "Large Community-list number (standard)\n"
5512 "Large Communitly-list number (expanded)\n"
5513 "Large Community-list name\n"
5514 "Delete matching large communities\n")
5517 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
5518 char xpath_value
[XPATH_MAXLEN
];
5519 int idx_lcomm_list
= 2;
5521 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5523 snprintf(xpath_value
, sizeof(xpath_value
),
5524 "%s/rmap-set-action/frr-bgp-route-map:comm-list-name",
5526 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
5527 argv
[idx_lcomm_list
]->arg
);
5529 return nb_cli_apply_changes(vty
, NULL
);
5532 DEFUN_YANG (no_set_lcommunity_delete
,
5533 no_set_lcommunity_delete_cmd
,
5534 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
5537 "set BGP large community list (for deletion)\n"
5538 "Large Community-list number (standard)\n"
5539 "Large Communitly-list number (expanded)\n"
5540 "Large Community-list name\n"
5541 "Delete matching large communities\n")
5544 "./set-action[action='frr-bgp-route-map:large-comm-list-delete']";
5546 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5547 return nb_cli_apply_changes(vty
, NULL
);
5550 ALIAS_YANG (no_set_lcommunity_delete
,
5551 no_set_lcommunity_delete_short_cmd
,
5552 "no set large-comm-list",
5555 "set BGP large community list (for deletion)\n")
5557 DEFUN_YANG (set_ecommunity_rt
,
5558 set_ecommunity_rt_cmd
,
5559 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
5561 "BGP extended community attribute\n"
5562 "Route Target extended community\n"
5563 "VPN extended community\n")
5569 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
5570 char xpath_value
[XPATH_MAXLEN
];
5572 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5574 snprintf(xpath_value
, sizeof(xpath_value
),
5575 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-rt", xpath
);
5576 str
= argv_concat(argv
, argc
, idx_asn_nn
);
5577 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5578 ret
= nb_cli_apply_changes(vty
, NULL
);
5579 XFREE(MTYPE_TMP
, str
);
5583 DEFUN_YANG (no_set_ecommunity_rt
,
5584 no_set_ecommunity_rt_cmd
,
5585 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
5588 "BGP extended community attribute\n"
5589 "Route Target extended community\n"
5590 "VPN extended community\n")
5593 "./set-action[action='frr-bgp-route-map:set-extcommunity-rt']";
5594 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5595 return nb_cli_apply_changes(vty
, NULL
);
5598 ALIAS_YANG (no_set_ecommunity_rt
,
5599 no_set_ecommunity_rt_short_cmd
,
5600 "no set extcommunity rt",
5603 "BGP extended community attribute\n"
5604 "Route Target extended community\n")
5606 DEFUN_YANG (set_ecommunity_soo
,
5607 set_ecommunity_soo_cmd
,
5608 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
5610 "BGP extended community attribute\n"
5611 "Site-of-Origin extended community\n"
5612 "VPN extended community\n")
5618 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
5619 char xpath_value
[XPATH_MAXLEN
];
5621 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5623 snprintf(xpath_value
, sizeof(xpath_value
),
5624 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-soo",
5626 str
= argv_concat(argv
, argc
, idx_asn_nn
);
5627 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, str
);
5628 ret
= nb_cli_apply_changes(vty
, NULL
);
5629 XFREE(MTYPE_TMP
, str
);
5633 DEFUN_YANG (no_set_ecommunity_soo
,
5634 no_set_ecommunity_soo_cmd
,
5635 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
5638 "BGP extended community attribute\n"
5639 "Site-of-Origin extended community\n"
5640 "VPN extended community\n")
5643 "./set-action[action='frr-bgp-route-map:set-extcommunity-soo']";
5644 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5645 return nb_cli_apply_changes(vty
, NULL
);
5648 ALIAS_YANG (no_set_ecommunity_soo
,
5649 no_set_ecommunity_soo_short_cmd
,
5650 "no set extcommunity soo",
5653 "GP extended community attribute\n"
5654 "Site-of-Origin extended community\n")
5656 DEFUN_YANG (set_ecommunity_lb
,
5657 set_ecommunity_lb_cmd
,
5658 "set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
5660 "BGP extended community attribute\n"
5661 "Link bandwidth extended community\n"
5662 "Bandwidth value in Mbps\n"
5663 "Cumulative bandwidth of all multipaths (outbound-only)\n"
5664 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
5665 "Attribute is set as non-transitive\n")
5668 int idx_non_transitive
= 4;
5670 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
5671 char xpath_lb_type
[XPATH_MAXLEN
];
5672 char xpath_bandwidth
[XPATH_MAXLEN
];
5673 char xpath_non_transitive
[XPATH_MAXLEN
];
5675 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5677 snprintf(xpath_lb_type
, sizeof(xpath_lb_type
),
5678 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/lb-type",
5680 snprintf(xpath_bandwidth
, sizeof(xpath_bandwidth
),
5681 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/bandwidth",
5683 snprintf(xpath_non_transitive
, sizeof(xpath_non_transitive
),
5684 "%s/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific",
5687 if ((strcmp(argv
[idx_lb
]->arg
, "cumulative")) == 0)
5688 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
5689 "cumulative-bandwidth");
5690 else if ((strcmp(argv
[idx_lb
]->arg
, "num-multipaths")) == 0)
5691 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
5692 "computed-bandwidth");
5694 nb_cli_enqueue_change(vty
, xpath_lb_type
, NB_OP_MODIFY
,
5695 "explicit-bandwidth");
5696 nb_cli_enqueue_change(vty
, xpath_bandwidth
, NB_OP_MODIFY
,
5700 if (argv
[idx_non_transitive
])
5701 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
5704 nb_cli_enqueue_change(vty
, xpath_non_transitive
, NB_OP_MODIFY
,
5707 return nb_cli_apply_changes(vty
, NULL
);
5710 DEFUN_YANG (no_set_ecommunity_lb
,
5711 no_set_ecommunity_lb_cmd
,
5712 "no set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
5715 "BGP extended community attribute\n"
5716 "Link bandwidth extended community\n"
5717 "Bandwidth value in Mbps\n"
5718 "Cumulative bandwidth of all multipaths (outbound-only)\n"
5719 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
5720 "Attribute is set as non-transitive\n")
5723 "./set-action[action='frr-bgp-route-map:set-extcommunity-lb']";
5725 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5726 return nb_cli_apply_changes(vty
, NULL
);
5729 ALIAS_YANG (no_set_ecommunity_lb
,
5730 no_set_ecommunity_lb_short_cmd
,
5731 "no set extcommunity bandwidth",
5734 "BGP extended community attribute\n"
5735 "Link bandwidth extended community\n")
5737 DEFUN_YANG (set_origin
,
5739 "set origin <egp|igp|incomplete>",
5744 "unknown heritage\n")
5747 const char *origin_type
;
5749 "./set-action[action='frr-bgp-route-map:set-origin']";
5750 char xpath_value
[XPATH_MAXLEN
];
5752 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
5753 origin_type
= "igp";
5754 else if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
5755 origin_type
= "egp";
5756 else if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
5757 origin_type
= "incomplete";
5759 vty_out(vty
, "%% Invalid match origin type\n");
5760 return CMD_WARNING_CONFIG_FAILED
;
5763 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5764 snprintf(xpath_value
, sizeof(xpath_value
),
5765 "%s/rmap-set-action/frr-bgp-route-map:origin", xpath
);
5766 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, origin_type
);
5768 return nb_cli_apply_changes(vty
, NULL
);
5771 DEFUN_YANG (no_set_origin
,
5773 "no set origin [<egp|igp|incomplete>]",
5779 "unknown heritage\n")
5782 "./set-action[action='frr-bgp-route-map:set-origin']";
5784 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5785 return nb_cli_apply_changes(vty
, NULL
);
5788 DEFUN_YANG (set_atomic_aggregate
,
5789 set_atomic_aggregate_cmd
,
5790 "set atomic-aggregate",
5792 "BGP atomic aggregate attribute\n" )
5795 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
5796 char xpath_value
[XPATH_MAXLEN
];
5798 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5799 snprintf(xpath_value
, sizeof(xpath_value
),
5800 "%s/rmap-set-action/frr-bgp-route-map:atomic-aggregate",
5802 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, NULL
);
5804 return nb_cli_apply_changes(vty
, NULL
);
5807 DEFUN_YANG (no_set_atomic_aggregate
,
5808 no_set_atomic_aggregate_cmd
,
5809 "no set atomic-aggregate",
5812 "BGP atomic aggregate attribute\n" )
5815 "./set-action[action='frr-bgp-route-map:atomic-aggregate']";
5817 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5818 return nb_cli_apply_changes(vty
, NULL
);
5821 DEFUN_YANG (set_aggregator_as
,
5822 set_aggregator_as_cmd
,
5823 "set aggregator as (1-4294967295) A.B.C.D",
5825 "BGP aggregator attribute\n"
5826 "AS number of aggregator\n"
5828 "IP address of aggregator\n")
5832 char xpath_asn
[XPATH_MAXLEN
];
5833 char xpath_addr
[XPATH_MAXLEN
];
5835 "./set-action[action='frr-bgp-route-map:aggregator']";
5837 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5840 xpath_asn
, sizeof(xpath_asn
),
5841 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-asn",
5843 nb_cli_enqueue_change(vty
, xpath_asn
, NB_OP_MODIFY
,
5844 argv
[idx_number
]->arg
);
5847 xpath_addr
, sizeof(xpath_addr
),
5848 "%s/rmap-set-action/frr-bgp-route-map:aggregator/aggregator-address",
5850 nb_cli_enqueue_change(vty
, xpath_addr
, NB_OP_MODIFY
,
5851 argv
[idx_ipv4
]->arg
);
5853 return nb_cli_apply_changes(vty
, NULL
);
5856 DEFUN_YANG (no_set_aggregator_as
,
5857 no_set_aggregator_as_cmd
,
5858 "no set aggregator as [(1-4294967295) A.B.C.D]",
5861 "BGP aggregator attribute\n"
5862 "AS number of aggregator\n"
5864 "IP address of aggregator\n")
5867 "./set-action[action='frr-bgp-route-map:aggregator']";
5869 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5870 return nb_cli_apply_changes(vty
, NULL
);
5873 DEFUN_YANG (match_ipv6_next_hop
,
5874 match_ipv6_next_hop_cmd
,
5875 "match ipv6 next-hop X:X::X:X",
5878 "Match IPv6 next-hop address of route\n"
5879 "IPv6 address of next hop\n")
5882 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
5883 char xpath_value
[XPATH_MAXLEN
];
5885 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5886 snprintf(xpath_value
, sizeof(xpath_value
),
5887 "%s/rmap-match-condition/frr-bgp-route-map:ipv6-address",
5889 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[3]->arg
);
5891 return nb_cli_apply_changes(vty
, NULL
);
5894 DEFUN_YANG (no_match_ipv6_next_hop
,
5895 no_match_ipv6_next_hop_cmd
,
5896 "no match ipv6 next-hop X:X::X:X",
5900 "Match IPv6 next-hop address of route\n"
5901 "IPv6 address of next hop\n")
5904 "./match-condition[condition='frr-bgp-route-map:ipv6-nexthop']";
5906 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5907 return nb_cli_apply_changes(vty
, NULL
);
5910 DEFPY_YANG (match_ipv4_next_hop
,
5911 match_ipv4_next_hop_cmd
,
5912 "match ip next-hop address A.B.C.D",
5915 "Match IP next-hop address of route\n"
5917 "IP address of next-hop\n")
5920 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
5921 char xpath_value
[XPATH_MAXLEN
];
5923 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5924 snprintf(xpath_value
, sizeof(xpath_value
),
5925 "%s/rmap-match-condition/frr-bgp-route-map:ipv4-address",
5927 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, argv
[4]->arg
);
5929 return nb_cli_apply_changes(vty
, NULL
);
5932 DEFPY_YANG (no_match_ipv4_next_hop
,
5933 no_match_ipv4_next_hop_cmd
,
5934 "no match ip next-hop address [A.B.C.D]",
5938 "Match IP next-hop address of route\n"
5940 "IP address of next-hop\n")
5943 "./match-condition[condition='frr-bgp-route-map:ipv4-nexthop']";
5945 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5946 return nb_cli_apply_changes(vty
, NULL
);
5949 DEFUN_YANG (set_ipv6_nexthop_peer
,
5950 set_ipv6_nexthop_peer_cmd
,
5951 "set ipv6 next-hop peer-address",
5954 "Next hop address\n"
5955 "Use peer address (for BGP only)\n")
5958 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
5959 char xpath_value
[XPATH_MAXLEN
];
5961 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5962 snprintf(xpath_value
, sizeof(xpath_value
),
5963 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
5964 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
5966 return nb_cli_apply_changes(vty
, NULL
);
5969 DEFUN_YANG (no_set_ipv6_nexthop_peer
,
5970 no_set_ipv6_nexthop_peer_cmd
,
5971 "no set ipv6 next-hop peer-address",
5975 "IPv6 next-hop address\n"
5976 "Use peer address (for BGP only)\n")
5979 "./set-action[action='frr-bgp-route-map:ipv6-peer-address']";
5981 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
5982 return nb_cli_apply_changes(vty
, NULL
);
5985 DEFUN_YANG (set_ipv6_nexthop_prefer_global
,
5986 set_ipv6_nexthop_prefer_global_cmd
,
5987 "set ipv6 next-hop prefer-global",
5990 "IPv6 next-hop address\n"
5991 "Prefer global over link-local if both exist\n")
5994 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
5995 char xpath_value
[XPATH_MAXLEN
];
5997 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
5998 snprintf(xpath_value
, sizeof(xpath_value
),
5999 "%s/rmap-set-action/frr-bgp-route-map:preference", xpath
);
6000 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
, "true");
6002 return nb_cli_apply_changes(vty
, NULL
);
6005 DEFUN_YANG (no_set_ipv6_nexthop_prefer_global
,
6006 no_set_ipv6_nexthop_prefer_global_cmd
,
6007 "no set ipv6 next-hop prefer-global",
6011 "IPv6 next-hop address\n"
6012 "Prefer global over link-local if both exist\n")
6015 "./set-action[action='frr-bgp-route-map:ipv6-prefer-global']";
6017 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6018 return nb_cli_apply_changes(vty
, NULL
);
6021 DEFUN_YANG (set_ipv6_nexthop_global
,
6022 set_ipv6_nexthop_global_cmd
,
6023 "set ipv6 next-hop global X:X::X:X",
6026 "IPv6 next-hop address\n"
6027 "IPv6 global address\n"
6028 "IPv6 address of next hop\n")
6032 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6033 char xpath_value
[XPATH_MAXLEN
];
6035 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6036 snprintf(xpath_value
, sizeof(xpath_value
),
6037 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address", xpath
);
6038 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6039 argv
[idx_ipv6
]->arg
);
6041 return nb_cli_apply_changes(vty
, NULL
);
6044 DEFUN_YANG (no_set_ipv6_nexthop_global
,
6045 no_set_ipv6_nexthop_global_cmd
,
6046 "no set ipv6 next-hop global X:X::X:X",
6050 "IPv6 next-hop address\n"
6051 "IPv6 global address\n"
6052 "IPv6 address of next hop\n")
6055 "./set-action[action='frr-bgp-route-map:ipv6-nexthop-global']";
6057 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6058 return nb_cli_apply_changes(vty
, NULL
);
6061 #ifdef KEEP_OLD_VPN_COMMANDS
6062 DEFUN_YANG (set_vpn_nexthop
,
6063 set_vpn_nexthop_cmd
,
6064 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6066 "VPNv4 information\n"
6067 "VPN next-hop address\n"
6068 "IP address of next hop\n"
6069 "VPNv6 information\n"
6070 "VPN next-hop address\n"
6071 "IPv6 address of next hop\n")
6076 char xpath_value
[XPATH_MAXLEN
];
6078 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6079 if (afi
== AFI_IP
) {
6081 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6083 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6085 xpath_value
, sizeof(xpath_value
),
6086 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6090 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6092 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6094 xpath_value
, sizeof(xpath_value
),
6095 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6099 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6102 return nb_cli_apply_changes(vty
, NULL
);
6108 DEFUN_YANG (no_set_vpn_nexthop
,
6109 no_set_vpn_nexthop_cmd
,
6110 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
6113 "VPNv4 information\n"
6114 "VPN next-hop address\n"
6115 "IP address of next hop\n"
6116 "VPNv6 information\n"
6117 "VPN next-hop address\n"
6118 "IPv6 address of next hop\n")
6123 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
6124 if (afi
== AFI_IP
) {
6126 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6127 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6130 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6131 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6133 return nb_cli_apply_changes(vty
, NULL
);
6137 #endif /* KEEP_OLD_VPN_COMMANDS */
6139 DEFUN_YANG (set_ipx_vpn_nexthop
,
6140 set_ipx_vpn_nexthop_cmd
,
6141 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
6143 "IPv4 information\n"
6144 "IPv6 information\n"
6146 "VPN next-hop address\n"
6147 "IP address of next hop\n"
6148 "IPv6 address of next hop\n")
6153 char xpath_value
[XPATH_MAXLEN
];
6155 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6156 if (afi
== AFI_IP
) {
6158 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6160 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6162 xpath_value
, sizeof(xpath_value
),
6163 "%s/rmap-set-action/frr-bgp-route-map:ipv4-address",
6167 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6169 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6171 xpath_value
, sizeof(xpath_value
),
6172 "%s/rmap-set-action/frr-bgp-route-map:ipv6-address",
6175 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6177 return nb_cli_apply_changes(vty
, NULL
);
6182 DEFUN_YANG (no_set_ipx_vpn_nexthop
,
6183 no_set_ipx_vpn_nexthop_cmd
,
6184 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
6187 "IPv4 information\n"
6188 "IPv6 information\n"
6190 "VPN next-hop address\n"
6191 "IP address of next hop\n"
6192 "IPv6 address of next hop\n")
6197 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
6198 if (afi
== AFI_IP
) {
6200 "./set-action[action='frr-bgp-route-map:ipv4-vpn-address']";
6201 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6204 "./set-action[action='frr-bgp-route-map:ipv6-vpn-address']";
6205 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6207 return nb_cli_apply_changes(vty
, NULL
);
6212 DEFUN_YANG (set_originator_id
,
6213 set_originator_id_cmd
,
6214 "set originator-id A.B.C.D",
6216 "BGP originator ID attribute\n"
6217 "IP address of originator\n")
6221 "./set-action[action='frr-bgp-route-map:originator-id']";
6222 char xpath_value
[XPATH_MAXLEN
];
6224 nb_cli_enqueue_change(vty
, xpath
, NB_OP_CREATE
, NULL
);
6225 snprintf(xpath_value
, sizeof(xpath_value
),
6226 "%s/rmap-set-action/frr-bgp-route-map:originator-id", xpath
);
6227 nb_cli_enqueue_change(vty
, xpath_value
, NB_OP_MODIFY
,
6228 argv
[idx_ipv4
]->arg
);
6230 return nb_cli_apply_changes(vty
, NULL
);
6233 DEFUN_YANG (no_set_originator_id
,
6234 no_set_originator_id_cmd
,
6235 "no set originator-id [A.B.C.D]",
6238 "BGP originator ID attribute\n"
6239 "IP address of originator\n")
6242 "./set-action[action='frr-bgp-route-map:originator-id']";
6244 nb_cli_enqueue_change(vty
, xpath
, NB_OP_DESTROY
, NULL
);
6245 return nb_cli_apply_changes(vty
, NULL
);
6248 /* Initialization of route map. */
6249 void bgp_route_map_init(void)
6253 route_map_add_hook(bgp_route_map_add
);
6254 route_map_delete_hook(bgp_route_map_delete
);
6255 route_map_event_hook(bgp_route_map_event
);
6257 route_map_match_interface_hook(generic_match_add
);
6258 route_map_no_match_interface_hook(generic_match_delete
);
6260 route_map_match_ip_address_hook(generic_match_add
);
6261 route_map_no_match_ip_address_hook(generic_match_delete
);
6263 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
6264 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
6266 route_map_match_ip_next_hop_hook(generic_match_add
);
6267 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
6269 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
6270 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
6272 route_map_match_ip_next_hop_type_hook(generic_match_add
);
6273 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
6275 route_map_match_ipv6_address_hook(generic_match_add
);
6276 route_map_no_match_ipv6_address_hook(generic_match_delete
);
6278 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
6279 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
6281 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
6282 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
6284 route_map_match_metric_hook(generic_match_add
);
6285 route_map_no_match_metric_hook(generic_match_delete
);
6287 route_map_match_tag_hook(generic_match_add
);
6288 route_map_no_match_tag_hook(generic_match_delete
);
6290 route_map_set_srte_color_hook(generic_set_add
);
6291 route_map_no_set_srte_color_hook(generic_set_delete
);
6293 route_map_set_ip_nexthop_hook(generic_set_add
);
6294 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
6296 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
6297 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
6299 route_map_set_metric_hook(generic_set_add
);
6300 route_map_no_set_metric_hook(generic_set_delete
);
6302 route_map_set_tag_hook(generic_set_add
);
6303 route_map_no_set_tag_hook(generic_set_delete
);
6305 route_map_install_match(&route_match_peer_cmd
);
6306 route_map_install_match(&route_match_local_pref_cmd
);
6307 #ifdef HAVE_SCRIPTING
6308 route_map_install_match(&route_match_script_cmd
);
6310 route_map_install_match(&route_match_ip_address_cmd
);
6311 route_map_install_match(&route_match_ip_next_hop_cmd
);
6312 route_map_install_match(&route_match_ip_route_source_cmd
);
6313 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
6314 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
6315 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
6316 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
6317 route_map_install_match(&route_match_aspath_cmd
);
6318 route_map_install_match(&route_match_community_cmd
);
6319 route_map_install_match(&route_match_lcommunity_cmd
);
6320 route_map_install_match(&route_match_ecommunity_cmd
);
6321 route_map_install_match(&route_match_local_pref_cmd
);
6322 route_map_install_match(&route_match_metric_cmd
);
6323 route_map_install_match(&route_match_origin_cmd
);
6324 route_map_install_match(&route_match_probability_cmd
);
6325 route_map_install_match(&route_match_interface_cmd
);
6326 route_map_install_match(&route_match_tag_cmd
);
6327 route_map_install_match(&route_match_mac_address_cmd
);
6328 route_map_install_match(&route_match_evpn_vni_cmd
);
6329 route_map_install_match(&route_match_evpn_route_type_cmd
);
6330 route_map_install_match(&route_match_evpn_rd_cmd
);
6331 route_map_install_match(&route_match_evpn_default_route_cmd
);
6332 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
6334 route_map_install_set(&route_set_evpn_gateway_ip_ipv4_cmd
);
6335 route_map_install_set(&route_set_evpn_gateway_ip_ipv6_cmd
);
6336 route_map_install_set(&route_set_table_id_cmd
);
6337 route_map_install_set(&route_set_srte_color_cmd
);
6338 route_map_install_set(&route_set_ip_nexthop_cmd
);
6339 route_map_install_set(&route_set_local_pref_cmd
);
6340 route_map_install_set(&route_set_weight_cmd
);
6341 route_map_install_set(&route_set_label_index_cmd
);
6342 route_map_install_set(&route_set_metric_cmd
);
6343 route_map_install_set(&route_set_distance_cmd
);
6344 route_map_install_set(&route_set_aspath_prepend_cmd
);
6345 route_map_install_set(&route_set_aspath_exclude_cmd
);
6346 route_map_install_set(&route_set_origin_cmd
);
6347 route_map_install_set(&route_set_atomic_aggregate_cmd
);
6348 route_map_install_set(&route_set_aggregator_as_cmd
);
6349 route_map_install_set(&route_set_community_cmd
);
6350 route_map_install_set(&route_set_community_delete_cmd
);
6351 route_map_install_set(&route_set_lcommunity_cmd
);
6352 route_map_install_set(&route_set_lcommunity_delete_cmd
);
6353 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
6354 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
6355 route_map_install_set(&route_set_originator_id_cmd
);
6356 route_map_install_set(&route_set_ecommunity_rt_cmd
);
6357 route_map_install_set(&route_set_ecommunity_soo_cmd
);
6358 route_map_install_set(&route_set_ecommunity_lb_cmd
);
6359 route_map_install_set(&route_set_tag_cmd
);
6360 route_map_install_set(&route_set_label_index_cmd
);
6362 install_element(RMAP_NODE
, &match_peer_cmd
);
6363 install_element(RMAP_NODE
, &match_peer_local_cmd
);
6364 install_element(RMAP_NODE
, &no_match_peer_cmd
);
6365 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
6366 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
6367 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
6368 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
6369 install_element(RMAP_NODE
, &match_mac_address_cmd
);
6370 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
6371 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
6372 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
6373 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
6374 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
6375 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
6376 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
6377 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
6378 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
6379 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv4_cmd
);
6380 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv4_cmd
);
6381 install_element(RMAP_NODE
, &set_evpn_gw_ip_ipv6_cmd
);
6382 install_element(RMAP_NODE
, &no_set_evpn_gw_ip_ipv6_cmd
);
6383 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
6384 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
6386 install_element(RMAP_NODE
, &match_aspath_cmd
);
6387 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
6388 install_element(RMAP_NODE
, &match_local_pref_cmd
);
6389 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
6390 install_element(RMAP_NODE
, &match_community_cmd
);
6391 install_element(RMAP_NODE
, &no_match_community_cmd
);
6392 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
6393 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
6394 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
6395 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
6396 install_element(RMAP_NODE
, &match_origin_cmd
);
6397 install_element(RMAP_NODE
, &no_match_origin_cmd
);
6398 install_element(RMAP_NODE
, &match_probability_cmd
);
6399 install_element(RMAP_NODE
, &no_match_probability_cmd
);
6401 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
6402 install_element(RMAP_NODE
, &set_table_id_cmd
);
6403 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
6404 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
6405 install_element(RMAP_NODE
, &set_local_pref_cmd
);
6406 install_element(RMAP_NODE
, &set_distance_cmd
);
6407 install_element(RMAP_NODE
, &no_set_distance_cmd
);
6408 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
6409 install_element(RMAP_NODE
, &set_weight_cmd
);
6410 install_element(RMAP_NODE
, &set_label_index_cmd
);
6411 install_element(RMAP_NODE
, &no_set_weight_cmd
);
6412 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
6413 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
6414 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
6415 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
6416 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
6417 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
6418 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
6419 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
6420 install_element(RMAP_NODE
, &set_origin_cmd
);
6421 install_element(RMAP_NODE
, &no_set_origin_cmd
);
6422 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
6423 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
6424 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
6425 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
6426 install_element(RMAP_NODE
, &set_community_cmd
);
6427 install_element(RMAP_NODE
, &set_community_none_cmd
);
6428 install_element(RMAP_NODE
, &no_set_community_cmd
);
6429 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
6430 install_element(RMAP_NODE
, &set_community_delete_cmd
);
6431 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
6432 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
6433 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
6434 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
6435 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
6436 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
6437 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
6438 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
6439 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
6440 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
6441 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
6442 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
6443 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
6444 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
6445 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
6446 install_element(RMAP_NODE
, &set_ecommunity_lb_cmd
);
6447 install_element(RMAP_NODE
, &no_set_ecommunity_lb_cmd
);
6448 install_element(RMAP_NODE
, &no_set_ecommunity_lb_short_cmd
);
6449 #ifdef KEEP_OLD_VPN_COMMANDS
6450 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
6451 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
6452 #endif /* KEEP_OLD_VPN_COMMANDS */
6453 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
6454 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
6455 install_element(RMAP_NODE
, &set_originator_id_cmd
);
6456 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
6458 route_map_install_match(&route_match_ipv6_address_cmd
);
6459 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
6460 route_map_install_match(&route_match_ipv4_next_hop_cmd
);
6461 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
6462 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
6463 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
6464 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
6465 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
6466 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
6468 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
6469 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
6470 install_element(RMAP_NODE
, &match_ipv4_next_hop_cmd
);
6471 install_element(RMAP_NODE
, &no_match_ipv4_next_hop_cmd
);
6472 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
6473 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
6474 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
6475 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
6476 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
6477 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
6478 #ifdef HAVE_SCRIPTING
6479 install_element(RMAP_NODE
, &match_script_cmd
);
6483 void bgp_route_map_terminate(void)
6485 /* ToDo: Cleanup all the used memory */