1 /* Route map function of bgpd.
2 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #ifdef HAVE_LIBPCREPOSIX
33 #include <pcreposix.h>
36 #endif /* HAVE_LIBPCREPOSIX */
38 #include "sockunion.h"
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_table.h"
45 #include "bgpd/bgp_attr.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_packet.h"
48 #include "bgpd/bgp_route.h"
49 #include "bgpd/bgp_zebra.h"
50 #include "bgpd/bgp_regex.h"
51 #include "bgpd/bgp_community.h"
52 #include "bgpd/bgp_clist.h"
53 #include "bgpd/bgp_filter.h"
54 #include "bgpd/bgp_mplsvpn.h"
55 #include "bgpd/bgp_ecommunity.h"
56 #include "bgpd/bgp_lcommunity.h"
57 #include "bgpd/bgp_vty.h"
58 #include "bgpd/bgp_debug.h"
59 #include "bgpd/bgp_evpn.h"
60 #include "bgpd/bgp_evpn_private.h"
61 #include "bgpd/bgp_evpn_vty.h"
62 #include "bgpd/bgp_mplsvpn.h"
63 #include "bgpd/bgp_pbr.h"
64 #include "bgpd/bgp_flowspec_util.h"
65 #include "bgpd/bgp_encap_types.h"
68 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
71 #ifndef VTYSH_EXTRACT_PL
72 #include "bgpd/bgp_routemap_clippy.c"
75 /* Memo of route-map commands.
84 ip route-source : Done
88 ipv6 route-source: (This will not be implemented by bgpd)
89 ipv6 prefix-list : Done
90 length : (This will not be implemented by bgpd)
92 route-type : (This will not be implemented by bgpd)
94 local-preference : Done
96 set as-path prepend : Done
98 automatic-tag : (This will not be implemented by bgpd)
100 large-community : Done
101 large-comm-list : Done
104 default : (This will not be implemented by bgpd)
105 interface : (This will not be implemented by bgpd)
106 ip default : (This will not be implemented by bgpd)
108 ip precedence : (This will not be implemented by bgpd)
109 ip tos : (This will not be implemented by bgpd)
110 level : (This will not be implemented by bgpd)
111 local-preference : Done
113 metric-type : Not yet
121 set ipv6 next-hop global: Done
122 set ipv6 next-hop prefer-global: Done
123 set ipv6 next-hop local : Done
124 set as-path exclude : Done
128 /* generic value manipulation to be shared in multiple rules */
130 #define RMAP_VALUE_SET 0
131 #define RMAP_VALUE_ADD 1
132 #define RMAP_VALUE_SUB 2
140 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
142 if (rv
->variable
== 0 && value
== rv
->value
)
148 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
153 switch (rv
->variable
) {
162 switch (rv
->action
) {
164 if (current
> UINT32_MAX
- value
)
166 return current
+ value
;
168 if (current
<= value
)
170 return current
- value
;
176 static void *route_value_compile(const char *arg
)
178 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
179 unsigned long larg
= 0;
181 struct rmap_value
*rv
;
184 action
= RMAP_VALUE_ADD
;
186 } else if (arg
[0] == '-') {
187 action
= RMAP_VALUE_SUB
;
191 if (all_digit(arg
)) {
193 larg
= strtoul(arg
, &endptr
, 10);
194 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
197 if (strcmp(arg
, "rtt") == 0)
203 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
211 static void route_value_free(void *rule
)
213 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
216 /* generic as path object to be shared in multiple rules */
218 static void *route_aspath_compile(const char *arg
)
220 struct aspath
*aspath
;
222 aspath
= aspath_str2aspath(arg
);
228 static void route_aspath_free(void *rule
)
230 struct aspath
*aspath
= rule
;
234 struct bgp_match_peer_compiled
{
239 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
241 /* Compares the peer specified in the 'match peer' clause with the peer
242 received in bgp_path_info->peer. If it is the same, or if the peer structure
243 received is a peer_group containing it, returns RMAP_MATCH. */
244 static enum route_map_cmd_result_t
245 route_match_peer(void *rule
, const struct prefix
*prefix
,
246 route_map_object_t type
, void *object
)
248 struct bgp_match_peer_compiled
*pc
;
250 union sockunion su_def
= {
251 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
252 struct peer_group
*group
;
254 struct listnode
*node
, *nnode
;
256 if (type
== RMAP_BGP
) {
259 peer
= ((struct bgp_path_info
*)object
)->peer
;
265 if (strcmp(peer
->conf_if
, pc
->interface
) == 0)
271 /* If su='0.0.0.0' (command 'match peer local'), and it's a
273 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
276 if (sockunion_same(su
, &su_def
)) {
278 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
279 || CHECK_FLAG(peer
->rmap_type
,
280 PEER_RMAP_TYPE_REDISTRIBUTE
)
281 || CHECK_FLAG(peer
->rmap_type
,
282 PEER_RMAP_TYPE_AGGREGATE
)
283 || CHECK_FLAG(peer
->rmap_type
,
284 PEER_RMAP_TYPE_DEFAULT
))
291 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
292 if (sockunion_same(su
, &peer
->su
))
298 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
300 if (sockunion_same(su
, &peer
->su
))
309 static void *route_match_peer_compile(const char *arg
)
311 struct bgp_match_peer_compiled
*pc
;
314 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
315 sizeof(struct bgp_match_peer_compiled
));
317 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
319 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
326 /* Free route map's compiled `ip address' value. */
327 static void route_match_peer_free(void *rule
)
329 struct bgp_match_peer_compiled
*pc
= rule
;
331 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
333 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
336 /* Route map commands for ip address matching. */
337 struct route_map_rule_cmd route_match_peer_cmd
= {"peer", route_match_peer
,
338 route_match_peer_compile
,
339 route_match_peer_free
};
341 #if defined(HAVE_LUA)
342 static enum route_map_cmd_result_t
343 route_match_command(void *rule
, const struct prefix
*prefix
,
344 route_map_object_t type
, void *object
)
346 int status
= RMAP_NOMATCH
;
347 u_int32_t locpref
= 0;
348 u_int32_t newlocpref
= 0;
349 enum lua_rm_status lrm_status
;
350 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
351 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
357 * Setup the prefix information to pass in
359 lua_setup_prefix_table(L
, prefix
);
361 zlog_debug("Set up prefix table");
363 * Setup the bgp_path_info information
366 lua_pushinteger(L
, path
->attr
->med
);
367 lua_setfield(L
, -2, "metric");
368 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
369 lua_setfield(L
, -2, "ifindex");
370 lua_pushstring(L
, path
->attr
->aspath
->str
);
371 lua_setfield(L
, -2, "aspath");
372 lua_pushinteger(L
, path
->attr
->local_pref
);
373 lua_setfield(L
, -2, "localpref");
374 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
375 lua_setglobal(L
, "nexthop");
377 zlog_debug("Set up nexthop information");
381 lrm_status
= lua_run_rm_rule(L
, rule
);
382 switch (lrm_status
) {
384 zlog_debug("RM_FAILURE");
387 zlog_debug("RM_NOMATCH");
389 case LUA_RM_MATCH_AND_CHANGE
:
390 zlog_debug("MATCH AND CHANGE");
391 lua_getglobal(L
, "nexthop");
392 path
->attr
->med
= get_integer(L
, "metric");
394 * This needs to be abstraced with the set function
396 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
397 locpref
= path
->attr
->local_pref
;
398 newlocpref
= get_integer(L
, "localpref");
399 if (newlocpref
!= locpref
) {
400 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
401 path
->attr
->local_pref
= newlocpref
;
406 zlog_debug("MATCH ONLY");
414 static void *route_match_command_compile(const char *arg
)
418 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
423 route_match_command_free(void *rule
)
425 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
428 struct route_map_rule_cmd route_match_command_cmd
= {
431 route_match_command_compile
,
432 route_match_command_free
436 /* `match ip address IP_ACCESS_LIST' */
438 /* Match function should return 1 if match is success else return
440 static enum route_map_cmd_result_t
441 route_match_ip_address(void *rule
, const struct prefix
*prefix
,
442 route_map_object_t type
, void *object
)
444 struct access_list
*alist
;
446 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
447 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
451 return (access_list_apply(alist
, prefix
) == FILTER_DENY
458 /* Route map `ip address' match statement. `arg' should be
460 static void *route_match_ip_address_compile(const char *arg
)
462 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
465 /* Free route map's compiled `ip address' value. */
466 static void route_match_ip_address_free(void *rule
)
468 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
471 /* Route map commands for ip address matching. */
472 struct route_map_rule_cmd route_match_ip_address_cmd
= {
473 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
474 route_match_ip_address_free
};
476 /* `match ip next-hop IP_ADDRESS' */
478 /* Match function return 1 if match is success else return zero. */
479 static enum route_map_cmd_result_t
480 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
,
481 route_map_object_t type
, void *object
)
483 struct access_list
*alist
;
484 struct bgp_path_info
*path
;
485 struct prefix_ipv4 p
;
487 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
490 p
.prefix
= path
->attr
->nexthop
;
491 p
.prefixlen
= IPV4_MAX_BITLEN
;
493 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
497 return (access_list_apply(alist
, &p
) == FILTER_DENY
504 /* Route map `ip next-hop' match statement. `arg' is
506 static void *route_match_ip_next_hop_compile(const char *arg
)
508 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
511 /* Free route map's compiled `ip address' value. */
512 static void route_match_ip_next_hop_free(void *rule
)
514 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
517 /* Route map commands for ip next-hop matching. */
518 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
519 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
520 route_match_ip_next_hop_free
};
522 /* `match ip route-source ACCESS-LIST' */
524 /* Match function return 1 if match is success else return zero. */
525 static enum route_map_cmd_result_t
526 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
,
527 route_map_object_t type
, void *object
)
529 struct access_list
*alist
;
530 struct bgp_path_info
*path
;
532 struct prefix_ipv4 p
;
534 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
538 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
542 p
.prefix
= peer
->su
.sin
.sin_addr
;
543 p
.prefixlen
= IPV4_MAX_BITLEN
;
545 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
549 return (access_list_apply(alist
, &p
) == FILTER_DENY
556 /* Route map `ip route-source' match statement. `arg' is
558 static void *route_match_ip_route_source_compile(const char *arg
)
560 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
563 /* Free route map's compiled `ip address' value. */
564 static void route_match_ip_route_source_free(void *rule
)
566 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
569 /* Route map commands for ip route-source matching. */
570 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
571 "ip route-source", route_match_ip_route_source
,
572 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
574 static enum route_map_cmd_result_t
575 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
576 const struct prefix
*p
)
579 struct bgp_pbr_entry_main api
;
581 memset(&api
, 0, sizeof(api
));
583 /* extract match from flowspec entries */
584 ret
= bgp_flowspec_match_rules_fill(
585 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
586 p
->u
.prefix_flowspec
.prefixlen
, &api
);
589 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
590 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
591 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
593 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
596 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
597 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
598 if (family2afi((&api
.src_prefix
)->family
) != afi
)
600 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
607 static enum route_map_cmd_result_t
608 route_match_address_prefix_list(void *rule
, afi_t afi
,
609 const struct prefix
*prefix
,
610 route_map_object_t type
, void *object
)
612 struct prefix_list
*plist
;
614 if (type
!= RMAP_BGP
)
617 plist
= prefix_list_lookup(afi
, (char *)rule
);
621 if (prefix
->family
== AF_FLOWSPEC
)
622 return route_match_prefix_list_flowspec(afi
, plist
,
624 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
628 static enum route_map_cmd_result_t
629 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
630 route_map_object_t type
, void *object
)
632 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, type
,
636 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
638 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
641 static void route_match_ip_address_prefix_list_free(void *rule
)
643 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
646 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
647 "ip address prefix-list", route_match_ip_address_prefix_list
,
648 route_match_ip_address_prefix_list_compile
,
649 route_match_ip_address_prefix_list_free
};
651 /* `match ip next-hop prefix-list PREFIX_LIST' */
653 static enum route_map_cmd_result_t
654 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
655 route_map_object_t type
, void *object
)
657 struct prefix_list
*plist
;
658 struct bgp_path_info
*path
;
659 struct prefix_ipv4 p
;
661 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
664 p
.prefix
= path
->attr
->nexthop
;
665 p
.prefixlen
= IPV4_MAX_BITLEN
;
667 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
671 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
678 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
680 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
683 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
685 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
688 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
689 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
690 route_match_ip_next_hop_prefix_list_compile
,
691 route_match_ip_next_hop_prefix_list_free
};
693 /* `match ip next-hop type <blackhole>' */
695 static enum route_map_cmd_result_t
696 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
697 route_map_object_t type
, void *object
)
699 struct bgp_path_info
*path
;
701 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
702 path
= (struct bgp_path_info
*)object
;
706 /* If nexthop interface's index can't be resolved and nexthop is
707 set to any address then mark it as type `blackhole`.
708 This logic works for matching kernel/static routes like:
709 `ip route add blackhole 10.0.0.1`. */
710 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
711 && !path
->attr
->nh_ifindex
)
717 static void *route_match_ip_next_hop_type_compile(const char *arg
)
719 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
722 static void route_match_ip_next_hop_type_free(void *rule
)
724 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
727 static struct route_map_rule_cmd route_match_ip_next_hop_type_cmd
= {
728 "ip next-hop type", route_match_ip_next_hop_type
,
729 route_match_ip_next_hop_type_compile
,
730 route_match_ip_next_hop_type_free
};
732 /* `match ip route-source prefix-list PREFIX_LIST' */
734 static enum route_map_cmd_result_t
735 route_match_ip_route_source_prefix_list(void *rule
,
736 const struct prefix
*prefix
,
737 route_map_object_t type
, void *object
)
739 struct prefix_list
*plist
;
740 struct bgp_path_info
*path
;
742 struct prefix_ipv4 p
;
744 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
748 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
752 p
.prefix
= peer
->su
.sin
.sin_addr
;
753 p
.prefixlen
= IPV4_MAX_BITLEN
;
755 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
759 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
766 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
768 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
771 static void route_match_ip_route_source_prefix_list_free(void *rule
)
773 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
776 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
777 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
778 route_match_ip_route_source_prefix_list_compile
,
779 route_match_ip_route_source_prefix_list_free
};
781 /* `match evpn default-route' */
783 /* Match function should return 1 if match is success else 0 */
784 static enum route_map_cmd_result_t
785 route_match_evpn_default_route(void *rule
, const struct prefix
*p
,
786 route_map_object_t type
, void *object
)
788 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
794 /* Route map commands for default-route matching. */
795 struct route_map_rule_cmd route_match_evpn_default_route_cmd
= {
796 "evpn default-route", route_match_evpn_default_route
, NULL
, NULL
};
798 /* `match mac address MAC_ACCESS_LIST' */
800 /* Match function should return 1 if match is success else return
802 static enum route_map_cmd_result_t
803 route_match_mac_address(void *rule
, const struct prefix
*prefix
,
804 route_map_object_t type
, void *object
)
806 struct access_list
*alist
;
809 if (type
== RMAP_BGP
) {
810 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
814 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
817 p
.family
= AF_ETHERNET
;
818 p
.prefixlen
= ETH_ALEN
* 8;
819 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
821 return (access_list_apply(alist
, &p
) == FILTER_DENY
829 /* Route map `mac address' match statement. `arg' should be
831 static void *route_match_mac_address_compile(const char *arg
)
833 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
836 /* Free route map's compiled `ip address' value. */
837 static void route_match_mac_address_free(void *rule
)
839 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
842 /* Route map commands for mac address matching. */
843 struct route_map_rule_cmd route_match_mac_address_cmd
= {
844 "mac address", route_match_mac_address
, route_match_mac_address_compile
,
845 route_match_mac_address_free
};
848 * Match function returns:
849 * ...RMAP_MATCH if match is found.
850 * ...RMAP_NOMATCH if match is not found.
851 * ...RMAP_NOOP to ignore this match check.
853 static enum route_map_cmd_result_t
854 route_match_vni(void *rule
, const struct prefix
*prefix
,
855 route_map_object_t type
, void *object
)
858 unsigned int label_cnt
= 0;
859 struct bgp_path_info
*path
= NULL
;
860 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
862 if (type
== RMAP_BGP
) {
863 vni
= *((vni_t
*)rule
);
864 path
= (struct bgp_path_info
*)object
;
867 * This rmap filter is valid for vxlan tunnel type only.
868 * For any other tunnel type, return noop to ignore
871 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
875 * Apply filter to type 1, 2, 5 routes only.
876 * Other route types do not have vni label.
878 if (evp
&& (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
&&
879 evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
&&
880 evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
883 if (path
->extra
== NULL
)
886 for ( ; label_cnt
< BGP_MAX_LABELS
&&
887 label_cnt
< path
->extra
->num_labels
; label_cnt
++) {
888 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
896 /* Route map `vni' match statement. */
897 static void *route_match_vni_compile(const char *arg
)
902 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
904 *vni
= strtoul(arg
, &end
, 10);
906 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
913 /* Free route map's compiled `vni' value. */
914 static void route_match_vni_free(void *rule
)
916 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
919 /* Route map commands for vni matching. */
920 struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
921 "evpn vni", route_match_vni
, route_match_vni_compile
,
922 route_match_vni_free
};
924 /* `match evpn route-type' */
926 /* Match function should return 1 if match is success else return
928 static enum route_map_cmd_result_t
929 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
,
930 route_map_object_t type
, void *object
)
932 uint8_t route_type
= 0;
934 if (type
== RMAP_BGP
) {
935 route_type
= *((uint8_t *)rule
);
937 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
944 /* Route map `route-type' match statement. */
945 static void *route_match_evpn_route_type_compile(const char *arg
)
947 uint8_t *route_type
= NULL
;
949 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
951 if (strncmp(arg
, "ma", 2) == 0)
952 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
953 else if (strncmp(arg
, "mu", 2) == 0)
954 *route_type
= BGP_EVPN_IMET_ROUTE
;
956 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
961 /* Free route map's compiled `route-type' value. */
962 static void route_match_evpn_route_type_free(void *rule
)
964 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
967 /* Route map commands for evpn route-type matching. */
968 struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
969 "evpn route-type", route_match_evpn_route_type
,
970 route_match_evpn_route_type_compile
, route_match_evpn_route_type_free
};
974 /* Match function should return 1 if match is success else return zero. */
975 static enum route_map_cmd_result_t
976 route_match_rd(void *rule
, const struct prefix
*prefix
,
977 route_map_object_t type
, void *object
)
979 struct prefix_rd
*prd_rule
= NULL
;
980 struct prefix_rd
*prd_route
= NULL
;
981 struct bgp_path_info
*path
= NULL
;
983 if (type
== RMAP_BGP
) {
984 if (prefix
->family
!= AF_EVPN
)
987 prd_rule
= (struct prefix_rd
*)rule
;
988 path
= (struct bgp_path_info
*)object
;
990 if (path
->net
== NULL
|| path
->net
->prn
== NULL
)
993 prd_route
= (struct prefix_rd
*)&path
->net
->prn
->p
;
994 if (memcmp(prd_route
->val
, prd_rule
->val
, ECOMMUNITY_SIZE
) == 0)
1001 /* Route map `rd' match statement. */
1002 static void *route_match_rd_compile(const char *arg
)
1004 struct prefix_rd
*prd
;
1007 prd
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct prefix_rd
));
1009 ret
= str2prefix_rd(arg
, prd
);
1011 XFREE(MTYPE_ROUTE_MAP_COMPILED
, prd
);
1018 /* Free route map's compiled `rd' value. */
1019 static void route_match_rd_free(void *rule
)
1021 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1024 /* Route map commands for rd matching. */
1025 struct route_map_rule_cmd route_match_evpn_rd_cmd
= {
1026 "evpn rd", route_match_rd
, route_match_rd_compile
,
1027 route_match_rd_free
};
1029 /* Route map commands for VRF route leak with source vrf matching */
1030 static enum route_map_cmd_result_t
1031 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1032 route_map_object_t type
, void *object
)
1034 struct bgp_path_info
*path
;
1037 if (type
== RMAP_BGP
) {
1039 path
= (struct bgp_path_info
*)object
;
1041 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1042 return RMAP_NOMATCH
;
1044 if (path
->extra
== NULL
)
1045 return RMAP_NOMATCH
;
1047 if (strncmp(vrf_name
, vrf_id_to_name(
1048 path
->extra
->bgp_orig
->vrf_id
), VRF_NAMSIZ
)
1053 return RMAP_NOMATCH
;
1056 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1058 uint8_t *vrf_name
= NULL
;
1060 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1065 /* Free route map's compiled `route-type' value. */
1066 static void route_match_vrl_source_vrf_free(void *rule
)
1068 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1071 struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1072 "source-vrf", route_match_vrl_source_vrf
,
1073 route_match_vrl_source_vrf_compile
,
1074 route_match_vrl_source_vrf_free
};
1076 /* `match local-preference LOCAL-PREF' */
1078 /* Match function return 1 if match is success else return zero. */
1079 static enum route_map_cmd_result_t
1080 route_match_local_pref(void *rule
, const struct prefix
*prefix
,
1081 route_map_object_t type
, void *object
)
1083 uint32_t *local_pref
;
1084 struct bgp_path_info
*path
;
1086 if (type
== RMAP_BGP
) {
1090 if (path
->attr
->local_pref
== *local_pref
)
1093 return RMAP_NOMATCH
;
1095 return RMAP_NOMATCH
;
1099 * Route map `match local-preference' match statement.
1100 * `arg' is local-pref value
1102 static void *route_match_local_pref_compile(const char *arg
)
1104 uint32_t *local_pref
;
1105 char *endptr
= NULL
;
1106 unsigned long tmpval
;
1108 /* Locpref value shoud be integer. */
1109 if (!all_digit(arg
))
1113 tmpval
= strtoul(arg
, &endptr
, 10);
1114 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1117 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1119 *local_pref
= tmpval
;
1123 /* Free route map's compiled `match local-preference' value. */
1124 static void route_match_local_pref_free(void *rule
)
1126 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1129 /* Route map commands for metric matching. */
1130 struct route_map_rule_cmd route_match_local_pref_cmd
= {
1131 "local-preference", route_match_local_pref
,
1132 route_match_local_pref_compile
, route_match_local_pref_free
};
1134 /* `match metric METRIC' */
1136 /* Match function return 1 if match is success else return zero. */
1137 static enum route_map_cmd_result_t
1138 route_match_metric(void *rule
, const struct prefix
*prefix
,
1139 route_map_object_t type
, void *object
)
1141 struct rmap_value
*rv
;
1142 struct bgp_path_info
*path
;
1144 if (type
== RMAP_BGP
) {
1147 return route_value_match(rv
, path
->attr
->med
);
1149 return RMAP_NOMATCH
;
1152 /* Route map commands for metric matching. */
1153 struct route_map_rule_cmd route_match_metric_cmd
= {
1154 "metric", route_match_metric
, route_value_compile
, route_value_free
,
1157 /* `match as-path ASPATH' */
1159 /* Match function for as-path match. I assume given object is */
1160 static enum route_map_cmd_result_t
1161 route_match_aspath(void *rule
, const struct prefix
*prefix
,
1162 route_map_object_t type
, void *object
)
1165 struct as_list
*as_list
;
1166 struct bgp_path_info
*path
;
1168 if (type
== RMAP_BGP
) {
1169 as_list
= as_list_lookup((char *)rule
);
1170 if (as_list
== NULL
)
1171 return RMAP_NOMATCH
;
1175 /* Perform match. */
1176 return ((as_list_apply(as_list
, path
->attr
->aspath
)
1181 return RMAP_NOMATCH
;
1184 /* Compile function for as-path match. */
1185 static void *route_match_aspath_compile(const char *arg
)
1187 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1190 /* Compile function for as-path match. */
1191 static void route_match_aspath_free(void *rule
)
1193 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1196 /* Route map commands for aspath matching. */
1197 struct route_map_rule_cmd route_match_aspath_cmd
= {
1198 "as-path", route_match_aspath
, route_match_aspath_compile
,
1199 route_match_aspath_free
};
1201 /* `match community COMMUNIY' */
1202 struct rmap_community
{
1208 /* Match function for community match. */
1209 static enum route_map_cmd_result_t
1210 route_match_community(void *rule
, const struct prefix
*prefix
,
1211 route_map_object_t type
, void *object
)
1213 struct community_list
*list
;
1214 struct bgp_path_info
*path
;
1215 struct rmap_community
*rcom
= rule
;
1217 if (type
== RMAP_BGP
) {
1221 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1223 COMMUNITY_LIST_MASTER
);
1225 return RMAP_NOMATCH
;
1228 if (community_list_exact_match(path
->attr
->community
,
1232 if (community_list_match(path
->attr
->community
, list
))
1236 return RMAP_NOMATCH
;
1239 /* Compile function for community match. */
1240 static void *route_match_community_compile(const char *arg
)
1242 struct rmap_community
*rcom
;
1246 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1248 p
= strchr(arg
, ' ');
1251 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1252 memcpy(rcom
->name
, arg
, len
);
1255 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1259 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1263 /* Compile function for community match. */
1264 static void route_match_community_free(void *rule
)
1266 struct rmap_community
*rcom
= rule
;
1268 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1269 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1273 * In routemap processing there is a need to add the
1274 * name as a rule_key in the dependency table. Routemap
1275 * lib is unaware of rule_key when exact-match clause
1276 * is in use. routemap lib uses the compiled output to
1277 * get the rule_key value.
1279 static void *route_match_get_community_key(void *rule
)
1281 struct rmap_community
*rcom
;
1288 /* Route map commands for community matching. */
1289 struct route_map_rule_cmd route_match_community_cmd
= {
1290 "community", route_match_community
, route_match_community_compile
,
1291 route_match_community_free
, route_match_get_community_key
};
1293 /* Match function for lcommunity match. */
1294 static enum route_map_cmd_result_t
1295 route_match_lcommunity(void *rule
, const struct prefix
*prefix
,
1296 route_map_object_t type
, void *object
)
1298 struct community_list
*list
;
1299 struct bgp_path_info
*path
;
1300 struct rmap_community
*rcom
= rule
;
1302 if (type
== RMAP_BGP
) {
1305 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1307 LARGE_COMMUNITY_LIST_MASTER
);
1309 return RMAP_NOMATCH
;
1312 if (lcommunity_list_exact_match(
1313 path
->attr
->lcommunity
,
1317 if (lcommunity_list_match(
1318 path
->attr
->lcommunity
,
1323 return RMAP_NOMATCH
;
1326 /* Compile function for community match. */
1327 static void *route_match_lcommunity_compile(const char *arg
)
1329 struct rmap_community
*rcom
;
1333 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1335 p
= strchr(arg
, ' ');
1338 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1339 memcpy(rcom
->name
, arg
, len
);
1342 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1346 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1350 /* Compile function for community match. */
1351 static void route_match_lcommunity_free(void *rule
)
1353 struct rmap_community
*rcom
= rule
;
1355 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1356 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1359 /* Route map commands for community matching. */
1360 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1361 "large-community", route_match_lcommunity
,
1362 route_match_lcommunity_compile
, route_match_lcommunity_free
,
1363 route_match_get_community_key
};
1366 /* Match function for extcommunity match. */
1367 static enum route_map_cmd_result_t
1368 route_match_ecommunity(void *rule
, const struct prefix
*prefix
,
1369 route_map_object_t type
, void *object
)
1371 struct community_list
*list
;
1372 struct bgp_path_info
*path
;
1373 struct rmap_community
*rcom
= rule
;
1375 if (type
== RMAP_BGP
) {
1378 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1380 EXTCOMMUNITY_LIST_MASTER
);
1382 return RMAP_NOMATCH
;
1384 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1387 return RMAP_NOMATCH
;
1390 /* Compile function for extcommunity match. */
1391 static void *route_match_ecommunity_compile(const char *arg
)
1393 struct rmap_community
*rcom
;
1395 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1396 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1397 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1402 /* Compile function for extcommunity match. */
1403 static void route_match_ecommunity_free(void *rule
)
1405 struct rmap_community
*rcom
= rule
;
1407 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1408 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1411 /* Route map commands for community matching. */
1412 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1413 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1414 route_match_ecommunity_free
};
1416 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1417 and `address-family vpnv4'. */
1419 /* `match origin' */
1420 static enum route_map_cmd_result_t
1421 route_match_origin(void *rule
, const struct prefix
*prefix
,
1422 route_map_object_t type
, void *object
)
1425 struct bgp_path_info
*path
;
1427 if (type
== RMAP_BGP
) {
1431 if (path
->attr
->origin
== *origin
)
1435 return RMAP_NOMATCH
;
1438 static void *route_match_origin_compile(const char *arg
)
1442 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1444 if (strcmp(arg
, "igp") == 0)
1446 else if (strcmp(arg
, "egp") == 0)
1454 /* Free route map's compiled `ip address' value. */
1455 static void route_match_origin_free(void *rule
)
1457 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1460 /* Route map commands for origin matching. */
1461 struct route_map_rule_cmd route_match_origin_cmd
= {
1462 "origin", route_match_origin
, route_match_origin_compile
,
1463 route_match_origin_free
};
1465 /* match probability { */
1467 static enum route_map_cmd_result_t
1468 route_match_probability(void *rule
, const struct prefix
*prefix
,
1469 route_map_object_t type
, void *object
)
1473 switch (*(long *)rule
) {
1479 if (r
< *(long *)rule
) {
1484 return RMAP_NOMATCH
;
1487 static void *route_match_probability_compile(const char *arg
)
1493 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1503 *lobule
= RAND_MAX
/ 100 * perc
;
1509 static void route_match_probability_free(void *rule
)
1511 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1514 struct route_map_rule_cmd route_match_probability_cmd
= {
1515 "probability", route_match_probability
, route_match_probability_compile
,
1516 route_match_probability_free
};
1518 /* `match interface IFNAME' */
1519 /* Match function should return 1 if match is success else return
1521 static enum route_map_cmd_result_t
1522 route_match_interface(void *rule
, const struct prefix
*prefix
,
1523 route_map_object_t type
, void *object
)
1525 struct interface
*ifp
;
1526 struct bgp_path_info
*path
;
1528 if (type
== RMAP_BGP
) {
1532 return RMAP_NOMATCH
;
1534 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1536 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1537 return RMAP_NOMATCH
;
1541 return RMAP_NOMATCH
;
1544 /* Route map `interface' match statement. `arg' should be
1546 static void *route_match_interface_compile(const char *arg
)
1548 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1551 /* Free route map's compiled `interface' value. */
1552 static void route_match_interface_free(void *rule
)
1554 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1557 /* Route map commands for ip address matching. */
1558 struct route_map_rule_cmd route_match_interface_cmd
= {
1559 "interface", route_match_interface
, route_match_interface_compile
,
1560 route_match_interface_free
};
1564 /* `set ip next-hop IP_ADDRESS' */
1566 /* Match function return 1 if match is success else return zero. */
1567 static enum route_map_cmd_result_t
1568 route_match_tag(void *rule
, const struct prefix
*prefix
,
1569 route_map_object_t type
, void *object
)
1572 struct bgp_path_info
*path
;
1574 if (type
== RMAP_BGP
) {
1578 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1581 return RMAP_NOMATCH
;
1585 /* Route map commands for tag matching. */
1586 static struct route_map_rule_cmd route_match_tag_cmd
= {
1587 "tag", route_match_tag
, route_map_rule_tag_compile
,
1588 route_map_rule_tag_free
,
1592 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1593 struct rmap_ip_nexthop_set
{
1594 struct in_addr
*address
;
1599 static enum route_map_cmd_result_t
1600 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
,
1601 route_map_object_t type
, void *object
)
1603 struct rmap_ip_nexthop_set
*rins
= rule
;
1604 struct bgp_path_info
*path
;
1607 if (type
!= RMAP_BGP
)
1610 if (prefix
->family
== AF_INET6
)
1616 if (rins
->unchanged
) {
1617 SET_FLAG(path
->attr
->rmap_change_flags
,
1618 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1619 } else if (rins
->peer_address
) {
1620 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1621 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1623 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1624 path
->attr
->nexthop
.s_addr
=
1625 sockunion2ip(peer
->su_remote
);
1626 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1627 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1628 /* The next hop value will be set as part of
1629 * packet rewrite. Set the flags here to indicate
1630 * that rewrite needs to be done.
1631 * Also, clear the value.
1633 SET_FLAG(path
->attr
->rmap_change_flags
,
1634 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1635 path
->attr
->nexthop
.s_addr
= 0;
1638 /* Set next hop value. */
1639 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1640 path
->attr
->nexthop
= *rins
->address
;
1641 SET_FLAG(path
->attr
->rmap_change_flags
,
1642 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1643 /* case for MP-BGP : MPLS VPN */
1644 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1645 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1651 /* Route map `ip nexthop' compile function. Given string is converted
1652 to struct in_addr structure. */
1653 static void *route_set_ip_nexthop_compile(const char *arg
)
1655 struct rmap_ip_nexthop_set
*rins
;
1656 struct in_addr
*address
= NULL
;
1657 int peer_address
= 0;
1661 if (strcmp(arg
, "peer-address") == 0)
1663 else if (strcmp(arg
, "unchanged") == 0)
1666 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1667 sizeof(struct in_addr
));
1668 ret
= inet_aton(arg
, address
);
1671 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1676 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1677 sizeof(struct rmap_ip_nexthop_set
));
1679 rins
->address
= address
;
1680 rins
->peer_address
= peer_address
;
1681 rins
->unchanged
= unchanged
;
1686 /* Free route map's compiled `ip nexthop' value. */
1687 static void route_set_ip_nexthop_free(void *rule
)
1689 struct rmap_ip_nexthop_set
*rins
= rule
;
1691 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1693 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1696 /* Route map commands for ip nexthop set. */
1697 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1698 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1699 route_set_ip_nexthop_free
};
1701 /* `set local-preference LOCAL_PREF' */
1703 /* Set local preference. */
1704 static enum route_map_cmd_result_t
1705 route_set_local_pref(void *rule
, const struct prefix
*prefix
,
1706 route_map_object_t type
, void *object
)
1708 struct rmap_value
*rv
;
1709 struct bgp_path_info
*path
;
1710 uint32_t locpref
= 0;
1712 if (type
== RMAP_BGP
) {
1713 /* Fetch routemap's rule information. */
1717 /* Set local preference value. */
1718 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1719 locpref
= path
->attr
->local_pref
;
1721 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1722 path
->attr
->local_pref
=
1723 route_value_adjust(rv
, locpref
, path
->peer
);
1729 /* Set local preference rule structure. */
1730 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1731 "local-preference", route_set_local_pref
, route_value_compile
,
1735 /* `set weight WEIGHT' */
1738 static enum route_map_cmd_result_t
1739 route_set_weight(void *rule
, const struct prefix
*prefix
,
1740 route_map_object_t type
, void *object
)
1742 struct rmap_value
*rv
;
1743 struct bgp_path_info
*path
;
1745 if (type
== RMAP_BGP
) {
1746 /* Fetch routemap's rule information. */
1750 /* Set weight value. */
1751 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1757 /* Set local preference rule structure. */
1758 struct route_map_rule_cmd route_set_weight_cmd
= {
1759 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1762 /* `set distance DISTANCE */
1763 static enum route_map_cmd_result_t
1764 route_set_distance(void *rule
, const struct prefix
*prefix
,
1765 route_map_object_t type
, void *object
)
1767 struct bgp_path_info
*path
= object
;
1768 struct rmap_value
*rv
= rule
;
1770 if (type
!= RMAP_BGP
)
1773 path
->attr
->distance
= rv
->value
;
1778 /* set distance rule structure */
1779 struct route_map_rule_cmd route_set_distance_cmd
= {
1782 route_value_compile
,
1786 /* `set metric METRIC' */
1788 /* Set metric to attribute. */
1789 static enum route_map_cmd_result_t
1790 route_set_metric(void *rule
, const struct prefix
*prefix
,
1791 route_map_object_t type
, void *object
)
1793 struct rmap_value
*rv
;
1794 struct bgp_path_info
*path
;
1797 if (type
== RMAP_BGP
) {
1798 /* Fetch routemap's rule information. */
1802 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1803 med
= path
->attr
->med
;
1805 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1806 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1811 /* Set metric rule structure. */
1812 struct route_map_rule_cmd route_set_metric_cmd
= {
1813 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1816 /* `set table (1-4294967295)' */
1818 static enum route_map_cmd_result_t
route_set_table_id(void *rule
,
1819 const struct prefix
*prefix
,
1820 route_map_object_t type
,
1823 struct rmap_value
*rv
;
1824 struct bgp_path_info
*path
;
1826 if (type
== RMAP_BGP
) {
1827 /* Fetch routemap's rule information. */
1831 path
->attr
->rmap_table_id
= rv
->value
;
1836 /* Set table_id rule structure. */
1837 static struct route_map_rule_cmd route_set_table_id_cmd
= {
1838 "table", route_set_table_id
,
1839 route_value_compile
, route_value_free
1842 /* `set as-path prepend ASPATH' */
1844 /* For AS path prepend mechanism. */
1845 static enum route_map_cmd_result_t
1846 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
,
1847 route_map_object_t type
, void *object
)
1849 struct aspath
*aspath
;
1851 struct bgp_path_info
*path
;
1853 if (type
== RMAP_BGP
) {
1856 if (path
->attr
->aspath
->refcnt
)
1857 new = aspath_dup(path
->attr
->aspath
);
1859 new = path
->attr
->aspath
;
1861 if ((uintptr_t)rule
> 10) {
1863 aspath_prepend(aspath
, new);
1865 as_t as
= aspath_leftmost(new);
1867 as
= path
->peer
->as
;
1868 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1871 path
->attr
->aspath
= new;
1877 static void *route_set_aspath_prepend_compile(const char *arg
)
1881 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1882 return (void *)(uintptr_t)num
;
1884 return route_aspath_compile(arg
);
1887 static void route_set_aspath_prepend_free(void *rule
)
1889 if ((uintptr_t)rule
> 10)
1890 route_aspath_free(rule
);
1894 /* Set as-path prepend rule structure. */
1895 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1896 "as-path prepend", route_set_aspath_prepend
,
1897 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1900 /* `set as-path exclude ASn' */
1902 /* For ASN exclude mechanism.
1903 * Iterate over ASns requested and filter them from the given AS_PATH one by
1905 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1907 static enum route_map_cmd_result_t
1908 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
,
1909 route_map_object_t type
, void *object
)
1911 struct aspath
*new_path
, *exclude_path
;
1912 struct bgp_path_info
*path
;
1914 if (type
== RMAP_BGP
) {
1915 exclude_path
= rule
;
1917 if (path
->attr
->aspath
->refcnt
)
1918 new_path
= aspath_dup(path
->attr
->aspath
);
1920 new_path
= path
->attr
->aspath
;
1921 path
->attr
->aspath
=
1922 aspath_filter_exclude(new_path
, exclude_path
);
1927 /* Set ASn exlude rule structure. */
1928 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1929 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1933 /* `set community COMMUNITY' */
1934 struct rmap_com_set
{
1935 struct community
*com
;
1940 /* For community set mechanism. */
1941 static enum route_map_cmd_result_t
1942 route_set_community(void *rule
, const struct prefix
*prefix
,
1943 route_map_object_t type
, void *object
)
1945 struct rmap_com_set
*rcs
;
1946 struct bgp_path_info
*path
;
1948 struct community
*new = NULL
;
1949 struct community
*old
;
1950 struct community
*merge
;
1952 if (type
== RMAP_BGP
) {
1956 old
= attr
->community
;
1960 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1961 attr
->community
= NULL
;
1962 /* See the longer comment down below. */
1963 if (old
&& old
->refcnt
== 0)
1964 community_free(&old
);
1968 /* "additive" case. */
1969 if (rcs
->additive
&& old
) {
1970 merge
= community_merge(community_dup(old
), rcs
->com
);
1972 new = community_uniq_sort(merge
);
1973 community_free(&merge
);
1975 new = community_dup(rcs
->com
);
1977 /* HACK: if the old community is not intern'd,
1978 * we should free it here, or all reference to it may be
1980 * Really need to cleanup attribute caching sometime.
1982 if (old
&& old
->refcnt
== 0)
1983 community_free(&old
);
1985 /* will be interned by caller if required */
1986 attr
->community
= new;
1988 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1994 /* Compile function for set community. */
1995 static void *route_set_community_compile(const char *arg
)
1997 struct rmap_com_set
*rcs
;
1998 struct community
*com
= NULL
;
2003 if (strcmp(arg
, "none") == 0)
2006 sp
= strstr(arg
, "additive");
2008 if (sp
&& sp
> arg
) {
2009 /* "additive" keyword is included. */
2014 com
= community_str2com(arg
);
2023 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2025 rcs
->additive
= additive
;
2031 /* Free function for set community. */
2032 static void route_set_community_free(void *rule
)
2034 struct rmap_com_set
*rcs
= rule
;
2037 community_free(&rcs
->com
);
2038 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2041 /* Set community rule structure. */
2042 struct route_map_rule_cmd route_set_community_cmd
= {
2043 "community", route_set_community
, route_set_community_compile
,
2044 route_set_community_free
,
2047 /* `set community COMMUNITY' */
2048 struct rmap_lcom_set
{
2049 struct lcommunity
*lcom
;
2055 /* For lcommunity set mechanism. */
2056 static enum route_map_cmd_result_t
2057 route_set_lcommunity(void *rule
, const struct prefix
*prefix
,
2058 route_map_object_t type
, void *object
)
2060 struct rmap_lcom_set
*rcs
;
2061 struct bgp_path_info
*path
;
2063 struct lcommunity
*new = NULL
;
2064 struct lcommunity
*old
;
2065 struct lcommunity
*merge
;
2067 if (type
== RMAP_BGP
) {
2071 old
= attr
->lcommunity
;
2076 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
2077 attr
->lcommunity
= NULL
;
2079 /* See the longer comment down below. */
2080 if (old
&& old
->refcnt
== 0)
2081 lcommunity_free(&old
);
2085 if (rcs
->additive
&& old
) {
2086 merge
= lcommunity_merge(lcommunity_dup(old
),
2089 new = lcommunity_uniq_sort(merge
);
2090 lcommunity_free(&merge
);
2092 new = lcommunity_dup(rcs
->lcom
);
2094 /* HACK: if the old large-community is not intern'd,
2095 * we should free it here, or all reference to it may be
2097 * Really need to cleanup attribute caching sometime.
2099 if (old
&& old
->refcnt
== 0)
2100 lcommunity_free(&old
);
2102 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2103 attr
->lcommunity
= new;
2105 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2111 /* Compile function for set community. */
2112 static void *route_set_lcommunity_compile(const char *arg
)
2114 struct rmap_lcom_set
*rcs
;
2115 struct lcommunity
*lcom
= NULL
;
2120 if (strcmp(arg
, "none") == 0)
2123 sp
= strstr(arg
, "additive");
2125 if (sp
&& sp
> arg
) {
2126 /* "additive" keyworkd is included. */
2131 lcom
= lcommunity_str2com(arg
);
2140 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2142 rcs
->additive
= additive
;
2148 /* Free function for set lcommunity. */
2149 static void route_set_lcommunity_free(void *rule
)
2151 struct rmap_lcom_set
*rcs
= rule
;
2154 lcommunity_free(&rcs
->lcom
);
2156 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2159 /* Set community rule structure. */
2160 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2161 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
2162 route_set_lcommunity_free
,
2165 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2167 /* For large community set mechanism. */
2168 static enum route_map_cmd_result_t
2169 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
,
2170 route_map_object_t type
, void *object
)
2172 struct community_list
*list
;
2173 struct lcommunity
*merge
;
2174 struct lcommunity
*new;
2175 struct lcommunity
*old
;
2176 struct bgp_path_info
*path
;
2177 struct rmap_community
*rcom
= rule
;
2179 if (type
== RMAP_BGP
) {
2184 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2186 LARGE_COMMUNITY_LIST_MASTER
);
2187 old
= path
->attr
->lcommunity
;
2190 merge
= lcommunity_list_match_delete(
2191 lcommunity_dup(old
), list
);
2192 new = lcommunity_uniq_sort(merge
);
2193 lcommunity_free(&merge
);
2195 /* HACK: if the old community is not intern'd,
2196 * we should free it here, or all reference to it may be
2198 * Really need to cleanup attribute caching sometime.
2200 if (old
->refcnt
== 0)
2201 lcommunity_free(&old
);
2203 if (new->size
== 0) {
2204 path
->attr
->lcommunity
= NULL
;
2205 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2206 BGP_ATTR_LARGE_COMMUNITIES
);
2207 lcommunity_free(&new);
2209 path
->attr
->lcommunity
= new;
2210 path
->attr
->flag
|= ATTR_FLAG_BIT(
2211 BGP_ATTR_LARGE_COMMUNITIES
);
2219 /* Compile function for set lcommunity. */
2220 static void *route_set_lcommunity_delete_compile(const char *arg
)
2222 struct rmap_community
*rcom
;
2226 frrstr_split(arg
, " ", &splits
, &num
);
2228 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2229 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2230 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2232 for (int i
= 0; i
< num
; i
++)
2233 XFREE(MTYPE_TMP
, splits
[i
]);
2234 XFREE(MTYPE_TMP
, splits
);
2239 /* Free function for set lcommunity. */
2240 static void route_set_lcommunity_delete_free(void *rule
)
2242 struct rmap_community
*rcom
= rule
;
2244 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2245 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2248 /* Set lcommunity rule structure. */
2249 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2250 "large-comm-list", route_set_lcommunity_delete
,
2251 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2255 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2257 /* For community set mechanism. */
2258 static enum route_map_cmd_result_t
2259 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2260 route_map_object_t type
, void *object
)
2262 struct community_list
*list
;
2263 struct community
*merge
;
2264 struct community
*new;
2265 struct community
*old
;
2266 struct bgp_path_info
*path
;
2267 struct rmap_community
*rcom
= rule
;
2269 if (type
== RMAP_BGP
) {
2274 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2276 COMMUNITY_LIST_MASTER
);
2277 old
= path
->attr
->community
;
2280 merge
= community_list_match_delete(community_dup(old
),
2282 new = community_uniq_sort(merge
);
2283 community_free(&merge
);
2285 /* HACK: if the old community is not intern'd,
2286 * we should free it here, or all reference to it may be
2288 * Really need to cleanup attribute caching sometime.
2290 if (old
->refcnt
== 0)
2291 community_free(&old
);
2293 if (new->size
== 0) {
2294 path
->attr
->community
= NULL
;
2296 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2297 community_free(&new);
2299 path
->attr
->community
= new;
2301 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2309 /* Compile function for set community. */
2310 static void *route_set_community_delete_compile(const char *arg
)
2312 struct rmap_community
*rcom
;
2316 frrstr_split(arg
, " ", &splits
, &num
);
2318 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2319 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2320 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2322 for (int i
= 0; i
< num
; i
++)
2323 XFREE(MTYPE_TMP
, splits
[i
]);
2324 XFREE(MTYPE_TMP
, splits
);
2329 /* Free function for set community. */
2330 static void route_set_community_delete_free(void *rule
)
2332 struct rmap_community
*rcom
= rule
;
2334 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2335 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2338 /* Set community rule structure. */
2339 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2340 "comm-list", route_set_community_delete
,
2341 route_set_community_delete_compile
, route_set_community_delete_free
,
2344 /* `set extcommunity rt COMMUNITY' */
2346 /* For community set mechanism. Used by _rt and _soo. */
2347 static enum route_map_cmd_result_t
2348 route_set_ecommunity(void *rule
, const struct prefix
*prefix
,
2349 route_map_object_t type
, void *object
)
2351 struct ecommunity
*ecom
;
2352 struct ecommunity
*new_ecom
;
2353 struct ecommunity
*old_ecom
;
2354 struct bgp_path_info
*path
;
2356 if (type
== RMAP_BGP
) {
2363 /* We assume additive for Extended Community. */
2364 old_ecom
= path
->attr
->ecommunity
;
2367 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2370 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2371 * bgp_update_receive()
2372 * ->refcnt = 0 => set by a previous route-map
2374 if (!old_ecom
->refcnt
)
2375 ecommunity_free(&old_ecom
);
2377 new_ecom
= ecommunity_dup(ecom
);
2379 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2380 path
->attr
->ecommunity
= new_ecom
;
2382 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2387 /* Compile function for set community. */
2388 static void *route_set_ecommunity_rt_compile(const char *arg
)
2390 struct ecommunity
*ecom
;
2392 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2395 return ecommunity_intern(ecom
);
2398 /* Free function for set community. Used by _rt and _soo */
2399 static void route_set_ecommunity_free(void *rule
)
2401 struct ecommunity
*ecom
= rule
;
2402 ecommunity_unintern(&ecom
);
2405 /* Set community rule structure. */
2406 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2407 "extcommunity rt", route_set_ecommunity
,
2408 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2411 /* `set extcommunity soo COMMUNITY' */
2413 /* Compile function for set community. */
2414 static void *route_set_ecommunity_soo_compile(const char *arg
)
2416 struct ecommunity
*ecom
;
2418 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2422 return ecommunity_intern(ecom
);
2425 /* Set community rule structure. */
2426 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2427 "extcommunity soo", route_set_ecommunity
,
2428 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2431 /* `set origin ORIGIN' */
2433 /* For origin set. */
2434 static enum route_map_cmd_result_t
2435 route_set_origin(void *rule
, const struct prefix
*prefix
,
2436 route_map_object_t type
, void *object
)
2439 struct bgp_path_info
*path
;
2441 if (type
== RMAP_BGP
) {
2445 path
->attr
->origin
= *origin
;
2451 /* Compile function for origin set. */
2452 static void *route_set_origin_compile(const char *arg
)
2456 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2458 if (strcmp(arg
, "igp") == 0)
2460 else if (strcmp(arg
, "egp") == 0)
2468 /* Compile function for origin set. */
2469 static void route_set_origin_free(void *rule
)
2471 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2474 /* Set origin rule structure. */
2475 struct route_map_rule_cmd route_set_origin_cmd
= {
2476 "origin", route_set_origin
, route_set_origin_compile
,
2477 route_set_origin_free
,
2480 /* `set atomic-aggregate' */
2482 /* For atomic aggregate set. */
2483 static enum route_map_cmd_result_t
2484 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
,
2485 route_map_object_t type
, void *object
)
2487 struct bgp_path_info
*path
;
2489 if (type
== RMAP_BGP
) {
2491 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2497 /* Compile function for atomic aggregate. */
2498 static void *route_set_atomic_aggregate_compile(const char *arg
)
2503 /* Compile function for atomic aggregate. */
2504 static void route_set_atomic_aggregate_free(void *rule
)
2509 /* Set atomic aggregate rule structure. */
2510 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2511 "atomic-aggregate", route_set_atomic_aggregate
,
2512 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2515 /* `set aggregator as AS A.B.C.D' */
2518 struct in_addr address
;
2521 static enum route_map_cmd_result_t
2522 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
,
2523 route_map_object_t type
, void *object
)
2525 struct bgp_path_info
*path
;
2526 struct aggregator
*aggregator
;
2528 if (type
== RMAP_BGP
) {
2532 path
->attr
->aggregator_as
= aggregator
->as
;
2533 path
->attr
->aggregator_addr
= aggregator
->address
;
2534 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2540 static void *route_set_aggregator_as_compile(const char *arg
)
2542 struct aggregator
*aggregator
;
2548 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2549 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2550 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2554 aggregator
->as
= strtoul(as
, NULL
, 10);
2555 ret
= inet_aton(address
, &aggregator
->address
);
2557 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2563 static void route_set_aggregator_as_free(void *rule
)
2565 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2568 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2569 "aggregator as", route_set_aggregator_as
,
2570 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2573 /* Set tag to object. object must be pointer to struct bgp_path_info */
2574 static enum route_map_cmd_result_t
2575 route_set_tag(void *rule
, const struct prefix
*prefix
,
2576 route_map_object_t type
, void *object
)
2579 struct bgp_path_info
*path
;
2581 if (type
== RMAP_BGP
) {
2586 path
->attr
->tag
= *tag
;
2592 /* Route map commands for tag set. */
2593 static struct route_map_rule_cmd route_set_tag_cmd
= {
2594 "tag", route_set_tag
, route_map_rule_tag_compile
,
2595 route_map_rule_tag_free
,
2598 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2599 static enum route_map_cmd_result_t
2600 route_set_label_index(void *rule
, const struct prefix
*prefix
,
2601 route_map_object_t type
, void *object
)
2603 struct rmap_value
*rv
;
2604 struct bgp_path_info
*path
;
2605 uint32_t label_index
;
2607 if (type
== RMAP_BGP
) {
2608 /* Fetch routemap's rule information. */
2612 /* Set label-index value. */
2613 label_index
= rv
->value
;
2615 path
->attr
->label_index
= label_index
;
2616 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2623 /* Route map commands for label-index set. */
2624 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2625 "label-index", route_set_label_index
, route_value_compile
,
2629 /* `match ipv6 address IP_ACCESS_LIST' */
2631 static enum route_map_cmd_result_t
2632 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
,
2633 route_map_object_t type
, void *object
)
2635 struct access_list
*alist
;
2637 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2638 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2640 return RMAP_NOMATCH
;
2642 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2646 return RMAP_NOMATCH
;
2649 static void *route_match_ipv6_address_compile(const char *arg
)
2651 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2654 static void route_match_ipv6_address_free(void *rule
)
2656 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2659 /* Route map commands for ip address matching. */
2660 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2661 "ipv6 address", route_match_ipv6_address
,
2662 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2664 /* `match ipv6 next-hop IP_ADDRESS' */
2666 static enum route_map_cmd_result_t
2667 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
,
2668 route_map_object_t type
, void *object
)
2670 struct in6_addr
*addr
= rule
;
2671 struct bgp_path_info
*path
;
2673 if (type
== RMAP_BGP
) {
2676 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2679 if (path
->attr
->mp_nexthop_len
2680 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2681 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2684 return RMAP_NOMATCH
;
2687 return RMAP_NOMATCH
;
2690 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2692 struct in6_addr
*address
;
2695 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2697 ret
= inet_pton(AF_INET6
, arg
, address
);
2699 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2706 static void route_match_ipv6_next_hop_free(void *rule
)
2708 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2711 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2712 "ipv6 next-hop", route_match_ipv6_next_hop
,
2713 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2715 /* `match ipv6 address prefix-list PREFIX_LIST' */
2717 static enum route_map_cmd_result_t
2718 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2719 route_map_object_t type
, void *object
)
2721 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, type
,
2725 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2727 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2730 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2732 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2735 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2736 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2737 route_match_ipv6_address_prefix_list_compile
,
2738 route_match_ipv6_address_prefix_list_free
};
2740 /* `match ipv6 next-hop type <TYPE>' */
2742 static enum route_map_cmd_result_t
2743 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2744 route_map_object_t type
, void *object
)
2746 struct bgp_path_info
*path
;
2747 struct in6_addr
*addr
= rule
;
2749 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2750 path
= (struct bgp_path_info
*)object
;
2752 return RMAP_NOMATCH
;
2754 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2755 && !path
->attr
->nh_ifindex
)
2758 return RMAP_NOMATCH
;
2761 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2763 struct in6_addr
*address
;
2766 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2768 ret
= inet_pton(AF_INET6
, "::0", address
);
2770 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2777 static void route_match_ipv6_next_hop_type_free(void *rule
)
2779 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2782 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2783 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2784 route_match_ipv6_next_hop_type_compile
,
2785 route_match_ipv6_next_hop_type_free
};
2787 /* `set ipv6 nexthop global IP_ADDRESS' */
2789 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2790 static enum route_map_cmd_result_t
2791 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
,
2792 route_map_object_t type
, void *object
)
2794 struct in6_addr
*address
;
2795 struct bgp_path_info
*path
;
2797 if (type
== RMAP_BGP
) {
2798 /* Fetch routemap's rule information. */
2802 /* Set next hop value. */
2803 path
->attr
->mp_nexthop_global
= *address
;
2805 /* Set nexthop length. */
2806 if (path
->attr
->mp_nexthop_len
== 0)
2807 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2809 SET_FLAG(path
->attr
->rmap_change_flags
,
2810 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2816 /* Route map `ip next-hop' compile function. Given string is converted
2817 to struct in_addr structure. */
2818 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2821 struct in6_addr
*address
;
2823 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2825 ret
= inet_pton(AF_INET6
, arg
, address
);
2828 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2835 /* Free route map's compiled `ip next-hop' value. */
2836 static void route_set_ipv6_nexthop_global_free(void *rule
)
2838 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2841 /* Route map commands for ip nexthop set. */
2842 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2843 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2844 route_set_ipv6_nexthop_global_compile
,
2845 route_set_ipv6_nexthop_global_free
};
2847 /* Set next-hop preference value. */
2848 static enum route_map_cmd_result_t
2849 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2850 route_map_object_t type
, void *object
)
2852 struct bgp_path_info
*path
;
2855 if (type
== RMAP_BGP
) {
2856 /* Fetch routemap's rule information. */
2860 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2861 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
2862 /* Set next hop preference to global */
2863 path
->attr
->mp_nexthop_prefer_global
= true;
2864 SET_FLAG(path
->attr
->rmap_change_flags
,
2865 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2867 path
->attr
->mp_nexthop_prefer_global
= false;
2868 SET_FLAG(path
->attr
->rmap_change_flags
,
2869 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2875 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2879 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2885 /* Free route map's compiled `ip next-hop' value. */
2886 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2888 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2891 /* Route map commands for ip nexthop set preferred. */
2892 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2893 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2894 route_set_ipv6_nexthop_prefer_global_compile
,
2895 route_set_ipv6_nexthop_prefer_global_free
};
2897 /* `set ipv6 nexthop local IP_ADDRESS' */
2899 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2900 static enum route_map_cmd_result_t
2901 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
,
2902 route_map_object_t type
, void *object
)
2904 struct in6_addr
*address
;
2905 struct bgp_path_info
*path
;
2907 if (type
== RMAP_BGP
) {
2908 /* Fetch routemap's rule information. */
2912 /* Set next hop value. */
2913 path
->attr
->mp_nexthop_local
= *address
;
2915 /* Set nexthop length. */
2916 if (path
->attr
->mp_nexthop_len
2917 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2918 path
->attr
->mp_nexthop_len
=
2919 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2921 SET_FLAG(path
->attr
->rmap_change_flags
,
2922 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2928 /* Route map `ip nexthop' compile function. Given string is converted
2929 to struct in_addr structure. */
2930 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2933 struct in6_addr
*address
;
2935 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2937 ret
= inet_pton(AF_INET6
, arg
, address
);
2940 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2947 /* Free route map's compiled `ip nexthop' value. */
2948 static void route_set_ipv6_nexthop_local_free(void *rule
)
2950 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2953 /* Route map commands for ip nexthop set. */
2954 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2955 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2956 route_set_ipv6_nexthop_local_compile
,
2957 route_set_ipv6_nexthop_local_free
};
2959 /* `set ipv6 nexthop peer-address' */
2961 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2962 static enum route_map_cmd_result_t
2963 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
,
2964 route_map_object_t type
, void *object
)
2966 struct in6_addr peer_address
;
2967 struct bgp_path_info
*path
;
2970 if (type
== RMAP_BGP
) {
2971 /* Fetch routemap's rule information. */
2975 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2976 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2978 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2979 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2980 /* Set next hop value and length in attribute. */
2981 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2982 path
->attr
->mp_nexthop_local
= peer_address
;
2983 if (path
->attr
->mp_nexthop_len
2984 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2985 path
->attr
->mp_nexthop_len
=
2986 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2988 path
->attr
->mp_nexthop_global
= peer_address
;
2989 if (path
->attr
->mp_nexthop_len
== 0)
2990 path
->attr
->mp_nexthop_len
=
2991 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2994 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2995 /* The next hop value will be set as part of packet
2997 * Set the flags here to indicate that rewrite needs to
2999 * Also, clear the value - we clear both global and
3001 * nexthops, whether we send one or both is determined
3004 SET_FLAG(path
->attr
->rmap_change_flags
,
3005 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3006 /* clear next hop value. */
3007 memset(&(path
->attr
->mp_nexthop_global
), 0,
3008 sizeof(struct in6_addr
));
3009 memset(&(path
->attr
->mp_nexthop_local
), 0,
3010 sizeof(struct in6_addr
));
3017 /* Route map `ip next-hop' compile function. Given string is converted
3018 to struct in_addr structure. */
3019 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3023 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3029 /* Free route map's compiled `ip next-hop' value. */
3030 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3032 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3035 /* Route map commands for ip nexthop set. */
3036 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3037 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
3038 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
3040 /* `set ipv4 vpn next-hop A.B.C.D' */
3042 static enum route_map_cmd_result_t
3043 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
,
3044 route_map_object_t type
, void *object
)
3046 struct in_addr
*address
;
3047 struct bgp_path_info
*path
;
3049 if (type
== RMAP_BGP
) {
3050 /* Fetch routemap's rule information. */
3054 /* Set next hop value. */
3055 path
->attr
->mp_nexthop_global_in
= *address
;
3056 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3062 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3065 struct in_addr
*address
;
3067 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3069 ret
= inet_aton(arg
, address
);
3072 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3079 /* `set ipv6 vpn next-hop A.B.C.D' */
3081 static enum route_map_cmd_result_t
3082 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
,
3083 route_map_object_t type
, void *object
)
3085 struct in6_addr
*address
;
3086 struct bgp_path_info
*path
;
3088 if (type
== RMAP_BGP
) {
3089 /* Fetch routemap's rule information. */
3093 /* Set next hop value. */
3094 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3095 sizeof(struct in6_addr
));
3096 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3102 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3105 struct in6_addr
*address
;
3107 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3108 ret
= inet_pton(AF_INET6
, arg
, address
);
3111 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3118 static void route_set_vpn_nexthop_free(void *rule
)
3120 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3123 /* Route map commands for ipv4 next-hop set. */
3124 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3125 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
3126 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
3128 /* Route map commands for ipv6 next-hop set. */
3129 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3130 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
3131 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
3133 /* `set originator-id' */
3135 /* For origin set. */
3136 static enum route_map_cmd_result_t
3137 route_set_originator_id(void *rule
, const struct prefix
*prefix
,
3138 route_map_object_t type
, void *object
)
3140 struct in_addr
*address
;
3141 struct bgp_path_info
*path
;
3143 if (type
== RMAP_BGP
) {
3147 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3148 path
->attr
->originator_id
= *address
;
3154 /* Compile function for originator-id set. */
3155 static void *route_set_originator_id_compile(const char *arg
)
3158 struct in_addr
*address
;
3160 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3162 ret
= inet_aton(arg
, address
);
3165 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3172 /* Compile function for originator_id set. */
3173 static void route_set_originator_id_free(void *rule
)
3175 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3178 /* Set originator-id rule structure. */
3179 struct route_map_rule_cmd route_set_originator_id_cmd
= {
3180 "originator-id", route_set_originator_id
,
3181 route_set_originator_id_compile
, route_set_originator_id_free
,
3184 /* Add bgp route map rule. */
3185 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3186 const char *arg
, route_map_event_t type
)
3188 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3189 int retval
= CMD_SUCCESS
;
3190 enum rmap_compile_rets ret
;
3192 ret
= route_map_add_match(index
, command
, arg
, type
);
3194 case RMAP_RULE_MISSING
:
3195 vty_out(vty
, "%% BGP Can't find rule.\n");
3196 retval
= CMD_WARNING_CONFIG_FAILED
;
3198 case RMAP_COMPILE_ERROR
:
3199 vty_out(vty
, "%% BGP Argument is malformed.\n");
3200 retval
= CMD_WARNING_CONFIG_FAILED
;
3202 case RMAP_COMPILE_SUCCESS
:
3204 * Intentionally doing nothing here.
3212 /* Delete bgp route map rule. */
3213 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3214 const char *arg
, route_map_event_t type
)
3216 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3217 enum rmap_compile_rets ret
;
3218 int retval
= CMD_SUCCESS
;
3219 char *dep_name
= NULL
;
3221 char *rmap_name
= NULL
;
3223 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3224 /* ignore the mundane, the types without any dependency */
3226 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3229 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3231 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3233 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3236 ret
= route_map_delete_match(index
, command
, dep_name
, type
);
3238 case RMAP_RULE_MISSING
:
3239 vty_out(vty
, "%% BGP Can't find rule.\n");
3240 retval
= CMD_WARNING_CONFIG_FAILED
;
3242 case RMAP_COMPILE_ERROR
:
3243 vty_out(vty
, "%% BGP Argument is malformed.\n");
3244 retval
= CMD_WARNING_CONFIG_FAILED
;
3246 case RMAP_COMPILE_SUCCESS
:
3248 * Nothing to do here
3253 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3254 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3260 * This is the workhorse routine for processing in/out routemap
3263 static void bgp_route_map_process_peer(const char *rmap_name
,
3264 struct route_map
*map
, struct peer
*peer
,
3265 int afi
, int safi
, int route_update
)
3267 struct bgp_filter
*filter
;
3269 if (!peer
|| !rmap_name
)
3272 filter
= &peer
->filter
[afi
][safi
];
3274 * in is for non-route-server clients,
3275 * out is for all peers
3277 if (filter
->map
[RMAP_IN
].name
3278 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3279 filter
->map
[RMAP_IN
].map
= map
;
3281 if (route_update
&& peer
->status
== Established
) {
3282 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3283 PEER_FLAG_SOFT_RECONFIG
)) {
3284 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3286 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3287 rmap_name
, peer
->host
);
3289 bgp_soft_reconfig_in(peer
, afi
, safi
);
3290 } else if (CHECK_FLAG(peer
->cap
,
3291 PEER_CAP_REFRESH_OLD_RCV
)
3292 || CHECK_FLAG(peer
->cap
,
3293 PEER_CAP_REFRESH_NEW_RCV
)) {
3294 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3296 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3297 rmap_name
, peer
->host
);
3298 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3305 * For outbound, unsuppress and default-originate map change (content or
3306 * map created), merely update the "config" here, the actual route
3307 * announcement happens at the group level.
3309 if (filter
->map
[RMAP_OUT
].name
3310 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3311 filter
->map
[RMAP_OUT
].map
= map
;
3313 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3314 filter
->usmap
.map
= map
;
3316 if (peer
->default_rmap
[afi
][safi
].name
3317 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3318 peer
->default_rmap
[afi
][safi
].map
= map
;
3321 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3322 struct route_map
*map
,
3325 struct peer_group
*group
;
3326 struct listnode
*node
, *nnode
;
3327 struct bgp_filter
*filter
;
3334 /* All the peers have been updated correctly already. This is
3335 * just updating the placeholder data. No real update required.
3337 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3338 FOREACH_AFI_SAFI (afi
, safi
) {
3339 filter
= &group
->conf
->filter
[afi
][safi
];
3341 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3342 if ((filter
->map
[direct
].name
)
3343 && (strcmp(rmap_name
,
3344 filter
->map
[direct
].name
)
3346 filter
->map
[direct
].map
= map
;
3349 if (filter
->usmap
.name
3350 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3351 filter
->usmap
.map
= map
;
3357 * Note that if an extreme number (tens of thousands) of route-maps are in use
3358 * and if bgp has an extreme number of peers, network statements, etc then this
3359 * function can consume a lot of cycles. This is due to this function being
3360 * called for each route-map and within this function we walk the list of peers,
3361 * network statements, etc looking to see if they use this route-map.
3363 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3370 struct bgp_node
*bn
;
3371 struct bgp_static
*bgp_static
;
3372 struct bgp_aggregate
*aggregate
;
3373 struct listnode
*node
, *nnode
;
3374 struct route_map
*map
;
3375 char buf
[INET6_ADDRSTRLEN
];
3377 map
= route_map_lookup_by_name(rmap_name
);
3379 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3381 /* Ignore dummy peer-group structure */
3382 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3385 FOREACH_AFI_SAFI (afi
, safi
) {
3386 /* process in/out/import/export/default-orig
3388 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3389 safi
, route_update
);
3393 /* for outbound/default-orig route-maps, process for groups */
3394 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3397 /* update peer-group config (template) */
3398 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3400 FOREACH_AFI_SAFI (afi
, safi
) {
3401 /* For table route-map updates. */
3402 if (!bgp_fibupd_safi(safi
))
3405 if (bgp
->table_map
[afi
][safi
].name
3406 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3409 /* bgp->table_map[afi][safi].map is NULL.
3410 * i.e Route map creation event.
3411 * So update applied_counter.
3412 * If it is not NULL, i.e It may be routemap updation or
3413 * deletion. so no need to update the counter.
3415 if (!bgp
->table_map
[afi
][safi
].map
)
3416 route_map_counter_increment(map
);
3417 bgp
->table_map
[afi
][safi
].map
= map
;
3419 if (BGP_DEBUG(zebra
, ZEBRA
))
3421 "Processing route_map %s update on "
3425 bgp_zebra_announce_table(bgp
, afi
, safi
);
3428 /* For network route-map updates. */
3429 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3430 bn
= bgp_route_next(bn
)) {
3431 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3435 if (!bgp_static
->rmap
.name
3436 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3439 if (!bgp_static
->rmap
.map
)
3440 route_map_counter_increment(map
);
3442 bgp_static
->rmap
.map
= map
;
3444 if (route_update
&& !bgp_static
->backdoor
) {
3445 if (bgp_debug_zebra(&bn
->p
))
3447 "Processing route_map %s update on static route %s",
3449 inet_ntop(bn
->p
.family
,
3450 &bn
->p
.u
.prefix
, buf
,
3452 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3457 /* For aggregate-address route-map updates. */
3458 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
3459 bn
= bgp_route_next(bn
)) {
3460 aggregate
= bgp_node_get_bgp_aggregate_info(bn
);
3464 if (!aggregate
->rmap
.name
3465 || (strcmp(rmap_name
, aggregate
->rmap
.name
) != 0))
3468 if (!aggregate
->rmap
.map
)
3469 route_map_counter_increment(map
);
3471 aggregate
->rmap
.map
= map
;
3474 if (bgp_debug_zebra(&bn
->p
))
3476 "Processing route_map %s update on aggregate-address route %s",
3478 inet_ntop(bn
->p
.family
,
3479 &bn
->p
.u
.prefix
, buf
,
3481 bgp_aggregate_route(bgp
, &bn
->p
, afi
, safi
,
3487 /* For redistribute route-map updates. */
3488 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3489 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3490 struct list
*red_list
;
3491 struct bgp_redist
*red
;
3493 red_list
= bgp
->redist
[afi
][i
];
3497 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3499 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3503 route_map_counter_increment(map
);
3505 red
->rmap
.map
= map
;
3510 if (BGP_DEBUG(zebra
, ZEBRA
))
3512 "Processing route_map %s update on redistributed routes",
3515 bgp_redistribute_resend(bgp
, afi
, i
,
3520 /* for type5 command route-maps */
3521 FOREACH_AFI_SAFI (afi
, safi
) {
3522 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3523 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3527 /* Make sure the route-map is populated here if not already done */
3528 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3530 if (BGP_DEBUG(zebra
, ZEBRA
))
3532 "Processing route_map %s update on advertise type5 route command",
3535 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3536 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3537 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3542 static void bgp_route_map_process_update_cb(char *rmap_name
)
3544 struct listnode
*node
, *nnode
;
3547 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3548 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3551 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3552 vnc_routemap_update(bgp
, __func__
);
3556 vpn_policy_routemap_event(rmap_name
);
3559 int bgp_route_map_update_timer(struct thread
*thread
)
3561 bm
->t_rmap_update
= NULL
;
3563 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3568 static void bgp_route_map_mark_update(const char *rmap_name
)
3570 struct listnode
*node
, *nnode
;
3573 /* If new update is received before the current timer timed out,
3574 * turn it off and start a new timer.
3576 if (bm
->t_rmap_update
!= NULL
)
3577 THREAD_OFF(bm
->t_rmap_update
);
3579 /* rmap_update_timer of 0 means don't do route updates */
3580 if (bm
->rmap_update_timer
) {
3581 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3582 NULL
, bm
->rmap_update_timer
,
3583 &bm
->t_rmap_update
);
3585 /* Signal the groups that a route-map update event has
3587 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3588 update_group_policy_update(bgp
,
3589 BGP_POLICY_ROUTE_MAP
,
3592 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3593 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3595 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3596 vnc_routemap_update(bgp
, __func__
);
3601 static void bgp_route_map_add(const char *rmap_name
)
3603 if (route_map_mark_updated(rmap_name
) == 0)
3604 bgp_route_map_mark_update(rmap_name
);
3606 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3609 static void bgp_route_map_delete(const char *rmap_name
)
3611 if (route_map_mark_updated(rmap_name
) == 0)
3612 bgp_route_map_mark_update(rmap_name
);
3614 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3617 static void bgp_route_map_event(const char *rmap_name
)
3619 if (route_map_mark_updated(rmap_name
) == 0)
3620 bgp_route_map_mark_update(rmap_name
);
3622 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3625 DEFUN (match_mac_address
,
3626 match_mac_address_cmd
,
3627 "match mac address WORD",
3630 "Match address of route\n"
3631 "MAC Access-list name\n")
3633 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3634 RMAP_EVENT_FILTER_ADDED
);
3637 DEFUN (no_match_mac_address
,
3638 no_match_mac_address_cmd
,
3639 "no match mac address WORD",
3643 "Match address of route\n"
3644 "MAC acess-list name\n")
3646 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3647 RMAP_EVENT_FILTER_DELETED
);
3650 DEFUN (match_evpn_route_type
,
3651 match_evpn_route_type_cmd
,
3652 "match evpn route-type <macip | multicast | prefix>",
3655 "Match route-type\n"
3660 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3661 RMAP_EVENT_MATCH_ADDED
);
3664 DEFUN (no_match_evpn_route_type
,
3665 no_match_evpn_route_type_cmd
,
3666 "no match evpn route-type <macip | multicast | prefix>",
3670 "Match route-type\n"
3675 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3676 RMAP_EVENT_MATCH_DELETED
);
3680 DEFUN (match_evpn_vni
,
3682 "match evpn vni " CMD_VNI_RANGE
,
3688 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3689 RMAP_EVENT_MATCH_ADDED
);
3692 DEFUN (no_match_evpn_vni
,
3693 no_match_evpn_vni_cmd
,
3694 "no match evpn vni " CMD_VNI_RANGE
,
3701 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3702 RMAP_EVENT_MATCH_DELETED
);
3705 DEFUN (match_evpn_default_route
,
3706 match_evpn_default_route_cmd
,
3707 "match evpn default-route",
3710 "default EVPN type-5 route\n")
3712 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3713 RMAP_EVENT_MATCH_ADDED
);
3716 DEFUN (no_match_evpn_default_route
,
3717 no_match_evpn_default_route_cmd
,
3718 "no match evpn default-route",
3722 "default EVPN type-5 route\n")
3724 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3725 RMAP_EVENT_MATCH_DELETED
);
3728 DEFUN (match_evpn_rd
,
3730 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
3733 "Route Distinguisher\n"
3734 "ASN:XX or A.B.C.D:XX\n")
3736 return bgp_route_match_add(vty
, "evpn rd", argv
[3]->arg
,
3737 RMAP_EVENT_MATCH_ADDED
);
3740 DEFUN (no_match_evpn_rd
,
3741 no_match_evpn_rd_cmd
,
3742 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
3746 "Route Distinguisher\n"
3747 "ASN:XX or A.B.C.D:XX\n")
3749 return bgp_route_match_delete(vty
, "evpn rd", argv
[4]->arg
,
3750 RMAP_EVENT_MATCH_DELETED
);
3753 DEFPY(match_vrl_source_vrf
,
3754 match_vrl_source_vrf_cmd
,
3755 "match source-vrf NAME$vrf_name",
3760 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3761 RMAP_EVENT_MATCH_ADDED
);
3764 DEFPY(no_match_vrl_source_vrf
,
3765 no_match_vrl_source_vrf_cmd
,
3766 "no match source-vrf NAME$vrf_name",
3772 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3773 RMAP_EVENT_MATCH_DELETED
);
3778 "match peer <A.B.C.D|X:X::X:X|WORD>",
3780 "Match peer address\n"
3781 "IP address of peer\n"
3782 "IPv6 address of peer\n"
3783 "Interface name of peer\n")
3786 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3787 RMAP_EVENT_MATCH_ADDED
);
3790 DEFUN (match_peer_local
,
3791 match_peer_local_cmd
,
3794 "Match peer address\n"
3795 "Static or Redistributed routes\n")
3797 return bgp_route_match_add(vty
, "peer", "local",
3798 RMAP_EVENT_MATCH_DELETED
);
3801 DEFUN (no_match_peer
,
3803 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3806 "Match peer address\n"
3807 "Static or Redistributed routes\n"
3808 "IP address of peer\n"
3809 "IPv6 address of peer\n"
3810 "Interface name of peer\n")
3814 if (argc
<= idx_peer
)
3815 return bgp_route_match_delete(vty
, "peer", NULL
,
3816 RMAP_EVENT_MATCH_DELETED
);
3817 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3818 RMAP_EVENT_MATCH_DELETED
);
3821 #if defined(HAVE_LUA)
3822 DEFUN (match_command
,
3824 "match command WORD",
3826 "Run a command to match\n"
3827 "The command to run\n")
3829 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3830 RMAP_EVENT_FILTER_ADDED
);
3833 DEFUN (no_match_command
,
3834 no_match_command_cmd
,
3835 "no match command WORD",
3838 "Run a command to match\n"
3839 "The command to run\n")
3841 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3842 RMAP_EVENT_FILTER_DELETED
);
3846 /* match probability */
3847 DEFUN (match_probability
,
3848 match_probability_cmd
,
3849 "match probability (0-100)",
3851 "Match portion of routes defined by percentage value\n"
3852 "Percentage of routes\n")
3855 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3856 RMAP_EVENT_MATCH_ADDED
);
3860 DEFUN (no_match_probability
,
3861 no_match_probability_cmd
,
3862 "no match probability [(1-99)]",
3865 "Match portion of routes defined by percentage value\n"
3866 "Percentage of routes\n")
3869 if (argc
<= idx_number
)
3870 return bgp_route_match_delete(vty
, "probability", NULL
,
3871 RMAP_EVENT_MATCH_DELETED
);
3872 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3873 RMAP_EVENT_MATCH_DELETED
);
3877 DEFUN (match_ip_route_source
,
3878 match_ip_route_source_cmd
,
3879 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3882 "Match advertising source address of route\n"
3883 "IP access-list number\n"
3884 "IP access-list number (expanded range)\n"
3885 "IP standard access-list name\n")
3888 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3889 RMAP_EVENT_FILTER_ADDED
);
3893 DEFUN (no_match_ip_route_source
,
3894 no_match_ip_route_source_cmd
,
3895 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3899 "Match advertising source address of route\n"
3900 "IP access-list number\n"
3901 "IP access-list number (expanded range)\n"
3902 "IP standard access-list name\n")
3905 if (argc
<= idx_number
)
3906 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3907 RMAP_EVENT_FILTER_DELETED
);
3908 return bgp_route_match_delete(vty
, "ip route-source",
3909 argv
[idx_number
]->arg
,
3910 RMAP_EVENT_FILTER_DELETED
);
3914 DEFUN (match_ip_route_source_prefix_list
,
3915 match_ip_route_source_prefix_list_cmd
,
3916 "match ip route-source prefix-list WORD",
3919 "Match advertising source address of route\n"
3920 "Match entries of prefix-lists\n"
3921 "IP prefix-list name\n")
3924 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3925 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3929 DEFUN (no_match_ip_route_source_prefix_list
,
3930 no_match_ip_route_source_prefix_list_cmd
,
3931 "no match ip route-source prefix-list [WORD]",
3935 "Match advertising source address of route\n"
3936 "Match entries of prefix-lists\n"
3937 "IP prefix-list name\n")
3940 if (argc
<= idx_word
)
3941 return bgp_route_match_delete(vty
,
3942 "ip route-source prefix-list",
3943 NULL
, RMAP_EVENT_PLIST_DELETED
);
3944 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3945 argv
[idx_word
]->arg
,
3946 RMAP_EVENT_PLIST_DELETED
);
3950 DEFUN (match_local_pref
,
3951 match_local_pref_cmd
,
3952 "match local-preference (0-4294967295)",
3954 "Match local-preference of route\n"
3958 return bgp_route_match_add(vty
, "local-preference",
3959 argv
[idx_number
]->arg
,
3960 RMAP_EVENT_MATCH_ADDED
);
3964 DEFUN (no_match_local_pref
,
3965 no_match_local_pref_cmd
,
3966 "no match local-preference [(0-4294967295)]",
3969 "Match local preference of route\n"
3970 "Local preference value\n")
3972 int idx_localpref
= 3;
3973 if (argc
<= idx_localpref
)
3974 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3975 RMAP_EVENT_MATCH_DELETED
);
3976 return bgp_route_match_delete(vty
, "local-preference",
3977 argv
[idx_localpref
]->arg
,
3978 RMAP_EVENT_MATCH_DELETED
);
3982 DEFUN (match_community
,
3983 match_community_cmd
,
3984 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3986 "Match BGP community list\n"
3987 "Community-list number (standard)\n"
3988 "Community-list number (expanded)\n"
3989 "Community-list name\n"
3990 "Do exact matching of communities\n")
3992 int idx_comm_list
= 2;
3997 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3998 strlen(argv
[idx_comm_list
]->arg
)
3999 + strlen("exact-match") + 2);
4001 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
4003 argstr
= argv
[idx_comm_list
]->arg
;
4005 ret
= bgp_route_match_add(vty
, "community", argstr
,
4006 RMAP_EVENT_CLIST_ADDED
);
4008 if (argstr
!= argv
[idx_comm_list
]->arg
)
4009 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4014 DEFUN (no_match_community
,
4015 no_match_community_cmd
,
4016 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
4019 "Match BGP community list\n"
4020 "Community-list number (standard)\n"
4021 "Community-list number (expanded)\n"
4022 "Community-list name\n"
4023 "Do exact matching of communities\n")
4025 return bgp_route_match_delete(vty
, "community", NULL
,
4026 RMAP_EVENT_CLIST_DELETED
);
4029 DEFUN (match_lcommunity
,
4030 match_lcommunity_cmd
,
4031 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
4033 "Match BGP large community list\n"
4034 "Large Community-list number (standard)\n"
4035 "Large Community-list number (expanded)\n"
4036 "Large Community-list name\n"
4037 "Do exact matching of communities\n")
4039 int idx_lcomm_list
= 2;
4044 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4045 strlen(argv
[idx_lcomm_list
]->arg
)
4046 + strlen("exact-match") + 2);
4048 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
4050 argstr
= argv
[idx_lcomm_list
]->arg
;
4052 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
4053 RMAP_EVENT_LLIST_ADDED
);
4054 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
4055 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4060 DEFUN (no_match_lcommunity
,
4061 no_match_lcommunity_cmd
,
4062 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
4065 "Match BGP large community list\n"
4066 "Large Community-list number (standard)\n"
4067 "Large Community-list number (expanded)\n"
4068 "Large Community-list name\n"
4069 "Do exact matching of communities\n")
4071 return bgp_route_match_delete(vty
, "large-community", NULL
,
4072 RMAP_EVENT_LLIST_DELETED
);
4075 DEFUN (match_ecommunity
,
4076 match_ecommunity_cmd
,
4077 "match extcommunity <(1-99)|(100-500)|WORD>",
4079 "Match BGP/VPN extended community list\n"
4080 "Extended community-list number (standard)\n"
4081 "Extended community-list number (expanded)\n"
4082 "Extended community-list name\n")
4084 int idx_comm_list
= 2;
4085 return bgp_route_match_add(vty
, "extcommunity",
4086 argv
[idx_comm_list
]->arg
,
4087 RMAP_EVENT_ECLIST_ADDED
);
4091 DEFUN (no_match_ecommunity
,
4092 no_match_ecommunity_cmd
,
4093 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
4096 "Match BGP/VPN extended community list\n"
4097 "Extended community-list number (standard)\n"
4098 "Extended community-list number (expanded)\n"
4099 "Extended community-list name\n")
4101 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
4102 RMAP_EVENT_ECLIST_DELETED
);
4106 DEFUN (match_aspath
,
4108 "match as-path WORD",
4110 "Match BGP AS path list\n"
4111 "AS path access-list name\n")
4114 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
4115 RMAP_EVENT_ASLIST_ADDED
);
4119 DEFUN (no_match_aspath
,
4120 no_match_aspath_cmd
,
4121 "no match as-path [WORD]",
4124 "Match BGP AS path list\n"
4125 "AS path access-list name\n")
4127 return bgp_route_match_delete(vty
, "as-path", NULL
,
4128 RMAP_EVENT_ASLIST_DELETED
);
4132 DEFUN (match_origin
,
4134 "match origin <egp|igp|incomplete>",
4139 "unknown heritage\n")
4142 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4143 return bgp_route_match_add(vty
, "origin", "igp",
4144 RMAP_EVENT_MATCH_ADDED
);
4145 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4146 return bgp_route_match_add(vty
, "origin", "egp",
4147 RMAP_EVENT_MATCH_ADDED
);
4148 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4149 return bgp_route_match_add(vty
, "origin", "incomplete",
4150 RMAP_EVENT_MATCH_ADDED
);
4152 vty_out(vty
, "%% Invalid match origin type\n");
4153 return CMD_WARNING_CONFIG_FAILED
;
4157 DEFUN (no_match_origin
,
4158 no_match_origin_cmd
,
4159 "no match origin [<egp|igp|incomplete>]",
4165 "unknown heritage\n")
4167 return bgp_route_match_delete(vty
, "origin", NULL
,
4168 RMAP_EVENT_MATCH_DELETED
);
4171 DEFUN (set_table_id
,
4173 "set table (1-4294967295)",
4175 "export route to non-main kernel table\n"
4176 "Kernel routing table id\n")
4180 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4182 return generic_set_add(vty
, index
, "table", argv
[idx_id
]->arg
);
4185 DEFUN (no_set_table_id
,
4186 no_set_table_id_cmd
,
4190 "export route to non-main kernel table\n")
4192 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4194 return generic_set_delete(vty
, index
, "table", NULL
);
4197 DEFUN (set_ip_nexthop_peer
,
4198 set_ip_nexthop_peer_cmd
,
4199 "[no] set ip next-hop peer-address",
4203 "Next hop address\n"
4204 "Use peer address (for BGP only)\n")
4206 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4207 const char *) = strmatch(argv
[0]->text
, "no")
4208 ? generic_set_delete
4211 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4215 DEFUN (set_ip_nexthop_unchanged
,
4216 set_ip_nexthop_unchanged_cmd
,
4217 "[no] set ip next-hop unchanged",
4221 "Next hop address\n"
4222 "Don't modify existing Next hop address\n")
4224 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4225 const char *) = strmatch(argv
[0]->text
, "no")
4226 ? generic_set_delete
4229 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4233 DEFUN (set_distance
,
4235 "set distance (0-255)",
4237 "BGP Administrative Distance to use\n"
4242 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4243 "distance", argv
[idx_number
]->arg
);
4246 DEFUN (no_set_distance
,
4247 no_set_distance_cmd
,
4248 "no set distance [(0-255)]",
4250 "BGP Administrative Distance to use\n"
4253 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4257 DEFUN (set_local_pref
,
4259 "set local-preference (0-4294967295)",
4261 "BGP local preference path attribute\n"
4262 "Preference value\n")
4265 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4266 "local-preference", argv
[idx_number
]->arg
);
4270 DEFUN (no_set_local_pref
,
4271 no_set_local_pref_cmd
,
4272 "no set local-preference [(0-4294967295)]",
4275 "BGP local preference path attribute\n"
4276 "Preference value\n")
4278 int idx_localpref
= 3;
4279 if (argc
<= idx_localpref
)
4280 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4281 "local-preference", NULL
);
4282 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4283 "local-preference", argv
[idx_localpref
]->arg
);
4289 "set weight (0-4294967295)",
4291 "BGP weight for routing table\n"
4295 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4296 argv
[idx_number
]->arg
);
4300 DEFUN (no_set_weight
,
4302 "no set weight [(0-4294967295)]",
4305 "BGP weight for routing table\n"
4309 if (argc
<= idx_weight
)
4310 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4312 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4313 "weight", argv
[idx_weight
]->arg
);
4316 DEFUN (set_label_index
,
4317 set_label_index_cmd
,
4318 "set label-index (0-1048560)",
4320 "Label index to associate with the prefix\n"
4321 "Label index value\n")
4324 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4325 "label-index", argv
[idx_number
]->arg
);
4328 DEFUN (no_set_label_index
,
4329 no_set_label_index_cmd
,
4330 "no set label-index [(0-1048560)]",
4333 "Label index to associate with the prefix\n"
4334 "Label index value\n")
4336 int idx_label_index
= 3;
4337 if (argc
<= idx_label_index
)
4338 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4339 "label-index", NULL
);
4340 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4341 "label-index", argv
[idx_label_index
]->arg
);
4344 DEFUN (set_aspath_prepend_asn
,
4345 set_aspath_prepend_asn_cmd
,
4346 "set as-path prepend (1-4294967295)...",
4348 "Transform BGP AS_PATH attribute\n"
4349 "Prepend to the as-path\n"
4356 str
= argv_concat(argv
, argc
, idx_asn
);
4357 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4358 "as-path prepend", str
);
4359 XFREE(MTYPE_TMP
, str
);
4364 DEFUN (set_aspath_prepend_lastas
,
4365 set_aspath_prepend_lastas_cmd
,
4366 "set as-path prepend last-as (1-10)",
4368 "Transform BGP AS_PATH attribute\n"
4369 "Prepend to the as-path\n"
4370 "Use the peer's AS-number\n"
4371 "Number of times to insert\n")
4373 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4376 DEFUN (no_set_aspath_prepend
,
4377 no_set_aspath_prepend_cmd
,
4378 "no set as-path prepend [(1-4294967295)]",
4381 "Transform BGP AS_PATH attribute\n"
4382 "Prepend to the as-path\n"
4389 str
= argv_concat(argv
, argc
, idx_asn
);
4390 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4391 "as-path prepend", str
);
4392 XFREE(MTYPE_TMP
, str
);
4396 DEFUN (no_set_aspath_prepend_lastas
,
4397 no_set_aspath_prepend_lastas_cmd
,
4398 "no set as-path prepend last-as [(1-10)]",
4401 "Transform BGP AS_PATH attribute\n"
4402 "Prepend to the as-path\n"
4403 "Use the peers AS-number\n"
4404 "Number of times to insert\n")
4406 return no_set_aspath_prepend(self
, vty
, argc
, argv
);
4409 DEFUN (set_aspath_exclude
,
4410 set_aspath_exclude_cmd
,
4411 "set as-path exclude (1-4294967295)...",
4413 "Transform BGP AS-path attribute\n"
4414 "Exclude from the as-path\n"
4421 str
= argv_concat(argv
, argc
, idx_asn
);
4422 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4423 "as-path exclude", str
);
4424 XFREE(MTYPE_TMP
, str
);
4428 DEFUN (no_set_aspath_exclude
,
4429 no_set_aspath_exclude_cmd
,
4430 "no set as-path exclude (1-4294967295)...",
4433 "Transform BGP AS_PATH attribute\n"
4434 "Exclude from the as-path\n"
4441 str
= argv_concat(argv
, argc
, idx_asn
);
4442 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4443 "as-path exclude", str
);
4444 XFREE(MTYPE_TMP
, str
);
4448 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4449 "no set as-path exclude",
4451 "Transform BGP AS_PATH attribute\n"
4452 "Exclude from the as-path\n")
4454 DEFUN (set_community
,
4456 "set community AA:NN...",
4458 "BGP community attribute\n"
4466 struct community
*com
= NULL
;
4471 b
= buffer_new(1024);
4473 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4474 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4481 buffer_putc(b
, ' ');
4485 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4487 buffer_putstr(b
, "internet");
4490 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4492 buffer_putstr(b
, "local-AS");
4495 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4496 && strncmp(argv
[i
]->arg
, "no-advertise",
4497 strlen(argv
[i
]->arg
))
4499 buffer_putstr(b
, "no-advertise");
4502 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4503 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4505 buffer_putstr(b
, "no-export");
4508 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4509 strlen(argv
[i
]->arg
))
4511 buffer_putstr(b
, "graceful-shutdown");
4514 buffer_putstr(b
, argv
[i
]->arg
);
4516 buffer_putc(b
, '\0');
4518 /* Fetch result string then compile it to communities attribute. */
4519 str
= buffer_getstr(b
);
4523 com
= community_str2com(str
);
4524 XFREE(MTYPE_TMP
, str
);
4527 /* Can't compile user input into communities attribute. */
4529 vty_out(vty
, "%% Malformed communities attribute\n");
4530 return CMD_WARNING_CONFIG_FAILED
;
4533 /* Set communites attribute string. */
4534 str
= community_str(com
, false);
4537 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4538 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4539 strlcpy(argstr
, str
, argstr_sz
);
4540 strlcat(argstr
, " additive", argstr_sz
);
4541 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4542 "community", argstr
);
4543 XFREE(MTYPE_TMP
, argstr
);
4545 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4548 community_free(&com
);
4553 DEFUN (set_community_none
,
4554 set_community_none_cmd
,
4555 "set community none",
4557 "BGP community attribute\n"
4558 "No community attribute\n")
4560 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4561 "community", "none");
4564 DEFUN (no_set_community
,
4565 no_set_community_cmd
,
4566 "no set community AA:NN...",
4569 "BGP community attribute\n"
4572 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4576 ALIAS (no_set_community
,
4577 no_set_community_short_cmd
,
4581 "BGP community attribute\n")
4584 DEFUN (set_community_delete
,
4585 set_community_delete_cmd
,
4586 "set comm-list <(1-99)|(100-500)|WORD> delete",
4588 "set BGP community list (for deletion)\n"
4589 "Community-list number (standard)\n"
4590 "Community-list number (expanded)\n"
4591 "Community-list name\n"
4592 "Delete matching communities\n")
4594 int idx_comm_list
= 2;
4597 args
= argv_concat(argv
, argc
, idx_comm_list
);
4598 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4600 XFREE(MTYPE_TMP
, args
);
4605 DEFUN (no_set_community_delete
,
4606 no_set_community_delete_cmd
,
4607 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4610 "set BGP community list (for deletion)\n"
4611 "Community-list number (standard)\n"
4612 "Community-list number (expanded)\n"
4613 "Community-list name\n"
4614 "Delete matching communities\n")
4616 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4620 DEFUN (set_lcommunity
,
4622 "set large-community AA:BB:CC...",
4624 "BGP large community attribute\n"
4625 "Large Community number in aa:bb:cc format or additive\n")
4630 str
= argv_concat(argv
, argc
, 2);
4631 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4632 "large-community", str
);
4633 XFREE(MTYPE_TMP
, str
);
4638 DEFUN (set_lcommunity_none
,
4639 set_lcommunity_none_cmd
,
4640 "set large-community none",
4642 "BGP large community attribute\n"
4643 "No large community attribute\n")
4645 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4646 "large-community", "none");
4649 DEFUN (no_set_lcommunity
,
4650 no_set_lcommunity_cmd
,
4651 "no set large-community none",
4654 "BGP large community attribute\n"
4655 "No community attribute\n")
4657 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4658 "large-community", NULL
);
4661 DEFUN (no_set_lcommunity1
,
4662 no_set_lcommunity1_cmd
,
4663 "no set large-community AA:BB:CC...",
4666 "BGP large community attribute\n"
4667 "Large community in AA:BB:CC... format or additive\n")
4669 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4670 "large-community", NULL
);
4673 ALIAS (no_set_lcommunity1
,
4674 no_set_lcommunity1_short_cmd
,
4675 "no set large-community",
4678 "BGP large community attribute\n")
4680 DEFUN (set_lcommunity_delete
,
4681 set_lcommunity_delete_cmd
,
4682 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4684 "set BGP large community list (for deletion)\n"
4685 "Large Community-list number (standard)\n"
4686 "Large Communitly-list number (expanded)\n"
4687 "Large Community-list name\n"
4688 "Delete matching large communities\n")
4690 int idx_lcomm_list
= 2;
4693 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
4694 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4695 "large-comm-list", args
);
4696 XFREE(MTYPE_TMP
, args
);
4701 DEFUN (no_set_lcommunity_delete
,
4702 no_set_lcommunity_delete_cmd
,
4703 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4706 "set BGP large community list (for deletion)\n"
4707 "Large Community-list number (standard)\n"
4708 "Large Communitly-list number (expanded)\n"
4709 "Large Community-list name\n"
4710 "Delete matching large communities\n")
4712 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4713 "large-comm-list", NULL
);
4716 ALIAS (no_set_lcommunity_delete
,
4717 no_set_lcommunity_delete_short_cmd
,
4718 "no set large-comm-list",
4721 "set BGP large community list (for deletion)\n")
4723 DEFUN (set_ecommunity_rt
,
4724 set_ecommunity_rt_cmd
,
4725 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4727 "BGP extended community attribute\n"
4728 "Route Target extended community\n"
4729 "VPN extended community\n")
4735 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4736 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4737 "extcommunity rt", str
);
4738 XFREE(MTYPE_TMP
, str
);
4743 DEFUN (no_set_ecommunity_rt
,
4744 no_set_ecommunity_rt_cmd
,
4745 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4748 "BGP extended community attribute\n"
4749 "Route Target extended community\n"
4750 "VPN extended community\n")
4752 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4753 "extcommunity rt", NULL
);
4756 ALIAS (no_set_ecommunity_rt
,
4757 no_set_ecommunity_rt_short_cmd
,
4758 "no set extcommunity rt",
4761 "BGP extended community attribute\n"
4762 "Route Target extended community\n")
4764 DEFUN (set_ecommunity_soo
,
4765 set_ecommunity_soo_cmd
,
4766 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4768 "BGP extended community attribute\n"
4769 "Site-of-Origin extended community\n"
4770 "VPN extended community\n")
4776 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4777 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4778 "extcommunity soo", str
);
4779 XFREE(MTYPE_TMP
, str
);
4784 DEFUN (no_set_ecommunity_soo
,
4785 no_set_ecommunity_soo_cmd
,
4786 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4789 "BGP extended community attribute\n"
4790 "Site-of-Origin extended community\n"
4791 "VPN extended community\n")
4793 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4794 "extcommunity soo", NULL
);
4797 ALIAS (no_set_ecommunity_soo
,
4798 no_set_ecommunity_soo_short_cmd
,
4799 "no set extcommunity soo",
4802 "GP extended community attribute\n"
4803 "Site-of-Origin extended community\n")
4807 "set origin <egp|igp|incomplete>",
4812 "unknown heritage\n")
4815 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4816 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4818 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4819 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4821 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4822 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4823 "origin", "incomplete");
4825 vty_out(vty
, "%% Invalid set origin type\n");
4826 return CMD_WARNING_CONFIG_FAILED
;
4830 DEFUN (no_set_origin
,
4832 "no set origin [<egp|igp|incomplete>]",
4838 "unknown heritage\n")
4840 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4845 DEFUN (set_atomic_aggregate
,
4846 set_atomic_aggregate_cmd
,
4847 "set atomic-aggregate",
4849 "BGP atomic aggregate attribute\n" )
4851 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4852 "atomic-aggregate", NULL
);
4855 DEFUN (no_set_atomic_aggregate
,
4856 no_set_atomic_aggregate_cmd
,
4857 "no set atomic-aggregate",
4860 "BGP atomic aggregate attribute\n" )
4862 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4863 "atomic-aggregate", NULL
);
4866 DEFUN (set_aggregator_as
,
4867 set_aggregator_as_cmd
,
4868 "set aggregator as (1-4294967295) A.B.C.D",
4870 "BGP aggregator attribute\n"
4871 "AS number of aggregator\n"
4873 "IP address of aggregator\n")
4878 struct in_addr address
;
4881 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4883 vty_out(vty
, "Aggregator IP address is invalid\n");
4884 return CMD_WARNING_CONFIG_FAILED
;
4887 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4888 strlen(argv
[idx_number
]->arg
)
4889 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4891 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4893 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4894 "aggregator as", argstr
);
4896 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4902 DEFUN (no_set_aggregator_as
,
4903 no_set_aggregator_as_cmd
,
4904 "no set aggregator as [(1-4294967295) A.B.C.D]",
4907 "BGP aggregator attribute\n"
4908 "AS number of aggregator\n"
4910 "IP address of aggregator\n")
4915 struct in_addr address
;
4918 if (argc
<= idx_asn
)
4919 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4920 "aggregator as", NULL
);
4922 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4924 vty_out(vty
, "Aggregator IP address is invalid\n");
4925 return CMD_WARNING_CONFIG_FAILED
;
4928 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4929 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4932 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4934 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4935 "aggregator as", argstr
);
4937 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4942 DEFUN (match_ipv6_next_hop
,
4943 match_ipv6_next_hop_cmd
,
4944 "match ipv6 next-hop X:X::X:X",
4947 "Match IPv6 next-hop address of route\n"
4948 "IPv6 address of next hop\n")
4951 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4952 RMAP_EVENT_MATCH_ADDED
);
4955 DEFUN (no_match_ipv6_next_hop
,
4956 no_match_ipv6_next_hop_cmd
,
4957 "no match ipv6 next-hop X:X::X:X",
4961 "Match IPv6 next-hop address of route\n"
4962 "IPv6 address of next hop\n")
4965 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4966 RMAP_EVENT_MATCH_DELETED
);
4970 DEFUN (set_ipv6_nexthop_peer
,
4971 set_ipv6_nexthop_peer_cmd
,
4972 "set ipv6 next-hop peer-address",
4975 "Next hop address\n"
4976 "Use peer address (for BGP only)\n")
4978 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4979 "ipv6 next-hop peer-address", NULL
);
4982 DEFUN (no_set_ipv6_nexthop_peer
,
4983 no_set_ipv6_nexthop_peer_cmd
,
4984 "no set ipv6 next-hop peer-address",
4988 "IPv6 next-hop address\n"
4989 "Use peer address (for BGP only)\n")
4991 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4992 "ipv6 next-hop peer-address", NULL
);
4995 DEFUN (set_ipv6_nexthop_prefer_global
,
4996 set_ipv6_nexthop_prefer_global_cmd
,
4997 "set ipv6 next-hop prefer-global",
5000 "IPv6 next-hop address\n"
5001 "Prefer global over link-local if both exist\n")
5003 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5004 "ipv6 next-hop prefer-global", NULL
);
5008 DEFUN (no_set_ipv6_nexthop_prefer_global
,
5009 no_set_ipv6_nexthop_prefer_global_cmd
,
5010 "no set ipv6 next-hop prefer-global",
5014 "IPv6 next-hop address\n"
5015 "Prefer global over link-local if both exist\n")
5017 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5018 "ipv6 next-hop prefer-global", NULL
);
5021 DEFUN (set_ipv6_nexthop_global
,
5022 set_ipv6_nexthop_global_cmd
,
5023 "set ipv6 next-hop global X:X::X:X",
5026 "IPv6 next-hop address\n"
5027 "IPv6 global address\n"
5028 "IPv6 address of next hop\n")
5031 struct in6_addr addr
;
5034 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
5036 vty_out(vty
, "%% Malformed nexthop address\n");
5037 return CMD_WARNING_CONFIG_FAILED
;
5039 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
5040 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
5041 vty_out(vty
, "%% Invalid global nexthop address\n");
5042 return CMD_WARNING_CONFIG_FAILED
;
5045 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5046 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
5050 DEFUN (no_set_ipv6_nexthop_global
,
5051 no_set_ipv6_nexthop_global_cmd
,
5052 "no set ipv6 next-hop global X:X::X:X",
5056 "IPv6 next-hop address\n"
5057 "IPv6 global address\n"
5058 "IPv6 address of next hop\n")
5061 if (argc
<= idx_ipv6
)
5062 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5063 "ipv6 next-hop global", NULL
);
5064 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5065 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
5068 #ifdef KEEP_OLD_VPN_COMMANDS
5069 DEFUN (set_vpn_nexthop
,
5070 set_vpn_nexthop_cmd
,
5071 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5073 "VPNv4 information\n"
5074 "VPN next-hop address\n"
5075 "IP address of next hop\n"
5076 "VPNv6 information\n"
5077 "VPN next-hop address\n"
5078 "IPv6 address of next hop\n")
5084 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5086 return generic_set_add(
5087 vty
, VTY_GET_CONTEXT(route_map_index
),
5088 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5090 return generic_set_add(
5091 vty
, VTY_GET_CONTEXT(route_map_index
),
5092 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5097 DEFUN (no_set_vpn_nexthop
,
5098 no_set_vpn_nexthop_cmd
,
5099 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5102 "VPNv4 information\n"
5103 "VPN next-hop address\n"
5104 "IP address of next hop\n"
5105 "VPNv6 information\n"
5106 "VPN next-hop address\n"
5107 "IPv6 address of next hop\n")
5117 arg
= argv
[idx_ip
]->arg
;
5118 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5120 return generic_set_delete(
5121 vty
, VTY_GET_CONTEXT(route_map_index
),
5122 "ipv4 vpn next-hop", arg
);
5124 return generic_set_delete(
5125 vty
, VTY_GET_CONTEXT(route_map_index
),
5126 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5130 #endif /* KEEP_OLD_VPN_COMMANDS */
5132 DEFUN (set_ipx_vpn_nexthop
,
5133 set_ipx_vpn_nexthop_cmd
,
5134 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
5136 "IPv4 information\n"
5137 "IPv6 information\n"
5139 "VPN next-hop address\n"
5140 "IP address of next hop\n"
5141 "IPv6 address of next hop\n")
5147 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5149 return generic_set_add(
5150 vty
, VTY_GET_CONTEXT(route_map_index
),
5151 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5153 return generic_set_add(
5154 vty
, VTY_GET_CONTEXT(route_map_index
),
5155 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5160 DEFUN (no_set_ipx_vpn_nexthop
,
5161 no_set_ipx_vpn_nexthop_cmd
,
5162 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
5165 "IPv4 information\n"
5166 "IPv6 information\n"
5168 "VPN next-hop address\n"
5169 "IP address of next hop\n"
5170 "IPv6 address of next hop\n")
5180 arg
= argv
[idx_ip
]->arg
;
5181 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5183 return generic_set_delete(
5184 vty
, VTY_GET_CONTEXT(route_map_index
),
5185 "ipv4 vpn next-hop", arg
);
5187 return generic_set_delete(
5188 vty
, VTY_GET_CONTEXT(route_map_index
),
5189 "ipv6 vpn next-hop", arg
);
5194 DEFUN (set_originator_id
,
5195 set_originator_id_cmd
,
5196 "set originator-id A.B.C.D",
5198 "BGP originator ID attribute\n"
5199 "IP address of originator\n")
5202 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5203 "originator-id", argv
[idx_ipv4
]->arg
);
5207 DEFUN (no_set_originator_id
,
5208 no_set_originator_id_cmd
,
5209 "no set originator-id [A.B.C.D]",
5212 "BGP originator ID attribute\n"
5213 "IP address of originator\n")
5217 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
5219 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5220 "originator-id", arg
);
5224 /* Initialization of route map. */
5225 void bgp_route_map_init(void)
5229 route_map_add_hook(bgp_route_map_add
);
5230 route_map_delete_hook(bgp_route_map_delete
);
5231 route_map_event_hook(bgp_route_map_event
);
5233 route_map_match_interface_hook(generic_match_add
);
5234 route_map_no_match_interface_hook(generic_match_delete
);
5236 route_map_match_ip_address_hook(generic_match_add
);
5237 route_map_no_match_ip_address_hook(generic_match_delete
);
5239 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
5240 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
5242 route_map_match_ip_next_hop_hook(generic_match_add
);
5243 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
5245 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
5246 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5248 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5249 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5251 route_map_match_ipv6_address_hook(generic_match_add
);
5252 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5254 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5255 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5257 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5258 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5260 route_map_match_metric_hook(generic_match_add
);
5261 route_map_no_match_metric_hook(generic_match_delete
);
5263 route_map_match_tag_hook(generic_match_add
);
5264 route_map_no_match_tag_hook(generic_match_delete
);
5266 route_map_set_ip_nexthop_hook(generic_set_add
);
5267 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5269 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5270 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5272 route_map_set_metric_hook(generic_set_add
);
5273 route_map_no_set_metric_hook(generic_set_delete
);
5275 route_map_set_tag_hook(generic_set_add
);
5276 route_map_no_set_tag_hook(generic_set_delete
);
5278 route_map_install_match(&route_match_peer_cmd
);
5279 route_map_install_match(&route_match_local_pref_cmd
);
5280 #if defined(HAVE_LUA)
5281 route_map_install_match(&route_match_command_cmd
);
5283 route_map_install_match(&route_match_ip_address_cmd
);
5284 route_map_install_match(&route_match_ip_next_hop_cmd
);
5285 route_map_install_match(&route_match_ip_route_source_cmd
);
5286 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5287 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5288 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5289 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5290 route_map_install_match(&route_match_aspath_cmd
);
5291 route_map_install_match(&route_match_community_cmd
);
5292 route_map_install_match(&route_match_lcommunity_cmd
);
5293 route_map_install_match(&route_match_ecommunity_cmd
);
5294 route_map_install_match(&route_match_local_pref_cmd
);
5295 route_map_install_match(&route_match_metric_cmd
);
5296 route_map_install_match(&route_match_origin_cmd
);
5297 route_map_install_match(&route_match_probability_cmd
);
5298 route_map_install_match(&route_match_interface_cmd
);
5299 route_map_install_match(&route_match_tag_cmd
);
5300 route_map_install_match(&route_match_mac_address_cmd
);
5301 route_map_install_match(&route_match_evpn_vni_cmd
);
5302 route_map_install_match(&route_match_evpn_route_type_cmd
);
5303 route_map_install_match(&route_match_evpn_rd_cmd
);
5304 route_map_install_match(&route_match_evpn_default_route_cmd
);
5305 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5307 route_map_install_set(&route_set_table_id_cmd
);
5308 route_map_install_set(&route_set_ip_nexthop_cmd
);
5309 route_map_install_set(&route_set_local_pref_cmd
);
5310 route_map_install_set(&route_set_weight_cmd
);
5311 route_map_install_set(&route_set_label_index_cmd
);
5312 route_map_install_set(&route_set_metric_cmd
);
5313 route_map_install_set(&route_set_distance_cmd
);
5314 route_map_install_set(&route_set_aspath_prepend_cmd
);
5315 route_map_install_set(&route_set_aspath_exclude_cmd
);
5316 route_map_install_set(&route_set_origin_cmd
);
5317 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5318 route_map_install_set(&route_set_aggregator_as_cmd
);
5319 route_map_install_set(&route_set_community_cmd
);
5320 route_map_install_set(&route_set_community_delete_cmd
);
5321 route_map_install_set(&route_set_lcommunity_cmd
);
5322 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5323 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5324 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5325 route_map_install_set(&route_set_originator_id_cmd
);
5326 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5327 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5328 route_map_install_set(&route_set_tag_cmd
);
5329 route_map_install_set(&route_set_label_index_cmd
);
5331 install_element(RMAP_NODE
, &match_peer_cmd
);
5332 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5333 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5334 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5335 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5336 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5337 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5338 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5339 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5340 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5341 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5342 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5343 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5344 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
5345 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
5346 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5347 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5348 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5349 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5351 install_element(RMAP_NODE
, &match_aspath_cmd
);
5352 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5353 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5354 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5355 install_element(RMAP_NODE
, &match_community_cmd
);
5356 install_element(RMAP_NODE
, &no_match_community_cmd
);
5357 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5358 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5359 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5360 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5361 install_element(RMAP_NODE
, &match_origin_cmd
);
5362 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5363 install_element(RMAP_NODE
, &match_probability_cmd
);
5364 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5366 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
5367 install_element(RMAP_NODE
, &set_table_id_cmd
);
5368 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5369 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5370 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5371 install_element(RMAP_NODE
, &set_distance_cmd
);
5372 install_element(RMAP_NODE
, &no_set_distance_cmd
);
5373 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5374 install_element(RMAP_NODE
, &set_weight_cmd
);
5375 install_element(RMAP_NODE
, &set_label_index_cmd
);
5376 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5377 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5378 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5379 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5380 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5381 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5382 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
5383 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5384 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5385 install_element(RMAP_NODE
, &set_origin_cmd
);
5386 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5387 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5388 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5389 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5390 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5391 install_element(RMAP_NODE
, &set_community_cmd
);
5392 install_element(RMAP_NODE
, &set_community_none_cmd
);
5393 install_element(RMAP_NODE
, &no_set_community_cmd
);
5394 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5395 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5396 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5397 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5398 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5399 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5400 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5401 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5402 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5403 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5404 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5405 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5406 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5407 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5408 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5409 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5410 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5411 #ifdef KEEP_OLD_VPN_COMMANDS
5412 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5413 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5414 #endif /* KEEP_OLD_VPN_COMMANDS */
5415 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5416 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5417 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5418 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5420 route_map_install_match(&route_match_ipv6_address_cmd
);
5421 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5422 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5423 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5424 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5425 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5426 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5427 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5429 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5430 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5431 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5432 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5433 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5434 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5435 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5436 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5437 #if defined(HAVE_LUA)
5438 install_element(RMAP_NODE
, &match_command_cmd
);
5439 install_element(RMAP_NODE
, &no_match_command_cmd
);
5443 void bgp_route_map_terminate(void)
5445 /* ToDo: Cleanup all the used memory */