1 /* Route map function of bgpd.
2 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #ifdef HAVE_LIBPCREPOSIX
33 #include <pcreposix.h>
36 #endif /* HAVE_LIBPCREPOSIX */
38 #include "sockunion.h"
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_table.h"
45 #include "bgpd/bgp_attr.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_packet.h"
48 #include "bgpd/bgp_route.h"
49 #include "bgpd/bgp_zebra.h"
50 #include "bgpd/bgp_regex.h"
51 #include "bgpd/bgp_community.h"
52 #include "bgpd/bgp_clist.h"
53 #include "bgpd/bgp_filter.h"
54 #include "bgpd/bgp_mplsvpn.h"
55 #include "bgpd/bgp_ecommunity.h"
56 #include "bgpd/bgp_lcommunity.h"
57 #include "bgpd/bgp_vty.h"
58 #include "bgpd/bgp_debug.h"
59 #include "bgpd/bgp_evpn.h"
60 #include "bgpd/bgp_evpn_private.h"
61 #include "bgpd/bgp_evpn_vty.h"
62 #include "bgpd/bgp_mplsvpn.h"
63 #include "bgpd/bgp_pbr.h"
64 #include "bgpd/bgp_flowspec_util.h"
65 #include "bgpd/bgp_encap_types.h"
68 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
71 #ifndef VTYSH_EXTRACT_PL
72 #include "bgpd/bgp_routemap_clippy.c"
75 /* Memo of route-map commands.
84 ip route-source : Done
88 ipv6 route-source: (This will not be implemented by bgpd)
89 ipv6 prefix-list : Done
90 length : (This will not be implemented by bgpd)
92 route-type : (This will not be implemented by bgpd)
94 local-preference : Done
96 set as-path prepend : Done
98 automatic-tag : (This will not be implemented by bgpd)
100 large-community : Done
101 large-comm-list : Done
104 default : (This will not be implemented by bgpd)
105 interface : (This will not be implemented by bgpd)
106 ip default : (This will not be implemented by bgpd)
108 ip precedence : (This will not be implemented by bgpd)
109 ip tos : (This will not be implemented by bgpd)
110 level : (This will not be implemented by bgpd)
111 local-preference : Done
113 metric-type : Not yet
121 set ipv6 next-hop global: Done
122 set ipv6 next-hop prefer-global: Done
123 set ipv6 next-hop local : Done
124 set as-path exclude : Done
128 /* generic value manipulation to be shared in multiple rules */
130 #define RMAP_VALUE_SET 0
131 #define RMAP_VALUE_ADD 1
132 #define RMAP_VALUE_SUB 2
140 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
142 if (rv
->variable
== 0 && value
== rv
->value
)
148 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
153 switch (rv
->variable
) {
162 switch (rv
->action
) {
164 if (current
> UINT32_MAX
- value
)
166 return current
+ value
;
168 if (current
<= value
)
170 return current
- value
;
176 static void *route_value_compile(const char *arg
)
178 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
179 unsigned long larg
= 0;
181 struct rmap_value
*rv
;
184 action
= RMAP_VALUE_ADD
;
186 } else if (arg
[0] == '-') {
187 action
= RMAP_VALUE_SUB
;
191 if (all_digit(arg
)) {
193 larg
= strtoul(arg
, &endptr
, 10);
194 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
197 if (strcmp(arg
, "rtt") == 0)
203 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
211 static void route_value_free(void *rule
)
213 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
216 /* generic as path object to be shared in multiple rules */
218 static void *route_aspath_compile(const char *arg
)
220 struct aspath
*aspath
;
222 aspath
= aspath_str2aspath(arg
);
228 static void route_aspath_free(void *rule
)
230 struct aspath
*aspath
= rule
;
234 struct bgp_match_peer_compiled
{
239 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
241 /* Compares the peer specified in the 'match peer' clause with the peer
242 received in bgp_path_info->peer. If it is the same, or if the peer structure
243 received is a peer_group containing it, returns RMAP_MATCH. */
244 static enum route_map_cmd_result_t
245 route_match_peer(void *rule
, const struct prefix
*prefix
,
246 route_map_object_t type
, void *object
)
248 struct bgp_match_peer_compiled
*pc
;
250 union sockunion su_def
= {
251 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
252 struct peer_group
*group
;
254 struct listnode
*node
, *nnode
;
256 if (type
== RMAP_BGP
) {
259 peer
= ((struct bgp_path_info
*)object
)->peer
;
265 if (strcmp(peer
->conf_if
, pc
->interface
) == 0)
271 /* If su='0.0.0.0' (command 'match peer local'), and it's a
273 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
276 if (sockunion_same(su
, &su_def
)) {
278 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
279 || CHECK_FLAG(peer
->rmap_type
,
280 PEER_RMAP_TYPE_REDISTRIBUTE
)
281 || CHECK_FLAG(peer
->rmap_type
,
282 PEER_RMAP_TYPE_AGGREGATE
)
283 || CHECK_FLAG(peer
->rmap_type
,
284 PEER_RMAP_TYPE_DEFAULT
))
291 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
292 if (sockunion_same(su
, &peer
->su
))
298 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
300 if (sockunion_same(su
, &peer
->su
))
309 static void *route_match_peer_compile(const char *arg
)
311 struct bgp_match_peer_compiled
*pc
;
314 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
315 sizeof(struct bgp_match_peer_compiled
));
317 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
319 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
326 /* Free route map's compiled `ip address' value. */
327 static void route_match_peer_free(void *rule
)
329 struct bgp_match_peer_compiled
*pc
= rule
;
331 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
333 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
336 /* Route map commands for ip address matching. */
337 struct route_map_rule_cmd route_match_peer_cmd
= {"peer", route_match_peer
,
338 route_match_peer_compile
,
339 route_match_peer_free
};
341 #if defined(HAVE_LUA)
342 static enum route_map_cmd_result_t
343 route_match_command(void *rule
, const struct prefix
*prefix
,
344 route_map_object_t type
, void *object
)
346 int status
= RMAP_NOMATCH
;
347 u_int32_t locpref
= 0;
348 u_int32_t newlocpref
= 0;
349 enum lua_rm_status lrm_status
;
350 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
351 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
357 * Setup the prefix information to pass in
359 lua_setup_prefix_table(L
, prefix
);
361 zlog_debug("Set up prefix table");
363 * Setup the bgp_path_info information
366 lua_pushinteger(L
, path
->attr
->med
);
367 lua_setfield(L
, -2, "metric");
368 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
369 lua_setfield(L
, -2, "ifindex");
370 lua_pushstring(L
, path
->attr
->aspath
->str
);
371 lua_setfield(L
, -2, "aspath");
372 lua_pushinteger(L
, path
->attr
->local_pref
);
373 lua_setfield(L
, -2, "localpref");
374 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
375 lua_setglobal(L
, "nexthop");
377 zlog_debug("Set up nexthop information");
381 lrm_status
= lua_run_rm_rule(L
, rule
);
382 switch (lrm_status
) {
384 zlog_debug("RM_FAILURE");
387 zlog_debug("RM_NOMATCH");
389 case LUA_RM_MATCH_AND_CHANGE
:
390 zlog_debug("MATCH AND CHANGE");
391 lua_getglobal(L
, "nexthop");
392 path
->attr
->med
= get_integer(L
, "metric");
394 * This needs to be abstraced with the set function
396 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
397 locpref
= path
->attr
->local_pref
;
398 newlocpref
= get_integer(L
, "localpref");
399 if (newlocpref
!= locpref
) {
400 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
401 path
->attr
->local_pref
= newlocpref
;
406 zlog_debug("MATCH ONLY");
414 static void *route_match_command_compile(const char *arg
)
418 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
423 route_match_command_free(void *rule
)
425 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
428 struct route_map_rule_cmd route_match_command_cmd
= {
431 route_match_command_compile
,
432 route_match_command_free
436 /* `match ip address IP_ACCESS_LIST' */
438 /* Match function should return 1 if match is success else return
440 static enum route_map_cmd_result_t
441 route_match_ip_address(void *rule
, const struct prefix
*prefix
,
442 route_map_object_t type
, void *object
)
444 struct access_list
*alist
;
446 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
447 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
451 return (access_list_apply(alist
, prefix
) == FILTER_DENY
458 /* Route map `ip address' match statement. `arg' should be
460 static void *route_match_ip_address_compile(const char *arg
)
462 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
465 /* Free route map's compiled `ip address' value. */
466 static void route_match_ip_address_free(void *rule
)
468 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
471 /* Route map commands for ip address matching. */
472 struct route_map_rule_cmd route_match_ip_address_cmd
= {
473 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
474 route_match_ip_address_free
};
476 /* `match ip next-hop IP_ADDRESS' */
478 /* Match function return 1 if match is success else return zero. */
479 static enum route_map_cmd_result_t
480 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
,
481 route_map_object_t type
, void *object
)
483 struct access_list
*alist
;
484 struct bgp_path_info
*path
;
485 struct prefix_ipv4 p
;
487 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
490 p
.prefix
= path
->attr
->nexthop
;
491 p
.prefixlen
= IPV4_MAX_BITLEN
;
493 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
497 return (access_list_apply(alist
, &p
) == FILTER_DENY
504 /* Route map `ip next-hop' match statement. `arg' is
506 static void *route_match_ip_next_hop_compile(const char *arg
)
508 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
511 /* Free route map's compiled `ip address' value. */
512 static void route_match_ip_next_hop_free(void *rule
)
514 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
517 /* Route map commands for ip next-hop matching. */
518 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
519 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
520 route_match_ip_next_hop_free
};
522 /* `match ip route-source ACCESS-LIST' */
524 /* Match function return 1 if match is success else return zero. */
525 static enum route_map_cmd_result_t
526 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
,
527 route_map_object_t type
, void *object
)
529 struct access_list
*alist
;
530 struct bgp_path_info
*path
;
532 struct prefix_ipv4 p
;
534 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
538 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
542 p
.prefix
= peer
->su
.sin
.sin_addr
;
543 p
.prefixlen
= IPV4_MAX_BITLEN
;
545 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
549 return (access_list_apply(alist
, &p
) == FILTER_DENY
556 /* Route map `ip route-source' match statement. `arg' is
558 static void *route_match_ip_route_source_compile(const char *arg
)
560 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
563 /* Free route map's compiled `ip address' value. */
564 static void route_match_ip_route_source_free(void *rule
)
566 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
569 /* Route map commands for ip route-source matching. */
570 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
571 "ip route-source", route_match_ip_route_source
,
572 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
574 static enum route_map_cmd_result_t
575 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
576 const struct prefix
*p
)
579 struct bgp_pbr_entry_main api
;
581 memset(&api
, 0, sizeof(api
));
583 /* extract match from flowspec entries */
584 ret
= bgp_flowspec_match_rules_fill(
585 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
586 p
->u
.prefix_flowspec
.prefixlen
, &api
);
589 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
590 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
591 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
593 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
596 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
597 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
598 if (family2afi((&api
.src_prefix
)->family
) != afi
)
600 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
607 static enum route_map_cmd_result_t
608 route_match_address_prefix_list(void *rule
, afi_t afi
,
609 const struct prefix
*prefix
,
610 route_map_object_t type
, void *object
)
612 struct prefix_list
*plist
;
614 if (type
!= RMAP_BGP
)
617 plist
= prefix_list_lookup(afi
, (char *)rule
);
621 if (prefix
->family
== AF_FLOWSPEC
)
622 return route_match_prefix_list_flowspec(afi
, plist
,
624 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
628 static enum route_map_cmd_result_t
629 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
630 route_map_object_t type
, void *object
)
632 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, type
,
636 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
638 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
641 static void route_match_ip_address_prefix_list_free(void *rule
)
643 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
646 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
647 "ip address prefix-list", route_match_ip_address_prefix_list
,
648 route_match_ip_address_prefix_list_compile
,
649 route_match_ip_address_prefix_list_free
};
651 /* `match ip next-hop prefix-list PREFIX_LIST' */
653 static enum route_map_cmd_result_t
654 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
655 route_map_object_t type
, void *object
)
657 struct prefix_list
*plist
;
658 struct bgp_path_info
*path
;
659 struct prefix_ipv4 p
;
661 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
664 p
.prefix
= path
->attr
->nexthop
;
665 p
.prefixlen
= IPV4_MAX_BITLEN
;
667 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
671 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
678 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
680 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
683 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
685 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
688 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
689 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
690 route_match_ip_next_hop_prefix_list_compile
,
691 route_match_ip_next_hop_prefix_list_free
};
693 /* `match ip next-hop type <blackhole>' */
695 static enum route_map_cmd_result_t
696 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
697 route_map_object_t type
, void *object
)
699 struct bgp_path_info
*path
;
701 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
702 path
= (struct bgp_path_info
*)object
;
706 /* If nexthop interface's index can't be resolved and nexthop is
707 set to any address then mark it as type `blackhole`.
708 This logic works for matching kernel/static routes like:
709 `ip route add blackhole 10.0.0.1`. */
710 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
711 && !path
->attr
->nh_ifindex
)
717 static void *route_match_ip_next_hop_type_compile(const char *arg
)
719 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
722 static void route_match_ip_next_hop_type_free(void *rule
)
724 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
727 static struct route_map_rule_cmd route_match_ip_next_hop_type_cmd
= {
728 "ip next-hop type", route_match_ip_next_hop_type
,
729 route_match_ip_next_hop_type_compile
,
730 route_match_ip_next_hop_type_free
};
732 /* `match ip route-source prefix-list PREFIX_LIST' */
734 static enum route_map_cmd_result_t
735 route_match_ip_route_source_prefix_list(void *rule
,
736 const struct prefix
*prefix
,
737 route_map_object_t type
, void *object
)
739 struct prefix_list
*plist
;
740 struct bgp_path_info
*path
;
742 struct prefix_ipv4 p
;
744 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
748 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
752 p
.prefix
= peer
->su
.sin
.sin_addr
;
753 p
.prefixlen
= IPV4_MAX_BITLEN
;
755 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
759 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
766 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
768 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
771 static void route_match_ip_route_source_prefix_list_free(void *rule
)
773 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
776 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
777 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
778 route_match_ip_route_source_prefix_list_compile
,
779 route_match_ip_route_source_prefix_list_free
};
781 /* `match evpn default-route' */
783 /* Match function should return 1 if match is success else 0 */
784 static enum route_map_cmd_result_t
785 route_match_evpn_default_route(void *rule
, const struct prefix
*p
,
786 route_map_object_t type
, void *object
)
788 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
794 /* Route map commands for default-route matching. */
795 struct route_map_rule_cmd route_match_evpn_default_route_cmd
= {
796 "evpn default-route", route_match_evpn_default_route
, NULL
, NULL
};
798 /* `match mac address MAC_ACCESS_LIST' */
800 /* Match function should return 1 if match is success else return
802 static enum route_map_cmd_result_t
803 route_match_mac_address(void *rule
, const struct prefix
*prefix
,
804 route_map_object_t type
, void *object
)
806 struct access_list
*alist
;
809 if (type
== RMAP_BGP
) {
810 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
814 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
817 p
.family
= AF_ETHERNET
;
818 p
.prefixlen
= ETH_ALEN
* 8;
819 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
821 return (access_list_apply(alist
, &p
) == FILTER_DENY
829 /* Route map `mac address' match statement. `arg' should be
831 static void *route_match_mac_address_compile(const char *arg
)
833 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
836 /* Free route map's compiled `ip address' value. */
837 static void route_match_mac_address_free(void *rule
)
839 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
842 /* Route map commands for mac address matching. */
843 struct route_map_rule_cmd route_match_mac_address_cmd
= {
844 "mac address", route_match_mac_address
, route_match_mac_address_compile
,
845 route_match_mac_address_free
};
848 * Match function returns:
849 * ...RMAP_MATCH if match is found.
850 * ...RMAP_NOMATCH if match is not found.
851 * ...RMAP_NOOP to ignore this match check.
853 static enum route_map_cmd_result_t
854 route_match_vni(void *rule
, const struct prefix
*prefix
,
855 route_map_object_t type
, void *object
)
858 unsigned int label_cnt
= 0;
859 struct bgp_path_info
*path
= NULL
;
860 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
862 if (type
== RMAP_BGP
) {
863 vni
= *((vni_t
*)rule
);
864 path
= (struct bgp_path_info
*)object
;
867 * This rmap filter is valid for vxlan tunnel type only.
868 * For any other tunnel type, return noop to ignore
871 if (path
->attr
->encap_tunneltype
!= BGP_ENCAP_TYPE_VXLAN
)
875 * Apply filter to type 1, 2, 5 routes only.
876 * Other route types do not have vni label.
878 if (evp
&& (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
&&
879 evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
&&
880 evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
883 if (path
->extra
== NULL
)
886 for ( ; label_cnt
< BGP_MAX_LABELS
&&
887 label_cnt
< path
->extra
->num_labels
; label_cnt
++) {
888 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
896 /* Route map `vni' match statement. */
897 static void *route_match_vni_compile(const char *arg
)
902 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
904 *vni
= strtoul(arg
, &end
, 10);
906 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
913 /* Free route map's compiled `vni' value. */
914 static void route_match_vni_free(void *rule
)
916 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
919 /* Route map commands for vni matching. */
920 struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
921 "evpn vni", route_match_vni
, route_match_vni_compile
,
922 route_match_vni_free
};
924 /* `match evpn route-type' */
926 /* Match function should return 1 if match is success else return
928 static enum route_map_cmd_result_t
929 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
,
930 route_map_object_t type
, void *object
)
932 uint8_t route_type
= 0;
934 if (type
== RMAP_BGP
) {
935 route_type
= *((uint8_t *)rule
);
937 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
944 /* Route map `route-type' match statement. */
945 static void *route_match_evpn_route_type_compile(const char *arg
)
947 uint8_t *route_type
= NULL
;
949 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
951 if (strncmp(arg
, "ma", 2) == 0)
952 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
953 else if (strncmp(arg
, "mu", 2) == 0)
954 *route_type
= BGP_EVPN_IMET_ROUTE
;
956 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
961 /* Free route map's compiled `route-type' value. */
962 static void route_match_evpn_route_type_free(void *rule
)
964 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
967 /* Route map commands for evpn route-type matching. */
968 struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
969 "evpn route-type", route_match_evpn_route_type
,
970 route_match_evpn_route_type_compile
, route_match_evpn_route_type_free
};
972 /* Route map commands for VRF route leak with source vrf matching */
973 static enum route_map_cmd_result_t
974 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
975 route_map_object_t type
, void *object
)
977 struct bgp_path_info
*path
;
980 if (type
== RMAP_BGP
) {
982 path
= (struct bgp_path_info
*)object
;
984 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
987 if (path
->extra
== NULL
)
990 if (strncmp(vrf_name
, vrf_id_to_name(
991 path
->extra
->bgp_orig
->vrf_id
), VRF_NAMSIZ
)
999 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1001 uint8_t *vrf_name
= NULL
;
1003 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1008 /* Free route map's compiled `route-type' value. */
1009 static void route_match_vrl_source_vrf_free(void *rule
)
1011 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1014 struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1015 "source-vrf", route_match_vrl_source_vrf
,
1016 route_match_vrl_source_vrf_compile
,
1017 route_match_vrl_source_vrf_free
};
1019 /* `match local-preference LOCAL-PREF' */
1021 /* Match function return 1 if match is success else return zero. */
1022 static enum route_map_cmd_result_t
1023 route_match_local_pref(void *rule
, const struct prefix
*prefix
,
1024 route_map_object_t type
, void *object
)
1026 uint32_t *local_pref
;
1027 struct bgp_path_info
*path
;
1029 if (type
== RMAP_BGP
) {
1033 if (path
->attr
->local_pref
== *local_pref
)
1036 return RMAP_NOMATCH
;
1038 return RMAP_NOMATCH
;
1041 /* Route map `match local-preference' match statement.
1042 `arg' is local-pref value */
1043 static void *route_match_local_pref_compile(const char *arg
)
1045 uint32_t *local_pref
;
1046 char *endptr
= NULL
;
1047 unsigned long tmpval
;
1049 /* Locpref value shoud be integer. */
1050 if (!all_digit(arg
))
1054 tmpval
= strtoul(arg
, &endptr
, 10);
1055 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1058 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1060 *local_pref
= tmpval
;
1064 /* Free route map's compiled `match local-preference' value. */
1065 static void route_match_local_pref_free(void *rule
)
1067 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1070 /* Route map commands for metric matching. */
1071 struct route_map_rule_cmd route_match_local_pref_cmd
= {
1072 "local-preference", route_match_local_pref
,
1073 route_match_local_pref_compile
, route_match_local_pref_free
};
1075 /* `match metric METRIC' */
1077 /* Match function return 1 if match is success else return zero. */
1078 static enum route_map_cmd_result_t
1079 route_match_metric(void *rule
, const struct prefix
*prefix
,
1080 route_map_object_t type
, void *object
)
1082 struct rmap_value
*rv
;
1083 struct bgp_path_info
*path
;
1085 if (type
== RMAP_BGP
) {
1088 return route_value_match(rv
, path
->attr
->med
);
1090 return RMAP_NOMATCH
;
1093 /* Route map commands for metric matching. */
1094 struct route_map_rule_cmd route_match_metric_cmd
= {
1095 "metric", route_match_metric
, route_value_compile
, route_value_free
,
1098 /* `match as-path ASPATH' */
1100 /* Match function for as-path match. I assume given object is */
1101 static enum route_map_cmd_result_t
1102 route_match_aspath(void *rule
, const struct prefix
*prefix
,
1103 route_map_object_t type
, void *object
)
1106 struct as_list
*as_list
;
1107 struct bgp_path_info
*path
;
1109 if (type
== RMAP_BGP
) {
1110 as_list
= as_list_lookup((char *)rule
);
1111 if (as_list
== NULL
)
1112 return RMAP_NOMATCH
;
1116 /* Perform match. */
1117 return ((as_list_apply(as_list
, path
->attr
->aspath
)
1122 return RMAP_NOMATCH
;
1125 /* Compile function for as-path match. */
1126 static void *route_match_aspath_compile(const char *arg
)
1128 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1131 /* Compile function for as-path match. */
1132 static void route_match_aspath_free(void *rule
)
1134 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1137 /* Route map commands for aspath matching. */
1138 struct route_map_rule_cmd route_match_aspath_cmd
= {
1139 "as-path", route_match_aspath
, route_match_aspath_compile
,
1140 route_match_aspath_free
};
1142 /* `match community COMMUNIY' */
1143 struct rmap_community
{
1149 /* Match function for community match. */
1150 static enum route_map_cmd_result_t
1151 route_match_community(void *rule
, const struct prefix
*prefix
,
1152 route_map_object_t type
, void *object
)
1154 struct community_list
*list
;
1155 struct bgp_path_info
*path
;
1156 struct rmap_community
*rcom
= rule
;
1158 if (type
== RMAP_BGP
) {
1162 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1164 COMMUNITY_LIST_MASTER
);
1166 return RMAP_NOMATCH
;
1169 if (community_list_exact_match(path
->attr
->community
,
1173 if (community_list_match(path
->attr
->community
, list
))
1177 return RMAP_NOMATCH
;
1180 /* Compile function for community match. */
1181 static void *route_match_community_compile(const char *arg
)
1183 struct rmap_community
*rcom
;
1187 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1189 p
= strchr(arg
, ' ');
1192 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1193 memcpy(rcom
->name
, arg
, len
);
1196 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1200 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1204 /* Compile function for community match. */
1205 static void route_match_community_free(void *rule
)
1207 struct rmap_community
*rcom
= rule
;
1209 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1210 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1214 * In routemap processing there is a need to add the
1215 * name as a rule_key in the dependency table. Routemap
1216 * lib is unaware of rule_key when exact-match clause
1217 * is in use. routemap lib uses the compiled output to
1218 * get the rule_key value.
1220 static void *route_match_get_community_key(void *rule
)
1222 struct rmap_community
*rcom
;
1229 /* Route map commands for community matching. */
1230 struct route_map_rule_cmd route_match_community_cmd
= {
1231 "community", route_match_community
, route_match_community_compile
,
1232 route_match_community_free
, route_match_get_community_key
};
1234 /* Match function for lcommunity match. */
1235 static enum route_map_cmd_result_t
1236 route_match_lcommunity(void *rule
, const struct prefix
*prefix
,
1237 route_map_object_t type
, void *object
)
1239 struct community_list
*list
;
1240 struct bgp_path_info
*path
;
1241 struct rmap_community
*rcom
= rule
;
1243 if (type
== RMAP_BGP
) {
1246 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1248 LARGE_COMMUNITY_LIST_MASTER
);
1250 return RMAP_NOMATCH
;
1253 if (lcommunity_list_exact_match(
1254 path
->attr
->lcommunity
,
1258 if (lcommunity_list_match(
1259 path
->attr
->lcommunity
,
1264 return RMAP_NOMATCH
;
1267 /* Compile function for community match. */
1268 static void *route_match_lcommunity_compile(const char *arg
)
1270 struct rmap_community
*rcom
;
1274 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1276 p
= strchr(arg
, ' ');
1279 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1280 memcpy(rcom
->name
, arg
, len
);
1283 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1287 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1291 /* Compile function for community match. */
1292 static void route_match_lcommunity_free(void *rule
)
1294 struct rmap_community
*rcom
= rule
;
1296 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1297 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1300 /* Route map commands for community matching. */
1301 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1302 "large-community", route_match_lcommunity
,
1303 route_match_lcommunity_compile
, route_match_lcommunity_free
,
1304 route_match_get_community_key
};
1307 /* Match function for extcommunity match. */
1308 static enum route_map_cmd_result_t
1309 route_match_ecommunity(void *rule
, const struct prefix
*prefix
,
1310 route_map_object_t type
, void *object
)
1312 struct community_list
*list
;
1313 struct bgp_path_info
*path
;
1314 struct rmap_community
*rcom
= rule
;
1316 if (type
== RMAP_BGP
) {
1319 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1321 EXTCOMMUNITY_LIST_MASTER
);
1323 return RMAP_NOMATCH
;
1325 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1328 return RMAP_NOMATCH
;
1331 /* Compile function for extcommunity match. */
1332 static void *route_match_ecommunity_compile(const char *arg
)
1334 struct rmap_community
*rcom
;
1336 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1337 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1338 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1343 /* Compile function for extcommunity match. */
1344 static void route_match_ecommunity_free(void *rule
)
1346 struct rmap_community
*rcom
= rule
;
1348 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1349 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1352 /* Route map commands for community matching. */
1353 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1354 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1355 route_match_ecommunity_free
};
1357 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1358 and `address-family vpnv4'. */
1360 /* `match origin' */
1361 static enum route_map_cmd_result_t
1362 route_match_origin(void *rule
, const struct prefix
*prefix
,
1363 route_map_object_t type
, void *object
)
1366 struct bgp_path_info
*path
;
1368 if (type
== RMAP_BGP
) {
1372 if (path
->attr
->origin
== *origin
)
1376 return RMAP_NOMATCH
;
1379 static void *route_match_origin_compile(const char *arg
)
1383 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1385 if (strcmp(arg
, "igp") == 0)
1387 else if (strcmp(arg
, "egp") == 0)
1395 /* Free route map's compiled `ip address' value. */
1396 static void route_match_origin_free(void *rule
)
1398 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1401 /* Route map commands for origin matching. */
1402 struct route_map_rule_cmd route_match_origin_cmd
= {
1403 "origin", route_match_origin
, route_match_origin_compile
,
1404 route_match_origin_free
};
1406 /* match probability { */
1408 static enum route_map_cmd_result_t
1409 route_match_probability(void *rule
, const struct prefix
*prefix
,
1410 route_map_object_t type
, void *object
)
1414 switch (*(long *)rule
) {
1420 if (r
< *(long *)rule
) {
1425 return RMAP_NOMATCH
;
1428 static void *route_match_probability_compile(const char *arg
)
1434 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1444 *lobule
= RAND_MAX
/ 100 * perc
;
1450 static void route_match_probability_free(void *rule
)
1452 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1455 struct route_map_rule_cmd route_match_probability_cmd
= {
1456 "probability", route_match_probability
, route_match_probability_compile
,
1457 route_match_probability_free
};
1459 /* `match interface IFNAME' */
1460 /* Match function should return 1 if match is success else return
1462 static enum route_map_cmd_result_t
1463 route_match_interface(void *rule
, const struct prefix
*prefix
,
1464 route_map_object_t type
, void *object
)
1466 struct interface
*ifp
;
1467 struct bgp_path_info
*path
;
1469 if (type
== RMAP_BGP
) {
1473 return RMAP_NOMATCH
;
1475 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1477 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1478 return RMAP_NOMATCH
;
1482 return RMAP_NOMATCH
;
1485 /* Route map `interface' match statement. `arg' should be
1487 static void *route_match_interface_compile(const char *arg
)
1489 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1492 /* Free route map's compiled `interface' value. */
1493 static void route_match_interface_free(void *rule
)
1495 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1498 /* Route map commands for ip address matching. */
1499 struct route_map_rule_cmd route_match_interface_cmd
= {
1500 "interface", route_match_interface
, route_match_interface_compile
,
1501 route_match_interface_free
};
1505 /* `set ip next-hop IP_ADDRESS' */
1507 /* Match function return 1 if match is success else return zero. */
1508 static enum route_map_cmd_result_t
1509 route_match_tag(void *rule
, const struct prefix
*prefix
,
1510 route_map_object_t type
, void *object
)
1513 struct bgp_path_info
*path
;
1515 if (type
== RMAP_BGP
) {
1519 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1522 return RMAP_NOMATCH
;
1526 /* Route map commands for tag matching. */
1527 static struct route_map_rule_cmd route_match_tag_cmd
= {
1528 "tag", route_match_tag
, route_map_rule_tag_compile
,
1529 route_map_rule_tag_free
,
1533 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1534 struct rmap_ip_nexthop_set
{
1535 struct in_addr
*address
;
1540 static enum route_map_cmd_result_t
1541 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
,
1542 route_map_object_t type
, void *object
)
1544 struct rmap_ip_nexthop_set
*rins
= rule
;
1545 struct bgp_path_info
*path
;
1548 if (type
!= RMAP_BGP
)
1551 if (prefix
->family
== AF_INET6
)
1557 if (rins
->unchanged
) {
1558 SET_FLAG(path
->attr
->rmap_change_flags
,
1559 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1560 } else if (rins
->peer_address
) {
1561 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1562 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1564 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1565 path
->attr
->nexthop
.s_addr
=
1566 sockunion2ip(peer
->su_remote
);
1567 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1568 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1569 /* The next hop value will be set as part of
1570 * packet rewrite. Set the flags here to indicate
1571 * that rewrite needs to be done.
1572 * Also, clear the value.
1574 SET_FLAG(path
->attr
->rmap_change_flags
,
1575 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1576 path
->attr
->nexthop
.s_addr
= 0;
1579 /* Set next hop value. */
1580 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1581 path
->attr
->nexthop
= *rins
->address
;
1582 SET_FLAG(path
->attr
->rmap_change_flags
,
1583 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1584 /* case for MP-BGP : MPLS VPN */
1585 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1586 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1592 /* Route map `ip nexthop' compile function. Given string is converted
1593 to struct in_addr structure. */
1594 static void *route_set_ip_nexthop_compile(const char *arg
)
1596 struct rmap_ip_nexthop_set
*rins
;
1597 struct in_addr
*address
= NULL
;
1598 int peer_address
= 0;
1602 if (strcmp(arg
, "peer-address") == 0)
1604 else if (strcmp(arg
, "unchanged") == 0)
1607 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1608 sizeof(struct in_addr
));
1609 ret
= inet_aton(arg
, address
);
1612 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1617 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1618 sizeof(struct rmap_ip_nexthop_set
));
1620 rins
->address
= address
;
1621 rins
->peer_address
= peer_address
;
1622 rins
->unchanged
= unchanged
;
1627 /* Free route map's compiled `ip nexthop' value. */
1628 static void route_set_ip_nexthop_free(void *rule
)
1630 struct rmap_ip_nexthop_set
*rins
= rule
;
1632 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1634 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1637 /* Route map commands for ip nexthop set. */
1638 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1639 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1640 route_set_ip_nexthop_free
};
1642 /* `set local-preference LOCAL_PREF' */
1644 /* Set local preference. */
1645 static enum route_map_cmd_result_t
1646 route_set_local_pref(void *rule
, const struct prefix
*prefix
,
1647 route_map_object_t type
, void *object
)
1649 struct rmap_value
*rv
;
1650 struct bgp_path_info
*path
;
1651 uint32_t locpref
= 0;
1653 if (type
== RMAP_BGP
) {
1654 /* Fetch routemap's rule information. */
1658 /* Set local preference value. */
1659 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1660 locpref
= path
->attr
->local_pref
;
1662 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1663 path
->attr
->local_pref
=
1664 route_value_adjust(rv
, locpref
, path
->peer
);
1670 /* Set local preference rule structure. */
1671 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1672 "local-preference", route_set_local_pref
, route_value_compile
,
1676 /* `set weight WEIGHT' */
1679 static enum route_map_cmd_result_t
1680 route_set_weight(void *rule
, const struct prefix
*prefix
,
1681 route_map_object_t type
, void *object
)
1683 struct rmap_value
*rv
;
1684 struct bgp_path_info
*path
;
1686 if (type
== RMAP_BGP
) {
1687 /* Fetch routemap's rule information. */
1691 /* Set weight value. */
1692 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1698 /* Set local preference rule structure. */
1699 struct route_map_rule_cmd route_set_weight_cmd
= {
1700 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1703 /* `set distance DISTANCE */
1704 static enum route_map_cmd_result_t
1705 route_set_distance(void *rule
, const struct prefix
*prefix
,
1706 route_map_object_t type
, void *object
)
1708 struct bgp_path_info
*path
= object
;
1709 struct rmap_value
*rv
= rule
;
1711 if (type
!= RMAP_BGP
)
1714 path
->attr
->distance
= rv
->value
;
1719 /* set distance rule structure */
1720 struct route_map_rule_cmd route_set_distance_cmd
= {
1723 route_value_compile
,
1727 /* `set metric METRIC' */
1729 /* Set metric to attribute. */
1730 static enum route_map_cmd_result_t
1731 route_set_metric(void *rule
, const struct prefix
*prefix
,
1732 route_map_object_t type
, void *object
)
1734 struct rmap_value
*rv
;
1735 struct bgp_path_info
*path
;
1738 if (type
== RMAP_BGP
) {
1739 /* Fetch routemap's rule information. */
1743 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1744 med
= path
->attr
->med
;
1746 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1747 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1752 /* Set metric rule structure. */
1753 struct route_map_rule_cmd route_set_metric_cmd
= {
1754 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1757 /* `set table (1-4294967295)' */
1759 static enum route_map_cmd_result_t
route_set_table_id(void *rule
,
1760 const struct prefix
*prefix
,
1761 route_map_object_t type
,
1764 struct rmap_value
*rv
;
1765 struct bgp_path_info
*path
;
1767 if (type
== RMAP_BGP
) {
1768 /* Fetch routemap's rule information. */
1772 path
->attr
->rmap_table_id
= rv
->value
;
1777 /* Set table_id rule structure. */
1778 static struct route_map_rule_cmd route_set_table_id_cmd
= {
1779 "table", route_set_table_id
,
1780 route_value_compile
, route_value_free
1783 /* `set as-path prepend ASPATH' */
1785 /* For AS path prepend mechanism. */
1786 static enum route_map_cmd_result_t
1787 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
,
1788 route_map_object_t type
, void *object
)
1790 struct aspath
*aspath
;
1792 struct bgp_path_info
*path
;
1794 if (type
== RMAP_BGP
) {
1797 if (path
->attr
->aspath
->refcnt
)
1798 new = aspath_dup(path
->attr
->aspath
);
1800 new = path
->attr
->aspath
;
1802 if ((uintptr_t)rule
> 10) {
1804 aspath_prepend(aspath
, new);
1806 as_t as
= aspath_leftmost(new);
1808 as
= path
->peer
->as
;
1809 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1812 path
->attr
->aspath
= new;
1818 static void *route_set_aspath_prepend_compile(const char *arg
)
1822 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1823 return (void *)(uintptr_t)num
;
1825 return route_aspath_compile(arg
);
1828 static void route_set_aspath_prepend_free(void *rule
)
1830 if ((uintptr_t)rule
> 10)
1831 route_aspath_free(rule
);
1835 /* Set as-path prepend rule structure. */
1836 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1837 "as-path prepend", route_set_aspath_prepend
,
1838 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1841 /* `set as-path exclude ASn' */
1843 /* For ASN exclude mechanism.
1844 * Iterate over ASns requested and filter them from the given AS_PATH one by
1846 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1848 static enum route_map_cmd_result_t
1849 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
,
1850 route_map_object_t type
, void *object
)
1852 struct aspath
*new_path
, *exclude_path
;
1853 struct bgp_path_info
*path
;
1855 if (type
== RMAP_BGP
) {
1856 exclude_path
= rule
;
1858 if (path
->attr
->aspath
->refcnt
)
1859 new_path
= aspath_dup(path
->attr
->aspath
);
1861 new_path
= path
->attr
->aspath
;
1862 path
->attr
->aspath
=
1863 aspath_filter_exclude(new_path
, exclude_path
);
1868 /* Set ASn exlude rule structure. */
1869 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1870 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1874 /* `set community COMMUNITY' */
1875 struct rmap_com_set
{
1876 struct community
*com
;
1881 /* For community set mechanism. */
1882 static enum route_map_cmd_result_t
1883 route_set_community(void *rule
, const struct prefix
*prefix
,
1884 route_map_object_t type
, void *object
)
1886 struct rmap_com_set
*rcs
;
1887 struct bgp_path_info
*path
;
1889 struct community
*new = NULL
;
1890 struct community
*old
;
1891 struct community
*merge
;
1893 if (type
== RMAP_BGP
) {
1897 old
= attr
->community
;
1901 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1902 attr
->community
= NULL
;
1903 /* See the longer comment down below. */
1904 if (old
&& old
->refcnt
== 0)
1905 community_free(&old
);
1909 /* "additive" case. */
1910 if (rcs
->additive
&& old
) {
1911 merge
= community_merge(community_dup(old
), rcs
->com
);
1913 new = community_uniq_sort(merge
);
1914 community_free(&merge
);
1916 new = community_dup(rcs
->com
);
1918 /* HACK: if the old community is not intern'd,
1919 * we should free it here, or all reference to it may be
1921 * Really need to cleanup attribute caching sometime.
1923 if (old
&& old
->refcnt
== 0)
1924 community_free(&old
);
1926 /* will be interned by caller if required */
1927 attr
->community
= new;
1929 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1935 /* Compile function for set community. */
1936 static void *route_set_community_compile(const char *arg
)
1938 struct rmap_com_set
*rcs
;
1939 struct community
*com
= NULL
;
1944 if (strcmp(arg
, "none") == 0)
1947 sp
= strstr(arg
, "additive");
1949 if (sp
&& sp
> arg
) {
1950 /* "additive" keyword is included. */
1955 com
= community_str2com(arg
);
1964 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1966 rcs
->additive
= additive
;
1972 /* Free function for set community. */
1973 static void route_set_community_free(void *rule
)
1975 struct rmap_com_set
*rcs
= rule
;
1978 community_free(&rcs
->com
);
1979 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1982 /* Set community rule structure. */
1983 struct route_map_rule_cmd route_set_community_cmd
= {
1984 "community", route_set_community
, route_set_community_compile
,
1985 route_set_community_free
,
1988 /* `set community COMMUNITY' */
1989 struct rmap_lcom_set
{
1990 struct lcommunity
*lcom
;
1996 /* For lcommunity set mechanism. */
1997 static enum route_map_cmd_result_t
1998 route_set_lcommunity(void *rule
, const struct prefix
*prefix
,
1999 route_map_object_t type
, void *object
)
2001 struct rmap_lcom_set
*rcs
;
2002 struct bgp_path_info
*path
;
2004 struct lcommunity
*new = NULL
;
2005 struct lcommunity
*old
;
2006 struct lcommunity
*merge
;
2008 if (type
== RMAP_BGP
) {
2012 old
= attr
->lcommunity
;
2017 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
2018 attr
->lcommunity
= NULL
;
2020 /* See the longer comment down below. */
2021 if (old
&& old
->refcnt
== 0)
2022 lcommunity_free(&old
);
2026 if (rcs
->additive
&& old
) {
2027 merge
= lcommunity_merge(lcommunity_dup(old
),
2030 new = lcommunity_uniq_sort(merge
);
2031 lcommunity_free(&merge
);
2033 new = lcommunity_dup(rcs
->lcom
);
2035 /* HACK: if the old large-community is not intern'd,
2036 * we should free it here, or all reference to it may be
2038 * Really need to cleanup attribute caching sometime.
2040 if (old
&& old
->refcnt
== 0)
2041 lcommunity_free(&old
);
2043 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2044 attr
->lcommunity
= new;
2046 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2052 /* Compile function for set community. */
2053 static void *route_set_lcommunity_compile(const char *arg
)
2055 struct rmap_lcom_set
*rcs
;
2056 struct lcommunity
*lcom
= NULL
;
2061 if (strcmp(arg
, "none") == 0)
2064 sp
= strstr(arg
, "additive");
2066 if (sp
&& sp
> arg
) {
2067 /* "additive" keyworkd is included. */
2072 lcom
= lcommunity_str2com(arg
);
2081 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2083 rcs
->additive
= additive
;
2089 /* Free function for set lcommunity. */
2090 static void route_set_lcommunity_free(void *rule
)
2092 struct rmap_lcom_set
*rcs
= rule
;
2095 lcommunity_free(&rcs
->lcom
);
2097 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2100 /* Set community rule structure. */
2101 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2102 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
2103 route_set_lcommunity_free
,
2106 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2108 /* For large community set mechanism. */
2109 static enum route_map_cmd_result_t
2110 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
,
2111 route_map_object_t type
, void *object
)
2113 struct community_list
*list
;
2114 struct lcommunity
*merge
;
2115 struct lcommunity
*new;
2116 struct lcommunity
*old
;
2117 struct bgp_path_info
*path
;
2118 struct rmap_community
*rcom
= rule
;
2120 if (type
== RMAP_BGP
) {
2125 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2127 LARGE_COMMUNITY_LIST_MASTER
);
2128 old
= path
->attr
->lcommunity
;
2131 merge
= lcommunity_list_match_delete(
2132 lcommunity_dup(old
), list
);
2133 new = lcommunity_uniq_sort(merge
);
2134 lcommunity_free(&merge
);
2136 /* HACK: if the old community is not intern'd,
2137 * we should free it here, or all reference to it may be
2139 * Really need to cleanup attribute caching sometime.
2141 if (old
->refcnt
== 0)
2142 lcommunity_free(&old
);
2144 if (new->size
== 0) {
2145 path
->attr
->lcommunity
= NULL
;
2146 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2147 BGP_ATTR_LARGE_COMMUNITIES
);
2148 lcommunity_free(&new);
2150 path
->attr
->lcommunity
= new;
2151 path
->attr
->flag
|= ATTR_FLAG_BIT(
2152 BGP_ATTR_LARGE_COMMUNITIES
);
2160 /* Compile function for set lcommunity. */
2161 static void *route_set_lcommunity_delete_compile(const char *arg
)
2163 struct rmap_community
*rcom
;
2167 frrstr_split(arg
, " ", &splits
, &num
);
2169 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2170 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2171 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2173 for (int i
= 0; i
< num
; i
++)
2174 XFREE(MTYPE_TMP
, splits
[i
]);
2175 XFREE(MTYPE_TMP
, splits
);
2180 /* Free function for set lcommunity. */
2181 static void route_set_lcommunity_delete_free(void *rule
)
2183 struct rmap_community
*rcom
= rule
;
2185 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2186 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2189 /* Set lcommunity rule structure. */
2190 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2191 "large-comm-list", route_set_lcommunity_delete
,
2192 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2196 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2198 /* For community set mechanism. */
2199 static enum route_map_cmd_result_t
2200 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2201 route_map_object_t type
, void *object
)
2203 struct community_list
*list
;
2204 struct community
*merge
;
2205 struct community
*new;
2206 struct community
*old
;
2207 struct bgp_path_info
*path
;
2208 struct rmap_community
*rcom
= rule
;
2210 if (type
== RMAP_BGP
) {
2215 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2217 COMMUNITY_LIST_MASTER
);
2218 old
= path
->attr
->community
;
2221 merge
= community_list_match_delete(community_dup(old
),
2223 new = community_uniq_sort(merge
);
2224 community_free(&merge
);
2226 /* HACK: if the old community is not intern'd,
2227 * we should free it here, or all reference to it may be
2229 * Really need to cleanup attribute caching sometime.
2231 if (old
->refcnt
== 0)
2232 community_free(&old
);
2234 if (new->size
== 0) {
2235 path
->attr
->community
= NULL
;
2237 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2238 community_free(&new);
2240 path
->attr
->community
= new;
2242 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2250 /* Compile function for set community. */
2251 static void *route_set_community_delete_compile(const char *arg
)
2253 struct rmap_community
*rcom
;
2257 frrstr_split(arg
, " ", &splits
, &num
);
2259 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2260 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2261 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2263 for (int i
= 0; i
< num
; i
++)
2264 XFREE(MTYPE_TMP
, splits
[i
]);
2265 XFREE(MTYPE_TMP
, splits
);
2270 /* Free function for set community. */
2271 static void route_set_community_delete_free(void *rule
)
2273 struct rmap_community
*rcom
= rule
;
2275 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2276 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2279 /* Set community rule structure. */
2280 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2281 "comm-list", route_set_community_delete
,
2282 route_set_community_delete_compile
, route_set_community_delete_free
,
2285 /* `set extcommunity rt COMMUNITY' */
2287 /* For community set mechanism. Used by _rt and _soo. */
2288 static enum route_map_cmd_result_t
2289 route_set_ecommunity(void *rule
, const struct prefix
*prefix
,
2290 route_map_object_t type
, void *object
)
2292 struct ecommunity
*ecom
;
2293 struct ecommunity
*new_ecom
;
2294 struct ecommunity
*old_ecom
;
2295 struct bgp_path_info
*path
;
2297 if (type
== RMAP_BGP
) {
2304 /* We assume additive for Extended Community. */
2305 old_ecom
= path
->attr
->ecommunity
;
2308 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2311 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2312 * bgp_update_receive()
2313 * ->refcnt = 0 => set by a previous route-map
2315 if (!old_ecom
->refcnt
)
2316 ecommunity_free(&old_ecom
);
2318 new_ecom
= ecommunity_dup(ecom
);
2320 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2321 path
->attr
->ecommunity
= new_ecom
;
2323 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2328 /* Compile function for set community. */
2329 static void *route_set_ecommunity_rt_compile(const char *arg
)
2331 struct ecommunity
*ecom
;
2333 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2336 return ecommunity_intern(ecom
);
2339 /* Free function for set community. Used by _rt and _soo */
2340 static void route_set_ecommunity_free(void *rule
)
2342 struct ecommunity
*ecom
= rule
;
2343 ecommunity_unintern(&ecom
);
2346 /* Set community rule structure. */
2347 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2348 "extcommunity rt", route_set_ecommunity
,
2349 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2352 /* `set extcommunity soo COMMUNITY' */
2354 /* Compile function for set community. */
2355 static void *route_set_ecommunity_soo_compile(const char *arg
)
2357 struct ecommunity
*ecom
;
2359 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2363 return ecommunity_intern(ecom
);
2366 /* Set community rule structure. */
2367 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2368 "extcommunity soo", route_set_ecommunity
,
2369 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2372 /* `set origin ORIGIN' */
2374 /* For origin set. */
2375 static enum route_map_cmd_result_t
2376 route_set_origin(void *rule
, const struct prefix
*prefix
,
2377 route_map_object_t type
, void *object
)
2380 struct bgp_path_info
*path
;
2382 if (type
== RMAP_BGP
) {
2386 path
->attr
->origin
= *origin
;
2392 /* Compile function for origin set. */
2393 static void *route_set_origin_compile(const char *arg
)
2397 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2399 if (strcmp(arg
, "igp") == 0)
2401 else if (strcmp(arg
, "egp") == 0)
2409 /* Compile function for origin set. */
2410 static void route_set_origin_free(void *rule
)
2412 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2415 /* Set origin rule structure. */
2416 struct route_map_rule_cmd route_set_origin_cmd
= {
2417 "origin", route_set_origin
, route_set_origin_compile
,
2418 route_set_origin_free
,
2421 /* `set atomic-aggregate' */
2423 /* For atomic aggregate set. */
2424 static enum route_map_cmd_result_t
2425 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
,
2426 route_map_object_t type
, void *object
)
2428 struct bgp_path_info
*path
;
2430 if (type
== RMAP_BGP
) {
2432 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2438 /* Compile function for atomic aggregate. */
2439 static void *route_set_atomic_aggregate_compile(const char *arg
)
2444 /* Compile function for atomic aggregate. */
2445 static void route_set_atomic_aggregate_free(void *rule
)
2450 /* Set atomic aggregate rule structure. */
2451 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2452 "atomic-aggregate", route_set_atomic_aggregate
,
2453 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2456 /* `set aggregator as AS A.B.C.D' */
2459 struct in_addr address
;
2462 static enum route_map_cmd_result_t
2463 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
,
2464 route_map_object_t type
, void *object
)
2466 struct bgp_path_info
*path
;
2467 struct aggregator
*aggregator
;
2469 if (type
== RMAP_BGP
) {
2473 path
->attr
->aggregator_as
= aggregator
->as
;
2474 path
->attr
->aggregator_addr
= aggregator
->address
;
2475 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2481 static void *route_set_aggregator_as_compile(const char *arg
)
2483 struct aggregator
*aggregator
;
2489 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2490 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2491 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2495 aggregator
->as
= strtoul(as
, NULL
, 10);
2496 ret
= inet_aton(address
, &aggregator
->address
);
2498 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2504 static void route_set_aggregator_as_free(void *rule
)
2506 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2509 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2510 "aggregator as", route_set_aggregator_as
,
2511 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2514 /* Set tag to object. object must be pointer to struct bgp_path_info */
2515 static enum route_map_cmd_result_t
2516 route_set_tag(void *rule
, const struct prefix
*prefix
,
2517 route_map_object_t type
, void *object
)
2520 struct bgp_path_info
*path
;
2522 if (type
== RMAP_BGP
) {
2527 path
->attr
->tag
= *tag
;
2533 /* Route map commands for tag set. */
2534 static struct route_map_rule_cmd route_set_tag_cmd
= {
2535 "tag", route_set_tag
, route_map_rule_tag_compile
,
2536 route_map_rule_tag_free
,
2539 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2540 static enum route_map_cmd_result_t
2541 route_set_label_index(void *rule
, const struct prefix
*prefix
,
2542 route_map_object_t type
, void *object
)
2544 struct rmap_value
*rv
;
2545 struct bgp_path_info
*path
;
2546 uint32_t label_index
;
2548 if (type
== RMAP_BGP
) {
2549 /* Fetch routemap's rule information. */
2553 /* Set label-index value. */
2554 label_index
= rv
->value
;
2556 path
->attr
->label_index
= label_index
;
2557 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2564 /* Route map commands for label-index set. */
2565 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2566 "label-index", route_set_label_index
, route_value_compile
,
2570 /* `match ipv6 address IP_ACCESS_LIST' */
2572 static enum route_map_cmd_result_t
2573 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
,
2574 route_map_object_t type
, void *object
)
2576 struct access_list
*alist
;
2578 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2579 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2581 return RMAP_NOMATCH
;
2583 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2587 return RMAP_NOMATCH
;
2590 static void *route_match_ipv6_address_compile(const char *arg
)
2592 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2595 static void route_match_ipv6_address_free(void *rule
)
2597 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2600 /* Route map commands for ip address matching. */
2601 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2602 "ipv6 address", route_match_ipv6_address
,
2603 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2605 /* `match ipv6 next-hop IP_ADDRESS' */
2607 static enum route_map_cmd_result_t
2608 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
,
2609 route_map_object_t type
, void *object
)
2611 struct in6_addr
*addr
= rule
;
2612 struct bgp_path_info
*path
;
2614 if (type
== RMAP_BGP
) {
2617 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2620 if (path
->attr
->mp_nexthop_len
2621 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2622 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2625 return RMAP_NOMATCH
;
2628 return RMAP_NOMATCH
;
2631 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2633 struct in6_addr
*address
;
2636 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2638 ret
= inet_pton(AF_INET6
, arg
, address
);
2640 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2647 static void route_match_ipv6_next_hop_free(void *rule
)
2649 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2652 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2653 "ipv6 next-hop", route_match_ipv6_next_hop
,
2654 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2656 /* `match ipv6 address prefix-list PREFIX_LIST' */
2658 static enum route_map_cmd_result_t
2659 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2660 route_map_object_t type
, void *object
)
2662 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, type
,
2666 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2668 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2671 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2673 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2676 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2677 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2678 route_match_ipv6_address_prefix_list_compile
,
2679 route_match_ipv6_address_prefix_list_free
};
2681 /* `match ipv6 next-hop type <TYPE>' */
2683 static enum route_map_cmd_result_t
2684 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2685 route_map_object_t type
, void *object
)
2687 struct bgp_path_info
*path
;
2688 struct in6_addr
*addr
= rule
;
2690 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2691 path
= (struct bgp_path_info
*)object
;
2693 return RMAP_NOMATCH
;
2695 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2696 && !path
->attr
->nh_ifindex
)
2699 return RMAP_NOMATCH
;
2702 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2704 struct in6_addr
*address
;
2707 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2709 ret
= inet_pton(AF_INET6
, "::0", address
);
2711 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2718 static void route_match_ipv6_next_hop_type_free(void *rule
)
2720 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2723 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2724 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2725 route_match_ipv6_next_hop_type_compile
,
2726 route_match_ipv6_next_hop_type_free
};
2728 /* `set ipv6 nexthop global IP_ADDRESS' */
2730 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2731 static enum route_map_cmd_result_t
2732 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
,
2733 route_map_object_t type
, void *object
)
2735 struct in6_addr
*address
;
2736 struct bgp_path_info
*path
;
2738 if (type
== RMAP_BGP
) {
2739 /* Fetch routemap's rule information. */
2743 /* Set next hop value. */
2744 path
->attr
->mp_nexthop_global
= *address
;
2746 /* Set nexthop length. */
2747 if (path
->attr
->mp_nexthop_len
== 0)
2748 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2750 SET_FLAG(path
->attr
->rmap_change_flags
,
2751 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2757 /* Route map `ip next-hop' compile function. Given string is converted
2758 to struct in_addr structure. */
2759 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2762 struct in6_addr
*address
;
2764 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2766 ret
= inet_pton(AF_INET6
, arg
, address
);
2769 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2776 /* Free route map's compiled `ip next-hop' value. */
2777 static void route_set_ipv6_nexthop_global_free(void *rule
)
2779 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2782 /* Route map commands for ip nexthop set. */
2783 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2784 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2785 route_set_ipv6_nexthop_global_compile
,
2786 route_set_ipv6_nexthop_global_free
};
2788 /* Set next-hop preference value. */
2789 static enum route_map_cmd_result_t
2790 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2791 route_map_object_t type
, void *object
)
2793 struct bgp_path_info
*path
;
2796 if (type
== RMAP_BGP
) {
2797 /* Fetch routemap's rule information. */
2801 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2802 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
2803 /* Set next hop preference to global */
2804 path
->attr
->mp_nexthop_prefer_global
= true;
2805 SET_FLAG(path
->attr
->rmap_change_flags
,
2806 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2808 path
->attr
->mp_nexthop_prefer_global
= false;
2809 SET_FLAG(path
->attr
->rmap_change_flags
,
2810 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2816 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2820 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2826 /* Free route map's compiled `ip next-hop' value. */
2827 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2829 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2832 /* Route map commands for ip nexthop set preferred. */
2833 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2834 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2835 route_set_ipv6_nexthop_prefer_global_compile
,
2836 route_set_ipv6_nexthop_prefer_global_free
};
2838 /* `set ipv6 nexthop local IP_ADDRESS' */
2840 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2841 static enum route_map_cmd_result_t
2842 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
,
2843 route_map_object_t type
, void *object
)
2845 struct in6_addr
*address
;
2846 struct bgp_path_info
*path
;
2848 if (type
== RMAP_BGP
) {
2849 /* Fetch routemap's rule information. */
2853 /* Set next hop value. */
2854 path
->attr
->mp_nexthop_local
= *address
;
2856 /* Set nexthop length. */
2857 if (path
->attr
->mp_nexthop_len
2858 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2859 path
->attr
->mp_nexthop_len
=
2860 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2862 SET_FLAG(path
->attr
->rmap_change_flags
,
2863 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2869 /* Route map `ip nexthop' compile function. Given string is converted
2870 to struct in_addr structure. */
2871 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2874 struct in6_addr
*address
;
2876 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2878 ret
= inet_pton(AF_INET6
, arg
, address
);
2881 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2888 /* Free route map's compiled `ip nexthop' value. */
2889 static void route_set_ipv6_nexthop_local_free(void *rule
)
2891 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2894 /* Route map commands for ip nexthop set. */
2895 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2896 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2897 route_set_ipv6_nexthop_local_compile
,
2898 route_set_ipv6_nexthop_local_free
};
2900 /* `set ipv6 nexthop peer-address' */
2902 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2903 static enum route_map_cmd_result_t
2904 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
,
2905 route_map_object_t type
, void *object
)
2907 struct in6_addr peer_address
;
2908 struct bgp_path_info
*path
;
2911 if (type
== RMAP_BGP
) {
2912 /* Fetch routemap's rule information. */
2916 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2917 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2919 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2920 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2921 /* Set next hop value and length in attribute. */
2922 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2923 path
->attr
->mp_nexthop_local
= peer_address
;
2924 if (path
->attr
->mp_nexthop_len
2925 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2926 path
->attr
->mp_nexthop_len
=
2927 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2929 path
->attr
->mp_nexthop_global
= peer_address
;
2930 if (path
->attr
->mp_nexthop_len
== 0)
2931 path
->attr
->mp_nexthop_len
=
2932 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2935 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2936 /* The next hop value will be set as part of packet
2938 * Set the flags here to indicate that rewrite needs to
2940 * Also, clear the value - we clear both global and
2942 * nexthops, whether we send one or both is determined
2945 SET_FLAG(path
->attr
->rmap_change_flags
,
2946 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2947 /* clear next hop value. */
2948 memset(&(path
->attr
->mp_nexthop_global
), 0,
2949 sizeof(struct in6_addr
));
2950 memset(&(path
->attr
->mp_nexthop_local
), 0,
2951 sizeof(struct in6_addr
));
2958 /* Route map `ip next-hop' compile function. Given string is converted
2959 to struct in_addr structure. */
2960 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2964 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2970 /* Free route map's compiled `ip next-hop' value. */
2971 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2973 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2976 /* Route map commands for ip nexthop set. */
2977 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2978 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2979 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2981 /* `set ipv4 vpn next-hop A.B.C.D' */
2983 static enum route_map_cmd_result_t
2984 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
,
2985 route_map_object_t type
, void *object
)
2987 struct in_addr
*address
;
2988 struct bgp_path_info
*path
;
2990 if (type
== RMAP_BGP
) {
2991 /* Fetch routemap's rule information. */
2995 /* Set next hop value. */
2996 path
->attr
->mp_nexthop_global_in
= *address
;
2997 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3003 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3006 struct in_addr
*address
;
3008 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3010 ret
= inet_aton(arg
, address
);
3013 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3020 /* `set ipv6 vpn next-hop A.B.C.D' */
3022 static enum route_map_cmd_result_t
3023 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
,
3024 route_map_object_t type
, void *object
)
3026 struct in6_addr
*address
;
3027 struct bgp_path_info
*path
;
3029 if (type
== RMAP_BGP
) {
3030 /* Fetch routemap's rule information. */
3034 /* Set next hop value. */
3035 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3036 sizeof(struct in6_addr
));
3037 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3043 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3046 struct in6_addr
*address
;
3048 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3049 ret
= inet_pton(AF_INET6
, arg
, address
);
3052 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3059 static void route_set_vpn_nexthop_free(void *rule
)
3061 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3064 /* Route map commands for ipv4 next-hop set. */
3065 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3066 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
3067 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
3069 /* Route map commands for ipv6 next-hop set. */
3070 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3071 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
3072 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
3074 /* `set originator-id' */
3076 /* For origin set. */
3077 static enum route_map_cmd_result_t
3078 route_set_originator_id(void *rule
, const struct prefix
*prefix
,
3079 route_map_object_t type
, void *object
)
3081 struct in_addr
*address
;
3082 struct bgp_path_info
*path
;
3084 if (type
== RMAP_BGP
) {
3088 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3089 path
->attr
->originator_id
= *address
;
3095 /* Compile function for originator-id set. */
3096 static void *route_set_originator_id_compile(const char *arg
)
3099 struct in_addr
*address
;
3101 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3103 ret
= inet_aton(arg
, address
);
3106 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3113 /* Compile function for originator_id set. */
3114 static void route_set_originator_id_free(void *rule
)
3116 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3119 /* Set originator-id rule structure. */
3120 struct route_map_rule_cmd route_set_originator_id_cmd
= {
3121 "originator-id", route_set_originator_id
,
3122 route_set_originator_id_compile
, route_set_originator_id_free
,
3125 /* Add bgp route map rule. */
3126 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3127 const char *arg
, route_map_event_t type
)
3129 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3130 int retval
= CMD_SUCCESS
;
3131 enum rmap_compile_rets ret
;
3133 ret
= route_map_add_match(index
, command
, arg
, type
);
3135 case RMAP_RULE_MISSING
:
3136 vty_out(vty
, "%% BGP Can't find rule.\n");
3137 retval
= CMD_WARNING_CONFIG_FAILED
;
3139 case RMAP_COMPILE_ERROR
:
3140 vty_out(vty
, "%% BGP Argument is malformed.\n");
3141 retval
= CMD_WARNING_CONFIG_FAILED
;
3143 case RMAP_COMPILE_SUCCESS
:
3145 * Intentionally doing nothing here.
3153 /* Delete bgp route map rule. */
3154 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3155 const char *arg
, route_map_event_t type
)
3157 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3158 enum rmap_compile_rets ret
;
3159 int retval
= CMD_SUCCESS
;
3160 char *dep_name
= NULL
;
3162 char *rmap_name
= NULL
;
3164 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3165 /* ignore the mundane, the types without any dependency */
3167 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3170 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3172 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3174 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3177 ret
= route_map_delete_match(index
, command
, dep_name
, type
);
3179 case RMAP_RULE_MISSING
:
3180 vty_out(vty
, "%% BGP Can't find rule.\n");
3181 retval
= CMD_WARNING_CONFIG_FAILED
;
3183 case RMAP_COMPILE_ERROR
:
3184 vty_out(vty
, "%% BGP Argument is malformed.\n");
3185 retval
= CMD_WARNING_CONFIG_FAILED
;
3187 case RMAP_COMPILE_SUCCESS
:
3189 * Nothing to do here
3194 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3195 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3201 * This is the workhorse routine for processing in/out routemap
3204 static void bgp_route_map_process_peer(const char *rmap_name
,
3205 struct route_map
*map
, struct peer
*peer
,
3206 int afi
, int safi
, int route_update
)
3208 struct bgp_filter
*filter
;
3210 if (!peer
|| !rmap_name
)
3213 filter
= &peer
->filter
[afi
][safi
];
3215 * in is for non-route-server clients,
3216 * out is for all peers
3218 if (filter
->map
[RMAP_IN
].name
3219 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3220 filter
->map
[RMAP_IN
].map
= map
;
3222 if (route_update
&& peer
->status
== Established
) {
3223 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3224 PEER_FLAG_SOFT_RECONFIG
)) {
3225 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3227 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3228 rmap_name
, peer
->host
);
3230 bgp_soft_reconfig_in(peer
, afi
, safi
);
3231 } else if (CHECK_FLAG(peer
->cap
,
3232 PEER_CAP_REFRESH_OLD_RCV
)
3233 || CHECK_FLAG(peer
->cap
,
3234 PEER_CAP_REFRESH_NEW_RCV
)) {
3235 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3237 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3238 rmap_name
, peer
->host
);
3239 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3246 * For outbound, unsuppress and default-originate map change (content or
3247 * map created), merely update the "config" here, the actual route
3248 * announcement happens at the group level.
3250 if (filter
->map
[RMAP_OUT
].name
3251 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3252 filter
->map
[RMAP_OUT
].map
= map
;
3254 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3255 filter
->usmap
.map
= map
;
3257 if (peer
->default_rmap
[afi
][safi
].name
3258 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3259 peer
->default_rmap
[afi
][safi
].map
= map
;
3262 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3263 struct route_map
*map
,
3266 struct peer_group
*group
;
3267 struct listnode
*node
, *nnode
;
3268 struct bgp_filter
*filter
;
3275 /* All the peers have been updated correctly already. This is
3276 * just updating the placeholder data. No real update required.
3278 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3279 FOREACH_AFI_SAFI (afi
, safi
) {
3280 filter
= &group
->conf
->filter
[afi
][safi
];
3282 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3283 if ((filter
->map
[direct
].name
)
3284 && (strcmp(rmap_name
,
3285 filter
->map
[direct
].name
)
3287 filter
->map
[direct
].map
= map
;
3290 if (filter
->usmap
.name
3291 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3292 filter
->usmap
.map
= map
;
3298 * Note that if an extreme number (tens of thousands) of route-maps are in use
3299 * and if bgp has an extreme number of peers, network statements, etc then this
3300 * function can consume a lot of cycles. This is due to this function being
3301 * called for each route-map and within this function we walk the list of peers,
3302 * network statements, etc looking to see if they use this route-map.
3304 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3311 struct bgp_node
*bn
;
3312 struct bgp_static
*bgp_static
;
3313 struct bgp_aggregate
*aggregate
;
3314 struct listnode
*node
, *nnode
;
3315 struct route_map
*map
;
3316 char buf
[INET6_ADDRSTRLEN
];
3318 map
= route_map_lookup_by_name(rmap_name
);
3320 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3322 /* Ignore dummy peer-group structure */
3323 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3326 FOREACH_AFI_SAFI (afi
, safi
) {
3327 /* process in/out/import/export/default-orig
3329 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3330 safi
, route_update
);
3334 /* for outbound/default-orig route-maps, process for groups */
3335 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3338 /* update peer-group config (template) */
3339 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3341 FOREACH_AFI_SAFI (afi
, safi
) {
3342 /* For table route-map updates. */
3343 if (!bgp_fibupd_safi(safi
))
3346 if (bgp
->table_map
[afi
][safi
].name
3347 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3350 /* bgp->table_map[afi][safi].map is NULL.
3351 * i.e Route map creation event.
3352 * So update applied_counter.
3353 * If it is not NULL, i.e It may be routemap updation or
3354 * deletion. so no need to update the counter.
3356 if (!bgp
->table_map
[afi
][safi
].map
)
3357 route_map_counter_increment(map
);
3358 bgp
->table_map
[afi
][safi
].map
= map
;
3360 if (BGP_DEBUG(zebra
, ZEBRA
))
3362 "Processing route_map %s update on "
3366 bgp_zebra_announce_table(bgp
, afi
, safi
);
3369 /* For network route-map updates. */
3370 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3371 bn
= bgp_route_next(bn
)) {
3372 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3376 if (!bgp_static
->rmap
.name
3377 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3380 if (!bgp_static
->rmap
.map
)
3381 route_map_counter_increment(map
);
3383 bgp_static
->rmap
.map
= map
;
3385 if (route_update
&& !bgp_static
->backdoor
) {
3386 if (bgp_debug_zebra(&bn
->p
))
3388 "Processing route_map %s update on static route %s",
3390 inet_ntop(bn
->p
.family
,
3391 &bn
->p
.u
.prefix
, buf
,
3393 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3398 /* For aggregate-address route-map updates. */
3399 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
3400 bn
= bgp_route_next(bn
)) {
3401 aggregate
= bgp_node_get_bgp_aggregate_info(bn
);
3405 if (!aggregate
->rmap
.name
3406 || (strcmp(rmap_name
, aggregate
->rmap
.name
) != 0))
3409 if (!aggregate
->rmap
.map
)
3410 route_map_counter_increment(map
);
3412 aggregate
->rmap
.map
= map
;
3415 if (bgp_debug_zebra(&bn
->p
))
3417 "Processing route_map %s update on aggregate-address route %s",
3419 inet_ntop(bn
->p
.family
,
3420 &bn
->p
.u
.prefix
, buf
,
3422 bgp_aggregate_route(bgp
, &bn
->p
, afi
, safi
,
3428 /* For redistribute route-map updates. */
3429 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3430 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3431 struct list
*red_list
;
3432 struct bgp_redist
*red
;
3434 red_list
= bgp
->redist
[afi
][i
];
3438 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3440 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3444 route_map_counter_increment(map
);
3446 red
->rmap
.map
= map
;
3451 if (BGP_DEBUG(zebra
, ZEBRA
))
3453 "Processing route_map %s update on redistributed routes",
3456 bgp_redistribute_resend(bgp
, afi
, i
,
3461 /* for type5 command route-maps */
3462 FOREACH_AFI_SAFI (afi
, safi
) {
3463 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3464 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3468 /* Make sure the route-map is populated here if not already done */
3469 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3471 if (BGP_DEBUG(zebra
, ZEBRA
))
3473 "Processing route_map %s update on advertise type5 route command",
3476 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3477 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3478 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3483 static void bgp_route_map_process_update_cb(char *rmap_name
)
3485 struct listnode
*node
, *nnode
;
3488 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3489 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3492 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3493 vnc_routemap_update(bgp
, __func__
);
3497 vpn_policy_routemap_event(rmap_name
);
3500 int bgp_route_map_update_timer(struct thread
*thread
)
3502 bm
->t_rmap_update
= NULL
;
3504 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3509 static void bgp_route_map_mark_update(const char *rmap_name
)
3511 struct listnode
*node
, *nnode
;
3514 /* If new update is received before the current timer timed out,
3515 * turn it off and start a new timer.
3517 if (bm
->t_rmap_update
!= NULL
)
3518 THREAD_OFF(bm
->t_rmap_update
);
3520 /* rmap_update_timer of 0 means don't do route updates */
3521 if (bm
->rmap_update_timer
) {
3522 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3523 NULL
, bm
->rmap_update_timer
,
3524 &bm
->t_rmap_update
);
3526 /* Signal the groups that a route-map update event has
3528 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3529 update_group_policy_update(bgp
,
3530 BGP_POLICY_ROUTE_MAP
,
3533 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3534 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3536 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3537 vnc_routemap_update(bgp
, __func__
);
3542 static void bgp_route_map_add(const char *rmap_name
)
3544 if (route_map_mark_updated(rmap_name
) == 0)
3545 bgp_route_map_mark_update(rmap_name
);
3547 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3550 static void bgp_route_map_delete(const char *rmap_name
)
3552 if (route_map_mark_updated(rmap_name
) == 0)
3553 bgp_route_map_mark_update(rmap_name
);
3555 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3558 static void bgp_route_map_event(const char *rmap_name
)
3560 if (route_map_mark_updated(rmap_name
) == 0)
3561 bgp_route_map_mark_update(rmap_name
);
3563 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3566 DEFUN (match_mac_address
,
3567 match_mac_address_cmd
,
3568 "match mac address WORD",
3571 "Match address of route\n"
3572 "MAC Access-list name\n")
3574 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3575 RMAP_EVENT_FILTER_ADDED
);
3578 DEFUN (no_match_mac_address
,
3579 no_match_mac_address_cmd
,
3580 "no match mac address WORD",
3584 "Match address of route\n"
3585 "MAC acess-list name\n")
3587 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3588 RMAP_EVENT_FILTER_DELETED
);
3591 DEFUN (match_evpn_route_type
,
3592 match_evpn_route_type_cmd
,
3593 "match evpn route-type <macip | multicast | prefix>",
3596 "Match route-type\n"
3601 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3602 RMAP_EVENT_MATCH_ADDED
);
3605 DEFUN (no_match_evpn_route_type
,
3606 no_match_evpn_route_type_cmd
,
3607 "no match evpn route-type <macip | multicast | prefix>",
3611 "Match route-type\n"
3616 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3617 RMAP_EVENT_MATCH_DELETED
);
3621 DEFUN (match_evpn_vni
,
3623 "match evpn vni " CMD_VNI_RANGE
,
3629 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3630 RMAP_EVENT_MATCH_ADDED
);
3633 DEFUN (no_match_evpn_vni
,
3634 no_match_evpn_vni_cmd
,
3635 "no match evpn vni " CMD_VNI_RANGE
,
3642 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3643 RMAP_EVENT_MATCH_DELETED
);
3646 DEFUN (match_evpn_default_route
,
3647 match_evpn_default_route_cmd
,
3648 "match evpn default-route",
3651 "default EVPN type-5 route\n")
3653 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3654 RMAP_EVENT_MATCH_ADDED
);
3657 DEFUN (no_match_evpn_default_route
,
3658 no_match_evpn_default_route_cmd
,
3659 "no match evpn default-route",
3663 "default EVPN type-5 route\n")
3665 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3666 RMAP_EVENT_MATCH_DELETED
);
3669 DEFPY(match_vrl_source_vrf
,
3670 match_vrl_source_vrf_cmd
,
3671 "match source-vrf NAME$vrf_name",
3676 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3677 RMAP_EVENT_MATCH_ADDED
);
3680 DEFPY(no_match_vrl_source_vrf
,
3681 no_match_vrl_source_vrf_cmd
,
3682 "no match source-vrf NAME$vrf_name",
3688 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3689 RMAP_EVENT_MATCH_DELETED
);
3694 "match peer <A.B.C.D|X:X::X:X|WORD>",
3696 "Match peer address\n"
3697 "IP address of peer\n"
3698 "IPv6 address of peer\n"
3699 "Interface name of peer\n")
3702 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3703 RMAP_EVENT_MATCH_ADDED
);
3706 DEFUN (match_peer_local
,
3707 match_peer_local_cmd
,
3710 "Match peer address\n"
3711 "Static or Redistributed routes\n")
3713 return bgp_route_match_add(vty
, "peer", "local",
3714 RMAP_EVENT_MATCH_DELETED
);
3717 DEFUN (no_match_peer
,
3719 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3722 "Match peer address\n"
3723 "Static or Redistributed routes\n"
3724 "IP address of peer\n"
3725 "IPv6 address of peer\n"
3726 "Interface name of peer\n")
3730 if (argc
<= idx_peer
)
3731 return bgp_route_match_delete(vty
, "peer", NULL
,
3732 RMAP_EVENT_MATCH_DELETED
);
3733 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3734 RMAP_EVENT_MATCH_DELETED
);
3737 #if defined(HAVE_LUA)
3738 DEFUN (match_command
,
3740 "match command WORD",
3742 "Run a command to match\n"
3743 "The command to run\n")
3745 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3746 RMAP_EVENT_FILTER_ADDED
);
3749 DEFUN (no_match_command
,
3750 no_match_command_cmd
,
3751 "no match command WORD",
3754 "Run a command to match\n"
3755 "The command to run\n")
3757 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3758 RMAP_EVENT_FILTER_DELETED
);
3762 /* match probability */
3763 DEFUN (match_probability
,
3764 match_probability_cmd
,
3765 "match probability (0-100)",
3767 "Match portion of routes defined by percentage value\n"
3768 "Percentage of routes\n")
3771 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3772 RMAP_EVENT_MATCH_ADDED
);
3776 DEFUN (no_match_probability
,
3777 no_match_probability_cmd
,
3778 "no match probability [(1-99)]",
3781 "Match portion of routes defined by percentage value\n"
3782 "Percentage of routes\n")
3785 if (argc
<= idx_number
)
3786 return bgp_route_match_delete(vty
, "probability", NULL
,
3787 RMAP_EVENT_MATCH_DELETED
);
3788 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3789 RMAP_EVENT_MATCH_DELETED
);
3793 DEFUN (match_ip_route_source
,
3794 match_ip_route_source_cmd
,
3795 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3798 "Match advertising source address of route\n"
3799 "IP access-list number\n"
3800 "IP access-list number (expanded range)\n"
3801 "IP standard access-list name\n")
3804 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3805 RMAP_EVENT_FILTER_ADDED
);
3809 DEFUN (no_match_ip_route_source
,
3810 no_match_ip_route_source_cmd
,
3811 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3815 "Match advertising source address of route\n"
3816 "IP access-list number\n"
3817 "IP access-list number (expanded range)\n"
3818 "IP standard access-list name\n")
3821 if (argc
<= idx_number
)
3822 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3823 RMAP_EVENT_FILTER_DELETED
);
3824 return bgp_route_match_delete(vty
, "ip route-source",
3825 argv
[idx_number
]->arg
,
3826 RMAP_EVENT_FILTER_DELETED
);
3830 DEFUN (match_ip_route_source_prefix_list
,
3831 match_ip_route_source_prefix_list_cmd
,
3832 "match ip route-source prefix-list WORD",
3835 "Match advertising source address of route\n"
3836 "Match entries of prefix-lists\n"
3837 "IP prefix-list name\n")
3840 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3841 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3845 DEFUN (no_match_ip_route_source_prefix_list
,
3846 no_match_ip_route_source_prefix_list_cmd
,
3847 "no match ip route-source prefix-list [WORD]",
3851 "Match advertising source address of route\n"
3852 "Match entries of prefix-lists\n"
3853 "IP prefix-list name\n")
3856 if (argc
<= idx_word
)
3857 return bgp_route_match_delete(vty
,
3858 "ip route-source prefix-list",
3859 NULL
, RMAP_EVENT_PLIST_DELETED
);
3860 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3861 argv
[idx_word
]->arg
,
3862 RMAP_EVENT_PLIST_DELETED
);
3866 DEFUN (match_local_pref
,
3867 match_local_pref_cmd
,
3868 "match local-preference (0-4294967295)",
3870 "Match local-preference of route\n"
3874 return bgp_route_match_add(vty
, "local-preference",
3875 argv
[idx_number
]->arg
,
3876 RMAP_EVENT_MATCH_ADDED
);
3880 DEFUN (no_match_local_pref
,
3881 no_match_local_pref_cmd
,
3882 "no match local-preference [(0-4294967295)]",
3885 "Match local preference of route\n"
3886 "Local preference value\n")
3888 int idx_localpref
= 3;
3889 if (argc
<= idx_localpref
)
3890 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3891 RMAP_EVENT_MATCH_DELETED
);
3892 return bgp_route_match_delete(vty
, "local-preference",
3893 argv
[idx_localpref
]->arg
,
3894 RMAP_EVENT_MATCH_DELETED
);
3898 DEFUN (match_community
,
3899 match_community_cmd
,
3900 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3902 "Match BGP community list\n"
3903 "Community-list number (standard)\n"
3904 "Community-list number (expanded)\n"
3905 "Community-list name\n"
3906 "Do exact matching of communities\n")
3908 int idx_comm_list
= 2;
3913 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3914 strlen(argv
[idx_comm_list
]->arg
)
3915 + strlen("exact-match") + 2);
3917 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3919 argstr
= argv
[idx_comm_list
]->arg
;
3921 ret
= bgp_route_match_add(vty
, "community", argstr
,
3922 RMAP_EVENT_CLIST_ADDED
);
3924 if (argstr
!= argv
[idx_comm_list
]->arg
)
3925 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3930 DEFUN (no_match_community
,
3931 no_match_community_cmd
,
3932 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3935 "Match BGP community list\n"
3936 "Community-list number (standard)\n"
3937 "Community-list number (expanded)\n"
3938 "Community-list name\n"
3939 "Do exact matching of communities\n")
3941 return bgp_route_match_delete(vty
, "community", NULL
,
3942 RMAP_EVENT_CLIST_DELETED
);
3945 DEFUN (match_lcommunity
,
3946 match_lcommunity_cmd
,
3947 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
3949 "Match BGP large community list\n"
3950 "Large Community-list number (standard)\n"
3951 "Large Community-list number (expanded)\n"
3952 "Large Community-list name\n"
3953 "Do exact matching of communities\n")
3955 int idx_lcomm_list
= 2;
3960 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3961 strlen(argv
[idx_lcomm_list
]->arg
)
3962 + strlen("exact-match") + 2);
3964 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
3966 argstr
= argv
[idx_lcomm_list
]->arg
;
3968 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
3969 RMAP_EVENT_LLIST_ADDED
);
3970 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
3971 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3976 DEFUN (no_match_lcommunity
,
3977 no_match_lcommunity_cmd
,
3978 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
3981 "Match BGP large community list\n"
3982 "Large Community-list number (standard)\n"
3983 "Large Community-list number (expanded)\n"
3984 "Large Community-list name\n"
3985 "Do exact matching of communities\n")
3987 return bgp_route_match_delete(vty
, "large-community", NULL
,
3988 RMAP_EVENT_LLIST_DELETED
);
3991 DEFUN (match_ecommunity
,
3992 match_ecommunity_cmd
,
3993 "match extcommunity <(1-99)|(100-500)|WORD>",
3995 "Match BGP/VPN extended community list\n"
3996 "Extended community-list number (standard)\n"
3997 "Extended community-list number (expanded)\n"
3998 "Extended community-list name\n")
4000 int idx_comm_list
= 2;
4001 return bgp_route_match_add(vty
, "extcommunity",
4002 argv
[idx_comm_list
]->arg
,
4003 RMAP_EVENT_ECLIST_ADDED
);
4007 DEFUN (no_match_ecommunity
,
4008 no_match_ecommunity_cmd
,
4009 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
4012 "Match BGP/VPN extended community list\n"
4013 "Extended community-list number (standard)\n"
4014 "Extended community-list number (expanded)\n"
4015 "Extended community-list name\n")
4017 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
4018 RMAP_EVENT_ECLIST_DELETED
);
4022 DEFUN (match_aspath
,
4024 "match as-path WORD",
4026 "Match BGP AS path list\n"
4027 "AS path access-list name\n")
4030 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
4031 RMAP_EVENT_ASLIST_ADDED
);
4035 DEFUN (no_match_aspath
,
4036 no_match_aspath_cmd
,
4037 "no match as-path [WORD]",
4040 "Match BGP AS path list\n"
4041 "AS path access-list name\n")
4043 return bgp_route_match_delete(vty
, "as-path", NULL
,
4044 RMAP_EVENT_ASLIST_DELETED
);
4048 DEFUN (match_origin
,
4050 "match origin <egp|igp|incomplete>",
4055 "unknown heritage\n")
4058 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4059 return bgp_route_match_add(vty
, "origin", "igp",
4060 RMAP_EVENT_MATCH_ADDED
);
4061 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4062 return bgp_route_match_add(vty
, "origin", "egp",
4063 RMAP_EVENT_MATCH_ADDED
);
4064 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4065 return bgp_route_match_add(vty
, "origin", "incomplete",
4066 RMAP_EVENT_MATCH_ADDED
);
4068 vty_out(vty
, "%% Invalid match origin type\n");
4069 return CMD_WARNING_CONFIG_FAILED
;
4073 DEFUN (no_match_origin
,
4074 no_match_origin_cmd
,
4075 "no match origin [<egp|igp|incomplete>]",
4081 "unknown heritage\n")
4083 return bgp_route_match_delete(vty
, "origin", NULL
,
4084 RMAP_EVENT_MATCH_DELETED
);
4087 DEFUN (set_table_id
,
4089 "set table (1-4294967295)",
4091 "export route to non-main kernel table\n"
4092 "Kernel routing table id\n")
4096 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4098 return generic_set_add(vty
, index
, "table", argv
[idx_id
]->arg
);
4101 DEFUN (no_set_table_id
,
4102 no_set_table_id_cmd
,
4106 "export route to non-main kernel table\n")
4108 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4110 return generic_set_delete(vty
, index
, "table", NULL
);
4113 DEFUN (set_ip_nexthop_peer
,
4114 set_ip_nexthop_peer_cmd
,
4115 "[no] set ip next-hop peer-address",
4119 "Next hop address\n"
4120 "Use peer address (for BGP only)\n")
4122 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4123 const char *) = strmatch(argv
[0]->text
, "no")
4124 ? generic_set_delete
4127 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4131 DEFUN (set_ip_nexthop_unchanged
,
4132 set_ip_nexthop_unchanged_cmd
,
4133 "[no] set ip next-hop unchanged",
4137 "Next hop address\n"
4138 "Don't modify existing Next hop address\n")
4140 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4141 const char *) = strmatch(argv
[0]->text
, "no")
4142 ? generic_set_delete
4145 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4149 DEFUN (set_distance
,
4151 "set distance (0-255)",
4153 "BGP Administrative Distance to use\n"
4158 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4159 "distance", argv
[idx_number
]->arg
);
4162 DEFUN (no_set_distance
,
4163 no_set_distance_cmd
,
4164 "no set distance [(0-255)]",
4166 "BGP Administrative Distance to use\n"
4169 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4173 DEFUN (set_local_pref
,
4175 "set local-preference (0-4294967295)",
4177 "BGP local preference path attribute\n"
4178 "Preference value\n")
4181 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4182 "local-preference", argv
[idx_number
]->arg
);
4186 DEFUN (no_set_local_pref
,
4187 no_set_local_pref_cmd
,
4188 "no set local-preference [(0-4294967295)]",
4191 "BGP local preference path attribute\n"
4192 "Preference value\n")
4194 int idx_localpref
= 3;
4195 if (argc
<= idx_localpref
)
4196 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4197 "local-preference", NULL
);
4198 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4199 "local-preference", argv
[idx_localpref
]->arg
);
4205 "set weight (0-4294967295)",
4207 "BGP weight for routing table\n"
4211 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4212 argv
[idx_number
]->arg
);
4216 DEFUN (no_set_weight
,
4218 "no set weight [(0-4294967295)]",
4221 "BGP weight for routing table\n"
4225 if (argc
<= idx_weight
)
4226 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4228 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4229 "weight", argv
[idx_weight
]->arg
);
4232 DEFUN (set_label_index
,
4233 set_label_index_cmd
,
4234 "set label-index (0-1048560)",
4236 "Label index to associate with the prefix\n"
4237 "Label index value\n")
4240 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4241 "label-index", argv
[idx_number
]->arg
);
4244 DEFUN (no_set_label_index
,
4245 no_set_label_index_cmd
,
4246 "no set label-index [(0-1048560)]",
4249 "Label index to associate with the prefix\n"
4250 "Label index value\n")
4252 int idx_label_index
= 3;
4253 if (argc
<= idx_label_index
)
4254 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4255 "label-index", NULL
);
4256 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4257 "label-index", argv
[idx_label_index
]->arg
);
4260 DEFUN (set_aspath_prepend_asn
,
4261 set_aspath_prepend_asn_cmd
,
4262 "set as-path prepend (1-4294967295)...",
4264 "Transform BGP AS_PATH attribute\n"
4265 "Prepend to the as-path\n"
4272 str
= argv_concat(argv
, argc
, idx_asn
);
4273 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4274 "as-path prepend", str
);
4275 XFREE(MTYPE_TMP
, str
);
4280 DEFUN (set_aspath_prepend_lastas
,
4281 set_aspath_prepend_lastas_cmd
,
4282 "set as-path prepend last-as (1-10)",
4284 "Transform BGP AS_PATH attribute\n"
4285 "Prepend to the as-path\n"
4286 "Use the peer's AS-number\n"
4287 "Number of times to insert\n")
4289 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4292 DEFUN (no_set_aspath_prepend
,
4293 no_set_aspath_prepend_cmd
,
4294 "no set as-path prepend [(1-4294967295)]",
4297 "Transform BGP AS_PATH attribute\n"
4298 "Prepend to the as-path\n"
4305 str
= argv_concat(argv
, argc
, idx_asn
);
4306 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4307 "as-path prepend", str
);
4308 XFREE(MTYPE_TMP
, str
);
4312 DEFUN (no_set_aspath_prepend_lastas
,
4313 no_set_aspath_prepend_lastas_cmd
,
4314 "no set as-path prepend last-as [(1-10)]",
4317 "Transform BGP AS_PATH attribute\n"
4318 "Prepend to the as-path\n"
4319 "Use the peers AS-number\n"
4320 "Number of times to insert\n")
4322 return no_set_aspath_prepend(self
, vty
, argc
, argv
);
4325 DEFUN (set_aspath_exclude
,
4326 set_aspath_exclude_cmd
,
4327 "set as-path exclude (1-4294967295)...",
4329 "Transform BGP AS-path attribute\n"
4330 "Exclude from the as-path\n"
4337 str
= argv_concat(argv
, argc
, idx_asn
);
4338 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4339 "as-path exclude", str
);
4340 XFREE(MTYPE_TMP
, str
);
4344 DEFUN (no_set_aspath_exclude
,
4345 no_set_aspath_exclude_cmd
,
4346 "no set as-path exclude (1-4294967295)...",
4349 "Transform BGP AS_PATH attribute\n"
4350 "Exclude from the as-path\n"
4357 str
= argv_concat(argv
, argc
, idx_asn
);
4358 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4359 "as-path exclude", str
);
4360 XFREE(MTYPE_TMP
, str
);
4364 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4365 "no set as-path exclude",
4367 "Transform BGP AS_PATH attribute\n"
4368 "Exclude from the as-path\n")
4370 DEFUN (set_community
,
4372 "set community AA:NN...",
4374 "BGP community attribute\n"
4382 struct community
*com
= NULL
;
4387 b
= buffer_new(1024);
4389 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4390 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4397 buffer_putc(b
, ' ');
4401 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4403 buffer_putstr(b
, "internet");
4406 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4408 buffer_putstr(b
, "local-AS");
4411 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4412 && strncmp(argv
[i
]->arg
, "no-advertise",
4413 strlen(argv
[i
]->arg
))
4415 buffer_putstr(b
, "no-advertise");
4418 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4419 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4421 buffer_putstr(b
, "no-export");
4424 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4425 strlen(argv
[i
]->arg
))
4427 buffer_putstr(b
, "graceful-shutdown");
4430 buffer_putstr(b
, argv
[i
]->arg
);
4432 buffer_putc(b
, '\0');
4434 /* Fetch result string then compile it to communities attribute. */
4435 str
= buffer_getstr(b
);
4439 com
= community_str2com(str
);
4440 XFREE(MTYPE_TMP
, str
);
4443 /* Can't compile user input into communities attribute. */
4445 vty_out(vty
, "%% Malformed communities attribute\n");
4446 return CMD_WARNING_CONFIG_FAILED
;
4449 /* Set communites attribute string. */
4450 str
= community_str(com
, false);
4453 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4454 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4455 strlcpy(argstr
, str
, argstr_sz
);
4456 strlcat(argstr
, " additive", argstr_sz
);
4457 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4458 "community", argstr
);
4459 XFREE(MTYPE_TMP
, argstr
);
4461 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4464 community_free(&com
);
4469 DEFUN (set_community_none
,
4470 set_community_none_cmd
,
4471 "set community none",
4473 "BGP community attribute\n"
4474 "No community attribute\n")
4476 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4477 "community", "none");
4480 DEFUN (no_set_community
,
4481 no_set_community_cmd
,
4482 "no set community AA:NN...",
4485 "BGP community attribute\n"
4488 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4492 ALIAS (no_set_community
,
4493 no_set_community_short_cmd
,
4497 "BGP community attribute\n")
4500 DEFUN (set_community_delete
,
4501 set_community_delete_cmd
,
4502 "set comm-list <(1-99)|(100-500)|WORD> delete",
4504 "set BGP community list (for deletion)\n"
4505 "Community-list number (standard)\n"
4506 "Community-list number (expanded)\n"
4507 "Community-list name\n"
4508 "Delete matching communities\n")
4510 int idx_comm_list
= 2;
4513 args
= argv_concat(argv
, argc
, idx_comm_list
);
4514 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4516 XFREE(MTYPE_TMP
, args
);
4521 DEFUN (no_set_community_delete
,
4522 no_set_community_delete_cmd
,
4523 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4526 "set BGP community list (for deletion)\n"
4527 "Community-list number (standard)\n"
4528 "Community-list number (expanded)\n"
4529 "Community-list name\n"
4530 "Delete matching communities\n")
4532 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4536 DEFUN (set_lcommunity
,
4538 "set large-community AA:BB:CC...",
4540 "BGP large community attribute\n"
4541 "Large Community number in aa:bb:cc format or additive\n")
4546 str
= argv_concat(argv
, argc
, 2);
4547 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4548 "large-community", str
);
4549 XFREE(MTYPE_TMP
, str
);
4554 DEFUN (set_lcommunity_none
,
4555 set_lcommunity_none_cmd
,
4556 "set large-community none",
4558 "BGP large community attribute\n"
4559 "No large community attribute\n")
4561 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4562 "large-community", "none");
4565 DEFUN (no_set_lcommunity
,
4566 no_set_lcommunity_cmd
,
4567 "no set large-community none",
4570 "BGP large community attribute\n"
4571 "No community attribute\n")
4573 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4574 "large-community", NULL
);
4577 DEFUN (no_set_lcommunity1
,
4578 no_set_lcommunity1_cmd
,
4579 "no set large-community AA:BB:CC...",
4582 "BGP large community attribute\n"
4583 "Large community in AA:BB:CC... format or additive\n")
4585 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4586 "large-community", NULL
);
4589 ALIAS (no_set_lcommunity1
,
4590 no_set_lcommunity1_short_cmd
,
4591 "no set large-community",
4594 "BGP large community attribute\n")
4596 DEFUN (set_lcommunity_delete
,
4597 set_lcommunity_delete_cmd
,
4598 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4600 "set BGP large community list (for deletion)\n"
4601 "Large Community-list number (standard)\n"
4602 "Large Communitly-list number (expanded)\n"
4603 "Large Community-list name\n"
4604 "Delete matching large communities\n")
4606 int idx_lcomm_list
= 2;
4609 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
4610 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4611 "large-comm-list", args
);
4612 XFREE(MTYPE_TMP
, args
);
4617 DEFUN (no_set_lcommunity_delete
,
4618 no_set_lcommunity_delete_cmd
,
4619 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4622 "set BGP large community list (for deletion)\n"
4623 "Large Community-list number (standard)\n"
4624 "Large Communitly-list number (expanded)\n"
4625 "Large Community-list name\n"
4626 "Delete matching large communities\n")
4628 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4629 "large-comm-list", NULL
);
4632 ALIAS (no_set_lcommunity_delete
,
4633 no_set_lcommunity_delete_short_cmd
,
4634 "no set large-comm-list",
4637 "set BGP large community list (for deletion)\n")
4639 DEFUN (set_ecommunity_rt
,
4640 set_ecommunity_rt_cmd
,
4641 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4643 "BGP extended community attribute\n"
4644 "Route Target extended community\n"
4645 "VPN extended community\n")
4651 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4652 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4653 "extcommunity rt", str
);
4654 XFREE(MTYPE_TMP
, str
);
4659 DEFUN (no_set_ecommunity_rt
,
4660 no_set_ecommunity_rt_cmd
,
4661 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4664 "BGP extended community attribute\n"
4665 "Route Target extended community\n"
4666 "VPN extended community\n")
4668 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4669 "extcommunity rt", NULL
);
4672 ALIAS (no_set_ecommunity_rt
,
4673 no_set_ecommunity_rt_short_cmd
,
4674 "no set extcommunity rt",
4677 "BGP extended community attribute\n"
4678 "Route Target extended community\n")
4680 DEFUN (set_ecommunity_soo
,
4681 set_ecommunity_soo_cmd
,
4682 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4684 "BGP extended community attribute\n"
4685 "Site-of-Origin extended community\n"
4686 "VPN extended community\n")
4692 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4693 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4694 "extcommunity soo", str
);
4695 XFREE(MTYPE_TMP
, str
);
4700 DEFUN (no_set_ecommunity_soo
,
4701 no_set_ecommunity_soo_cmd
,
4702 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4705 "BGP extended community attribute\n"
4706 "Site-of-Origin extended community\n"
4707 "VPN extended community\n")
4709 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4710 "extcommunity soo", NULL
);
4713 ALIAS (no_set_ecommunity_soo
,
4714 no_set_ecommunity_soo_short_cmd
,
4715 "no set extcommunity soo",
4718 "GP extended community attribute\n"
4719 "Site-of-Origin extended community\n")
4723 "set origin <egp|igp|incomplete>",
4728 "unknown heritage\n")
4731 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4732 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4734 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4735 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4737 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4738 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4739 "origin", "incomplete");
4741 vty_out(vty
, "%% Invalid set origin type\n");
4742 return CMD_WARNING_CONFIG_FAILED
;
4746 DEFUN (no_set_origin
,
4748 "no set origin [<egp|igp|incomplete>]",
4754 "unknown heritage\n")
4756 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4761 DEFUN (set_atomic_aggregate
,
4762 set_atomic_aggregate_cmd
,
4763 "set atomic-aggregate",
4765 "BGP atomic aggregate attribute\n" )
4767 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4768 "atomic-aggregate", NULL
);
4771 DEFUN (no_set_atomic_aggregate
,
4772 no_set_atomic_aggregate_cmd
,
4773 "no set atomic-aggregate",
4776 "BGP atomic aggregate attribute\n" )
4778 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4779 "atomic-aggregate", NULL
);
4782 DEFUN (set_aggregator_as
,
4783 set_aggregator_as_cmd
,
4784 "set aggregator as (1-4294967295) A.B.C.D",
4786 "BGP aggregator attribute\n"
4787 "AS number of aggregator\n"
4789 "IP address of aggregator\n")
4794 struct in_addr address
;
4797 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4799 vty_out(vty
, "Aggregator IP address is invalid\n");
4800 return CMD_WARNING_CONFIG_FAILED
;
4803 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4804 strlen(argv
[idx_number
]->arg
)
4805 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4807 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4809 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4810 "aggregator as", argstr
);
4812 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4818 DEFUN (no_set_aggregator_as
,
4819 no_set_aggregator_as_cmd
,
4820 "no set aggregator as [(1-4294967295) A.B.C.D]",
4823 "BGP aggregator attribute\n"
4824 "AS number of aggregator\n"
4826 "IP address of aggregator\n")
4831 struct in_addr address
;
4834 if (argc
<= idx_asn
)
4835 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4836 "aggregator as", NULL
);
4838 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4840 vty_out(vty
, "Aggregator IP address is invalid\n");
4841 return CMD_WARNING_CONFIG_FAILED
;
4844 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4845 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4848 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4850 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4851 "aggregator as", argstr
);
4853 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4858 DEFUN (match_ipv6_next_hop
,
4859 match_ipv6_next_hop_cmd
,
4860 "match ipv6 next-hop X:X::X:X",
4863 "Match IPv6 next-hop address of route\n"
4864 "IPv6 address of next hop\n")
4867 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4868 RMAP_EVENT_MATCH_ADDED
);
4871 DEFUN (no_match_ipv6_next_hop
,
4872 no_match_ipv6_next_hop_cmd
,
4873 "no match ipv6 next-hop X:X::X:X",
4877 "Match IPv6 next-hop address of route\n"
4878 "IPv6 address of next hop\n")
4881 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4882 RMAP_EVENT_MATCH_DELETED
);
4886 DEFUN (set_ipv6_nexthop_peer
,
4887 set_ipv6_nexthop_peer_cmd
,
4888 "set ipv6 next-hop peer-address",
4891 "Next hop address\n"
4892 "Use peer address (for BGP only)\n")
4894 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4895 "ipv6 next-hop peer-address", NULL
);
4898 DEFUN (no_set_ipv6_nexthop_peer
,
4899 no_set_ipv6_nexthop_peer_cmd
,
4900 "no set ipv6 next-hop peer-address",
4904 "IPv6 next-hop address\n"
4905 "Use peer address (for BGP only)\n")
4907 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4908 "ipv6 next-hop peer-address", NULL
);
4911 DEFUN (set_ipv6_nexthop_prefer_global
,
4912 set_ipv6_nexthop_prefer_global_cmd
,
4913 "set ipv6 next-hop prefer-global",
4916 "IPv6 next-hop address\n"
4917 "Prefer global over link-local if both exist\n")
4919 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4920 "ipv6 next-hop prefer-global", NULL
);
4924 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4925 no_set_ipv6_nexthop_prefer_global_cmd
,
4926 "no set ipv6 next-hop prefer-global",
4930 "IPv6 next-hop address\n"
4931 "Prefer global over link-local if both exist\n")
4933 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4934 "ipv6 next-hop prefer-global", NULL
);
4937 DEFUN (set_ipv6_nexthop_global
,
4938 set_ipv6_nexthop_global_cmd
,
4939 "set ipv6 next-hop global X:X::X:X",
4942 "IPv6 next-hop address\n"
4943 "IPv6 global address\n"
4944 "IPv6 address of next hop\n")
4947 struct in6_addr addr
;
4950 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4952 vty_out(vty
, "%% Malformed nexthop address\n");
4953 return CMD_WARNING_CONFIG_FAILED
;
4955 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4956 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4957 vty_out(vty
, "%% Invalid global nexthop address\n");
4958 return CMD_WARNING_CONFIG_FAILED
;
4961 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4962 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4966 DEFUN (no_set_ipv6_nexthop_global
,
4967 no_set_ipv6_nexthop_global_cmd
,
4968 "no set ipv6 next-hop global X:X::X:X",
4972 "IPv6 next-hop address\n"
4973 "IPv6 global address\n"
4974 "IPv6 address of next hop\n")
4977 if (argc
<= idx_ipv6
)
4978 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4979 "ipv6 next-hop global", NULL
);
4980 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4981 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4984 #ifdef KEEP_OLD_VPN_COMMANDS
4985 DEFUN (set_vpn_nexthop
,
4986 set_vpn_nexthop_cmd
,
4987 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4989 "VPNv4 information\n"
4990 "VPN next-hop address\n"
4991 "IP address of next hop\n"
4992 "VPNv6 information\n"
4993 "VPN next-hop address\n"
4994 "IPv6 address of next hop\n")
5000 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5002 return generic_set_add(
5003 vty
, VTY_GET_CONTEXT(route_map_index
),
5004 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5006 return generic_set_add(
5007 vty
, VTY_GET_CONTEXT(route_map_index
),
5008 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5013 DEFUN (no_set_vpn_nexthop
,
5014 no_set_vpn_nexthop_cmd
,
5015 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5018 "VPNv4 information\n"
5019 "VPN next-hop address\n"
5020 "IP address of next hop\n"
5021 "VPNv6 information\n"
5022 "VPN next-hop address\n"
5023 "IPv6 address of next hop\n")
5033 arg
= argv
[idx_ip
]->arg
;
5034 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5036 return generic_set_delete(
5037 vty
, VTY_GET_CONTEXT(route_map_index
),
5038 "ipv4 vpn next-hop", arg
);
5040 return generic_set_delete(
5041 vty
, VTY_GET_CONTEXT(route_map_index
),
5042 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5046 #endif /* KEEP_OLD_VPN_COMMANDS */
5048 DEFUN (set_ipx_vpn_nexthop
,
5049 set_ipx_vpn_nexthop_cmd
,
5050 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
5052 "IPv4 information\n"
5053 "IPv6 information\n"
5055 "VPN next-hop address\n"
5056 "IP address of next hop\n"
5057 "IPv6 address of next hop\n")
5063 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5065 return generic_set_add(
5066 vty
, VTY_GET_CONTEXT(route_map_index
),
5067 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5069 return generic_set_add(
5070 vty
, VTY_GET_CONTEXT(route_map_index
),
5071 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5076 DEFUN (no_set_ipx_vpn_nexthop
,
5077 no_set_ipx_vpn_nexthop_cmd
,
5078 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
5081 "IPv4 information\n"
5082 "IPv6 information\n"
5084 "VPN next-hop address\n"
5085 "IP address of next hop\n"
5086 "IPv6 address of next hop\n")
5096 arg
= argv
[idx_ip
]->arg
;
5097 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5099 return generic_set_delete(
5100 vty
, VTY_GET_CONTEXT(route_map_index
),
5101 "ipv4 vpn next-hop", arg
);
5103 return generic_set_delete(
5104 vty
, VTY_GET_CONTEXT(route_map_index
),
5105 "ipv6 vpn next-hop", arg
);
5110 DEFUN (set_originator_id
,
5111 set_originator_id_cmd
,
5112 "set originator-id A.B.C.D",
5114 "BGP originator ID attribute\n"
5115 "IP address of originator\n")
5118 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5119 "originator-id", argv
[idx_ipv4
]->arg
);
5123 DEFUN (no_set_originator_id
,
5124 no_set_originator_id_cmd
,
5125 "no set originator-id [A.B.C.D]",
5128 "BGP originator ID attribute\n"
5129 "IP address of originator\n")
5133 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
5135 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5136 "originator-id", arg
);
5140 /* Initialization of route map. */
5141 void bgp_route_map_init(void)
5145 route_map_add_hook(bgp_route_map_add
);
5146 route_map_delete_hook(bgp_route_map_delete
);
5147 route_map_event_hook(bgp_route_map_event
);
5149 route_map_match_interface_hook(generic_match_add
);
5150 route_map_no_match_interface_hook(generic_match_delete
);
5152 route_map_match_ip_address_hook(generic_match_add
);
5153 route_map_no_match_ip_address_hook(generic_match_delete
);
5155 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
5156 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
5158 route_map_match_ip_next_hop_hook(generic_match_add
);
5159 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
5161 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
5162 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5164 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5165 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5167 route_map_match_ipv6_address_hook(generic_match_add
);
5168 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5170 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5171 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5173 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5174 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5176 route_map_match_metric_hook(generic_match_add
);
5177 route_map_no_match_metric_hook(generic_match_delete
);
5179 route_map_match_tag_hook(generic_match_add
);
5180 route_map_no_match_tag_hook(generic_match_delete
);
5182 route_map_set_ip_nexthop_hook(generic_set_add
);
5183 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5185 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5186 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5188 route_map_set_metric_hook(generic_set_add
);
5189 route_map_no_set_metric_hook(generic_set_delete
);
5191 route_map_set_tag_hook(generic_set_add
);
5192 route_map_no_set_tag_hook(generic_set_delete
);
5194 route_map_install_match(&route_match_peer_cmd
);
5195 route_map_install_match(&route_match_local_pref_cmd
);
5196 #if defined(HAVE_LUA)
5197 route_map_install_match(&route_match_command_cmd
);
5199 route_map_install_match(&route_match_ip_address_cmd
);
5200 route_map_install_match(&route_match_ip_next_hop_cmd
);
5201 route_map_install_match(&route_match_ip_route_source_cmd
);
5202 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5203 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5204 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5205 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5206 route_map_install_match(&route_match_aspath_cmd
);
5207 route_map_install_match(&route_match_community_cmd
);
5208 route_map_install_match(&route_match_lcommunity_cmd
);
5209 route_map_install_match(&route_match_ecommunity_cmd
);
5210 route_map_install_match(&route_match_local_pref_cmd
);
5211 route_map_install_match(&route_match_metric_cmd
);
5212 route_map_install_match(&route_match_origin_cmd
);
5213 route_map_install_match(&route_match_probability_cmd
);
5214 route_map_install_match(&route_match_interface_cmd
);
5215 route_map_install_match(&route_match_tag_cmd
);
5216 route_map_install_match(&route_match_mac_address_cmd
);
5217 route_map_install_match(&route_match_evpn_vni_cmd
);
5218 route_map_install_match(&route_match_evpn_route_type_cmd
);
5219 route_map_install_match(&route_match_evpn_default_route_cmd
);
5220 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5222 route_map_install_set(&route_set_table_id_cmd
);
5223 route_map_install_set(&route_set_ip_nexthop_cmd
);
5224 route_map_install_set(&route_set_local_pref_cmd
);
5225 route_map_install_set(&route_set_weight_cmd
);
5226 route_map_install_set(&route_set_label_index_cmd
);
5227 route_map_install_set(&route_set_metric_cmd
);
5228 route_map_install_set(&route_set_distance_cmd
);
5229 route_map_install_set(&route_set_aspath_prepend_cmd
);
5230 route_map_install_set(&route_set_aspath_exclude_cmd
);
5231 route_map_install_set(&route_set_origin_cmd
);
5232 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5233 route_map_install_set(&route_set_aggregator_as_cmd
);
5234 route_map_install_set(&route_set_community_cmd
);
5235 route_map_install_set(&route_set_community_delete_cmd
);
5236 route_map_install_set(&route_set_lcommunity_cmd
);
5237 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5238 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5239 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5240 route_map_install_set(&route_set_originator_id_cmd
);
5241 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5242 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5243 route_map_install_set(&route_set_tag_cmd
);
5244 route_map_install_set(&route_set_label_index_cmd
);
5246 install_element(RMAP_NODE
, &match_peer_cmd
);
5247 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5248 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5249 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5250 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5251 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5252 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5253 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5254 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5255 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5256 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5257 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5258 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5259 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5260 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5261 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5262 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5264 install_element(RMAP_NODE
, &match_aspath_cmd
);
5265 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5266 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5267 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5268 install_element(RMAP_NODE
, &match_community_cmd
);
5269 install_element(RMAP_NODE
, &no_match_community_cmd
);
5270 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5271 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5272 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5273 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5274 install_element(RMAP_NODE
, &match_origin_cmd
);
5275 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5276 install_element(RMAP_NODE
, &match_probability_cmd
);
5277 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5279 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
5280 install_element(RMAP_NODE
, &set_table_id_cmd
);
5281 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5282 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5283 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5284 install_element(RMAP_NODE
, &set_distance_cmd
);
5285 install_element(RMAP_NODE
, &no_set_distance_cmd
);
5286 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5287 install_element(RMAP_NODE
, &set_weight_cmd
);
5288 install_element(RMAP_NODE
, &set_label_index_cmd
);
5289 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5290 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5291 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5292 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5293 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5294 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5295 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
5296 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5297 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5298 install_element(RMAP_NODE
, &set_origin_cmd
);
5299 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5300 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5301 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5302 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5303 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5304 install_element(RMAP_NODE
, &set_community_cmd
);
5305 install_element(RMAP_NODE
, &set_community_none_cmd
);
5306 install_element(RMAP_NODE
, &no_set_community_cmd
);
5307 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5308 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5309 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5310 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5311 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5312 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5313 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5314 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5315 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5316 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5317 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5318 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5319 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5320 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5321 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5322 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5323 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5324 #ifdef KEEP_OLD_VPN_COMMANDS
5325 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5326 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5327 #endif /* KEEP_OLD_VPN_COMMANDS */
5328 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5329 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5330 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5331 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5333 route_map_install_match(&route_match_ipv6_address_cmd
);
5334 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5335 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5336 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5337 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5338 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5339 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5340 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5342 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5343 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5344 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5345 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5346 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5347 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5348 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5349 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5350 #if defined(HAVE_LUA)
5351 install_element(RMAP_NODE
, &match_command_cmd
);
5352 install_element(RMAP_NODE
, &no_match_command_cmd
);
5356 void bgp_route_map_terminate(void)
5358 /* ToDo: Cleanup all the used memory */