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 static const struct route_map_rule_cmd route_match_peer_cmd
= {
340 route_match_peer_compile
,
341 route_match_peer_free
344 #if defined(HAVE_LUA)
345 static enum route_map_cmd_result_t
346 route_match_command(void *rule
, const struct prefix
*prefix
,
347 route_map_object_t type
, void *object
)
349 int status
= RMAP_NOMATCH
;
350 u_int32_t locpref
= 0;
351 u_int32_t newlocpref
= 0;
352 enum lua_rm_status lrm_status
;
353 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
354 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
360 * Setup the prefix information to pass in
362 lua_setup_prefix_table(L
, prefix
);
364 zlog_debug("Set up prefix table");
366 * Setup the bgp_path_info information
369 lua_pushinteger(L
, path
->attr
->med
);
370 lua_setfield(L
, -2, "metric");
371 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
372 lua_setfield(L
, -2, "ifindex");
373 lua_pushstring(L
, path
->attr
->aspath
->str
);
374 lua_setfield(L
, -2, "aspath");
375 lua_pushinteger(L
, path
->attr
->local_pref
);
376 lua_setfield(L
, -2, "localpref");
377 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
378 lua_setglobal(L
, "nexthop");
380 zlog_debug("Set up nexthop information");
384 lrm_status
= lua_run_rm_rule(L
, rule
);
385 switch (lrm_status
) {
387 zlog_debug("RM_FAILURE");
390 zlog_debug("RM_NOMATCH");
392 case LUA_RM_MATCH_AND_CHANGE
:
393 zlog_debug("MATCH AND CHANGE");
394 lua_getglobal(L
, "nexthop");
395 path
->attr
->med
= get_integer(L
, "metric");
397 * This needs to be abstraced with the set function
399 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
400 locpref
= path
->attr
->local_pref
;
401 newlocpref
= get_integer(L
, "localpref");
402 if (newlocpref
!= locpref
) {
403 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
404 path
->attr
->local_pref
= newlocpref
;
409 zlog_debug("MATCH ONLY");
417 static void *route_match_command_compile(const char *arg
)
421 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
426 route_match_command_free(void *rule
)
428 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
431 static const struct route_map_rule_cmd route_match_command_cmd
= {
434 route_match_command_compile
,
435 route_match_command_free
439 /* `match ip address IP_ACCESS_LIST' */
441 /* Match function should return 1 if match is success else return
443 static enum route_map_cmd_result_t
444 route_match_ip_address(void *rule
, const struct prefix
*prefix
,
445 route_map_object_t type
, void *object
)
447 struct access_list
*alist
;
449 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
450 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
454 return (access_list_apply(alist
, prefix
) == FILTER_DENY
461 /* Route map `ip address' match statement. `arg' should be
463 static void *route_match_ip_address_compile(const char *arg
)
465 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
468 /* Free route map's compiled `ip address' value. */
469 static void route_match_ip_address_free(void *rule
)
471 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
474 /* Route map commands for ip address matching. */
475 static const struct route_map_rule_cmd route_match_ip_address_cmd
= {
477 route_match_ip_address
,
478 route_match_ip_address_compile
,
479 route_match_ip_address_free
482 /* `match ip next-hop IP_ADDRESS' */
484 /* Match function return 1 if match is success else return zero. */
485 static enum route_map_cmd_result_t
486 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
,
487 route_map_object_t type
, void *object
)
489 struct access_list
*alist
;
490 struct bgp_path_info
*path
;
491 struct prefix_ipv4 p
;
493 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
496 p
.prefix
= path
->attr
->nexthop
;
497 p
.prefixlen
= IPV4_MAX_BITLEN
;
499 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
503 return (access_list_apply(alist
, &p
) == FILTER_DENY
510 /* Route map `ip next-hop' match statement. `arg' is
512 static void *route_match_ip_next_hop_compile(const char *arg
)
514 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
517 /* Free route map's compiled `ip address' value. */
518 static void route_match_ip_next_hop_free(void *rule
)
520 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
523 /* Route map commands for ip next-hop matching. */
524 static const struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
526 route_match_ip_next_hop
,
527 route_match_ip_next_hop_compile
,
528 route_match_ip_next_hop_free
531 /* `match ip route-source ACCESS-LIST' */
533 /* Match function return 1 if match is success else return zero. */
534 static enum route_map_cmd_result_t
535 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
,
536 route_map_object_t type
, void *object
)
538 struct access_list
*alist
;
539 struct bgp_path_info
*path
;
541 struct prefix_ipv4 p
;
543 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
547 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
551 p
.prefix
= peer
->su
.sin
.sin_addr
;
552 p
.prefixlen
= IPV4_MAX_BITLEN
;
554 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
558 return (access_list_apply(alist
, &p
) == FILTER_DENY
565 /* Route map `ip route-source' match statement. `arg' is
567 static void *route_match_ip_route_source_compile(const char *arg
)
569 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
572 /* Free route map's compiled `ip address' value. */
573 static void route_match_ip_route_source_free(void *rule
)
575 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
578 /* Route map commands for ip route-source matching. */
579 static const struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
581 route_match_ip_route_source
,
582 route_match_ip_route_source_compile
,
583 route_match_ip_route_source_free
586 static enum route_map_cmd_result_t
587 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
588 const struct prefix
*p
)
591 struct bgp_pbr_entry_main api
;
593 memset(&api
, 0, sizeof(api
));
595 /* extract match from flowspec entries */
596 ret
= bgp_flowspec_match_rules_fill(
597 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
598 p
->u
.prefix_flowspec
.prefixlen
, &api
);
601 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
602 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
603 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
605 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
608 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
609 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
610 if (family2afi((&api
.src_prefix
)->family
) != afi
)
612 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
619 static enum route_map_cmd_result_t
620 route_match_address_prefix_list(void *rule
, afi_t afi
,
621 const struct prefix
*prefix
,
622 route_map_object_t type
, void *object
)
624 struct prefix_list
*plist
;
626 if (type
!= RMAP_BGP
)
629 plist
= prefix_list_lookup(afi
, (char *)rule
);
633 if (prefix
->family
== AF_FLOWSPEC
)
634 return route_match_prefix_list_flowspec(afi
, plist
,
636 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
640 static enum route_map_cmd_result_t
641 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
642 route_map_object_t type
, void *object
)
644 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, type
,
648 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
650 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
653 static void route_match_ip_address_prefix_list_free(void *rule
)
655 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
658 static const struct route_map_rule_cmd
659 route_match_ip_address_prefix_list_cmd
= {
660 "ip address prefix-list",
661 route_match_ip_address_prefix_list
,
662 route_match_ip_address_prefix_list_compile
,
663 route_match_ip_address_prefix_list_free
666 /* `match ip next-hop prefix-list PREFIX_LIST' */
668 static enum route_map_cmd_result_t
669 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
670 route_map_object_t type
, void *object
)
672 struct prefix_list
*plist
;
673 struct bgp_path_info
*path
;
674 struct prefix_ipv4 p
;
676 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
679 p
.prefix
= path
->attr
->nexthop
;
680 p
.prefixlen
= IPV4_MAX_BITLEN
;
682 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
686 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
693 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
695 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
698 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
700 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
703 static const struct route_map_rule_cmd
704 route_match_ip_next_hop_prefix_list_cmd
= {
705 "ip next-hop prefix-list",
706 route_match_ip_next_hop_prefix_list
,
707 route_match_ip_next_hop_prefix_list_compile
,
708 route_match_ip_next_hop_prefix_list_free
711 /* `match ip next-hop type <blackhole>' */
713 static enum route_map_cmd_result_t
714 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
715 route_map_object_t type
, void *object
)
717 struct bgp_path_info
*path
;
719 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
720 path
= (struct bgp_path_info
*)object
;
724 /* If nexthop interface's index can't be resolved and nexthop is
725 set to any address then mark it as type `blackhole`.
726 This logic works for matching kernel/static routes like:
727 `ip route add blackhole 10.0.0.1`. */
728 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
729 && !path
->attr
->nh_ifindex
)
735 static void *route_match_ip_next_hop_type_compile(const char *arg
)
737 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
740 static void route_match_ip_next_hop_type_free(void *rule
)
742 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
745 static const struct route_map_rule_cmd
746 route_match_ip_next_hop_type_cmd
= {
748 route_match_ip_next_hop_type
,
749 route_match_ip_next_hop_type_compile
,
750 route_match_ip_next_hop_type_free
753 /* `match ip route-source prefix-list PREFIX_LIST' */
755 static enum route_map_cmd_result_t
756 route_match_ip_route_source_prefix_list(void *rule
,
757 const struct prefix
*prefix
,
758 route_map_object_t type
, void *object
)
760 struct prefix_list
*plist
;
761 struct bgp_path_info
*path
;
763 struct prefix_ipv4 p
;
765 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
769 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
773 p
.prefix
= peer
->su
.sin
.sin_addr
;
774 p
.prefixlen
= IPV4_MAX_BITLEN
;
776 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
780 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
787 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
789 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
792 static void route_match_ip_route_source_prefix_list_free(void *rule
)
794 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
797 static const struct route_map_rule_cmd
798 route_match_ip_route_source_prefix_list_cmd
= {
799 "ip route-source prefix-list",
800 route_match_ip_route_source_prefix_list
,
801 route_match_ip_route_source_prefix_list_compile
,
802 route_match_ip_route_source_prefix_list_free
805 /* `match evpn default-route' */
807 /* Match function should return 1 if match is success else 0 */
808 static enum route_map_cmd_result_t
809 route_match_evpn_default_route(void *rule
, const struct prefix
*p
,
810 route_map_object_t type
, void *object
)
812 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
818 /* Route map commands for default-route matching. */
819 static const struct route_map_rule_cmd
820 route_match_evpn_default_route_cmd
= {
821 "evpn default-route",
822 route_match_evpn_default_route
,
827 /* `match mac address MAC_ACCESS_LIST' */
829 /* Match function should return 1 if match is success else return
831 static enum route_map_cmd_result_t
832 route_match_mac_address(void *rule
, const struct prefix
*prefix
,
833 route_map_object_t type
, void *object
)
835 struct access_list
*alist
;
838 if (type
== RMAP_BGP
) {
839 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
843 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
846 p
.family
= AF_ETHERNET
;
847 p
.prefixlen
= ETH_ALEN
* 8;
848 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
850 return (access_list_apply(alist
, &p
) == FILTER_DENY
858 /* Route map `mac address' match statement. `arg' should be
860 static void *route_match_mac_address_compile(const char *arg
)
862 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
865 /* Free route map's compiled `ip address' value. */
866 static void route_match_mac_address_free(void *rule
)
868 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
871 /* Route map commands for mac address matching. */
872 static const struct route_map_rule_cmd route_match_mac_address_cmd
= {
874 route_match_mac_address
,
875 route_match_mac_address_compile
,
876 route_match_mac_address_free
880 * Match function returns:
881 * ...RMAP_MATCH if match is found.
882 * ...RMAP_NOMATCH if match is not found.
883 * ...RMAP_NOOP to ignore this match check.
885 static enum route_map_cmd_result_t
886 route_match_vni(void *rule
, const struct prefix
*prefix
,
887 route_map_object_t type
, void *object
)
890 unsigned int label_cnt
= 0;
891 struct bgp_path_info
*path
= NULL
;
892 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
894 if (type
== RMAP_BGP
) {
895 vni
= *((vni_t
*)rule
);
896 path
= (struct bgp_path_info
*)object
;
899 * This rmap filter is valid for vxlan tunnel type only.
900 * For any other tunnel type, return noop to ignore
903 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
907 * Apply filter to type 1, 2, 5 routes only.
908 * Other route types do not have vni label.
910 if (evp
&& (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
&&
911 evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
&&
912 evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
915 if (path
->extra
== NULL
)
918 for ( ; label_cnt
< BGP_MAX_LABELS
&&
919 label_cnt
< path
->extra
->num_labels
; label_cnt
++) {
920 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
928 /* Route map `vni' match statement. */
929 static void *route_match_vni_compile(const char *arg
)
934 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
936 *vni
= strtoul(arg
, &end
, 10);
938 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
945 /* Free route map's compiled `vni' value. */
946 static void route_match_vni_free(void *rule
)
948 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
951 /* Route map commands for vni matching. */
952 static const struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
955 route_match_vni_compile
,
959 /* `match evpn route-type' */
961 /* Match function should return 1 if match is success else return
963 static enum route_map_cmd_result_t
964 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
,
965 route_map_object_t type
, void *object
)
967 uint8_t route_type
= 0;
969 if (type
== RMAP_BGP
) {
970 route_type
= *((uint8_t *)rule
);
972 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
979 /* Route map `route-type' match statement. */
980 static void *route_match_evpn_route_type_compile(const char *arg
)
982 uint8_t *route_type
= NULL
;
984 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
986 if (strncmp(arg
, "ma", 2) == 0)
987 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
988 else if (strncmp(arg
, "mu", 2) == 0)
989 *route_type
= BGP_EVPN_IMET_ROUTE
;
991 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
996 /* Free route map's compiled `route-type' value. */
997 static void route_match_evpn_route_type_free(void *rule
)
999 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1002 /* Route map commands for evpn route-type matching. */
1003 static const struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
1005 route_match_evpn_route_type
,
1006 route_match_evpn_route_type_compile
,
1007 route_match_evpn_route_type_free
1012 /* Match function should return 1 if match is success else return zero. */
1013 static enum route_map_cmd_result_t
1014 route_match_rd(void *rule
, const struct prefix
*prefix
,
1015 route_map_object_t type
, void *object
)
1017 struct prefix_rd
*prd_rule
= NULL
;
1018 struct prefix_rd
*prd_route
= NULL
;
1019 struct bgp_path_info
*path
= NULL
;
1021 if (type
== RMAP_BGP
) {
1022 if (prefix
->family
!= AF_EVPN
)
1023 return RMAP_NOMATCH
;
1025 prd_rule
= (struct prefix_rd
*)rule
;
1026 path
= (struct bgp_path_info
*)object
;
1028 if (path
->net
== NULL
|| path
->net
->prn
== NULL
)
1029 return RMAP_NOMATCH
;
1031 prd_route
= (struct prefix_rd
*)&path
->net
->prn
->p
;
1032 if (memcmp(prd_route
->val
, prd_rule
->val
, ECOMMUNITY_SIZE
) == 0)
1036 return RMAP_NOMATCH
;
1039 /* Route map `rd' match statement. */
1040 static void *route_match_rd_compile(const char *arg
)
1042 struct prefix_rd
*prd
;
1045 prd
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct prefix_rd
));
1047 ret
= str2prefix_rd(arg
, prd
);
1049 XFREE(MTYPE_ROUTE_MAP_COMPILED
, prd
);
1056 /* Free route map's compiled `rd' value. */
1057 static void route_match_rd_free(void *rule
)
1059 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1062 /* Route map commands for rd matching. */
1063 static const struct route_map_rule_cmd route_match_evpn_rd_cmd
= {
1066 route_match_rd_compile
,
1070 /* Route map commands for VRF route leak with source vrf matching */
1071 static enum route_map_cmd_result_t
1072 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
1073 route_map_object_t type
, void *object
)
1075 struct bgp_path_info
*path
;
1078 if (type
== RMAP_BGP
) {
1080 path
= (struct bgp_path_info
*)object
;
1082 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
1083 return RMAP_NOMATCH
;
1085 if (path
->extra
== NULL
)
1086 return RMAP_NOMATCH
;
1088 if (strncmp(vrf_name
, vrf_id_to_name(
1089 path
->extra
->bgp_orig
->vrf_id
), VRF_NAMSIZ
)
1094 return RMAP_NOMATCH
;
1097 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1099 uint8_t *vrf_name
= NULL
;
1101 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1106 /* Free route map's compiled `route-type' value. */
1107 static void route_match_vrl_source_vrf_free(void *rule
)
1109 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1112 static const struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1114 route_match_vrl_source_vrf
,
1115 route_match_vrl_source_vrf_compile
,
1116 route_match_vrl_source_vrf_free
1119 /* `match local-preference LOCAL-PREF' */
1121 /* Match function return 1 if match is success else return zero. */
1122 static enum route_map_cmd_result_t
1123 route_match_local_pref(void *rule
, const struct prefix
*prefix
,
1124 route_map_object_t type
, void *object
)
1126 uint32_t *local_pref
;
1127 struct bgp_path_info
*path
;
1129 if (type
== RMAP_BGP
) {
1133 if (path
->attr
->local_pref
== *local_pref
)
1136 return RMAP_NOMATCH
;
1138 return RMAP_NOMATCH
;
1142 * Route map `match local-preference' match statement.
1143 * `arg' is local-pref value
1145 static void *route_match_local_pref_compile(const char *arg
)
1147 uint32_t *local_pref
;
1148 char *endptr
= NULL
;
1149 unsigned long tmpval
;
1151 /* Locpref value shoud be integer. */
1152 if (!all_digit(arg
))
1156 tmpval
= strtoul(arg
, &endptr
, 10);
1157 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1160 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1162 *local_pref
= tmpval
;
1166 /* Free route map's compiled `match local-preference' value. */
1167 static void route_match_local_pref_free(void *rule
)
1169 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1172 /* Route map commands for metric matching. */
1173 static const struct route_map_rule_cmd route_match_local_pref_cmd
= {
1175 route_match_local_pref
,
1176 route_match_local_pref_compile
,
1177 route_match_local_pref_free
1180 /* `match metric METRIC' */
1182 /* Match function return 1 if match is success else return zero. */
1183 static enum route_map_cmd_result_t
1184 route_match_metric(void *rule
, const struct prefix
*prefix
,
1185 route_map_object_t type
, void *object
)
1187 struct rmap_value
*rv
;
1188 struct bgp_path_info
*path
;
1190 if (type
== RMAP_BGP
) {
1193 return route_value_match(rv
, path
->attr
->med
);
1195 return RMAP_NOMATCH
;
1198 /* Route map commands for metric matching. */
1199 static const struct route_map_rule_cmd route_match_metric_cmd
= {
1202 route_value_compile
,
1206 /* `match as-path ASPATH' */
1208 /* Match function for as-path match. I assume given object is */
1209 static enum route_map_cmd_result_t
1210 route_match_aspath(void *rule
, const struct prefix
*prefix
,
1211 route_map_object_t type
, void *object
)
1214 struct as_list
*as_list
;
1215 struct bgp_path_info
*path
;
1217 if (type
== RMAP_BGP
) {
1218 as_list
= as_list_lookup((char *)rule
);
1219 if (as_list
== NULL
)
1220 return RMAP_NOMATCH
;
1224 /* Perform match. */
1225 return ((as_list_apply(as_list
, path
->attr
->aspath
)
1230 return RMAP_NOMATCH
;
1233 /* Compile function for as-path match. */
1234 static void *route_match_aspath_compile(const char *arg
)
1236 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1239 /* Compile function for as-path match. */
1240 static void route_match_aspath_free(void *rule
)
1242 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1245 /* Route map commands for aspath matching. */
1246 static const struct route_map_rule_cmd route_match_aspath_cmd
= {
1249 route_match_aspath_compile
,
1250 route_match_aspath_free
1253 /* `match community COMMUNIY' */
1254 struct rmap_community
{
1260 /* Match function for community match. */
1261 static enum route_map_cmd_result_t
1262 route_match_community(void *rule
, const struct prefix
*prefix
,
1263 route_map_object_t type
, void *object
)
1265 struct community_list
*list
;
1266 struct bgp_path_info
*path
;
1267 struct rmap_community
*rcom
= rule
;
1269 if (type
== RMAP_BGP
) {
1273 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1275 COMMUNITY_LIST_MASTER
);
1277 return RMAP_NOMATCH
;
1280 if (community_list_exact_match(path
->attr
->community
,
1284 if (community_list_match(path
->attr
->community
, list
))
1288 return RMAP_NOMATCH
;
1291 /* Compile function for community match. */
1292 static void *route_match_community_compile(const char *arg
)
1294 struct rmap_community
*rcom
;
1298 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1300 p
= strchr(arg
, ' ');
1303 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1304 memcpy(rcom
->name
, arg
, len
);
1307 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1311 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1315 /* Compile function for community match. */
1316 static void route_match_community_free(void *rule
)
1318 struct rmap_community
*rcom
= rule
;
1320 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1321 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1325 * In routemap processing there is a need to add the
1326 * name as a rule_key in the dependency table. Routemap
1327 * lib is unaware of rule_key when exact-match clause
1328 * is in use. routemap lib uses the compiled output to
1329 * get the rule_key value.
1331 static void *route_match_get_community_key(void *rule
)
1333 struct rmap_community
*rcom
;
1340 /* Route map commands for community matching. */
1341 static const struct route_map_rule_cmd route_match_community_cmd
= {
1343 route_match_community
,
1344 route_match_community_compile
,
1345 route_match_community_free
,
1346 route_match_get_community_key
1349 /* Match function for lcommunity match. */
1350 static enum route_map_cmd_result_t
1351 route_match_lcommunity(void *rule
, const struct prefix
*prefix
,
1352 route_map_object_t type
, void *object
)
1354 struct community_list
*list
;
1355 struct bgp_path_info
*path
;
1356 struct rmap_community
*rcom
= rule
;
1358 if (type
== RMAP_BGP
) {
1361 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1363 LARGE_COMMUNITY_LIST_MASTER
);
1365 return RMAP_NOMATCH
;
1368 if (lcommunity_list_exact_match(
1369 path
->attr
->lcommunity
,
1373 if (lcommunity_list_match(
1374 path
->attr
->lcommunity
,
1379 return RMAP_NOMATCH
;
1382 /* Compile function for community match. */
1383 static void *route_match_lcommunity_compile(const char *arg
)
1385 struct rmap_community
*rcom
;
1389 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1391 p
= strchr(arg
, ' ');
1394 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1395 memcpy(rcom
->name
, arg
, len
);
1398 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1402 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1406 /* Compile function for community match. */
1407 static void route_match_lcommunity_free(void *rule
)
1409 struct rmap_community
*rcom
= rule
;
1411 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1412 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1415 /* Route map commands for community matching. */
1416 static const struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1418 route_match_lcommunity
,
1419 route_match_lcommunity_compile
,
1420 route_match_lcommunity_free
,
1421 route_match_get_community_key
1425 /* Match function for extcommunity match. */
1426 static enum route_map_cmd_result_t
1427 route_match_ecommunity(void *rule
, const struct prefix
*prefix
,
1428 route_map_object_t type
, void *object
)
1430 struct community_list
*list
;
1431 struct bgp_path_info
*path
;
1432 struct rmap_community
*rcom
= rule
;
1434 if (type
== RMAP_BGP
) {
1437 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1439 EXTCOMMUNITY_LIST_MASTER
);
1441 return RMAP_NOMATCH
;
1443 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1446 return RMAP_NOMATCH
;
1449 /* Compile function for extcommunity match. */
1450 static void *route_match_ecommunity_compile(const char *arg
)
1452 struct rmap_community
*rcom
;
1454 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1455 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1456 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1461 /* Compile function for extcommunity match. */
1462 static void route_match_ecommunity_free(void *rule
)
1464 struct rmap_community
*rcom
= rule
;
1466 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1467 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1470 /* Route map commands for community matching. */
1471 static const struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1473 route_match_ecommunity
,
1474 route_match_ecommunity_compile
,
1475 route_match_ecommunity_free
1478 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1479 and `address-family vpnv4'. */
1481 /* `match origin' */
1482 static enum route_map_cmd_result_t
1483 route_match_origin(void *rule
, const struct prefix
*prefix
,
1484 route_map_object_t type
, void *object
)
1487 struct bgp_path_info
*path
;
1489 if (type
== RMAP_BGP
) {
1493 if (path
->attr
->origin
== *origin
)
1497 return RMAP_NOMATCH
;
1500 static void *route_match_origin_compile(const char *arg
)
1504 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1506 if (strcmp(arg
, "igp") == 0)
1508 else if (strcmp(arg
, "egp") == 0)
1516 /* Free route map's compiled `ip address' value. */
1517 static void route_match_origin_free(void *rule
)
1519 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1522 /* Route map commands for origin matching. */
1523 static const struct route_map_rule_cmd route_match_origin_cmd
= {
1526 route_match_origin_compile
,
1527 route_match_origin_free
1530 /* match probability { */
1532 static enum route_map_cmd_result_t
1533 route_match_probability(void *rule
, const struct prefix
*prefix
,
1534 route_map_object_t type
, void *object
)
1538 switch (*(long *)rule
) {
1544 if (r
< *(long *)rule
) {
1549 return RMAP_NOMATCH
;
1552 static void *route_match_probability_compile(const char *arg
)
1558 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1568 *lobule
= RAND_MAX
/ 100 * perc
;
1574 static void route_match_probability_free(void *rule
)
1576 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1579 static const struct route_map_rule_cmd route_match_probability_cmd
= {
1581 route_match_probability
,
1582 route_match_probability_compile
,
1583 route_match_probability_free
1586 /* `match interface IFNAME' */
1587 /* Match function should return 1 if match is success else return
1589 static enum route_map_cmd_result_t
1590 route_match_interface(void *rule
, const struct prefix
*prefix
,
1591 route_map_object_t type
, void *object
)
1593 struct interface
*ifp
;
1594 struct bgp_path_info
*path
;
1596 if (type
== RMAP_BGP
) {
1600 return RMAP_NOMATCH
;
1602 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1604 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1605 return RMAP_NOMATCH
;
1609 return RMAP_NOMATCH
;
1612 /* Route map `interface' match statement. `arg' should be
1614 static void *route_match_interface_compile(const char *arg
)
1616 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1619 /* Free route map's compiled `interface' value. */
1620 static void route_match_interface_free(void *rule
)
1622 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1625 /* Route map commands for ip address matching. */
1626 static const struct route_map_rule_cmd route_match_interface_cmd
= {
1628 route_match_interface
,
1629 route_match_interface_compile
,
1630 route_match_interface_free
1635 /* `set ip next-hop IP_ADDRESS' */
1637 /* Match function return 1 if match is success else return zero. */
1638 static enum route_map_cmd_result_t
1639 route_match_tag(void *rule
, const struct prefix
*prefix
,
1640 route_map_object_t type
, void *object
)
1643 struct bgp_path_info
*path
;
1645 if (type
== RMAP_BGP
) {
1649 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1652 return RMAP_NOMATCH
;
1656 /* Route map commands for tag matching. */
1657 static const struct route_map_rule_cmd route_match_tag_cmd
= {
1660 route_map_rule_tag_compile
,
1661 route_map_rule_tag_free
,
1665 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1666 struct rmap_ip_nexthop_set
{
1667 struct in_addr
*address
;
1672 static enum route_map_cmd_result_t
1673 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
,
1674 route_map_object_t type
, void *object
)
1676 struct rmap_ip_nexthop_set
*rins
= rule
;
1677 struct bgp_path_info
*path
;
1680 if (type
!= RMAP_BGP
)
1683 if (prefix
->family
== AF_INET6
)
1689 if (rins
->unchanged
) {
1690 SET_FLAG(path
->attr
->rmap_change_flags
,
1691 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1692 } else if (rins
->peer_address
) {
1693 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1694 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1696 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1697 path
->attr
->nexthop
.s_addr
=
1698 sockunion2ip(peer
->su_remote
);
1699 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1700 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1701 /* The next hop value will be set as part of
1702 * packet rewrite. Set the flags here to indicate
1703 * that rewrite needs to be done.
1704 * Also, clear the value.
1706 SET_FLAG(path
->attr
->rmap_change_flags
,
1707 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1708 path
->attr
->nexthop
.s_addr
= INADDR_ANY
;
1711 /* Set next hop value. */
1712 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1713 path
->attr
->nexthop
= *rins
->address
;
1714 SET_FLAG(path
->attr
->rmap_change_flags
,
1715 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1716 /* case for MP-BGP : MPLS VPN */
1717 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1718 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1724 /* Route map `ip nexthop' compile function. Given string is converted
1725 to struct in_addr structure. */
1726 static void *route_set_ip_nexthop_compile(const char *arg
)
1728 struct rmap_ip_nexthop_set
*rins
;
1729 struct in_addr
*address
= NULL
;
1730 int peer_address
= 0;
1734 if (strcmp(arg
, "peer-address") == 0)
1736 else if (strcmp(arg
, "unchanged") == 0)
1739 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1740 sizeof(struct in_addr
));
1741 ret
= inet_aton(arg
, address
);
1744 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1749 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1750 sizeof(struct rmap_ip_nexthop_set
));
1752 rins
->address
= address
;
1753 rins
->peer_address
= peer_address
;
1754 rins
->unchanged
= unchanged
;
1759 /* Free route map's compiled `ip nexthop' value. */
1760 static void route_set_ip_nexthop_free(void *rule
)
1762 struct rmap_ip_nexthop_set
*rins
= rule
;
1764 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1766 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1769 /* Route map commands for ip nexthop set. */
1770 static const struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1772 route_set_ip_nexthop
,
1773 route_set_ip_nexthop_compile
,
1774 route_set_ip_nexthop_free
1777 /* `set local-preference LOCAL_PREF' */
1779 /* Set local preference. */
1780 static enum route_map_cmd_result_t
1781 route_set_local_pref(void *rule
, const struct prefix
*prefix
,
1782 route_map_object_t type
, void *object
)
1784 struct rmap_value
*rv
;
1785 struct bgp_path_info
*path
;
1786 uint32_t locpref
= 0;
1788 if (type
== RMAP_BGP
) {
1789 /* Fetch routemap's rule information. */
1793 /* Set local preference value. */
1794 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1795 locpref
= path
->attr
->local_pref
;
1797 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1798 path
->attr
->local_pref
=
1799 route_value_adjust(rv
, locpref
, path
->peer
);
1805 /* Set local preference rule structure. */
1806 static const struct route_map_rule_cmd route_set_local_pref_cmd
= {
1808 route_set_local_pref
,
1809 route_value_compile
,
1813 /* `set weight WEIGHT' */
1816 static enum route_map_cmd_result_t
1817 route_set_weight(void *rule
, const struct prefix
*prefix
,
1818 route_map_object_t type
, void *object
)
1820 struct rmap_value
*rv
;
1821 struct bgp_path_info
*path
;
1823 if (type
== RMAP_BGP
) {
1824 /* Fetch routemap's rule information. */
1828 /* Set weight value. */
1829 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1835 /* Set local preference rule structure. */
1836 static const struct route_map_rule_cmd route_set_weight_cmd
= {
1839 route_value_compile
,
1843 /* `set distance DISTANCE */
1844 static enum route_map_cmd_result_t
1845 route_set_distance(void *rule
, const struct prefix
*prefix
,
1846 route_map_object_t type
, void *object
)
1848 struct bgp_path_info
*path
= object
;
1849 struct rmap_value
*rv
= rule
;
1851 if (type
!= RMAP_BGP
)
1854 path
->attr
->distance
= rv
->value
;
1859 /* set distance rule structure */
1860 static const struct route_map_rule_cmd route_set_distance_cmd
= {
1863 route_value_compile
,
1867 /* `set metric METRIC' */
1869 /* Set metric to attribute. */
1870 static enum route_map_cmd_result_t
1871 route_set_metric(void *rule
, const struct prefix
*prefix
,
1872 route_map_object_t type
, void *object
)
1874 struct rmap_value
*rv
;
1875 struct bgp_path_info
*path
;
1878 if (type
== RMAP_BGP
) {
1879 /* Fetch routemap's rule information. */
1883 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1884 med
= path
->attr
->med
;
1886 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1887 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1892 /* Set metric rule structure. */
1893 static const struct route_map_rule_cmd route_set_metric_cmd
= {
1896 route_value_compile
,
1900 /* `set table (1-4294967295)' */
1902 static enum route_map_cmd_result_t
route_set_table_id(void *rule
,
1903 const struct prefix
*prefix
,
1904 route_map_object_t type
,
1907 struct rmap_value
*rv
;
1908 struct bgp_path_info
*path
;
1910 if (type
== RMAP_BGP
) {
1911 /* Fetch routemap's rule information. */
1915 path
->attr
->rmap_table_id
= rv
->value
;
1920 /* Set table_id rule structure. */
1921 static const struct route_map_rule_cmd route_set_table_id_cmd
= {
1924 route_value_compile
,
1928 /* `set as-path prepend ASPATH' */
1930 /* For AS path prepend mechanism. */
1931 static enum route_map_cmd_result_t
1932 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
,
1933 route_map_object_t type
, void *object
)
1935 struct aspath
*aspath
;
1937 struct bgp_path_info
*path
;
1939 if (type
== RMAP_BGP
) {
1942 if (path
->attr
->aspath
->refcnt
)
1943 new = aspath_dup(path
->attr
->aspath
);
1945 new = path
->attr
->aspath
;
1947 if ((uintptr_t)rule
> 10) {
1949 aspath_prepend(aspath
, new);
1951 as_t as
= aspath_leftmost(new);
1953 as
= path
->peer
->as
;
1954 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1957 path
->attr
->aspath
= new;
1963 static void *route_set_aspath_prepend_compile(const char *arg
)
1967 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1968 return (void *)(uintptr_t)num
;
1970 return route_aspath_compile(arg
);
1973 static void route_set_aspath_prepend_free(void *rule
)
1975 if ((uintptr_t)rule
> 10)
1976 route_aspath_free(rule
);
1980 /* Set as-path prepend rule structure. */
1981 static const struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1983 route_set_aspath_prepend
,
1984 route_set_aspath_prepend_compile
,
1985 route_set_aspath_prepend_free
,
1988 /* `set as-path exclude ASn' */
1990 /* For ASN exclude mechanism.
1991 * Iterate over ASns requested and filter them from the given AS_PATH one by
1993 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1995 static enum route_map_cmd_result_t
1996 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
,
1997 route_map_object_t type
, void *object
)
1999 struct aspath
*new_path
, *exclude_path
;
2000 struct bgp_path_info
*path
;
2002 if (type
== RMAP_BGP
) {
2003 exclude_path
= rule
;
2005 if (path
->attr
->aspath
->refcnt
)
2006 new_path
= aspath_dup(path
->attr
->aspath
);
2008 new_path
= path
->attr
->aspath
;
2009 path
->attr
->aspath
=
2010 aspath_filter_exclude(new_path
, exclude_path
);
2015 /* Set ASn exlude rule structure. */
2016 static const struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
2018 route_set_aspath_exclude
,
2019 route_aspath_compile
,
2023 /* `set community COMMUNITY' */
2024 struct rmap_com_set
{
2025 struct community
*com
;
2030 /* For community set mechanism. */
2031 static enum route_map_cmd_result_t
2032 route_set_community(void *rule
, const struct prefix
*prefix
,
2033 route_map_object_t type
, void *object
)
2035 struct rmap_com_set
*rcs
;
2036 struct bgp_path_info
*path
;
2038 struct community
*new = NULL
;
2039 struct community
*old
;
2040 struct community
*merge
;
2042 if (type
== RMAP_BGP
) {
2046 old
= attr
->community
;
2050 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
2051 attr
->community
= NULL
;
2052 /* See the longer comment down below. */
2053 if (old
&& old
->refcnt
== 0)
2054 community_free(&old
);
2058 /* "additive" case. */
2059 if (rcs
->additive
&& old
) {
2060 merge
= community_merge(community_dup(old
), rcs
->com
);
2062 new = community_uniq_sort(merge
);
2063 community_free(&merge
);
2065 new = community_dup(rcs
->com
);
2067 /* HACK: if the old community is not intern'd,
2068 * we should free it here, or all reference to it may be
2070 * Really need to cleanup attribute caching sometime.
2072 if (old
&& old
->refcnt
== 0)
2073 community_free(&old
);
2075 /* will be interned by caller if required */
2076 attr
->community
= new;
2078 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2084 /* Compile function for set community. */
2085 static void *route_set_community_compile(const char *arg
)
2087 struct rmap_com_set
*rcs
;
2088 struct community
*com
= NULL
;
2093 if (strcmp(arg
, "none") == 0)
2096 sp
= strstr(arg
, "additive");
2098 if (sp
&& sp
> arg
) {
2099 /* "additive" keyword is included. */
2104 com
= community_str2com(arg
);
2113 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2115 rcs
->additive
= additive
;
2121 /* Free function for set community. */
2122 static void route_set_community_free(void *rule
)
2124 struct rmap_com_set
*rcs
= rule
;
2127 community_free(&rcs
->com
);
2128 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2131 /* Set community rule structure. */
2132 static const struct route_map_rule_cmd route_set_community_cmd
= {
2134 route_set_community
,
2135 route_set_community_compile
,
2136 route_set_community_free
,
2139 /* `set community COMMUNITY' */
2140 struct rmap_lcom_set
{
2141 struct lcommunity
*lcom
;
2147 /* For lcommunity set mechanism. */
2148 static enum route_map_cmd_result_t
2149 route_set_lcommunity(void *rule
, const struct prefix
*prefix
,
2150 route_map_object_t type
, void *object
)
2152 struct rmap_lcom_set
*rcs
;
2153 struct bgp_path_info
*path
;
2155 struct lcommunity
*new = NULL
;
2156 struct lcommunity
*old
;
2157 struct lcommunity
*merge
;
2159 if (type
== RMAP_BGP
) {
2163 old
= attr
->lcommunity
;
2168 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
2169 attr
->lcommunity
= NULL
;
2171 /* See the longer comment down below. */
2172 if (old
&& old
->refcnt
== 0)
2173 lcommunity_free(&old
);
2177 if (rcs
->additive
&& old
) {
2178 merge
= lcommunity_merge(lcommunity_dup(old
),
2181 new = lcommunity_uniq_sort(merge
);
2182 lcommunity_free(&merge
);
2184 new = lcommunity_dup(rcs
->lcom
);
2186 /* HACK: if the old large-community is not intern'd,
2187 * we should free it here, or all reference to it may be
2189 * Really need to cleanup attribute caching sometime.
2191 if (old
&& old
->refcnt
== 0)
2192 lcommunity_free(&old
);
2194 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2195 attr
->lcommunity
= new;
2197 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2203 /* Compile function for set community. */
2204 static void *route_set_lcommunity_compile(const char *arg
)
2206 struct rmap_lcom_set
*rcs
;
2207 struct lcommunity
*lcom
= NULL
;
2212 if (strcmp(arg
, "none") == 0)
2215 sp
= strstr(arg
, "additive");
2217 if (sp
&& sp
> arg
) {
2218 /* "additive" keyworkd is included. */
2223 lcom
= lcommunity_str2com(arg
);
2232 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2234 rcs
->additive
= additive
;
2240 /* Free function for set lcommunity. */
2241 static void route_set_lcommunity_free(void *rule
)
2243 struct rmap_lcom_set
*rcs
= rule
;
2246 lcommunity_free(&rcs
->lcom
);
2248 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2251 /* Set community rule structure. */
2252 static const struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2254 route_set_lcommunity
,
2255 route_set_lcommunity_compile
,
2256 route_set_lcommunity_free
,
2259 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2261 /* For large community set mechanism. */
2262 static enum route_map_cmd_result_t
2263 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
,
2264 route_map_object_t type
, void *object
)
2266 struct community_list
*list
;
2267 struct lcommunity
*merge
;
2268 struct lcommunity
*new;
2269 struct lcommunity
*old
;
2270 struct bgp_path_info
*path
;
2271 struct rmap_community
*rcom
= rule
;
2273 if (type
== RMAP_BGP
) {
2278 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2280 LARGE_COMMUNITY_LIST_MASTER
);
2281 old
= path
->attr
->lcommunity
;
2284 merge
= lcommunity_list_match_delete(
2285 lcommunity_dup(old
), list
);
2286 new = lcommunity_uniq_sort(merge
);
2287 lcommunity_free(&merge
);
2289 /* HACK: if the old community is not intern'd,
2290 * we should free it here, or all reference to it may be
2292 * Really need to cleanup attribute caching sometime.
2294 if (old
->refcnt
== 0)
2295 lcommunity_free(&old
);
2297 if (new->size
== 0) {
2298 path
->attr
->lcommunity
= NULL
;
2299 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2300 BGP_ATTR_LARGE_COMMUNITIES
);
2301 lcommunity_free(&new);
2303 path
->attr
->lcommunity
= new;
2304 path
->attr
->flag
|= ATTR_FLAG_BIT(
2305 BGP_ATTR_LARGE_COMMUNITIES
);
2313 /* Compile function for set lcommunity. */
2314 static void *route_set_lcommunity_delete_compile(const char *arg
)
2316 struct rmap_community
*rcom
;
2320 frrstr_split(arg
, " ", &splits
, &num
);
2322 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2323 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2324 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2326 for (int i
= 0; i
< num
; i
++)
2327 XFREE(MTYPE_TMP
, splits
[i
]);
2328 XFREE(MTYPE_TMP
, splits
);
2333 /* Free function for set lcommunity. */
2334 static void route_set_lcommunity_delete_free(void *rule
)
2336 struct rmap_community
*rcom
= rule
;
2338 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2339 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2342 /* Set lcommunity rule structure. */
2343 static const struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2345 route_set_lcommunity_delete
,
2346 route_set_lcommunity_delete_compile
,
2347 route_set_lcommunity_delete_free
,
2351 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2353 /* For community set mechanism. */
2354 static enum route_map_cmd_result_t
2355 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2356 route_map_object_t type
, void *object
)
2358 struct community_list
*list
;
2359 struct community
*merge
;
2360 struct community
*new;
2361 struct community
*old
;
2362 struct bgp_path_info
*path
;
2363 struct rmap_community
*rcom
= rule
;
2365 if (type
== RMAP_BGP
) {
2370 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2372 COMMUNITY_LIST_MASTER
);
2373 old
= path
->attr
->community
;
2376 merge
= community_list_match_delete(community_dup(old
),
2378 new = community_uniq_sort(merge
);
2379 community_free(&merge
);
2381 /* HACK: if the old community is not intern'd,
2382 * we should free it here, or all reference to it may be
2384 * Really need to cleanup attribute caching sometime.
2386 if (old
->refcnt
== 0)
2387 community_free(&old
);
2389 if (new->size
== 0) {
2390 path
->attr
->community
= NULL
;
2392 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2393 community_free(&new);
2395 path
->attr
->community
= new;
2397 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2405 /* Compile function for set community. */
2406 static void *route_set_community_delete_compile(const char *arg
)
2408 struct rmap_community
*rcom
;
2412 frrstr_split(arg
, " ", &splits
, &num
);
2414 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2415 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2416 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2418 for (int i
= 0; i
< num
; i
++)
2419 XFREE(MTYPE_TMP
, splits
[i
]);
2420 XFREE(MTYPE_TMP
, splits
);
2425 /* Free function for set community. */
2426 static void route_set_community_delete_free(void *rule
)
2428 struct rmap_community
*rcom
= rule
;
2430 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2431 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2434 /* Set community rule structure. */
2435 static const struct route_map_rule_cmd route_set_community_delete_cmd
= {
2437 route_set_community_delete
,
2438 route_set_community_delete_compile
,
2439 route_set_community_delete_free
,
2442 /* `set extcommunity rt COMMUNITY' */
2444 /* For community set mechanism. Used by _rt and _soo. */
2445 static enum route_map_cmd_result_t
2446 route_set_ecommunity(void *rule
, const struct prefix
*prefix
,
2447 route_map_object_t type
, void *object
)
2449 struct ecommunity
*ecom
;
2450 struct ecommunity
*new_ecom
;
2451 struct ecommunity
*old_ecom
;
2452 struct bgp_path_info
*path
;
2454 if (type
== RMAP_BGP
) {
2461 /* We assume additive for Extended Community. */
2462 old_ecom
= path
->attr
->ecommunity
;
2465 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2468 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2469 * bgp_update_receive()
2470 * ->refcnt = 0 => set by a previous route-map
2472 if (!old_ecom
->refcnt
)
2473 ecommunity_free(&old_ecom
);
2475 new_ecom
= ecommunity_dup(ecom
);
2477 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2478 path
->attr
->ecommunity
= new_ecom
;
2480 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2485 /* Compile function for set community. */
2486 static void *route_set_ecommunity_rt_compile(const char *arg
)
2488 struct ecommunity
*ecom
;
2490 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2493 return ecommunity_intern(ecom
);
2496 /* Free function for set community. Used by _rt and _soo */
2497 static void route_set_ecommunity_free(void *rule
)
2499 struct ecommunity
*ecom
= rule
;
2500 ecommunity_unintern(&ecom
);
2503 /* Set community rule structure. */
2504 static const struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2506 route_set_ecommunity
,
2507 route_set_ecommunity_rt_compile
,
2508 route_set_ecommunity_free
,
2511 /* `set extcommunity soo COMMUNITY' */
2513 /* Compile function for set community. */
2514 static void *route_set_ecommunity_soo_compile(const char *arg
)
2516 struct ecommunity
*ecom
;
2518 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2522 return ecommunity_intern(ecom
);
2525 /* Set community rule structure. */
2526 static const struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2528 route_set_ecommunity
,
2529 route_set_ecommunity_soo_compile
,
2530 route_set_ecommunity_free
,
2533 /* `set origin ORIGIN' */
2535 /* For origin set. */
2536 static enum route_map_cmd_result_t
2537 route_set_origin(void *rule
, const struct prefix
*prefix
,
2538 route_map_object_t type
, void *object
)
2541 struct bgp_path_info
*path
;
2543 if (type
== RMAP_BGP
) {
2547 path
->attr
->origin
= *origin
;
2553 /* Compile function for origin set. */
2554 static void *route_set_origin_compile(const char *arg
)
2558 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2560 if (strcmp(arg
, "igp") == 0)
2562 else if (strcmp(arg
, "egp") == 0)
2570 /* Compile function for origin set. */
2571 static void route_set_origin_free(void *rule
)
2573 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2576 /* Set origin rule structure. */
2577 static const struct route_map_rule_cmd route_set_origin_cmd
= {
2580 route_set_origin_compile
,
2581 route_set_origin_free
,
2584 /* `set atomic-aggregate' */
2586 /* For atomic aggregate set. */
2587 static enum route_map_cmd_result_t
2588 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
,
2589 route_map_object_t type
, void *object
)
2591 struct bgp_path_info
*path
;
2593 if (type
== RMAP_BGP
) {
2595 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2601 /* Compile function for atomic aggregate. */
2602 static void *route_set_atomic_aggregate_compile(const char *arg
)
2607 /* Compile function for atomic aggregate. */
2608 static void route_set_atomic_aggregate_free(void *rule
)
2613 /* Set atomic aggregate rule structure. */
2614 static const struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2616 route_set_atomic_aggregate
,
2617 route_set_atomic_aggregate_compile
,
2618 route_set_atomic_aggregate_free
,
2621 /* `set aggregator as AS A.B.C.D' */
2624 struct in_addr address
;
2627 static enum route_map_cmd_result_t
2628 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
,
2629 route_map_object_t type
, void *object
)
2631 struct bgp_path_info
*path
;
2632 struct aggregator
*aggregator
;
2634 if (type
== RMAP_BGP
) {
2638 path
->attr
->aggregator_as
= aggregator
->as
;
2639 path
->attr
->aggregator_addr
= aggregator
->address
;
2640 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2646 static void *route_set_aggregator_as_compile(const char *arg
)
2648 struct aggregator
*aggregator
;
2654 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2655 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2656 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2660 aggregator
->as
= strtoul(as
, NULL
, 10);
2661 ret
= inet_aton(address
, &aggregator
->address
);
2663 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2669 static void route_set_aggregator_as_free(void *rule
)
2671 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2674 static const struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2676 route_set_aggregator_as
,
2677 route_set_aggregator_as_compile
,
2678 route_set_aggregator_as_free
,
2681 /* Set tag to object. object must be pointer to struct bgp_path_info */
2682 static enum route_map_cmd_result_t
2683 route_set_tag(void *rule
, const struct prefix
*prefix
,
2684 route_map_object_t type
, void *object
)
2687 struct bgp_path_info
*path
;
2689 if (type
== RMAP_BGP
) {
2694 path
->attr
->tag
= *tag
;
2700 /* Route map commands for tag set. */
2701 static const struct route_map_rule_cmd route_set_tag_cmd
= {
2704 route_map_rule_tag_compile
,
2705 route_map_rule_tag_free
,
2708 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2709 static enum route_map_cmd_result_t
2710 route_set_label_index(void *rule
, const struct prefix
*prefix
,
2711 route_map_object_t type
, void *object
)
2713 struct rmap_value
*rv
;
2714 struct bgp_path_info
*path
;
2715 uint32_t label_index
;
2717 if (type
== RMAP_BGP
) {
2718 /* Fetch routemap's rule information. */
2722 /* Set label-index value. */
2723 label_index
= rv
->value
;
2725 path
->attr
->label_index
= label_index
;
2726 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2733 /* Route map commands for label-index set. */
2734 static const struct route_map_rule_cmd route_set_label_index_cmd
= {
2736 route_set_label_index
,
2737 route_value_compile
,
2741 /* `match ipv6 address IP_ACCESS_LIST' */
2743 static enum route_map_cmd_result_t
2744 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
,
2745 route_map_object_t type
, void *object
)
2747 struct access_list
*alist
;
2749 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2750 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2752 return RMAP_NOMATCH
;
2754 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2758 return RMAP_NOMATCH
;
2761 static void *route_match_ipv6_address_compile(const char *arg
)
2763 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2766 static void route_match_ipv6_address_free(void *rule
)
2768 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2771 /* Route map commands for ip address matching. */
2772 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2774 route_match_ipv6_address
,
2775 route_match_ipv6_address_compile
,
2776 route_match_ipv6_address_free
2779 /* `match ipv6 next-hop IP_ADDRESS' */
2781 static enum route_map_cmd_result_t
2782 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
,
2783 route_map_object_t type
, void *object
)
2785 struct in6_addr
*addr
= rule
;
2786 struct bgp_path_info
*path
;
2788 if (type
== RMAP_BGP
) {
2791 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2794 if (path
->attr
->mp_nexthop_len
2795 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2796 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2799 return RMAP_NOMATCH
;
2802 return RMAP_NOMATCH
;
2805 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2807 struct in6_addr
*address
;
2810 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2812 ret
= inet_pton(AF_INET6
, arg
, address
);
2814 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2821 static void route_match_ipv6_next_hop_free(void *rule
)
2823 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2826 static const struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2828 route_match_ipv6_next_hop
,
2829 route_match_ipv6_next_hop_compile
,
2830 route_match_ipv6_next_hop_free
2833 /* `match ipv6 address prefix-list PREFIX_LIST' */
2835 static enum route_map_cmd_result_t
2836 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2837 route_map_object_t type
, void *object
)
2839 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, type
,
2843 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2845 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2848 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2850 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2853 static const struct route_map_rule_cmd
2854 route_match_ipv6_address_prefix_list_cmd
= {
2855 "ipv6 address prefix-list",
2856 route_match_ipv6_address_prefix_list
,
2857 route_match_ipv6_address_prefix_list_compile
,
2858 route_match_ipv6_address_prefix_list_free
2861 /* `match ipv6 next-hop type <TYPE>' */
2863 static enum route_map_cmd_result_t
2864 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2865 route_map_object_t type
, void *object
)
2867 struct bgp_path_info
*path
;
2868 struct in6_addr
*addr
= rule
;
2870 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2871 path
= (struct bgp_path_info
*)object
;
2873 return RMAP_NOMATCH
;
2875 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2876 && !path
->attr
->nh_ifindex
)
2879 return RMAP_NOMATCH
;
2882 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2884 struct in6_addr
*address
;
2887 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2889 ret
= inet_pton(AF_INET6
, "::0", address
);
2891 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2898 static void route_match_ipv6_next_hop_type_free(void *rule
)
2900 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2903 static const struct route_map_rule_cmd
2904 route_match_ipv6_next_hop_type_cmd
= {
2905 "ipv6 next-hop type",
2906 route_match_ipv6_next_hop_type
,
2907 route_match_ipv6_next_hop_type_compile
,
2908 route_match_ipv6_next_hop_type_free
2911 /* `set ipv6 nexthop global IP_ADDRESS' */
2913 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2914 static enum route_map_cmd_result_t
2915 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
,
2916 route_map_object_t type
, void *object
)
2918 struct in6_addr
*address
;
2919 struct bgp_path_info
*path
;
2921 if (type
== RMAP_BGP
) {
2922 /* Fetch routemap's rule information. */
2926 /* Set next hop value. */
2927 path
->attr
->mp_nexthop_global
= *address
;
2929 /* Set nexthop length. */
2930 if (path
->attr
->mp_nexthop_len
== 0)
2931 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2933 SET_FLAG(path
->attr
->rmap_change_flags
,
2934 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2940 /* Route map `ip next-hop' compile function. Given string is converted
2941 to struct in_addr structure. */
2942 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2945 struct in6_addr
*address
;
2947 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2949 ret
= inet_pton(AF_INET6
, arg
, address
);
2952 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2959 /* Free route map's compiled `ip next-hop' value. */
2960 static void route_set_ipv6_nexthop_global_free(void *rule
)
2962 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2965 /* Route map commands for ip nexthop set. */
2966 static const struct route_map_rule_cmd
2967 route_set_ipv6_nexthop_global_cmd
= {
2968 "ipv6 next-hop global",
2969 route_set_ipv6_nexthop_global
,
2970 route_set_ipv6_nexthop_global_compile
,
2971 route_set_ipv6_nexthop_global_free
2974 /* Set next-hop preference value. */
2975 static enum route_map_cmd_result_t
2976 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2977 route_map_object_t type
, void *object
)
2979 struct bgp_path_info
*path
;
2982 if (type
== RMAP_BGP
) {
2983 /* Fetch routemap's rule information. */
2987 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2988 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
2989 /* Set next hop preference to global */
2990 path
->attr
->mp_nexthop_prefer_global
= true;
2991 SET_FLAG(path
->attr
->rmap_change_flags
,
2992 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2994 path
->attr
->mp_nexthop_prefer_global
= false;
2995 SET_FLAG(path
->attr
->rmap_change_flags
,
2996 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
3002 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
3006 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3012 /* Free route map's compiled `ip next-hop' value. */
3013 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
3015 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3018 /* Route map commands for ip nexthop set preferred. */
3019 static const struct route_map_rule_cmd
3020 route_set_ipv6_nexthop_prefer_global_cmd
= {
3021 "ipv6 next-hop prefer-global",
3022 route_set_ipv6_nexthop_prefer_global
,
3023 route_set_ipv6_nexthop_prefer_global_compile
,
3024 route_set_ipv6_nexthop_prefer_global_free
3027 /* `set ipv6 nexthop local IP_ADDRESS' */
3029 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3030 static enum route_map_cmd_result_t
3031 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
,
3032 route_map_object_t type
, void *object
)
3034 struct in6_addr
*address
;
3035 struct bgp_path_info
*path
;
3037 if (type
== RMAP_BGP
) {
3038 /* Fetch routemap's rule information. */
3042 /* Set next hop value. */
3043 path
->attr
->mp_nexthop_local
= *address
;
3045 /* Set nexthop length. */
3046 if (path
->attr
->mp_nexthop_len
3047 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3048 path
->attr
->mp_nexthop_len
=
3049 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3051 SET_FLAG(path
->attr
->rmap_change_flags
,
3052 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
3058 /* Route map `ip nexthop' compile function. Given string is converted
3059 to struct in_addr structure. */
3060 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
3063 struct in6_addr
*address
;
3065 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3067 ret
= inet_pton(AF_INET6
, arg
, address
);
3070 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3077 /* Free route map's compiled `ip nexthop' value. */
3078 static void route_set_ipv6_nexthop_local_free(void *rule
)
3080 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3083 /* Route map commands for ip nexthop set. */
3084 static const struct route_map_rule_cmd
3085 route_set_ipv6_nexthop_local_cmd
= {
3086 "ipv6 next-hop local",
3087 route_set_ipv6_nexthop_local
,
3088 route_set_ipv6_nexthop_local_compile
,
3089 route_set_ipv6_nexthop_local_free
3092 /* `set ipv6 nexthop peer-address' */
3094 /* Set nexthop to object. ojbect must be pointer to struct attr. */
3095 static enum route_map_cmd_result_t
3096 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
,
3097 route_map_object_t type
, void *object
)
3099 struct in6_addr peer_address
;
3100 struct bgp_path_info
*path
;
3103 if (type
== RMAP_BGP
) {
3104 /* Fetch routemap's rule information. */
3108 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
3109 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
3111 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
3112 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
3113 /* Set next hop value and length in attribute. */
3114 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
3115 path
->attr
->mp_nexthop_local
= peer_address
;
3116 if (path
->attr
->mp_nexthop_len
3117 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
3118 path
->attr
->mp_nexthop_len
=
3119 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
3121 path
->attr
->mp_nexthop_global
= peer_address
;
3122 if (path
->attr
->mp_nexthop_len
== 0)
3123 path
->attr
->mp_nexthop_len
=
3124 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
3127 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
3128 /* The next hop value will be set as part of packet
3130 * Set the flags here to indicate that rewrite needs to
3132 * Also, clear the value - we clear both global and
3134 * nexthops, whether we send one or both is determined
3137 SET_FLAG(path
->attr
->rmap_change_flags
,
3138 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
3139 /* clear next hop value. */
3140 memset(&(path
->attr
->mp_nexthop_global
), 0,
3141 sizeof(struct in6_addr
));
3142 memset(&(path
->attr
->mp_nexthop_local
), 0,
3143 sizeof(struct in6_addr
));
3150 /* Route map `ip next-hop' compile function. Given string is converted
3151 to struct in_addr structure. */
3152 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
3156 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
3162 /* Free route map's compiled `ip next-hop' value. */
3163 static void route_set_ipv6_nexthop_peer_free(void *rule
)
3165 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3168 /* Route map commands for ip nexthop set. */
3169 static const struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
3170 "ipv6 next-hop peer-address",
3171 route_set_ipv6_nexthop_peer
,
3172 route_set_ipv6_nexthop_peer_compile
,
3173 route_set_ipv6_nexthop_peer_free
3176 /* `set ipv4 vpn next-hop A.B.C.D' */
3178 static enum route_map_cmd_result_t
3179 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
,
3180 route_map_object_t type
, void *object
)
3182 struct in_addr
*address
;
3183 struct bgp_path_info
*path
;
3185 if (type
== RMAP_BGP
) {
3186 /* Fetch routemap's rule information. */
3190 /* Set next hop value. */
3191 path
->attr
->mp_nexthop_global_in
= *address
;
3192 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3198 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3201 struct in_addr
*address
;
3203 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3205 ret
= inet_aton(arg
, address
);
3208 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3215 /* `set ipv6 vpn next-hop A.B.C.D' */
3217 static enum route_map_cmd_result_t
3218 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
,
3219 route_map_object_t type
, void *object
)
3221 struct in6_addr
*address
;
3222 struct bgp_path_info
*path
;
3224 if (type
== RMAP_BGP
) {
3225 /* Fetch routemap's rule information. */
3229 /* Set next hop value. */
3230 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3231 sizeof(struct in6_addr
));
3232 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3238 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3241 struct in6_addr
*address
;
3243 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3244 ret
= inet_pton(AF_INET6
, arg
, address
);
3247 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3254 static void route_set_vpn_nexthop_free(void *rule
)
3256 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3259 /* Route map commands for ipv4 next-hop set. */
3260 static const struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3261 "ipv4 vpn next-hop",
3262 route_set_vpnv4_nexthop
,
3263 route_set_vpnv4_nexthop_compile
,
3264 route_set_vpn_nexthop_free
3267 /* Route map commands for ipv6 next-hop set. */
3268 static const struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3269 "ipv6 vpn next-hop",
3270 route_set_vpnv6_nexthop
,
3271 route_set_vpnv6_nexthop_compile
,
3272 route_set_vpn_nexthop_free
3275 /* `set originator-id' */
3277 /* For origin set. */
3278 static enum route_map_cmd_result_t
3279 route_set_originator_id(void *rule
, const struct prefix
*prefix
,
3280 route_map_object_t type
, void *object
)
3282 struct in_addr
*address
;
3283 struct bgp_path_info
*path
;
3285 if (type
== RMAP_BGP
) {
3289 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3290 path
->attr
->originator_id
= *address
;
3296 /* Compile function for originator-id set. */
3297 static void *route_set_originator_id_compile(const char *arg
)
3300 struct in_addr
*address
;
3302 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3304 ret
= inet_aton(arg
, address
);
3307 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3314 /* Compile function for originator_id set. */
3315 static void route_set_originator_id_free(void *rule
)
3317 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3320 /* Set originator-id rule structure. */
3321 static const struct route_map_rule_cmd route_set_originator_id_cmd
= {
3323 route_set_originator_id
,
3324 route_set_originator_id_compile
,
3325 route_set_originator_id_free
,
3328 /* Add bgp route map rule. */
3329 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3330 const char *arg
, route_map_event_t type
)
3332 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3333 int retval
= CMD_SUCCESS
;
3334 enum rmap_compile_rets ret
;
3336 ret
= route_map_add_match(index
, command
, arg
, type
);
3338 case RMAP_RULE_MISSING
:
3339 vty_out(vty
, "%% BGP Can't find rule.\n");
3340 retval
= CMD_WARNING_CONFIG_FAILED
;
3342 case RMAP_COMPILE_ERROR
:
3343 vty_out(vty
, "%% BGP Argument is malformed.\n");
3344 retval
= CMD_WARNING_CONFIG_FAILED
;
3346 case RMAP_COMPILE_SUCCESS
:
3348 * Intentionally doing nothing here.
3356 /* Delete bgp route map rule. */
3357 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3358 const char *arg
, route_map_event_t type
)
3360 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3361 enum rmap_compile_rets ret
;
3362 int retval
= CMD_SUCCESS
;
3363 char *dep_name
= NULL
;
3365 char *rmap_name
= NULL
;
3367 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3368 /* ignore the mundane, the types without any dependency */
3370 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3373 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3375 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3377 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3380 ret
= route_map_delete_match(index
, command
, dep_name
, type
);
3382 case RMAP_RULE_MISSING
:
3383 vty_out(vty
, "%% BGP Can't find rule.\n");
3384 retval
= CMD_WARNING_CONFIG_FAILED
;
3386 case RMAP_COMPILE_ERROR
:
3387 vty_out(vty
, "%% BGP Argument is malformed.\n");
3388 retval
= CMD_WARNING_CONFIG_FAILED
;
3390 case RMAP_COMPILE_SUCCESS
:
3392 * Nothing to do here
3397 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3398 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3404 * This is the workhorse routine for processing in/out routemap
3407 static void bgp_route_map_process_peer(const char *rmap_name
,
3408 struct route_map
*map
, struct peer
*peer
,
3409 int afi
, int safi
, int route_update
)
3411 struct bgp_filter
*filter
;
3413 if (!peer
|| !rmap_name
)
3416 filter
= &peer
->filter
[afi
][safi
];
3418 * in is for non-route-server clients,
3419 * out is for all peers
3421 if (filter
->map
[RMAP_IN
].name
3422 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3423 filter
->map
[RMAP_IN
].map
= map
;
3425 if (route_update
&& peer
->status
== Established
) {
3426 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3427 PEER_FLAG_SOFT_RECONFIG
)) {
3428 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3430 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3431 rmap_name
, peer
->host
);
3433 bgp_soft_reconfig_in(peer
, afi
, safi
);
3434 } else if (CHECK_FLAG(peer
->cap
,
3435 PEER_CAP_REFRESH_OLD_RCV
)
3436 || CHECK_FLAG(peer
->cap
,
3437 PEER_CAP_REFRESH_NEW_RCV
)) {
3438 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3440 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3441 rmap_name
, peer
->host
);
3442 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3449 * For outbound, unsuppress and default-originate map change (content or
3450 * map created), merely update the "config" here, the actual route
3451 * announcement happens at the group level.
3453 if (filter
->map
[RMAP_OUT
].name
3454 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3455 filter
->map
[RMAP_OUT
].map
= map
;
3457 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3458 filter
->usmap
.map
= map
;
3460 if (peer
->default_rmap
[afi
][safi
].name
3461 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3462 peer
->default_rmap
[afi
][safi
].map
= map
;
3465 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3466 struct route_map
*map
,
3469 struct peer_group
*group
;
3470 struct listnode
*node
, *nnode
;
3471 struct bgp_filter
*filter
;
3478 /* All the peers have been updated correctly already. This is
3479 * just updating the placeholder data. No real update required.
3481 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3482 FOREACH_AFI_SAFI (afi
, safi
) {
3483 filter
= &group
->conf
->filter
[afi
][safi
];
3485 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3486 if ((filter
->map
[direct
].name
)
3487 && (strcmp(rmap_name
,
3488 filter
->map
[direct
].name
)
3490 filter
->map
[direct
].map
= map
;
3493 if (filter
->usmap
.name
3494 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3495 filter
->usmap
.map
= map
;
3501 * Note that if an extreme number (tens of thousands) of route-maps are in use
3502 * and if bgp has an extreme number of peers, network statements, etc then this
3503 * function can consume a lot of cycles. This is due to this function being
3504 * called for each route-map and within this function we walk the list of peers,
3505 * network statements, etc looking to see if they use this route-map.
3507 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3514 struct bgp_node
*bn
;
3515 struct bgp_static
*bgp_static
;
3516 struct bgp_aggregate
*aggregate
;
3517 struct listnode
*node
, *nnode
;
3518 struct route_map
*map
;
3519 char buf
[INET6_ADDRSTRLEN
];
3521 map
= route_map_lookup_by_name(rmap_name
);
3523 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3525 /* Ignore dummy peer-group structure */
3526 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3529 FOREACH_AFI_SAFI (afi
, safi
) {
3530 /* process in/out/import/export/default-orig
3532 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3533 safi
, route_update
);
3537 /* for outbound/default-orig route-maps, process for groups */
3538 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3541 /* update peer-group config (template) */
3542 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3544 FOREACH_AFI_SAFI (afi
, safi
) {
3545 /* For table route-map updates. */
3546 if (!bgp_fibupd_safi(safi
))
3549 if (bgp
->table_map
[afi
][safi
].name
3550 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3553 /* bgp->table_map[afi][safi].map is NULL.
3554 * i.e Route map creation event.
3555 * So update applied_counter.
3556 * If it is not NULL, i.e It may be routemap updation or
3557 * deletion. so no need to update the counter.
3559 if (!bgp
->table_map
[afi
][safi
].map
)
3560 route_map_counter_increment(map
);
3561 bgp
->table_map
[afi
][safi
].map
= map
;
3563 if (BGP_DEBUG(zebra
, ZEBRA
))
3565 "Processing route_map %s update on "
3569 bgp_zebra_announce_table(bgp
, afi
, safi
);
3572 /* For network route-map updates. */
3573 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3574 bn
= bgp_route_next(bn
)) {
3575 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3579 if (!bgp_static
->rmap
.name
3580 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3583 if (!bgp_static
->rmap
.map
)
3584 route_map_counter_increment(map
);
3586 bgp_static
->rmap
.map
= map
;
3588 if (route_update
&& !bgp_static
->backdoor
) {
3589 if (bgp_debug_zebra(&bn
->p
))
3591 "Processing route_map %s update on static route %s",
3593 inet_ntop(bn
->p
.family
,
3594 &bn
->p
.u
.prefix
, buf
,
3596 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3601 /* For aggregate-address route-map updates. */
3602 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
3603 bn
= bgp_route_next(bn
)) {
3604 aggregate
= bgp_node_get_bgp_aggregate_info(bn
);
3608 if (!aggregate
->rmap
.name
3609 || (strcmp(rmap_name
, aggregate
->rmap
.name
) != 0))
3612 if (!aggregate
->rmap
.map
)
3613 route_map_counter_increment(map
);
3615 aggregate
->rmap
.map
= map
;
3618 if (bgp_debug_zebra(&bn
->p
))
3620 "Processing route_map %s update on aggregate-address route %s",
3622 inet_ntop(bn
->p
.family
,
3623 &bn
->p
.u
.prefix
, buf
,
3625 bgp_aggregate_route(bgp
, &bn
->p
, afi
, safi
,
3631 /* For redistribute route-map updates. */
3632 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3633 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3634 struct list
*red_list
;
3635 struct bgp_redist
*red
;
3637 red_list
= bgp
->redist
[afi
][i
];
3641 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3643 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3647 route_map_counter_increment(map
);
3649 red
->rmap
.map
= map
;
3654 if (BGP_DEBUG(zebra
, ZEBRA
))
3656 "Processing route_map %s update on redistributed routes",
3659 bgp_redistribute_resend(bgp
, afi
, i
,
3664 /* for type5 command route-maps */
3665 FOREACH_AFI_SAFI (afi
, safi
) {
3666 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3667 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3671 /* Make sure the route-map is populated here if not already done */
3672 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3674 if (BGP_DEBUG(zebra
, ZEBRA
))
3676 "Processing route_map %s update on advertise type5 route command",
3679 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3680 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3681 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3686 static void bgp_route_map_process_update_cb(char *rmap_name
)
3688 struct listnode
*node
, *nnode
;
3691 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3692 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3695 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3696 vnc_routemap_update(bgp
, __func__
);
3700 vpn_policy_routemap_event(rmap_name
);
3703 int bgp_route_map_update_timer(struct thread
*thread
)
3705 bm
->t_rmap_update
= NULL
;
3707 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3712 static void bgp_route_map_mark_update(const char *rmap_name
)
3714 struct listnode
*node
, *nnode
;
3717 /* If new update is received before the current timer timed out,
3718 * turn it off and start a new timer.
3720 if (bm
->t_rmap_update
!= NULL
)
3721 THREAD_OFF(bm
->t_rmap_update
);
3723 /* rmap_update_timer of 0 means don't do route updates */
3724 if (bm
->rmap_update_timer
) {
3725 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3726 NULL
, bm
->rmap_update_timer
,
3727 &bm
->t_rmap_update
);
3729 /* Signal the groups that a route-map update event has
3731 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3732 update_group_policy_update(bgp
,
3733 BGP_POLICY_ROUTE_MAP
,
3736 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3737 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3739 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3740 vnc_routemap_update(bgp
, __func__
);
3745 static void bgp_route_map_add(const char *rmap_name
)
3747 if (route_map_mark_updated(rmap_name
) == 0)
3748 bgp_route_map_mark_update(rmap_name
);
3750 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3753 static void bgp_route_map_delete(const char *rmap_name
)
3755 if (route_map_mark_updated(rmap_name
) == 0)
3756 bgp_route_map_mark_update(rmap_name
);
3758 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3761 static void bgp_route_map_event(const char *rmap_name
)
3763 if (route_map_mark_updated(rmap_name
) == 0)
3764 bgp_route_map_mark_update(rmap_name
);
3766 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3769 DEFUN (match_mac_address
,
3770 match_mac_address_cmd
,
3771 "match mac address WORD",
3774 "Match address of route\n"
3775 "MAC Access-list name\n")
3777 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3778 RMAP_EVENT_FILTER_ADDED
);
3781 DEFUN (no_match_mac_address
,
3782 no_match_mac_address_cmd
,
3783 "no match mac address WORD",
3787 "Match address of route\n"
3788 "MAC acess-list name\n")
3790 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3791 RMAP_EVENT_FILTER_DELETED
);
3794 DEFUN (match_evpn_route_type
,
3795 match_evpn_route_type_cmd
,
3796 "match evpn route-type <macip | multicast | prefix>",
3799 "Match route-type\n"
3804 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3805 RMAP_EVENT_MATCH_ADDED
);
3808 DEFUN (no_match_evpn_route_type
,
3809 no_match_evpn_route_type_cmd
,
3810 "no match evpn route-type <macip | multicast | prefix>",
3814 "Match route-type\n"
3819 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3820 RMAP_EVENT_MATCH_DELETED
);
3824 DEFUN (match_evpn_vni
,
3826 "match evpn vni " CMD_VNI_RANGE
,
3832 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3833 RMAP_EVENT_MATCH_ADDED
);
3836 DEFUN (no_match_evpn_vni
,
3837 no_match_evpn_vni_cmd
,
3838 "no match evpn vni " CMD_VNI_RANGE
,
3845 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3846 RMAP_EVENT_MATCH_DELETED
);
3849 DEFUN (match_evpn_default_route
,
3850 match_evpn_default_route_cmd
,
3851 "match evpn default-route",
3854 "default EVPN type-5 route\n")
3856 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3857 RMAP_EVENT_MATCH_ADDED
);
3860 DEFUN (no_match_evpn_default_route
,
3861 no_match_evpn_default_route_cmd
,
3862 "no match evpn default-route",
3866 "default EVPN type-5 route\n")
3868 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3869 RMAP_EVENT_MATCH_DELETED
);
3872 DEFUN (match_evpn_rd
,
3874 "match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
3877 "Route Distinguisher\n"
3878 "ASN:XX or A.B.C.D:XX\n")
3880 return bgp_route_match_add(vty
, "evpn rd", argv
[3]->arg
,
3881 RMAP_EVENT_MATCH_ADDED
);
3884 DEFUN (no_match_evpn_rd
,
3885 no_match_evpn_rd_cmd
,
3886 "no match evpn rd ASN:NN_OR_IP-ADDRESS:NN",
3890 "Route Distinguisher\n"
3891 "ASN:XX or A.B.C.D:XX\n")
3893 return bgp_route_match_delete(vty
, "evpn rd", argv
[4]->arg
,
3894 RMAP_EVENT_MATCH_DELETED
);
3897 DEFPY(match_vrl_source_vrf
,
3898 match_vrl_source_vrf_cmd
,
3899 "match source-vrf NAME$vrf_name",
3904 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3905 RMAP_EVENT_MATCH_ADDED
);
3908 DEFPY(no_match_vrl_source_vrf
,
3909 no_match_vrl_source_vrf_cmd
,
3910 "no match source-vrf NAME$vrf_name",
3916 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3917 RMAP_EVENT_MATCH_DELETED
);
3922 "match peer <A.B.C.D|X:X::X:X|WORD>",
3924 "Match peer address\n"
3925 "IP address of peer\n"
3926 "IPv6 address of peer\n"
3927 "Interface name of peer\n")
3930 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3931 RMAP_EVENT_MATCH_ADDED
);
3934 DEFUN (match_peer_local
,
3935 match_peer_local_cmd
,
3938 "Match peer address\n"
3939 "Static or Redistributed routes\n")
3941 return bgp_route_match_add(vty
, "peer", "local",
3942 RMAP_EVENT_MATCH_DELETED
);
3945 DEFUN (no_match_peer
,
3947 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3950 "Match peer address\n"
3951 "Static or Redistributed routes\n"
3952 "IP address of peer\n"
3953 "IPv6 address of peer\n"
3954 "Interface name of peer\n")
3958 if (argc
<= idx_peer
)
3959 return bgp_route_match_delete(vty
, "peer", NULL
,
3960 RMAP_EVENT_MATCH_DELETED
);
3961 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3962 RMAP_EVENT_MATCH_DELETED
);
3965 #if defined(HAVE_LUA)
3966 DEFUN (match_command
,
3968 "match command WORD",
3970 "Run a command to match\n"
3971 "The command to run\n")
3973 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3974 RMAP_EVENT_FILTER_ADDED
);
3977 DEFUN (no_match_command
,
3978 no_match_command_cmd
,
3979 "no match command WORD",
3982 "Run a command to match\n"
3983 "The command to run\n")
3985 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3986 RMAP_EVENT_FILTER_DELETED
);
3990 /* match probability */
3991 DEFUN (match_probability
,
3992 match_probability_cmd
,
3993 "match probability (0-100)",
3995 "Match portion of routes defined by percentage value\n"
3996 "Percentage of routes\n")
3999 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
4000 RMAP_EVENT_MATCH_ADDED
);
4004 DEFUN (no_match_probability
,
4005 no_match_probability_cmd
,
4006 "no match probability [(1-99)]",
4009 "Match portion of routes defined by percentage value\n"
4010 "Percentage of routes\n")
4013 if (argc
<= idx_number
)
4014 return bgp_route_match_delete(vty
, "probability", NULL
,
4015 RMAP_EVENT_MATCH_DELETED
);
4016 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
4017 RMAP_EVENT_MATCH_DELETED
);
4021 DEFUN (match_ip_route_source
,
4022 match_ip_route_source_cmd
,
4023 "match ip route-source <(1-199)|(1300-2699)|WORD>",
4026 "Match advertising source address of route\n"
4027 "IP access-list number\n"
4028 "IP access-list number (expanded range)\n"
4029 "IP standard access-list name\n")
4032 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
4033 RMAP_EVENT_FILTER_ADDED
);
4037 DEFUN (no_match_ip_route_source
,
4038 no_match_ip_route_source_cmd
,
4039 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
4043 "Match advertising source address of route\n"
4044 "IP access-list number\n"
4045 "IP access-list number (expanded range)\n"
4046 "IP standard access-list name\n")
4049 if (argc
<= idx_number
)
4050 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
4051 RMAP_EVENT_FILTER_DELETED
);
4052 return bgp_route_match_delete(vty
, "ip route-source",
4053 argv
[idx_number
]->arg
,
4054 RMAP_EVENT_FILTER_DELETED
);
4058 DEFUN (match_ip_route_source_prefix_list
,
4059 match_ip_route_source_prefix_list_cmd
,
4060 "match ip route-source prefix-list WORD",
4063 "Match advertising source address of route\n"
4064 "Match entries of prefix-lists\n"
4065 "IP prefix-list name\n")
4068 return bgp_route_match_add(vty
, "ip route-source prefix-list",
4069 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
4073 DEFUN (no_match_ip_route_source_prefix_list
,
4074 no_match_ip_route_source_prefix_list_cmd
,
4075 "no match ip route-source prefix-list [WORD]",
4079 "Match advertising source address of route\n"
4080 "Match entries of prefix-lists\n"
4081 "IP prefix-list name\n")
4084 if (argc
<= idx_word
)
4085 return bgp_route_match_delete(vty
,
4086 "ip route-source prefix-list",
4087 NULL
, RMAP_EVENT_PLIST_DELETED
);
4088 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
4089 argv
[idx_word
]->arg
,
4090 RMAP_EVENT_PLIST_DELETED
);
4094 DEFUN (match_local_pref
,
4095 match_local_pref_cmd
,
4096 "match local-preference (0-4294967295)",
4098 "Match local-preference of route\n"
4102 return bgp_route_match_add(vty
, "local-preference",
4103 argv
[idx_number
]->arg
,
4104 RMAP_EVENT_MATCH_ADDED
);
4108 DEFUN (no_match_local_pref
,
4109 no_match_local_pref_cmd
,
4110 "no match local-preference [(0-4294967295)]",
4113 "Match local preference of route\n"
4114 "Local preference value\n")
4116 int idx_localpref
= 3;
4117 if (argc
<= idx_localpref
)
4118 return bgp_route_match_delete(vty
, "local-preference", NULL
,
4119 RMAP_EVENT_MATCH_DELETED
);
4120 return bgp_route_match_delete(vty
, "local-preference",
4121 argv
[idx_localpref
]->arg
,
4122 RMAP_EVENT_MATCH_DELETED
);
4126 DEFUN (match_community
,
4127 match_community_cmd
,
4128 "match community <(1-99)|(100-500)|WORD> [exact-match]",
4130 "Match BGP community list\n"
4131 "Community-list number (standard)\n"
4132 "Community-list number (expanded)\n"
4133 "Community-list name\n"
4134 "Do exact matching of communities\n")
4136 int idx_comm_list
= 2;
4141 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4142 strlen(argv
[idx_comm_list
]->arg
)
4143 + strlen("exact-match") + 2);
4145 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
4147 argstr
= argv
[idx_comm_list
]->arg
;
4149 ret
= bgp_route_match_add(vty
, "community", argstr
,
4150 RMAP_EVENT_CLIST_ADDED
);
4152 if (argstr
!= argv
[idx_comm_list
]->arg
)
4153 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4158 DEFUN (no_match_community
,
4159 no_match_community_cmd
,
4160 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
4163 "Match BGP community list\n"
4164 "Community-list number (standard)\n"
4165 "Community-list number (expanded)\n"
4166 "Community-list name\n"
4167 "Do exact matching of communities\n")
4169 return bgp_route_match_delete(vty
, "community", NULL
,
4170 RMAP_EVENT_CLIST_DELETED
);
4173 DEFUN (match_lcommunity
,
4174 match_lcommunity_cmd
,
4175 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
4177 "Match BGP large community list\n"
4178 "Large Community-list number (standard)\n"
4179 "Large Community-list number (expanded)\n"
4180 "Large Community-list name\n"
4181 "Do exact matching of communities\n")
4183 int idx_lcomm_list
= 2;
4188 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4189 strlen(argv
[idx_lcomm_list
]->arg
)
4190 + strlen("exact-match") + 2);
4192 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
4194 argstr
= argv
[idx_lcomm_list
]->arg
;
4196 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
4197 RMAP_EVENT_LLIST_ADDED
);
4198 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
4199 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4204 DEFUN (no_match_lcommunity
,
4205 no_match_lcommunity_cmd
,
4206 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
4209 "Match BGP large community list\n"
4210 "Large Community-list number (standard)\n"
4211 "Large Community-list number (expanded)\n"
4212 "Large Community-list name\n"
4213 "Do exact matching of communities\n")
4215 return bgp_route_match_delete(vty
, "large-community", NULL
,
4216 RMAP_EVENT_LLIST_DELETED
);
4219 DEFUN (match_ecommunity
,
4220 match_ecommunity_cmd
,
4221 "match extcommunity <(1-99)|(100-500)|WORD>",
4223 "Match BGP/VPN extended community list\n"
4224 "Extended community-list number (standard)\n"
4225 "Extended community-list number (expanded)\n"
4226 "Extended community-list name\n")
4228 int idx_comm_list
= 2;
4229 return bgp_route_match_add(vty
, "extcommunity",
4230 argv
[idx_comm_list
]->arg
,
4231 RMAP_EVENT_ECLIST_ADDED
);
4235 DEFUN (no_match_ecommunity
,
4236 no_match_ecommunity_cmd
,
4237 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
4240 "Match BGP/VPN extended community list\n"
4241 "Extended community-list number (standard)\n"
4242 "Extended community-list number (expanded)\n"
4243 "Extended community-list name\n")
4245 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
4246 RMAP_EVENT_ECLIST_DELETED
);
4250 DEFUN (match_aspath
,
4252 "match as-path WORD",
4254 "Match BGP AS path list\n"
4255 "AS path access-list name\n")
4258 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
4259 RMAP_EVENT_ASLIST_ADDED
);
4263 DEFUN (no_match_aspath
,
4264 no_match_aspath_cmd
,
4265 "no match as-path [WORD]",
4268 "Match BGP AS path list\n"
4269 "AS path access-list name\n")
4271 return bgp_route_match_delete(vty
, "as-path", NULL
,
4272 RMAP_EVENT_ASLIST_DELETED
);
4276 DEFUN (match_origin
,
4278 "match origin <egp|igp|incomplete>",
4283 "unknown heritage\n")
4286 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4287 return bgp_route_match_add(vty
, "origin", "igp",
4288 RMAP_EVENT_MATCH_ADDED
);
4289 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4290 return bgp_route_match_add(vty
, "origin", "egp",
4291 RMAP_EVENT_MATCH_ADDED
);
4292 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4293 return bgp_route_match_add(vty
, "origin", "incomplete",
4294 RMAP_EVENT_MATCH_ADDED
);
4296 vty_out(vty
, "%% Invalid match origin type\n");
4297 return CMD_WARNING_CONFIG_FAILED
;
4301 DEFUN (no_match_origin
,
4302 no_match_origin_cmd
,
4303 "no match origin [<egp|igp|incomplete>]",
4309 "unknown heritage\n")
4311 return bgp_route_match_delete(vty
, "origin", NULL
,
4312 RMAP_EVENT_MATCH_DELETED
);
4315 DEFUN (set_table_id
,
4317 "set table (1-4294967295)",
4319 "export route to non-main kernel table\n"
4320 "Kernel routing table id\n")
4324 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4326 return generic_set_add(vty
, index
, "table", argv
[idx_id
]->arg
);
4329 DEFUN (no_set_table_id
,
4330 no_set_table_id_cmd
,
4334 "export route to non-main kernel table\n")
4336 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4338 return generic_set_delete(vty
, index
, "table", NULL
);
4341 DEFUN (set_ip_nexthop_peer
,
4342 set_ip_nexthop_peer_cmd
,
4343 "[no] set ip next-hop peer-address",
4347 "Next hop address\n"
4348 "Use peer address (for BGP only)\n")
4350 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4351 const char *) = strmatch(argv
[0]->text
, "no")
4352 ? generic_set_delete
4355 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4359 DEFUN (set_ip_nexthop_unchanged
,
4360 set_ip_nexthop_unchanged_cmd
,
4361 "[no] set ip next-hop unchanged",
4365 "Next hop address\n"
4366 "Don't modify existing Next hop address\n")
4368 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4369 const char *) = strmatch(argv
[0]->text
, "no")
4370 ? generic_set_delete
4373 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4377 DEFUN (set_distance
,
4379 "set distance (0-255)",
4381 "BGP Administrative Distance to use\n"
4386 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4387 "distance", argv
[idx_number
]->arg
);
4390 DEFUN (no_set_distance
,
4391 no_set_distance_cmd
,
4392 "no set distance [(0-255)]",
4394 "BGP Administrative Distance to use\n"
4397 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4401 DEFUN (set_local_pref
,
4403 "set local-preference (0-4294967295)",
4405 "BGP local preference path attribute\n"
4406 "Preference value\n")
4409 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4410 "local-preference", argv
[idx_number
]->arg
);
4414 DEFUN (no_set_local_pref
,
4415 no_set_local_pref_cmd
,
4416 "no set local-preference [(0-4294967295)]",
4419 "BGP local preference path attribute\n"
4420 "Preference value\n")
4422 int idx_localpref
= 3;
4423 if (argc
<= idx_localpref
)
4424 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4425 "local-preference", NULL
);
4426 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4427 "local-preference", argv
[idx_localpref
]->arg
);
4433 "set weight (0-4294967295)",
4435 "BGP weight for routing table\n"
4439 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4440 argv
[idx_number
]->arg
);
4444 DEFUN (no_set_weight
,
4446 "no set weight [(0-4294967295)]",
4449 "BGP weight for routing table\n"
4453 if (argc
<= idx_weight
)
4454 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4456 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4457 "weight", argv
[idx_weight
]->arg
);
4460 DEFUN (set_label_index
,
4461 set_label_index_cmd
,
4462 "set label-index (0-1048560)",
4464 "Label index to associate with the prefix\n"
4465 "Label index value\n")
4468 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4469 "label-index", argv
[idx_number
]->arg
);
4472 DEFUN (no_set_label_index
,
4473 no_set_label_index_cmd
,
4474 "no set label-index [(0-1048560)]",
4477 "Label index to associate with the prefix\n"
4478 "Label index value\n")
4480 int idx_label_index
= 3;
4481 if (argc
<= idx_label_index
)
4482 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4483 "label-index", NULL
);
4484 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4485 "label-index", argv
[idx_label_index
]->arg
);
4488 DEFUN (set_aspath_prepend_asn
,
4489 set_aspath_prepend_asn_cmd
,
4490 "set as-path prepend (1-4294967295)...",
4492 "Transform BGP AS_PATH attribute\n"
4493 "Prepend to the as-path\n"
4500 str
= argv_concat(argv
, argc
, idx_asn
);
4501 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4502 "as-path prepend", str
);
4503 XFREE(MTYPE_TMP
, str
);
4508 DEFUN (set_aspath_prepend_lastas
,
4509 set_aspath_prepend_lastas_cmd
,
4510 "set as-path prepend last-as (1-10)",
4512 "Transform BGP AS_PATH attribute\n"
4513 "Prepend to the as-path\n"
4514 "Use the peer's AS-number\n"
4515 "Number of times to insert\n")
4517 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4520 DEFUN (no_set_aspath_prepend
,
4521 no_set_aspath_prepend_cmd
,
4522 "no set as-path prepend [(1-4294967295)]",
4525 "Transform BGP AS_PATH attribute\n"
4526 "Prepend to the as-path\n"
4533 str
= argv_concat(argv
, argc
, idx_asn
);
4534 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4535 "as-path prepend", str
);
4536 XFREE(MTYPE_TMP
, str
);
4540 DEFUN (no_set_aspath_prepend_lastas
,
4541 no_set_aspath_prepend_lastas_cmd
,
4542 "no set as-path prepend last-as [(1-10)]",
4545 "Transform BGP AS_PATH attribute\n"
4546 "Prepend to the as-path\n"
4547 "Use the peers AS-number\n"
4548 "Number of times to insert\n")
4550 return no_set_aspath_prepend(self
, vty
, argc
, argv
);
4553 DEFUN (set_aspath_exclude
,
4554 set_aspath_exclude_cmd
,
4555 "set as-path exclude (1-4294967295)...",
4557 "Transform BGP AS-path attribute\n"
4558 "Exclude from the as-path\n"
4565 str
= argv_concat(argv
, argc
, idx_asn
);
4566 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4567 "as-path exclude", str
);
4568 XFREE(MTYPE_TMP
, str
);
4572 DEFUN (no_set_aspath_exclude
,
4573 no_set_aspath_exclude_cmd
,
4574 "no set as-path exclude (1-4294967295)...",
4577 "Transform BGP AS_PATH attribute\n"
4578 "Exclude from the as-path\n"
4585 str
= argv_concat(argv
, argc
, idx_asn
);
4586 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4587 "as-path exclude", str
);
4588 XFREE(MTYPE_TMP
, str
);
4592 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4593 "no set as-path exclude",
4595 "Transform BGP AS_PATH attribute\n"
4596 "Exclude from the as-path\n")
4598 DEFUN (set_community
,
4600 "set community AA:NN...",
4602 "BGP community attribute\n"
4610 struct community
*com
= NULL
;
4615 b
= buffer_new(1024);
4617 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4618 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4625 buffer_putc(b
, ' ');
4629 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4631 buffer_putstr(b
, "internet");
4634 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4636 buffer_putstr(b
, "local-AS");
4639 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4640 && strncmp(argv
[i
]->arg
, "no-advertise",
4641 strlen(argv
[i
]->arg
))
4643 buffer_putstr(b
, "no-advertise");
4646 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4647 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4649 buffer_putstr(b
, "no-export");
4652 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4653 strlen(argv
[i
]->arg
))
4655 buffer_putstr(b
, "graceful-shutdown");
4658 buffer_putstr(b
, argv
[i
]->arg
);
4660 buffer_putc(b
, '\0');
4662 /* Fetch result string then compile it to communities attribute. */
4663 str
= buffer_getstr(b
);
4667 com
= community_str2com(str
);
4668 XFREE(MTYPE_TMP
, str
);
4671 /* Can't compile user input into communities attribute. */
4673 vty_out(vty
, "%% Malformed communities attribute\n");
4674 return CMD_WARNING_CONFIG_FAILED
;
4677 /* Set communites attribute string. */
4678 str
= community_str(com
, false);
4681 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4682 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4683 strlcpy(argstr
, str
, argstr_sz
);
4684 strlcat(argstr
, " additive", argstr_sz
);
4685 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4686 "community", argstr
);
4687 XFREE(MTYPE_TMP
, argstr
);
4689 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4692 community_free(&com
);
4697 DEFUN (set_community_none
,
4698 set_community_none_cmd
,
4699 "set community none",
4701 "BGP community attribute\n"
4702 "No community attribute\n")
4704 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4705 "community", "none");
4708 DEFUN (no_set_community
,
4709 no_set_community_cmd
,
4710 "no set community AA:NN...",
4713 "BGP community attribute\n"
4716 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4720 ALIAS (no_set_community
,
4721 no_set_community_short_cmd
,
4725 "BGP community attribute\n")
4728 DEFUN (set_community_delete
,
4729 set_community_delete_cmd
,
4730 "set comm-list <(1-99)|(100-500)|WORD> delete",
4732 "set BGP community list (for deletion)\n"
4733 "Community-list number (standard)\n"
4734 "Community-list number (expanded)\n"
4735 "Community-list name\n"
4736 "Delete matching communities\n")
4738 int idx_comm_list
= 2;
4741 args
= argv_concat(argv
, argc
, idx_comm_list
);
4742 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4744 XFREE(MTYPE_TMP
, args
);
4749 DEFUN (no_set_community_delete
,
4750 no_set_community_delete_cmd
,
4751 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4754 "set BGP community list (for deletion)\n"
4755 "Community-list number (standard)\n"
4756 "Community-list number (expanded)\n"
4757 "Community-list name\n"
4758 "Delete matching communities\n")
4760 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4764 DEFUN (set_lcommunity
,
4766 "set large-community AA:BB:CC...",
4768 "BGP large community attribute\n"
4769 "Large Community number in aa:bb:cc format or additive\n")
4774 str
= argv_concat(argv
, argc
, 2);
4775 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4776 "large-community", str
);
4777 XFREE(MTYPE_TMP
, str
);
4782 DEFUN (set_lcommunity_none
,
4783 set_lcommunity_none_cmd
,
4784 "set large-community none",
4786 "BGP large community attribute\n"
4787 "No large community attribute\n")
4789 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4790 "large-community", "none");
4793 DEFUN (no_set_lcommunity
,
4794 no_set_lcommunity_cmd
,
4795 "no set large-community none",
4798 "BGP large community attribute\n"
4799 "No community attribute\n")
4801 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4802 "large-community", NULL
);
4805 DEFUN (no_set_lcommunity1
,
4806 no_set_lcommunity1_cmd
,
4807 "no set large-community AA:BB:CC...",
4810 "BGP large community attribute\n"
4811 "Large community in AA:BB:CC... format or additive\n")
4813 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4814 "large-community", NULL
);
4817 ALIAS (no_set_lcommunity1
,
4818 no_set_lcommunity1_short_cmd
,
4819 "no set large-community",
4822 "BGP large community attribute\n")
4824 DEFUN (set_lcommunity_delete
,
4825 set_lcommunity_delete_cmd
,
4826 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4828 "set BGP large community list (for deletion)\n"
4829 "Large Community-list number (standard)\n"
4830 "Large Communitly-list number (expanded)\n"
4831 "Large Community-list name\n"
4832 "Delete matching large communities\n")
4834 int idx_lcomm_list
= 2;
4837 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
4838 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4839 "large-comm-list", args
);
4840 XFREE(MTYPE_TMP
, args
);
4845 DEFUN (no_set_lcommunity_delete
,
4846 no_set_lcommunity_delete_cmd
,
4847 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4850 "set BGP large community list (for deletion)\n"
4851 "Large Community-list number (standard)\n"
4852 "Large Communitly-list number (expanded)\n"
4853 "Large Community-list name\n"
4854 "Delete matching large communities\n")
4856 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4857 "large-comm-list", NULL
);
4860 ALIAS (no_set_lcommunity_delete
,
4861 no_set_lcommunity_delete_short_cmd
,
4862 "no set large-comm-list",
4865 "set BGP large community list (for deletion)\n")
4867 DEFUN (set_ecommunity_rt
,
4868 set_ecommunity_rt_cmd
,
4869 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4871 "BGP extended community attribute\n"
4872 "Route Target extended community\n"
4873 "VPN extended community\n")
4879 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4880 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4881 "extcommunity rt", str
);
4882 XFREE(MTYPE_TMP
, str
);
4887 DEFUN (no_set_ecommunity_rt
,
4888 no_set_ecommunity_rt_cmd
,
4889 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4892 "BGP extended community attribute\n"
4893 "Route Target extended community\n"
4894 "VPN extended community\n")
4896 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4897 "extcommunity rt", NULL
);
4900 ALIAS (no_set_ecommunity_rt
,
4901 no_set_ecommunity_rt_short_cmd
,
4902 "no set extcommunity rt",
4905 "BGP extended community attribute\n"
4906 "Route Target extended community\n")
4908 DEFUN (set_ecommunity_soo
,
4909 set_ecommunity_soo_cmd
,
4910 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4912 "BGP extended community attribute\n"
4913 "Site-of-Origin extended community\n"
4914 "VPN extended community\n")
4920 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4921 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4922 "extcommunity soo", str
);
4923 XFREE(MTYPE_TMP
, str
);
4928 DEFUN (no_set_ecommunity_soo
,
4929 no_set_ecommunity_soo_cmd
,
4930 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4933 "BGP extended community attribute\n"
4934 "Site-of-Origin extended community\n"
4935 "VPN extended community\n")
4937 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4938 "extcommunity soo", NULL
);
4941 ALIAS (no_set_ecommunity_soo
,
4942 no_set_ecommunity_soo_short_cmd
,
4943 "no set extcommunity soo",
4946 "GP extended community attribute\n"
4947 "Site-of-Origin extended community\n")
4951 "set origin <egp|igp|incomplete>",
4956 "unknown heritage\n")
4959 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4960 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4962 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4963 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4965 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4966 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4967 "origin", "incomplete");
4969 vty_out(vty
, "%% Invalid set origin type\n");
4970 return CMD_WARNING_CONFIG_FAILED
;
4974 DEFUN (no_set_origin
,
4976 "no set origin [<egp|igp|incomplete>]",
4982 "unknown heritage\n")
4984 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4989 DEFUN (set_atomic_aggregate
,
4990 set_atomic_aggregate_cmd
,
4991 "set atomic-aggregate",
4993 "BGP atomic aggregate attribute\n" )
4995 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4996 "atomic-aggregate", NULL
);
4999 DEFUN (no_set_atomic_aggregate
,
5000 no_set_atomic_aggregate_cmd
,
5001 "no set atomic-aggregate",
5004 "BGP atomic aggregate attribute\n" )
5006 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5007 "atomic-aggregate", NULL
);
5010 DEFUN (set_aggregator_as
,
5011 set_aggregator_as_cmd
,
5012 "set aggregator as (1-4294967295) A.B.C.D",
5014 "BGP aggregator attribute\n"
5015 "AS number of aggregator\n"
5017 "IP address of aggregator\n")
5022 struct in_addr address
;
5025 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
5027 vty_out(vty
, "Aggregator IP address is invalid\n");
5028 return CMD_WARNING_CONFIG_FAILED
;
5031 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
5032 strlen(argv
[idx_number
]->arg
)
5033 + strlen(argv
[idx_ipv4
]->arg
) + 2);
5035 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
5037 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5038 "aggregator as", argstr
);
5040 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
5046 DEFUN (no_set_aggregator_as
,
5047 no_set_aggregator_as_cmd
,
5048 "no set aggregator as [(1-4294967295) A.B.C.D]",
5051 "BGP aggregator attribute\n"
5052 "AS number of aggregator\n"
5054 "IP address of aggregator\n")
5059 struct in_addr address
;
5062 if (argc
<= idx_asn
)
5063 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5064 "aggregator as", NULL
);
5066 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
5068 vty_out(vty
, "Aggregator IP address is invalid\n");
5069 return CMD_WARNING_CONFIG_FAILED
;
5072 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
5073 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
5076 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
5078 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5079 "aggregator as", argstr
);
5081 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
5086 DEFUN (match_ipv6_next_hop
,
5087 match_ipv6_next_hop_cmd
,
5088 "match ipv6 next-hop X:X::X:X",
5091 "Match IPv6 next-hop address of route\n"
5092 "IPv6 address of next hop\n")
5095 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
5096 RMAP_EVENT_MATCH_ADDED
);
5099 DEFUN (no_match_ipv6_next_hop
,
5100 no_match_ipv6_next_hop_cmd
,
5101 "no match ipv6 next-hop X:X::X:X",
5105 "Match IPv6 next-hop address of route\n"
5106 "IPv6 address of next hop\n")
5109 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
5110 RMAP_EVENT_MATCH_DELETED
);
5114 DEFUN (set_ipv6_nexthop_peer
,
5115 set_ipv6_nexthop_peer_cmd
,
5116 "set ipv6 next-hop peer-address",
5119 "Next hop address\n"
5120 "Use peer address (for BGP only)\n")
5122 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5123 "ipv6 next-hop peer-address", NULL
);
5126 DEFUN (no_set_ipv6_nexthop_peer
,
5127 no_set_ipv6_nexthop_peer_cmd
,
5128 "no set ipv6 next-hop peer-address",
5132 "IPv6 next-hop address\n"
5133 "Use peer address (for BGP only)\n")
5135 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5136 "ipv6 next-hop peer-address", NULL
);
5139 DEFUN (set_ipv6_nexthop_prefer_global
,
5140 set_ipv6_nexthop_prefer_global_cmd
,
5141 "set ipv6 next-hop prefer-global",
5144 "IPv6 next-hop address\n"
5145 "Prefer global over link-local if both exist\n")
5147 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5148 "ipv6 next-hop prefer-global", NULL
);
5152 DEFUN (no_set_ipv6_nexthop_prefer_global
,
5153 no_set_ipv6_nexthop_prefer_global_cmd
,
5154 "no set ipv6 next-hop prefer-global",
5158 "IPv6 next-hop address\n"
5159 "Prefer global over link-local if both exist\n")
5161 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5162 "ipv6 next-hop prefer-global", NULL
);
5165 DEFUN (set_ipv6_nexthop_global
,
5166 set_ipv6_nexthop_global_cmd
,
5167 "set ipv6 next-hop global X:X::X:X",
5170 "IPv6 next-hop address\n"
5171 "IPv6 global address\n"
5172 "IPv6 address of next hop\n")
5175 struct in6_addr addr
;
5178 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
5180 vty_out(vty
, "%% Malformed nexthop address\n");
5181 return CMD_WARNING_CONFIG_FAILED
;
5183 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
5184 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
5185 vty_out(vty
, "%% Invalid global nexthop address\n");
5186 return CMD_WARNING_CONFIG_FAILED
;
5189 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5190 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
5194 DEFUN (no_set_ipv6_nexthop_global
,
5195 no_set_ipv6_nexthop_global_cmd
,
5196 "no set ipv6 next-hop global X:X::X:X",
5200 "IPv6 next-hop address\n"
5201 "IPv6 global address\n"
5202 "IPv6 address of next hop\n")
5205 if (argc
<= idx_ipv6
)
5206 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5207 "ipv6 next-hop global", NULL
);
5208 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5209 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
5212 #ifdef KEEP_OLD_VPN_COMMANDS
5213 DEFUN (set_vpn_nexthop
,
5214 set_vpn_nexthop_cmd
,
5215 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5217 "VPNv4 information\n"
5218 "VPN next-hop address\n"
5219 "IP address of next hop\n"
5220 "VPNv6 information\n"
5221 "VPN next-hop address\n"
5222 "IPv6 address of next hop\n")
5228 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5230 return generic_set_add(
5231 vty
, VTY_GET_CONTEXT(route_map_index
),
5232 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5234 return generic_set_add(
5235 vty
, VTY_GET_CONTEXT(route_map_index
),
5236 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5241 DEFUN (no_set_vpn_nexthop
,
5242 no_set_vpn_nexthop_cmd
,
5243 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5246 "VPNv4 information\n"
5247 "VPN next-hop address\n"
5248 "IP address of next hop\n"
5249 "VPNv6 information\n"
5250 "VPN next-hop address\n"
5251 "IPv6 address of next hop\n")
5261 arg
= argv
[idx_ip
]->arg
;
5262 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5264 return generic_set_delete(
5265 vty
, VTY_GET_CONTEXT(route_map_index
),
5266 "ipv4 vpn next-hop", arg
);
5268 return generic_set_delete(
5269 vty
, VTY_GET_CONTEXT(route_map_index
),
5270 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5274 #endif /* KEEP_OLD_VPN_COMMANDS */
5276 DEFUN (set_ipx_vpn_nexthop
,
5277 set_ipx_vpn_nexthop_cmd
,
5278 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
5280 "IPv4 information\n"
5281 "IPv6 information\n"
5283 "VPN next-hop address\n"
5284 "IP address of next hop\n"
5285 "IPv6 address of next hop\n")
5291 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5293 return generic_set_add(
5294 vty
, VTY_GET_CONTEXT(route_map_index
),
5295 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5297 return generic_set_add(
5298 vty
, VTY_GET_CONTEXT(route_map_index
),
5299 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5304 DEFUN (no_set_ipx_vpn_nexthop
,
5305 no_set_ipx_vpn_nexthop_cmd
,
5306 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
5309 "IPv4 information\n"
5310 "IPv6 information\n"
5312 "VPN next-hop address\n"
5313 "IP address of next hop\n"
5314 "IPv6 address of next hop\n")
5324 arg
= argv
[idx_ip
]->arg
;
5325 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5327 return generic_set_delete(
5328 vty
, VTY_GET_CONTEXT(route_map_index
),
5329 "ipv4 vpn next-hop", arg
);
5331 return generic_set_delete(
5332 vty
, VTY_GET_CONTEXT(route_map_index
),
5333 "ipv6 vpn next-hop", arg
);
5338 DEFUN (set_originator_id
,
5339 set_originator_id_cmd
,
5340 "set originator-id A.B.C.D",
5342 "BGP originator ID attribute\n"
5343 "IP address of originator\n")
5346 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5347 "originator-id", argv
[idx_ipv4
]->arg
);
5351 DEFUN (no_set_originator_id
,
5352 no_set_originator_id_cmd
,
5353 "no set originator-id [A.B.C.D]",
5356 "BGP originator ID attribute\n"
5357 "IP address of originator\n")
5361 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
5363 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5364 "originator-id", arg
);
5368 /* Initialization of route map. */
5369 void bgp_route_map_init(void)
5373 route_map_add_hook(bgp_route_map_add
);
5374 route_map_delete_hook(bgp_route_map_delete
);
5375 route_map_event_hook(bgp_route_map_event
);
5377 route_map_match_interface_hook(generic_match_add
);
5378 route_map_no_match_interface_hook(generic_match_delete
);
5380 route_map_match_ip_address_hook(generic_match_add
);
5381 route_map_no_match_ip_address_hook(generic_match_delete
);
5383 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
5384 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
5386 route_map_match_ip_next_hop_hook(generic_match_add
);
5387 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
5389 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
5390 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5392 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5393 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5395 route_map_match_ipv6_address_hook(generic_match_add
);
5396 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5398 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5399 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5401 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5402 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5404 route_map_match_metric_hook(generic_match_add
);
5405 route_map_no_match_metric_hook(generic_match_delete
);
5407 route_map_match_tag_hook(generic_match_add
);
5408 route_map_no_match_tag_hook(generic_match_delete
);
5410 route_map_set_ip_nexthop_hook(generic_set_add
);
5411 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5413 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5414 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5416 route_map_set_metric_hook(generic_set_add
);
5417 route_map_no_set_metric_hook(generic_set_delete
);
5419 route_map_set_tag_hook(generic_set_add
);
5420 route_map_no_set_tag_hook(generic_set_delete
);
5422 route_map_install_match(&route_match_peer_cmd
);
5423 route_map_install_match(&route_match_local_pref_cmd
);
5424 #if defined(HAVE_LUA)
5425 route_map_install_match(&route_match_command_cmd
);
5427 route_map_install_match(&route_match_ip_address_cmd
);
5428 route_map_install_match(&route_match_ip_next_hop_cmd
);
5429 route_map_install_match(&route_match_ip_route_source_cmd
);
5430 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5431 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5432 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5433 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5434 route_map_install_match(&route_match_aspath_cmd
);
5435 route_map_install_match(&route_match_community_cmd
);
5436 route_map_install_match(&route_match_lcommunity_cmd
);
5437 route_map_install_match(&route_match_ecommunity_cmd
);
5438 route_map_install_match(&route_match_local_pref_cmd
);
5439 route_map_install_match(&route_match_metric_cmd
);
5440 route_map_install_match(&route_match_origin_cmd
);
5441 route_map_install_match(&route_match_probability_cmd
);
5442 route_map_install_match(&route_match_interface_cmd
);
5443 route_map_install_match(&route_match_tag_cmd
);
5444 route_map_install_match(&route_match_mac_address_cmd
);
5445 route_map_install_match(&route_match_evpn_vni_cmd
);
5446 route_map_install_match(&route_match_evpn_route_type_cmd
);
5447 route_map_install_match(&route_match_evpn_rd_cmd
);
5448 route_map_install_match(&route_match_evpn_default_route_cmd
);
5449 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5451 route_map_install_set(&route_set_table_id_cmd
);
5452 route_map_install_set(&route_set_ip_nexthop_cmd
);
5453 route_map_install_set(&route_set_local_pref_cmd
);
5454 route_map_install_set(&route_set_weight_cmd
);
5455 route_map_install_set(&route_set_label_index_cmd
);
5456 route_map_install_set(&route_set_metric_cmd
);
5457 route_map_install_set(&route_set_distance_cmd
);
5458 route_map_install_set(&route_set_aspath_prepend_cmd
);
5459 route_map_install_set(&route_set_aspath_exclude_cmd
);
5460 route_map_install_set(&route_set_origin_cmd
);
5461 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5462 route_map_install_set(&route_set_aggregator_as_cmd
);
5463 route_map_install_set(&route_set_community_cmd
);
5464 route_map_install_set(&route_set_community_delete_cmd
);
5465 route_map_install_set(&route_set_lcommunity_cmd
);
5466 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5467 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5468 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5469 route_map_install_set(&route_set_originator_id_cmd
);
5470 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5471 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5472 route_map_install_set(&route_set_tag_cmd
);
5473 route_map_install_set(&route_set_label_index_cmd
);
5475 install_element(RMAP_NODE
, &match_peer_cmd
);
5476 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5477 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5478 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5479 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5480 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5481 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5482 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5483 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5484 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5485 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5486 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5487 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5488 install_element(RMAP_NODE
, &match_evpn_rd_cmd
);
5489 install_element(RMAP_NODE
, &no_match_evpn_rd_cmd
);
5490 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5491 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5492 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5493 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5495 install_element(RMAP_NODE
, &match_aspath_cmd
);
5496 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5497 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5498 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5499 install_element(RMAP_NODE
, &match_community_cmd
);
5500 install_element(RMAP_NODE
, &no_match_community_cmd
);
5501 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5502 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5503 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5504 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5505 install_element(RMAP_NODE
, &match_origin_cmd
);
5506 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5507 install_element(RMAP_NODE
, &match_probability_cmd
);
5508 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5510 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
5511 install_element(RMAP_NODE
, &set_table_id_cmd
);
5512 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5513 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5514 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5515 install_element(RMAP_NODE
, &set_distance_cmd
);
5516 install_element(RMAP_NODE
, &no_set_distance_cmd
);
5517 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5518 install_element(RMAP_NODE
, &set_weight_cmd
);
5519 install_element(RMAP_NODE
, &set_label_index_cmd
);
5520 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5521 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5522 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5523 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5524 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5525 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5526 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
5527 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5528 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5529 install_element(RMAP_NODE
, &set_origin_cmd
);
5530 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5531 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5532 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5533 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5534 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5535 install_element(RMAP_NODE
, &set_community_cmd
);
5536 install_element(RMAP_NODE
, &set_community_none_cmd
);
5537 install_element(RMAP_NODE
, &no_set_community_cmd
);
5538 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5539 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5540 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5541 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5542 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5543 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5544 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5545 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5546 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5547 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5548 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5549 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5550 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5551 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5552 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5553 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5554 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5555 #ifdef KEEP_OLD_VPN_COMMANDS
5556 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5557 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5558 #endif /* KEEP_OLD_VPN_COMMANDS */
5559 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5560 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5561 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5562 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5564 route_map_install_match(&route_match_ipv6_address_cmd
);
5565 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5566 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5567 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5568 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5569 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5570 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5571 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5573 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5574 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5575 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5576 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5577 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5578 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5579 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5580 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5581 #if defined(HAVE_LUA)
5582 install_element(RMAP_NODE
, &match_command_cmd
);
5583 install_element(RMAP_NODE
, &no_match_command_cmd
);
5587 void bgp_route_map_terminate(void)
5589 /* ToDo: Cleanup all the used memory */