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
120 set ipv6 next-hop global: Done
121 set ipv6 next-hop prefer-global: Done
122 set ipv6 next-hop local : Done
123 set as-path exclude : Done
127 /* generic value manipulation to be shared in multiple rules */
129 #define RMAP_VALUE_SET 0
130 #define RMAP_VALUE_ADD 1
131 #define RMAP_VALUE_SUB 2
139 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
141 if (rv
->variable
== 0 && value
== rv
->value
)
147 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
152 switch (rv
->variable
) {
161 switch (rv
->action
) {
163 if (current
> UINT32_MAX
- value
)
165 return current
+ value
;
167 if (current
<= value
)
169 return current
- value
;
175 static void *route_value_compile(const char *arg
)
177 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
178 unsigned long larg
= 0;
180 struct rmap_value
*rv
;
183 action
= RMAP_VALUE_ADD
;
185 } else if (arg
[0] == '-') {
186 action
= RMAP_VALUE_SUB
;
190 if (all_digit(arg
)) {
192 larg
= strtoul(arg
, &endptr
, 10);
193 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
196 if (strcmp(arg
, "rtt") == 0)
202 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
210 static void route_value_free(void *rule
)
212 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
215 /* generic as path object to be shared in multiple rules */
217 static void *route_aspath_compile(const char *arg
)
219 struct aspath
*aspath
;
221 aspath
= aspath_str2aspath(arg
);
227 static void route_aspath_free(void *rule
)
229 struct aspath
*aspath
= rule
;
233 struct bgp_match_peer_compiled
{
238 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
240 /* Compares the peer specified in the 'match peer' clause with the peer
241 received in bgp_path_info->peer. If it is the same, or if the peer structure
242 received is a peer_group containing it, returns RMAP_MATCH. */
243 static enum route_map_cmd_result_t
244 route_match_peer(void *rule
, const struct prefix
*prefix
,
245 route_map_object_t type
, void *object
)
247 struct bgp_match_peer_compiled
*pc
;
249 union sockunion su_def
= {
250 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
251 struct peer_group
*group
;
253 struct listnode
*node
, *nnode
;
255 if (type
== RMAP_BGP
) {
258 peer
= ((struct bgp_path_info
*)object
)->peer
;
264 if (strcmp(peer
->conf_if
, pc
->interface
) == 0)
270 /* If su='0.0.0.0' (command 'match peer local'), and it's a
272 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
275 if (sockunion_same(su
, &su_def
)) {
277 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
278 || CHECK_FLAG(peer
->rmap_type
,
279 PEER_RMAP_TYPE_REDISTRIBUTE
)
280 || CHECK_FLAG(peer
->rmap_type
,
281 PEER_RMAP_TYPE_AGGREGATE
)
282 || CHECK_FLAG(peer
->rmap_type
,
283 PEER_RMAP_TYPE_DEFAULT
))
290 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
291 if (sockunion_same(su
, &peer
->su
))
297 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
299 if (sockunion_same(su
, &peer
->su
))
308 static void *route_match_peer_compile(const char *arg
)
310 struct bgp_match_peer_compiled
*pc
;
313 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
314 sizeof(struct bgp_match_peer_compiled
));
316 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
318 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
325 /* Free route map's compiled `ip address' value. */
326 static void route_match_peer_free(void *rule
)
328 struct bgp_match_peer_compiled
*pc
= rule
;
330 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
332 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
335 /* Route map commands for ip address matching. */
336 struct route_map_rule_cmd route_match_peer_cmd
= {"peer", route_match_peer
,
337 route_match_peer_compile
,
338 route_match_peer_free
};
340 #if defined(HAVE_LUA)
341 static enum route_map_cmd_result_t
342 route_match_command(void *rule
, const struct prefix
*prefix
,
343 route_map_object_t type
, void *object
)
345 int status
= RMAP_NOMATCH
;
346 u_int32_t locpref
= 0;
347 u_int32_t newlocpref
= 0;
348 enum lua_rm_status lrm_status
;
349 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
350 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
356 * Setup the prefix information to pass in
358 lua_setup_prefix_table(L
, prefix
);
360 zlog_debug("Set up prefix table");
362 * Setup the bgp_path_info information
365 lua_pushinteger(L
, path
->attr
->med
);
366 lua_setfield(L
, -2, "metric");
367 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
368 lua_setfield(L
, -2, "ifindex");
369 lua_pushstring(L
, path
->attr
->aspath
->str
);
370 lua_setfield(L
, -2, "aspath");
371 lua_pushinteger(L
, path
->attr
->local_pref
);
372 lua_setfield(L
, -2, "localpref");
373 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
374 lua_setglobal(L
, "nexthop");
376 zlog_debug("Set up nexthop information");
380 lrm_status
= lua_run_rm_rule(L
, rule
);
381 switch (lrm_status
) {
383 zlog_debug("RM_FAILURE");
386 zlog_debug("RM_NOMATCH");
388 case LUA_RM_MATCH_AND_CHANGE
:
389 zlog_debug("MATCH AND CHANGE");
390 lua_getglobal(L
, "nexthop");
391 path
->attr
->med
= get_integer(L
, "metric");
393 * This needs to be abstraced with the set function
395 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
396 locpref
= path
->attr
->local_pref
;
397 newlocpref
= get_integer(L
, "localpref");
398 if (newlocpref
!= locpref
) {
399 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
400 path
->attr
->local_pref
= newlocpref
;
405 zlog_debug("MATCH ONLY");
413 static void *route_match_command_compile(const char *arg
)
417 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
422 route_match_command_free(void *rule
)
424 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
427 struct route_map_rule_cmd route_match_command_cmd
= {
430 route_match_command_compile
,
431 route_match_command_free
435 /* `match ip address IP_ACCESS_LIST' */
437 /* Match function should return 1 if match is success else return
439 static enum route_map_cmd_result_t
440 route_match_ip_address(void *rule
, const struct prefix
*prefix
,
441 route_map_object_t type
, void *object
)
443 struct access_list
*alist
;
445 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
446 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
450 return (access_list_apply(alist
, prefix
) == FILTER_DENY
457 /* Route map `ip address' match statement. `arg' should be
459 static void *route_match_ip_address_compile(const char *arg
)
461 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
464 /* Free route map's compiled `ip address' value. */
465 static void route_match_ip_address_free(void *rule
)
467 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
470 /* Route map commands for ip address matching. */
471 struct route_map_rule_cmd route_match_ip_address_cmd
= {
472 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
473 route_match_ip_address_free
};
475 /* `match ip next-hop IP_ADDRESS' */
477 /* Match function return 1 if match is success else return zero. */
478 static enum route_map_cmd_result_t
479 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
,
480 route_map_object_t type
, void *object
)
482 struct access_list
*alist
;
483 struct bgp_path_info
*path
;
484 struct prefix_ipv4 p
;
486 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
489 p
.prefix
= path
->attr
->nexthop
;
490 p
.prefixlen
= IPV4_MAX_BITLEN
;
492 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
496 return (access_list_apply(alist
, &p
) == FILTER_DENY
503 /* Route map `ip next-hop' match statement. `arg' is
505 static void *route_match_ip_next_hop_compile(const char *arg
)
507 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
510 /* Free route map's compiled `ip address' value. */
511 static void route_match_ip_next_hop_free(void *rule
)
513 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
516 /* Route map commands for ip next-hop matching. */
517 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
518 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
519 route_match_ip_next_hop_free
};
521 /* `match ip route-source ACCESS-LIST' */
523 /* Match function return 1 if match is success else return zero. */
524 static enum route_map_cmd_result_t
525 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
,
526 route_map_object_t type
, void *object
)
528 struct access_list
*alist
;
529 struct bgp_path_info
*path
;
531 struct prefix_ipv4 p
;
533 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
537 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
541 p
.prefix
= peer
->su
.sin
.sin_addr
;
542 p
.prefixlen
= IPV4_MAX_BITLEN
;
544 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
548 return (access_list_apply(alist
, &p
) == FILTER_DENY
555 /* Route map `ip route-source' match statement. `arg' is
557 static void *route_match_ip_route_source_compile(const char *arg
)
559 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
562 /* Free route map's compiled `ip address' value. */
563 static void route_match_ip_route_source_free(void *rule
)
565 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
568 /* Route map commands for ip route-source matching. */
569 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
570 "ip route-source", route_match_ip_route_source
,
571 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
573 static enum route_map_cmd_result_t
574 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
575 const struct prefix
*p
)
578 struct bgp_pbr_entry_main api
;
580 memset(&api
, 0, sizeof(api
));
582 /* extract match from flowspec entries */
583 ret
= bgp_flowspec_match_rules_fill(
584 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
585 p
->u
.prefix_flowspec
.prefixlen
, &api
);
588 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
589 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
590 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
592 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
595 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
596 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
597 if (family2afi((&api
.src_prefix
)->family
) != afi
)
599 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
606 static enum route_map_cmd_result_t
607 route_match_address_prefix_list(void *rule
, afi_t afi
,
608 const struct prefix
*prefix
,
609 route_map_object_t type
, void *object
)
611 struct prefix_list
*plist
;
613 if (type
!= RMAP_BGP
)
616 plist
= prefix_list_lookup(afi
, (char *)rule
);
620 if (prefix
->family
== AF_FLOWSPEC
)
621 return route_match_prefix_list_flowspec(afi
, plist
,
623 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
627 static enum route_map_cmd_result_t
628 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
629 route_map_object_t type
, void *object
)
631 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, type
,
635 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
637 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
640 static void route_match_ip_address_prefix_list_free(void *rule
)
642 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
645 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
646 "ip address prefix-list", route_match_ip_address_prefix_list
,
647 route_match_ip_address_prefix_list_compile
,
648 route_match_ip_address_prefix_list_free
};
650 /* `match ip next-hop prefix-list PREFIX_LIST' */
652 static enum route_map_cmd_result_t
653 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
654 route_map_object_t type
, void *object
)
656 struct prefix_list
*plist
;
657 struct bgp_path_info
*path
;
658 struct prefix_ipv4 p
;
660 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
663 p
.prefix
= path
->attr
->nexthop
;
664 p
.prefixlen
= IPV4_MAX_BITLEN
;
666 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
670 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
677 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
679 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
682 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
684 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
687 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
688 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
689 route_match_ip_next_hop_prefix_list_compile
,
690 route_match_ip_next_hop_prefix_list_free
};
692 /* `match ip next-hop type <blackhole>' */
694 static enum route_map_cmd_result_t
695 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
696 route_map_object_t type
, void *object
)
698 struct bgp_path_info
*path
;
700 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
701 path
= (struct bgp_path_info
*)object
;
702 if (!path
|| !path
->attr
)
705 /* If nexthop interface's index can't be resolved and nexthop is
706 set to any address then mark it as type `blackhole`.
707 This logic works for matching kernel/static routes like:
708 `ip route add blackhole 10.0.0.1`. */
709 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
710 && !path
->attr
->nh_ifindex
)
716 static void *route_match_ip_next_hop_type_compile(const char *arg
)
718 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
721 static void route_match_ip_next_hop_type_free(void *rule
)
723 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
726 static struct route_map_rule_cmd route_match_ip_next_hop_type_cmd
= {
727 "ip next-hop type", route_match_ip_next_hop_type
,
728 route_match_ip_next_hop_type_compile
,
729 route_match_ip_next_hop_type_free
};
731 /* `match ip route-source prefix-list PREFIX_LIST' */
733 static enum route_map_cmd_result_t
734 route_match_ip_route_source_prefix_list(void *rule
,
735 const struct prefix
*prefix
,
736 route_map_object_t type
, void *object
)
738 struct prefix_list
*plist
;
739 struct bgp_path_info
*path
;
741 struct prefix_ipv4 p
;
743 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
747 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
751 p
.prefix
= peer
->su
.sin
.sin_addr
;
752 p
.prefixlen
= IPV4_MAX_BITLEN
;
754 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
758 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
765 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
767 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
770 static void route_match_ip_route_source_prefix_list_free(void *rule
)
772 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
775 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
776 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
777 route_match_ip_route_source_prefix_list_compile
,
778 route_match_ip_route_source_prefix_list_free
};
780 /* `match evpn default-route' */
782 /* Match function should return 1 if match is success else 0 */
783 static enum route_map_cmd_result_t
784 route_match_evpn_default_route(void *rule
, const struct prefix
*p
,
785 route_map_object_t type
, void *object
)
787 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
793 /* Route map commands for default-route matching. */
794 struct route_map_rule_cmd route_match_evpn_default_route_cmd
= {
795 "evpn default-route", route_match_evpn_default_route
, NULL
, NULL
};
797 /* `match mac address MAC_ACCESS_LIST' */
799 /* Match function should return 1 if match is success else return
801 static enum route_map_cmd_result_t
802 route_match_mac_address(void *rule
, const struct prefix
*prefix
,
803 route_map_object_t type
, void *object
)
805 struct access_list
*alist
;
808 if (type
== RMAP_BGP
) {
809 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
813 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
816 p
.family
= AF_ETHERNET
;
817 p
.prefixlen
= ETH_ALEN
* 8;
818 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
820 return (access_list_apply(alist
, &p
) == FILTER_DENY
828 /* Route map `mac address' match statement. `arg' should be
830 static void *route_match_mac_address_compile(const char *arg
)
832 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
835 /* Free route map's compiled `ip address' value. */
836 static void route_match_mac_address_free(void *rule
)
838 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
841 /* Route map commands for mac address matching. */
842 struct route_map_rule_cmd route_match_mac_address_cmd
= {
843 "mac address", route_match_mac_address
, route_match_mac_address_compile
,
844 route_match_mac_address_free
};
847 * Match function returns:
848 * ...RMAP_MATCH if match is found.
849 * ...RMAP_NOMATCH if match is not found.
850 * ...RMAP_NOOP to ignore this match check.
852 static enum route_map_cmd_result_t
853 route_match_vni(void *rule
, const struct prefix
*prefix
,
854 route_map_object_t type
, void *object
)
857 unsigned int label_cnt
= 0;
858 struct bgp_path_info
*path
= NULL
;
859 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
861 if (type
== RMAP_BGP
) {
862 vni
= *((vni_t
*)rule
);
863 path
= (struct bgp_path_info
*)object
;
866 * This rmap filter is valid for vxlan tunnel type only.
867 * For any other tunnel type, return noop to ignore
870 if (path
->attr
&& path
->attr
->encap_tunneltype
!=
871 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
);
1213 /* Route map commands for community matching. */
1214 struct route_map_rule_cmd route_match_community_cmd
= {
1215 "community", route_match_community
, route_match_community_compile
,
1216 route_match_community_free
};
1218 /* Match function for lcommunity match. */
1219 static enum route_map_cmd_result_t
1220 route_match_lcommunity(void *rule
, const struct prefix
*prefix
,
1221 route_map_object_t type
, void *object
)
1223 struct community_list
*list
;
1224 struct bgp_path_info
*path
;
1225 struct rmap_community
*rcom
= rule
;
1227 if (type
== RMAP_BGP
) {
1230 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1232 LARGE_COMMUNITY_LIST_MASTER
);
1234 return RMAP_NOMATCH
;
1237 if (lcommunity_list_exact_match(
1238 path
->attr
->lcommunity
,
1242 if (lcommunity_list_match(
1243 path
->attr
->lcommunity
,
1248 return RMAP_NOMATCH
;
1251 /* Compile function for community match. */
1252 static void *route_match_lcommunity_compile(const char *arg
)
1254 struct rmap_community
*rcom
;
1258 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1260 p
= strchr(arg
, ' ');
1263 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1264 memcpy(rcom
->name
, arg
, len
);
1267 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1271 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1275 /* Compile function for community match. */
1276 static void route_match_lcommunity_free(void *rule
)
1278 struct rmap_community
*rcom
= rule
;
1280 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1281 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1284 /* Route map commands for community matching. */
1285 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1286 "large-community", route_match_lcommunity
,
1287 route_match_lcommunity_compile
, route_match_lcommunity_free
};
1290 /* Match function for extcommunity match. */
1291 static enum route_map_cmd_result_t
1292 route_match_ecommunity(void *rule
, const struct prefix
*prefix
,
1293 route_map_object_t type
, void *object
)
1295 struct community_list
*list
;
1296 struct bgp_path_info
*path
;
1297 struct rmap_community
*rcom
= rule
;
1299 if (type
== RMAP_BGP
) {
1302 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1304 EXTCOMMUNITY_LIST_MASTER
);
1306 return RMAP_NOMATCH
;
1308 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1311 return RMAP_NOMATCH
;
1314 /* Compile function for extcommunity match. */
1315 static void *route_match_ecommunity_compile(const char *arg
)
1317 struct rmap_community
*rcom
;
1319 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1320 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1321 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1326 /* Compile function for extcommunity match. */
1327 static void route_match_ecommunity_free(void *rule
)
1329 struct rmap_community
*rcom
= rule
;
1331 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1332 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1335 /* Route map commands for community matching. */
1336 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1337 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1338 route_match_ecommunity_free
};
1340 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1341 and `address-family vpnv4'. */
1343 /* `match origin' */
1344 static enum route_map_cmd_result_t
1345 route_match_origin(void *rule
, const struct prefix
*prefix
,
1346 route_map_object_t type
, void *object
)
1349 struct bgp_path_info
*path
;
1351 if (type
== RMAP_BGP
) {
1355 if (path
->attr
->origin
== *origin
)
1359 return RMAP_NOMATCH
;
1362 static void *route_match_origin_compile(const char *arg
)
1366 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1368 if (strcmp(arg
, "igp") == 0)
1370 else if (strcmp(arg
, "egp") == 0)
1378 /* Free route map's compiled `ip address' value. */
1379 static void route_match_origin_free(void *rule
)
1381 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1384 /* Route map commands for origin matching. */
1385 struct route_map_rule_cmd route_match_origin_cmd
= {
1386 "origin", route_match_origin
, route_match_origin_compile
,
1387 route_match_origin_free
};
1389 /* match probability { */
1391 static enum route_map_cmd_result_t
1392 route_match_probability(void *rule
, const struct prefix
*prefix
,
1393 route_map_object_t type
, void *object
)
1397 switch (*(long *)rule
) {
1403 if (r
< *(long *)rule
) {
1408 return RMAP_NOMATCH
;
1411 static void *route_match_probability_compile(const char *arg
)
1417 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1427 *lobule
= RAND_MAX
/ 100 * perc
;
1433 static void route_match_probability_free(void *rule
)
1435 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1438 struct route_map_rule_cmd route_match_probability_cmd
= {
1439 "probability", route_match_probability
, route_match_probability_compile
,
1440 route_match_probability_free
};
1442 /* `match interface IFNAME' */
1443 /* Match function should return 1 if match is success else return
1445 static enum route_map_cmd_result_t
1446 route_match_interface(void *rule
, const struct prefix
*prefix
,
1447 route_map_object_t type
, void *object
)
1449 struct interface
*ifp
;
1450 struct bgp_path_info
*path
;
1452 if (type
== RMAP_BGP
) {
1455 if (!path
|| !path
->attr
)
1456 return RMAP_NOMATCH
;
1458 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1460 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1461 return RMAP_NOMATCH
;
1465 return RMAP_NOMATCH
;
1468 /* Route map `interface' match statement. `arg' should be
1470 static void *route_match_interface_compile(const char *arg
)
1472 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1475 /* Free route map's compiled `interface' value. */
1476 static void route_match_interface_free(void *rule
)
1478 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1481 /* Route map commands for ip address matching. */
1482 struct route_map_rule_cmd route_match_interface_cmd
= {
1483 "interface", route_match_interface
, route_match_interface_compile
,
1484 route_match_interface_free
};
1488 /* `set ip next-hop IP_ADDRESS' */
1490 /* Match function return 1 if match is success else return zero. */
1491 static enum route_map_cmd_result_t
1492 route_match_tag(void *rule
, const struct prefix
*prefix
,
1493 route_map_object_t type
, void *object
)
1496 struct bgp_path_info
*path
;
1498 if (type
== RMAP_BGP
) {
1502 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1505 return RMAP_NOMATCH
;
1509 /* Route map commands for tag matching. */
1510 static struct route_map_rule_cmd route_match_tag_cmd
= {
1511 "tag", route_match_tag
, route_map_rule_tag_compile
,
1512 route_map_rule_tag_free
,
1516 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1517 struct rmap_ip_nexthop_set
{
1518 struct in_addr
*address
;
1523 static enum route_map_cmd_result_t
1524 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
,
1525 route_map_object_t type
, void *object
)
1527 struct rmap_ip_nexthop_set
*rins
= rule
;
1528 struct bgp_path_info
*path
;
1531 if (type
!= RMAP_BGP
)
1534 if (prefix
->family
== AF_INET6
)
1540 if (rins
->unchanged
) {
1541 SET_FLAG(path
->attr
->rmap_change_flags
,
1542 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1543 } else if (rins
->peer_address
) {
1544 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1545 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1547 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1548 path
->attr
->nexthop
.s_addr
=
1549 sockunion2ip(peer
->su_remote
);
1550 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1551 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1552 /* The next hop value will be set as part of
1553 * packet rewrite. Set the flags here to indicate
1554 * that rewrite needs to be done.
1555 * Also, clear the value.
1557 SET_FLAG(path
->attr
->rmap_change_flags
,
1558 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1559 path
->attr
->nexthop
.s_addr
= 0;
1562 /* Set next hop value. */
1563 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1564 path
->attr
->nexthop
= *rins
->address
;
1565 SET_FLAG(path
->attr
->rmap_change_flags
,
1566 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1567 /* case for MP-BGP : MPLS VPN */
1568 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1569 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1575 /* Route map `ip nexthop' compile function. Given string is converted
1576 to struct in_addr structure. */
1577 static void *route_set_ip_nexthop_compile(const char *arg
)
1579 struct rmap_ip_nexthop_set
*rins
;
1580 struct in_addr
*address
= NULL
;
1581 int peer_address
= 0;
1585 if (strcmp(arg
, "peer-address") == 0)
1587 else if (strcmp(arg
, "unchanged") == 0)
1590 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1591 sizeof(struct in_addr
));
1592 ret
= inet_aton(arg
, address
);
1595 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1600 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1601 sizeof(struct rmap_ip_nexthop_set
));
1603 rins
->address
= address
;
1604 rins
->peer_address
= peer_address
;
1605 rins
->unchanged
= unchanged
;
1610 /* Free route map's compiled `ip nexthop' value. */
1611 static void route_set_ip_nexthop_free(void *rule
)
1613 struct rmap_ip_nexthop_set
*rins
= rule
;
1615 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1617 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1620 /* Route map commands for ip nexthop set. */
1621 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1622 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1623 route_set_ip_nexthop_free
};
1625 /* `set local-preference LOCAL_PREF' */
1627 /* Set local preference. */
1628 static enum route_map_cmd_result_t
1629 route_set_local_pref(void *rule
, const struct prefix
*prefix
,
1630 route_map_object_t type
, void *object
)
1632 struct rmap_value
*rv
;
1633 struct bgp_path_info
*path
;
1634 uint32_t locpref
= 0;
1636 if (type
== RMAP_BGP
) {
1637 /* Fetch routemap's rule information. */
1641 /* Set local preference value. */
1642 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1643 locpref
= path
->attr
->local_pref
;
1645 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1646 path
->attr
->local_pref
=
1647 route_value_adjust(rv
, locpref
, path
->peer
);
1653 /* Set local preference rule structure. */
1654 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1655 "local-preference", route_set_local_pref
, route_value_compile
,
1659 /* `set weight WEIGHT' */
1662 static enum route_map_cmd_result_t
1663 route_set_weight(void *rule
, const struct prefix
*prefix
,
1664 route_map_object_t type
, void *object
)
1666 struct rmap_value
*rv
;
1667 struct bgp_path_info
*path
;
1669 if (type
== RMAP_BGP
) {
1670 /* Fetch routemap's rule information. */
1674 /* Set weight value. */
1675 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1681 /* Set local preference rule structure. */
1682 struct route_map_rule_cmd route_set_weight_cmd
= {
1683 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1686 /* `set metric METRIC' */
1688 /* Set metric to attribute. */
1689 static enum route_map_cmd_result_t
1690 route_set_metric(void *rule
, const struct prefix
*prefix
,
1691 route_map_object_t type
, void *object
)
1693 struct rmap_value
*rv
;
1694 struct bgp_path_info
*path
;
1697 if (type
== RMAP_BGP
) {
1698 /* Fetch routemap's rule information. */
1702 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1703 med
= path
->attr
->med
;
1705 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1706 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1711 /* Set metric rule structure. */
1712 struct route_map_rule_cmd route_set_metric_cmd
= {
1713 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1716 /* `set as-path prepend ASPATH' */
1718 /* For AS path prepend mechanism. */
1719 static enum route_map_cmd_result_t
1720 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
,
1721 route_map_object_t type
, void *object
)
1723 struct aspath
*aspath
;
1725 struct bgp_path_info
*path
;
1727 if (type
== RMAP_BGP
) {
1730 if (path
->attr
->aspath
->refcnt
)
1731 new = aspath_dup(path
->attr
->aspath
);
1733 new = path
->attr
->aspath
;
1735 if ((uintptr_t)rule
> 10) {
1737 aspath_prepend(aspath
, new);
1739 as_t as
= aspath_leftmost(new);
1741 as
= path
->peer
->as
;
1742 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1745 path
->attr
->aspath
= new;
1751 static void *route_set_aspath_prepend_compile(const char *arg
)
1755 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1756 return (void *)(uintptr_t)num
;
1758 return route_aspath_compile(arg
);
1761 static void route_set_aspath_prepend_free(void *rule
)
1763 if ((uintptr_t)rule
> 10)
1764 route_aspath_free(rule
);
1768 /* Set as-path prepend rule structure. */
1769 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1770 "as-path prepend", route_set_aspath_prepend
,
1771 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1774 /* `set as-path exclude ASn' */
1776 /* For ASN exclude mechanism.
1777 * Iterate over ASns requested and filter them from the given AS_PATH one by
1779 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1781 static enum route_map_cmd_result_t
1782 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
,
1783 route_map_object_t type
, void *object
)
1785 struct aspath
*new_path
, *exclude_path
;
1786 struct bgp_path_info
*path
;
1788 if (type
== RMAP_BGP
) {
1789 exclude_path
= rule
;
1791 if (path
->attr
->aspath
->refcnt
)
1792 new_path
= aspath_dup(path
->attr
->aspath
);
1794 new_path
= path
->attr
->aspath
;
1795 path
->attr
->aspath
=
1796 aspath_filter_exclude(new_path
, exclude_path
);
1801 /* Set ASn exlude rule structure. */
1802 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1803 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1807 /* `set community COMMUNITY' */
1808 struct rmap_com_set
{
1809 struct community
*com
;
1814 /* For community set mechanism. */
1815 static enum route_map_cmd_result_t
1816 route_set_community(void *rule
, const struct prefix
*prefix
,
1817 route_map_object_t type
, void *object
)
1819 struct rmap_com_set
*rcs
;
1820 struct bgp_path_info
*path
;
1822 struct community
*new = NULL
;
1823 struct community
*old
;
1824 struct community
*merge
;
1826 if (type
== RMAP_BGP
) {
1830 old
= attr
->community
;
1834 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1835 attr
->community
= NULL
;
1836 /* See the longer comment down below. */
1837 if (old
&& old
->refcnt
== 0)
1838 community_free(&old
);
1842 /* "additive" case. */
1843 if (rcs
->additive
&& old
) {
1844 merge
= community_merge(community_dup(old
), rcs
->com
);
1846 new = community_uniq_sort(merge
);
1847 community_free(&merge
);
1849 new = community_dup(rcs
->com
);
1851 /* HACK: if the old community is not intern'd,
1852 * we should free it here, or all reference to it may be
1854 * Really need to cleanup attribute caching sometime.
1856 if (old
&& old
->refcnt
== 0)
1857 community_free(&old
);
1859 /* will be interned by caller if required */
1860 attr
->community
= new;
1862 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1868 /* Compile function for set community. */
1869 static void *route_set_community_compile(const char *arg
)
1871 struct rmap_com_set
*rcs
;
1872 struct community
*com
= NULL
;
1877 if (strcmp(arg
, "none") == 0)
1880 sp
= strstr(arg
, "additive");
1882 if (sp
&& sp
> arg
) {
1883 /* "additive" keyword is included. */
1888 com
= community_str2com(arg
);
1897 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1899 rcs
->additive
= additive
;
1905 /* Free function for set community. */
1906 static void route_set_community_free(void *rule
)
1908 struct rmap_com_set
*rcs
= rule
;
1911 community_free(&rcs
->com
);
1912 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1915 /* Set community rule structure. */
1916 struct route_map_rule_cmd route_set_community_cmd
= {
1917 "community", route_set_community
, route_set_community_compile
,
1918 route_set_community_free
,
1921 /* `set community COMMUNITY' */
1922 struct rmap_lcom_set
{
1923 struct lcommunity
*lcom
;
1929 /* For lcommunity set mechanism. */
1930 static enum route_map_cmd_result_t
1931 route_set_lcommunity(void *rule
, const struct prefix
*prefix
,
1932 route_map_object_t type
, void *object
)
1934 struct rmap_lcom_set
*rcs
;
1935 struct bgp_path_info
*path
;
1937 struct lcommunity
*new = NULL
;
1938 struct lcommunity
*old
;
1939 struct lcommunity
*merge
;
1941 if (type
== RMAP_BGP
) {
1945 old
= attr
->lcommunity
;
1950 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
1951 attr
->lcommunity
= NULL
;
1953 /* See the longer comment down below. */
1954 if (old
&& old
->refcnt
== 0)
1955 lcommunity_free(&old
);
1959 if (rcs
->additive
&& old
) {
1960 merge
= lcommunity_merge(lcommunity_dup(old
),
1963 new = lcommunity_uniq_sort(merge
);
1964 lcommunity_free(&merge
);
1966 new = lcommunity_dup(rcs
->lcom
);
1968 /* HACK: if the old large-community is not intern'd,
1969 * we should free it here, or all reference to it may be
1971 * Really need to cleanup attribute caching sometime.
1973 if (old
&& old
->refcnt
== 0)
1974 lcommunity_free(&old
);
1976 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1977 attr
->lcommunity
= new;
1979 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
1985 /* Compile function for set community. */
1986 static void *route_set_lcommunity_compile(const char *arg
)
1988 struct rmap_lcom_set
*rcs
;
1989 struct lcommunity
*lcom
= NULL
;
1994 if (strcmp(arg
, "none") == 0)
1997 sp
= strstr(arg
, "additive");
1999 if (sp
&& sp
> arg
) {
2000 /* "additive" keyworkd is included. */
2005 lcom
= lcommunity_str2com(arg
);
2014 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2016 rcs
->additive
= additive
;
2022 /* Free function for set lcommunity. */
2023 static void route_set_lcommunity_free(void *rule
)
2025 struct rmap_lcom_set
*rcs
= rule
;
2028 lcommunity_free(&rcs
->lcom
);
2030 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2033 /* Set community rule structure. */
2034 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2035 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
2036 route_set_lcommunity_free
,
2039 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2041 /* For large community set mechanism. */
2042 static enum route_map_cmd_result_t
2043 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
,
2044 route_map_object_t type
, void *object
)
2046 struct community_list
*list
;
2047 struct lcommunity
*merge
;
2048 struct lcommunity
*new;
2049 struct lcommunity
*old
;
2050 struct bgp_path_info
*path
;
2051 struct rmap_community
*rcom
= rule
;
2053 if (type
== RMAP_BGP
) {
2058 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2060 LARGE_COMMUNITY_LIST_MASTER
);
2061 old
= path
->attr
->lcommunity
;
2064 merge
= lcommunity_list_match_delete(
2065 lcommunity_dup(old
), list
);
2066 new = lcommunity_uniq_sort(merge
);
2067 lcommunity_free(&merge
);
2069 /* HACK: if the old community is not intern'd,
2070 * we should free it here, or all reference to it may be
2072 * Really need to cleanup attribute caching sometime.
2074 if (old
->refcnt
== 0)
2075 lcommunity_free(&old
);
2077 if (new->size
== 0) {
2078 path
->attr
->lcommunity
= NULL
;
2079 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2080 BGP_ATTR_LARGE_COMMUNITIES
);
2081 lcommunity_free(&new);
2083 path
->attr
->lcommunity
= new;
2084 path
->attr
->flag
|= ATTR_FLAG_BIT(
2085 BGP_ATTR_LARGE_COMMUNITIES
);
2093 /* Compile function for set lcommunity. */
2094 static void *route_set_lcommunity_delete_compile(const char *arg
)
2096 struct rmap_community
*rcom
;
2100 frrstr_split(arg
, " ", &splits
, &num
);
2102 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2103 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2104 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2106 for (int i
= 0; i
< num
; i
++)
2107 XFREE(MTYPE_TMP
, splits
[i
]);
2108 XFREE(MTYPE_TMP
, splits
);
2113 /* Free function for set lcommunity. */
2114 static void route_set_lcommunity_delete_free(void *rule
)
2116 struct rmap_community
*rcom
= rule
;
2118 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2119 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2122 /* Set lcommunity rule structure. */
2123 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2124 "large-comm-list", route_set_lcommunity_delete
,
2125 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2129 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2131 /* For community set mechanism. */
2132 static enum route_map_cmd_result_t
2133 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2134 route_map_object_t type
, void *object
)
2136 struct community_list
*list
;
2137 struct community
*merge
;
2138 struct community
*new;
2139 struct community
*old
;
2140 struct bgp_path_info
*path
;
2141 struct rmap_community
*rcom
= rule
;
2143 if (type
== RMAP_BGP
) {
2148 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2150 COMMUNITY_LIST_MASTER
);
2151 old
= path
->attr
->community
;
2154 merge
= community_list_match_delete(community_dup(old
),
2156 new = community_uniq_sort(merge
);
2157 community_free(&merge
);
2159 /* HACK: if the old community is not intern'd,
2160 * we should free it here, or all reference to it may be
2162 * Really need to cleanup attribute caching sometime.
2164 if (old
->refcnt
== 0)
2165 community_free(&old
);
2167 if (new->size
== 0) {
2168 path
->attr
->community
= NULL
;
2170 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2171 community_free(&new);
2173 path
->attr
->community
= new;
2175 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2183 /* Compile function for set community. */
2184 static void *route_set_community_delete_compile(const char *arg
)
2186 struct rmap_community
*rcom
;
2190 frrstr_split(arg
, " ", &splits
, &num
);
2192 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2193 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2194 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2196 for (int i
= 0; i
< num
; i
++)
2197 XFREE(MTYPE_TMP
, splits
[i
]);
2198 XFREE(MTYPE_TMP
, splits
);
2203 /* Free function for set community. */
2204 static void route_set_community_delete_free(void *rule
)
2206 struct rmap_community
*rcom
= rule
;
2208 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2209 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2212 /* Set community rule structure. */
2213 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2214 "comm-list", route_set_community_delete
,
2215 route_set_community_delete_compile
, route_set_community_delete_free
,
2218 /* `set extcommunity rt COMMUNITY' */
2220 /* For community set mechanism. Used by _rt and _soo. */
2221 static enum route_map_cmd_result_t
2222 route_set_ecommunity(void *rule
, const struct prefix
*prefix
,
2223 route_map_object_t type
, void *object
)
2225 struct ecommunity
*ecom
;
2226 struct ecommunity
*new_ecom
;
2227 struct ecommunity
*old_ecom
;
2228 struct bgp_path_info
*path
;
2230 if (type
== RMAP_BGP
) {
2237 /* We assume additive for Extended Community. */
2238 old_ecom
= path
->attr
->ecommunity
;
2241 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2244 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2245 * bgp_update_receive()
2246 * ->refcnt = 0 => set by a previous route-map
2248 if (!old_ecom
->refcnt
)
2249 ecommunity_free(&old_ecom
);
2251 new_ecom
= ecommunity_dup(ecom
);
2253 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2254 path
->attr
->ecommunity
= new_ecom
;
2256 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2261 /* Compile function for set community. */
2262 static void *route_set_ecommunity_rt_compile(const char *arg
)
2264 struct ecommunity
*ecom
;
2266 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2269 return ecommunity_intern(ecom
);
2272 /* Free function for set community. Used by _rt and _soo */
2273 static void route_set_ecommunity_free(void *rule
)
2275 struct ecommunity
*ecom
= rule
;
2276 ecommunity_unintern(&ecom
);
2279 /* Set community rule structure. */
2280 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2281 "extcommunity rt", route_set_ecommunity
,
2282 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2285 /* `set extcommunity soo COMMUNITY' */
2287 /* Compile function for set community. */
2288 static void *route_set_ecommunity_soo_compile(const char *arg
)
2290 struct ecommunity
*ecom
;
2292 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2296 return ecommunity_intern(ecom
);
2299 /* Set community rule structure. */
2300 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2301 "extcommunity soo", route_set_ecommunity
,
2302 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2305 /* `set origin ORIGIN' */
2307 /* For origin set. */
2308 static enum route_map_cmd_result_t
2309 route_set_origin(void *rule
, const struct prefix
*prefix
,
2310 route_map_object_t type
, void *object
)
2313 struct bgp_path_info
*path
;
2315 if (type
== RMAP_BGP
) {
2319 path
->attr
->origin
= *origin
;
2325 /* Compile function for origin set. */
2326 static void *route_set_origin_compile(const char *arg
)
2330 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2332 if (strcmp(arg
, "igp") == 0)
2334 else if (strcmp(arg
, "egp") == 0)
2342 /* Compile function for origin set. */
2343 static void route_set_origin_free(void *rule
)
2345 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2348 /* Set origin rule structure. */
2349 struct route_map_rule_cmd route_set_origin_cmd
= {
2350 "origin", route_set_origin
, route_set_origin_compile
,
2351 route_set_origin_free
,
2354 /* `set atomic-aggregate' */
2356 /* For atomic aggregate set. */
2357 static enum route_map_cmd_result_t
2358 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
,
2359 route_map_object_t type
, void *object
)
2361 struct bgp_path_info
*path
;
2363 if (type
== RMAP_BGP
) {
2365 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2371 /* Compile function for atomic aggregate. */
2372 static void *route_set_atomic_aggregate_compile(const char *arg
)
2377 /* Compile function for atomic aggregate. */
2378 static void route_set_atomic_aggregate_free(void *rule
)
2383 /* Set atomic aggregate rule structure. */
2384 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2385 "atomic-aggregate", route_set_atomic_aggregate
,
2386 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2389 /* `set aggregator as AS A.B.C.D' */
2392 struct in_addr address
;
2395 static enum route_map_cmd_result_t
2396 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
,
2397 route_map_object_t type
, void *object
)
2399 struct bgp_path_info
*path
;
2400 struct aggregator
*aggregator
;
2402 if (type
== RMAP_BGP
) {
2406 path
->attr
->aggregator_as
= aggregator
->as
;
2407 path
->attr
->aggregator_addr
= aggregator
->address
;
2408 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2414 static void *route_set_aggregator_as_compile(const char *arg
)
2416 struct aggregator
*aggregator
;
2422 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2423 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2424 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2428 aggregator
->as
= strtoul(as
, NULL
, 10);
2429 ret
= inet_aton(address
, &aggregator
->address
);
2431 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2437 static void route_set_aggregator_as_free(void *rule
)
2439 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2442 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2443 "aggregator as", route_set_aggregator_as
,
2444 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2447 /* Set tag to object. object must be pointer to struct bgp_path_info */
2448 static enum route_map_cmd_result_t
2449 route_set_tag(void *rule
, const struct prefix
*prefix
,
2450 route_map_object_t type
, void *object
)
2453 struct bgp_path_info
*path
;
2455 if (type
== RMAP_BGP
) {
2460 path
->attr
->tag
= *tag
;
2466 /* Route map commands for tag set. */
2467 static struct route_map_rule_cmd route_set_tag_cmd
= {
2468 "tag", route_set_tag
, route_map_rule_tag_compile
,
2469 route_map_rule_tag_free
,
2472 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2473 static enum route_map_cmd_result_t
2474 route_set_label_index(void *rule
, const struct prefix
*prefix
,
2475 route_map_object_t type
, void *object
)
2477 struct rmap_value
*rv
;
2478 struct bgp_path_info
*path
;
2479 uint32_t label_index
;
2481 if (type
== RMAP_BGP
) {
2482 /* Fetch routemap's rule information. */
2486 /* Set label-index value. */
2487 label_index
= rv
->value
;
2489 path
->attr
->label_index
= label_index
;
2490 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2497 /* Route map commands for label-index set. */
2498 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2499 "label-index", route_set_label_index
, route_value_compile
,
2503 /* `match ipv6 address IP_ACCESS_LIST' */
2505 static enum route_map_cmd_result_t
2506 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
,
2507 route_map_object_t type
, void *object
)
2509 struct access_list
*alist
;
2511 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2512 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2514 return RMAP_NOMATCH
;
2516 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2520 return RMAP_NOMATCH
;
2523 static void *route_match_ipv6_address_compile(const char *arg
)
2525 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2528 static void route_match_ipv6_address_free(void *rule
)
2530 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2533 /* Route map commands for ip address matching. */
2534 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2535 "ipv6 address", route_match_ipv6_address
,
2536 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2538 /* `match ipv6 next-hop IP_ADDRESS' */
2540 static enum route_map_cmd_result_t
2541 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
,
2542 route_map_object_t type
, void *object
)
2544 struct in6_addr
*addr
= rule
;
2545 struct bgp_path_info
*path
;
2547 if (type
== RMAP_BGP
) {
2550 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2553 if (path
->attr
->mp_nexthop_len
2554 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2555 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2558 return RMAP_NOMATCH
;
2561 return RMAP_NOMATCH
;
2564 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2566 struct in6_addr
*address
;
2569 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2571 ret
= inet_pton(AF_INET6
, arg
, address
);
2573 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2580 static void route_match_ipv6_next_hop_free(void *rule
)
2582 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2585 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2586 "ipv6 next-hop", route_match_ipv6_next_hop
,
2587 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2589 /* `match ipv6 address prefix-list PREFIX_LIST' */
2591 static enum route_map_cmd_result_t
2592 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2593 route_map_object_t type
, void *object
)
2595 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, type
,
2599 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2601 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2604 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2606 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2609 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2610 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2611 route_match_ipv6_address_prefix_list_compile
,
2612 route_match_ipv6_address_prefix_list_free
};
2614 /* `match ipv6 next-hop type <TYPE>' */
2616 static enum route_map_cmd_result_t
2617 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2618 route_map_object_t type
, void *object
)
2620 struct bgp_path_info
*path
;
2621 struct in6_addr
*addr
= rule
;
2623 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2624 path
= (struct bgp_path_info
*)object
;
2625 if (!path
|| !path
->attr
)
2626 return RMAP_NOMATCH
;
2628 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2629 && !path
->attr
->nh_ifindex
)
2632 return RMAP_NOMATCH
;
2635 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2637 struct in6_addr
*address
;
2640 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2642 ret
= inet_pton(AF_INET6
, "::0", address
);
2644 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2651 static void route_match_ipv6_next_hop_type_free(void *rule
)
2653 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2656 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2657 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2658 route_match_ipv6_next_hop_type_compile
,
2659 route_match_ipv6_next_hop_type_free
};
2661 /* `set ipv6 nexthop global IP_ADDRESS' */
2663 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2664 static enum route_map_cmd_result_t
2665 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
,
2666 route_map_object_t type
, void *object
)
2668 struct in6_addr
*address
;
2669 struct bgp_path_info
*path
;
2671 if (type
== RMAP_BGP
) {
2672 /* Fetch routemap's rule information. */
2676 /* Set next hop value. */
2677 path
->attr
->mp_nexthop_global
= *address
;
2679 /* Set nexthop length. */
2680 if (path
->attr
->mp_nexthop_len
== 0)
2681 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2683 SET_FLAG(path
->attr
->rmap_change_flags
,
2684 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2690 /* Route map `ip next-hop' compile function. Given string is converted
2691 to struct in_addr structure. */
2692 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2695 struct in6_addr
*address
;
2697 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2699 ret
= inet_pton(AF_INET6
, arg
, address
);
2702 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2709 /* Free route map's compiled `ip next-hop' value. */
2710 static void route_set_ipv6_nexthop_global_free(void *rule
)
2712 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2715 /* Route map commands for ip nexthop set. */
2716 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2717 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2718 route_set_ipv6_nexthop_global_compile
,
2719 route_set_ipv6_nexthop_global_free
};
2721 /* Set next-hop preference value. */
2722 static enum route_map_cmd_result_t
2723 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2724 route_map_object_t type
, void *object
)
2726 struct bgp_path_info
*path
;
2729 if (type
== RMAP_BGP
) {
2730 /* Fetch routemap's rule information. */
2734 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2735 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2737 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2738 /* Set next hop preference to global */
2739 path
->attr
->mp_nexthop_prefer_global
= true;
2740 SET_FLAG(path
->attr
->rmap_change_flags
,
2741 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2743 path
->attr
->mp_nexthop_prefer_global
= false;
2744 SET_FLAG(path
->attr
->rmap_change_flags
,
2745 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2751 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2755 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2761 /* Free route map's compiled `ip next-hop' value. */
2762 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2764 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2767 /* Route map commands for ip nexthop set preferred. */
2768 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2769 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2770 route_set_ipv6_nexthop_prefer_global_compile
,
2771 route_set_ipv6_nexthop_prefer_global_free
};
2773 /* `set ipv6 nexthop local IP_ADDRESS' */
2775 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2776 static enum route_map_cmd_result_t
2777 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
,
2778 route_map_object_t type
, void *object
)
2780 struct in6_addr
*address
;
2781 struct bgp_path_info
*path
;
2783 if (type
== RMAP_BGP
) {
2784 /* Fetch routemap's rule information. */
2788 /* Set next hop value. */
2789 path
->attr
->mp_nexthop_local
= *address
;
2791 /* Set nexthop length. */
2792 if (path
->attr
->mp_nexthop_len
2793 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2794 path
->attr
->mp_nexthop_len
=
2795 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2797 SET_FLAG(path
->attr
->rmap_change_flags
,
2798 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2804 /* Route map `ip nexthop' compile function. Given string is converted
2805 to struct in_addr structure. */
2806 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2809 struct in6_addr
*address
;
2811 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2813 ret
= inet_pton(AF_INET6
, arg
, address
);
2816 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2823 /* Free route map's compiled `ip nexthop' value. */
2824 static void route_set_ipv6_nexthop_local_free(void *rule
)
2826 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2829 /* Route map commands for ip nexthop set. */
2830 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2831 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2832 route_set_ipv6_nexthop_local_compile
,
2833 route_set_ipv6_nexthop_local_free
};
2835 /* `set ipv6 nexthop peer-address' */
2837 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2838 static enum route_map_cmd_result_t
2839 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
,
2840 route_map_object_t type
, void *object
)
2842 struct in6_addr peer_address
;
2843 struct bgp_path_info
*path
;
2846 if (type
== RMAP_BGP
) {
2847 /* Fetch routemap's rule information. */
2851 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2852 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2854 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2855 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2856 /* Set next hop value and length in attribute. */
2857 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2858 path
->attr
->mp_nexthop_local
= peer_address
;
2859 if (path
->attr
->mp_nexthop_len
!= 32)
2860 path
->attr
->mp_nexthop_len
= 32;
2862 path
->attr
->mp_nexthop_global
= peer_address
;
2863 if (path
->attr
->mp_nexthop_len
== 0)
2864 path
->attr
->mp_nexthop_len
= 16;
2867 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2868 /* The next hop value will be set as part of packet
2870 * Set the flags here to indicate that rewrite needs to
2872 * Also, clear the value - we clear both global and
2874 * nexthops, whether we send one or both is determined
2877 SET_FLAG(path
->attr
->rmap_change_flags
,
2878 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2879 /* clear next hop value. */
2880 memset(&(path
->attr
->mp_nexthop_global
), 0,
2881 sizeof(struct in6_addr
));
2882 memset(&(path
->attr
->mp_nexthop_local
), 0,
2883 sizeof(struct in6_addr
));
2890 /* Route map `ip next-hop' compile function. Given string is converted
2891 to struct in_addr structure. */
2892 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2896 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2902 /* Free route map's compiled `ip next-hop' value. */
2903 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2905 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2908 /* Route map commands for ip nexthop set. */
2909 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2910 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2911 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2913 /* `set ipv4 vpn next-hop A.B.C.D' */
2915 static enum route_map_cmd_result_t
2916 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
,
2917 route_map_object_t type
, void *object
)
2919 struct in_addr
*address
;
2920 struct bgp_path_info
*path
;
2922 if (type
== RMAP_BGP
) {
2923 /* Fetch routemap's rule information. */
2927 /* Set next hop value. */
2928 path
->attr
->mp_nexthop_global_in
= *address
;
2929 path
->attr
->mp_nexthop_len
= 4;
2935 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2938 struct in_addr
*address
;
2940 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2942 ret
= inet_aton(arg
, address
);
2945 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2952 /* `set ipv6 vpn next-hop A.B.C.D' */
2954 static enum route_map_cmd_result_t
2955 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
,
2956 route_map_object_t type
, void *object
)
2958 struct in6_addr
*address
;
2959 struct bgp_path_info
*path
;
2961 if (type
== RMAP_BGP
) {
2962 /* Fetch routemap's rule information. */
2966 /* Set next hop value. */
2967 memcpy(&path
->attr
->mp_nexthop_global
, address
,
2968 sizeof(struct in6_addr
));
2969 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2975 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2978 struct in6_addr
*address
;
2980 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2981 ret
= inet_pton(AF_INET6
, arg
, address
);
2984 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2991 static void route_set_vpn_nexthop_free(void *rule
)
2993 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2996 /* Route map commands for ipv4 next-hop set. */
2997 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2998 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2999 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
3001 /* Route map commands for ipv6 next-hop set. */
3002 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3003 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
3004 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
3006 /* `set originator-id' */
3008 /* For origin set. */
3009 static enum route_map_cmd_result_t
3010 route_set_originator_id(void *rule
, const struct prefix
*prefix
,
3011 route_map_object_t type
, void *object
)
3013 struct in_addr
*address
;
3014 struct bgp_path_info
*path
;
3016 if (type
== RMAP_BGP
) {
3020 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3021 path
->attr
->originator_id
= *address
;
3027 /* Compile function for originator-id set. */
3028 static void *route_set_originator_id_compile(const char *arg
)
3031 struct in_addr
*address
;
3033 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3035 ret
= inet_aton(arg
, address
);
3038 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3045 /* Compile function for originator_id set. */
3046 static void route_set_originator_id_free(void *rule
)
3048 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3051 /* Set originator-id rule structure. */
3052 struct route_map_rule_cmd route_set_originator_id_cmd
= {
3053 "originator-id", route_set_originator_id
,
3054 route_set_originator_id_compile
, route_set_originator_id_free
,
3057 /* Add bgp route map rule. */
3058 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3059 const char *arg
, route_map_event_t type
)
3061 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3062 int retval
= CMD_SUCCESS
;
3063 enum rmap_compile_rets ret
;
3065 ret
= route_map_add_match(index
, command
, arg
, type
);
3067 case RMAP_RULE_MISSING
:
3068 vty_out(vty
, "%% BGP Can't find rule.\n");
3069 retval
= CMD_WARNING_CONFIG_FAILED
;
3071 case RMAP_COMPILE_ERROR
:
3072 vty_out(vty
, "%% BGP Argument is malformed.\n");
3073 retval
= CMD_WARNING_CONFIG_FAILED
;
3075 case RMAP_COMPILE_SUCCESS
:
3076 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
3077 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
3080 case RMAP_DUPLICATE_RULE
:
3082 * Intentionally doing nothing here.
3090 /* Delete bgp route map rule. */
3091 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3092 const char *arg
, route_map_event_t type
)
3094 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3095 enum rmap_compile_rets ret
;
3096 int retval
= CMD_SUCCESS
;
3097 char *dep_name
= NULL
;
3099 char *rmap_name
= NULL
;
3101 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3102 /* ignore the mundane, the types without any dependency */
3104 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3107 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3109 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3111 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3114 ret
= route_map_delete_match(index
, command
, dep_name
);
3116 case RMAP_RULE_MISSING
:
3117 vty_out(vty
, "%% BGP Can't find rule.\n");
3118 retval
= CMD_WARNING_CONFIG_FAILED
;
3120 case RMAP_COMPILE_ERROR
:
3121 vty_out(vty
, "%% BGP Argument is malformed.\n");
3122 retval
= CMD_WARNING_CONFIG_FAILED
;
3124 case RMAP_COMPILE_SUCCESS
:
3125 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
3126 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
3128 case RMAP_DUPLICATE_RULE
:
3130 * Nothing to do here
3135 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3136 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3142 * This is the workhorse routine for processing in/out routemap
3145 static void bgp_route_map_process_peer(const char *rmap_name
,
3146 struct route_map
*map
, struct peer
*peer
,
3147 int afi
, int safi
, int route_update
)
3149 struct bgp_filter
*filter
;
3151 if (!peer
|| !rmap_name
)
3154 filter
= &peer
->filter
[afi
][safi
];
3156 * in is for non-route-server clients,
3157 * out is for all peers
3159 if (filter
->map
[RMAP_IN
].name
3160 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3161 filter
->map
[RMAP_IN
].map
= map
;
3163 if (route_update
&& peer
->status
== Established
) {
3164 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3165 PEER_FLAG_SOFT_RECONFIG
)) {
3166 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3168 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3169 rmap_name
, peer
->host
);
3171 bgp_soft_reconfig_in(peer
, afi
, safi
);
3172 } else if (CHECK_FLAG(peer
->cap
,
3173 PEER_CAP_REFRESH_OLD_RCV
)
3174 || CHECK_FLAG(peer
->cap
,
3175 PEER_CAP_REFRESH_NEW_RCV
)) {
3176 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3178 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3179 rmap_name
, peer
->host
);
3180 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3187 * For outbound, unsuppress and default-originate map change (content or
3188 * map created), merely update the "config" here, the actual route
3189 * announcement happens at the group level.
3191 if (filter
->map
[RMAP_OUT
].name
3192 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3193 filter
->map
[RMAP_OUT
].map
= map
;
3195 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3196 filter
->usmap
.map
= map
;
3198 if (peer
->default_rmap
[afi
][safi
].name
3199 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3200 peer
->default_rmap
[afi
][safi
].map
= map
;
3203 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3204 struct route_map
*map
,
3207 struct peer_group
*group
;
3208 struct listnode
*node
, *nnode
;
3209 struct bgp_filter
*filter
;
3216 /* All the peers have been updated correctly already. This is
3217 * just updating the placeholder data. No real update required.
3219 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3220 FOREACH_AFI_SAFI (afi
, safi
) {
3221 filter
= &group
->conf
->filter
[afi
][safi
];
3223 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3224 if ((filter
->map
[direct
].name
)
3225 && (strcmp(rmap_name
,
3226 filter
->map
[direct
].name
)
3228 filter
->map
[direct
].map
= map
;
3231 if (filter
->usmap
.name
3232 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3233 filter
->usmap
.map
= map
;
3239 * Note that if an extreme number (tens of thousands) of route-maps are in use
3240 * and if bgp has an extreme number of peers, network statements, etc then this
3241 * function can consume a lot of cycles. This is due to this function being
3242 * called for each route-map and within this function we walk the list of peers,
3243 * network statements, etc looking to see if they use this route-map.
3245 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3252 struct bgp_node
*bn
;
3253 struct bgp_static
*bgp_static
;
3254 struct bgp_aggregate
*aggregate
;
3255 struct listnode
*node
, *nnode
;
3256 struct route_map
*map
;
3257 char buf
[INET6_ADDRSTRLEN
];
3259 map
= route_map_lookup_by_name(rmap_name
);
3261 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3263 /* Ignore dummy peer-group structure */
3264 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3267 FOREACH_AFI_SAFI (afi
, safi
) {
3268 /* process in/out/import/export/default-orig
3270 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3271 safi
, route_update
);
3275 /* for outbound/default-orig route-maps, process for groups */
3276 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3279 /* update peer-group config (template) */
3280 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3282 FOREACH_AFI_SAFI (afi
, safi
) {
3283 /* For table route-map updates. */
3284 if (!bgp_fibupd_safi(safi
))
3287 if (bgp
->table_map
[afi
][safi
].name
3288 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3291 /* bgp->table_map[afi][safi].map is NULL.
3292 * i.e Route map creation event.
3293 * So update applied_counter.
3294 * If it is not NULL, i.e It may be routemap updation or
3295 * deletion. so no need to update the counter.
3297 if (!bgp
->table_map
[afi
][safi
].map
)
3298 route_map_counter_increment(map
);
3299 bgp
->table_map
[afi
][safi
].map
= map
;
3301 if (BGP_DEBUG(zebra
, ZEBRA
))
3303 "Processing route_map %s update on "
3307 bgp_zebra_announce_table(bgp
, afi
, safi
);
3310 /* For network route-map updates. */
3311 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3312 bn
= bgp_route_next(bn
)) {
3313 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3317 if (!bgp_static
->rmap
.name
3318 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3321 if (!bgp_static
->rmap
.map
)
3322 route_map_counter_increment(map
);
3324 bgp_static
->rmap
.map
= map
;
3326 if (route_update
&& !bgp_static
->backdoor
) {
3327 if (bgp_debug_zebra(&bn
->p
))
3329 "Processing route_map %s update on static route %s",
3331 inet_ntop(bn
->p
.family
,
3332 &bn
->p
.u
.prefix
, buf
,
3334 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3339 /* For aggregate-address route-map updates. */
3340 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
3341 bn
= bgp_route_next(bn
)) {
3342 aggregate
= bgp_node_get_bgp_aggregate_info(bn
);
3346 if (!aggregate
->rmap
.name
3347 || (strcmp(rmap_name
, aggregate
->rmap
.name
) != 0))
3350 if (!aggregate
->rmap
.map
)
3351 route_map_counter_increment(map
);
3353 aggregate
->rmap
.map
= map
;
3356 if (bgp_debug_zebra(&bn
->p
))
3358 "Processing route_map %s update on aggregate-address route %s",
3360 inet_ntop(bn
->p
.family
,
3361 &bn
->p
.u
.prefix
, buf
,
3363 bgp_aggregate_route(bgp
, &bn
->p
, afi
, safi
,
3369 /* For redistribute route-map updates. */
3370 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3371 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3372 struct list
*red_list
;
3373 struct bgp_redist
*red
;
3375 red_list
= bgp
->redist
[afi
][i
];
3379 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3381 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3385 route_map_counter_increment(map
);
3387 red
->rmap
.map
= map
;
3392 if (BGP_DEBUG(zebra
, ZEBRA
))
3394 "Processing route_map %s update on redistributed routes",
3397 bgp_redistribute_resend(bgp
, afi
, i
,
3402 /* for type5 command route-maps */
3403 FOREACH_AFI_SAFI (afi
, safi
) {
3404 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3405 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3409 /* Make sure the route-map is populated here if not already done */
3410 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3412 if (BGP_DEBUG(zebra
, ZEBRA
))
3414 "Processing route_map %s update on advertise type5 route command",
3417 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3418 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3419 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3424 static void bgp_route_map_process_update_cb(char *rmap_name
)
3426 struct listnode
*node
, *nnode
;
3429 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3430 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3433 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3434 vnc_routemap_update(bgp
, __func__
);
3438 vpn_policy_routemap_event(rmap_name
);
3441 int bgp_route_map_update_timer(struct thread
*thread
)
3443 bm
->t_rmap_update
= NULL
;
3445 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3450 static void bgp_route_map_mark_update(const char *rmap_name
)
3452 struct listnode
*node
, *nnode
;
3455 /* If new update is received before the current timer timed out,
3456 * turn it off and start a new timer.
3458 if (bm
->t_rmap_update
!= NULL
)
3459 THREAD_OFF(bm
->t_rmap_update
);
3461 /* rmap_update_timer of 0 means don't do route updates */
3462 if (bm
->rmap_update_timer
) {
3463 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3464 NULL
, bm
->rmap_update_timer
,
3465 &bm
->t_rmap_update
);
3467 /* Signal the groups that a route-map update event has
3469 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3470 update_group_policy_update(bgp
,
3471 BGP_POLICY_ROUTE_MAP
,
3474 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3475 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3477 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3478 vnc_routemap_update(bgp
, __func__
);
3483 static void bgp_route_map_add(const char *rmap_name
)
3485 if (route_map_mark_updated(rmap_name
) == 0)
3486 bgp_route_map_mark_update(rmap_name
);
3488 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3491 static void bgp_route_map_delete(const char *rmap_name
)
3493 if (route_map_mark_updated(rmap_name
) == 0)
3494 bgp_route_map_mark_update(rmap_name
);
3496 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3499 static void bgp_route_map_event(const char *rmap_name
)
3501 if (route_map_mark_updated(rmap_name
) == 0)
3502 bgp_route_map_mark_update(rmap_name
);
3504 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3507 DEFUN (match_mac_address
,
3508 match_mac_address_cmd
,
3509 "match mac address WORD",
3512 "Match address of route\n"
3513 "MAC Access-list name\n")
3515 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3516 RMAP_EVENT_FILTER_ADDED
);
3519 DEFUN (no_match_mac_address
,
3520 no_match_mac_address_cmd
,
3521 "no match mac address WORD",
3525 "Match address of route\n"
3526 "MAC acess-list name\n")
3528 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3529 RMAP_EVENT_FILTER_DELETED
);
3532 DEFUN (match_evpn_route_type
,
3533 match_evpn_route_type_cmd
,
3534 "match evpn route-type <macip | multicast | prefix>",
3537 "Match route-type\n"
3542 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3543 RMAP_EVENT_MATCH_ADDED
);
3546 DEFUN (no_match_evpn_route_type
,
3547 no_match_evpn_route_type_cmd
,
3548 "no match evpn route-type <macip | multicast | prefix>",
3552 "Match route-type\n"
3557 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3558 RMAP_EVENT_MATCH_DELETED
);
3562 DEFUN (match_evpn_vni
,
3564 "match evpn vni " CMD_VNI_RANGE
,
3570 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3571 RMAP_EVENT_MATCH_ADDED
);
3574 DEFUN (no_match_evpn_vni
,
3575 no_match_evpn_vni_cmd
,
3576 "no match evpn vni " CMD_VNI_RANGE
,
3583 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3584 RMAP_EVENT_MATCH_DELETED
);
3587 DEFUN (match_evpn_default_route
,
3588 match_evpn_default_route_cmd
,
3589 "match evpn default-route",
3592 "default EVPN type-5 route\n")
3594 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3595 RMAP_EVENT_MATCH_ADDED
);
3598 DEFUN (no_match_evpn_default_route
,
3599 no_match_evpn_default_route_cmd
,
3600 "no match evpn default-route",
3604 "default EVPN type-5 route\n")
3606 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3607 RMAP_EVENT_MATCH_DELETED
);
3610 DEFPY(match_vrl_source_vrf
,
3611 match_vrl_source_vrf_cmd
,
3612 "match source-vrf NAME$vrf_name",
3617 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3618 RMAP_EVENT_MATCH_ADDED
);
3621 DEFPY(no_match_vrl_source_vrf
,
3622 no_match_vrl_source_vrf_cmd
,
3623 "no match source-vrf NAME$vrf_name",
3629 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3630 RMAP_EVENT_MATCH_DELETED
);
3635 "match peer <A.B.C.D|X:X::X:X|WORD>",
3637 "Match peer address\n"
3638 "IP address of peer\n"
3639 "IPv6 address of peer\n"
3640 "Interface name of peer\n")
3643 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3644 RMAP_EVENT_MATCH_ADDED
);
3647 DEFUN (match_peer_local
,
3648 match_peer_local_cmd
,
3651 "Match peer address\n"
3652 "Static or Redistributed routes\n")
3654 return bgp_route_match_add(vty
, "peer", "local",
3655 RMAP_EVENT_MATCH_DELETED
);
3658 DEFUN (no_match_peer
,
3660 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3663 "Match peer address\n"
3664 "Static or Redistributed routes\n"
3665 "IP address of peer\n"
3666 "IPv6 address of peer\n"
3667 "Interface name of peer\n")
3671 if (argc
<= idx_peer
)
3672 return bgp_route_match_delete(vty
, "peer", NULL
,
3673 RMAP_EVENT_MATCH_DELETED
);
3674 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3675 RMAP_EVENT_MATCH_DELETED
);
3678 #if defined(HAVE_LUA)
3679 DEFUN (match_command
,
3681 "match command WORD",
3683 "Run a command to match\n"
3684 "The command to run\n")
3686 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3687 RMAP_EVENT_FILTER_ADDED
);
3690 DEFUN (no_match_command
,
3691 no_match_command_cmd
,
3692 "no match command WORD",
3695 "Run a command to match\n"
3696 "The command to run\n")
3698 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3699 RMAP_EVENT_FILTER_DELETED
);
3703 /* match probability */
3704 DEFUN (match_probability
,
3705 match_probability_cmd
,
3706 "match probability (0-100)",
3708 "Match portion of routes defined by percentage value\n"
3709 "Percentage of routes\n")
3712 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3713 RMAP_EVENT_MATCH_ADDED
);
3717 DEFUN (no_match_probability
,
3718 no_match_probability_cmd
,
3719 "no match probability [(1-99)]",
3722 "Match portion of routes defined by percentage value\n"
3723 "Percentage of routes\n")
3726 if (argc
<= idx_number
)
3727 return bgp_route_match_delete(vty
, "probability", NULL
,
3728 RMAP_EVENT_MATCH_DELETED
);
3729 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3730 RMAP_EVENT_MATCH_DELETED
);
3734 DEFUN (match_ip_route_source
,
3735 match_ip_route_source_cmd
,
3736 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3739 "Match advertising source address of route\n"
3740 "IP access-list number\n"
3741 "IP access-list number (expanded range)\n"
3742 "IP standard access-list name\n")
3745 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3746 RMAP_EVENT_FILTER_ADDED
);
3750 DEFUN (no_match_ip_route_source
,
3751 no_match_ip_route_source_cmd
,
3752 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3756 "Match advertising source address of route\n"
3757 "IP access-list number\n"
3758 "IP access-list number (expanded range)\n"
3759 "IP standard access-list name\n")
3762 if (argc
<= idx_number
)
3763 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3764 RMAP_EVENT_FILTER_DELETED
);
3765 return bgp_route_match_delete(vty
, "ip route-source",
3766 argv
[idx_number
]->arg
,
3767 RMAP_EVENT_FILTER_DELETED
);
3771 DEFUN (match_ip_route_source_prefix_list
,
3772 match_ip_route_source_prefix_list_cmd
,
3773 "match ip route-source prefix-list WORD",
3776 "Match advertising source address of route\n"
3777 "Match entries of prefix-lists\n"
3778 "IP prefix-list name\n")
3781 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3782 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3786 DEFUN (no_match_ip_route_source_prefix_list
,
3787 no_match_ip_route_source_prefix_list_cmd
,
3788 "no match ip route-source prefix-list [WORD]",
3792 "Match advertising source address of route\n"
3793 "Match entries of prefix-lists\n"
3794 "IP prefix-list name\n")
3797 if (argc
<= idx_word
)
3798 return bgp_route_match_delete(vty
,
3799 "ip route-source prefix-list",
3800 NULL
, RMAP_EVENT_PLIST_DELETED
);
3801 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3802 argv
[idx_word
]->arg
,
3803 RMAP_EVENT_PLIST_DELETED
);
3807 DEFUN (match_local_pref
,
3808 match_local_pref_cmd
,
3809 "match local-preference (0-4294967295)",
3811 "Match local-preference of route\n"
3815 return bgp_route_match_add(vty
, "local-preference",
3816 argv
[idx_number
]->arg
,
3817 RMAP_EVENT_MATCH_ADDED
);
3821 DEFUN (no_match_local_pref
,
3822 no_match_local_pref_cmd
,
3823 "no match local-preference [(0-4294967295)]",
3826 "Match local preference of route\n"
3827 "Local preference value\n")
3829 int idx_localpref
= 3;
3830 if (argc
<= idx_localpref
)
3831 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3832 RMAP_EVENT_MATCH_DELETED
);
3833 return bgp_route_match_delete(vty
, "local-preference",
3834 argv
[idx_localpref
]->arg
,
3835 RMAP_EVENT_MATCH_DELETED
);
3839 DEFUN (match_community
,
3840 match_community_cmd
,
3841 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3843 "Match BGP community list\n"
3844 "Community-list number (standard)\n"
3845 "Community-list number (expanded)\n"
3846 "Community-list name\n"
3847 "Do exact matching of communities\n")
3849 int idx_comm_list
= 2;
3854 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3855 strlen(argv
[idx_comm_list
]->arg
)
3856 + strlen("exact-match") + 2);
3858 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3860 argstr
= argv
[idx_comm_list
]->arg
;
3862 ret
= bgp_route_match_add(vty
, "community", argstr
,
3863 RMAP_EVENT_CLIST_ADDED
);
3865 if (argstr
!= argv
[idx_comm_list
]->arg
)
3866 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3871 DEFUN (no_match_community
,
3872 no_match_community_cmd
,
3873 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3876 "Match BGP community list\n"
3877 "Community-list number (standard)\n"
3878 "Community-list number (expanded)\n"
3879 "Community-list name\n"
3880 "Do exact matching of communities\n")
3882 return bgp_route_match_delete(vty
, "community", NULL
,
3883 RMAP_EVENT_CLIST_DELETED
);
3886 DEFUN (match_lcommunity
,
3887 match_lcommunity_cmd
,
3888 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
3890 "Match BGP large community list\n"
3891 "Large Community-list number (standard)\n"
3892 "Large Community-list number (expanded)\n"
3893 "Large Community-list name\n"
3894 "Do exact matching of communities\n")
3896 int idx_lcomm_list
= 2;
3901 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3902 strlen(argv
[idx_lcomm_list
]->arg
)
3903 + strlen("exact-match") + 2);
3905 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
3907 argstr
= argv
[idx_lcomm_list
]->arg
;
3909 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
3910 RMAP_EVENT_LLIST_ADDED
);
3911 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
3912 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3917 DEFUN (no_match_lcommunity
,
3918 no_match_lcommunity_cmd
,
3919 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
3922 "Match BGP large community list\n"
3923 "Large Community-list number (standard)\n"
3924 "Large Community-list number (expanded)\n"
3925 "Large Community-list name\n"
3926 "Do exact matching of communities\n")
3928 return bgp_route_match_delete(vty
, "large-community", NULL
,
3929 RMAP_EVENT_LLIST_DELETED
);
3932 DEFUN (match_ecommunity
,
3933 match_ecommunity_cmd
,
3934 "match extcommunity <(1-99)|(100-500)|WORD>",
3936 "Match BGP/VPN extended community list\n"
3937 "Extended community-list number (standard)\n"
3938 "Extended community-list number (expanded)\n"
3939 "Extended community-list name\n")
3941 int idx_comm_list
= 2;
3942 return bgp_route_match_add(vty
, "extcommunity",
3943 argv
[idx_comm_list
]->arg
,
3944 RMAP_EVENT_ECLIST_ADDED
);
3948 DEFUN (no_match_ecommunity
,
3949 no_match_ecommunity_cmd
,
3950 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3953 "Match BGP/VPN extended community list\n"
3954 "Extended community-list number (standard)\n"
3955 "Extended community-list number (expanded)\n"
3956 "Extended community-list name\n")
3958 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3959 RMAP_EVENT_ECLIST_DELETED
);
3963 DEFUN (match_aspath
,
3965 "match as-path WORD",
3967 "Match BGP AS path list\n"
3968 "AS path access-list name\n")
3971 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3972 RMAP_EVENT_ASLIST_ADDED
);
3976 DEFUN (no_match_aspath
,
3977 no_match_aspath_cmd
,
3978 "no match as-path [WORD]",
3981 "Match BGP AS path list\n"
3982 "AS path access-list name\n")
3984 return bgp_route_match_delete(vty
, "as-path", NULL
,
3985 RMAP_EVENT_ASLIST_DELETED
);
3989 DEFUN (match_origin
,
3991 "match origin <egp|igp|incomplete>",
3996 "unknown heritage\n")
3999 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4000 return bgp_route_match_add(vty
, "origin", "igp",
4001 RMAP_EVENT_MATCH_ADDED
);
4002 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4003 return bgp_route_match_add(vty
, "origin", "egp",
4004 RMAP_EVENT_MATCH_ADDED
);
4005 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4006 return bgp_route_match_add(vty
, "origin", "incomplete",
4007 RMAP_EVENT_MATCH_ADDED
);
4009 vty_out(vty
, "%% Invalid match origin type\n");
4010 return CMD_WARNING_CONFIG_FAILED
;
4014 DEFUN (no_match_origin
,
4015 no_match_origin_cmd
,
4016 "no match origin [<egp|igp|incomplete>]",
4022 "unknown heritage\n")
4024 return bgp_route_match_delete(vty
, "origin", NULL
,
4025 RMAP_EVENT_MATCH_DELETED
);
4028 DEFUN (set_ip_nexthop_peer
,
4029 set_ip_nexthop_peer_cmd
,
4030 "[no] set ip next-hop peer-address",
4034 "Next hop address\n"
4035 "Use peer address (for BGP only)\n")
4037 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4038 const char *) = strmatch(argv
[0]->text
, "no")
4039 ? generic_set_delete
4042 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4046 DEFUN (set_ip_nexthop_unchanged
,
4047 set_ip_nexthop_unchanged_cmd
,
4048 "[no] set ip next-hop unchanged",
4052 "Next hop address\n"
4053 "Don't modify existing Next hop address\n")
4055 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4056 const char *) = strmatch(argv
[0]->text
, "no")
4057 ? generic_set_delete
4060 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4065 DEFUN (set_local_pref
,
4067 "set local-preference (0-4294967295)",
4069 "BGP local preference path attribute\n"
4070 "Preference value\n")
4073 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4074 "local-preference", argv
[idx_number
]->arg
);
4078 DEFUN (no_set_local_pref
,
4079 no_set_local_pref_cmd
,
4080 "no set local-preference [(0-4294967295)]",
4083 "BGP local preference path attribute\n"
4084 "Preference value\n")
4086 int idx_localpref
= 3;
4087 if (argc
<= idx_localpref
)
4088 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4089 "local-preference", NULL
);
4090 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4091 "local-preference", argv
[idx_localpref
]->arg
);
4097 "set weight (0-4294967295)",
4099 "BGP weight for routing table\n"
4103 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4104 argv
[idx_number
]->arg
);
4108 DEFUN (no_set_weight
,
4110 "no set weight [(0-4294967295)]",
4113 "BGP weight for routing table\n"
4117 if (argc
<= idx_weight
)
4118 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4120 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4121 "weight", argv
[idx_weight
]->arg
);
4124 DEFUN (set_label_index
,
4125 set_label_index_cmd
,
4126 "set label-index (0-1048560)",
4128 "Label index to associate with the prefix\n"
4129 "Label index value\n")
4132 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4133 "label-index", argv
[idx_number
]->arg
);
4136 DEFUN (no_set_label_index
,
4137 no_set_label_index_cmd
,
4138 "no set label-index [(0-1048560)]",
4141 "Label index to associate with the prefix\n"
4142 "Label index value\n")
4144 int idx_label_index
= 3;
4145 if (argc
<= idx_label_index
)
4146 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4147 "label-index", NULL
);
4148 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4149 "label-index", argv
[idx_label_index
]->arg
);
4152 DEFUN (set_aspath_prepend_asn
,
4153 set_aspath_prepend_asn_cmd
,
4154 "set as-path prepend (1-4294967295)...",
4156 "Transform BGP AS_PATH attribute\n"
4157 "Prepend to the as-path\n"
4164 str
= argv_concat(argv
, argc
, idx_asn
);
4165 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4166 "as-path prepend", str
);
4167 XFREE(MTYPE_TMP
, str
);
4172 DEFUN (set_aspath_prepend_lastas
,
4173 set_aspath_prepend_lastas_cmd
,
4174 "set as-path prepend last-as (1-10)",
4176 "Transform BGP AS_PATH attribute\n"
4177 "Prepend to the as-path\n"
4178 "Use the peer's AS-number\n"
4179 "Number of times to insert\n")
4181 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4184 DEFUN (no_set_aspath_prepend
,
4185 no_set_aspath_prepend_cmd
,
4186 "no set as-path prepend [(1-4294967295)]",
4189 "Transform BGP AS_PATH attribute\n"
4190 "Prepend to the as-path\n"
4197 str
= argv_concat(argv
, argc
, idx_asn
);
4198 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4199 "as-path prepend", str
);
4200 XFREE(MTYPE_TMP
, str
);
4204 DEFUN (no_set_aspath_prepend_lastas
,
4205 no_set_aspath_prepend_lastas_cmd
,
4206 "no set as-path prepend last-as [(1-10)]",
4209 "Transform BGP AS_PATH attribute\n"
4210 "Prepend to the as-path\n"
4211 "Use the peers AS-number\n"
4212 "Number of times to insert\n")
4214 return no_set_aspath_prepend(self
, vty
, argc
, argv
);
4217 DEFUN (set_aspath_exclude
,
4218 set_aspath_exclude_cmd
,
4219 "set as-path exclude (1-4294967295)...",
4221 "Transform BGP AS-path attribute\n"
4222 "Exclude from the as-path\n"
4229 str
= argv_concat(argv
, argc
, idx_asn
);
4230 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4231 "as-path exclude", str
);
4232 XFREE(MTYPE_TMP
, str
);
4236 DEFUN (no_set_aspath_exclude
,
4237 no_set_aspath_exclude_cmd
,
4238 "no set as-path exclude (1-4294967295)...",
4241 "Transform BGP AS_PATH attribute\n"
4242 "Exclude from the as-path\n"
4249 str
= argv_concat(argv
, argc
, idx_asn
);
4250 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4251 "as-path exclude", str
);
4252 XFREE(MTYPE_TMP
, str
);
4256 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4257 "no set as-path exclude",
4259 "Transform BGP AS_PATH attribute\n"
4260 "Exclude from the as-path\n")
4262 DEFUN (set_community
,
4264 "set community AA:NN...",
4266 "BGP community attribute\n"
4274 struct community
*com
= NULL
;
4279 b
= buffer_new(1024);
4281 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4282 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4289 buffer_putc(b
, ' ');
4293 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4295 buffer_putstr(b
, "internet");
4298 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4300 buffer_putstr(b
, "local-AS");
4303 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4304 && strncmp(argv
[i
]->arg
, "no-advertise",
4305 strlen(argv
[i
]->arg
))
4307 buffer_putstr(b
, "no-advertise");
4310 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4311 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4313 buffer_putstr(b
, "no-export");
4316 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4317 strlen(argv
[i
]->arg
))
4319 buffer_putstr(b
, "graceful-shutdown");
4322 buffer_putstr(b
, argv
[i
]->arg
);
4324 buffer_putc(b
, '\0');
4326 /* Fetch result string then compile it to communities attribute. */
4327 str
= buffer_getstr(b
);
4331 com
= community_str2com(str
);
4332 XFREE(MTYPE_TMP
, str
);
4335 /* Can't compile user input into communities attribute. */
4337 vty_out(vty
, "%% Malformed communities attribute\n");
4338 return CMD_WARNING_CONFIG_FAILED
;
4341 /* Set communites attribute string. */
4342 str
= community_str(com
, false);
4345 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4346 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4347 strlcpy(argstr
, str
, argstr_sz
);
4348 strlcat(argstr
, " additive", argstr_sz
);
4349 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4350 "community", argstr
);
4351 XFREE(MTYPE_TMP
, argstr
);
4353 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4356 community_free(&com
);
4361 DEFUN (set_community_none
,
4362 set_community_none_cmd
,
4363 "set community none",
4365 "BGP community attribute\n"
4366 "No community attribute\n")
4368 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4369 "community", "none");
4372 DEFUN (no_set_community
,
4373 no_set_community_cmd
,
4374 "no set community AA:NN...",
4377 "BGP community attribute\n"
4380 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4384 ALIAS (no_set_community
,
4385 no_set_community_short_cmd
,
4389 "BGP community attribute\n")
4392 DEFUN (set_community_delete
,
4393 set_community_delete_cmd
,
4394 "set comm-list <(1-99)|(100-500)|WORD> delete",
4396 "set BGP community list (for deletion)\n"
4397 "Community-list number (standard)\n"
4398 "Community-list number (expanded)\n"
4399 "Community-list name\n"
4400 "Delete matching communities\n")
4402 int idx_comm_list
= 2;
4405 args
= argv_concat(argv
, argc
, idx_comm_list
);
4406 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4408 XFREE(MTYPE_TMP
, args
);
4413 DEFUN (no_set_community_delete
,
4414 no_set_community_delete_cmd
,
4415 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4418 "set BGP community list (for deletion)\n"
4419 "Community-list number (standard)\n"
4420 "Community-list number (expanded)\n"
4421 "Community-list name\n"
4422 "Delete matching communities\n")
4424 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4428 DEFUN (set_lcommunity
,
4430 "set large-community AA:BB:CC...",
4432 "BGP large community attribute\n"
4433 "Large Community number in aa:bb:cc format or additive\n")
4438 str
= argv_concat(argv
, argc
, 2);
4439 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4440 "large-community", str
);
4441 XFREE(MTYPE_TMP
, str
);
4446 DEFUN (set_lcommunity_none
,
4447 set_lcommunity_none_cmd
,
4448 "set large-community none",
4450 "BGP large community attribute\n"
4451 "No large community attribute\n")
4453 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4454 "large-community", "none");
4457 DEFUN (no_set_lcommunity
,
4458 no_set_lcommunity_cmd
,
4459 "no set large-community none",
4462 "BGP large community attribute\n"
4463 "No community attribute\n")
4465 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4466 "large-community", NULL
);
4469 DEFUN (no_set_lcommunity1
,
4470 no_set_lcommunity1_cmd
,
4471 "no set large-community AA:BB:CC...",
4474 "BGP large community attribute\n"
4475 "Large community in AA:BB:CC... format or additive\n")
4477 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4478 "large-community", NULL
);
4481 ALIAS (no_set_lcommunity1
,
4482 no_set_lcommunity1_short_cmd
,
4483 "no set large-community",
4486 "BGP large community attribute\n")
4488 DEFUN (set_lcommunity_delete
,
4489 set_lcommunity_delete_cmd
,
4490 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4492 "set BGP large community list (for deletion)\n"
4493 "Large Community-list number (standard)\n"
4494 "Large Communitly-list number (expanded)\n"
4495 "Large Community-list name\n"
4496 "Delete matching large communities\n")
4498 int idx_lcomm_list
= 2;
4501 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
4502 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4503 "large-comm-list", args
);
4504 XFREE(MTYPE_TMP
, args
);
4509 DEFUN (no_set_lcommunity_delete
,
4510 no_set_lcommunity_delete_cmd
,
4511 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4514 "set BGP large community list (for deletion)\n"
4515 "Large Community-list number (standard)\n"
4516 "Large Communitly-list number (expanded)\n"
4517 "Large Community-list name\n"
4518 "Delete matching large communities\n")
4520 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4521 "large-comm-list", NULL
);
4524 ALIAS (no_set_lcommunity_delete
,
4525 no_set_lcommunity_delete_short_cmd
,
4526 "no set large-comm-list",
4529 "set BGP large community list (for deletion)\n")
4531 DEFUN (set_ecommunity_rt
,
4532 set_ecommunity_rt_cmd
,
4533 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4535 "BGP extended community attribute\n"
4536 "Route Target extended community\n"
4537 "VPN extended community\n")
4543 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4544 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4545 "extcommunity rt", str
);
4546 XFREE(MTYPE_TMP
, str
);
4551 DEFUN (no_set_ecommunity_rt
,
4552 no_set_ecommunity_rt_cmd
,
4553 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4556 "BGP extended community attribute\n"
4557 "Route Target extended community\n"
4558 "VPN extended community\n")
4560 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4561 "extcommunity rt", NULL
);
4564 ALIAS (no_set_ecommunity_rt
,
4565 no_set_ecommunity_rt_short_cmd
,
4566 "no set extcommunity rt",
4569 "BGP extended community attribute\n"
4570 "Route Target extended community\n")
4572 DEFUN (set_ecommunity_soo
,
4573 set_ecommunity_soo_cmd
,
4574 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4576 "BGP extended community attribute\n"
4577 "Site-of-Origin extended community\n"
4578 "VPN extended community\n")
4584 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4585 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4586 "extcommunity soo", str
);
4587 XFREE(MTYPE_TMP
, str
);
4592 DEFUN (no_set_ecommunity_soo
,
4593 no_set_ecommunity_soo_cmd
,
4594 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4597 "BGP extended community attribute\n"
4598 "Site-of-Origin extended community\n"
4599 "VPN extended community\n")
4601 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4602 "extcommunity soo", NULL
);
4605 ALIAS (no_set_ecommunity_soo
,
4606 no_set_ecommunity_soo_short_cmd
,
4607 "no set extcommunity soo",
4610 "GP extended community attribute\n"
4611 "Site-of-Origin extended community\n")
4615 "set origin <egp|igp|incomplete>",
4620 "unknown heritage\n")
4623 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4624 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4626 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4627 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4629 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4630 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4631 "origin", "incomplete");
4633 vty_out(vty
, "%% Invalid set origin type\n");
4634 return CMD_WARNING_CONFIG_FAILED
;
4638 DEFUN (no_set_origin
,
4640 "no set origin [<egp|igp|incomplete>]",
4646 "unknown heritage\n")
4648 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4653 DEFUN (set_atomic_aggregate
,
4654 set_atomic_aggregate_cmd
,
4655 "set atomic-aggregate",
4657 "BGP atomic aggregate attribute\n" )
4659 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4660 "atomic-aggregate", NULL
);
4663 DEFUN (no_set_atomic_aggregate
,
4664 no_set_atomic_aggregate_cmd
,
4665 "no set atomic-aggregate",
4668 "BGP atomic aggregate attribute\n" )
4670 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4671 "atomic-aggregate", NULL
);
4674 DEFUN (set_aggregator_as
,
4675 set_aggregator_as_cmd
,
4676 "set aggregator as (1-4294967295) A.B.C.D",
4678 "BGP aggregator attribute\n"
4679 "AS number of aggregator\n"
4681 "IP address of aggregator\n")
4686 struct in_addr address
;
4689 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4691 vty_out(vty
, "Aggregator IP address is invalid\n");
4692 return CMD_WARNING_CONFIG_FAILED
;
4695 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4696 strlen(argv
[idx_number
]->arg
)
4697 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4699 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4701 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4702 "aggregator as", argstr
);
4704 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4710 DEFUN (no_set_aggregator_as
,
4711 no_set_aggregator_as_cmd
,
4712 "no set aggregator as [(1-4294967295) A.B.C.D]",
4715 "BGP aggregator attribute\n"
4716 "AS number of aggregator\n"
4718 "IP address of aggregator\n")
4723 struct in_addr address
;
4726 if (argc
<= idx_asn
)
4727 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4728 "aggregator as", NULL
);
4730 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4732 vty_out(vty
, "Aggregator IP address is invalid\n");
4733 return CMD_WARNING_CONFIG_FAILED
;
4736 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4737 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4740 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4742 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4743 "aggregator as", argstr
);
4745 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4750 DEFUN (match_ipv6_next_hop
,
4751 match_ipv6_next_hop_cmd
,
4752 "match ipv6 next-hop X:X::X:X",
4755 "Match IPv6 next-hop address of route\n"
4756 "IPv6 address of next hop\n")
4759 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4760 RMAP_EVENT_MATCH_ADDED
);
4763 DEFUN (no_match_ipv6_next_hop
,
4764 no_match_ipv6_next_hop_cmd
,
4765 "no match ipv6 next-hop X:X::X:X",
4769 "Match IPv6 next-hop address of route\n"
4770 "IPv6 address of next hop\n")
4773 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4774 RMAP_EVENT_MATCH_DELETED
);
4778 DEFUN (set_ipv6_nexthop_peer
,
4779 set_ipv6_nexthop_peer_cmd
,
4780 "set ipv6 next-hop peer-address",
4783 "Next hop address\n"
4784 "Use peer address (for BGP only)\n")
4786 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4787 "ipv6 next-hop peer-address", NULL
);
4790 DEFUN (no_set_ipv6_nexthop_peer
,
4791 no_set_ipv6_nexthop_peer_cmd
,
4792 "no set ipv6 next-hop peer-address",
4796 "IPv6 next-hop address\n"
4797 "Use peer address (for BGP only)\n")
4799 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4800 "ipv6 next-hop peer-address", NULL
);
4803 DEFUN (set_ipv6_nexthop_prefer_global
,
4804 set_ipv6_nexthop_prefer_global_cmd
,
4805 "set ipv6 next-hop prefer-global",
4808 "IPv6 next-hop address\n"
4809 "Prefer global over link-local if both exist\n")
4811 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4812 "ipv6 next-hop prefer-global", NULL
);
4816 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4817 no_set_ipv6_nexthop_prefer_global_cmd
,
4818 "no set ipv6 next-hop prefer-global",
4822 "IPv6 next-hop address\n"
4823 "Prefer global over link-local if both exist\n")
4825 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4826 "ipv6 next-hop prefer-global", NULL
);
4829 DEFUN (set_ipv6_nexthop_global
,
4830 set_ipv6_nexthop_global_cmd
,
4831 "set ipv6 next-hop global X:X::X:X",
4834 "IPv6 next-hop address\n"
4835 "IPv6 global address\n"
4836 "IPv6 address of next hop\n")
4839 struct in6_addr addr
;
4842 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4844 vty_out(vty
, "%% Malformed nexthop address\n");
4845 return CMD_WARNING_CONFIG_FAILED
;
4847 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4848 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4849 vty_out(vty
, "%% Invalid global nexthop address\n");
4850 return CMD_WARNING_CONFIG_FAILED
;
4853 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4854 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4858 DEFUN (no_set_ipv6_nexthop_global
,
4859 no_set_ipv6_nexthop_global_cmd
,
4860 "no set ipv6 next-hop global X:X::X:X",
4864 "IPv6 next-hop address\n"
4865 "IPv6 global address\n"
4866 "IPv6 address of next hop\n")
4869 if (argc
<= idx_ipv6
)
4870 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4871 "ipv6 next-hop global", NULL
);
4872 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4873 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4876 #ifdef KEEP_OLD_VPN_COMMANDS
4877 DEFUN (set_vpn_nexthop
,
4878 set_vpn_nexthop_cmd
,
4879 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4881 "VPNv4 information\n"
4882 "VPN next-hop address\n"
4883 "IP address of next hop\n"
4884 "VPNv6 information\n"
4885 "VPN next-hop address\n"
4886 "IPv6 address of next hop\n")
4892 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4894 return generic_set_add(
4895 vty
, VTY_GET_CONTEXT(route_map_index
),
4896 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4898 return generic_set_add(
4899 vty
, VTY_GET_CONTEXT(route_map_index
),
4900 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4905 DEFUN (no_set_vpn_nexthop
,
4906 no_set_vpn_nexthop_cmd
,
4907 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4910 "VPNv4 information\n"
4911 "VPN next-hop address\n"
4912 "IP address of next hop\n"
4913 "VPNv6 information\n"
4914 "VPN next-hop address\n"
4915 "IPv6 address of next hop\n")
4925 arg
= argv
[idx_ip
]->arg
;
4926 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4928 return generic_set_delete(
4929 vty
, VTY_GET_CONTEXT(route_map_index
),
4930 "ipv4 vpn next-hop", arg
);
4932 return generic_set_delete(
4933 vty
, VTY_GET_CONTEXT(route_map_index
),
4934 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4938 #endif /* KEEP_OLD_VPN_COMMANDS */
4940 DEFUN (set_ipx_vpn_nexthop
,
4941 set_ipx_vpn_nexthop_cmd
,
4942 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4944 "IPv4 information\n"
4945 "IPv6 information\n"
4947 "VPN next-hop address\n"
4948 "IP address of next hop\n"
4949 "IPv6 address of next hop\n")
4955 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4957 return generic_set_add(
4958 vty
, VTY_GET_CONTEXT(route_map_index
),
4959 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4961 return generic_set_add(
4962 vty
, VTY_GET_CONTEXT(route_map_index
),
4963 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4968 DEFUN (no_set_ipx_vpn_nexthop
,
4969 no_set_ipx_vpn_nexthop_cmd
,
4970 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4973 "IPv4 information\n"
4974 "IPv6 information\n"
4976 "VPN next-hop address\n"
4977 "IP address of next hop\n"
4978 "IPv6 address of next hop\n")
4988 arg
= argv
[idx_ip
]->arg
;
4989 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4991 return generic_set_delete(
4992 vty
, VTY_GET_CONTEXT(route_map_index
),
4993 "ipv4 vpn next-hop", arg
);
4995 return generic_set_delete(
4996 vty
, VTY_GET_CONTEXT(route_map_index
),
4997 "ipv6 vpn next-hop", arg
);
5002 DEFUN (set_originator_id
,
5003 set_originator_id_cmd
,
5004 "set originator-id A.B.C.D",
5006 "BGP originator ID attribute\n"
5007 "IP address of originator\n")
5010 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5011 "originator-id", argv
[idx_ipv4
]->arg
);
5015 DEFUN (no_set_originator_id
,
5016 no_set_originator_id_cmd
,
5017 "no set originator-id [A.B.C.D]",
5020 "BGP originator ID attribute\n"
5021 "IP address of originator\n")
5025 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
5027 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5028 "originator-id", arg
);
5032 /* Initialization of route map. */
5033 void bgp_route_map_init(void)
5037 route_map_add_hook(bgp_route_map_add
);
5038 route_map_delete_hook(bgp_route_map_delete
);
5039 route_map_event_hook(bgp_route_map_event
);
5041 route_map_match_interface_hook(generic_match_add
);
5042 route_map_no_match_interface_hook(generic_match_delete
);
5044 route_map_match_ip_address_hook(generic_match_add
);
5045 route_map_no_match_ip_address_hook(generic_match_delete
);
5047 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
5048 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
5050 route_map_match_ip_next_hop_hook(generic_match_add
);
5051 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
5053 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
5054 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5056 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5057 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5059 route_map_match_ipv6_address_hook(generic_match_add
);
5060 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5062 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5063 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5065 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5066 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5068 route_map_match_metric_hook(generic_match_add
);
5069 route_map_no_match_metric_hook(generic_match_delete
);
5071 route_map_match_tag_hook(generic_match_add
);
5072 route_map_no_match_tag_hook(generic_match_delete
);
5074 route_map_set_ip_nexthop_hook(generic_set_add
);
5075 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5077 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5078 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5080 route_map_set_metric_hook(generic_set_add
);
5081 route_map_no_set_metric_hook(generic_set_delete
);
5083 route_map_set_tag_hook(generic_set_add
);
5084 route_map_no_set_tag_hook(generic_set_delete
);
5086 route_map_install_match(&route_match_peer_cmd
);
5087 route_map_install_match(&route_match_local_pref_cmd
);
5088 #if defined(HAVE_LUA)
5089 route_map_install_match(&route_match_command_cmd
);
5091 route_map_install_match(&route_match_ip_address_cmd
);
5092 route_map_install_match(&route_match_ip_next_hop_cmd
);
5093 route_map_install_match(&route_match_ip_route_source_cmd
);
5094 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5095 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5096 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5097 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5098 route_map_install_match(&route_match_aspath_cmd
);
5099 route_map_install_match(&route_match_community_cmd
);
5100 route_map_install_match(&route_match_lcommunity_cmd
);
5101 route_map_install_match(&route_match_ecommunity_cmd
);
5102 route_map_install_match(&route_match_local_pref_cmd
);
5103 route_map_install_match(&route_match_metric_cmd
);
5104 route_map_install_match(&route_match_origin_cmd
);
5105 route_map_install_match(&route_match_probability_cmd
);
5106 route_map_install_match(&route_match_interface_cmd
);
5107 route_map_install_match(&route_match_tag_cmd
);
5108 route_map_install_match(&route_match_mac_address_cmd
);
5109 route_map_install_match(&route_match_evpn_vni_cmd
);
5110 route_map_install_match(&route_match_evpn_route_type_cmd
);
5111 route_map_install_match(&route_match_evpn_default_route_cmd
);
5112 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5114 route_map_install_set(&route_set_ip_nexthop_cmd
);
5115 route_map_install_set(&route_set_local_pref_cmd
);
5116 route_map_install_set(&route_set_weight_cmd
);
5117 route_map_install_set(&route_set_label_index_cmd
);
5118 route_map_install_set(&route_set_metric_cmd
);
5119 route_map_install_set(&route_set_aspath_prepend_cmd
);
5120 route_map_install_set(&route_set_aspath_exclude_cmd
);
5121 route_map_install_set(&route_set_origin_cmd
);
5122 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5123 route_map_install_set(&route_set_aggregator_as_cmd
);
5124 route_map_install_set(&route_set_community_cmd
);
5125 route_map_install_set(&route_set_community_delete_cmd
);
5126 route_map_install_set(&route_set_lcommunity_cmd
);
5127 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5128 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5129 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5130 route_map_install_set(&route_set_originator_id_cmd
);
5131 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5132 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5133 route_map_install_set(&route_set_tag_cmd
);
5134 route_map_install_set(&route_set_label_index_cmd
);
5136 install_element(RMAP_NODE
, &match_peer_cmd
);
5137 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5138 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5139 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5140 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5141 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5142 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5143 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5144 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5145 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5146 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5147 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5148 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5149 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5150 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5151 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5152 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5154 install_element(RMAP_NODE
, &match_aspath_cmd
);
5155 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5156 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5157 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5158 install_element(RMAP_NODE
, &match_community_cmd
);
5159 install_element(RMAP_NODE
, &no_match_community_cmd
);
5160 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5161 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5162 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5163 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5164 install_element(RMAP_NODE
, &match_origin_cmd
);
5165 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5166 install_element(RMAP_NODE
, &match_probability_cmd
);
5167 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5169 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5170 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5171 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5172 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5173 install_element(RMAP_NODE
, &set_weight_cmd
);
5174 install_element(RMAP_NODE
, &set_label_index_cmd
);
5175 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5176 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5177 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5178 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5179 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5180 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5181 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
5182 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5183 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5184 install_element(RMAP_NODE
, &set_origin_cmd
);
5185 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5186 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5187 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5188 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5189 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5190 install_element(RMAP_NODE
, &set_community_cmd
);
5191 install_element(RMAP_NODE
, &set_community_none_cmd
);
5192 install_element(RMAP_NODE
, &no_set_community_cmd
);
5193 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5194 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5195 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5196 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5197 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5198 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5199 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5200 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5201 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5202 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5203 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5204 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5205 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5206 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5207 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5208 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5209 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5210 #ifdef KEEP_OLD_VPN_COMMANDS
5211 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5212 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5213 #endif /* KEEP_OLD_VPN_COMMANDS */
5214 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5215 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5216 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5217 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5219 route_map_install_match(&route_match_ipv6_address_cmd
);
5220 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5221 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5222 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5223 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5224 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5225 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5226 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5228 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5229 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5230 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5231 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5232 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5233 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5234 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5235 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5236 #if defined(HAVE_LUA)
5237 install_element(RMAP_NODE
, &match_command_cmd
);
5238 install_element(RMAP_NODE
, &no_match_command_cmd
);
5242 void bgp_route_map_terminate(void)
5244 /* ToDo: Cleanup all the used memory */