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
);
1214 * In routemap processing there is a need to add the
1215 * name as a rule_key in the dependency table. Routemap
1216 * lib is unaware of rule_key when exact-match clause
1217 * is in use. routemap lib uses the compiled output to
1218 * get the rule_key value.
1220 static void *route_match_get_community_key(void *rule
)
1222 struct rmap_community
*rcom
;
1229 /* Route map commands for community matching. */
1230 struct route_map_rule_cmd route_match_community_cmd
= {
1231 "community", route_match_community
, route_match_community_compile
,
1232 route_match_community_free
, route_match_get_community_key
};
1234 /* Match function for lcommunity match. */
1235 static enum route_map_cmd_result_t
1236 route_match_lcommunity(void *rule
, const struct prefix
*prefix
,
1237 route_map_object_t type
, void *object
)
1239 struct community_list
*list
;
1240 struct bgp_path_info
*path
;
1241 struct rmap_community
*rcom
= rule
;
1243 if (type
== RMAP_BGP
) {
1246 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1248 LARGE_COMMUNITY_LIST_MASTER
);
1250 return RMAP_NOMATCH
;
1253 if (lcommunity_list_exact_match(
1254 path
->attr
->lcommunity
,
1258 if (lcommunity_list_match(
1259 path
->attr
->lcommunity
,
1264 return RMAP_NOMATCH
;
1267 /* Compile function for community match. */
1268 static void *route_match_lcommunity_compile(const char *arg
)
1270 struct rmap_community
*rcom
;
1274 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1276 p
= strchr(arg
, ' ');
1279 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1280 memcpy(rcom
->name
, arg
, len
);
1283 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1287 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1291 /* Compile function for community match. */
1292 static void route_match_lcommunity_free(void *rule
)
1294 struct rmap_community
*rcom
= rule
;
1296 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1297 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1300 /* Route map commands for community matching. */
1301 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1302 "large-community", route_match_lcommunity
,
1303 route_match_lcommunity_compile
, route_match_lcommunity_free
,
1304 route_match_get_community_key
};
1307 /* Match function for extcommunity match. */
1308 static enum route_map_cmd_result_t
1309 route_match_ecommunity(void *rule
, const struct prefix
*prefix
,
1310 route_map_object_t type
, void *object
)
1312 struct community_list
*list
;
1313 struct bgp_path_info
*path
;
1314 struct rmap_community
*rcom
= rule
;
1316 if (type
== RMAP_BGP
) {
1319 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1321 EXTCOMMUNITY_LIST_MASTER
);
1323 return RMAP_NOMATCH
;
1325 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1328 return RMAP_NOMATCH
;
1331 /* Compile function for extcommunity match. */
1332 static void *route_match_ecommunity_compile(const char *arg
)
1334 struct rmap_community
*rcom
;
1336 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1337 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1338 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1343 /* Compile function for extcommunity match. */
1344 static void route_match_ecommunity_free(void *rule
)
1346 struct rmap_community
*rcom
= rule
;
1348 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1349 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1352 /* Route map commands for community matching. */
1353 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1354 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1355 route_match_ecommunity_free
};
1357 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1358 and `address-family vpnv4'. */
1360 /* `match origin' */
1361 static enum route_map_cmd_result_t
1362 route_match_origin(void *rule
, const struct prefix
*prefix
,
1363 route_map_object_t type
, void *object
)
1366 struct bgp_path_info
*path
;
1368 if (type
== RMAP_BGP
) {
1372 if (path
->attr
->origin
== *origin
)
1376 return RMAP_NOMATCH
;
1379 static void *route_match_origin_compile(const char *arg
)
1383 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1385 if (strcmp(arg
, "igp") == 0)
1387 else if (strcmp(arg
, "egp") == 0)
1395 /* Free route map's compiled `ip address' value. */
1396 static void route_match_origin_free(void *rule
)
1398 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1401 /* Route map commands for origin matching. */
1402 struct route_map_rule_cmd route_match_origin_cmd
= {
1403 "origin", route_match_origin
, route_match_origin_compile
,
1404 route_match_origin_free
};
1406 /* match probability { */
1408 static enum route_map_cmd_result_t
1409 route_match_probability(void *rule
, const struct prefix
*prefix
,
1410 route_map_object_t type
, void *object
)
1414 switch (*(long *)rule
) {
1420 if (r
< *(long *)rule
) {
1425 return RMAP_NOMATCH
;
1428 static void *route_match_probability_compile(const char *arg
)
1434 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1444 *lobule
= RAND_MAX
/ 100 * perc
;
1450 static void route_match_probability_free(void *rule
)
1452 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1455 struct route_map_rule_cmd route_match_probability_cmd
= {
1456 "probability", route_match_probability
, route_match_probability_compile
,
1457 route_match_probability_free
};
1459 /* `match interface IFNAME' */
1460 /* Match function should return 1 if match is success else return
1462 static enum route_map_cmd_result_t
1463 route_match_interface(void *rule
, const struct prefix
*prefix
,
1464 route_map_object_t type
, void *object
)
1466 struct interface
*ifp
;
1467 struct bgp_path_info
*path
;
1469 if (type
== RMAP_BGP
) {
1472 if (!path
|| !path
->attr
)
1473 return RMAP_NOMATCH
;
1475 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1477 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1478 return RMAP_NOMATCH
;
1482 return RMAP_NOMATCH
;
1485 /* Route map `interface' match statement. `arg' should be
1487 static void *route_match_interface_compile(const char *arg
)
1489 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1492 /* Free route map's compiled `interface' value. */
1493 static void route_match_interface_free(void *rule
)
1495 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1498 /* Route map commands for ip address matching. */
1499 struct route_map_rule_cmd route_match_interface_cmd
= {
1500 "interface", route_match_interface
, route_match_interface_compile
,
1501 route_match_interface_free
};
1505 /* `set ip next-hop IP_ADDRESS' */
1507 /* Match function return 1 if match is success else return zero. */
1508 static enum route_map_cmd_result_t
1509 route_match_tag(void *rule
, const struct prefix
*prefix
,
1510 route_map_object_t type
, void *object
)
1513 struct bgp_path_info
*path
;
1515 if (type
== RMAP_BGP
) {
1519 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1522 return RMAP_NOMATCH
;
1526 /* Route map commands for tag matching. */
1527 static struct route_map_rule_cmd route_match_tag_cmd
= {
1528 "tag", route_match_tag
, route_map_rule_tag_compile
,
1529 route_map_rule_tag_free
,
1533 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1534 struct rmap_ip_nexthop_set
{
1535 struct in_addr
*address
;
1540 static enum route_map_cmd_result_t
1541 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
,
1542 route_map_object_t type
, void *object
)
1544 struct rmap_ip_nexthop_set
*rins
= rule
;
1545 struct bgp_path_info
*path
;
1548 if (type
!= RMAP_BGP
)
1551 if (prefix
->family
== AF_INET6
)
1557 if (rins
->unchanged
) {
1558 SET_FLAG(path
->attr
->rmap_change_flags
,
1559 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1560 } else if (rins
->peer_address
) {
1561 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1562 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1564 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1565 path
->attr
->nexthop
.s_addr
=
1566 sockunion2ip(peer
->su_remote
);
1567 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1568 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1569 /* The next hop value will be set as part of
1570 * packet rewrite. Set the flags here to indicate
1571 * that rewrite needs to be done.
1572 * Also, clear the value.
1574 SET_FLAG(path
->attr
->rmap_change_flags
,
1575 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1576 path
->attr
->nexthop
.s_addr
= 0;
1579 /* Set next hop value. */
1580 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1581 path
->attr
->nexthop
= *rins
->address
;
1582 SET_FLAG(path
->attr
->rmap_change_flags
,
1583 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1584 /* case for MP-BGP : MPLS VPN */
1585 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1586 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1592 /* Route map `ip nexthop' compile function. Given string is converted
1593 to struct in_addr structure. */
1594 static void *route_set_ip_nexthop_compile(const char *arg
)
1596 struct rmap_ip_nexthop_set
*rins
;
1597 struct in_addr
*address
= NULL
;
1598 int peer_address
= 0;
1602 if (strcmp(arg
, "peer-address") == 0)
1604 else if (strcmp(arg
, "unchanged") == 0)
1607 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1608 sizeof(struct in_addr
));
1609 ret
= inet_aton(arg
, address
);
1612 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1617 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1618 sizeof(struct rmap_ip_nexthop_set
));
1620 rins
->address
= address
;
1621 rins
->peer_address
= peer_address
;
1622 rins
->unchanged
= unchanged
;
1627 /* Free route map's compiled `ip nexthop' value. */
1628 static void route_set_ip_nexthop_free(void *rule
)
1630 struct rmap_ip_nexthop_set
*rins
= rule
;
1632 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1634 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1637 /* Route map commands for ip nexthop set. */
1638 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1639 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1640 route_set_ip_nexthop_free
};
1642 /* `set local-preference LOCAL_PREF' */
1644 /* Set local preference. */
1645 static enum route_map_cmd_result_t
1646 route_set_local_pref(void *rule
, const struct prefix
*prefix
,
1647 route_map_object_t type
, void *object
)
1649 struct rmap_value
*rv
;
1650 struct bgp_path_info
*path
;
1651 uint32_t locpref
= 0;
1653 if (type
== RMAP_BGP
) {
1654 /* Fetch routemap's rule information. */
1658 /* Set local preference value. */
1659 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1660 locpref
= path
->attr
->local_pref
;
1662 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1663 path
->attr
->local_pref
=
1664 route_value_adjust(rv
, locpref
, path
->peer
);
1670 /* Set local preference rule structure. */
1671 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1672 "local-preference", route_set_local_pref
, route_value_compile
,
1676 /* `set weight WEIGHT' */
1679 static enum route_map_cmd_result_t
1680 route_set_weight(void *rule
, const struct prefix
*prefix
,
1681 route_map_object_t type
, void *object
)
1683 struct rmap_value
*rv
;
1684 struct bgp_path_info
*path
;
1686 if (type
== RMAP_BGP
) {
1687 /* Fetch routemap's rule information. */
1691 /* Set weight value. */
1692 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1698 /* Set local preference rule structure. */
1699 struct route_map_rule_cmd route_set_weight_cmd
= {
1700 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1703 /* `set metric METRIC' */
1705 /* Set metric to attribute. */
1706 static enum route_map_cmd_result_t
1707 route_set_metric(void *rule
, const struct prefix
*prefix
,
1708 route_map_object_t type
, void *object
)
1710 struct rmap_value
*rv
;
1711 struct bgp_path_info
*path
;
1714 if (type
== RMAP_BGP
) {
1715 /* Fetch routemap's rule information. */
1719 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1720 med
= path
->attr
->med
;
1722 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1723 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1728 /* Set metric rule structure. */
1729 struct route_map_rule_cmd route_set_metric_cmd
= {
1730 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1733 /* `set as-path prepend ASPATH' */
1735 /* For AS path prepend mechanism. */
1736 static enum route_map_cmd_result_t
1737 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
,
1738 route_map_object_t type
, void *object
)
1740 struct aspath
*aspath
;
1742 struct bgp_path_info
*path
;
1744 if (type
== RMAP_BGP
) {
1747 if (path
->attr
->aspath
->refcnt
)
1748 new = aspath_dup(path
->attr
->aspath
);
1750 new = path
->attr
->aspath
;
1752 if ((uintptr_t)rule
> 10) {
1754 aspath_prepend(aspath
, new);
1756 as_t as
= aspath_leftmost(new);
1758 as
= path
->peer
->as
;
1759 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1762 path
->attr
->aspath
= new;
1768 static void *route_set_aspath_prepend_compile(const char *arg
)
1772 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1773 return (void *)(uintptr_t)num
;
1775 return route_aspath_compile(arg
);
1778 static void route_set_aspath_prepend_free(void *rule
)
1780 if ((uintptr_t)rule
> 10)
1781 route_aspath_free(rule
);
1785 /* Set as-path prepend rule structure. */
1786 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1787 "as-path prepend", route_set_aspath_prepend
,
1788 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1791 /* `set as-path exclude ASn' */
1793 /* For ASN exclude mechanism.
1794 * Iterate over ASns requested and filter them from the given AS_PATH one by
1796 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1798 static enum route_map_cmd_result_t
1799 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
,
1800 route_map_object_t type
, void *object
)
1802 struct aspath
*new_path
, *exclude_path
;
1803 struct bgp_path_info
*path
;
1805 if (type
== RMAP_BGP
) {
1806 exclude_path
= rule
;
1808 if (path
->attr
->aspath
->refcnt
)
1809 new_path
= aspath_dup(path
->attr
->aspath
);
1811 new_path
= path
->attr
->aspath
;
1812 path
->attr
->aspath
=
1813 aspath_filter_exclude(new_path
, exclude_path
);
1818 /* Set ASn exlude rule structure. */
1819 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1820 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1824 /* `set community COMMUNITY' */
1825 struct rmap_com_set
{
1826 struct community
*com
;
1831 /* For community set mechanism. */
1832 static enum route_map_cmd_result_t
1833 route_set_community(void *rule
, const struct prefix
*prefix
,
1834 route_map_object_t type
, void *object
)
1836 struct rmap_com_set
*rcs
;
1837 struct bgp_path_info
*path
;
1839 struct community
*new = NULL
;
1840 struct community
*old
;
1841 struct community
*merge
;
1843 if (type
== RMAP_BGP
) {
1847 old
= attr
->community
;
1851 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1852 attr
->community
= NULL
;
1853 /* See the longer comment down below. */
1854 if (old
&& old
->refcnt
== 0)
1855 community_free(&old
);
1859 /* "additive" case. */
1860 if (rcs
->additive
&& old
) {
1861 merge
= community_merge(community_dup(old
), rcs
->com
);
1863 new = community_uniq_sort(merge
);
1864 community_free(&merge
);
1866 new = community_dup(rcs
->com
);
1868 /* HACK: if the old community is not intern'd,
1869 * we should free it here, or all reference to it may be
1871 * Really need to cleanup attribute caching sometime.
1873 if (old
&& old
->refcnt
== 0)
1874 community_free(&old
);
1876 /* will be interned by caller if required */
1877 attr
->community
= new;
1879 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1885 /* Compile function for set community. */
1886 static void *route_set_community_compile(const char *arg
)
1888 struct rmap_com_set
*rcs
;
1889 struct community
*com
= NULL
;
1894 if (strcmp(arg
, "none") == 0)
1897 sp
= strstr(arg
, "additive");
1899 if (sp
&& sp
> arg
) {
1900 /* "additive" keyword is included. */
1905 com
= community_str2com(arg
);
1914 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1916 rcs
->additive
= additive
;
1922 /* Free function for set community. */
1923 static void route_set_community_free(void *rule
)
1925 struct rmap_com_set
*rcs
= rule
;
1928 community_free(&rcs
->com
);
1929 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1932 /* Set community rule structure. */
1933 struct route_map_rule_cmd route_set_community_cmd
= {
1934 "community", route_set_community
, route_set_community_compile
,
1935 route_set_community_free
,
1938 /* `set community COMMUNITY' */
1939 struct rmap_lcom_set
{
1940 struct lcommunity
*lcom
;
1946 /* For lcommunity set mechanism. */
1947 static enum route_map_cmd_result_t
1948 route_set_lcommunity(void *rule
, const struct prefix
*prefix
,
1949 route_map_object_t type
, void *object
)
1951 struct rmap_lcom_set
*rcs
;
1952 struct bgp_path_info
*path
;
1954 struct lcommunity
*new = NULL
;
1955 struct lcommunity
*old
;
1956 struct lcommunity
*merge
;
1958 if (type
== RMAP_BGP
) {
1962 old
= attr
->lcommunity
;
1967 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
1968 attr
->lcommunity
= NULL
;
1970 /* See the longer comment down below. */
1971 if (old
&& old
->refcnt
== 0)
1972 lcommunity_free(&old
);
1976 if (rcs
->additive
&& old
) {
1977 merge
= lcommunity_merge(lcommunity_dup(old
),
1980 new = lcommunity_uniq_sort(merge
);
1981 lcommunity_free(&merge
);
1983 new = lcommunity_dup(rcs
->lcom
);
1985 /* HACK: if the old large-community is not intern'd,
1986 * we should free it here, or all reference to it may be
1988 * Really need to cleanup attribute caching sometime.
1990 if (old
&& old
->refcnt
== 0)
1991 lcommunity_free(&old
);
1993 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1994 attr
->lcommunity
= new;
1996 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2002 /* Compile function for set community. */
2003 static void *route_set_lcommunity_compile(const char *arg
)
2005 struct rmap_lcom_set
*rcs
;
2006 struct lcommunity
*lcom
= NULL
;
2011 if (strcmp(arg
, "none") == 0)
2014 sp
= strstr(arg
, "additive");
2016 if (sp
&& sp
> arg
) {
2017 /* "additive" keyworkd is included. */
2022 lcom
= lcommunity_str2com(arg
);
2031 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2033 rcs
->additive
= additive
;
2039 /* Free function for set lcommunity. */
2040 static void route_set_lcommunity_free(void *rule
)
2042 struct rmap_lcom_set
*rcs
= rule
;
2045 lcommunity_free(&rcs
->lcom
);
2047 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2050 /* Set community rule structure. */
2051 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2052 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
2053 route_set_lcommunity_free
,
2056 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2058 /* For large community set mechanism. */
2059 static enum route_map_cmd_result_t
2060 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
,
2061 route_map_object_t type
, void *object
)
2063 struct community_list
*list
;
2064 struct lcommunity
*merge
;
2065 struct lcommunity
*new;
2066 struct lcommunity
*old
;
2067 struct bgp_path_info
*path
;
2068 struct rmap_community
*rcom
= rule
;
2070 if (type
== RMAP_BGP
) {
2075 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2077 LARGE_COMMUNITY_LIST_MASTER
);
2078 old
= path
->attr
->lcommunity
;
2081 merge
= lcommunity_list_match_delete(
2082 lcommunity_dup(old
), list
);
2083 new = lcommunity_uniq_sort(merge
);
2084 lcommunity_free(&merge
);
2086 /* HACK: if the old community is not intern'd,
2087 * we should free it here, or all reference to it may be
2089 * Really need to cleanup attribute caching sometime.
2091 if (old
->refcnt
== 0)
2092 lcommunity_free(&old
);
2094 if (new->size
== 0) {
2095 path
->attr
->lcommunity
= NULL
;
2096 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2097 BGP_ATTR_LARGE_COMMUNITIES
);
2098 lcommunity_free(&new);
2100 path
->attr
->lcommunity
= new;
2101 path
->attr
->flag
|= ATTR_FLAG_BIT(
2102 BGP_ATTR_LARGE_COMMUNITIES
);
2110 /* Compile function for set lcommunity. */
2111 static void *route_set_lcommunity_delete_compile(const char *arg
)
2113 struct rmap_community
*rcom
;
2117 frrstr_split(arg
, " ", &splits
, &num
);
2119 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2120 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2121 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2123 for (int i
= 0; i
< num
; i
++)
2124 XFREE(MTYPE_TMP
, splits
[i
]);
2125 XFREE(MTYPE_TMP
, splits
);
2130 /* Free function for set lcommunity. */
2131 static void route_set_lcommunity_delete_free(void *rule
)
2133 struct rmap_community
*rcom
= rule
;
2135 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2136 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2139 /* Set lcommunity rule structure. */
2140 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2141 "large-comm-list", route_set_lcommunity_delete
,
2142 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2146 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2148 /* For community set mechanism. */
2149 static enum route_map_cmd_result_t
2150 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2151 route_map_object_t type
, void *object
)
2153 struct community_list
*list
;
2154 struct community
*merge
;
2155 struct community
*new;
2156 struct community
*old
;
2157 struct bgp_path_info
*path
;
2158 struct rmap_community
*rcom
= rule
;
2160 if (type
== RMAP_BGP
) {
2165 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2167 COMMUNITY_LIST_MASTER
);
2168 old
= path
->attr
->community
;
2171 merge
= community_list_match_delete(community_dup(old
),
2173 new = community_uniq_sort(merge
);
2174 community_free(&merge
);
2176 /* HACK: if the old community is not intern'd,
2177 * we should free it here, or all reference to it may be
2179 * Really need to cleanup attribute caching sometime.
2181 if (old
->refcnt
== 0)
2182 community_free(&old
);
2184 if (new->size
== 0) {
2185 path
->attr
->community
= NULL
;
2187 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2188 community_free(&new);
2190 path
->attr
->community
= new;
2192 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2200 /* Compile function for set community. */
2201 static void *route_set_community_delete_compile(const char *arg
)
2203 struct rmap_community
*rcom
;
2207 frrstr_split(arg
, " ", &splits
, &num
);
2209 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2210 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2211 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2213 for (int i
= 0; i
< num
; i
++)
2214 XFREE(MTYPE_TMP
, splits
[i
]);
2215 XFREE(MTYPE_TMP
, splits
);
2220 /* Free function for set community. */
2221 static void route_set_community_delete_free(void *rule
)
2223 struct rmap_community
*rcom
= rule
;
2225 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2226 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2229 /* Set community rule structure. */
2230 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2231 "comm-list", route_set_community_delete
,
2232 route_set_community_delete_compile
, route_set_community_delete_free
,
2235 /* `set extcommunity rt COMMUNITY' */
2237 /* For community set mechanism. Used by _rt and _soo. */
2238 static enum route_map_cmd_result_t
2239 route_set_ecommunity(void *rule
, const struct prefix
*prefix
,
2240 route_map_object_t type
, void *object
)
2242 struct ecommunity
*ecom
;
2243 struct ecommunity
*new_ecom
;
2244 struct ecommunity
*old_ecom
;
2245 struct bgp_path_info
*path
;
2247 if (type
== RMAP_BGP
) {
2254 /* We assume additive for Extended Community. */
2255 old_ecom
= path
->attr
->ecommunity
;
2258 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2261 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2262 * bgp_update_receive()
2263 * ->refcnt = 0 => set by a previous route-map
2265 if (!old_ecom
->refcnt
)
2266 ecommunity_free(&old_ecom
);
2268 new_ecom
= ecommunity_dup(ecom
);
2270 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2271 path
->attr
->ecommunity
= new_ecom
;
2273 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2278 /* Compile function for set community. */
2279 static void *route_set_ecommunity_rt_compile(const char *arg
)
2281 struct ecommunity
*ecom
;
2283 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2286 return ecommunity_intern(ecom
);
2289 /* Free function for set community. Used by _rt and _soo */
2290 static void route_set_ecommunity_free(void *rule
)
2292 struct ecommunity
*ecom
= rule
;
2293 ecommunity_unintern(&ecom
);
2296 /* Set community rule structure. */
2297 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2298 "extcommunity rt", route_set_ecommunity
,
2299 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2302 /* `set extcommunity soo COMMUNITY' */
2304 /* Compile function for set community. */
2305 static void *route_set_ecommunity_soo_compile(const char *arg
)
2307 struct ecommunity
*ecom
;
2309 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2313 return ecommunity_intern(ecom
);
2316 /* Set community rule structure. */
2317 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2318 "extcommunity soo", route_set_ecommunity
,
2319 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2322 /* `set origin ORIGIN' */
2324 /* For origin set. */
2325 static enum route_map_cmd_result_t
2326 route_set_origin(void *rule
, const struct prefix
*prefix
,
2327 route_map_object_t type
, void *object
)
2330 struct bgp_path_info
*path
;
2332 if (type
== RMAP_BGP
) {
2336 path
->attr
->origin
= *origin
;
2342 /* Compile function for origin set. */
2343 static void *route_set_origin_compile(const char *arg
)
2347 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2349 if (strcmp(arg
, "igp") == 0)
2351 else if (strcmp(arg
, "egp") == 0)
2359 /* Compile function for origin set. */
2360 static void route_set_origin_free(void *rule
)
2362 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2365 /* Set origin rule structure. */
2366 struct route_map_rule_cmd route_set_origin_cmd
= {
2367 "origin", route_set_origin
, route_set_origin_compile
,
2368 route_set_origin_free
,
2371 /* `set atomic-aggregate' */
2373 /* For atomic aggregate set. */
2374 static enum route_map_cmd_result_t
2375 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
,
2376 route_map_object_t type
, void *object
)
2378 struct bgp_path_info
*path
;
2380 if (type
== RMAP_BGP
) {
2382 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2388 /* Compile function for atomic aggregate. */
2389 static void *route_set_atomic_aggregate_compile(const char *arg
)
2394 /* Compile function for atomic aggregate. */
2395 static void route_set_atomic_aggregate_free(void *rule
)
2400 /* Set atomic aggregate rule structure. */
2401 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2402 "atomic-aggregate", route_set_atomic_aggregate
,
2403 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2406 /* `set aggregator as AS A.B.C.D' */
2409 struct in_addr address
;
2412 static enum route_map_cmd_result_t
2413 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
,
2414 route_map_object_t type
, void *object
)
2416 struct bgp_path_info
*path
;
2417 struct aggregator
*aggregator
;
2419 if (type
== RMAP_BGP
) {
2423 path
->attr
->aggregator_as
= aggregator
->as
;
2424 path
->attr
->aggregator_addr
= aggregator
->address
;
2425 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2431 static void *route_set_aggregator_as_compile(const char *arg
)
2433 struct aggregator
*aggregator
;
2439 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2440 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2441 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2445 aggregator
->as
= strtoul(as
, NULL
, 10);
2446 ret
= inet_aton(address
, &aggregator
->address
);
2448 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2454 static void route_set_aggregator_as_free(void *rule
)
2456 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2459 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2460 "aggregator as", route_set_aggregator_as
,
2461 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2464 /* Set tag to object. object must be pointer to struct bgp_path_info */
2465 static enum route_map_cmd_result_t
2466 route_set_tag(void *rule
, const struct prefix
*prefix
,
2467 route_map_object_t type
, void *object
)
2470 struct bgp_path_info
*path
;
2472 if (type
== RMAP_BGP
) {
2477 path
->attr
->tag
= *tag
;
2483 /* Route map commands for tag set. */
2484 static struct route_map_rule_cmd route_set_tag_cmd
= {
2485 "tag", route_set_tag
, route_map_rule_tag_compile
,
2486 route_map_rule_tag_free
,
2489 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2490 static enum route_map_cmd_result_t
2491 route_set_label_index(void *rule
, const struct prefix
*prefix
,
2492 route_map_object_t type
, void *object
)
2494 struct rmap_value
*rv
;
2495 struct bgp_path_info
*path
;
2496 uint32_t label_index
;
2498 if (type
== RMAP_BGP
) {
2499 /* Fetch routemap's rule information. */
2503 /* Set label-index value. */
2504 label_index
= rv
->value
;
2506 path
->attr
->label_index
= label_index
;
2507 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2514 /* Route map commands for label-index set. */
2515 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2516 "label-index", route_set_label_index
, route_value_compile
,
2520 /* `match ipv6 address IP_ACCESS_LIST' */
2522 static enum route_map_cmd_result_t
2523 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
,
2524 route_map_object_t type
, void *object
)
2526 struct access_list
*alist
;
2528 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2529 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2531 return RMAP_NOMATCH
;
2533 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2537 return RMAP_NOMATCH
;
2540 static void *route_match_ipv6_address_compile(const char *arg
)
2542 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2545 static void route_match_ipv6_address_free(void *rule
)
2547 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2550 /* Route map commands for ip address matching. */
2551 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2552 "ipv6 address", route_match_ipv6_address
,
2553 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2555 /* `match ipv6 next-hop IP_ADDRESS' */
2557 static enum route_map_cmd_result_t
2558 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
,
2559 route_map_object_t type
, void *object
)
2561 struct in6_addr
*addr
= rule
;
2562 struct bgp_path_info
*path
;
2564 if (type
== RMAP_BGP
) {
2567 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2570 if (path
->attr
->mp_nexthop_len
2571 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2572 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2575 return RMAP_NOMATCH
;
2578 return RMAP_NOMATCH
;
2581 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2583 struct in6_addr
*address
;
2586 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2588 ret
= inet_pton(AF_INET6
, arg
, address
);
2590 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2597 static void route_match_ipv6_next_hop_free(void *rule
)
2599 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2602 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2603 "ipv6 next-hop", route_match_ipv6_next_hop
,
2604 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2606 /* `match ipv6 address prefix-list PREFIX_LIST' */
2608 static enum route_map_cmd_result_t
2609 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2610 route_map_object_t type
, void *object
)
2612 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, type
,
2616 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2618 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2621 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2623 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2626 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2627 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2628 route_match_ipv6_address_prefix_list_compile
,
2629 route_match_ipv6_address_prefix_list_free
};
2631 /* `match ipv6 next-hop type <TYPE>' */
2633 static enum route_map_cmd_result_t
2634 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2635 route_map_object_t type
, void *object
)
2637 struct bgp_path_info
*path
;
2638 struct in6_addr
*addr
= rule
;
2640 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2641 path
= (struct bgp_path_info
*)object
;
2642 if (!path
|| !path
->attr
)
2643 return RMAP_NOMATCH
;
2645 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2646 && !path
->attr
->nh_ifindex
)
2649 return RMAP_NOMATCH
;
2652 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2654 struct in6_addr
*address
;
2657 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2659 ret
= inet_pton(AF_INET6
, "::0", address
);
2661 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2668 static void route_match_ipv6_next_hop_type_free(void *rule
)
2670 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2673 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2674 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2675 route_match_ipv6_next_hop_type_compile
,
2676 route_match_ipv6_next_hop_type_free
};
2678 /* `set ipv6 nexthop global IP_ADDRESS' */
2680 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2681 static enum route_map_cmd_result_t
2682 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
,
2683 route_map_object_t type
, void *object
)
2685 struct in6_addr
*address
;
2686 struct bgp_path_info
*path
;
2688 if (type
== RMAP_BGP
) {
2689 /* Fetch routemap's rule information. */
2693 /* Set next hop value. */
2694 path
->attr
->mp_nexthop_global
= *address
;
2696 /* Set nexthop length. */
2697 if (path
->attr
->mp_nexthop_len
== 0)
2698 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2700 SET_FLAG(path
->attr
->rmap_change_flags
,
2701 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2707 /* Route map `ip next-hop' compile function. Given string is converted
2708 to struct in_addr structure. */
2709 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2712 struct in6_addr
*address
;
2714 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2716 ret
= inet_pton(AF_INET6
, arg
, address
);
2719 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2726 /* Free route map's compiled `ip next-hop' value. */
2727 static void route_set_ipv6_nexthop_global_free(void *rule
)
2729 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2732 /* Route map commands for ip nexthop set. */
2733 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2734 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2735 route_set_ipv6_nexthop_global_compile
,
2736 route_set_ipv6_nexthop_global_free
};
2738 /* Set next-hop preference value. */
2739 static enum route_map_cmd_result_t
2740 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2741 route_map_object_t type
, void *object
)
2743 struct bgp_path_info
*path
;
2746 if (type
== RMAP_BGP
) {
2747 /* Fetch routemap's rule information. */
2751 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2752 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2754 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2755 /* Set next hop preference to global */
2756 path
->attr
->mp_nexthop_prefer_global
= true;
2757 SET_FLAG(path
->attr
->rmap_change_flags
,
2758 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2760 path
->attr
->mp_nexthop_prefer_global
= false;
2761 SET_FLAG(path
->attr
->rmap_change_flags
,
2762 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2768 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2772 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2778 /* Free route map's compiled `ip next-hop' value. */
2779 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2781 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2784 /* Route map commands for ip nexthop set preferred. */
2785 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2786 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2787 route_set_ipv6_nexthop_prefer_global_compile
,
2788 route_set_ipv6_nexthop_prefer_global_free
};
2790 /* `set ipv6 nexthop local IP_ADDRESS' */
2792 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2793 static enum route_map_cmd_result_t
2794 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
,
2795 route_map_object_t type
, void *object
)
2797 struct in6_addr
*address
;
2798 struct bgp_path_info
*path
;
2800 if (type
== RMAP_BGP
) {
2801 /* Fetch routemap's rule information. */
2805 /* Set next hop value. */
2806 path
->attr
->mp_nexthop_local
= *address
;
2808 /* Set nexthop length. */
2809 if (path
->attr
->mp_nexthop_len
2810 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2811 path
->attr
->mp_nexthop_len
=
2812 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2814 SET_FLAG(path
->attr
->rmap_change_flags
,
2815 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2821 /* Route map `ip nexthop' compile function. Given string is converted
2822 to struct in_addr structure. */
2823 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2826 struct in6_addr
*address
;
2828 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2830 ret
= inet_pton(AF_INET6
, arg
, address
);
2833 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2840 /* Free route map's compiled `ip nexthop' value. */
2841 static void route_set_ipv6_nexthop_local_free(void *rule
)
2843 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2846 /* Route map commands for ip nexthop set. */
2847 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2848 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2849 route_set_ipv6_nexthop_local_compile
,
2850 route_set_ipv6_nexthop_local_free
};
2852 /* `set ipv6 nexthop peer-address' */
2854 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2855 static enum route_map_cmd_result_t
2856 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
,
2857 route_map_object_t type
, void *object
)
2859 struct in6_addr peer_address
;
2860 struct bgp_path_info
*path
;
2863 if (type
== RMAP_BGP
) {
2864 /* Fetch routemap's rule information. */
2868 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2869 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2871 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2872 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2873 /* Set next hop value and length in attribute. */
2874 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2875 path
->attr
->mp_nexthop_local
= peer_address
;
2876 if (path
->attr
->mp_nexthop_len
!= 32)
2877 path
->attr
->mp_nexthop_len
= 32;
2879 path
->attr
->mp_nexthop_global
= peer_address
;
2880 if (path
->attr
->mp_nexthop_len
== 0)
2881 path
->attr
->mp_nexthop_len
= 16;
2884 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2885 /* The next hop value will be set as part of packet
2887 * Set the flags here to indicate that rewrite needs to
2889 * Also, clear the value - we clear both global and
2891 * nexthops, whether we send one or both is determined
2894 SET_FLAG(path
->attr
->rmap_change_flags
,
2895 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2896 /* clear next hop value. */
2897 memset(&(path
->attr
->mp_nexthop_global
), 0,
2898 sizeof(struct in6_addr
));
2899 memset(&(path
->attr
->mp_nexthop_local
), 0,
2900 sizeof(struct in6_addr
));
2907 /* Route map `ip next-hop' compile function. Given string is converted
2908 to struct in_addr structure. */
2909 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2913 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2919 /* Free route map's compiled `ip next-hop' value. */
2920 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2922 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2925 /* Route map commands for ip nexthop set. */
2926 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2927 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2928 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2930 /* `set ipv4 vpn next-hop A.B.C.D' */
2932 static enum route_map_cmd_result_t
2933 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
,
2934 route_map_object_t type
, void *object
)
2936 struct in_addr
*address
;
2937 struct bgp_path_info
*path
;
2939 if (type
== RMAP_BGP
) {
2940 /* Fetch routemap's rule information. */
2944 /* Set next hop value. */
2945 path
->attr
->mp_nexthop_global_in
= *address
;
2946 path
->attr
->mp_nexthop_len
= 4;
2952 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2955 struct in_addr
*address
;
2957 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2959 ret
= inet_aton(arg
, address
);
2962 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2969 /* `set ipv6 vpn next-hop A.B.C.D' */
2971 static enum route_map_cmd_result_t
2972 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
,
2973 route_map_object_t type
, void *object
)
2975 struct in6_addr
*address
;
2976 struct bgp_path_info
*path
;
2978 if (type
== RMAP_BGP
) {
2979 /* Fetch routemap's rule information. */
2983 /* Set next hop value. */
2984 memcpy(&path
->attr
->mp_nexthop_global
, address
,
2985 sizeof(struct in6_addr
));
2986 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2992 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2995 struct in6_addr
*address
;
2997 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2998 ret
= inet_pton(AF_INET6
, arg
, address
);
3001 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3008 static void route_set_vpn_nexthop_free(void *rule
)
3010 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3013 /* Route map commands for ipv4 next-hop set. */
3014 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3015 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
3016 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
3018 /* Route map commands for ipv6 next-hop set. */
3019 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3020 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
3021 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
3023 /* `set originator-id' */
3025 /* For origin set. */
3026 static enum route_map_cmd_result_t
3027 route_set_originator_id(void *rule
, const struct prefix
*prefix
,
3028 route_map_object_t type
, void *object
)
3030 struct in_addr
*address
;
3031 struct bgp_path_info
*path
;
3033 if (type
== RMAP_BGP
) {
3037 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3038 path
->attr
->originator_id
= *address
;
3044 /* Compile function for originator-id set. */
3045 static void *route_set_originator_id_compile(const char *arg
)
3048 struct in_addr
*address
;
3050 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3052 ret
= inet_aton(arg
, address
);
3055 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3062 /* Compile function for originator_id set. */
3063 static void route_set_originator_id_free(void *rule
)
3065 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3068 /* Set originator-id rule structure. */
3069 struct route_map_rule_cmd route_set_originator_id_cmd
= {
3070 "originator-id", route_set_originator_id
,
3071 route_set_originator_id_compile
, route_set_originator_id_free
,
3074 /* Add bgp route map rule. */
3075 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3076 const char *arg
, route_map_event_t type
)
3078 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3079 int retval
= CMD_SUCCESS
;
3080 enum rmap_compile_rets ret
;
3082 ret
= route_map_add_match(index
, command
, arg
, type
);
3084 case RMAP_RULE_MISSING
:
3085 vty_out(vty
, "%% BGP Can't find rule.\n");
3086 retval
= CMD_WARNING_CONFIG_FAILED
;
3088 case RMAP_COMPILE_ERROR
:
3089 vty_out(vty
, "%% BGP Argument is malformed.\n");
3090 retval
= CMD_WARNING_CONFIG_FAILED
;
3092 case RMAP_COMPILE_SUCCESS
:
3094 * Intentionally doing nothing here.
3102 /* Delete bgp route map rule. */
3103 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3104 const char *arg
, route_map_event_t type
)
3106 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3107 enum rmap_compile_rets ret
;
3108 int retval
= CMD_SUCCESS
;
3109 char *dep_name
= NULL
;
3111 char *rmap_name
= NULL
;
3113 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3114 /* ignore the mundane, the types without any dependency */
3116 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3119 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3121 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3123 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3126 ret
= route_map_delete_match(index
, command
, dep_name
, type
);
3128 case RMAP_RULE_MISSING
:
3129 vty_out(vty
, "%% BGP Can't find rule.\n");
3130 retval
= CMD_WARNING_CONFIG_FAILED
;
3132 case RMAP_COMPILE_ERROR
:
3133 vty_out(vty
, "%% BGP Argument is malformed.\n");
3134 retval
= CMD_WARNING_CONFIG_FAILED
;
3136 case RMAP_COMPILE_SUCCESS
:
3138 * Nothing to do here
3143 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3144 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3150 * This is the workhorse routine for processing in/out routemap
3153 static void bgp_route_map_process_peer(const char *rmap_name
,
3154 struct route_map
*map
, struct peer
*peer
,
3155 int afi
, int safi
, int route_update
)
3157 struct bgp_filter
*filter
;
3159 if (!peer
|| !rmap_name
)
3162 filter
= &peer
->filter
[afi
][safi
];
3164 * in is for non-route-server clients,
3165 * out is for all peers
3167 if (filter
->map
[RMAP_IN
].name
3168 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3169 filter
->map
[RMAP_IN
].map
= map
;
3171 if (route_update
&& peer
->status
== Established
) {
3172 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3173 PEER_FLAG_SOFT_RECONFIG
)) {
3174 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3176 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3177 rmap_name
, peer
->host
);
3179 bgp_soft_reconfig_in(peer
, afi
, safi
);
3180 } else if (CHECK_FLAG(peer
->cap
,
3181 PEER_CAP_REFRESH_OLD_RCV
)
3182 || CHECK_FLAG(peer
->cap
,
3183 PEER_CAP_REFRESH_NEW_RCV
)) {
3184 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3186 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3187 rmap_name
, peer
->host
);
3188 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3195 * For outbound, unsuppress and default-originate map change (content or
3196 * map created), merely update the "config" here, the actual route
3197 * announcement happens at the group level.
3199 if (filter
->map
[RMAP_OUT
].name
3200 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3201 filter
->map
[RMAP_OUT
].map
= map
;
3203 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3204 filter
->usmap
.map
= map
;
3206 if (peer
->default_rmap
[afi
][safi
].name
3207 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3208 peer
->default_rmap
[afi
][safi
].map
= map
;
3211 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3212 struct route_map
*map
,
3215 struct peer_group
*group
;
3216 struct listnode
*node
, *nnode
;
3217 struct bgp_filter
*filter
;
3224 /* All the peers have been updated correctly already. This is
3225 * just updating the placeholder data. No real update required.
3227 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3228 FOREACH_AFI_SAFI (afi
, safi
) {
3229 filter
= &group
->conf
->filter
[afi
][safi
];
3231 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3232 if ((filter
->map
[direct
].name
)
3233 && (strcmp(rmap_name
,
3234 filter
->map
[direct
].name
)
3236 filter
->map
[direct
].map
= map
;
3239 if (filter
->usmap
.name
3240 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3241 filter
->usmap
.map
= map
;
3247 * Note that if an extreme number (tens of thousands) of route-maps are in use
3248 * and if bgp has an extreme number of peers, network statements, etc then this
3249 * function can consume a lot of cycles. This is due to this function being
3250 * called for each route-map and within this function we walk the list of peers,
3251 * network statements, etc looking to see if they use this route-map.
3253 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3260 struct bgp_node
*bn
;
3261 struct bgp_static
*bgp_static
;
3262 struct bgp_aggregate
*aggregate
;
3263 struct listnode
*node
, *nnode
;
3264 struct route_map
*map
;
3265 char buf
[INET6_ADDRSTRLEN
];
3267 map
= route_map_lookup_by_name(rmap_name
);
3269 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3271 /* Ignore dummy peer-group structure */
3272 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3275 FOREACH_AFI_SAFI (afi
, safi
) {
3276 /* process in/out/import/export/default-orig
3278 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3279 safi
, route_update
);
3283 /* for outbound/default-orig route-maps, process for groups */
3284 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3287 /* update peer-group config (template) */
3288 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3290 FOREACH_AFI_SAFI (afi
, safi
) {
3291 /* For table route-map updates. */
3292 if (!bgp_fibupd_safi(safi
))
3295 if (bgp
->table_map
[afi
][safi
].name
3296 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3299 /* bgp->table_map[afi][safi].map is NULL.
3300 * i.e Route map creation event.
3301 * So update applied_counter.
3302 * If it is not NULL, i.e It may be routemap updation or
3303 * deletion. so no need to update the counter.
3305 if (!bgp
->table_map
[afi
][safi
].map
)
3306 route_map_counter_increment(map
);
3307 bgp
->table_map
[afi
][safi
].map
= map
;
3309 if (BGP_DEBUG(zebra
, ZEBRA
))
3311 "Processing route_map %s update on "
3315 bgp_zebra_announce_table(bgp
, afi
, safi
);
3318 /* For network route-map updates. */
3319 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3320 bn
= bgp_route_next(bn
)) {
3321 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3325 if (!bgp_static
->rmap
.name
3326 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3329 if (!bgp_static
->rmap
.map
)
3330 route_map_counter_increment(map
);
3332 bgp_static
->rmap
.map
= map
;
3334 if (route_update
&& !bgp_static
->backdoor
) {
3335 if (bgp_debug_zebra(&bn
->p
))
3337 "Processing route_map %s update on static route %s",
3339 inet_ntop(bn
->p
.family
,
3340 &bn
->p
.u
.prefix
, buf
,
3342 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3347 /* For aggregate-address route-map updates. */
3348 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
3349 bn
= bgp_route_next(bn
)) {
3350 aggregate
= bgp_node_get_bgp_aggregate_info(bn
);
3354 if (!aggregate
->rmap
.name
3355 || (strcmp(rmap_name
, aggregate
->rmap
.name
) != 0))
3358 if (!aggregate
->rmap
.map
)
3359 route_map_counter_increment(map
);
3361 aggregate
->rmap
.map
= map
;
3364 if (bgp_debug_zebra(&bn
->p
))
3366 "Processing route_map %s update on aggregate-address route %s",
3368 inet_ntop(bn
->p
.family
,
3369 &bn
->p
.u
.prefix
, buf
,
3371 bgp_aggregate_route(bgp
, &bn
->p
, afi
, safi
,
3377 /* For redistribute route-map updates. */
3378 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3379 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3380 struct list
*red_list
;
3381 struct bgp_redist
*red
;
3383 red_list
= bgp
->redist
[afi
][i
];
3387 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3389 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3393 route_map_counter_increment(map
);
3395 red
->rmap
.map
= map
;
3400 if (BGP_DEBUG(zebra
, ZEBRA
))
3402 "Processing route_map %s update on redistributed routes",
3405 bgp_redistribute_resend(bgp
, afi
, i
,
3410 /* for type5 command route-maps */
3411 FOREACH_AFI_SAFI (afi
, safi
) {
3412 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3413 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3417 /* Make sure the route-map is populated here if not already done */
3418 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3420 if (BGP_DEBUG(zebra
, ZEBRA
))
3422 "Processing route_map %s update on advertise type5 route command",
3425 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3426 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3427 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3432 static void bgp_route_map_process_update_cb(char *rmap_name
)
3434 struct listnode
*node
, *nnode
;
3437 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3438 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3441 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3442 vnc_routemap_update(bgp
, __func__
);
3446 vpn_policy_routemap_event(rmap_name
);
3449 int bgp_route_map_update_timer(struct thread
*thread
)
3451 bm
->t_rmap_update
= NULL
;
3453 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3458 static void bgp_route_map_mark_update(const char *rmap_name
)
3460 struct listnode
*node
, *nnode
;
3463 /* If new update is received before the current timer timed out,
3464 * turn it off and start a new timer.
3466 if (bm
->t_rmap_update
!= NULL
)
3467 THREAD_OFF(bm
->t_rmap_update
);
3469 /* rmap_update_timer of 0 means don't do route updates */
3470 if (bm
->rmap_update_timer
) {
3471 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3472 NULL
, bm
->rmap_update_timer
,
3473 &bm
->t_rmap_update
);
3475 /* Signal the groups that a route-map update event has
3477 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3478 update_group_policy_update(bgp
,
3479 BGP_POLICY_ROUTE_MAP
,
3482 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3483 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3485 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3486 vnc_routemap_update(bgp
, __func__
);
3491 static void bgp_route_map_add(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_ADDED
);
3499 static void bgp_route_map_delete(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_DELETED
);
3507 static void bgp_route_map_event(const char *rmap_name
)
3509 if (route_map_mark_updated(rmap_name
) == 0)
3510 bgp_route_map_mark_update(rmap_name
);
3512 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3515 DEFUN (match_mac_address
,
3516 match_mac_address_cmd
,
3517 "match mac address WORD",
3520 "Match address of route\n"
3521 "MAC Access-list name\n")
3523 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3524 RMAP_EVENT_FILTER_ADDED
);
3527 DEFUN (no_match_mac_address
,
3528 no_match_mac_address_cmd
,
3529 "no match mac address WORD",
3533 "Match address of route\n"
3534 "MAC acess-list name\n")
3536 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3537 RMAP_EVENT_FILTER_DELETED
);
3540 DEFUN (match_evpn_route_type
,
3541 match_evpn_route_type_cmd
,
3542 "match evpn route-type <macip | multicast | prefix>",
3545 "Match route-type\n"
3550 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3551 RMAP_EVENT_MATCH_ADDED
);
3554 DEFUN (no_match_evpn_route_type
,
3555 no_match_evpn_route_type_cmd
,
3556 "no match evpn route-type <macip | multicast | prefix>",
3560 "Match route-type\n"
3565 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3566 RMAP_EVENT_MATCH_DELETED
);
3570 DEFUN (match_evpn_vni
,
3572 "match evpn vni " CMD_VNI_RANGE
,
3578 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3579 RMAP_EVENT_MATCH_ADDED
);
3582 DEFUN (no_match_evpn_vni
,
3583 no_match_evpn_vni_cmd
,
3584 "no match evpn vni " CMD_VNI_RANGE
,
3591 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3592 RMAP_EVENT_MATCH_DELETED
);
3595 DEFUN (match_evpn_default_route
,
3596 match_evpn_default_route_cmd
,
3597 "match evpn default-route",
3600 "default EVPN type-5 route\n")
3602 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3603 RMAP_EVENT_MATCH_ADDED
);
3606 DEFUN (no_match_evpn_default_route
,
3607 no_match_evpn_default_route_cmd
,
3608 "no match evpn default-route",
3612 "default EVPN type-5 route\n")
3614 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3615 RMAP_EVENT_MATCH_DELETED
);
3618 DEFPY(match_vrl_source_vrf
,
3619 match_vrl_source_vrf_cmd
,
3620 "match source-vrf NAME$vrf_name",
3625 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3626 RMAP_EVENT_MATCH_ADDED
);
3629 DEFPY(no_match_vrl_source_vrf
,
3630 no_match_vrl_source_vrf_cmd
,
3631 "no match source-vrf NAME$vrf_name",
3637 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3638 RMAP_EVENT_MATCH_DELETED
);
3643 "match peer <A.B.C.D|X:X::X:X|WORD>",
3645 "Match peer address\n"
3646 "IP address of peer\n"
3647 "IPv6 address of peer\n"
3648 "Interface name of peer\n")
3651 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3652 RMAP_EVENT_MATCH_ADDED
);
3655 DEFUN (match_peer_local
,
3656 match_peer_local_cmd
,
3659 "Match peer address\n"
3660 "Static or Redistributed routes\n")
3662 return bgp_route_match_add(vty
, "peer", "local",
3663 RMAP_EVENT_MATCH_DELETED
);
3666 DEFUN (no_match_peer
,
3668 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3671 "Match peer address\n"
3672 "Static or Redistributed routes\n"
3673 "IP address of peer\n"
3674 "IPv6 address of peer\n"
3675 "Interface name of peer\n")
3679 if (argc
<= idx_peer
)
3680 return bgp_route_match_delete(vty
, "peer", NULL
,
3681 RMAP_EVENT_MATCH_DELETED
);
3682 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3683 RMAP_EVENT_MATCH_DELETED
);
3686 #if defined(HAVE_LUA)
3687 DEFUN (match_command
,
3689 "match command WORD",
3691 "Run a command to match\n"
3692 "The command to run\n")
3694 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3695 RMAP_EVENT_FILTER_ADDED
);
3698 DEFUN (no_match_command
,
3699 no_match_command_cmd
,
3700 "no match command WORD",
3703 "Run a command to match\n"
3704 "The command to run\n")
3706 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3707 RMAP_EVENT_FILTER_DELETED
);
3711 /* match probability */
3712 DEFUN (match_probability
,
3713 match_probability_cmd
,
3714 "match probability (0-100)",
3716 "Match portion of routes defined by percentage value\n"
3717 "Percentage of routes\n")
3720 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3721 RMAP_EVENT_MATCH_ADDED
);
3725 DEFUN (no_match_probability
,
3726 no_match_probability_cmd
,
3727 "no match probability [(1-99)]",
3730 "Match portion of routes defined by percentage value\n"
3731 "Percentage of routes\n")
3734 if (argc
<= idx_number
)
3735 return bgp_route_match_delete(vty
, "probability", NULL
,
3736 RMAP_EVENT_MATCH_DELETED
);
3737 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3738 RMAP_EVENT_MATCH_DELETED
);
3742 DEFUN (match_ip_route_source
,
3743 match_ip_route_source_cmd
,
3744 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3747 "Match advertising source address of route\n"
3748 "IP access-list number\n"
3749 "IP access-list number (expanded range)\n"
3750 "IP standard access-list name\n")
3753 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3754 RMAP_EVENT_FILTER_ADDED
);
3758 DEFUN (no_match_ip_route_source
,
3759 no_match_ip_route_source_cmd
,
3760 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3764 "Match advertising source address of route\n"
3765 "IP access-list number\n"
3766 "IP access-list number (expanded range)\n"
3767 "IP standard access-list name\n")
3770 if (argc
<= idx_number
)
3771 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3772 RMAP_EVENT_FILTER_DELETED
);
3773 return bgp_route_match_delete(vty
, "ip route-source",
3774 argv
[idx_number
]->arg
,
3775 RMAP_EVENT_FILTER_DELETED
);
3779 DEFUN (match_ip_route_source_prefix_list
,
3780 match_ip_route_source_prefix_list_cmd
,
3781 "match ip route-source prefix-list WORD",
3784 "Match advertising source address of route\n"
3785 "Match entries of prefix-lists\n"
3786 "IP prefix-list name\n")
3789 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3790 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3794 DEFUN (no_match_ip_route_source_prefix_list
,
3795 no_match_ip_route_source_prefix_list_cmd
,
3796 "no match ip route-source prefix-list [WORD]",
3800 "Match advertising source address of route\n"
3801 "Match entries of prefix-lists\n"
3802 "IP prefix-list name\n")
3805 if (argc
<= idx_word
)
3806 return bgp_route_match_delete(vty
,
3807 "ip route-source prefix-list",
3808 NULL
, RMAP_EVENT_PLIST_DELETED
);
3809 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3810 argv
[idx_word
]->arg
,
3811 RMAP_EVENT_PLIST_DELETED
);
3815 DEFUN (match_local_pref
,
3816 match_local_pref_cmd
,
3817 "match local-preference (0-4294967295)",
3819 "Match local-preference of route\n"
3823 return bgp_route_match_add(vty
, "local-preference",
3824 argv
[idx_number
]->arg
,
3825 RMAP_EVENT_MATCH_ADDED
);
3829 DEFUN (no_match_local_pref
,
3830 no_match_local_pref_cmd
,
3831 "no match local-preference [(0-4294967295)]",
3834 "Match local preference of route\n"
3835 "Local preference value\n")
3837 int idx_localpref
= 3;
3838 if (argc
<= idx_localpref
)
3839 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3840 RMAP_EVENT_MATCH_DELETED
);
3841 return bgp_route_match_delete(vty
, "local-preference",
3842 argv
[idx_localpref
]->arg
,
3843 RMAP_EVENT_MATCH_DELETED
);
3847 DEFUN (match_community
,
3848 match_community_cmd
,
3849 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3851 "Match BGP community list\n"
3852 "Community-list number (standard)\n"
3853 "Community-list number (expanded)\n"
3854 "Community-list name\n"
3855 "Do exact matching of communities\n")
3857 int idx_comm_list
= 2;
3862 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3863 strlen(argv
[idx_comm_list
]->arg
)
3864 + strlen("exact-match") + 2);
3866 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3868 argstr
= argv
[idx_comm_list
]->arg
;
3870 ret
= bgp_route_match_add(vty
, "community", argstr
,
3871 RMAP_EVENT_CLIST_ADDED
);
3873 if (argstr
!= argv
[idx_comm_list
]->arg
)
3874 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3879 DEFUN (no_match_community
,
3880 no_match_community_cmd
,
3881 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3884 "Match BGP community list\n"
3885 "Community-list number (standard)\n"
3886 "Community-list number (expanded)\n"
3887 "Community-list name\n"
3888 "Do exact matching of communities\n")
3890 return bgp_route_match_delete(vty
, "community", NULL
,
3891 RMAP_EVENT_CLIST_DELETED
);
3894 DEFUN (match_lcommunity
,
3895 match_lcommunity_cmd
,
3896 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
3898 "Match BGP large community list\n"
3899 "Large Community-list number (standard)\n"
3900 "Large Community-list number (expanded)\n"
3901 "Large Community-list name\n"
3902 "Do exact matching of communities\n")
3904 int idx_lcomm_list
= 2;
3909 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3910 strlen(argv
[idx_lcomm_list
]->arg
)
3911 + strlen("exact-match") + 2);
3913 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
3915 argstr
= argv
[idx_lcomm_list
]->arg
;
3917 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
3918 RMAP_EVENT_LLIST_ADDED
);
3919 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
3920 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3925 DEFUN (no_match_lcommunity
,
3926 no_match_lcommunity_cmd
,
3927 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
3930 "Match BGP large community list\n"
3931 "Large Community-list number (standard)\n"
3932 "Large Community-list number (expanded)\n"
3933 "Large Community-list name\n"
3934 "Do exact matching of communities\n")
3936 return bgp_route_match_delete(vty
, "large-community", NULL
,
3937 RMAP_EVENT_LLIST_DELETED
);
3940 DEFUN (match_ecommunity
,
3941 match_ecommunity_cmd
,
3942 "match extcommunity <(1-99)|(100-500)|WORD>",
3944 "Match BGP/VPN extended community list\n"
3945 "Extended community-list number (standard)\n"
3946 "Extended community-list number (expanded)\n"
3947 "Extended community-list name\n")
3949 int idx_comm_list
= 2;
3950 return bgp_route_match_add(vty
, "extcommunity",
3951 argv
[idx_comm_list
]->arg
,
3952 RMAP_EVENT_ECLIST_ADDED
);
3956 DEFUN (no_match_ecommunity
,
3957 no_match_ecommunity_cmd
,
3958 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3961 "Match BGP/VPN extended community list\n"
3962 "Extended community-list number (standard)\n"
3963 "Extended community-list number (expanded)\n"
3964 "Extended community-list name\n")
3966 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3967 RMAP_EVENT_ECLIST_DELETED
);
3971 DEFUN (match_aspath
,
3973 "match as-path WORD",
3975 "Match BGP AS path list\n"
3976 "AS path access-list name\n")
3979 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3980 RMAP_EVENT_ASLIST_ADDED
);
3984 DEFUN (no_match_aspath
,
3985 no_match_aspath_cmd
,
3986 "no match as-path [WORD]",
3989 "Match BGP AS path list\n"
3990 "AS path access-list name\n")
3992 return bgp_route_match_delete(vty
, "as-path", NULL
,
3993 RMAP_EVENT_ASLIST_DELETED
);
3997 DEFUN (match_origin
,
3999 "match origin <egp|igp|incomplete>",
4004 "unknown heritage\n")
4007 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4008 return bgp_route_match_add(vty
, "origin", "igp",
4009 RMAP_EVENT_MATCH_ADDED
);
4010 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4011 return bgp_route_match_add(vty
, "origin", "egp",
4012 RMAP_EVENT_MATCH_ADDED
);
4013 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4014 return bgp_route_match_add(vty
, "origin", "incomplete",
4015 RMAP_EVENT_MATCH_ADDED
);
4017 vty_out(vty
, "%% Invalid match origin type\n");
4018 return CMD_WARNING_CONFIG_FAILED
;
4022 DEFUN (no_match_origin
,
4023 no_match_origin_cmd
,
4024 "no match origin [<egp|igp|incomplete>]",
4030 "unknown heritage\n")
4032 return bgp_route_match_delete(vty
, "origin", NULL
,
4033 RMAP_EVENT_MATCH_DELETED
);
4036 DEFUN (set_ip_nexthop_peer
,
4037 set_ip_nexthop_peer_cmd
,
4038 "[no] set ip next-hop peer-address",
4042 "Next hop address\n"
4043 "Use peer address (for BGP only)\n")
4045 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4046 const char *) = strmatch(argv
[0]->text
, "no")
4047 ? generic_set_delete
4050 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4054 DEFUN (set_ip_nexthop_unchanged
,
4055 set_ip_nexthop_unchanged_cmd
,
4056 "[no] set ip next-hop unchanged",
4060 "Next hop address\n"
4061 "Don't modify existing Next hop address\n")
4063 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4064 const char *) = strmatch(argv
[0]->text
, "no")
4065 ? generic_set_delete
4068 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4073 DEFUN (set_local_pref
,
4075 "set local-preference (0-4294967295)",
4077 "BGP local preference path attribute\n"
4078 "Preference value\n")
4081 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4082 "local-preference", argv
[idx_number
]->arg
);
4086 DEFUN (no_set_local_pref
,
4087 no_set_local_pref_cmd
,
4088 "no set local-preference [(0-4294967295)]",
4091 "BGP local preference path attribute\n"
4092 "Preference value\n")
4094 int idx_localpref
= 3;
4095 if (argc
<= idx_localpref
)
4096 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4097 "local-preference", NULL
);
4098 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4099 "local-preference", argv
[idx_localpref
]->arg
);
4105 "set weight (0-4294967295)",
4107 "BGP weight for routing table\n"
4111 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4112 argv
[idx_number
]->arg
);
4116 DEFUN (no_set_weight
,
4118 "no set weight [(0-4294967295)]",
4121 "BGP weight for routing table\n"
4125 if (argc
<= idx_weight
)
4126 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4128 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4129 "weight", argv
[idx_weight
]->arg
);
4132 DEFUN (set_label_index
,
4133 set_label_index_cmd
,
4134 "set label-index (0-1048560)",
4136 "Label index to associate with the prefix\n"
4137 "Label index value\n")
4140 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4141 "label-index", argv
[idx_number
]->arg
);
4144 DEFUN (no_set_label_index
,
4145 no_set_label_index_cmd
,
4146 "no set label-index [(0-1048560)]",
4149 "Label index to associate with the prefix\n"
4150 "Label index value\n")
4152 int idx_label_index
= 3;
4153 if (argc
<= idx_label_index
)
4154 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4155 "label-index", NULL
);
4156 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4157 "label-index", argv
[idx_label_index
]->arg
);
4160 DEFUN (set_aspath_prepend_asn
,
4161 set_aspath_prepend_asn_cmd
,
4162 "set as-path prepend (1-4294967295)...",
4164 "Transform BGP AS_PATH attribute\n"
4165 "Prepend to the as-path\n"
4172 str
= argv_concat(argv
, argc
, idx_asn
);
4173 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4174 "as-path prepend", str
);
4175 XFREE(MTYPE_TMP
, str
);
4180 DEFUN (set_aspath_prepend_lastas
,
4181 set_aspath_prepend_lastas_cmd
,
4182 "set as-path prepend last-as (1-10)",
4184 "Transform BGP AS_PATH attribute\n"
4185 "Prepend to the as-path\n"
4186 "Use the peer's AS-number\n"
4187 "Number of times to insert\n")
4189 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4192 DEFUN (no_set_aspath_prepend
,
4193 no_set_aspath_prepend_cmd
,
4194 "no set as-path prepend [(1-4294967295)]",
4197 "Transform BGP AS_PATH attribute\n"
4198 "Prepend to the as-path\n"
4205 str
= argv_concat(argv
, argc
, idx_asn
);
4206 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4207 "as-path prepend", str
);
4208 XFREE(MTYPE_TMP
, str
);
4212 DEFUN (no_set_aspath_prepend_lastas
,
4213 no_set_aspath_prepend_lastas_cmd
,
4214 "no set as-path prepend last-as [(1-10)]",
4217 "Transform BGP AS_PATH attribute\n"
4218 "Prepend to the as-path\n"
4219 "Use the peers AS-number\n"
4220 "Number of times to insert\n")
4222 return no_set_aspath_prepend(self
, vty
, argc
, argv
);
4225 DEFUN (set_aspath_exclude
,
4226 set_aspath_exclude_cmd
,
4227 "set as-path exclude (1-4294967295)...",
4229 "Transform BGP AS-path attribute\n"
4230 "Exclude from the as-path\n"
4237 str
= argv_concat(argv
, argc
, idx_asn
);
4238 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4239 "as-path exclude", str
);
4240 XFREE(MTYPE_TMP
, str
);
4244 DEFUN (no_set_aspath_exclude
,
4245 no_set_aspath_exclude_cmd
,
4246 "no set as-path exclude (1-4294967295)...",
4249 "Transform BGP AS_PATH attribute\n"
4250 "Exclude from the as-path\n"
4257 str
= argv_concat(argv
, argc
, idx_asn
);
4258 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4259 "as-path exclude", str
);
4260 XFREE(MTYPE_TMP
, str
);
4264 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4265 "no set as-path exclude",
4267 "Transform BGP AS_PATH attribute\n"
4268 "Exclude from the as-path\n")
4270 DEFUN (set_community
,
4272 "set community AA:NN...",
4274 "BGP community attribute\n"
4282 struct community
*com
= NULL
;
4287 b
= buffer_new(1024);
4289 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4290 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4297 buffer_putc(b
, ' ');
4301 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4303 buffer_putstr(b
, "internet");
4306 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4308 buffer_putstr(b
, "local-AS");
4311 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4312 && strncmp(argv
[i
]->arg
, "no-advertise",
4313 strlen(argv
[i
]->arg
))
4315 buffer_putstr(b
, "no-advertise");
4318 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4319 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4321 buffer_putstr(b
, "no-export");
4324 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4325 strlen(argv
[i
]->arg
))
4327 buffer_putstr(b
, "graceful-shutdown");
4330 buffer_putstr(b
, argv
[i
]->arg
);
4332 buffer_putc(b
, '\0');
4334 /* Fetch result string then compile it to communities attribute. */
4335 str
= buffer_getstr(b
);
4339 com
= community_str2com(str
);
4340 XFREE(MTYPE_TMP
, str
);
4343 /* Can't compile user input into communities attribute. */
4345 vty_out(vty
, "%% Malformed communities attribute\n");
4346 return CMD_WARNING_CONFIG_FAILED
;
4349 /* Set communites attribute string. */
4350 str
= community_str(com
, false);
4353 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4354 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4355 strlcpy(argstr
, str
, argstr_sz
);
4356 strlcat(argstr
, " additive", argstr_sz
);
4357 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4358 "community", argstr
);
4359 XFREE(MTYPE_TMP
, argstr
);
4361 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4364 community_free(&com
);
4369 DEFUN (set_community_none
,
4370 set_community_none_cmd
,
4371 "set community none",
4373 "BGP community attribute\n"
4374 "No community attribute\n")
4376 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4377 "community", "none");
4380 DEFUN (no_set_community
,
4381 no_set_community_cmd
,
4382 "no set community AA:NN...",
4385 "BGP community attribute\n"
4388 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4392 ALIAS (no_set_community
,
4393 no_set_community_short_cmd
,
4397 "BGP community attribute\n")
4400 DEFUN (set_community_delete
,
4401 set_community_delete_cmd
,
4402 "set comm-list <(1-99)|(100-500)|WORD> delete",
4404 "set BGP community list (for deletion)\n"
4405 "Community-list number (standard)\n"
4406 "Community-list number (expanded)\n"
4407 "Community-list name\n"
4408 "Delete matching communities\n")
4410 int idx_comm_list
= 2;
4413 args
= argv_concat(argv
, argc
, idx_comm_list
);
4414 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4416 XFREE(MTYPE_TMP
, args
);
4421 DEFUN (no_set_community_delete
,
4422 no_set_community_delete_cmd
,
4423 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4426 "set BGP community list (for deletion)\n"
4427 "Community-list number (standard)\n"
4428 "Community-list number (expanded)\n"
4429 "Community-list name\n"
4430 "Delete matching communities\n")
4432 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4436 DEFUN (set_lcommunity
,
4438 "set large-community AA:BB:CC...",
4440 "BGP large community attribute\n"
4441 "Large Community number in aa:bb:cc format or additive\n")
4446 str
= argv_concat(argv
, argc
, 2);
4447 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4448 "large-community", str
);
4449 XFREE(MTYPE_TMP
, str
);
4454 DEFUN (set_lcommunity_none
,
4455 set_lcommunity_none_cmd
,
4456 "set large-community none",
4458 "BGP large community attribute\n"
4459 "No large community attribute\n")
4461 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4462 "large-community", "none");
4465 DEFUN (no_set_lcommunity
,
4466 no_set_lcommunity_cmd
,
4467 "no set large-community none",
4470 "BGP large community attribute\n"
4471 "No community attribute\n")
4473 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4474 "large-community", NULL
);
4477 DEFUN (no_set_lcommunity1
,
4478 no_set_lcommunity1_cmd
,
4479 "no set large-community AA:BB:CC...",
4482 "BGP large community attribute\n"
4483 "Large community in AA:BB:CC... format or additive\n")
4485 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4486 "large-community", NULL
);
4489 ALIAS (no_set_lcommunity1
,
4490 no_set_lcommunity1_short_cmd
,
4491 "no set large-community",
4494 "BGP large community attribute\n")
4496 DEFUN (set_lcommunity_delete
,
4497 set_lcommunity_delete_cmd
,
4498 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4500 "set BGP large community list (for deletion)\n"
4501 "Large Community-list number (standard)\n"
4502 "Large Communitly-list number (expanded)\n"
4503 "Large Community-list name\n"
4504 "Delete matching large communities\n")
4506 int idx_lcomm_list
= 2;
4509 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
4510 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4511 "large-comm-list", args
);
4512 XFREE(MTYPE_TMP
, args
);
4517 DEFUN (no_set_lcommunity_delete
,
4518 no_set_lcommunity_delete_cmd
,
4519 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4522 "set BGP large community list (for deletion)\n"
4523 "Large Community-list number (standard)\n"
4524 "Large Communitly-list number (expanded)\n"
4525 "Large Community-list name\n"
4526 "Delete matching large communities\n")
4528 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4529 "large-comm-list", NULL
);
4532 ALIAS (no_set_lcommunity_delete
,
4533 no_set_lcommunity_delete_short_cmd
,
4534 "no set large-comm-list",
4537 "set BGP large community list (for deletion)\n")
4539 DEFUN (set_ecommunity_rt
,
4540 set_ecommunity_rt_cmd
,
4541 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4543 "BGP extended community attribute\n"
4544 "Route Target extended community\n"
4545 "VPN extended community\n")
4551 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4552 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4553 "extcommunity rt", str
);
4554 XFREE(MTYPE_TMP
, str
);
4559 DEFUN (no_set_ecommunity_rt
,
4560 no_set_ecommunity_rt_cmd
,
4561 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4564 "BGP extended community attribute\n"
4565 "Route Target extended community\n"
4566 "VPN extended community\n")
4568 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4569 "extcommunity rt", NULL
);
4572 ALIAS (no_set_ecommunity_rt
,
4573 no_set_ecommunity_rt_short_cmd
,
4574 "no set extcommunity rt",
4577 "BGP extended community attribute\n"
4578 "Route Target extended community\n")
4580 DEFUN (set_ecommunity_soo
,
4581 set_ecommunity_soo_cmd
,
4582 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4584 "BGP extended community attribute\n"
4585 "Site-of-Origin extended community\n"
4586 "VPN extended community\n")
4592 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4593 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4594 "extcommunity soo", str
);
4595 XFREE(MTYPE_TMP
, str
);
4600 DEFUN (no_set_ecommunity_soo
,
4601 no_set_ecommunity_soo_cmd
,
4602 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4605 "BGP extended community attribute\n"
4606 "Site-of-Origin extended community\n"
4607 "VPN extended community\n")
4609 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4610 "extcommunity soo", NULL
);
4613 ALIAS (no_set_ecommunity_soo
,
4614 no_set_ecommunity_soo_short_cmd
,
4615 "no set extcommunity soo",
4618 "GP extended community attribute\n"
4619 "Site-of-Origin extended community\n")
4623 "set origin <egp|igp|incomplete>",
4628 "unknown heritage\n")
4631 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4632 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4634 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4635 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4637 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4638 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4639 "origin", "incomplete");
4641 vty_out(vty
, "%% Invalid set origin type\n");
4642 return CMD_WARNING_CONFIG_FAILED
;
4646 DEFUN (no_set_origin
,
4648 "no set origin [<egp|igp|incomplete>]",
4654 "unknown heritage\n")
4656 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4661 DEFUN (set_atomic_aggregate
,
4662 set_atomic_aggregate_cmd
,
4663 "set atomic-aggregate",
4665 "BGP atomic aggregate attribute\n" )
4667 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4668 "atomic-aggregate", NULL
);
4671 DEFUN (no_set_atomic_aggregate
,
4672 no_set_atomic_aggregate_cmd
,
4673 "no set atomic-aggregate",
4676 "BGP atomic aggregate attribute\n" )
4678 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4679 "atomic-aggregate", NULL
);
4682 DEFUN (set_aggregator_as
,
4683 set_aggregator_as_cmd
,
4684 "set aggregator as (1-4294967295) A.B.C.D",
4686 "BGP aggregator attribute\n"
4687 "AS number of aggregator\n"
4689 "IP address of aggregator\n")
4694 struct in_addr address
;
4697 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4699 vty_out(vty
, "Aggregator IP address is invalid\n");
4700 return CMD_WARNING_CONFIG_FAILED
;
4703 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4704 strlen(argv
[idx_number
]->arg
)
4705 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4707 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4709 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4710 "aggregator as", argstr
);
4712 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4718 DEFUN (no_set_aggregator_as
,
4719 no_set_aggregator_as_cmd
,
4720 "no set aggregator as [(1-4294967295) A.B.C.D]",
4723 "BGP aggregator attribute\n"
4724 "AS number of aggregator\n"
4726 "IP address of aggregator\n")
4731 struct in_addr address
;
4734 if (argc
<= idx_asn
)
4735 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4736 "aggregator as", NULL
);
4738 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4740 vty_out(vty
, "Aggregator IP address is invalid\n");
4741 return CMD_WARNING_CONFIG_FAILED
;
4744 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4745 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4748 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4750 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4751 "aggregator as", argstr
);
4753 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4758 DEFUN (match_ipv6_next_hop
,
4759 match_ipv6_next_hop_cmd
,
4760 "match ipv6 next-hop X:X::X:X",
4763 "Match IPv6 next-hop address of route\n"
4764 "IPv6 address of next hop\n")
4767 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4768 RMAP_EVENT_MATCH_ADDED
);
4771 DEFUN (no_match_ipv6_next_hop
,
4772 no_match_ipv6_next_hop_cmd
,
4773 "no match ipv6 next-hop X:X::X:X",
4777 "Match IPv6 next-hop address of route\n"
4778 "IPv6 address of next hop\n")
4781 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4782 RMAP_EVENT_MATCH_DELETED
);
4786 DEFUN (set_ipv6_nexthop_peer
,
4787 set_ipv6_nexthop_peer_cmd
,
4788 "set ipv6 next-hop peer-address",
4791 "Next hop address\n"
4792 "Use peer address (for BGP only)\n")
4794 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4795 "ipv6 next-hop peer-address", NULL
);
4798 DEFUN (no_set_ipv6_nexthop_peer
,
4799 no_set_ipv6_nexthop_peer_cmd
,
4800 "no set ipv6 next-hop peer-address",
4804 "IPv6 next-hop address\n"
4805 "Use peer address (for BGP only)\n")
4807 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4808 "ipv6 next-hop peer-address", NULL
);
4811 DEFUN (set_ipv6_nexthop_prefer_global
,
4812 set_ipv6_nexthop_prefer_global_cmd
,
4813 "set ipv6 next-hop prefer-global",
4816 "IPv6 next-hop address\n"
4817 "Prefer global over link-local if both exist\n")
4819 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4820 "ipv6 next-hop prefer-global", NULL
);
4824 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4825 no_set_ipv6_nexthop_prefer_global_cmd
,
4826 "no set ipv6 next-hop prefer-global",
4830 "IPv6 next-hop address\n"
4831 "Prefer global over link-local if both exist\n")
4833 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4834 "ipv6 next-hop prefer-global", NULL
);
4837 DEFUN (set_ipv6_nexthop_global
,
4838 set_ipv6_nexthop_global_cmd
,
4839 "set ipv6 next-hop global X:X::X:X",
4842 "IPv6 next-hop address\n"
4843 "IPv6 global address\n"
4844 "IPv6 address of next hop\n")
4847 struct in6_addr addr
;
4850 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4852 vty_out(vty
, "%% Malformed nexthop address\n");
4853 return CMD_WARNING_CONFIG_FAILED
;
4855 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4856 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4857 vty_out(vty
, "%% Invalid global nexthop address\n");
4858 return CMD_WARNING_CONFIG_FAILED
;
4861 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4862 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4866 DEFUN (no_set_ipv6_nexthop_global
,
4867 no_set_ipv6_nexthop_global_cmd
,
4868 "no set ipv6 next-hop global X:X::X:X",
4872 "IPv6 next-hop address\n"
4873 "IPv6 global address\n"
4874 "IPv6 address of next hop\n")
4877 if (argc
<= idx_ipv6
)
4878 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4879 "ipv6 next-hop global", NULL
);
4880 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4881 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4884 #ifdef KEEP_OLD_VPN_COMMANDS
4885 DEFUN (set_vpn_nexthop
,
4886 set_vpn_nexthop_cmd
,
4887 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4889 "VPNv4 information\n"
4890 "VPN next-hop address\n"
4891 "IP address of next hop\n"
4892 "VPNv6 information\n"
4893 "VPN next-hop address\n"
4894 "IPv6 address of next hop\n")
4900 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4902 return generic_set_add(
4903 vty
, VTY_GET_CONTEXT(route_map_index
),
4904 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4906 return generic_set_add(
4907 vty
, VTY_GET_CONTEXT(route_map_index
),
4908 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4913 DEFUN (no_set_vpn_nexthop
,
4914 no_set_vpn_nexthop_cmd
,
4915 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4918 "VPNv4 information\n"
4919 "VPN next-hop address\n"
4920 "IP address of next hop\n"
4921 "VPNv6 information\n"
4922 "VPN next-hop address\n"
4923 "IPv6 address of next hop\n")
4933 arg
= argv
[idx_ip
]->arg
;
4934 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4936 return generic_set_delete(
4937 vty
, VTY_GET_CONTEXT(route_map_index
),
4938 "ipv4 vpn next-hop", arg
);
4940 return generic_set_delete(
4941 vty
, VTY_GET_CONTEXT(route_map_index
),
4942 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4946 #endif /* KEEP_OLD_VPN_COMMANDS */
4948 DEFUN (set_ipx_vpn_nexthop
,
4949 set_ipx_vpn_nexthop_cmd
,
4950 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4952 "IPv4 information\n"
4953 "IPv6 information\n"
4955 "VPN next-hop address\n"
4956 "IP address of next hop\n"
4957 "IPv6 address of next hop\n")
4963 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4965 return generic_set_add(
4966 vty
, VTY_GET_CONTEXT(route_map_index
),
4967 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4969 return generic_set_add(
4970 vty
, VTY_GET_CONTEXT(route_map_index
),
4971 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4976 DEFUN (no_set_ipx_vpn_nexthop
,
4977 no_set_ipx_vpn_nexthop_cmd
,
4978 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4981 "IPv4 information\n"
4982 "IPv6 information\n"
4984 "VPN next-hop address\n"
4985 "IP address of next hop\n"
4986 "IPv6 address of next hop\n")
4996 arg
= argv
[idx_ip
]->arg
;
4997 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4999 return generic_set_delete(
5000 vty
, VTY_GET_CONTEXT(route_map_index
),
5001 "ipv4 vpn next-hop", arg
);
5003 return generic_set_delete(
5004 vty
, VTY_GET_CONTEXT(route_map_index
),
5005 "ipv6 vpn next-hop", arg
);
5010 DEFUN (set_originator_id
,
5011 set_originator_id_cmd
,
5012 "set originator-id A.B.C.D",
5014 "BGP originator ID attribute\n"
5015 "IP address of originator\n")
5018 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5019 "originator-id", argv
[idx_ipv4
]->arg
);
5023 DEFUN (no_set_originator_id
,
5024 no_set_originator_id_cmd
,
5025 "no set originator-id [A.B.C.D]",
5028 "BGP originator ID attribute\n"
5029 "IP address of originator\n")
5033 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
5035 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5036 "originator-id", arg
);
5040 /* Initialization of route map. */
5041 void bgp_route_map_init(void)
5045 route_map_add_hook(bgp_route_map_add
);
5046 route_map_delete_hook(bgp_route_map_delete
);
5047 route_map_event_hook(bgp_route_map_event
);
5049 route_map_match_interface_hook(generic_match_add
);
5050 route_map_no_match_interface_hook(generic_match_delete
);
5052 route_map_match_ip_address_hook(generic_match_add
);
5053 route_map_no_match_ip_address_hook(generic_match_delete
);
5055 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
5056 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
5058 route_map_match_ip_next_hop_hook(generic_match_add
);
5059 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
5061 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
5062 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5064 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5065 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5067 route_map_match_ipv6_address_hook(generic_match_add
);
5068 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5070 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5071 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5073 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5074 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5076 route_map_match_metric_hook(generic_match_add
);
5077 route_map_no_match_metric_hook(generic_match_delete
);
5079 route_map_match_tag_hook(generic_match_add
);
5080 route_map_no_match_tag_hook(generic_match_delete
);
5082 route_map_set_ip_nexthop_hook(generic_set_add
);
5083 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5085 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5086 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5088 route_map_set_metric_hook(generic_set_add
);
5089 route_map_no_set_metric_hook(generic_set_delete
);
5091 route_map_set_tag_hook(generic_set_add
);
5092 route_map_no_set_tag_hook(generic_set_delete
);
5094 route_map_install_match(&route_match_peer_cmd
);
5095 route_map_install_match(&route_match_local_pref_cmd
);
5096 #if defined(HAVE_LUA)
5097 route_map_install_match(&route_match_command_cmd
);
5099 route_map_install_match(&route_match_ip_address_cmd
);
5100 route_map_install_match(&route_match_ip_next_hop_cmd
);
5101 route_map_install_match(&route_match_ip_route_source_cmd
);
5102 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5103 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5104 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5105 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5106 route_map_install_match(&route_match_aspath_cmd
);
5107 route_map_install_match(&route_match_community_cmd
);
5108 route_map_install_match(&route_match_lcommunity_cmd
);
5109 route_map_install_match(&route_match_ecommunity_cmd
);
5110 route_map_install_match(&route_match_local_pref_cmd
);
5111 route_map_install_match(&route_match_metric_cmd
);
5112 route_map_install_match(&route_match_origin_cmd
);
5113 route_map_install_match(&route_match_probability_cmd
);
5114 route_map_install_match(&route_match_interface_cmd
);
5115 route_map_install_match(&route_match_tag_cmd
);
5116 route_map_install_match(&route_match_mac_address_cmd
);
5117 route_map_install_match(&route_match_evpn_vni_cmd
);
5118 route_map_install_match(&route_match_evpn_route_type_cmd
);
5119 route_map_install_match(&route_match_evpn_default_route_cmd
);
5120 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5122 route_map_install_set(&route_set_ip_nexthop_cmd
);
5123 route_map_install_set(&route_set_local_pref_cmd
);
5124 route_map_install_set(&route_set_weight_cmd
);
5125 route_map_install_set(&route_set_label_index_cmd
);
5126 route_map_install_set(&route_set_metric_cmd
);
5127 route_map_install_set(&route_set_aspath_prepend_cmd
);
5128 route_map_install_set(&route_set_aspath_exclude_cmd
);
5129 route_map_install_set(&route_set_origin_cmd
);
5130 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5131 route_map_install_set(&route_set_aggregator_as_cmd
);
5132 route_map_install_set(&route_set_community_cmd
);
5133 route_map_install_set(&route_set_community_delete_cmd
);
5134 route_map_install_set(&route_set_lcommunity_cmd
);
5135 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5136 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5137 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5138 route_map_install_set(&route_set_originator_id_cmd
);
5139 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5140 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5141 route_map_install_set(&route_set_tag_cmd
);
5142 route_map_install_set(&route_set_label_index_cmd
);
5144 install_element(RMAP_NODE
, &match_peer_cmd
);
5145 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5146 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5147 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5148 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5149 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5150 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5151 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5152 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5153 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5154 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5155 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5156 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5157 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5158 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5159 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5160 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5162 install_element(RMAP_NODE
, &match_aspath_cmd
);
5163 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5164 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5165 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5166 install_element(RMAP_NODE
, &match_community_cmd
);
5167 install_element(RMAP_NODE
, &no_match_community_cmd
);
5168 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5169 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5170 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5171 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5172 install_element(RMAP_NODE
, &match_origin_cmd
);
5173 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5174 install_element(RMAP_NODE
, &match_probability_cmd
);
5175 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5177 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5178 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5179 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5180 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5181 install_element(RMAP_NODE
, &set_weight_cmd
);
5182 install_element(RMAP_NODE
, &set_label_index_cmd
);
5183 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5184 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5185 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5186 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5187 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5188 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5189 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
5190 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5191 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5192 install_element(RMAP_NODE
, &set_origin_cmd
);
5193 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5194 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5195 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5196 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5197 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5198 install_element(RMAP_NODE
, &set_community_cmd
);
5199 install_element(RMAP_NODE
, &set_community_none_cmd
);
5200 install_element(RMAP_NODE
, &no_set_community_cmd
);
5201 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5202 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5203 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5204 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5205 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5206 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5207 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5208 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5209 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5210 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5211 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5212 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5213 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5214 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5215 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5216 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5217 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5218 #ifdef KEEP_OLD_VPN_COMMANDS
5219 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5220 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5221 #endif /* KEEP_OLD_VPN_COMMANDS */
5222 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5223 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5224 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5225 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5227 route_map_install_match(&route_match_ipv6_address_cmd
);
5228 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5229 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5230 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5231 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5232 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5233 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5234 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5236 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5237 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5238 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5239 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5240 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5241 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5242 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5243 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5244 #if defined(HAVE_LUA)
5245 install_element(RMAP_NODE
, &match_command_cmd
);
5246 install_element(RMAP_NODE
, &no_match_command_cmd
);
5250 void bgp_route_map_terminate(void)
5252 /* ToDo: Cleanup all the used memory */