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
2877 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2878 path
->attr
->mp_nexthop_len
=
2879 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2881 path
->attr
->mp_nexthop_global
= peer_address
;
2882 if (path
->attr
->mp_nexthop_len
== 0)
2883 path
->attr
->mp_nexthop_len
=
2884 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2887 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2888 /* The next hop value will be set as part of packet
2890 * Set the flags here to indicate that rewrite needs to
2892 * Also, clear the value - we clear both global and
2894 * nexthops, whether we send one or both is determined
2897 SET_FLAG(path
->attr
->rmap_change_flags
,
2898 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2899 /* clear next hop value. */
2900 memset(&(path
->attr
->mp_nexthop_global
), 0,
2901 sizeof(struct in6_addr
));
2902 memset(&(path
->attr
->mp_nexthop_local
), 0,
2903 sizeof(struct in6_addr
));
2910 /* Route map `ip next-hop' compile function. Given string is converted
2911 to struct in_addr structure. */
2912 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2916 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2922 /* Free route map's compiled `ip next-hop' value. */
2923 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2925 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2928 /* Route map commands for ip nexthop set. */
2929 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2930 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2931 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2933 /* `set ipv4 vpn next-hop A.B.C.D' */
2935 static enum route_map_cmd_result_t
2936 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
,
2937 route_map_object_t type
, void *object
)
2939 struct in_addr
*address
;
2940 struct bgp_path_info
*path
;
2942 if (type
== RMAP_BGP
) {
2943 /* Fetch routemap's rule information. */
2947 /* Set next hop value. */
2948 path
->attr
->mp_nexthop_global_in
= *address
;
2949 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
2955 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2958 struct in_addr
*address
;
2960 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2962 ret
= inet_aton(arg
, address
);
2965 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2972 /* `set ipv6 vpn next-hop A.B.C.D' */
2974 static enum route_map_cmd_result_t
2975 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
,
2976 route_map_object_t type
, void *object
)
2978 struct in6_addr
*address
;
2979 struct bgp_path_info
*path
;
2981 if (type
== RMAP_BGP
) {
2982 /* Fetch routemap's rule information. */
2986 /* Set next hop value. */
2987 memcpy(&path
->attr
->mp_nexthop_global
, address
,
2988 sizeof(struct in6_addr
));
2989 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2995 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2998 struct in6_addr
*address
;
3000 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3001 ret
= inet_pton(AF_INET6
, arg
, address
);
3004 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3011 static void route_set_vpn_nexthop_free(void *rule
)
3013 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3016 /* Route map commands for ipv4 next-hop set. */
3017 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3018 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
3019 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
3021 /* Route map commands for ipv6 next-hop set. */
3022 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3023 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
3024 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
3026 /* `set originator-id' */
3028 /* For origin set. */
3029 static enum route_map_cmd_result_t
3030 route_set_originator_id(void *rule
, const struct prefix
*prefix
,
3031 route_map_object_t type
, void *object
)
3033 struct in_addr
*address
;
3034 struct bgp_path_info
*path
;
3036 if (type
== RMAP_BGP
) {
3040 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3041 path
->attr
->originator_id
= *address
;
3047 /* Compile function for originator-id set. */
3048 static void *route_set_originator_id_compile(const char *arg
)
3051 struct in_addr
*address
;
3053 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3055 ret
= inet_aton(arg
, address
);
3058 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3065 /* Compile function for originator_id set. */
3066 static void route_set_originator_id_free(void *rule
)
3068 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3071 /* Set originator-id rule structure. */
3072 struct route_map_rule_cmd route_set_originator_id_cmd
= {
3073 "originator-id", route_set_originator_id
,
3074 route_set_originator_id_compile
, route_set_originator_id_free
,
3077 /* Add bgp route map rule. */
3078 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3079 const char *arg
, route_map_event_t type
)
3081 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3082 int retval
= CMD_SUCCESS
;
3083 enum rmap_compile_rets ret
;
3085 ret
= route_map_add_match(index
, command
, arg
, type
);
3087 case RMAP_RULE_MISSING
:
3088 vty_out(vty
, "%% BGP Can't find rule.\n");
3089 retval
= CMD_WARNING_CONFIG_FAILED
;
3091 case RMAP_COMPILE_ERROR
:
3092 vty_out(vty
, "%% BGP Argument is malformed.\n");
3093 retval
= CMD_WARNING_CONFIG_FAILED
;
3095 case RMAP_COMPILE_SUCCESS
:
3097 * Intentionally doing nothing here.
3105 /* Delete bgp route map rule. */
3106 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3107 const char *arg
, route_map_event_t type
)
3109 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3110 enum rmap_compile_rets ret
;
3111 int retval
= CMD_SUCCESS
;
3112 char *dep_name
= NULL
;
3114 char *rmap_name
= NULL
;
3116 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3117 /* ignore the mundane, the types without any dependency */
3119 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3122 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3124 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3126 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3129 ret
= route_map_delete_match(index
, command
, dep_name
, type
);
3131 case RMAP_RULE_MISSING
:
3132 vty_out(vty
, "%% BGP Can't find rule.\n");
3133 retval
= CMD_WARNING_CONFIG_FAILED
;
3135 case RMAP_COMPILE_ERROR
:
3136 vty_out(vty
, "%% BGP Argument is malformed.\n");
3137 retval
= CMD_WARNING_CONFIG_FAILED
;
3139 case RMAP_COMPILE_SUCCESS
:
3141 * Nothing to do here
3146 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3147 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3153 * This is the workhorse routine for processing in/out routemap
3156 static void bgp_route_map_process_peer(const char *rmap_name
,
3157 struct route_map
*map
, struct peer
*peer
,
3158 int afi
, int safi
, int route_update
)
3160 struct bgp_filter
*filter
;
3162 if (!peer
|| !rmap_name
)
3165 filter
= &peer
->filter
[afi
][safi
];
3167 * in is for non-route-server clients,
3168 * out is for all peers
3170 if (filter
->map
[RMAP_IN
].name
3171 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3172 filter
->map
[RMAP_IN
].map
= map
;
3174 if (route_update
&& peer
->status
== Established
) {
3175 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3176 PEER_FLAG_SOFT_RECONFIG
)) {
3177 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3179 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3180 rmap_name
, peer
->host
);
3182 bgp_soft_reconfig_in(peer
, afi
, safi
);
3183 } else if (CHECK_FLAG(peer
->cap
,
3184 PEER_CAP_REFRESH_OLD_RCV
)
3185 || CHECK_FLAG(peer
->cap
,
3186 PEER_CAP_REFRESH_NEW_RCV
)) {
3187 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3189 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3190 rmap_name
, peer
->host
);
3191 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3198 * For outbound, unsuppress and default-originate map change (content or
3199 * map created), merely update the "config" here, the actual route
3200 * announcement happens at the group level.
3202 if (filter
->map
[RMAP_OUT
].name
3203 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3204 filter
->map
[RMAP_OUT
].map
= map
;
3206 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3207 filter
->usmap
.map
= map
;
3209 if (peer
->default_rmap
[afi
][safi
].name
3210 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3211 peer
->default_rmap
[afi
][safi
].map
= map
;
3214 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3215 struct route_map
*map
,
3218 struct peer_group
*group
;
3219 struct listnode
*node
, *nnode
;
3220 struct bgp_filter
*filter
;
3227 /* All the peers have been updated correctly already. This is
3228 * just updating the placeholder data. No real update required.
3230 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3231 FOREACH_AFI_SAFI (afi
, safi
) {
3232 filter
= &group
->conf
->filter
[afi
][safi
];
3234 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3235 if ((filter
->map
[direct
].name
)
3236 && (strcmp(rmap_name
,
3237 filter
->map
[direct
].name
)
3239 filter
->map
[direct
].map
= map
;
3242 if (filter
->usmap
.name
3243 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3244 filter
->usmap
.map
= map
;
3250 * Note that if an extreme number (tens of thousands) of route-maps are in use
3251 * and if bgp has an extreme number of peers, network statements, etc then this
3252 * function can consume a lot of cycles. This is due to this function being
3253 * called for each route-map and within this function we walk the list of peers,
3254 * network statements, etc looking to see if they use this route-map.
3256 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3263 struct bgp_node
*bn
;
3264 struct bgp_static
*bgp_static
;
3265 struct bgp_aggregate
*aggregate
;
3266 struct listnode
*node
, *nnode
;
3267 struct route_map
*map
;
3268 char buf
[INET6_ADDRSTRLEN
];
3270 map
= route_map_lookup_by_name(rmap_name
);
3272 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3274 /* Ignore dummy peer-group structure */
3275 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3278 FOREACH_AFI_SAFI (afi
, safi
) {
3279 /* process in/out/import/export/default-orig
3281 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3282 safi
, route_update
);
3286 /* for outbound/default-orig route-maps, process for groups */
3287 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3290 /* update peer-group config (template) */
3291 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3293 FOREACH_AFI_SAFI (afi
, safi
) {
3294 /* For table route-map updates. */
3295 if (!bgp_fibupd_safi(safi
))
3298 if (bgp
->table_map
[afi
][safi
].name
3299 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3302 /* bgp->table_map[afi][safi].map is NULL.
3303 * i.e Route map creation event.
3304 * So update applied_counter.
3305 * If it is not NULL, i.e It may be routemap updation or
3306 * deletion. so no need to update the counter.
3308 if (!bgp
->table_map
[afi
][safi
].map
)
3309 route_map_counter_increment(map
);
3310 bgp
->table_map
[afi
][safi
].map
= map
;
3312 if (BGP_DEBUG(zebra
, ZEBRA
))
3314 "Processing route_map %s update on "
3318 bgp_zebra_announce_table(bgp
, afi
, safi
);
3321 /* For network route-map updates. */
3322 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3323 bn
= bgp_route_next(bn
)) {
3324 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3328 if (!bgp_static
->rmap
.name
3329 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3332 if (!bgp_static
->rmap
.map
)
3333 route_map_counter_increment(map
);
3335 bgp_static
->rmap
.map
= map
;
3337 if (route_update
&& !bgp_static
->backdoor
) {
3338 if (bgp_debug_zebra(&bn
->p
))
3340 "Processing route_map %s update on static route %s",
3342 inet_ntop(bn
->p
.family
,
3343 &bn
->p
.u
.prefix
, buf
,
3345 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3350 /* For aggregate-address route-map updates. */
3351 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
3352 bn
= bgp_route_next(bn
)) {
3353 aggregate
= bgp_node_get_bgp_aggregate_info(bn
);
3357 if (!aggregate
->rmap
.name
3358 || (strcmp(rmap_name
, aggregate
->rmap
.name
) != 0))
3361 if (!aggregate
->rmap
.map
)
3362 route_map_counter_increment(map
);
3364 aggregate
->rmap
.map
= map
;
3367 if (bgp_debug_zebra(&bn
->p
))
3369 "Processing route_map %s update on aggregate-address route %s",
3371 inet_ntop(bn
->p
.family
,
3372 &bn
->p
.u
.prefix
, buf
,
3374 bgp_aggregate_route(bgp
, &bn
->p
, afi
, safi
,
3380 /* For redistribute route-map updates. */
3381 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3382 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3383 struct list
*red_list
;
3384 struct bgp_redist
*red
;
3386 red_list
= bgp
->redist
[afi
][i
];
3390 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3392 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3396 route_map_counter_increment(map
);
3398 red
->rmap
.map
= map
;
3403 if (BGP_DEBUG(zebra
, ZEBRA
))
3405 "Processing route_map %s update on redistributed routes",
3408 bgp_redistribute_resend(bgp
, afi
, i
,
3413 /* for type5 command route-maps */
3414 FOREACH_AFI_SAFI (afi
, safi
) {
3415 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3416 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3420 /* Make sure the route-map is populated here if not already done */
3421 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3423 if (BGP_DEBUG(zebra
, ZEBRA
))
3425 "Processing route_map %s update on advertise type5 route command",
3428 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3429 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3430 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3435 static void bgp_route_map_process_update_cb(char *rmap_name
)
3437 struct listnode
*node
, *nnode
;
3440 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3441 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3444 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3445 vnc_routemap_update(bgp
, __func__
);
3449 vpn_policy_routemap_event(rmap_name
);
3452 int bgp_route_map_update_timer(struct thread
*thread
)
3454 bm
->t_rmap_update
= NULL
;
3456 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3461 static void bgp_route_map_mark_update(const char *rmap_name
)
3463 struct listnode
*node
, *nnode
;
3466 /* If new update is received before the current timer timed out,
3467 * turn it off and start a new timer.
3469 if (bm
->t_rmap_update
!= NULL
)
3470 THREAD_OFF(bm
->t_rmap_update
);
3472 /* rmap_update_timer of 0 means don't do route updates */
3473 if (bm
->rmap_update_timer
) {
3474 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3475 NULL
, bm
->rmap_update_timer
,
3476 &bm
->t_rmap_update
);
3478 /* Signal the groups that a route-map update event has
3480 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3481 update_group_policy_update(bgp
,
3482 BGP_POLICY_ROUTE_MAP
,
3485 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3486 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3488 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3489 vnc_routemap_update(bgp
, __func__
);
3494 static void bgp_route_map_add(const char *rmap_name
)
3496 if (route_map_mark_updated(rmap_name
) == 0)
3497 bgp_route_map_mark_update(rmap_name
);
3499 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3502 static void bgp_route_map_delete(const char *rmap_name
)
3504 if (route_map_mark_updated(rmap_name
) == 0)
3505 bgp_route_map_mark_update(rmap_name
);
3507 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3510 static void bgp_route_map_event(const char *rmap_name
)
3512 if (route_map_mark_updated(rmap_name
) == 0)
3513 bgp_route_map_mark_update(rmap_name
);
3515 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3518 DEFUN (match_mac_address
,
3519 match_mac_address_cmd
,
3520 "match mac address WORD",
3523 "Match address of route\n"
3524 "MAC Access-list name\n")
3526 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3527 RMAP_EVENT_FILTER_ADDED
);
3530 DEFUN (no_match_mac_address
,
3531 no_match_mac_address_cmd
,
3532 "no match mac address WORD",
3536 "Match address of route\n"
3537 "MAC acess-list name\n")
3539 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3540 RMAP_EVENT_FILTER_DELETED
);
3543 DEFUN (match_evpn_route_type
,
3544 match_evpn_route_type_cmd
,
3545 "match evpn route-type <macip | multicast | prefix>",
3548 "Match route-type\n"
3553 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3554 RMAP_EVENT_MATCH_ADDED
);
3557 DEFUN (no_match_evpn_route_type
,
3558 no_match_evpn_route_type_cmd
,
3559 "no match evpn route-type <macip | multicast | prefix>",
3563 "Match route-type\n"
3568 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3569 RMAP_EVENT_MATCH_DELETED
);
3573 DEFUN (match_evpn_vni
,
3575 "match evpn vni " CMD_VNI_RANGE
,
3581 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3582 RMAP_EVENT_MATCH_ADDED
);
3585 DEFUN (no_match_evpn_vni
,
3586 no_match_evpn_vni_cmd
,
3587 "no match evpn vni " CMD_VNI_RANGE
,
3594 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3595 RMAP_EVENT_MATCH_DELETED
);
3598 DEFUN (match_evpn_default_route
,
3599 match_evpn_default_route_cmd
,
3600 "match evpn default-route",
3603 "default EVPN type-5 route\n")
3605 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3606 RMAP_EVENT_MATCH_ADDED
);
3609 DEFUN (no_match_evpn_default_route
,
3610 no_match_evpn_default_route_cmd
,
3611 "no match evpn default-route",
3615 "default EVPN type-5 route\n")
3617 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3618 RMAP_EVENT_MATCH_DELETED
);
3621 DEFPY(match_vrl_source_vrf
,
3622 match_vrl_source_vrf_cmd
,
3623 "match source-vrf NAME$vrf_name",
3628 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3629 RMAP_EVENT_MATCH_ADDED
);
3632 DEFPY(no_match_vrl_source_vrf
,
3633 no_match_vrl_source_vrf_cmd
,
3634 "no match source-vrf NAME$vrf_name",
3640 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3641 RMAP_EVENT_MATCH_DELETED
);
3646 "match peer <A.B.C.D|X:X::X:X|WORD>",
3648 "Match peer address\n"
3649 "IP address of peer\n"
3650 "IPv6 address of peer\n"
3651 "Interface name of peer\n")
3654 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3655 RMAP_EVENT_MATCH_ADDED
);
3658 DEFUN (match_peer_local
,
3659 match_peer_local_cmd
,
3662 "Match peer address\n"
3663 "Static or Redistributed routes\n")
3665 return bgp_route_match_add(vty
, "peer", "local",
3666 RMAP_EVENT_MATCH_DELETED
);
3669 DEFUN (no_match_peer
,
3671 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3674 "Match peer address\n"
3675 "Static or Redistributed routes\n"
3676 "IP address of peer\n"
3677 "IPv6 address of peer\n"
3678 "Interface name of peer\n")
3682 if (argc
<= idx_peer
)
3683 return bgp_route_match_delete(vty
, "peer", NULL
,
3684 RMAP_EVENT_MATCH_DELETED
);
3685 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3686 RMAP_EVENT_MATCH_DELETED
);
3689 #if defined(HAVE_LUA)
3690 DEFUN (match_command
,
3692 "match command WORD",
3694 "Run a command to match\n"
3695 "The command to run\n")
3697 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3698 RMAP_EVENT_FILTER_ADDED
);
3701 DEFUN (no_match_command
,
3702 no_match_command_cmd
,
3703 "no match command WORD",
3706 "Run a command to match\n"
3707 "The command to run\n")
3709 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3710 RMAP_EVENT_FILTER_DELETED
);
3714 /* match probability */
3715 DEFUN (match_probability
,
3716 match_probability_cmd
,
3717 "match probability (0-100)",
3719 "Match portion of routes defined by percentage value\n"
3720 "Percentage of routes\n")
3723 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3724 RMAP_EVENT_MATCH_ADDED
);
3728 DEFUN (no_match_probability
,
3729 no_match_probability_cmd
,
3730 "no match probability [(1-99)]",
3733 "Match portion of routes defined by percentage value\n"
3734 "Percentage of routes\n")
3737 if (argc
<= idx_number
)
3738 return bgp_route_match_delete(vty
, "probability", NULL
,
3739 RMAP_EVENT_MATCH_DELETED
);
3740 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3741 RMAP_EVENT_MATCH_DELETED
);
3745 DEFUN (match_ip_route_source
,
3746 match_ip_route_source_cmd
,
3747 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3750 "Match advertising source address of route\n"
3751 "IP access-list number\n"
3752 "IP access-list number (expanded range)\n"
3753 "IP standard access-list name\n")
3756 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3757 RMAP_EVENT_FILTER_ADDED
);
3761 DEFUN (no_match_ip_route_source
,
3762 no_match_ip_route_source_cmd
,
3763 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3767 "Match advertising source address of route\n"
3768 "IP access-list number\n"
3769 "IP access-list number (expanded range)\n"
3770 "IP standard access-list name\n")
3773 if (argc
<= idx_number
)
3774 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3775 RMAP_EVENT_FILTER_DELETED
);
3776 return bgp_route_match_delete(vty
, "ip route-source",
3777 argv
[idx_number
]->arg
,
3778 RMAP_EVENT_FILTER_DELETED
);
3782 DEFUN (match_ip_route_source_prefix_list
,
3783 match_ip_route_source_prefix_list_cmd
,
3784 "match ip route-source prefix-list WORD",
3787 "Match advertising source address of route\n"
3788 "Match entries of prefix-lists\n"
3789 "IP prefix-list name\n")
3792 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3793 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3797 DEFUN (no_match_ip_route_source_prefix_list
,
3798 no_match_ip_route_source_prefix_list_cmd
,
3799 "no match ip route-source prefix-list [WORD]",
3803 "Match advertising source address of route\n"
3804 "Match entries of prefix-lists\n"
3805 "IP prefix-list name\n")
3808 if (argc
<= idx_word
)
3809 return bgp_route_match_delete(vty
,
3810 "ip route-source prefix-list",
3811 NULL
, RMAP_EVENT_PLIST_DELETED
);
3812 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3813 argv
[idx_word
]->arg
,
3814 RMAP_EVENT_PLIST_DELETED
);
3818 DEFUN (match_local_pref
,
3819 match_local_pref_cmd
,
3820 "match local-preference (0-4294967295)",
3822 "Match local-preference of route\n"
3826 return bgp_route_match_add(vty
, "local-preference",
3827 argv
[idx_number
]->arg
,
3828 RMAP_EVENT_MATCH_ADDED
);
3832 DEFUN (no_match_local_pref
,
3833 no_match_local_pref_cmd
,
3834 "no match local-preference [(0-4294967295)]",
3837 "Match local preference of route\n"
3838 "Local preference value\n")
3840 int idx_localpref
= 3;
3841 if (argc
<= idx_localpref
)
3842 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3843 RMAP_EVENT_MATCH_DELETED
);
3844 return bgp_route_match_delete(vty
, "local-preference",
3845 argv
[idx_localpref
]->arg
,
3846 RMAP_EVENT_MATCH_DELETED
);
3850 DEFUN (match_community
,
3851 match_community_cmd
,
3852 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3854 "Match BGP community list\n"
3855 "Community-list number (standard)\n"
3856 "Community-list number (expanded)\n"
3857 "Community-list name\n"
3858 "Do exact matching of communities\n")
3860 int idx_comm_list
= 2;
3865 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3866 strlen(argv
[idx_comm_list
]->arg
)
3867 + strlen("exact-match") + 2);
3869 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3871 argstr
= argv
[idx_comm_list
]->arg
;
3873 ret
= bgp_route_match_add(vty
, "community", argstr
,
3874 RMAP_EVENT_CLIST_ADDED
);
3876 if (argstr
!= argv
[idx_comm_list
]->arg
)
3877 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3882 DEFUN (no_match_community
,
3883 no_match_community_cmd
,
3884 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3887 "Match BGP community list\n"
3888 "Community-list number (standard)\n"
3889 "Community-list number (expanded)\n"
3890 "Community-list name\n"
3891 "Do exact matching of communities\n")
3893 return bgp_route_match_delete(vty
, "community", NULL
,
3894 RMAP_EVENT_CLIST_DELETED
);
3897 DEFUN (match_lcommunity
,
3898 match_lcommunity_cmd
,
3899 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
3901 "Match BGP large community list\n"
3902 "Large Community-list number (standard)\n"
3903 "Large Community-list number (expanded)\n"
3904 "Large Community-list name\n"
3905 "Do exact matching of communities\n")
3907 int idx_lcomm_list
= 2;
3912 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3913 strlen(argv
[idx_lcomm_list
]->arg
)
3914 + strlen("exact-match") + 2);
3916 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
3918 argstr
= argv
[idx_lcomm_list
]->arg
;
3920 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
3921 RMAP_EVENT_LLIST_ADDED
);
3922 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
3923 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3928 DEFUN (no_match_lcommunity
,
3929 no_match_lcommunity_cmd
,
3930 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
3933 "Match BGP large community list\n"
3934 "Large Community-list number (standard)\n"
3935 "Large Community-list number (expanded)\n"
3936 "Large Community-list name\n"
3937 "Do exact matching of communities\n")
3939 return bgp_route_match_delete(vty
, "large-community", NULL
,
3940 RMAP_EVENT_LLIST_DELETED
);
3943 DEFUN (match_ecommunity
,
3944 match_ecommunity_cmd
,
3945 "match extcommunity <(1-99)|(100-500)|WORD>",
3947 "Match BGP/VPN extended community list\n"
3948 "Extended community-list number (standard)\n"
3949 "Extended community-list number (expanded)\n"
3950 "Extended community-list name\n")
3952 int idx_comm_list
= 2;
3953 return bgp_route_match_add(vty
, "extcommunity",
3954 argv
[idx_comm_list
]->arg
,
3955 RMAP_EVENT_ECLIST_ADDED
);
3959 DEFUN (no_match_ecommunity
,
3960 no_match_ecommunity_cmd
,
3961 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3964 "Match BGP/VPN extended community list\n"
3965 "Extended community-list number (standard)\n"
3966 "Extended community-list number (expanded)\n"
3967 "Extended community-list name\n")
3969 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3970 RMAP_EVENT_ECLIST_DELETED
);
3974 DEFUN (match_aspath
,
3976 "match as-path WORD",
3978 "Match BGP AS path list\n"
3979 "AS path access-list name\n")
3982 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3983 RMAP_EVENT_ASLIST_ADDED
);
3987 DEFUN (no_match_aspath
,
3988 no_match_aspath_cmd
,
3989 "no match as-path [WORD]",
3992 "Match BGP AS path list\n"
3993 "AS path access-list name\n")
3995 return bgp_route_match_delete(vty
, "as-path", NULL
,
3996 RMAP_EVENT_ASLIST_DELETED
);
4000 DEFUN (match_origin
,
4002 "match origin <egp|igp|incomplete>",
4007 "unknown heritage\n")
4010 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4011 return bgp_route_match_add(vty
, "origin", "igp",
4012 RMAP_EVENT_MATCH_ADDED
);
4013 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4014 return bgp_route_match_add(vty
, "origin", "egp",
4015 RMAP_EVENT_MATCH_ADDED
);
4016 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4017 return bgp_route_match_add(vty
, "origin", "incomplete",
4018 RMAP_EVENT_MATCH_ADDED
);
4020 vty_out(vty
, "%% Invalid match origin type\n");
4021 return CMD_WARNING_CONFIG_FAILED
;
4025 DEFUN (no_match_origin
,
4026 no_match_origin_cmd
,
4027 "no match origin [<egp|igp|incomplete>]",
4033 "unknown heritage\n")
4035 return bgp_route_match_delete(vty
, "origin", NULL
,
4036 RMAP_EVENT_MATCH_DELETED
);
4039 DEFUN (set_ip_nexthop_peer
,
4040 set_ip_nexthop_peer_cmd
,
4041 "[no] set ip next-hop peer-address",
4045 "Next hop address\n"
4046 "Use peer address (for BGP only)\n")
4048 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4049 const char *) = strmatch(argv
[0]->text
, "no")
4050 ? generic_set_delete
4053 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4057 DEFUN (set_ip_nexthop_unchanged
,
4058 set_ip_nexthop_unchanged_cmd
,
4059 "[no] set ip next-hop unchanged",
4063 "Next hop address\n"
4064 "Don't modify existing Next hop address\n")
4066 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4067 const char *) = strmatch(argv
[0]->text
, "no")
4068 ? generic_set_delete
4071 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4076 DEFUN (set_local_pref
,
4078 "set local-preference (0-4294967295)",
4080 "BGP local preference path attribute\n"
4081 "Preference value\n")
4084 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4085 "local-preference", argv
[idx_number
]->arg
);
4089 DEFUN (no_set_local_pref
,
4090 no_set_local_pref_cmd
,
4091 "no set local-preference [(0-4294967295)]",
4094 "BGP local preference path attribute\n"
4095 "Preference value\n")
4097 int idx_localpref
= 3;
4098 if (argc
<= idx_localpref
)
4099 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4100 "local-preference", NULL
);
4101 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4102 "local-preference", argv
[idx_localpref
]->arg
);
4108 "set weight (0-4294967295)",
4110 "BGP weight for routing table\n"
4114 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4115 argv
[idx_number
]->arg
);
4119 DEFUN (no_set_weight
,
4121 "no set weight [(0-4294967295)]",
4124 "BGP weight for routing table\n"
4128 if (argc
<= idx_weight
)
4129 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4131 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4132 "weight", argv
[idx_weight
]->arg
);
4135 DEFUN (set_label_index
,
4136 set_label_index_cmd
,
4137 "set label-index (0-1048560)",
4139 "Label index to associate with the prefix\n"
4140 "Label index value\n")
4143 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4144 "label-index", argv
[idx_number
]->arg
);
4147 DEFUN (no_set_label_index
,
4148 no_set_label_index_cmd
,
4149 "no set label-index [(0-1048560)]",
4152 "Label index to associate with the prefix\n"
4153 "Label index value\n")
4155 int idx_label_index
= 3;
4156 if (argc
<= idx_label_index
)
4157 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4158 "label-index", NULL
);
4159 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4160 "label-index", argv
[idx_label_index
]->arg
);
4163 DEFUN (set_aspath_prepend_asn
,
4164 set_aspath_prepend_asn_cmd
,
4165 "set as-path prepend (1-4294967295)...",
4167 "Transform BGP AS_PATH attribute\n"
4168 "Prepend to the as-path\n"
4175 str
= argv_concat(argv
, argc
, idx_asn
);
4176 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4177 "as-path prepend", str
);
4178 XFREE(MTYPE_TMP
, str
);
4183 DEFUN (set_aspath_prepend_lastas
,
4184 set_aspath_prepend_lastas_cmd
,
4185 "set as-path prepend last-as (1-10)",
4187 "Transform BGP AS_PATH attribute\n"
4188 "Prepend to the as-path\n"
4189 "Use the peer's AS-number\n"
4190 "Number of times to insert\n")
4192 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4195 DEFUN (no_set_aspath_prepend
,
4196 no_set_aspath_prepend_cmd
,
4197 "no set as-path prepend [(1-4294967295)]",
4200 "Transform BGP AS_PATH attribute\n"
4201 "Prepend to the as-path\n"
4208 str
= argv_concat(argv
, argc
, idx_asn
);
4209 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4210 "as-path prepend", str
);
4211 XFREE(MTYPE_TMP
, str
);
4215 DEFUN (no_set_aspath_prepend_lastas
,
4216 no_set_aspath_prepend_lastas_cmd
,
4217 "no set as-path prepend last-as [(1-10)]",
4220 "Transform BGP AS_PATH attribute\n"
4221 "Prepend to the as-path\n"
4222 "Use the peers AS-number\n"
4223 "Number of times to insert\n")
4225 return no_set_aspath_prepend(self
, vty
, argc
, argv
);
4228 DEFUN (set_aspath_exclude
,
4229 set_aspath_exclude_cmd
,
4230 "set as-path exclude (1-4294967295)...",
4232 "Transform BGP AS-path attribute\n"
4233 "Exclude from the as-path\n"
4240 str
= argv_concat(argv
, argc
, idx_asn
);
4241 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4242 "as-path exclude", str
);
4243 XFREE(MTYPE_TMP
, str
);
4247 DEFUN (no_set_aspath_exclude
,
4248 no_set_aspath_exclude_cmd
,
4249 "no set as-path exclude (1-4294967295)...",
4252 "Transform BGP AS_PATH attribute\n"
4253 "Exclude from the as-path\n"
4260 str
= argv_concat(argv
, argc
, idx_asn
);
4261 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4262 "as-path exclude", str
);
4263 XFREE(MTYPE_TMP
, str
);
4267 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4268 "no set as-path exclude",
4270 "Transform BGP AS_PATH attribute\n"
4271 "Exclude from the as-path\n")
4273 DEFUN (set_community
,
4275 "set community AA:NN...",
4277 "BGP community attribute\n"
4285 struct community
*com
= NULL
;
4290 b
= buffer_new(1024);
4292 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4293 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4300 buffer_putc(b
, ' ');
4304 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4306 buffer_putstr(b
, "internet");
4309 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4311 buffer_putstr(b
, "local-AS");
4314 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4315 && strncmp(argv
[i
]->arg
, "no-advertise",
4316 strlen(argv
[i
]->arg
))
4318 buffer_putstr(b
, "no-advertise");
4321 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4322 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4324 buffer_putstr(b
, "no-export");
4327 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4328 strlen(argv
[i
]->arg
))
4330 buffer_putstr(b
, "graceful-shutdown");
4333 buffer_putstr(b
, argv
[i
]->arg
);
4335 buffer_putc(b
, '\0');
4337 /* Fetch result string then compile it to communities attribute. */
4338 str
= buffer_getstr(b
);
4342 com
= community_str2com(str
);
4343 XFREE(MTYPE_TMP
, str
);
4346 /* Can't compile user input into communities attribute. */
4348 vty_out(vty
, "%% Malformed communities attribute\n");
4349 return CMD_WARNING_CONFIG_FAILED
;
4352 /* Set communites attribute string. */
4353 str
= community_str(com
, false);
4356 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4357 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4358 strlcpy(argstr
, str
, argstr_sz
);
4359 strlcat(argstr
, " additive", argstr_sz
);
4360 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4361 "community", argstr
);
4362 XFREE(MTYPE_TMP
, argstr
);
4364 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4367 community_free(&com
);
4372 DEFUN (set_community_none
,
4373 set_community_none_cmd
,
4374 "set community none",
4376 "BGP community attribute\n"
4377 "No community attribute\n")
4379 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4380 "community", "none");
4383 DEFUN (no_set_community
,
4384 no_set_community_cmd
,
4385 "no set community AA:NN...",
4388 "BGP community attribute\n"
4391 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4395 ALIAS (no_set_community
,
4396 no_set_community_short_cmd
,
4400 "BGP community attribute\n")
4403 DEFUN (set_community_delete
,
4404 set_community_delete_cmd
,
4405 "set comm-list <(1-99)|(100-500)|WORD> delete",
4407 "set BGP community list (for deletion)\n"
4408 "Community-list number (standard)\n"
4409 "Community-list number (expanded)\n"
4410 "Community-list name\n"
4411 "Delete matching communities\n")
4413 int idx_comm_list
= 2;
4416 args
= argv_concat(argv
, argc
, idx_comm_list
);
4417 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4419 XFREE(MTYPE_TMP
, args
);
4424 DEFUN (no_set_community_delete
,
4425 no_set_community_delete_cmd
,
4426 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4429 "set BGP community list (for deletion)\n"
4430 "Community-list number (standard)\n"
4431 "Community-list number (expanded)\n"
4432 "Community-list name\n"
4433 "Delete matching communities\n")
4435 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4439 DEFUN (set_lcommunity
,
4441 "set large-community AA:BB:CC...",
4443 "BGP large community attribute\n"
4444 "Large Community number in aa:bb:cc format or additive\n")
4449 str
= argv_concat(argv
, argc
, 2);
4450 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4451 "large-community", str
);
4452 XFREE(MTYPE_TMP
, str
);
4457 DEFUN (set_lcommunity_none
,
4458 set_lcommunity_none_cmd
,
4459 "set large-community none",
4461 "BGP large community attribute\n"
4462 "No large community attribute\n")
4464 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4465 "large-community", "none");
4468 DEFUN (no_set_lcommunity
,
4469 no_set_lcommunity_cmd
,
4470 "no set large-community none",
4473 "BGP large community attribute\n"
4474 "No community attribute\n")
4476 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4477 "large-community", NULL
);
4480 DEFUN (no_set_lcommunity1
,
4481 no_set_lcommunity1_cmd
,
4482 "no set large-community AA:BB:CC...",
4485 "BGP large community attribute\n"
4486 "Large community in AA:BB:CC... format or additive\n")
4488 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4489 "large-community", NULL
);
4492 ALIAS (no_set_lcommunity1
,
4493 no_set_lcommunity1_short_cmd
,
4494 "no set large-community",
4497 "BGP large community attribute\n")
4499 DEFUN (set_lcommunity_delete
,
4500 set_lcommunity_delete_cmd
,
4501 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4503 "set BGP large community list (for deletion)\n"
4504 "Large Community-list number (standard)\n"
4505 "Large Communitly-list number (expanded)\n"
4506 "Large Community-list name\n"
4507 "Delete matching large communities\n")
4509 int idx_lcomm_list
= 2;
4512 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
4513 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4514 "large-comm-list", args
);
4515 XFREE(MTYPE_TMP
, args
);
4520 DEFUN (no_set_lcommunity_delete
,
4521 no_set_lcommunity_delete_cmd
,
4522 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4525 "set BGP large community list (for deletion)\n"
4526 "Large Community-list number (standard)\n"
4527 "Large Communitly-list number (expanded)\n"
4528 "Large Community-list name\n"
4529 "Delete matching large communities\n")
4531 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4532 "large-comm-list", NULL
);
4535 ALIAS (no_set_lcommunity_delete
,
4536 no_set_lcommunity_delete_short_cmd
,
4537 "no set large-comm-list",
4540 "set BGP large community list (for deletion)\n")
4542 DEFUN (set_ecommunity_rt
,
4543 set_ecommunity_rt_cmd
,
4544 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4546 "BGP extended community attribute\n"
4547 "Route Target extended community\n"
4548 "VPN extended community\n")
4554 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4555 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4556 "extcommunity rt", str
);
4557 XFREE(MTYPE_TMP
, str
);
4562 DEFUN (no_set_ecommunity_rt
,
4563 no_set_ecommunity_rt_cmd
,
4564 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4567 "BGP extended community attribute\n"
4568 "Route Target extended community\n"
4569 "VPN extended community\n")
4571 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4572 "extcommunity rt", NULL
);
4575 ALIAS (no_set_ecommunity_rt
,
4576 no_set_ecommunity_rt_short_cmd
,
4577 "no set extcommunity rt",
4580 "BGP extended community attribute\n"
4581 "Route Target extended community\n")
4583 DEFUN (set_ecommunity_soo
,
4584 set_ecommunity_soo_cmd
,
4585 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4587 "BGP extended community attribute\n"
4588 "Site-of-Origin extended community\n"
4589 "VPN extended community\n")
4595 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4596 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4597 "extcommunity soo", str
);
4598 XFREE(MTYPE_TMP
, str
);
4603 DEFUN (no_set_ecommunity_soo
,
4604 no_set_ecommunity_soo_cmd
,
4605 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4608 "BGP extended community attribute\n"
4609 "Site-of-Origin extended community\n"
4610 "VPN extended community\n")
4612 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4613 "extcommunity soo", NULL
);
4616 ALIAS (no_set_ecommunity_soo
,
4617 no_set_ecommunity_soo_short_cmd
,
4618 "no set extcommunity soo",
4621 "GP extended community attribute\n"
4622 "Site-of-Origin extended community\n")
4626 "set origin <egp|igp|incomplete>",
4631 "unknown heritage\n")
4634 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4635 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4637 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4638 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4640 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4641 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4642 "origin", "incomplete");
4644 vty_out(vty
, "%% Invalid set origin type\n");
4645 return CMD_WARNING_CONFIG_FAILED
;
4649 DEFUN (no_set_origin
,
4651 "no set origin [<egp|igp|incomplete>]",
4657 "unknown heritage\n")
4659 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4664 DEFUN (set_atomic_aggregate
,
4665 set_atomic_aggregate_cmd
,
4666 "set atomic-aggregate",
4668 "BGP atomic aggregate attribute\n" )
4670 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4671 "atomic-aggregate", NULL
);
4674 DEFUN (no_set_atomic_aggregate
,
4675 no_set_atomic_aggregate_cmd
,
4676 "no set atomic-aggregate",
4679 "BGP atomic aggregate attribute\n" )
4681 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4682 "atomic-aggregate", NULL
);
4685 DEFUN (set_aggregator_as
,
4686 set_aggregator_as_cmd
,
4687 "set aggregator as (1-4294967295) A.B.C.D",
4689 "BGP aggregator attribute\n"
4690 "AS number of aggregator\n"
4692 "IP address of aggregator\n")
4697 struct in_addr address
;
4700 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4702 vty_out(vty
, "Aggregator IP address is invalid\n");
4703 return CMD_WARNING_CONFIG_FAILED
;
4706 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4707 strlen(argv
[idx_number
]->arg
)
4708 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4710 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4712 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4713 "aggregator as", argstr
);
4715 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4721 DEFUN (no_set_aggregator_as
,
4722 no_set_aggregator_as_cmd
,
4723 "no set aggregator as [(1-4294967295) A.B.C.D]",
4726 "BGP aggregator attribute\n"
4727 "AS number of aggregator\n"
4729 "IP address of aggregator\n")
4734 struct in_addr address
;
4737 if (argc
<= idx_asn
)
4738 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4739 "aggregator as", NULL
);
4741 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4743 vty_out(vty
, "Aggregator IP address is invalid\n");
4744 return CMD_WARNING_CONFIG_FAILED
;
4747 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4748 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4751 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4753 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4754 "aggregator as", argstr
);
4756 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4761 DEFUN (match_ipv6_next_hop
,
4762 match_ipv6_next_hop_cmd
,
4763 "match ipv6 next-hop X:X::X:X",
4766 "Match IPv6 next-hop address of route\n"
4767 "IPv6 address of next hop\n")
4770 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4771 RMAP_EVENT_MATCH_ADDED
);
4774 DEFUN (no_match_ipv6_next_hop
,
4775 no_match_ipv6_next_hop_cmd
,
4776 "no match ipv6 next-hop X:X::X:X",
4780 "Match IPv6 next-hop address of route\n"
4781 "IPv6 address of next hop\n")
4784 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4785 RMAP_EVENT_MATCH_DELETED
);
4789 DEFUN (set_ipv6_nexthop_peer
,
4790 set_ipv6_nexthop_peer_cmd
,
4791 "set ipv6 next-hop peer-address",
4794 "Next hop address\n"
4795 "Use peer address (for BGP only)\n")
4797 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4798 "ipv6 next-hop peer-address", NULL
);
4801 DEFUN (no_set_ipv6_nexthop_peer
,
4802 no_set_ipv6_nexthop_peer_cmd
,
4803 "no set ipv6 next-hop peer-address",
4807 "IPv6 next-hop address\n"
4808 "Use peer address (for BGP only)\n")
4810 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4811 "ipv6 next-hop peer-address", NULL
);
4814 DEFUN (set_ipv6_nexthop_prefer_global
,
4815 set_ipv6_nexthop_prefer_global_cmd
,
4816 "set ipv6 next-hop prefer-global",
4819 "IPv6 next-hop address\n"
4820 "Prefer global over link-local if both exist\n")
4822 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4823 "ipv6 next-hop prefer-global", NULL
);
4827 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4828 no_set_ipv6_nexthop_prefer_global_cmd
,
4829 "no set ipv6 next-hop prefer-global",
4833 "IPv6 next-hop address\n"
4834 "Prefer global over link-local if both exist\n")
4836 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4837 "ipv6 next-hop prefer-global", NULL
);
4840 DEFUN (set_ipv6_nexthop_global
,
4841 set_ipv6_nexthop_global_cmd
,
4842 "set ipv6 next-hop global X:X::X:X",
4845 "IPv6 next-hop address\n"
4846 "IPv6 global address\n"
4847 "IPv6 address of next hop\n")
4850 struct in6_addr addr
;
4853 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4855 vty_out(vty
, "%% Malformed nexthop address\n");
4856 return CMD_WARNING_CONFIG_FAILED
;
4858 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4859 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4860 vty_out(vty
, "%% Invalid global nexthop address\n");
4861 return CMD_WARNING_CONFIG_FAILED
;
4864 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4865 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4869 DEFUN (no_set_ipv6_nexthop_global
,
4870 no_set_ipv6_nexthop_global_cmd
,
4871 "no set ipv6 next-hop global X:X::X:X",
4875 "IPv6 next-hop address\n"
4876 "IPv6 global address\n"
4877 "IPv6 address of next hop\n")
4880 if (argc
<= idx_ipv6
)
4881 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4882 "ipv6 next-hop global", NULL
);
4883 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4884 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4887 #ifdef KEEP_OLD_VPN_COMMANDS
4888 DEFUN (set_vpn_nexthop
,
4889 set_vpn_nexthop_cmd
,
4890 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4892 "VPNv4 information\n"
4893 "VPN next-hop address\n"
4894 "IP address of next hop\n"
4895 "VPNv6 information\n"
4896 "VPN next-hop address\n"
4897 "IPv6 address of next hop\n")
4903 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4905 return generic_set_add(
4906 vty
, VTY_GET_CONTEXT(route_map_index
),
4907 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4909 return generic_set_add(
4910 vty
, VTY_GET_CONTEXT(route_map_index
),
4911 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4916 DEFUN (no_set_vpn_nexthop
,
4917 no_set_vpn_nexthop_cmd
,
4918 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4921 "VPNv4 information\n"
4922 "VPN next-hop address\n"
4923 "IP address of next hop\n"
4924 "VPNv6 information\n"
4925 "VPN next-hop address\n"
4926 "IPv6 address of next hop\n")
4936 arg
= argv
[idx_ip
]->arg
;
4937 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4939 return generic_set_delete(
4940 vty
, VTY_GET_CONTEXT(route_map_index
),
4941 "ipv4 vpn next-hop", arg
);
4943 return generic_set_delete(
4944 vty
, VTY_GET_CONTEXT(route_map_index
),
4945 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4949 #endif /* KEEP_OLD_VPN_COMMANDS */
4951 DEFUN (set_ipx_vpn_nexthop
,
4952 set_ipx_vpn_nexthop_cmd
,
4953 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4955 "IPv4 information\n"
4956 "IPv6 information\n"
4958 "VPN next-hop address\n"
4959 "IP address of next hop\n"
4960 "IPv6 address of next hop\n")
4966 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4968 return generic_set_add(
4969 vty
, VTY_GET_CONTEXT(route_map_index
),
4970 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4972 return generic_set_add(
4973 vty
, VTY_GET_CONTEXT(route_map_index
),
4974 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4979 DEFUN (no_set_ipx_vpn_nexthop
,
4980 no_set_ipx_vpn_nexthop_cmd
,
4981 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4984 "IPv4 information\n"
4985 "IPv6 information\n"
4987 "VPN next-hop address\n"
4988 "IP address of next hop\n"
4989 "IPv6 address of next hop\n")
4999 arg
= argv
[idx_ip
]->arg
;
5000 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5002 return generic_set_delete(
5003 vty
, VTY_GET_CONTEXT(route_map_index
),
5004 "ipv4 vpn next-hop", arg
);
5006 return generic_set_delete(
5007 vty
, VTY_GET_CONTEXT(route_map_index
),
5008 "ipv6 vpn next-hop", arg
);
5013 DEFUN (set_originator_id
,
5014 set_originator_id_cmd
,
5015 "set originator-id A.B.C.D",
5017 "BGP originator ID attribute\n"
5018 "IP address of originator\n")
5021 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5022 "originator-id", argv
[idx_ipv4
]->arg
);
5026 DEFUN (no_set_originator_id
,
5027 no_set_originator_id_cmd
,
5028 "no set originator-id [A.B.C.D]",
5031 "BGP originator ID attribute\n"
5032 "IP address of originator\n")
5036 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
5038 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5039 "originator-id", arg
);
5043 /* Initialization of route map. */
5044 void bgp_route_map_init(void)
5048 route_map_add_hook(bgp_route_map_add
);
5049 route_map_delete_hook(bgp_route_map_delete
);
5050 route_map_event_hook(bgp_route_map_event
);
5052 route_map_match_interface_hook(generic_match_add
);
5053 route_map_no_match_interface_hook(generic_match_delete
);
5055 route_map_match_ip_address_hook(generic_match_add
);
5056 route_map_no_match_ip_address_hook(generic_match_delete
);
5058 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
5059 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
5061 route_map_match_ip_next_hop_hook(generic_match_add
);
5062 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
5064 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
5065 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5067 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5068 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5070 route_map_match_ipv6_address_hook(generic_match_add
);
5071 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5073 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5074 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5076 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5077 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5079 route_map_match_metric_hook(generic_match_add
);
5080 route_map_no_match_metric_hook(generic_match_delete
);
5082 route_map_match_tag_hook(generic_match_add
);
5083 route_map_no_match_tag_hook(generic_match_delete
);
5085 route_map_set_ip_nexthop_hook(generic_set_add
);
5086 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5088 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5089 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5091 route_map_set_metric_hook(generic_set_add
);
5092 route_map_no_set_metric_hook(generic_set_delete
);
5094 route_map_set_tag_hook(generic_set_add
);
5095 route_map_no_set_tag_hook(generic_set_delete
);
5097 route_map_install_match(&route_match_peer_cmd
);
5098 route_map_install_match(&route_match_local_pref_cmd
);
5099 #if defined(HAVE_LUA)
5100 route_map_install_match(&route_match_command_cmd
);
5102 route_map_install_match(&route_match_ip_address_cmd
);
5103 route_map_install_match(&route_match_ip_next_hop_cmd
);
5104 route_map_install_match(&route_match_ip_route_source_cmd
);
5105 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5106 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5107 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5108 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5109 route_map_install_match(&route_match_aspath_cmd
);
5110 route_map_install_match(&route_match_community_cmd
);
5111 route_map_install_match(&route_match_lcommunity_cmd
);
5112 route_map_install_match(&route_match_ecommunity_cmd
);
5113 route_map_install_match(&route_match_local_pref_cmd
);
5114 route_map_install_match(&route_match_metric_cmd
);
5115 route_map_install_match(&route_match_origin_cmd
);
5116 route_map_install_match(&route_match_probability_cmd
);
5117 route_map_install_match(&route_match_interface_cmd
);
5118 route_map_install_match(&route_match_tag_cmd
);
5119 route_map_install_match(&route_match_mac_address_cmd
);
5120 route_map_install_match(&route_match_evpn_vni_cmd
);
5121 route_map_install_match(&route_match_evpn_route_type_cmd
);
5122 route_map_install_match(&route_match_evpn_default_route_cmd
);
5123 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5125 route_map_install_set(&route_set_ip_nexthop_cmd
);
5126 route_map_install_set(&route_set_local_pref_cmd
);
5127 route_map_install_set(&route_set_weight_cmd
);
5128 route_map_install_set(&route_set_label_index_cmd
);
5129 route_map_install_set(&route_set_metric_cmd
);
5130 route_map_install_set(&route_set_aspath_prepend_cmd
);
5131 route_map_install_set(&route_set_aspath_exclude_cmd
);
5132 route_map_install_set(&route_set_origin_cmd
);
5133 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5134 route_map_install_set(&route_set_aggregator_as_cmd
);
5135 route_map_install_set(&route_set_community_cmd
);
5136 route_map_install_set(&route_set_community_delete_cmd
);
5137 route_map_install_set(&route_set_lcommunity_cmd
);
5138 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5139 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5140 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5141 route_map_install_set(&route_set_originator_id_cmd
);
5142 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5143 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5144 route_map_install_set(&route_set_tag_cmd
);
5145 route_map_install_set(&route_set_label_index_cmd
);
5147 install_element(RMAP_NODE
, &match_peer_cmd
);
5148 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5149 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5150 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5151 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5152 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5153 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5154 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5155 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5156 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5157 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5158 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5159 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5160 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5161 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5162 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5163 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5165 install_element(RMAP_NODE
, &match_aspath_cmd
);
5166 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5167 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5168 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5169 install_element(RMAP_NODE
, &match_community_cmd
);
5170 install_element(RMAP_NODE
, &no_match_community_cmd
);
5171 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5172 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5173 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5174 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5175 install_element(RMAP_NODE
, &match_origin_cmd
);
5176 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5177 install_element(RMAP_NODE
, &match_probability_cmd
);
5178 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5180 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5181 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5182 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5183 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5184 install_element(RMAP_NODE
, &set_weight_cmd
);
5185 install_element(RMAP_NODE
, &set_label_index_cmd
);
5186 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5187 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5188 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5189 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5190 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5191 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5192 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
5193 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5194 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5195 install_element(RMAP_NODE
, &set_origin_cmd
);
5196 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5197 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5198 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5199 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5200 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5201 install_element(RMAP_NODE
, &set_community_cmd
);
5202 install_element(RMAP_NODE
, &set_community_none_cmd
);
5203 install_element(RMAP_NODE
, &no_set_community_cmd
);
5204 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5205 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5206 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5207 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5208 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5209 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5210 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5211 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5212 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5213 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5214 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5215 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5216 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5217 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5218 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5219 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5220 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5221 #ifdef KEEP_OLD_VPN_COMMANDS
5222 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5223 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5224 #endif /* KEEP_OLD_VPN_COMMANDS */
5225 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5226 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5227 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5228 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5230 route_map_install_match(&route_match_ipv6_address_cmd
);
5231 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5232 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5233 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5234 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5235 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5236 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5237 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5239 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5240 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5241 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5242 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5243 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5244 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5245 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5246 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5247 #if defined(HAVE_LUA)
5248 install_element(RMAP_NODE
, &match_command_cmd
);
5249 install_element(RMAP_NODE
, &no_match_command_cmd
);
5253 void bgp_route_map_terminate(void)
5255 /* ToDo: Cleanup all the used memory */