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"
44 #include "bgpd/bgpd.h"
45 #include "bgpd/bgp_table.h"
46 #include "bgpd/bgp_attr.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_packet.h"
49 #include "bgpd/bgp_route.h"
50 #include "bgpd/bgp_zebra.h"
51 #include "bgpd/bgp_regex.h"
52 #include "bgpd/bgp_community.h"
53 #include "bgpd/bgp_clist.h"
54 #include "bgpd/bgp_filter.h"
55 #include "bgpd/bgp_mplsvpn.h"
56 #include "bgpd/bgp_ecommunity.h"
57 #include "bgpd/bgp_lcommunity.h"
58 #include "bgpd/bgp_vty.h"
59 #include "bgpd/bgp_debug.h"
60 #include "bgpd/bgp_evpn.h"
61 #include "bgpd/bgp_evpn_private.h"
62 #include "bgpd/bgp_evpn_vty.h"
63 #include "bgpd/bgp_mplsvpn.h"
64 #include "bgpd/bgp_pbr.h"
65 #include "bgpd/bgp_flowspec_util.h"
66 #include "bgpd/bgp_encap_types.h"
67 #include "bgpd/bgp_mpath.h"
70 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
73 #ifndef VTYSH_EXTRACT_PL
74 #include "bgpd/bgp_routemap_clippy.c"
77 /* Memo of route-map commands.
86 ip route-source : Done
90 ipv6 route-source: (This will not be implemented by bgpd)
91 ipv6 prefix-list : Done
92 length : (This will not be implemented by bgpd)
94 route-type : (This will not be implemented by bgpd)
96 local-preference : Done
98 set as-path prepend : Done
100 automatic-tag : (This will not be implemented by bgpd)
102 large-community : Done
103 large-comm-list : Done
106 default : (This will not be implemented by bgpd)
107 interface : (This will not be implemented by bgpd)
108 ip default : (This will not be implemented by bgpd)
110 ip precedence : (This will not be implemented by bgpd)
111 ip tos : (This will not be implemented by bgpd)
112 level : (This will not be implemented by bgpd)
113 local-preference : Done
115 metric-type : Not yet
123 set ipv6 next-hop global: Done
124 set ipv6 next-hop prefer-global: Done
125 set ipv6 next-hop local : Done
126 set as-path exclude : Done
130 /* generic value manipulation to be shared in multiple rules */
132 #define RMAP_VALUE_SET 0
133 #define RMAP_VALUE_ADD 1
134 #define RMAP_VALUE_SUB 2
142 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
144 if (rv
->variable
== 0 && value
== rv
->value
)
150 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
155 switch (rv
->variable
) {
164 switch (rv
->action
) {
166 if (current
> UINT32_MAX
- value
)
168 return current
+ value
;
170 if (current
<= value
)
172 return current
- value
;
178 static void *route_value_compile(const char *arg
)
180 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
181 unsigned long larg
= 0;
183 struct rmap_value
*rv
;
186 action
= RMAP_VALUE_ADD
;
188 } else if (arg
[0] == '-') {
189 action
= RMAP_VALUE_SUB
;
193 if (all_digit(arg
)) {
195 larg
= strtoul(arg
, &endptr
, 10);
196 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
199 if (strcmp(arg
, "rtt") == 0)
205 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
213 static void route_value_free(void *rule
)
215 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
218 /* generic as path object to be shared in multiple rules */
220 static void *route_aspath_compile(const char *arg
)
222 struct aspath
*aspath
;
224 aspath
= aspath_str2aspath(arg
);
230 static void route_aspath_free(void *rule
)
232 struct aspath
*aspath
= rule
;
236 struct bgp_match_peer_compiled
{
241 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
243 /* Compares the peer specified in the 'match peer' clause with the peer
244 received in bgp_path_info->peer. If it is the same, or if the peer structure
245 received is a peer_group containing it, returns RMAP_MATCH. */
246 static enum route_map_cmd_result_t
247 route_match_peer(void *rule
, const struct prefix
*prefix
,
248 route_map_object_t type
, void *object
)
250 struct bgp_match_peer_compiled
*pc
;
252 union sockunion su_def
= {
253 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
254 struct peer_group
*group
;
256 struct listnode
*node
, *nnode
;
258 if (type
== RMAP_BGP
) {
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
,
282 PEER_RMAP_TYPE_REDISTRIBUTE
)
283 || CHECK_FLAG(peer
->rmap_type
,
284 PEER_RMAP_TYPE_AGGREGATE
)
285 || CHECK_FLAG(peer
->rmap_type
,
286 PEER_RMAP_TYPE_DEFAULT
))
293 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
294 if (sockunion_same(su
, &peer
->su
))
300 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
302 if (sockunion_same(su
, &peer
->su
))
311 static void *route_match_peer_compile(const char *arg
)
313 struct bgp_match_peer_compiled
*pc
;
316 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
317 sizeof(struct bgp_match_peer_compiled
));
319 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
321 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
328 /* Free route map's compiled `ip address' value. */
329 static void route_match_peer_free(void *rule
)
331 struct bgp_match_peer_compiled
*pc
= rule
;
333 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
335 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
338 /* Route map commands for ip address matching. */
339 static const struct route_map_rule_cmd route_match_peer_cmd
= {
342 route_match_peer_compile
,
343 route_match_peer_free
346 #if defined(HAVE_LUA)
347 static enum route_map_cmd_result_t
348 route_match_command(void *rule
, const struct prefix
*prefix
,
349 route_map_object_t type
, void *object
)
351 int status
= RMAP_NOMATCH
;
352 u_int32_t locpref
= 0;
353 u_int32_t newlocpref
= 0;
354 enum lua_rm_status lrm_status
;
355 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
356 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
362 * Setup the prefix information to pass in
364 lua_setup_prefix_table(L
, prefix
);
366 zlog_debug("Set up prefix table");
368 * Setup the bgp_path_info information
371 lua_pushinteger(L
, path
->attr
->med
);
372 lua_setfield(L
, -2, "metric");
373 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
374 lua_setfield(L
, -2, "ifindex");
375 lua_pushstring(L
, path
->attr
->aspath
->str
);
376 lua_setfield(L
, -2, "aspath");
377 lua_pushinteger(L
, path
->attr
->local_pref
);
378 lua_setfield(L
, -2, "localpref");
379 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
380 lua_setglobal(L
, "nexthop");
382 zlog_debug("Set up nexthop information");
386 lrm_status
= lua_run_rm_rule(L
, rule
);
387 switch (lrm_status
) {
389 zlog_debug("RM_FAILURE");
392 zlog_debug("RM_NOMATCH");
394 case LUA_RM_MATCH_AND_CHANGE
:
395 zlog_debug("MATCH AND CHANGE");
396 lua_getglobal(L
, "nexthop");
397 path
->attr
->med
= get_integer(L
, "metric");
399 * This needs to be abstraced with the set function
401 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
402 locpref
= path
->attr
->local_pref
;
403 newlocpref
= get_integer(L
, "localpref");
404 if (newlocpref
!= locpref
) {
405 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
406 path
->attr
->local_pref
= newlocpref
;
411 zlog_debug("MATCH ONLY");
419 static void *route_match_command_compile(const char *arg
)
423 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
428 route_match_command_free(void *rule
)
430 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
433 static const struct route_map_rule_cmd route_match_command_cmd
= {
436 route_match_command_compile
,
437 route_match_command_free
441 /* `match ip address IP_ACCESS_LIST' */
443 /* Match function should return 1 if match is success else return
445 static enum route_map_cmd_result_t
446 route_match_ip_address(void *rule
, const struct prefix
*prefix
,
447 route_map_object_t type
, void *object
)
449 struct access_list
*alist
;
451 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
452 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
456 return (access_list_apply(alist
, prefix
) == FILTER_DENY
463 /* Route map `ip address' match statement. `arg' should be
465 static void *route_match_ip_address_compile(const char *arg
)
467 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
470 /* Free route map's compiled `ip address' value. */
471 static void route_match_ip_address_free(void *rule
)
473 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
476 /* Route map commands for ip address matching. */
477 static const struct route_map_rule_cmd route_match_ip_address_cmd
= {
479 route_match_ip_address
,
480 route_match_ip_address_compile
,
481 route_match_ip_address_free
484 /* `match ip next-hop IP_ADDRESS' */
486 /* Match function return 1 if match is success else return zero. */
487 static enum route_map_cmd_result_t
488 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
,
489 route_map_object_t type
, void *object
)
491 struct access_list
*alist
;
492 struct bgp_path_info
*path
;
493 struct prefix_ipv4 p
;
495 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
498 p
.prefix
= path
->attr
->nexthop
;
499 p
.prefixlen
= IPV4_MAX_BITLEN
;
501 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
505 return (access_list_apply(alist
, &p
) == FILTER_DENY
512 /* Route map `ip next-hop' match statement. `arg' is
514 static void *route_match_ip_next_hop_compile(const char *arg
)
516 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
519 /* Free route map's compiled `ip address' value. */
520 static void route_match_ip_next_hop_free(void *rule
)
522 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
525 /* Route map commands for ip next-hop matching. */
526 static const struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
528 route_match_ip_next_hop
,
529 route_match_ip_next_hop_compile
,
530 route_match_ip_next_hop_free
533 /* `match ip route-source ACCESS-LIST' */
535 /* Match function return 1 if match is success else return zero. */
536 static enum route_map_cmd_result_t
537 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
,
538 route_map_object_t type
, void *object
)
540 struct access_list
*alist
;
541 struct bgp_path_info
*path
;
543 struct prefix_ipv4 p
;
545 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
549 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
553 p
.prefix
= peer
->su
.sin
.sin_addr
;
554 p
.prefixlen
= IPV4_MAX_BITLEN
;
556 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
560 return (access_list_apply(alist
, &p
) == FILTER_DENY
567 /* Route map `ip route-source' match statement. `arg' is
569 static void *route_match_ip_route_source_compile(const char *arg
)
571 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
574 /* Free route map's compiled `ip address' value. */
575 static void route_match_ip_route_source_free(void *rule
)
577 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
580 /* Route map commands for ip route-source matching. */
581 static const struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
583 route_match_ip_route_source
,
584 route_match_ip_route_source_compile
,
585 route_match_ip_route_source_free
588 static enum route_map_cmd_result_t
589 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
590 const struct prefix
*p
)
593 struct bgp_pbr_entry_main api
;
595 memset(&api
, 0, sizeof(api
));
597 /* extract match from flowspec entries */
598 ret
= bgp_flowspec_match_rules_fill(
599 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
600 p
->u
.prefix_flowspec
.prefixlen
, &api
);
603 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
604 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
605 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
607 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
610 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
611 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
612 if (family2afi((&api
.src_prefix
)->family
) != afi
)
614 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
621 static enum route_map_cmd_result_t
622 route_match_address_prefix_list(void *rule
, afi_t afi
,
623 const struct prefix
*prefix
,
624 route_map_object_t type
, void *object
)
626 struct prefix_list
*plist
;
628 if (type
!= RMAP_BGP
)
631 plist
= prefix_list_lookup(afi
, (char *)rule
);
635 if (prefix
->family
== AF_FLOWSPEC
)
636 return route_match_prefix_list_flowspec(afi
, plist
,
638 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
642 static enum route_map_cmd_result_t
643 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
644 route_map_object_t type
, void *object
)
646 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, type
,
650 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
652 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
655 static void route_match_ip_address_prefix_list_free(void *rule
)
657 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
660 static const struct route_map_rule_cmd
661 route_match_ip_address_prefix_list_cmd
= {
662 "ip address prefix-list",
663 route_match_ip_address_prefix_list
,
664 route_match_ip_address_prefix_list_compile
,
665 route_match_ip_address_prefix_list_free
668 /* `match ip next-hop prefix-list PREFIX_LIST' */
670 static enum route_map_cmd_result_t
671 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
672 route_map_object_t type
, void *object
)
674 struct prefix_list
*plist
;
675 struct bgp_path_info
*path
;
676 struct prefix_ipv4 p
;
678 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
681 p
.prefix
= path
->attr
->nexthop
;
682 p
.prefixlen
= IPV4_MAX_BITLEN
;
684 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
688 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
695 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
697 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
700 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
702 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
705 static const struct route_map_rule_cmd
706 route_match_ip_next_hop_prefix_list_cmd
= {
707 "ip next-hop prefix-list",
708 route_match_ip_next_hop_prefix_list
,
709 route_match_ip_next_hop_prefix_list_compile
,
710 route_match_ip_next_hop_prefix_list_free
713 /* `match ip next-hop type <blackhole>' */
715 static enum route_map_cmd_result_t
716 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
717 route_map_object_t type
, void *object
)
719 struct bgp_path_info
*path
;
721 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
722 path
= (struct bgp_path_info
*)object
;
726 /* If nexthop interface's index can't be resolved and nexthop is
727 set to any address then mark it as type `blackhole`.
728 This logic works for matching kernel/static routes like:
729 `ip route add blackhole 10.0.0.1`. */
730 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
731 && !path
->attr
->nh_ifindex
)
737 static void *route_match_ip_next_hop_type_compile(const char *arg
)
739 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
742 static void route_match_ip_next_hop_type_free(void *rule
)
744 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
747 static const struct route_map_rule_cmd
748 route_match_ip_next_hop_type_cmd
= {
750 route_match_ip_next_hop_type
,
751 route_match_ip_next_hop_type_compile
,
752 route_match_ip_next_hop_type_free
755 /* `match ip route-source prefix-list PREFIX_LIST' */
757 static enum route_map_cmd_result_t
758 route_match_ip_route_source_prefix_list(void *rule
,
759 const struct prefix
*prefix
,
760 route_map_object_t type
, void *object
)
762 struct prefix_list
*plist
;
763 struct bgp_path_info
*path
;
765 struct prefix_ipv4 p
;
767 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
771 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
775 p
.prefix
= peer
->su
.sin
.sin_addr
;
776 p
.prefixlen
= IPV4_MAX_BITLEN
;
778 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
782 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
789 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
791 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
794 static void route_match_ip_route_source_prefix_list_free(void *rule
)
796 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
799 static const struct route_map_rule_cmd
800 route_match_ip_route_source_prefix_list_cmd
= {
801 "ip route-source prefix-list",
802 route_match_ip_route_source_prefix_list
,
803 route_match_ip_route_source_prefix_list_compile
,
804 route_match_ip_route_source_prefix_list_free
807 /* `match evpn default-route' */
809 /* Match function should return 1 if match is success else 0 */
810 static enum route_map_cmd_result_t
811 route_match_evpn_default_route(void *rule
, const struct prefix
*p
,
812 route_map_object_t type
, void *object
)
814 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
820 /* Route map commands for default-route matching. */
821 static const struct route_map_rule_cmd
822 route_match_evpn_default_route_cmd
= {
823 "evpn default-route",
824 route_match_evpn_default_route
,
829 /* `match mac address MAC_ACCESS_LIST' */
831 /* Match function should return 1 if match is success else return
833 static enum route_map_cmd_result_t
834 route_match_mac_address(void *rule
, const struct prefix
*prefix
,
835 route_map_object_t type
, void *object
)
837 struct access_list
*alist
;
840 if (type
== RMAP_BGP
) {
841 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
845 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
848 p
.family
= AF_ETHERNET
;
849 p
.prefixlen
= ETH_ALEN
* 8;
850 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
852 return (access_list_apply(alist
, &p
) == FILTER_DENY
860 /* Route map `mac address' match statement. `arg' should be
862 static void *route_match_mac_address_compile(const char *arg
)
864 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
867 /* Free route map's compiled `ip address' value. */
868 static void route_match_mac_address_free(void *rule
)
870 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
873 /* Route map commands for mac address matching. */
874 static const struct route_map_rule_cmd route_match_mac_address_cmd
= {
876 route_match_mac_address
,
877 route_match_mac_address_compile
,
878 route_match_mac_address_free
882 * Match function returns:
883 * ...RMAP_MATCH if match is found.
884 * ...RMAP_NOMATCH if match is not found.
885 * ...RMAP_NOOP to ignore this match check.
887 static enum route_map_cmd_result_t
888 route_match_vni(void *rule
, const struct prefix
*prefix
,
889 route_map_object_t type
, void *object
)
892 unsigned int label_cnt
= 0;
893 struct bgp_path_info
*path
= NULL
;
894 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
896 if (type
== RMAP_BGP
) {
897 vni
= *((vni_t
*)rule
);
898 path
= (struct bgp_path_info
*)object
;
901 * This rmap filter is valid for vxlan tunnel type only.
902 * For any other tunnel type, return noop to ignore
905 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
909 * Apply filter to type 1, 2, 5 routes only.
910 * Other route types do not have vni label.
912 if (evp
&& (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
&&
913 evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
&&
914 evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
917 if (path
->extra
== NULL
)
920 for ( ; label_cnt
< BGP_MAX_LABELS
&&
921 label_cnt
< path
->extra
->num_labels
; label_cnt
++) {
922 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
930 /* Route map `vni' match statement. */
931 static void *route_match_vni_compile(const char *arg
)
936 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
938 *vni
= strtoul(arg
, &end
, 10);
940 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
947 /* Free route map's compiled `vni' value. */
948 static void route_match_vni_free(void *rule
)
950 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
953 /* Route map commands for vni matching. */
954 static const struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
957 route_match_vni_compile
,
961 /* `match evpn route-type' */
963 /* Match function should return 1 if match is success else return
965 static enum route_map_cmd_result_t
966 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
,
967 route_map_object_t type
, void *object
)
969 uint8_t route_type
= 0;
971 if (type
== RMAP_BGP
) {
972 route_type
= *((uint8_t *)rule
);
974 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
981 /* Route map `route-type' match statement. */
982 static void *route_match_evpn_route_type_compile(const char *arg
)
984 uint8_t *route_type
= NULL
;
986 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
988 if (strncmp(arg
, "ma", 2) == 0)
989 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
990 else if (strncmp(arg
, "mu", 2) == 0)
991 *route_type
= BGP_EVPN_IMET_ROUTE
;
993 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
998 /* Free route map's compiled `route-type' value. */
999 static void route_match_evpn_route_type_free(void *rule
)
1001 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1004 /* Route map commands for evpn route-type matching. */
1005 static const struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
1007 route_match_evpn_route_type
,
1008 route_match_evpn_route_type_compile
,
1009 route_match_evpn_route_type_free
1014 /* Match function should return 1 if match is success else return zero. */
1015 static enum route_map_cmd_result_t
1016 route_match_rd(void *rule
, const struct prefix
*prefix
,
1017 route_map_object_t type
, void *object
)
1019 struct prefix_rd
*prd_rule
= NULL
;
1020 const struct prefix_rd
*prd_route
= NULL
;
1021 struct bgp_path_info
*path
= NULL
;
1023 if (type
== RMAP_BGP
) {
1024 if (prefix
->family
!= AF_EVPN
)
1025 return RMAP_NOMATCH
;
1027 prd_rule
= (struct prefix_rd
*)rule
;
1028 path
= (struct bgp_path_info
*)object
;
1030 if (path
->net
== NULL
|| path
->net
->prn
== NULL
)
1031 return RMAP_NOMATCH
;
1034 (struct prefix_rd
*)bgp_node_get_prefix(path
->net
->prn
);
1035 if (memcmp(prd_route
->val
, prd_rule
->val
, ECOMMUNITY_SIZE
) == 0)
1039 return RMAP_NOMATCH
;
1042 /* Route map `rd' match statement. */
1043 static void *route_match_rd_compile(const char *arg
)
1045 struct prefix_rd
*prd
;
1048 prd
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct prefix_rd
));
1050 ret
= str2prefix_rd(arg
, prd
);
1052 XFREE(MTYPE_ROUTE_MAP_COMPILED
, prd
);
1059 /* Free route map's compiled `rd' value. */
1060 static void route_match_rd_free(void *rule
)
1062 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1065 /* Route map commands for rd matching. */
1066 static const struct route_map_rule_cmd route_match_evpn_rd_cmd
= {
1069 route_match_rd_compile
,
1073 /* Route map commands for VRF route leak with source vrf matching */
1074 static enum route_map_cmd_result_t
1075 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1076 route_map_object_t type
, void *object
)
1078 struct bgp_path_info
*path
;
1081 if (type
== RMAP_BGP
) {
1083 path
= (struct bgp_path_info
*)object
;
1085 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1086 return RMAP_NOMATCH
;
1088 if (path
->extra
== NULL
)
1089 return RMAP_NOMATCH
;
1091 if (strncmp(vrf_name
, vrf_id_to_name(
1092 path
->extra
->bgp_orig
->vrf_id
), VRF_NAMSIZ
)
1097 return RMAP_NOMATCH
;
1100 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1102 uint8_t *vrf_name
= NULL
;
1104 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1109 /* Free route map's compiled `route-type' value. */
1110 static void route_match_vrl_source_vrf_free(void *rule
)
1112 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1115 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1117 route_match_vrl_source_vrf
,
1118 route_match_vrl_source_vrf_compile
,
1119 route_match_vrl_source_vrf_free
1122 /* `match local-preference LOCAL-PREF' */
1124 /* Match function return 1 if match is success else return zero. */
1125 static enum route_map_cmd_result_t
1126 route_match_local_pref(void *rule
, const struct prefix
*prefix
,
1127 route_map_object_t type
, void *object
)
1129 uint32_t *local_pref
;
1130 struct bgp_path_info
*path
;
1132 if (type
== RMAP_BGP
) {
1136 if (path
->attr
->local_pref
== *local_pref
)
1139 return RMAP_NOMATCH
;
1141 return RMAP_NOMATCH
;
1145 * Route map `match local-preference' match statement.
1146 * `arg' is local-pref value
1148 static void *route_match_local_pref_compile(const char *arg
)
1150 uint32_t *local_pref
;
1151 char *endptr
= NULL
;
1152 unsigned long tmpval
;
1154 /* Locpref value shoud be integer. */
1155 if (!all_digit(arg
))
1159 tmpval
= strtoul(arg
, &endptr
, 10);
1160 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1163 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1165 *local_pref
= tmpval
;
1169 /* Free route map's compiled `match local-preference' value. */
1170 static void route_match_local_pref_free(void *rule
)
1172 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1175 /* Route map commands for metric matching. */
1176 static const struct route_map_rule_cmd route_match_local_pref_cmd
= {
1178 route_match_local_pref
,
1179 route_match_local_pref_compile
,
1180 route_match_local_pref_free
1183 /* `match metric METRIC' */
1185 /* Match function return 1 if match is success else return zero. */
1186 static enum route_map_cmd_result_t
1187 route_match_metric(void *rule
, const struct prefix
*prefix
,
1188 route_map_object_t type
, void *object
)
1190 struct rmap_value
*rv
;
1191 struct bgp_path_info
*path
;
1193 if (type
== RMAP_BGP
) {
1196 return route_value_match(rv
, path
->attr
->med
);
1198 return RMAP_NOMATCH
;
1201 /* Route map commands for metric matching. */
1202 static const struct route_map_rule_cmd route_match_metric_cmd
= {
1205 route_value_compile
,
1209 /* `match as-path ASPATH' */
1211 /* Match function for as-path match. I assume given object is */
1212 static enum route_map_cmd_result_t
1213 route_match_aspath(void *rule
, const struct prefix
*prefix
,
1214 route_map_object_t type
, void *object
)
1217 struct as_list
*as_list
;
1218 struct bgp_path_info
*path
;
1220 if (type
== RMAP_BGP
) {
1221 as_list
= as_list_lookup((char *)rule
);
1222 if (as_list
== NULL
)
1223 return RMAP_NOMATCH
;
1227 /* Perform match. */
1228 return ((as_list_apply(as_list
, path
->attr
->aspath
)
1233 return RMAP_NOMATCH
;
1236 /* Compile function for as-path match. */
1237 static void *route_match_aspath_compile(const char *arg
)
1239 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1242 /* Compile function for as-path match. */
1243 static void route_match_aspath_free(void *rule
)
1245 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1248 /* Route map commands for aspath matching. */
1249 static const struct route_map_rule_cmd route_match_aspath_cmd
= {
1252 route_match_aspath_compile
,
1253 route_match_aspath_free
1256 /* `match community COMMUNIY' */
1257 struct rmap_community
{
1263 /* Match function for community match. */
1264 static enum route_map_cmd_result_t
1265 route_match_community(void *rule
, const struct prefix
*prefix
,
1266 route_map_object_t type
, void *object
)
1268 struct community_list
*list
;
1269 struct bgp_path_info
*path
;
1270 struct rmap_community
*rcom
= rule
;
1272 if (type
== RMAP_BGP
) {
1276 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1278 COMMUNITY_LIST_MASTER
);
1280 return RMAP_NOMATCH
;
1283 if (community_list_exact_match(path
->attr
->community
,
1287 if (community_list_match(path
->attr
->community
, list
))
1291 return RMAP_NOMATCH
;
1294 /* Compile function for community match. */
1295 static void *route_match_community_compile(const char *arg
)
1297 struct rmap_community
*rcom
;
1301 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1303 p
= strchr(arg
, ' ');
1306 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1307 memcpy(rcom
->name
, arg
, len
);
1310 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1314 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1318 /* Compile function for community match. */
1319 static void route_match_community_free(void *rule
)
1321 struct rmap_community
*rcom
= rule
;
1323 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1324 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1328 * In routemap processing there is a need to add the
1329 * name as a rule_key in the dependency table. Routemap
1330 * lib is unaware of rule_key when exact-match clause
1331 * is in use. routemap lib uses the compiled output to
1332 * get the rule_key value.
1334 static void *route_match_get_community_key(void *rule
)
1336 struct rmap_community
*rcom
;
1343 /* Route map commands for community matching. */
1344 static const struct route_map_rule_cmd route_match_community_cmd
= {
1346 route_match_community
,
1347 route_match_community_compile
,
1348 route_match_community_free
,
1349 route_match_get_community_key
1352 /* Match function for lcommunity match. */
1353 static enum route_map_cmd_result_t
1354 route_match_lcommunity(void *rule
, const struct prefix
*prefix
,
1355 route_map_object_t type
, void *object
)
1357 struct community_list
*list
;
1358 struct bgp_path_info
*path
;
1359 struct rmap_community
*rcom
= rule
;
1361 if (type
== RMAP_BGP
) {
1364 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1366 LARGE_COMMUNITY_LIST_MASTER
);
1368 return RMAP_NOMATCH
;
1371 if (lcommunity_list_exact_match(
1372 path
->attr
->lcommunity
,
1376 if (lcommunity_list_match(
1377 path
->attr
->lcommunity
,
1382 return RMAP_NOMATCH
;
1385 /* Compile function for community match. */
1386 static void *route_match_lcommunity_compile(const char *arg
)
1388 struct rmap_community
*rcom
;
1392 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1394 p
= strchr(arg
, ' ');
1397 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1398 memcpy(rcom
->name
, arg
, len
);
1401 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1405 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1409 /* Compile function for community match. */
1410 static void route_match_lcommunity_free(void *rule
)
1412 struct rmap_community
*rcom
= rule
;
1414 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1415 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1418 /* Route map commands for community matching. */
1419 static const struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1421 route_match_lcommunity
,
1422 route_match_lcommunity_compile
,
1423 route_match_lcommunity_free
,
1424 route_match_get_community_key
1428 /* Match function for extcommunity match. */
1429 static enum route_map_cmd_result_t
1430 route_match_ecommunity(void *rule
, const struct prefix
*prefix
,
1431 route_map_object_t type
, void *object
)
1433 struct community_list
*list
;
1434 struct bgp_path_info
*path
;
1435 struct rmap_community
*rcom
= rule
;
1437 if (type
== RMAP_BGP
) {
1440 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1442 EXTCOMMUNITY_LIST_MASTER
);
1444 return RMAP_NOMATCH
;
1446 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1449 return RMAP_NOMATCH
;
1452 /* Compile function for extcommunity match. */
1453 static void *route_match_ecommunity_compile(const char *arg
)
1455 struct rmap_community
*rcom
;
1457 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1458 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1459 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1464 /* Compile function for extcommunity match. */
1465 static void route_match_ecommunity_free(void *rule
)
1467 struct rmap_community
*rcom
= rule
;
1469 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1470 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1473 /* Route map commands for community matching. */
1474 static const struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1476 route_match_ecommunity
,
1477 route_match_ecommunity_compile
,
1478 route_match_ecommunity_free
1481 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1482 and `address-family vpnv4'. */
1484 /* `match origin' */
1485 static enum route_map_cmd_result_t
1486 route_match_origin(void *rule
, const struct prefix
*prefix
,
1487 route_map_object_t type
, void *object
)
1490 struct bgp_path_info
*path
;
1492 if (type
== RMAP_BGP
) {
1496 if (path
->attr
->origin
== *origin
)
1500 return RMAP_NOMATCH
;
1503 static void *route_match_origin_compile(const char *arg
)
1507 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1509 if (strcmp(arg
, "igp") == 0)
1511 else if (strcmp(arg
, "egp") == 0)
1519 /* Free route map's compiled `ip address' value. */
1520 static void route_match_origin_free(void *rule
)
1522 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1525 /* Route map commands for origin matching. */
1526 static const struct route_map_rule_cmd route_match_origin_cmd
= {
1529 route_match_origin_compile
,
1530 route_match_origin_free
1533 /* match probability { */
1535 static enum route_map_cmd_result_t
1536 route_match_probability(void *rule
, const struct prefix
*prefix
,
1537 route_map_object_t type
, void *object
)
1539 long r
= frr_weak_random();
1541 switch (*(long *)rule
) {
1547 if (r
< *(long *)rule
) {
1552 return RMAP_NOMATCH
;
1555 static void *route_match_probability_compile(const char *arg
)
1561 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1571 *lobule
= RAND_MAX
/ 100 * perc
;
1577 static void route_match_probability_free(void *rule
)
1579 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1582 static const struct route_map_rule_cmd route_match_probability_cmd
= {
1584 route_match_probability
,
1585 route_match_probability_compile
,
1586 route_match_probability_free
1589 /* `match interface IFNAME' */
1590 /* Match function should return 1 if match is success else return
1592 static enum route_map_cmd_result_t
1593 route_match_interface(void *rule
, const struct prefix
*prefix
,
1594 route_map_object_t type
, void *object
)
1596 struct interface
*ifp
;
1597 struct bgp_path_info
*path
;
1599 if (type
== RMAP_BGP
) {
1603 return RMAP_NOMATCH
;
1605 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1607 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1608 return RMAP_NOMATCH
;
1612 return RMAP_NOMATCH
;
1615 /* Route map `interface' match statement. `arg' should be
1617 static void *route_match_interface_compile(const char *arg
)
1619 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1622 /* Free route map's compiled `interface' value. */
1623 static void route_match_interface_free(void *rule
)
1625 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1628 /* Route map commands for ip address matching. */
1629 static const struct route_map_rule_cmd route_match_interface_cmd
= {
1631 route_match_interface
,
1632 route_match_interface_compile
,
1633 route_match_interface_free
1638 /* `set ip next-hop IP_ADDRESS' */
1640 /* Match function return 1 if match is success else return zero. */
1641 static enum route_map_cmd_result_t
1642 route_match_tag(void *rule
, const struct prefix
*prefix
,
1643 route_map_object_t type
, void *object
)
1646 struct bgp_path_info
*path
;
1648 if (type
== RMAP_BGP
) {
1652 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1655 return RMAP_NOMATCH
;
1659 /* Route map commands for tag matching. */
1660 static const struct route_map_rule_cmd route_match_tag_cmd
= {
1663 route_map_rule_tag_compile
,
1664 route_map_rule_tag_free
,
1668 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1669 struct rmap_ip_nexthop_set
{
1670 struct in_addr
*address
;
1675 static enum route_map_cmd_result_t
1676 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
,
1677 route_map_object_t type
, void *object
)
1679 struct rmap_ip_nexthop_set
*rins
= rule
;
1680 struct bgp_path_info
*path
;
1683 if (type
!= RMAP_BGP
)
1686 if (prefix
->family
== AF_INET6
)
1692 if (rins
->unchanged
) {
1693 SET_FLAG(path
->attr
->rmap_change_flags
,
1694 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1695 } else if (rins
->peer_address
) {
1696 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1697 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1699 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1700 path
->attr
->nexthop
.s_addr
=
1701 sockunion2ip(peer
->su_remote
);
1702 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1703 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1704 /* The next hop value will be set as part of
1705 * packet rewrite. Set the flags here to indicate
1706 * that rewrite needs to be done.
1707 * Also, clear the value.
1709 SET_FLAG(path
->attr
->rmap_change_flags
,
1710 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1711 path
->attr
->nexthop
.s_addr
= INADDR_ANY
;
1714 /* Set next hop value. */
1715 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1716 path
->attr
->nexthop
= *rins
->address
;
1717 SET_FLAG(path
->attr
->rmap_change_flags
,
1718 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1719 /* case for MP-BGP : MPLS VPN */
1720 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1721 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1727 /* Route map `ip nexthop' compile function. Given string is converted
1728 to struct in_addr structure. */
1729 static void *route_set_ip_nexthop_compile(const char *arg
)
1731 struct rmap_ip_nexthop_set
*rins
;
1732 struct in_addr
*address
= NULL
;
1733 int peer_address
= 0;
1737 if (strcmp(arg
, "peer-address") == 0)
1739 else if (strcmp(arg
, "unchanged") == 0)
1742 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1743 sizeof(struct in_addr
));
1744 ret
= inet_aton(arg
, address
);
1747 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1752 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1753 sizeof(struct rmap_ip_nexthop_set
));
1755 rins
->address
= address
;
1756 rins
->peer_address
= peer_address
;
1757 rins
->unchanged
= unchanged
;
1762 /* Free route map's compiled `ip nexthop' value. */
1763 static void route_set_ip_nexthop_free(void *rule
)
1765 struct rmap_ip_nexthop_set
*rins
= rule
;
1767 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1769 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1772 /* Route map commands for ip nexthop set. */
1773 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1775 route_set_ip_nexthop
,
1776 route_set_ip_nexthop_compile
,
1777 route_set_ip_nexthop_free
1780 /* `set local-preference LOCAL_PREF' */
1782 /* Set local preference. */
1783 static enum route_map_cmd_result_t
1784 route_set_local_pref(void *rule
, const struct prefix
*prefix
,
1785 route_map_object_t type
, void *object
)
1787 struct rmap_value
*rv
;
1788 struct bgp_path_info
*path
;
1789 uint32_t locpref
= 0;
1791 if (type
== RMAP_BGP
) {
1792 /* Fetch routemap's rule information. */
1796 /* Set local preference value. */
1797 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1798 locpref
= path
->attr
->local_pref
;
1800 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1801 path
->attr
->local_pref
=
1802 route_value_adjust(rv
, locpref
, path
->peer
);
1808 /* Set local preference rule structure. */
1809 static const struct route_map_rule_cmd route_set_local_pref_cmd
= {
1811 route_set_local_pref
,
1812 route_value_compile
,
1816 /* `set weight WEIGHT' */
1819 static enum route_map_cmd_result_t
1820 route_set_weight(void *rule
, const struct prefix
*prefix
,
1821 route_map_object_t type
, void *object
)
1823 struct rmap_value
*rv
;
1824 struct bgp_path_info
*path
;
1826 if (type
== RMAP_BGP
) {
1827 /* Fetch routemap's rule information. */
1831 /* Set weight value. */
1832 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1838 /* Set local preference rule structure. */
1839 static const struct route_map_rule_cmd route_set_weight_cmd
= {
1842 route_value_compile
,
1846 /* `set distance DISTANCE */
1847 static enum route_map_cmd_result_t
1848 route_set_distance(void *rule
, const struct prefix
*prefix
,
1849 route_map_object_t type
, void *object
)
1851 struct bgp_path_info
*path
= object
;
1852 struct rmap_value
*rv
= rule
;
1854 if (type
!= RMAP_BGP
)
1857 path
->attr
->distance
= rv
->value
;
1862 /* set distance rule structure */
1863 static const struct route_map_rule_cmd route_set_distance_cmd
= {
1866 route_value_compile
,
1870 /* `set metric METRIC' */
1872 /* Set metric to attribute. */
1873 static enum route_map_cmd_result_t
1874 route_set_metric(void *rule
, const struct prefix
*prefix
,
1875 route_map_object_t type
, void *object
)
1877 struct rmap_value
*rv
;
1878 struct bgp_path_info
*path
;
1881 if (type
== RMAP_BGP
) {
1882 /* Fetch routemap's rule information. */
1886 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1887 med
= path
->attr
->med
;
1889 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1890 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1895 /* Set metric rule structure. */
1896 static const struct route_map_rule_cmd route_set_metric_cmd
= {
1899 route_value_compile
,
1903 /* `set table (1-4294967295)' */
1905 static enum route_map_cmd_result_t
route_set_table_id(void *rule
,
1906 const struct prefix
*prefix
,
1907 route_map_object_t type
,
1910 struct rmap_value
*rv
;
1911 struct bgp_path_info
*path
;
1913 if (type
== RMAP_BGP
) {
1914 /* Fetch routemap's rule information. */
1918 path
->attr
->rmap_table_id
= rv
->value
;
1923 /* Set table_id rule structure. */
1924 static const struct route_map_rule_cmd route_set_table_id_cmd
= {
1927 route_value_compile
,
1931 /* `set as-path prepend ASPATH' */
1933 /* For AS path prepend mechanism. */
1934 static enum route_map_cmd_result_t
1935 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
,
1936 route_map_object_t type
, void *object
)
1938 struct aspath
*aspath
;
1940 struct bgp_path_info
*path
;
1942 if (type
== RMAP_BGP
) {
1945 if (path
->attr
->aspath
->refcnt
)
1946 new = aspath_dup(path
->attr
->aspath
);
1948 new = path
->attr
->aspath
;
1950 if ((uintptr_t)rule
> 10) {
1952 aspath_prepend(aspath
, new);
1954 as_t as
= aspath_leftmost(new);
1956 as
= path
->peer
->as
;
1957 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1960 path
->attr
->aspath
= new;
1966 static void *route_set_aspath_prepend_compile(const char *arg
)
1970 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1971 return (void *)(uintptr_t)num
;
1973 return route_aspath_compile(arg
);
1976 static void route_set_aspath_prepend_free(void *rule
)
1978 if ((uintptr_t)rule
> 10)
1979 route_aspath_free(rule
);
1983 /* Set as-path prepend rule structure. */
1984 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1986 route_set_aspath_prepend
,
1987 route_set_aspath_prepend_compile
,
1988 route_set_aspath_prepend_free
,
1991 /* `set as-path exclude ASn' */
1993 /* For ASN exclude mechanism.
1994 * Iterate over ASns requested and filter them from the given AS_PATH one by
1996 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1998 static enum route_map_cmd_result_t
1999 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
,
2000 route_map_object_t type
, void *object
)
2002 struct aspath
*new_path
, *exclude_path
;
2003 struct bgp_path_info
*path
;
2005 if (type
== RMAP_BGP
) {
2006 exclude_path
= rule
;
2008 if (path
->attr
->aspath
->refcnt
)
2009 new_path
= aspath_dup(path
->attr
->aspath
);
2011 new_path
= path
->attr
->aspath
;
2012 path
->attr
->aspath
=
2013 aspath_filter_exclude(new_path
, exclude_path
);
2018 /* Set ASn exlude rule structure. */
2019 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
2021 route_set_aspath_exclude
,
2022 route_aspath_compile
,
2026 /* `set community COMMUNITY' */
2027 struct rmap_com_set
{
2028 struct community
*com
;
2033 /* For community set mechanism. */
2034 static enum route_map_cmd_result_t
2035 route_set_community(void *rule
, const struct prefix
*prefix
,
2036 route_map_object_t type
, void *object
)
2038 struct rmap_com_set
*rcs
;
2039 struct bgp_path_info
*path
;
2041 struct community
*new = NULL
;
2042 struct community
*old
;
2043 struct community
*merge
;
2045 if (type
== RMAP_BGP
) {
2049 old
= attr
->community
;
2053 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
2054 attr
->community
= NULL
;
2055 /* See the longer comment down below. */
2056 if (old
&& old
->refcnt
== 0)
2057 community_free(&old
);
2061 /* "additive" case. */
2062 if (rcs
->additive
&& old
) {
2063 merge
= community_merge(community_dup(old
), rcs
->com
);
2065 new = community_uniq_sort(merge
);
2066 community_free(&merge
);
2068 new = community_dup(rcs
->com
);
2070 /* HACK: if the old community is not intern'd,
2071 * we should free it here, or all reference to it may be
2073 * Really need to cleanup attribute caching sometime.
2075 if (old
&& old
->refcnt
== 0)
2076 community_free(&old
);
2078 /* will be interned by caller if required */
2079 attr
->community
= new;
2081 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2087 /* Compile function for set community. */
2088 static void *route_set_community_compile(const char *arg
)
2090 struct rmap_com_set
*rcs
;
2091 struct community
*com
= NULL
;
2096 if (strcmp(arg
, "none") == 0)
2099 sp
= strstr(arg
, "additive");
2101 if (sp
&& sp
> arg
) {
2102 /* "additive" keyword is included. */
2107 com
= community_str2com(arg
);
2116 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2118 rcs
->additive
= additive
;
2124 /* Free function for set community. */
2125 static void route_set_community_free(void *rule
)
2127 struct rmap_com_set
*rcs
= rule
;
2130 community_free(&rcs
->com
);
2131 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2134 /* Set community rule structure. */
2135 static const struct route_map_rule_cmd route_set_community_cmd
= {
2137 route_set_community
,
2138 route_set_community_compile
,
2139 route_set_community_free
,
2142 /* `set community COMMUNITY' */
2143 struct rmap_lcom_set
{
2144 struct lcommunity
*lcom
;
2150 /* For lcommunity set mechanism. */
2151 static enum route_map_cmd_result_t
2152 route_set_lcommunity(void *rule
, const struct prefix
*prefix
,
2153 route_map_object_t type
, void *object
)
2155 struct rmap_lcom_set
*rcs
;
2156 struct bgp_path_info
*path
;
2158 struct lcommunity
*new = NULL
;
2159 struct lcommunity
*old
;
2160 struct lcommunity
*merge
;
2162 if (type
== RMAP_BGP
) {
2166 old
= attr
->lcommunity
;
2171 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
2172 attr
->lcommunity
= NULL
;
2174 /* See the longer comment down below. */
2175 if (old
&& old
->refcnt
== 0)
2176 lcommunity_free(&old
);
2180 if (rcs
->additive
&& old
) {
2181 merge
= lcommunity_merge(lcommunity_dup(old
),
2184 new = lcommunity_uniq_sort(merge
);
2185 lcommunity_free(&merge
);
2187 new = lcommunity_dup(rcs
->lcom
);
2189 /* HACK: if the old large-community is not intern'd,
2190 * we should free it here, or all reference to it may be
2192 * Really need to cleanup attribute caching sometime.
2194 if (old
&& old
->refcnt
== 0)
2195 lcommunity_free(&old
);
2197 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2198 attr
->lcommunity
= new;
2200 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2206 /* Compile function for set community. */
2207 static void *route_set_lcommunity_compile(const char *arg
)
2209 struct rmap_lcom_set
*rcs
;
2210 struct lcommunity
*lcom
= NULL
;
2215 if (strcmp(arg
, "none") == 0)
2218 sp
= strstr(arg
, "additive");
2220 if (sp
&& sp
> arg
) {
2221 /* "additive" keyworkd is included. */
2226 lcom
= lcommunity_str2com(arg
);
2235 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2237 rcs
->additive
= additive
;
2243 /* Free function for set lcommunity. */
2244 static void route_set_lcommunity_free(void *rule
)
2246 struct rmap_lcom_set
*rcs
= rule
;
2249 lcommunity_free(&rcs
->lcom
);
2251 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2254 /* Set community rule structure. */
2255 static const struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2257 route_set_lcommunity
,
2258 route_set_lcommunity_compile
,
2259 route_set_lcommunity_free
,
2262 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2264 /* For large community set mechanism. */
2265 static enum route_map_cmd_result_t
2266 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
,
2267 route_map_object_t type
, void *object
)
2269 struct community_list
*list
;
2270 struct lcommunity
*merge
;
2271 struct lcommunity
*new;
2272 struct lcommunity
*old
;
2273 struct bgp_path_info
*path
;
2274 struct rmap_community
*rcom
= rule
;
2276 if (type
== RMAP_BGP
) {
2281 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2283 LARGE_COMMUNITY_LIST_MASTER
);
2284 old
= path
->attr
->lcommunity
;
2287 merge
= lcommunity_list_match_delete(
2288 lcommunity_dup(old
), list
);
2289 new = lcommunity_uniq_sort(merge
);
2290 lcommunity_free(&merge
);
2292 /* HACK: if the old community is not intern'd,
2293 * we should free it here, or all reference to it may be
2295 * Really need to cleanup attribute caching sometime.
2297 if (old
->refcnt
== 0)
2298 lcommunity_free(&old
);
2300 if (new->size
== 0) {
2301 path
->attr
->lcommunity
= NULL
;
2302 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2303 BGP_ATTR_LARGE_COMMUNITIES
);
2304 lcommunity_free(&new);
2306 path
->attr
->lcommunity
= new;
2307 path
->attr
->flag
|= ATTR_FLAG_BIT(
2308 BGP_ATTR_LARGE_COMMUNITIES
);
2316 /* Compile function for set lcommunity. */
2317 static void *route_set_lcommunity_delete_compile(const char *arg
)
2319 struct rmap_community
*rcom
;
2323 frrstr_split(arg
, " ", &splits
, &num
);
2325 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2326 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2327 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2329 for (int i
= 0; i
< num
; i
++)
2330 XFREE(MTYPE_TMP
, splits
[i
]);
2331 XFREE(MTYPE_TMP
, splits
);
2336 /* Free function for set lcommunity. */
2337 static void route_set_lcommunity_delete_free(void *rule
)
2339 struct rmap_community
*rcom
= rule
;
2341 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2342 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2345 /* Set lcommunity rule structure. */
2346 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2348 route_set_lcommunity_delete
,
2349 route_set_lcommunity_delete_compile
,
2350 route_set_lcommunity_delete_free
,
2354 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2356 /* For community set mechanism. */
2357 static enum route_map_cmd_result_t
2358 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2359 route_map_object_t type
, void *object
)
2361 struct community_list
*list
;
2362 struct community
*merge
;
2363 struct community
*new;
2364 struct community
*old
;
2365 struct bgp_path_info
*path
;
2366 struct rmap_community
*rcom
= rule
;
2368 if (type
== RMAP_BGP
) {
2373 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2375 COMMUNITY_LIST_MASTER
);
2376 old
= path
->attr
->community
;
2379 merge
= community_list_match_delete(community_dup(old
),
2381 new = community_uniq_sort(merge
);
2382 community_free(&merge
);
2384 /* HACK: if the old community is not intern'd,
2385 * we should free it here, or all reference to it may be
2387 * Really need to cleanup attribute caching sometime.
2389 if (old
->refcnt
== 0)
2390 community_free(&old
);
2392 if (new->size
== 0) {
2393 path
->attr
->community
= NULL
;
2395 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2396 community_free(&new);
2398 path
->attr
->community
= new;
2400 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2408 /* Compile function for set community. */
2409 static void *route_set_community_delete_compile(const char *arg
)
2411 struct rmap_community
*rcom
;
2415 frrstr_split(arg
, " ", &splits
, &num
);
2417 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2418 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2419 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2421 for (int i
= 0; i
< num
; i
++)
2422 XFREE(MTYPE_TMP
, splits
[i
]);
2423 XFREE(MTYPE_TMP
, splits
);
2428 /* Free function for set community. */
2429 static void route_set_community_delete_free(void *rule
)
2431 struct rmap_community
*rcom
= rule
;
2433 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2434 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2437 /* Set community rule structure. */
2438 static const struct route_map_rule_cmd route_set_community_delete_cmd
= {
2440 route_set_community_delete
,
2441 route_set_community_delete_compile
,
2442 route_set_community_delete_free
,
2445 /* `set extcommunity rt COMMUNITY' */
2447 /* For community set mechanism. Used by _rt and _soo. */
2448 static enum route_map_cmd_result_t
2449 route_set_ecommunity(void *rule
, const struct prefix
*prefix
,
2450 route_map_object_t type
, void *object
)
2452 struct ecommunity
*ecom
;
2453 struct ecommunity
*new_ecom
;
2454 struct ecommunity
*old_ecom
;
2455 struct bgp_path_info
*path
;
2457 if (type
== RMAP_BGP
) {
2464 /* We assume additive for Extended Community. */
2465 old_ecom
= path
->attr
->ecommunity
;
2468 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2471 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2472 * bgp_update_receive()
2473 * ->refcnt = 0 => set by a previous route-map
2475 if (!old_ecom
->refcnt
)
2476 ecommunity_free(&old_ecom
);
2478 new_ecom
= ecommunity_dup(ecom
);
2480 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2481 path
->attr
->ecommunity
= new_ecom
;
2483 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2488 /* Compile function for set community. */
2489 static void *route_set_ecommunity_rt_compile(const char *arg
)
2491 struct ecommunity
*ecom
;
2493 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2496 return ecommunity_intern(ecom
);
2499 /* Free function for set community. Used by _rt and _soo */
2500 static void route_set_ecommunity_free(void *rule
)
2502 struct ecommunity
*ecom
= rule
;
2503 ecommunity_unintern(&ecom
);
2506 /* Set community rule structure. */
2507 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2509 route_set_ecommunity
,
2510 route_set_ecommunity_rt_compile
,
2511 route_set_ecommunity_free
,
2514 /* `set extcommunity soo COMMUNITY' */
2516 /* Compile function for set community. */
2517 static void *route_set_ecommunity_soo_compile(const char *arg
)
2519 struct ecommunity
*ecom
;
2521 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2525 return ecommunity_intern(ecom
);
2528 /* Set community rule structure. */
2529 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2531 route_set_ecommunity
,
2532 route_set_ecommunity_soo_compile
,
2533 route_set_ecommunity_free
,
2536 /* `set extcommunity bandwidth' */
2538 struct rmap_ecomm_lb_set
{
2540 #define RMAP_ECOMM_LB_SET_VALUE 1
2541 #define RMAP_ECOMM_LB_SET_CUMUL 2
2542 #define RMAP_ECOMM_LB_SET_NUM_MPATH 3
2547 static enum route_map_cmd_result_t
2548 route_set_ecommunity_lb(void *rule
, const struct prefix
*prefix
,
2549 route_map_object_t type
, void *object
)
2551 struct rmap_ecomm_lb_set
*rels
= rule
;
2552 struct bgp_path_info
*path
;
2554 struct ecommunity ecom_lb
= {0};
2555 struct ecommunity_val lb_eval
;
2556 uint32_t bw_bytes
= 0;
2557 uint16_t mpath_count
= 0;
2558 struct ecommunity
*new_ecom
;
2559 struct ecommunity
*old_ecom
;
2562 if (type
!= RMAP_BGP
)
2567 if (!peer
|| !peer
->bgp
)
2570 /* Build link bandwidth extended community */
2571 as
= (peer
->bgp
->as
> BGP_AS_MAX
) ? BGP_AS_TRANS
: peer
->bgp
->as
;
2572 if (rels
->lb_type
== RMAP_ECOMM_LB_SET_VALUE
) {
2573 bw_bytes
= ((uint64_t)rels
->bw
* 1000 * 1000) / 8;
2574 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_CUMUL
) {
2575 /* process this only for the best path. */
2576 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2579 bw_bytes
= (uint32_t)bgp_path_info_mpath_cumbw(path
);
2583 } else if (rels
->lb_type
== RMAP_ECOMM_LB_SET_NUM_MPATH
) {
2585 /* process this only for the best path. */
2586 if (!CHECK_FLAG(path
->flags
, BGP_PATH_SELECTED
))
2589 bw_bytes
= ((uint64_t)peer
->bgp
->lb_ref_bw
* 1000 * 1000) / 8;
2590 mpath_count
= bgp_path_info_mpath_count(path
) + 1;
2591 bw_bytes
*= mpath_count
;
2594 encode_lb_extcomm(as
, bw_bytes
, rels
->non_trans
, &lb_eval
);
2596 /* add to route or merge with existing */
2597 old_ecom
= path
->attr
->ecommunity
;
2599 new_ecom
= ecommunity_dup(old_ecom
);
2600 ecommunity_add_val(new_ecom
, &lb_eval
, true, true);
2601 if (!old_ecom
->refcnt
)
2602 ecommunity_free(&old_ecom
);
2605 ecom_lb
.val
= (uint8_t *)lb_eval
.val
;
2606 new_ecom
= ecommunity_dup(&ecom_lb
);
2609 /* new_ecom will be intern()'d or attr_flush()'d in call stack */
2610 path
->attr
->ecommunity
= new_ecom
;
2611 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2613 /* Mark that route-map has set link bandwidth; used in attribute
2614 * setting decisions.
2616 SET_FLAG(path
->attr
->rmap_change_flags
, BATTR_RMAP_LINK_BW_SET
);
2621 static void *route_set_ecommunity_lb_compile(const char *arg
)
2623 struct rmap_ecomm_lb_set
*rels
;
2626 char bw_str
[40] = {0};
2628 bool non_trans
= false;
2631 p
= strchr(arg
, ' ');
2636 memcpy(bw_str
, arg
, len
);
2641 if (strcmp(str
, "cumulative") == 0)
2642 lb_type
= RMAP_ECOMM_LB_SET_CUMUL
;
2643 else if (strcmp(str
, "num-multipaths") == 0)
2644 lb_type
= RMAP_ECOMM_LB_SET_NUM_MPATH
;
2648 bw
= strtoul(str
, &end
, 10);
2651 lb_type
= RMAP_ECOMM_LB_SET_VALUE
;
2654 rels
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
2655 sizeof(struct rmap_ecomm_lb_set
));
2656 rels
->lb_type
= lb_type
;
2658 rels
->non_trans
= non_trans
;
2663 static void route_set_ecommunity_lb_free(void *rule
)
2665 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2668 /* Set community rule structure. */
2669 struct route_map_rule_cmd route_set_ecommunity_lb_cmd
= {
2670 "extcommunity bandwidth",
2671 route_set_ecommunity_lb
,
2672 route_set_ecommunity_lb_compile
,
2673 route_set_ecommunity_lb_free
,
2676 /* `set origin ORIGIN' */
2678 /* For origin set. */
2679 static enum route_map_cmd_result_t
2680 route_set_origin(void *rule
, const struct prefix
*prefix
,
2681 route_map_object_t type
, void *object
)
2684 struct bgp_path_info
*path
;
2686 if (type
== RMAP_BGP
) {
2690 path
->attr
->origin
= *origin
;
2696 /* Compile function for origin set. */
2697 static void *route_set_origin_compile(const char *arg
)
2701 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2703 if (strcmp(arg
, "igp") == 0)
2705 else if (strcmp(arg
, "egp") == 0)
2713 /* Compile function for origin set. */
2714 static void route_set_origin_free(void *rule
)
2716 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2719 /* Set origin rule structure. */
2720 static const struct route_map_rule_cmd route_set_origin_cmd
= {
2723 route_set_origin_compile
,
2724 route_set_origin_free
,
2727 /* `set atomic-aggregate' */
2729 /* For atomic aggregate set. */
2730 static enum route_map_cmd_result_t
2731 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
,
2732 route_map_object_t type
, void *object
)
2734 struct bgp_path_info
*path
;
2736 if (type
== RMAP_BGP
) {
2738 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2744 /* Compile function for atomic aggregate. */
2745 static void *route_set_atomic_aggregate_compile(const char *arg
)
2750 /* Compile function for atomic aggregate. */
2751 static void route_set_atomic_aggregate_free(void *rule
)
2756 /* Set atomic aggregate rule structure. */
2757 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2759 route_set_atomic_aggregate
,
2760 route_set_atomic_aggregate_compile
,
2761 route_set_atomic_aggregate_free
,
2764 /* `set aggregator as AS A.B.C.D' */
2767 struct in_addr address
;
2770 static enum route_map_cmd_result_t
2771 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
,
2772 route_map_object_t type
, void *object
)
2774 struct bgp_path_info
*path
;
2775 struct aggregator
*aggregator
;
2777 if (type
== RMAP_BGP
) {
2781 path
->attr
->aggregator_as
= aggregator
->as
;
2782 path
->attr
->aggregator_addr
= aggregator
->address
;
2783 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2789 static void *route_set_aggregator_as_compile(const char *arg
)
2791 struct aggregator
*aggregator
;
2797 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2798 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2799 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2803 aggregator
->as
= strtoul(as
, NULL
, 10);
2804 ret
= inet_aton(address
, &aggregator
->address
);
2806 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2812 static void route_set_aggregator_as_free(void *rule
)
2814 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2817 static const struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2819 route_set_aggregator_as
,
2820 route_set_aggregator_as_compile
,
2821 route_set_aggregator_as_free
,
2824 /* Set tag to object. object must be pointer to struct bgp_path_info */
2825 static enum route_map_cmd_result_t
2826 route_set_tag(void *rule
, const struct prefix
*prefix
,
2827 route_map_object_t type
, void *object
)
2830 struct bgp_path_info
*path
;
2832 if (type
== RMAP_BGP
) {
2837 path
->attr
->tag
= *tag
;
2843 /* Route map commands for tag set. */
2844 static const struct route_map_rule_cmd route_set_tag_cmd
= {
2847 route_map_rule_tag_compile
,
2848 route_map_rule_tag_free
,
2851 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2852 static enum route_map_cmd_result_t
2853 route_set_label_index(void *rule
, const struct prefix
*prefix
,
2854 route_map_object_t type
, void *object
)
2856 struct rmap_value
*rv
;
2857 struct bgp_path_info
*path
;
2858 uint32_t label_index
;
2860 if (type
== RMAP_BGP
) {
2861 /* Fetch routemap's rule information. */
2865 /* Set label-index value. */
2866 label_index
= rv
->value
;
2868 path
->attr
->label_index
= label_index
;
2869 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2876 /* Route map commands for label-index set. */
2877 static const struct route_map_rule_cmd route_set_label_index_cmd
= {
2879 route_set_label_index
,
2880 route_value_compile
,
2884 /* `match ipv6 address IP_ACCESS_LIST' */
2886 static enum route_map_cmd_result_t
2887 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
,
2888 route_map_object_t type
, void *object
)
2890 struct access_list
*alist
;
2892 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2893 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2895 return RMAP_NOMATCH
;
2897 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2901 return RMAP_NOMATCH
;
2904 static void *route_match_ipv6_address_compile(const char *arg
)
2906 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2909 static void route_match_ipv6_address_free(void *rule
)
2911 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2914 /* Route map commands for ip address matching. */
2915 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2917 route_match_ipv6_address
,
2918 route_match_ipv6_address_compile
,
2919 route_match_ipv6_address_free
2922 /* `match ipv6 next-hop IP_ADDRESS' */
2924 static enum route_map_cmd_result_t
2925 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
,
2926 route_map_object_t type
, void *object
)
2928 struct in6_addr
*addr
= rule
;
2929 struct bgp_path_info
*path
;
2931 if (type
== RMAP_BGP
) {
2934 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2937 if (path
->attr
->mp_nexthop_len
2938 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2939 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2942 return RMAP_NOMATCH
;
2945 return RMAP_NOMATCH
;
2948 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2950 struct in6_addr
*address
;
2953 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2955 ret
= inet_pton(AF_INET6
, arg
, address
);
2957 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2964 static void route_match_ipv6_next_hop_free(void *rule
)
2966 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2969 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2971 route_match_ipv6_next_hop
,
2972 route_match_ipv6_next_hop_compile
,
2973 route_match_ipv6_next_hop_free
2976 /* `match ip next-hop IP_ADDRESS' */
2978 static enum route_map_cmd_result_t
2979 route_match_ipv4_next_hop(void *rule
, const struct prefix
*prefix
,
2980 route_map_object_t type
, void *object
)
2982 struct in_addr
*addr
= rule
;
2983 struct bgp_path_info
*path
;
2985 if (type
== RMAP_BGP
) {
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 return RMAP_NOMATCH
;
2999 static void *route_match_ipv4_next_hop_compile(const char *arg
)
3001 struct in_addr
*address
;
3004 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3006 ret
= inet_pton(AF_INET
, arg
, address
);
3008 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3015 static void route_match_ipv4_next_hop_free(void *rule
)
3017 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3020 static const struct route_map_rule_cmd route_match_ipv4_next_hop_cmd
= {
3021 "ip next-hop address",
3022 route_match_ipv4_next_hop
,
3023 route_match_ipv4_next_hop_compile
,
3024 route_match_ipv4_next_hop_free
3027 /* `match ipv6 address prefix-list PREFIX_LIST' */
3029 static enum route_map_cmd_result_t
3030 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
3031 route_map_object_t type
, void *object
)
3033 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, type
,
3037 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
3039 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
3042 static void route_match_ipv6_address_prefix_list_free(void *rule
)
3044 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3047 static const struct route_map_rule_cmd
3048 route_match_ipv6_address_prefix_list_cmd
= {
3049 "ipv6 address prefix-list",
3050 route_match_ipv6_address_prefix_list
,
3051 route_match_ipv6_address_prefix_list_compile
,
3052 route_match_ipv6_address_prefix_list_free
3055 /* `match ipv6 next-hop type <TYPE>' */
3057 static enum route_map_cmd_result_t
3058 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
3059 route_map_object_t type
, void *object
)
3061 struct bgp_path_info
*path
;
3062 struct in6_addr
*addr
= rule
;
3064 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
3065 path
= (struct bgp_path_info
*)object
;
3067 return RMAP_NOMATCH
;
3069 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
3070 && !path
->attr
->nh_ifindex
)
3073 return RMAP_NOMATCH
;
3076 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
3078 struct in6_addr
*address
;
3081 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3083 ret
= inet_pton(AF_INET6
, "::0", address
);
3085 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3092 static void route_match_ipv6_next_hop_type_free(void *rule
)
3094 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3097 static const struct route_map_rule_cmd
3098 route_match_ipv6_next_hop_type_cmd
= {
3099 "ipv6 next-hop type",
3100 route_match_ipv6_next_hop_type
,
3101 route_match_ipv6_next_hop_type_compile
,
3102 route_match_ipv6_next_hop_type_free
3105 /* `set ipv6 nexthop global IP_ADDRESS' */
3107 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3108 static enum route_map_cmd_result_t
3109 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
,
3110 route_map_object_t type
, void *object
)
3112 struct in6_addr
*address
;
3113 struct bgp_path_info
*path
;
3115 if (type
== RMAP_BGP
) {
3116 /* Fetch routemap's rule information. */
3120 /* Set next hop value. */
3121 path
->attr
->mp_nexthop_global
= *address
;
3123 /* Set nexthop length. */
3124 if (path
->attr
->mp_nexthop_len
== 0)
3125 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3127 SET_FLAG(path
->attr
->rmap_change_flags
,
3128 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
3134 /* Route map `ip next-hop' compile function. Given string is converted
3135 to struct in_addr structure. */
3136 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
3139 struct in6_addr
*address
;
3141 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3143 ret
= inet_pton(AF_INET6
, arg
, address
);
3146 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3153 /* Free route map's compiled `ip next-hop' value. */
3154 static void route_set_ipv6_nexthop_global_free(void *rule
)
3156 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3159 /* Route map commands for ip nexthop set. */
3160 static const struct route_map_rule_cmd
3161 route_set_ipv6_nexthop_global_cmd
= {
3162 "ipv6 next-hop global",
3163 route_set_ipv6_nexthop_global
,
3164 route_set_ipv6_nexthop_global_compile
,
3165 route_set_ipv6_nexthop_global_free
3168 /* Set next-hop preference value. */
3169 static enum route_map_cmd_result_t
3170 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
3171 route_map_object_t type
, void *object
)
3173 struct bgp_path_info
*path
;
3176 if (type
== RMAP_BGP
) {
3177 /* Fetch routemap's rule information. */
3181 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3182 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
3183 /* Set next hop preference to global */
3184 path
->attr
->mp_nexthop_prefer_global
= true;
3185 SET_FLAG(path
->attr
->rmap_change_flags
,
3186 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3188 path
->attr
->mp_nexthop_prefer_global
= false;
3189 SET_FLAG(path
->attr
->rmap_change_flags
,
3190 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3196 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
3200 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3206 /* Free route map's compiled `ip next-hop' value. */
3207 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
3209 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3212 /* Route map commands for ip nexthop set preferred. */
3213 static const struct route_map_rule_cmd
3214 route_set_ipv6_nexthop_prefer_global_cmd
= {
3215 "ipv6 next-hop prefer-global",
3216 route_set_ipv6_nexthop_prefer_global
,
3217 route_set_ipv6_nexthop_prefer_global_compile
,
3218 route_set_ipv6_nexthop_prefer_global_free
3221 /* `set ipv6 nexthop local IP_ADDRESS' */
3223 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3224 static enum route_map_cmd_result_t
3225 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
,
3226 route_map_object_t type
, void *object
)
3228 struct in6_addr
*address
;
3229 struct bgp_path_info
*path
;
3231 if (type
== RMAP_BGP
) {
3232 /* Fetch routemap's rule information. */
3236 /* Set next hop value. */
3237 path
->attr
->mp_nexthop_local
= *address
;
3239 /* Set nexthop length. */
3240 if (path
->attr
->mp_nexthop_len
3241 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3242 path
->attr
->mp_nexthop_len
=
3243 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3245 SET_FLAG(path
->attr
->rmap_change_flags
,
3246 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
3252 /* Route map `ip nexthop' compile function. Given string is converted
3253 to struct in_addr structure. */
3254 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
3257 struct in6_addr
*address
;
3259 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3261 ret
= inet_pton(AF_INET6
, arg
, address
);
3264 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3271 /* Free route map's compiled `ip nexthop' value. */
3272 static void route_set_ipv6_nexthop_local_free(void *rule
)
3274 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3277 /* Route map commands for ip nexthop set. */
3278 static const struct route_map_rule_cmd
3279 route_set_ipv6_nexthop_local_cmd
= {
3280 "ipv6 next-hop local",
3281 route_set_ipv6_nexthop_local
,
3282 route_set_ipv6_nexthop_local_compile
,
3283 route_set_ipv6_nexthop_local_free
3286 /* `set ipv6 nexthop peer-address' */
3288 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3289 static enum route_map_cmd_result_t
3290 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
,
3291 route_map_object_t type
, void *object
)
3293 struct in6_addr peer_address
;
3294 struct bgp_path_info
*path
;
3297 if (type
== RMAP_BGP
) {
3298 /* Fetch routemap's rule information. */
3302 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3303 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
3305 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
3306 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
3307 /* Set next hop value and length in attribute. */
3308 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
3309 path
->attr
->mp_nexthop_local
= peer_address
;
3310 if (path
->attr
->mp_nexthop_len
3311 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3312 path
->attr
->mp_nexthop_len
=
3313 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3315 path
->attr
->mp_nexthop_global
= peer_address
;
3316 if (path
->attr
->mp_nexthop_len
== 0)
3317 path
->attr
->mp_nexthop_len
=
3318 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3321 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
3322 /* The next hop value will be set as part of packet
3324 * Set the flags here to indicate that rewrite needs to
3326 * Also, clear the value - we clear both global and
3328 * nexthops, whether we send one or both is determined
3331 SET_FLAG(path
->attr
->rmap_change_flags
,
3332 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3333 /* clear next hop value. */
3334 memset(&(path
->attr
->mp_nexthop_global
), 0,
3335 sizeof(struct in6_addr
));
3336 memset(&(path
->attr
->mp_nexthop_local
), 0,
3337 sizeof(struct in6_addr
));
3344 /* Route map `ip next-hop' compile function. Given string is converted
3345 to struct in_addr structure. */
3346 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3350 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3356 /* Free route map's compiled `ip next-hop' value. */
3357 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3359 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3362 /* Route map commands for ip nexthop set. */
3363 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3364 "ipv6 next-hop peer-address",
3365 route_set_ipv6_nexthop_peer
,
3366 route_set_ipv6_nexthop_peer_compile
,
3367 route_set_ipv6_nexthop_peer_free
3370 /* `set ipv4 vpn next-hop A.B.C.D' */
3372 static enum route_map_cmd_result_t
3373 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
,
3374 route_map_object_t type
, void *object
)
3376 struct in_addr
*address
;
3377 struct bgp_path_info
*path
;
3379 if (type
== RMAP_BGP
) {
3380 /* Fetch routemap's rule information. */
3384 /* Set next hop value. */
3385 path
->attr
->mp_nexthop_global_in
= *address
;
3386 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3392 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3395 struct in_addr
*address
;
3397 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3399 ret
= inet_aton(arg
, address
);
3402 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3409 /* `set ipv6 vpn next-hop A.B.C.D' */
3411 static enum route_map_cmd_result_t
3412 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
,
3413 route_map_object_t type
, void *object
)
3415 struct in6_addr
*address
;
3416 struct bgp_path_info
*path
;
3418 if (type
== RMAP_BGP
) {
3419 /* Fetch routemap's rule information. */
3423 /* Set next hop value. */
3424 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3425 sizeof(struct in6_addr
));
3426 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3432 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3435 struct in6_addr
*address
;
3437 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3438 ret
= inet_pton(AF_INET6
, arg
, address
);
3441 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3448 static void route_set_vpn_nexthop_free(void *rule
)
3450 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3453 /* Route map commands for ipv4 next-hop set. */
3454 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3455 "ipv4 vpn next-hop",
3456 route_set_vpnv4_nexthop
,
3457 route_set_vpnv4_nexthop_compile
,
3458 route_set_vpn_nexthop_free
3461 /* Route map commands for ipv6 next-hop set. */
3462 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3463 "ipv6 vpn next-hop",
3464 route_set_vpnv6_nexthop
,
3465 route_set_vpnv6_nexthop_compile
,
3466 route_set_vpn_nexthop_free
3469 /* `set originator-id' */
3471 /* For origin set. */
3472 static enum route_map_cmd_result_t
3473 route_set_originator_id(void *rule
, const struct prefix
*prefix
,
3474 route_map_object_t type
, void *object
)
3476 struct in_addr
*address
;
3477 struct bgp_path_info
*path
;
3479 if (type
== RMAP_BGP
) {
3483 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3484 path
->attr
->originator_id
= *address
;
3490 /* Compile function for originator-id set. */
3491 static void *route_set_originator_id_compile(const char *arg
)
3494 struct in_addr
*address
;
3496 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3498 ret
= inet_aton(arg
, address
);
3501 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3508 /* Compile function for originator_id set. */
3509 static void route_set_originator_id_free(void *rule
)
3511 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3514 /* Set originator-id rule structure. */
3515 static const struct route_map_rule_cmd route_set_originator_id_cmd
= {
3517 route_set_originator_id
,
3518 route_set_originator_id_compile
,
3519 route_set_originator_id_free
,
3522 /* Add bgp route map rule. */
3523 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3524 const char *arg
, route_map_event_t type
)
3526 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3527 int retval
= CMD_SUCCESS
;
3528 enum rmap_compile_rets ret
;
3530 ret
= route_map_add_match(index
, command
, arg
, type
);
3532 case RMAP_RULE_MISSING
:
3533 vty_out(vty
, "%% BGP Can't find rule.\n");
3534 retval
= CMD_WARNING_CONFIG_FAILED
;
3536 case RMAP_COMPILE_ERROR
:
3537 vty_out(vty
, "%% BGP Argument is malformed.\n");
3538 retval
= CMD_WARNING_CONFIG_FAILED
;
3540 case RMAP_COMPILE_SUCCESS
:
3542 * Intentionally doing nothing here.
3550 /* Delete bgp route map rule. */
3551 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3552 const char *arg
, route_map_event_t type
)
3554 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3555 enum rmap_compile_rets ret
;
3556 int retval
= CMD_SUCCESS
;
3557 char *dep_name
= NULL
;
3559 char *rmap_name
= NULL
;
3561 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3562 /* ignore the mundane, the types without any dependency */
3564 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3567 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3569 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3571 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3574 ret
= route_map_delete_match(index
, command
, dep_name
, type
);
3576 case RMAP_RULE_MISSING
:
3577 vty_out(vty
, "%% BGP Can't find rule.\n");
3578 retval
= CMD_WARNING_CONFIG_FAILED
;
3580 case RMAP_COMPILE_ERROR
:
3581 vty_out(vty
, "%% BGP Argument is malformed.\n");
3582 retval
= CMD_WARNING_CONFIG_FAILED
;
3584 case RMAP_COMPILE_SUCCESS
:
3586 * Nothing to do here
3591 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3592 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3598 * This is the workhorse routine for processing in/out routemap
3601 static void bgp_route_map_process_peer(const char *rmap_name
,
3602 struct route_map
*map
, struct peer
*peer
,
3603 int afi
, int safi
, int route_update
)
3605 struct bgp_filter
*filter
;
3607 if (!peer
|| !rmap_name
)
3610 filter
= &peer
->filter
[afi
][safi
];
3612 * in is for non-route-server clients,
3613 * out is for all peers
3615 if (filter
->map
[RMAP_IN
].name
3616 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3617 filter
->map
[RMAP_IN
].map
= map
;
3619 if (route_update
&& peer
->status
== Established
) {
3620 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3621 PEER_FLAG_SOFT_RECONFIG
)) {
3622 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3624 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3625 rmap_name
, peer
->host
);
3627 bgp_soft_reconfig_in(peer
, afi
, safi
);
3628 } else if (CHECK_FLAG(peer
->cap
,
3629 PEER_CAP_REFRESH_OLD_RCV
)
3630 || CHECK_FLAG(peer
->cap
,
3631 PEER_CAP_REFRESH_NEW_RCV
)) {
3632 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3634 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3635 rmap_name
, peer
->host
);
3636 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3643 * For outbound, unsuppress and default-originate map change (content or
3644 * map created), merely update the "config" here, the actual route
3645 * announcement happens at the group level.
3647 if (filter
->map
[RMAP_OUT
].name
3648 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3649 filter
->map
[RMAP_OUT
].map
= map
;
3651 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3652 filter
->usmap
.map
= map
;
3654 if (peer
->default_rmap
[afi
][safi
].name
3655 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3656 peer
->default_rmap
[afi
][safi
].map
= map
;
3659 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3660 struct route_map
*map
,
3663 struct peer_group
*group
;
3664 struct listnode
*node
, *nnode
;
3665 struct bgp_filter
*filter
;
3672 /* All the peers have been updated correctly already. This is
3673 * just updating the placeholder data. No real update required.
3675 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3676 FOREACH_AFI_SAFI (afi
, safi
) {
3677 filter
= &group
->conf
->filter
[afi
][safi
];
3679 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3680 if ((filter
->map
[direct
].name
)
3681 && (strcmp(rmap_name
,
3682 filter
->map
[direct
].name
)
3684 filter
->map
[direct
].map
= map
;
3687 if (filter
->usmap
.name
3688 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3689 filter
->usmap
.map
= map
;
3695 * Note that if an extreme number (tens of thousands) of route-maps are in use
3696 * and if bgp has an extreme number of peers, network statements, etc then this
3697 * function can consume a lot of cycles. This is due to this function being
3698 * called for each route-map and within this function we walk the list of peers,
3699 * network statements, etc looking to see if they use this route-map.
3701 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3708 struct bgp_node
*bn
;
3709 struct bgp_static
*bgp_static
;
3710 struct bgp_aggregate
*aggregate
;
3711 struct listnode
*node
, *nnode
;
3712 struct route_map
*map
;
3713 char buf
[INET6_ADDRSTRLEN
];
3715 map
= route_map_lookup_by_name(rmap_name
);
3717 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3719 /* Ignore dummy peer-group structure */
3720 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3723 FOREACH_AFI_SAFI (afi
, safi
) {
3724 /* process in/out/import/export/default-orig
3726 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3727 safi
, route_update
);
3731 /* for outbound/default-orig route-maps, process for groups */
3732 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3735 /* update peer-group config (template) */
3736 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3738 FOREACH_AFI_SAFI (afi
, safi
) {
3739 /* For table route-map updates. */
3740 if (!bgp_fibupd_safi(safi
))
3743 if (bgp
->table_map
[afi
][safi
].name
3744 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3747 /* bgp->table_map[afi][safi].map is NULL.
3748 * i.e Route map creation event.
3749 * So update applied_counter.
3750 * If it is not NULL, i.e It may be routemap updation or
3751 * deletion. so no need to update the counter.
3753 if (!bgp
->table_map
[afi
][safi
].map
)
3754 route_map_counter_increment(map
);
3755 bgp
->table_map
[afi
][safi
].map
= map
;
3757 if (BGP_DEBUG(zebra
, ZEBRA
))
3759 "Processing route_map %s update on "
3763 bgp_zebra_announce_table(bgp
, afi
, safi
);
3766 /* For network route-map updates. */
3767 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3768 bn
= bgp_route_next(bn
)) {
3769 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3773 if (!bgp_static
->rmap
.name
3774 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3777 if (!bgp_static
->rmap
.map
)
3778 route_map_counter_increment(map
);
3780 bgp_static
->rmap
.map
= map
;
3782 if (route_update
&& !bgp_static
->backdoor
) {
3783 const struct prefix
*bn_p
=
3784 bgp_node_get_prefix(bn
);
3786 if (bgp_debug_zebra(bn_p
))
3788 "Processing route_map %s update on static route %s",
3790 inet_ntop(bn_p
->family
,
3791 &bn_p
->u
.prefix
, buf
,
3793 bgp_static_update(bgp
, bn_p
, bgp_static
, afi
,
3798 /* For aggregate-address route-map updates. */
3799 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
3800 bn
= bgp_route_next(bn
)) {
3801 aggregate
= bgp_node_get_bgp_aggregate_info(bn
);
3805 if (!aggregate
->rmap
.name
3806 || (strcmp(rmap_name
, aggregate
->rmap
.name
) != 0))
3809 if (!aggregate
->rmap
.map
)
3810 route_map_counter_increment(map
);
3812 aggregate
->rmap
.map
= map
;
3815 const struct prefix
*bn_p
=
3816 bgp_node_get_prefix(bn
);
3818 if (bgp_debug_zebra(bn_p
))
3820 "Processing route_map %s update on aggregate-address route %s",
3822 inet_ntop(bn_p
->family
,
3823 &bn_p
->u
.prefix
, buf
,
3825 bgp_aggregate_route(bgp
, bn_p
, afi
, safi
,
3831 /* For redistribute route-map updates. */
3832 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3833 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3834 struct list
*red_list
;
3835 struct bgp_redist
*red
;
3837 red_list
= bgp
->redist
[afi
][i
];
3841 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3843 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3847 route_map_counter_increment(map
);
3849 red
->rmap
.map
= map
;
3854 if (BGP_DEBUG(zebra
, ZEBRA
))
3856 "Processing route_map %s update on redistributed routes",
3859 bgp_redistribute_resend(bgp
, afi
, i
,
3864 /* for type5 command route-maps */
3865 FOREACH_AFI_SAFI (afi
, safi
) {
3866 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3867 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3871 /* Make sure the route-map is populated here if not already done */
3872 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3874 if (BGP_DEBUG(zebra
, ZEBRA
))
3876 "Processing route_map %s update on advertise type5 route command",
3879 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3880 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3881 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3886 static void bgp_route_map_process_update_cb(char *rmap_name
)
3888 struct listnode
*node
, *nnode
;
3891 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3892 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3894 #ifdef ENABLE_BGP_VNC
3895 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3896 vnc_routemap_update(bgp
, __func__
);
3900 vpn_policy_routemap_event(rmap_name
);
3903 int bgp_route_map_update_timer(struct thread
*thread
)
3905 bm
->t_rmap_update
= NULL
;
3907 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3912 static void bgp_route_map_mark_update(const char *rmap_name
)
3914 struct listnode
*node
, *nnode
;
3917 /* If new update is received before the current timer timed out,
3918 * turn it off and start a new timer.
3920 if (bm
->t_rmap_update
!= NULL
)
3921 THREAD_OFF(bm
->t_rmap_update
);
3923 /* rmap_update_timer of 0 means don't do route updates */
3924 if (bm
->rmap_update_timer
) {
3925 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3926 NULL
, bm
->rmap_update_timer
,
3927 &bm
->t_rmap_update
);
3929 /* Signal the groups that a route-map update event has
3931 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3932 update_group_policy_update(bgp
,
3933 BGP_POLICY_ROUTE_MAP
,
3936 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3937 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3938 #ifdef ENABLE_BGP_VNC
3939 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3940 vnc_routemap_update(bgp
, __func__
);
3945 static void bgp_route_map_add(const char *rmap_name
)
3947 if (route_map_mark_updated(rmap_name
) == 0)
3948 bgp_route_map_mark_update(rmap_name
);
3950 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3953 static void bgp_route_map_delete(const char *rmap_name
)
3955 if (route_map_mark_updated(rmap_name
) == 0)
3956 bgp_route_map_mark_update(rmap_name
);
3958 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3961 static void bgp_route_map_event(const char *rmap_name
)
3963 if (route_map_mark_updated(rmap_name
) == 0)
3964 bgp_route_map_mark_update(rmap_name
);
3966 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3969 DEFUN (match_mac_address
,
3970 match_mac_address_cmd
,
3971 "match mac address WORD",
3974 "Match address of route\n"
3975 "MAC Access-list name\n")
3977 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3978 RMAP_EVENT_FILTER_ADDED
);
3981 DEFUN (no_match_mac_address
,
3982 no_match_mac_address_cmd
,
3983 "no match mac address WORD",
3987 "Match address of route\n"
3988 "MAC acess-list name\n")
3990 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3991 RMAP_EVENT_FILTER_DELETED
);
3994 DEFUN (match_evpn_route_type
,
3995 match_evpn_route_type_cmd
,
3996 "match evpn route-type <macip | multicast | prefix>",
3999 "Match route-type\n"
4004 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
4005 RMAP_EVENT_MATCH_ADDED
);
4008 DEFUN (no_match_evpn_route_type
,
4009 no_match_evpn_route_type_cmd
,
4010 "no match evpn route-type <macip | multicast | prefix>",
4014 "Match route-type\n"
4019 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
4020 RMAP_EVENT_MATCH_DELETED
);
4024 DEFUN (match_evpn_vni
,
4026 "match evpn vni " CMD_VNI_RANGE
,
4032 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
4033 RMAP_EVENT_MATCH_ADDED
);
4036 DEFUN (no_match_evpn_vni
,
4037 no_match_evpn_vni_cmd
,
4038 "no match evpn vni " CMD_VNI_RANGE
,
4045 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
4046 RMAP_EVENT_MATCH_DELETED
);
4049 DEFUN (match_evpn_default_route
,
4050 match_evpn_default_route_cmd
,
4051 "match evpn default-route",
4054 "default EVPN type-5 route\n")
4056 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
4057 RMAP_EVENT_MATCH_ADDED
);
4060 DEFUN (no_match_evpn_default_route
,
4061 no_match_evpn_default_route_cmd
,
4062 "no match evpn default-route",
4066 "default EVPN type-5 route\n")
4068 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
4069 RMAP_EVENT_MATCH_DELETED
);
4072 DEFUN (match_evpn_rd
,
4074 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4077 "Route Distinguisher\n"
4078 "ASN:XX or A.B.C.D:XX\n")
4080 return bgp_route_match_add(vty
, "evpn rd", argv
[3]->arg
,
4081 RMAP_EVENT_MATCH_ADDED
);
4084 DEFUN (no_match_evpn_rd
,
4085 no_match_evpn_rd_cmd
,
4086 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
4090 "Route Distinguisher\n"
4091 "ASN:XX or A.B.C.D:XX\n")
4093 return bgp_route_match_delete(vty
, "evpn rd", argv
[4]->arg
,
4094 RMAP_EVENT_MATCH_DELETED
);
4097 DEFPY(match_vrl_source_vrf
,
4098 match_vrl_source_vrf_cmd
,
4099 "match source-vrf NAME$vrf_name",
4104 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
4105 RMAP_EVENT_MATCH_ADDED
);
4108 DEFPY(no_match_vrl_source_vrf
,
4109 no_match_vrl_source_vrf_cmd
,
4110 "no match source-vrf NAME$vrf_name",
4116 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
4117 RMAP_EVENT_MATCH_DELETED
);
4122 "match peer <A.B.C.D|X:X::X:X|WORD>",
4124 "Match peer address\n"
4125 "IP address of peer\n"
4126 "IPv6 address of peer\n"
4127 "Interface name of peer\n")
4130 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
4131 RMAP_EVENT_MATCH_ADDED
);
4134 DEFUN (match_peer_local
,
4135 match_peer_local_cmd
,
4138 "Match peer address\n"
4139 "Static or Redistributed routes\n")
4141 return bgp_route_match_add(vty
, "peer", "local",
4142 RMAP_EVENT_MATCH_DELETED
);
4145 DEFUN (no_match_peer
,
4147 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
4150 "Match peer address\n"
4151 "Static or Redistributed routes\n"
4152 "IP address of peer\n"
4153 "IPv6 address of peer\n"
4154 "Interface name of peer\n")
4158 if (argc
<= idx_peer
)
4159 return bgp_route_match_delete(vty
, "peer", NULL
,
4160 RMAP_EVENT_MATCH_DELETED
);
4161 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
4162 RMAP_EVENT_MATCH_DELETED
);
4165 #if defined(HAVE_LUA)
4166 DEFUN (match_command
,
4168 "match command WORD",
4170 "Run a command to match\n"
4171 "The command to run\n")
4173 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
4174 RMAP_EVENT_FILTER_ADDED
);
4177 DEFUN (no_match_command
,
4178 no_match_command_cmd
,
4179 "no match command WORD",
4182 "Run a command to match\n"
4183 "The command to run\n")
4185 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
4186 RMAP_EVENT_FILTER_DELETED
);
4190 /* match probability */
4191 DEFUN (match_probability
,
4192 match_probability_cmd
,
4193 "match probability (0-100)",
4195 "Match portion of routes defined by percentage value\n"
4196 "Percentage of routes\n")
4199 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
4200 RMAP_EVENT_MATCH_ADDED
);
4204 DEFUN (no_match_probability
,
4205 no_match_probability_cmd
,
4206 "no match probability [(1-99)]",
4209 "Match portion of routes defined by percentage value\n"
4210 "Percentage of routes\n")
4213 if (argc
<= idx_number
)
4214 return bgp_route_match_delete(vty
, "probability", NULL
,
4215 RMAP_EVENT_MATCH_DELETED
);
4216 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
4217 RMAP_EVENT_MATCH_DELETED
);
4221 DEFUN (match_ip_route_source
,
4222 match_ip_route_source_cmd
,
4223 "match ip route-source <(1-199)|(1300-2699)|WORD>",
4226 "Match advertising source address of route\n"
4227 "IP access-list number\n"
4228 "IP access-list number (expanded range)\n"
4229 "IP standard access-list name\n")
4232 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
4233 RMAP_EVENT_FILTER_ADDED
);
4237 DEFUN (no_match_ip_route_source
,
4238 no_match_ip_route_source_cmd
,
4239 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
4243 "Match advertising source address of route\n"
4244 "IP access-list number\n"
4245 "IP access-list number (expanded range)\n"
4246 "IP standard access-list name\n")
4249 if (argc
<= idx_number
)
4250 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
4251 RMAP_EVENT_FILTER_DELETED
);
4252 return bgp_route_match_delete(vty
, "ip route-source",
4253 argv
[idx_number
]->arg
,
4254 RMAP_EVENT_FILTER_DELETED
);
4258 DEFUN (match_ip_route_source_prefix_list
,
4259 match_ip_route_source_prefix_list_cmd
,
4260 "match ip route-source prefix-list WORD",
4263 "Match advertising source address of route\n"
4264 "Match entries of prefix-lists\n"
4265 "IP prefix-list name\n")
4268 return bgp_route_match_add(vty
, "ip route-source prefix-list",
4269 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
4273 DEFUN (no_match_ip_route_source_prefix_list
,
4274 no_match_ip_route_source_prefix_list_cmd
,
4275 "no match ip route-source prefix-list [WORD]",
4279 "Match advertising source address of route\n"
4280 "Match entries of prefix-lists\n"
4281 "IP prefix-list name\n")
4284 if (argc
<= idx_word
)
4285 return bgp_route_match_delete(vty
,
4286 "ip route-source prefix-list",
4287 NULL
, RMAP_EVENT_PLIST_DELETED
);
4288 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
4289 argv
[idx_word
]->arg
,
4290 RMAP_EVENT_PLIST_DELETED
);
4294 DEFUN (match_local_pref
,
4295 match_local_pref_cmd
,
4296 "match local-preference (0-4294967295)",
4298 "Match local-preference of route\n"
4302 return bgp_route_match_add(vty
, "local-preference",
4303 argv
[idx_number
]->arg
,
4304 RMAP_EVENT_MATCH_ADDED
);
4308 DEFUN (no_match_local_pref
,
4309 no_match_local_pref_cmd
,
4310 "no match local-preference [(0-4294967295)]",
4313 "Match local preference of route\n"
4314 "Local preference value\n")
4316 int idx_localpref
= 3;
4317 if (argc
<= idx_localpref
)
4318 return bgp_route_match_delete(vty
, "local-preference", NULL
,
4319 RMAP_EVENT_MATCH_DELETED
);
4320 return bgp_route_match_delete(vty
, "local-preference",
4321 argv
[idx_localpref
]->arg
,
4322 RMAP_EVENT_MATCH_DELETED
);
4326 DEFUN (match_community
,
4327 match_community_cmd
,
4328 "match community <(1-99)|(100-500)|WORD> [exact-match]",
4330 "Match BGP community list\n"
4331 "Community-list number (standard)\n"
4332 "Community-list number (expanded)\n"
4333 "Community-list name\n"
4334 "Do exact matching of communities\n")
4336 int idx_comm_list
= 2;
4341 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4342 strlen(argv
[idx_comm_list
]->arg
)
4343 + strlen("exact-match") + 2);
4345 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
4347 argstr
= argv
[idx_comm_list
]->arg
;
4349 ret
= bgp_route_match_add(vty
, "community", argstr
,
4350 RMAP_EVENT_CLIST_ADDED
);
4352 if (argstr
!= argv
[idx_comm_list
]->arg
)
4353 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4358 DEFUN (no_match_community
,
4359 no_match_community_cmd
,
4360 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
4363 "Match BGP community list\n"
4364 "Community-list number (standard)\n"
4365 "Community-list number (expanded)\n"
4366 "Community-list name\n"
4367 "Do exact matching of communities\n")
4369 return bgp_route_match_delete(vty
, "community", NULL
,
4370 RMAP_EVENT_CLIST_DELETED
);
4373 DEFUN (match_lcommunity
,
4374 match_lcommunity_cmd
,
4375 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
4377 "Match BGP large community list\n"
4378 "Large Community-list number (standard)\n"
4379 "Large Community-list number (expanded)\n"
4380 "Large Community-list name\n"
4381 "Do exact matching of communities\n")
4383 int idx_lcomm_list
= 2;
4388 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4389 strlen(argv
[idx_lcomm_list
]->arg
)
4390 + strlen("exact-match") + 2);
4392 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
4394 argstr
= argv
[idx_lcomm_list
]->arg
;
4396 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
4397 RMAP_EVENT_LLIST_ADDED
);
4398 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
4399 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4404 DEFUN (no_match_lcommunity
,
4405 no_match_lcommunity_cmd
,
4406 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
4409 "Match BGP large community list\n"
4410 "Large Community-list number (standard)\n"
4411 "Large Community-list number (expanded)\n"
4412 "Large Community-list name\n"
4413 "Do exact matching of communities\n")
4415 return bgp_route_match_delete(vty
, "large-community", NULL
,
4416 RMAP_EVENT_LLIST_DELETED
);
4419 DEFUN (match_ecommunity
,
4420 match_ecommunity_cmd
,
4421 "match extcommunity <(1-99)|(100-500)|WORD>",
4423 "Match BGP/VPN extended community list\n"
4424 "Extended community-list number (standard)\n"
4425 "Extended community-list number (expanded)\n"
4426 "Extended community-list name\n")
4428 int idx_comm_list
= 2;
4429 return bgp_route_match_add(vty
, "extcommunity",
4430 argv
[idx_comm_list
]->arg
,
4431 RMAP_EVENT_ECLIST_ADDED
);
4435 DEFUN (no_match_ecommunity
,
4436 no_match_ecommunity_cmd
,
4437 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
4440 "Match BGP/VPN extended community list\n"
4441 "Extended community-list number (standard)\n"
4442 "Extended community-list number (expanded)\n"
4443 "Extended community-list name\n")
4445 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
4446 RMAP_EVENT_ECLIST_DELETED
);
4450 DEFUN (match_aspath
,
4452 "match as-path WORD",
4454 "Match BGP AS path list\n"
4455 "AS path access-list name\n")
4458 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
4459 RMAP_EVENT_ASLIST_ADDED
);
4463 DEFUN (no_match_aspath
,
4464 no_match_aspath_cmd
,
4465 "no match as-path [WORD]",
4468 "Match BGP AS path list\n"
4469 "AS path access-list name\n")
4471 return bgp_route_match_delete(vty
, "as-path", NULL
,
4472 RMAP_EVENT_ASLIST_DELETED
);
4476 DEFUN (match_origin
,
4478 "match origin <egp|igp|incomplete>",
4483 "unknown heritage\n")
4486 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4487 return bgp_route_match_add(vty
, "origin", "igp",
4488 RMAP_EVENT_MATCH_ADDED
);
4489 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4490 return bgp_route_match_add(vty
, "origin", "egp",
4491 RMAP_EVENT_MATCH_ADDED
);
4492 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4493 return bgp_route_match_add(vty
, "origin", "incomplete",
4494 RMAP_EVENT_MATCH_ADDED
);
4496 vty_out(vty
, "%% Invalid match origin type\n");
4497 return CMD_WARNING_CONFIG_FAILED
;
4501 DEFUN (no_match_origin
,
4502 no_match_origin_cmd
,
4503 "no match origin [<egp|igp|incomplete>]",
4509 "unknown heritage\n")
4511 return bgp_route_match_delete(vty
, "origin", NULL
,
4512 RMAP_EVENT_MATCH_DELETED
);
4515 DEFUN (set_table_id
,
4517 "set table (1-4294967295)",
4519 "export route to non-main kernel table\n"
4520 "Kernel routing table id\n")
4524 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4526 return generic_set_add(vty
, index
, "table", argv
[idx_id
]->arg
);
4529 DEFUN (no_set_table_id
,
4530 no_set_table_id_cmd
,
4534 "export route to non-main kernel table\n")
4536 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4538 return generic_set_delete(vty
, index
, "table", NULL
);
4541 DEFUN (set_ip_nexthop_peer
,
4542 set_ip_nexthop_peer_cmd
,
4543 "[no] set ip next-hop peer-address",
4547 "Next hop address\n"
4548 "Use peer address (for BGP only)\n")
4550 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4551 const char *) = strmatch(argv
[0]->text
, "no")
4552 ? generic_set_delete
4555 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4559 DEFUN (set_ip_nexthop_unchanged
,
4560 set_ip_nexthop_unchanged_cmd
,
4561 "[no] set ip next-hop unchanged",
4565 "Next hop address\n"
4566 "Don't modify existing Next hop address\n")
4568 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4569 const char *) = strmatch(argv
[0]->text
, "no")
4570 ? generic_set_delete
4573 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4577 DEFUN (set_distance
,
4579 "set distance (0-255)",
4581 "BGP Administrative Distance to use\n"
4586 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4587 "distance", argv
[idx_number
]->arg
);
4590 DEFUN (no_set_distance
,
4591 no_set_distance_cmd
,
4592 "no set distance [(0-255)]",
4594 "BGP Administrative Distance to use\n"
4597 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4601 DEFUN (set_local_pref
,
4603 "set local-preference WORD",
4605 "BGP local preference path attribute\n"
4606 "Preference value (0-4294967295)\n")
4609 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4610 "local-preference", argv
[idx_number
]->arg
);
4614 DEFUN (no_set_local_pref
,
4615 no_set_local_pref_cmd
,
4616 "no set local-preference [WORD]",
4619 "BGP local preference path attribute\n"
4620 "Preference value (0-4294967295)\n")
4622 int idx_localpref
= 3;
4623 if (argc
<= idx_localpref
)
4624 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4625 "local-preference", NULL
);
4626 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4627 "local-preference", argv
[idx_localpref
]->arg
);
4633 "set weight (0-4294967295)",
4635 "BGP weight for routing table\n"
4639 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4640 argv
[idx_number
]->arg
);
4644 DEFUN (no_set_weight
,
4646 "no set weight [(0-4294967295)]",
4649 "BGP weight for routing table\n"
4653 if (argc
<= idx_weight
)
4654 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4656 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4657 "weight", argv
[idx_weight
]->arg
);
4660 DEFUN (set_label_index
,
4661 set_label_index_cmd
,
4662 "set label-index (0-1048560)",
4664 "Label index to associate with the prefix\n"
4665 "Label index value\n")
4668 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4669 "label-index", argv
[idx_number
]->arg
);
4672 DEFUN (no_set_label_index
,
4673 no_set_label_index_cmd
,
4674 "no set label-index [(0-1048560)]",
4677 "Label index to associate with the prefix\n"
4678 "Label index value\n")
4680 int idx_label_index
= 3;
4681 if (argc
<= idx_label_index
)
4682 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4683 "label-index", NULL
);
4684 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4685 "label-index", argv
[idx_label_index
]->arg
);
4688 DEFUN (set_aspath_prepend_asn
,
4689 set_aspath_prepend_asn_cmd
,
4690 "set as-path prepend (1-4294967295)...",
4692 "Transform BGP AS_PATH attribute\n"
4693 "Prepend to the as-path\n"
4700 str
= argv_concat(argv
, argc
, idx_asn
);
4701 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4702 "as-path prepend", str
);
4703 XFREE(MTYPE_TMP
, str
);
4708 DEFUN (set_aspath_prepend_lastas
,
4709 set_aspath_prepend_lastas_cmd
,
4710 "set as-path prepend last-as (1-10)",
4712 "Transform BGP AS_PATH attribute\n"
4713 "Prepend to the as-path\n"
4714 "Use the peer's AS-number\n"
4715 "Number of times to insert\n")
4717 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4720 DEFUN (no_set_aspath_prepend
,
4721 no_set_aspath_prepend_cmd
,
4722 "no set as-path prepend [(1-4294967295)]",
4725 "Transform BGP AS_PATH attribute\n"
4726 "Prepend to the as-path\n"
4733 str
= argv_concat(argv
, argc
, idx_asn
);
4734 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4735 "as-path prepend", str
);
4736 XFREE(MTYPE_TMP
, str
);
4740 DEFUN (no_set_aspath_prepend_lastas
,
4741 no_set_aspath_prepend_lastas_cmd
,
4742 "no set as-path prepend last-as [(1-10)]",
4745 "Transform BGP AS_PATH attribute\n"
4746 "Prepend to the as-path\n"
4747 "Use the peers AS-number\n"
4748 "Number of times to insert\n")
4750 return no_set_aspath_prepend(self
, vty
, argc
, argv
);
4753 DEFUN (set_aspath_exclude
,
4754 set_aspath_exclude_cmd
,
4755 "set as-path exclude (1-4294967295)...",
4757 "Transform BGP AS-path attribute\n"
4758 "Exclude from the as-path\n"
4765 str
= argv_concat(argv
, argc
, idx_asn
);
4766 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4767 "as-path exclude", str
);
4768 XFREE(MTYPE_TMP
, str
);
4772 DEFUN (no_set_aspath_exclude
,
4773 no_set_aspath_exclude_cmd
,
4774 "no set as-path exclude (1-4294967295)...",
4777 "Transform BGP AS_PATH attribute\n"
4778 "Exclude from the as-path\n"
4785 str
= argv_concat(argv
, argc
, idx_asn
);
4786 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4787 "as-path exclude", str
);
4788 XFREE(MTYPE_TMP
, str
);
4792 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4793 "no set as-path exclude",
4795 "Transform BGP AS_PATH attribute\n"
4796 "Exclude from the as-path\n")
4798 DEFUN (set_community
,
4800 "set community AA:NN...",
4802 "BGP community attribute\n"
4810 struct community
*com
= NULL
;
4815 b
= buffer_new(1024);
4817 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4818 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4825 buffer_putc(b
, ' ');
4829 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4831 buffer_putstr(b
, "internet");
4834 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4836 buffer_putstr(b
, "local-AS");
4839 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4840 && strncmp(argv
[i
]->arg
, "no-advertise",
4841 strlen(argv
[i
]->arg
))
4843 buffer_putstr(b
, "no-advertise");
4846 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4847 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4849 buffer_putstr(b
, "no-export");
4852 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4853 strlen(argv
[i
]->arg
))
4855 buffer_putstr(b
, "graceful-shutdown");
4858 buffer_putstr(b
, argv
[i
]->arg
);
4860 buffer_putc(b
, '\0');
4862 /* Fetch result string then compile it to communities attribute. */
4863 str
= buffer_getstr(b
);
4867 com
= community_str2com(str
);
4868 XFREE(MTYPE_TMP
, str
);
4871 /* Can't compile user input into communities attribute. */
4873 vty_out(vty
, "%% Malformed communities attribute\n");
4874 return CMD_WARNING_CONFIG_FAILED
;
4877 /* Set communites attribute string. */
4878 str
= community_str(com
, false);
4881 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4882 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4883 strlcpy(argstr
, str
, argstr_sz
);
4884 strlcat(argstr
, " additive", argstr_sz
);
4885 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4886 "community", argstr
);
4887 XFREE(MTYPE_TMP
, argstr
);
4889 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4892 community_free(&com
);
4897 DEFUN (set_community_none
,
4898 set_community_none_cmd
,
4899 "set community none",
4901 "BGP community attribute\n"
4902 "No community attribute\n")
4904 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4905 "community", "none");
4908 DEFUN (no_set_community
,
4909 no_set_community_cmd
,
4910 "no set community AA:NN...",
4913 "BGP community attribute\n"
4916 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4920 ALIAS (no_set_community
,
4921 no_set_community_short_cmd
,
4925 "BGP community attribute\n")
4928 DEFUN (set_community_delete
,
4929 set_community_delete_cmd
,
4930 "set comm-list <(1-99)|(100-500)|WORD> delete",
4932 "set BGP community list (for deletion)\n"
4933 "Community-list number (standard)\n"
4934 "Community-list number (expanded)\n"
4935 "Community-list name\n"
4936 "Delete matching communities\n")
4938 int idx_comm_list
= 2;
4941 args
= argv_concat(argv
, argc
, idx_comm_list
);
4942 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4944 XFREE(MTYPE_TMP
, args
);
4949 DEFUN (no_set_community_delete
,
4950 no_set_community_delete_cmd
,
4951 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4954 "set BGP community list (for deletion)\n"
4955 "Community-list number (standard)\n"
4956 "Community-list number (expanded)\n"
4957 "Community-list name\n"
4958 "Delete matching communities\n")
4960 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4964 DEFUN (set_lcommunity
,
4966 "set large-community AA:BB:CC...",
4968 "BGP large community attribute\n"
4969 "Large Community number in aa:bb:cc format or additive\n")
4974 str
= argv_concat(argv
, argc
, 2);
4975 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4976 "large-community", str
);
4977 XFREE(MTYPE_TMP
, str
);
4982 DEFUN (set_lcommunity_none
,
4983 set_lcommunity_none_cmd
,
4984 "set large-community none",
4986 "BGP large community attribute\n"
4987 "No large community attribute\n")
4989 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4990 "large-community", "none");
4993 DEFUN (no_set_lcommunity
,
4994 no_set_lcommunity_cmd
,
4995 "no set large-community none",
4998 "BGP large community attribute\n"
4999 "No community attribute\n")
5001 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5002 "large-community", NULL
);
5005 DEFUN (no_set_lcommunity1
,
5006 no_set_lcommunity1_cmd
,
5007 "no set large-community AA:BB:CC...",
5010 "BGP large community attribute\n"
5011 "Large community in AA:BB:CC... format or additive\n")
5013 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5014 "large-community", NULL
);
5017 ALIAS (no_set_lcommunity1
,
5018 no_set_lcommunity1_short_cmd
,
5019 "no set large-community",
5022 "BGP large community attribute\n")
5024 DEFUN (set_lcommunity_delete
,
5025 set_lcommunity_delete_cmd
,
5026 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
5028 "set BGP large community list (for deletion)\n"
5029 "Large Community-list number (standard)\n"
5030 "Large Communitly-list number (expanded)\n"
5031 "Large Community-list name\n"
5032 "Delete matching large communities\n")
5034 int idx_lcomm_list
= 2;
5037 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
5038 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5039 "large-comm-list", args
);
5040 XFREE(MTYPE_TMP
, args
);
5045 DEFUN (no_set_lcommunity_delete
,
5046 no_set_lcommunity_delete_cmd
,
5047 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
5050 "set BGP large community list (for deletion)\n"
5051 "Large Community-list number (standard)\n"
5052 "Large Communitly-list number (expanded)\n"
5053 "Large Community-list name\n"
5054 "Delete matching large communities\n")
5056 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5057 "large-comm-list", NULL
);
5060 ALIAS (no_set_lcommunity_delete
,
5061 no_set_lcommunity_delete_short_cmd
,
5062 "no set large-comm-list",
5065 "set BGP large community list (for deletion)\n")
5067 DEFUN (set_ecommunity_rt
,
5068 set_ecommunity_rt_cmd
,
5069 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
5071 "BGP extended community attribute\n"
5072 "Route Target extended community\n"
5073 "VPN extended community\n")
5079 str
= argv_concat(argv
, argc
, idx_asn_nn
);
5080 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5081 "extcommunity rt", str
);
5082 XFREE(MTYPE_TMP
, str
);
5087 DEFUN (no_set_ecommunity_rt
,
5088 no_set_ecommunity_rt_cmd
,
5089 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
5092 "BGP extended community attribute\n"
5093 "Route Target extended community\n"
5094 "VPN extended community\n")
5096 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5097 "extcommunity rt", NULL
);
5100 ALIAS (no_set_ecommunity_rt
,
5101 no_set_ecommunity_rt_short_cmd
,
5102 "no set extcommunity rt",
5105 "BGP extended community attribute\n"
5106 "Route Target extended community\n")
5108 DEFUN (set_ecommunity_soo
,
5109 set_ecommunity_soo_cmd
,
5110 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
5112 "BGP extended community attribute\n"
5113 "Site-of-Origin extended community\n"
5114 "VPN extended community\n")
5120 str
= argv_concat(argv
, argc
, idx_asn_nn
);
5121 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5122 "extcommunity soo", str
);
5123 XFREE(MTYPE_TMP
, str
);
5128 DEFUN (no_set_ecommunity_soo
,
5129 no_set_ecommunity_soo_cmd
,
5130 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
5133 "BGP extended community attribute\n"
5134 "Site-of-Origin extended community\n"
5135 "VPN extended community\n")
5137 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5138 "extcommunity soo", NULL
);
5141 ALIAS (no_set_ecommunity_soo
,
5142 no_set_ecommunity_soo_short_cmd
,
5143 "no set extcommunity soo",
5146 "GP extended community attribute\n"
5147 "Site-of-Origin extended community\n")
5149 DEFUN (set_ecommunity_lb
,
5150 set_ecommunity_lb_cmd
,
5151 "set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
5153 "BGP extended community attribute\n"
5154 "Link bandwidth extended community\n"
5155 "Bandwidth value in Mbps\n"
5156 "Cumulative bandwidth of all multipaths (outbound-only)\n"
5157 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
5158 "Attribute is set as non-transitive\n")
5164 str
= argv_concat(argv
, argc
, idx_lb
);
5165 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5166 "extcommunity bandwidth", str
);
5167 XFREE(MTYPE_TMP
, str
);
5172 DEFUN (no_set_ecommunity_lb
,
5173 no_set_ecommunity_lb_cmd
,
5174 "no set extcommunity bandwidth <(1-25600)|cumulative|num-multipaths> [non-transitive]",
5177 "BGP extended community attribute\n"
5178 "Link bandwidth extended community\n"
5179 "Bandwidth value in Mbps\n"
5180 "Cumulative bandwidth of all multipaths (outbound-only)\n"
5181 "Internally computed bandwidth based on number of multipaths (outbound-only)\n"
5182 "Attribute is set as non-transitive\n")
5184 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5185 "extcommunity bandwidth", NULL
);
5188 ALIAS (no_set_ecommunity_lb
,
5189 no_set_ecommunity_lb_short_cmd
,
5190 "no set extcommunity bandwidth",
5193 "BGP extended community attribute\n"
5194 "Link bandwidth extended community\n")
5198 "set origin <egp|igp|incomplete>",
5203 "unknown heritage\n")
5206 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
5207 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5209 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
5210 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5212 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
5213 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5214 "origin", "incomplete");
5216 vty_out(vty
, "%% Invalid set origin type\n");
5217 return CMD_WARNING_CONFIG_FAILED
;
5221 DEFUN (no_set_origin
,
5223 "no set origin [<egp|igp|incomplete>]",
5229 "unknown heritage\n")
5231 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5236 DEFUN (set_atomic_aggregate
,
5237 set_atomic_aggregate_cmd
,
5238 "set atomic-aggregate",
5240 "BGP atomic aggregate attribute\n" )
5242 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5243 "atomic-aggregate", NULL
);
5246 DEFUN (no_set_atomic_aggregate
,
5247 no_set_atomic_aggregate_cmd
,
5248 "no set atomic-aggregate",
5251 "BGP atomic aggregate attribute\n" )
5253 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5254 "atomic-aggregate", NULL
);
5257 DEFUN (set_aggregator_as
,
5258 set_aggregator_as_cmd
,
5259 "set aggregator as (1-4294967295) A.B.C.D",
5261 "BGP aggregator attribute\n"
5262 "AS number of aggregator\n"
5264 "IP address of aggregator\n")
5269 struct in_addr address
;
5272 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
5274 vty_out(vty
, "Aggregator IP address is invalid\n");
5275 return CMD_WARNING_CONFIG_FAILED
;
5278 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
5279 strlen(argv
[idx_number
]->arg
)
5280 + strlen(argv
[idx_ipv4
]->arg
) + 2);
5282 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
5284 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5285 "aggregator as", argstr
);
5287 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
5293 DEFUN (no_set_aggregator_as
,
5294 no_set_aggregator_as_cmd
,
5295 "no set aggregator as [(1-4294967295) A.B.C.D]",
5298 "BGP aggregator attribute\n"
5299 "AS number of aggregator\n"
5301 "IP address of aggregator\n")
5306 struct in_addr address
;
5309 if (argc
<= idx_asn
)
5310 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5311 "aggregator as", NULL
);
5313 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
5315 vty_out(vty
, "Aggregator IP address is invalid\n");
5316 return CMD_WARNING_CONFIG_FAILED
;
5319 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
5320 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
5323 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
5325 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5326 "aggregator as", argstr
);
5328 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
5333 DEFUN (match_ipv6_next_hop
,
5334 match_ipv6_next_hop_cmd
,
5335 "match ipv6 next-hop X:X::X:X",
5338 "Match IPv6 next-hop address of route\n"
5339 "IPv6 address of next hop\n")
5342 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
5343 RMAP_EVENT_MATCH_ADDED
);
5346 DEFUN (no_match_ipv6_next_hop
,
5347 no_match_ipv6_next_hop_cmd
,
5348 "no match ipv6 next-hop X:X::X:X",
5352 "Match IPv6 next-hop address of route\n"
5353 "IPv6 address of next hop\n")
5356 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
5357 RMAP_EVENT_MATCH_DELETED
);
5360 DEFPY (match_ipv4_next_hop
,
5361 match_ipv4_next_hop_cmd
,
5362 "match ip next-hop address A.B.C.D",
5365 "Match IP next-hop address of route\n"
5367 "IP address of next-hop\n")
5371 return bgp_route_match_add(vty
, "ip next-hop address",
5372 argv
[idx_ipv4
]->arg
, RMAP_EVENT_MATCH_ADDED
);
5375 DEFPY (no_match_ipv4_next_hop
,
5376 no_match_ipv4_next_hop_cmd
,
5377 "no match ip next-hop address [A.B.C.D]",
5381 "Match IP next-hop address of route\n"
5383 "IP address of next-hop\n")
5385 return bgp_route_match_delete(vty
, "ip next-hop address", NULL
,
5386 RMAP_EVENT_MATCH_DELETED
);
5389 DEFUN (set_ipv6_nexthop_peer
,
5390 set_ipv6_nexthop_peer_cmd
,
5391 "set ipv6 next-hop peer-address",
5394 "Next hop address\n"
5395 "Use peer address (for BGP only)\n")
5397 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5398 "ipv6 next-hop peer-address", NULL
);
5401 DEFUN (no_set_ipv6_nexthop_peer
,
5402 no_set_ipv6_nexthop_peer_cmd
,
5403 "no set ipv6 next-hop peer-address",
5407 "IPv6 next-hop address\n"
5408 "Use peer address (for BGP only)\n")
5410 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5411 "ipv6 next-hop peer-address", NULL
);
5414 DEFUN (set_ipv6_nexthop_prefer_global
,
5415 set_ipv6_nexthop_prefer_global_cmd
,
5416 "set ipv6 next-hop prefer-global",
5419 "IPv6 next-hop address\n"
5420 "Prefer global over link-local if both exist\n")
5422 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5423 "ipv6 next-hop prefer-global", NULL
);
5427 DEFUN (no_set_ipv6_nexthop_prefer_global
,
5428 no_set_ipv6_nexthop_prefer_global_cmd
,
5429 "no set ipv6 next-hop prefer-global",
5433 "IPv6 next-hop address\n"
5434 "Prefer global over link-local if both exist\n")
5436 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5437 "ipv6 next-hop prefer-global", NULL
);
5440 DEFUN (set_ipv6_nexthop_global
,
5441 set_ipv6_nexthop_global_cmd
,
5442 "set ipv6 next-hop global X:X::X:X",
5445 "IPv6 next-hop address\n"
5446 "IPv6 global address\n"
5447 "IPv6 address of next hop\n")
5450 struct in6_addr addr
;
5453 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
5455 vty_out(vty
, "%% Malformed nexthop address\n");
5456 return CMD_WARNING_CONFIG_FAILED
;
5458 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
5459 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
5460 vty_out(vty
, "%% Invalid global nexthop address\n");
5461 return CMD_WARNING_CONFIG_FAILED
;
5464 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5465 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
5469 DEFUN (no_set_ipv6_nexthop_global
,
5470 no_set_ipv6_nexthop_global_cmd
,
5471 "no set ipv6 next-hop global X:X::X:X",
5475 "IPv6 next-hop address\n"
5476 "IPv6 global address\n"
5477 "IPv6 address of next hop\n")
5480 if (argc
<= idx_ipv6
)
5481 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5482 "ipv6 next-hop global", NULL
);
5483 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5484 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
5487 #ifdef KEEP_OLD_VPN_COMMANDS
5488 DEFUN (set_vpn_nexthop
,
5489 set_vpn_nexthop_cmd
,
5490 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5492 "VPNv4 information\n"
5493 "VPN next-hop address\n"
5494 "IP address of next hop\n"
5495 "VPNv6 information\n"
5496 "VPN next-hop address\n"
5497 "IPv6 address of next hop\n")
5503 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5505 return generic_set_add(
5506 vty
, VTY_GET_CONTEXT(route_map_index
),
5507 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5509 return generic_set_add(
5510 vty
, VTY_GET_CONTEXT(route_map_index
),
5511 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5516 DEFUN (no_set_vpn_nexthop
,
5517 no_set_vpn_nexthop_cmd
,
5518 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5521 "VPNv4 information\n"
5522 "VPN next-hop address\n"
5523 "IP address of next hop\n"
5524 "VPNv6 information\n"
5525 "VPN next-hop address\n"
5526 "IPv6 address of next hop\n")
5536 arg
= argv
[idx_ip
]->arg
;
5537 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5539 return generic_set_delete(
5540 vty
, VTY_GET_CONTEXT(route_map_index
),
5541 "ipv4 vpn next-hop", arg
);
5543 return generic_set_delete(
5544 vty
, VTY_GET_CONTEXT(route_map_index
),
5545 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5549 #endif /* KEEP_OLD_VPN_COMMANDS */
5551 DEFUN (set_ipx_vpn_nexthop
,
5552 set_ipx_vpn_nexthop_cmd
,
5553 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
5555 "IPv4 information\n"
5556 "IPv6 information\n"
5558 "VPN next-hop address\n"
5559 "IP address of next hop\n"
5560 "IPv6 address of next hop\n")
5566 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5568 return generic_set_add(
5569 vty
, VTY_GET_CONTEXT(route_map_index
),
5570 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5572 return generic_set_add(
5573 vty
, VTY_GET_CONTEXT(route_map_index
),
5574 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5579 DEFUN (no_set_ipx_vpn_nexthop
,
5580 no_set_ipx_vpn_nexthop_cmd
,
5581 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
5584 "IPv4 information\n"
5585 "IPv6 information\n"
5587 "VPN next-hop address\n"
5588 "IP address of next hop\n"
5589 "IPv6 address of next hop\n")
5599 arg
= argv
[idx_ip
]->arg
;
5600 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5602 return generic_set_delete(
5603 vty
, VTY_GET_CONTEXT(route_map_index
),
5604 "ipv4 vpn next-hop", arg
);
5606 return generic_set_delete(
5607 vty
, VTY_GET_CONTEXT(route_map_index
),
5608 "ipv6 vpn next-hop", arg
);
5613 DEFUN (set_originator_id
,
5614 set_originator_id_cmd
,
5615 "set originator-id A.B.C.D",
5617 "BGP originator ID attribute\n"
5618 "IP address of originator\n")
5621 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5622 "originator-id", argv
[idx_ipv4
]->arg
);
5626 DEFUN (no_set_originator_id
,
5627 no_set_originator_id_cmd
,
5628 "no set originator-id [A.B.C.D]",
5631 "BGP originator ID attribute\n"
5632 "IP address of originator\n")
5636 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
5638 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5639 "originator-id", arg
);
5643 /* Initialization of route map. */
5644 void bgp_route_map_init(void)
5648 route_map_add_hook(bgp_route_map_add
);
5649 route_map_delete_hook(bgp_route_map_delete
);
5650 route_map_event_hook(bgp_route_map_event
);
5652 route_map_match_interface_hook(generic_match_add
);
5653 route_map_no_match_interface_hook(generic_match_delete
);
5655 route_map_match_ip_address_hook(generic_match_add
);
5656 route_map_no_match_ip_address_hook(generic_match_delete
);
5658 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
5659 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
5661 route_map_match_ip_next_hop_hook(generic_match_add
);
5662 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
5664 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
5665 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5667 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5668 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5670 route_map_match_ipv6_address_hook(generic_match_add
);
5671 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5673 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5674 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5676 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5677 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5679 route_map_match_metric_hook(generic_match_add
);
5680 route_map_no_match_metric_hook(generic_match_delete
);
5682 route_map_match_tag_hook(generic_match_add
);
5683 route_map_no_match_tag_hook(generic_match_delete
);
5685 route_map_set_ip_nexthop_hook(generic_set_add
);
5686 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5688 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5689 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5691 route_map_set_metric_hook(generic_set_add
);
5692 route_map_no_set_metric_hook(generic_set_delete
);
5694 route_map_set_tag_hook(generic_set_add
);
5695 route_map_no_set_tag_hook(generic_set_delete
);
5697 route_map_install_match(&route_match_peer_cmd
);
5698 route_map_install_match(&route_match_local_pref_cmd
);
5699 #if defined(HAVE_LUA)
5700 route_map_install_match(&route_match_command_cmd
);
5702 route_map_install_match(&route_match_ip_address_cmd
);
5703 route_map_install_match(&route_match_ip_next_hop_cmd
);
5704 route_map_install_match(&route_match_ip_route_source_cmd
);
5705 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5706 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5707 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5708 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5709 route_map_install_match(&route_match_aspath_cmd
);
5710 route_map_install_match(&route_match_community_cmd
);
5711 route_map_install_match(&route_match_lcommunity_cmd
);
5712 route_map_install_match(&route_match_ecommunity_cmd
);
5713 route_map_install_match(&route_match_local_pref_cmd
);
5714 route_map_install_match(&route_match_metric_cmd
);
5715 route_map_install_match(&route_match_origin_cmd
);
5716 route_map_install_match(&route_match_probability_cmd
);
5717 route_map_install_match(&route_match_interface_cmd
);
5718 route_map_install_match(&route_match_tag_cmd
);
5719 route_map_install_match(&route_match_mac_address_cmd
);
5720 route_map_install_match(&route_match_evpn_vni_cmd
);
5721 route_map_install_match(&route_match_evpn_route_type_cmd
);
5722 route_map_install_match(&route_match_evpn_rd_cmd
);
5723 route_map_install_match(&route_match_evpn_default_route_cmd
);
5724 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5726 route_map_install_set(&route_set_table_id_cmd
);
5727 route_map_install_set(&route_set_ip_nexthop_cmd
);
5728 route_map_install_set(&route_set_local_pref_cmd
);
5729 route_map_install_set(&route_set_weight_cmd
);
5730 route_map_install_set(&route_set_label_index_cmd
);
5731 route_map_install_set(&route_set_metric_cmd
);
5732 route_map_install_set(&route_set_distance_cmd
);
5733 route_map_install_set(&route_set_aspath_prepend_cmd
);
5734 route_map_install_set(&route_set_aspath_exclude_cmd
);
5735 route_map_install_set(&route_set_origin_cmd
);
5736 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5737 route_map_install_set(&route_set_aggregator_as_cmd
);
5738 route_map_install_set(&route_set_community_cmd
);
5739 route_map_install_set(&route_set_community_delete_cmd
);
5740 route_map_install_set(&route_set_lcommunity_cmd
);
5741 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5742 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5743 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5744 route_map_install_set(&route_set_originator_id_cmd
);
5745 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5746 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5747 route_map_install_set(&route_set_ecommunity_lb_cmd
);
5748 route_map_install_set(&route_set_tag_cmd
);
5749 route_map_install_set(&route_set_label_index_cmd
);
5751 install_element(RMAP_NODE
, &match_peer_cmd
);
5752 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5753 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5754 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5755 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5756 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5757 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5758 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5759 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5760 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5761 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5762 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5763 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5764 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
5765 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
5766 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5767 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5768 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5769 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5771 install_element(RMAP_NODE
, &match_aspath_cmd
);
5772 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5773 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5774 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5775 install_element(RMAP_NODE
, &match_community_cmd
);
5776 install_element(RMAP_NODE
, &no_match_community_cmd
);
5777 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5778 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5779 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5780 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5781 install_element(RMAP_NODE
, &match_origin_cmd
);
5782 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5783 install_element(RMAP_NODE
, &match_probability_cmd
);
5784 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5786 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
5787 install_element(RMAP_NODE
, &set_table_id_cmd
);
5788 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5789 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5790 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5791 install_element(RMAP_NODE
, &set_distance_cmd
);
5792 install_element(RMAP_NODE
, &no_set_distance_cmd
);
5793 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5794 install_element(RMAP_NODE
, &set_weight_cmd
);
5795 install_element(RMAP_NODE
, &set_label_index_cmd
);
5796 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5797 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5798 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5799 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5800 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5801 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5802 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
5803 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5804 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5805 install_element(RMAP_NODE
, &set_origin_cmd
);
5806 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5807 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5808 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5809 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5810 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5811 install_element(RMAP_NODE
, &set_community_cmd
);
5812 install_element(RMAP_NODE
, &set_community_none_cmd
);
5813 install_element(RMAP_NODE
, &no_set_community_cmd
);
5814 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5815 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5816 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5817 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5818 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5819 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5820 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5821 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5822 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5823 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5824 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5825 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5826 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5827 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5828 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5829 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5830 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5831 install_element(RMAP_NODE
, &set_ecommunity_lb_cmd
);
5832 install_element(RMAP_NODE
, &no_set_ecommunity_lb_cmd
);
5833 install_element(RMAP_NODE
, &no_set_ecommunity_lb_short_cmd
);
5834 #ifdef KEEP_OLD_VPN_COMMANDS
5835 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5836 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5837 #endif /* KEEP_OLD_VPN_COMMANDS */
5838 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5839 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5840 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5841 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5843 route_map_install_match(&route_match_ipv6_address_cmd
);
5844 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5845 route_map_install_match(&route_match_ipv4_next_hop_cmd
);
5846 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5847 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5848 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5849 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5850 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5851 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5853 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5854 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5855 install_element(RMAP_NODE
, &match_ipv4_next_hop_cmd
);
5856 install_element(RMAP_NODE
, &no_match_ipv4_next_hop_cmd
);
5857 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5858 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5859 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5860 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5861 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5862 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5863 #if defined(HAVE_LUA)
5864 install_element(RMAP_NODE
, &match_command_cmd
);
5865 install_element(RMAP_NODE
, &no_match_command_cmd
);
5869 void bgp_route_map_terminate(void)
5871 /* ToDo: Cleanup all the used memory */