1 /* Route map function of bgpd.
2 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #ifdef HAVE_LIBPCREPOSIX
33 #include <pcreposix.h>
36 #endif /* HAVE_LIBPCREPOSIX */
38 #include "sockunion.h"
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_table.h"
45 #include "bgpd/bgp_attr.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_packet.h"
48 #include "bgpd/bgp_route.h"
49 #include "bgpd/bgp_zebra.h"
50 #include "bgpd/bgp_regex.h"
51 #include "bgpd/bgp_community.h"
52 #include "bgpd/bgp_clist.h"
53 #include "bgpd/bgp_filter.h"
54 #include "bgpd/bgp_mplsvpn.h"
55 #include "bgpd/bgp_ecommunity.h"
56 #include "bgpd/bgp_lcommunity.h"
57 #include "bgpd/bgp_vty.h"
58 #include "bgpd/bgp_debug.h"
59 #include "bgpd/bgp_evpn.h"
60 #include "bgpd/bgp_evpn_private.h"
61 #include "bgpd/bgp_evpn_vty.h"
62 #include "bgpd/bgp_mplsvpn.h"
63 #include "bgpd/bgp_pbr.h"
64 #include "bgpd/bgp_flowspec_util.h"
65 #include "bgpd/bgp_encap_types.h"
68 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
71 #ifndef VTYSH_EXTRACT_PL
72 #include "bgpd/bgp_routemap_clippy.c"
75 /* Memo of route-map commands.
84 ip route-source : Done
88 ipv6 route-source: (This will not be implemented by bgpd)
89 ipv6 prefix-list : Done
90 length : (This will not be implemented by bgpd)
92 route-type : (This will not be implemented by bgpd)
94 local-preference : Done
96 set as-path prepend : Done
98 automatic-tag : (This will not be implemented by bgpd)
100 large-community : Done
101 large-comm-list : Done
104 default : (This will not be implemented by bgpd)
105 interface : (This will not be implemented by bgpd)
106 ip default : (This will not be implemented by bgpd)
108 ip precedence : (This will not be implemented by bgpd)
109 ip tos : (This will not be implemented by bgpd)
110 level : (This will not be implemented by bgpd)
111 local-preference : Done
113 metric-type : Not yet
121 set ipv6 next-hop global: Done
122 set ipv6 next-hop prefer-global: Done
123 set ipv6 next-hop local : Done
124 set as-path exclude : Done
128 /* generic value manipulation to be shared in multiple rules */
130 #define RMAP_VALUE_SET 0
131 #define RMAP_VALUE_ADD 1
132 #define RMAP_VALUE_SUB 2
140 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
142 if (rv
->variable
== 0 && value
== rv
->value
)
148 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
153 switch (rv
->variable
) {
162 switch (rv
->action
) {
164 if (current
> UINT32_MAX
- value
)
166 return current
+ value
;
168 if (current
<= value
)
170 return current
- value
;
176 static void *route_value_compile(const char *arg
)
178 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
179 unsigned long larg
= 0;
181 struct rmap_value
*rv
;
184 action
= RMAP_VALUE_ADD
;
186 } else if (arg
[0] == '-') {
187 action
= RMAP_VALUE_SUB
;
191 if (all_digit(arg
)) {
193 larg
= strtoul(arg
, &endptr
, 10);
194 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
197 if (strcmp(arg
, "rtt") == 0)
203 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
211 static void route_value_free(void *rule
)
213 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
216 /* generic as path object to be shared in multiple rules */
218 static void *route_aspath_compile(const char *arg
)
220 struct aspath
*aspath
;
222 aspath
= aspath_str2aspath(arg
);
228 static void route_aspath_free(void *rule
)
230 struct aspath
*aspath
= rule
;
234 struct bgp_match_peer_compiled
{
239 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
241 /* Compares the peer specified in the 'match peer' clause with the peer
242 received in bgp_path_info->peer. If it is the same, or if the peer structure
243 received is a peer_group containing it, returns RMAP_MATCH. */
244 static enum route_map_cmd_result_t
245 route_match_peer(void *rule
, const struct prefix
*prefix
,
246 route_map_object_t type
, void *object
)
248 struct bgp_match_peer_compiled
*pc
;
250 union sockunion su_def
= {
251 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
252 struct peer_group
*group
;
254 struct listnode
*node
, *nnode
;
256 if (type
== RMAP_BGP
) {
259 peer
= ((struct bgp_path_info
*)object
)->peer
;
265 if (strcmp(peer
->conf_if
, pc
->interface
) == 0)
271 /* If su='0.0.0.0' (command 'match peer local'), and it's a
273 REDISTRIBUTE, AGGREGATE-ADDRESS or DEFAULT_GENERATED route
276 if (sockunion_same(su
, &su_def
)) {
278 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
279 || CHECK_FLAG(peer
->rmap_type
,
280 PEER_RMAP_TYPE_REDISTRIBUTE
)
281 || CHECK_FLAG(peer
->rmap_type
,
282 PEER_RMAP_TYPE_AGGREGATE
)
283 || CHECK_FLAG(peer
->rmap_type
,
284 PEER_RMAP_TYPE_DEFAULT
))
291 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
292 if (sockunion_same(su
, &peer
->su
))
298 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
300 if (sockunion_same(su
, &peer
->su
))
309 static void *route_match_peer_compile(const char *arg
)
311 struct bgp_match_peer_compiled
*pc
;
314 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
315 sizeof(struct bgp_match_peer_compiled
));
317 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
319 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
326 /* Free route map's compiled `ip address' value. */
327 static void route_match_peer_free(void *rule
)
329 struct bgp_match_peer_compiled
*pc
= rule
;
331 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
333 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
336 /* Route map commands for ip address matching. */
337 struct route_map_rule_cmd route_match_peer_cmd
= {"peer", route_match_peer
,
338 route_match_peer_compile
,
339 route_match_peer_free
};
341 #if defined(HAVE_LUA)
342 static enum route_map_cmd_result_t
343 route_match_command(void *rule
, const struct prefix
*prefix
,
344 route_map_object_t type
, void *object
)
346 int status
= RMAP_NOMATCH
;
347 u_int32_t locpref
= 0;
348 u_int32_t newlocpref
= 0;
349 enum lua_rm_status lrm_status
;
350 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
351 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
357 * Setup the prefix information to pass in
359 lua_setup_prefix_table(L
, prefix
);
361 zlog_debug("Set up prefix table");
363 * Setup the bgp_path_info information
366 lua_pushinteger(L
, path
->attr
->med
);
367 lua_setfield(L
, -2, "metric");
368 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
369 lua_setfield(L
, -2, "ifindex");
370 lua_pushstring(L
, path
->attr
->aspath
->str
);
371 lua_setfield(L
, -2, "aspath");
372 lua_pushinteger(L
, path
->attr
->local_pref
);
373 lua_setfield(L
, -2, "localpref");
374 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
375 lua_setglobal(L
, "nexthop");
377 zlog_debug("Set up nexthop information");
381 lrm_status
= lua_run_rm_rule(L
, rule
);
382 switch (lrm_status
) {
384 zlog_debug("RM_FAILURE");
387 zlog_debug("RM_NOMATCH");
389 case LUA_RM_MATCH_AND_CHANGE
:
390 zlog_debug("MATCH AND CHANGE");
391 lua_getglobal(L
, "nexthop");
392 path
->attr
->med
= get_integer(L
, "metric");
394 * This needs to be abstraced with the set function
396 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
397 locpref
= path
->attr
->local_pref
;
398 newlocpref
= get_integer(L
, "localpref");
399 if (newlocpref
!= locpref
) {
400 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
401 path
->attr
->local_pref
= newlocpref
;
406 zlog_debug("MATCH ONLY");
414 static void *route_match_command_compile(const char *arg
)
418 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
423 route_match_command_free(void *rule
)
425 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
428 struct route_map_rule_cmd route_match_command_cmd
= {
431 route_match_command_compile
,
432 route_match_command_free
436 /* `match ip address IP_ACCESS_LIST' */
438 /* Match function should return 1 if match is success else return
440 static enum route_map_cmd_result_t
441 route_match_ip_address(void *rule
, const struct prefix
*prefix
,
442 route_map_object_t type
, void *object
)
444 struct access_list
*alist
;
446 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
447 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
451 return (access_list_apply(alist
, prefix
) == FILTER_DENY
458 /* Route map `ip address' match statement. `arg' should be
460 static void *route_match_ip_address_compile(const char *arg
)
462 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
465 /* Free route map's compiled `ip address' value. */
466 static void route_match_ip_address_free(void *rule
)
468 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
471 /* Route map commands for ip address matching. */
472 struct route_map_rule_cmd route_match_ip_address_cmd
= {
473 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
474 route_match_ip_address_free
};
476 /* `match ip next-hop IP_ADDRESS' */
478 /* Match function return 1 if match is success else return zero. */
479 static enum route_map_cmd_result_t
480 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
,
481 route_map_object_t type
, void *object
)
483 struct access_list
*alist
;
484 struct bgp_path_info
*path
;
485 struct prefix_ipv4 p
;
487 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
490 p
.prefix
= path
->attr
->nexthop
;
491 p
.prefixlen
= IPV4_MAX_BITLEN
;
493 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
497 return (access_list_apply(alist
, &p
) == FILTER_DENY
504 /* Route map `ip next-hop' match statement. `arg' is
506 static void *route_match_ip_next_hop_compile(const char *arg
)
508 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
511 /* Free route map's compiled `ip address' value. */
512 static void route_match_ip_next_hop_free(void *rule
)
514 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
517 /* Route map commands for ip next-hop matching. */
518 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
519 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
520 route_match_ip_next_hop_free
};
522 /* `match ip route-source ACCESS-LIST' */
524 /* Match function return 1 if match is success else return zero. */
525 static enum route_map_cmd_result_t
526 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
,
527 route_map_object_t type
, void *object
)
529 struct access_list
*alist
;
530 struct bgp_path_info
*path
;
532 struct prefix_ipv4 p
;
534 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
538 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
542 p
.prefix
= peer
->su
.sin
.sin_addr
;
543 p
.prefixlen
= IPV4_MAX_BITLEN
;
545 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
549 return (access_list_apply(alist
, &p
) == FILTER_DENY
556 /* Route map `ip route-source' match statement. `arg' is
558 static void *route_match_ip_route_source_compile(const char *arg
)
560 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
563 /* Free route map's compiled `ip address' value. */
564 static void route_match_ip_route_source_free(void *rule
)
566 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
569 /* Route map commands for ip route-source matching. */
570 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
571 "ip route-source", route_match_ip_route_source
,
572 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
574 static enum route_map_cmd_result_t
575 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
576 const struct prefix
*p
)
579 struct bgp_pbr_entry_main api
;
581 memset(&api
, 0, sizeof(api
));
583 /* extract match from flowspec entries */
584 ret
= bgp_flowspec_match_rules_fill(
585 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
586 p
->u
.prefix_flowspec
.prefixlen
, &api
);
589 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
590 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
591 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
593 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
596 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
597 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
598 if (family2afi((&api
.src_prefix
)->family
) != afi
)
600 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
607 static enum route_map_cmd_result_t
608 route_match_address_prefix_list(void *rule
, afi_t afi
,
609 const struct prefix
*prefix
,
610 route_map_object_t type
, void *object
)
612 struct prefix_list
*plist
;
614 if (type
!= RMAP_BGP
)
617 plist
= prefix_list_lookup(afi
, (char *)rule
);
621 if (prefix
->family
== AF_FLOWSPEC
)
622 return route_match_prefix_list_flowspec(afi
, plist
,
624 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
628 static enum route_map_cmd_result_t
629 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
630 route_map_object_t type
, void *object
)
632 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, type
,
636 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
638 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
641 static void route_match_ip_address_prefix_list_free(void *rule
)
643 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
646 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
647 "ip address prefix-list", route_match_ip_address_prefix_list
,
648 route_match_ip_address_prefix_list_compile
,
649 route_match_ip_address_prefix_list_free
};
651 /* `match ip next-hop prefix-list PREFIX_LIST' */
653 static enum route_map_cmd_result_t
654 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
655 route_map_object_t type
, void *object
)
657 struct prefix_list
*plist
;
658 struct bgp_path_info
*path
;
659 struct prefix_ipv4 p
;
661 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
664 p
.prefix
= path
->attr
->nexthop
;
665 p
.prefixlen
= IPV4_MAX_BITLEN
;
667 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
671 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
678 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
680 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
683 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
685 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
688 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
689 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
690 route_match_ip_next_hop_prefix_list_compile
,
691 route_match_ip_next_hop_prefix_list_free
};
693 /* `match ip next-hop type <blackhole>' */
695 static enum route_map_cmd_result_t
696 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
697 route_map_object_t type
, void *object
)
699 struct bgp_path_info
*path
;
701 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
702 path
= (struct bgp_path_info
*)object
;
703 if (!path
|| !path
->attr
)
706 /* If nexthop interface's index can't be resolved and nexthop is
707 set to any address then mark it as type `blackhole`.
708 This logic works for matching kernel/static routes like:
709 `ip route add blackhole 10.0.0.1`. */
710 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
711 && !path
->attr
->nh_ifindex
)
717 static void *route_match_ip_next_hop_type_compile(const char *arg
)
719 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
722 static void route_match_ip_next_hop_type_free(void *rule
)
724 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
727 static struct route_map_rule_cmd route_match_ip_next_hop_type_cmd
= {
728 "ip next-hop type", route_match_ip_next_hop_type
,
729 route_match_ip_next_hop_type_compile
,
730 route_match_ip_next_hop_type_free
};
732 /* `match ip route-source prefix-list PREFIX_LIST' */
734 static enum route_map_cmd_result_t
735 route_match_ip_route_source_prefix_list(void *rule
,
736 const struct prefix
*prefix
,
737 route_map_object_t type
, void *object
)
739 struct prefix_list
*plist
;
740 struct bgp_path_info
*path
;
742 struct prefix_ipv4 p
;
744 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
748 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
752 p
.prefix
= peer
->su
.sin
.sin_addr
;
753 p
.prefixlen
= IPV4_MAX_BITLEN
;
755 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
759 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
766 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
768 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
771 static void route_match_ip_route_source_prefix_list_free(void *rule
)
773 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
776 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
777 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
778 route_match_ip_route_source_prefix_list_compile
,
779 route_match_ip_route_source_prefix_list_free
};
781 /* `match evpn default-route' */
783 /* Match function should return 1 if match is success else 0 */
784 static enum route_map_cmd_result_t
785 route_match_evpn_default_route(void *rule
, const struct prefix
*p
,
786 route_map_object_t type
, void *object
)
788 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
794 /* Route map commands for default-route matching. */
795 struct route_map_rule_cmd route_match_evpn_default_route_cmd
= {
796 "evpn default-route", route_match_evpn_default_route
, NULL
, NULL
};
798 /* `match mac address MAC_ACCESS_LIST' */
800 /* Match function should return 1 if match is success else return
802 static enum route_map_cmd_result_t
803 route_match_mac_address(void *rule
, const struct prefix
*prefix
,
804 route_map_object_t type
, void *object
)
806 struct access_list
*alist
;
809 if (type
== RMAP_BGP
) {
810 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
814 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
817 p
.family
= AF_ETHERNET
;
818 p
.prefixlen
= ETH_ALEN
* 8;
819 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
821 return (access_list_apply(alist
, &p
) == FILTER_DENY
829 /* Route map `mac address' match statement. `arg' should be
831 static void *route_match_mac_address_compile(const char *arg
)
833 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
836 /* Free route map's compiled `ip address' value. */
837 static void route_match_mac_address_free(void *rule
)
839 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
842 /* Route map commands for mac address matching. */
843 struct route_map_rule_cmd route_match_mac_address_cmd
= {
844 "mac address", route_match_mac_address
, route_match_mac_address_compile
,
845 route_match_mac_address_free
};
848 * Match function returns:
849 * ...RMAP_MATCH if match is found.
850 * ...RMAP_NOMATCH if match is not found.
851 * ...RMAP_NOOP to ignore this match check.
853 static enum route_map_cmd_result_t
854 route_match_vni(void *rule
, const struct prefix
*prefix
,
855 route_map_object_t type
, void *object
)
858 unsigned int label_cnt
= 0;
859 struct bgp_path_info
*path
= NULL
;
860 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
862 if (type
== RMAP_BGP
) {
863 vni
= *((vni_t
*)rule
);
864 path
= (struct bgp_path_info
*)object
;
867 * This rmap filter is valid for vxlan tunnel type only.
868 * For any other tunnel type, return noop to ignore
871 if (path
->attr
&& path
->attr
->encap_tunneltype
!=
872 BGP_ENCAP_TYPE_VXLAN
)
876 * Apply filter to type 1, 2, 5 routes only.
877 * Other route types do not have vni label.
879 if (evp
&& (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
&&
880 evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
&&
881 evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
884 if (path
->extra
== NULL
)
887 for ( ; label_cnt
< BGP_MAX_LABELS
&&
888 label_cnt
< path
->extra
->num_labels
; label_cnt
++) {
889 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
897 /* Route map `vni' match statement. */
898 static void *route_match_vni_compile(const char *arg
)
903 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
905 *vni
= strtoul(arg
, &end
, 10);
907 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
914 /* Free route map's compiled `vni' value. */
915 static void route_match_vni_free(void *rule
)
917 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
920 /* Route map commands for vni matching. */
921 struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
922 "evpn vni", route_match_vni
, route_match_vni_compile
,
923 route_match_vni_free
};
925 /* `match evpn route-type' */
927 /* Match function should return 1 if match is success else return
929 static enum route_map_cmd_result_t
930 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
,
931 route_map_object_t type
, void *object
)
933 uint8_t route_type
= 0;
935 if (type
== RMAP_BGP
) {
936 route_type
= *((uint8_t *)rule
);
938 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
945 /* Route map `route-type' match statement. */
946 static void *route_match_evpn_route_type_compile(const char *arg
)
948 uint8_t *route_type
= NULL
;
950 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
952 if (strncmp(arg
, "ma", 2) == 0)
953 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
954 else if (strncmp(arg
, "mu", 2) == 0)
955 *route_type
= BGP_EVPN_IMET_ROUTE
;
957 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
962 /* Free route map's compiled `route-type' value. */
963 static void route_match_evpn_route_type_free(void *rule
)
965 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
968 /* Route map commands for evpn route-type matching. */
969 struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
970 "evpn route-type", route_match_evpn_route_type
,
971 route_match_evpn_route_type_compile
, route_match_evpn_route_type_free
};
973 /* Route map commands for VRF route leak with source vrf matching */
974 static enum route_map_cmd_result_t
975 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
976 route_map_object_t type
, void *object
)
978 struct bgp_path_info
*path
;
981 if (type
== RMAP_BGP
) {
983 path
= (struct bgp_path_info
*)object
;
985 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
988 if (path
->extra
== NULL
)
991 if (strncmp(vrf_name
, vrf_id_to_name(
992 path
->extra
->bgp_orig
->vrf_id
), VRF_NAMSIZ
)
1000 static void *route_match_vrl_source_vrf_compile(const char *arg
)
1002 uint8_t *vrf_name
= NULL
;
1004 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1009 /* Free route map's compiled `route-type' value. */
1010 static void route_match_vrl_source_vrf_free(void *rule
)
1012 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1015 struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1016 "source-vrf", route_match_vrl_source_vrf
,
1017 route_match_vrl_source_vrf_compile
,
1018 route_match_vrl_source_vrf_free
};
1020 /* `match local-preference LOCAL-PREF' */
1022 /* Match function return 1 if match is success else return zero. */
1023 static enum route_map_cmd_result_t
1024 route_match_local_pref(void *rule
, const struct prefix
*prefix
,
1025 route_map_object_t type
, void *object
)
1027 uint32_t *local_pref
;
1028 struct bgp_path_info
*path
;
1030 if (type
== RMAP_BGP
) {
1034 if (path
->attr
->local_pref
== *local_pref
)
1037 return RMAP_NOMATCH
;
1039 return RMAP_NOMATCH
;
1042 /* Route map `match local-preference' match statement.
1043 `arg' is local-pref value */
1044 static void *route_match_local_pref_compile(const char *arg
)
1046 uint32_t *local_pref
;
1047 char *endptr
= NULL
;
1048 unsigned long tmpval
;
1050 /* Locpref value shoud be integer. */
1051 if (!all_digit(arg
))
1055 tmpval
= strtoul(arg
, &endptr
, 10);
1056 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1059 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1061 *local_pref
= tmpval
;
1065 /* Free route map's compiled `match local-preference' value. */
1066 static void route_match_local_pref_free(void *rule
)
1068 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1071 /* Route map commands for metric matching. */
1072 struct route_map_rule_cmd route_match_local_pref_cmd
= {
1073 "local-preference", route_match_local_pref
,
1074 route_match_local_pref_compile
, route_match_local_pref_free
};
1076 /* `match metric METRIC' */
1078 /* Match function return 1 if match is success else return zero. */
1079 static enum route_map_cmd_result_t
1080 route_match_metric(void *rule
, const struct prefix
*prefix
,
1081 route_map_object_t type
, void *object
)
1083 struct rmap_value
*rv
;
1084 struct bgp_path_info
*path
;
1086 if (type
== RMAP_BGP
) {
1089 return route_value_match(rv
, path
->attr
->med
);
1091 return RMAP_NOMATCH
;
1094 /* Route map commands for metric matching. */
1095 struct route_map_rule_cmd route_match_metric_cmd
= {
1096 "metric", route_match_metric
, route_value_compile
, route_value_free
,
1099 /* `match as-path ASPATH' */
1101 /* Match function for as-path match. I assume given object is */
1102 static enum route_map_cmd_result_t
1103 route_match_aspath(void *rule
, const struct prefix
*prefix
,
1104 route_map_object_t type
, void *object
)
1107 struct as_list
*as_list
;
1108 struct bgp_path_info
*path
;
1110 if (type
== RMAP_BGP
) {
1111 as_list
= as_list_lookup((char *)rule
);
1112 if (as_list
== NULL
)
1113 return RMAP_NOMATCH
;
1117 /* Perform match. */
1118 return ((as_list_apply(as_list
, path
->attr
->aspath
)
1123 return RMAP_NOMATCH
;
1126 /* Compile function for as-path match. */
1127 static void *route_match_aspath_compile(const char *arg
)
1129 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1132 /* Compile function for as-path match. */
1133 static void route_match_aspath_free(void *rule
)
1135 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1138 /* Route map commands for aspath matching. */
1139 struct route_map_rule_cmd route_match_aspath_cmd
= {
1140 "as-path", route_match_aspath
, route_match_aspath_compile
,
1141 route_match_aspath_free
};
1143 /* `match community COMMUNIY' */
1144 struct rmap_community
{
1150 /* Match function for community match. */
1151 static enum route_map_cmd_result_t
1152 route_match_community(void *rule
, const struct prefix
*prefix
,
1153 route_map_object_t type
, void *object
)
1155 struct community_list
*list
;
1156 struct bgp_path_info
*path
;
1157 struct rmap_community
*rcom
= rule
;
1159 if (type
== RMAP_BGP
) {
1163 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1165 COMMUNITY_LIST_MASTER
);
1167 return RMAP_NOMATCH
;
1170 if (community_list_exact_match(path
->attr
->community
,
1174 if (community_list_match(path
->attr
->community
, list
))
1178 return RMAP_NOMATCH
;
1181 /* Compile function for community match. */
1182 static void *route_match_community_compile(const char *arg
)
1184 struct rmap_community
*rcom
;
1188 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1190 p
= strchr(arg
, ' ');
1193 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1194 memcpy(rcom
->name
, arg
, len
);
1197 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1201 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1205 /* Compile function for community match. */
1206 static void route_match_community_free(void *rule
)
1208 struct rmap_community
*rcom
= rule
;
1210 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1211 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1215 * In routemap processing there is a need to add the
1216 * name as a rule_key in the dependency table. Routemap
1217 * lib is unaware of rule_key when exact-match clause
1218 * is in use. routemap lib uses the compiled output to
1219 * get the rule_key value.
1221 static void *route_match_get_community_key(void *rule
)
1223 struct rmap_community
*rcom
;
1230 /* Route map commands for community matching. */
1231 struct route_map_rule_cmd route_match_community_cmd
= {
1232 "community", route_match_community
, route_match_community_compile
,
1233 route_match_community_free
, route_match_get_community_key
};
1235 /* Match function for lcommunity match. */
1236 static enum route_map_cmd_result_t
1237 route_match_lcommunity(void *rule
, const struct prefix
*prefix
,
1238 route_map_object_t type
, void *object
)
1240 struct community_list
*list
;
1241 struct bgp_path_info
*path
;
1242 struct rmap_community
*rcom
= rule
;
1244 if (type
== RMAP_BGP
) {
1247 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1249 LARGE_COMMUNITY_LIST_MASTER
);
1251 return RMAP_NOMATCH
;
1254 if (lcommunity_list_exact_match(
1255 path
->attr
->lcommunity
,
1259 if (lcommunity_list_match(
1260 path
->attr
->lcommunity
,
1265 return RMAP_NOMATCH
;
1268 /* Compile function for community match. */
1269 static void *route_match_lcommunity_compile(const char *arg
)
1271 struct rmap_community
*rcom
;
1275 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1277 p
= strchr(arg
, ' ');
1280 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1281 memcpy(rcom
->name
, arg
, len
);
1284 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1288 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1292 /* Compile function for community match. */
1293 static void route_match_lcommunity_free(void *rule
)
1295 struct rmap_community
*rcom
= rule
;
1297 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1298 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1301 /* Route map commands for community matching. */
1302 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1303 "large-community", route_match_lcommunity
,
1304 route_match_lcommunity_compile
, route_match_lcommunity_free
,
1305 route_match_get_community_key
};
1308 /* Match function for extcommunity match. */
1309 static enum route_map_cmd_result_t
1310 route_match_ecommunity(void *rule
, const struct prefix
*prefix
,
1311 route_map_object_t type
, void *object
)
1313 struct community_list
*list
;
1314 struct bgp_path_info
*path
;
1315 struct rmap_community
*rcom
= rule
;
1317 if (type
== RMAP_BGP
) {
1320 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1322 EXTCOMMUNITY_LIST_MASTER
);
1324 return RMAP_NOMATCH
;
1326 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1329 return RMAP_NOMATCH
;
1332 /* Compile function for extcommunity match. */
1333 static void *route_match_ecommunity_compile(const char *arg
)
1335 struct rmap_community
*rcom
;
1337 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1338 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1339 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1344 /* Compile function for extcommunity match. */
1345 static void route_match_ecommunity_free(void *rule
)
1347 struct rmap_community
*rcom
= rule
;
1349 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1350 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1353 /* Route map commands for community matching. */
1354 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1355 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1356 route_match_ecommunity_free
};
1358 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1359 and `address-family vpnv4'. */
1361 /* `match origin' */
1362 static enum route_map_cmd_result_t
1363 route_match_origin(void *rule
, const struct prefix
*prefix
,
1364 route_map_object_t type
, void *object
)
1367 struct bgp_path_info
*path
;
1369 if (type
== RMAP_BGP
) {
1373 if (path
->attr
->origin
== *origin
)
1377 return RMAP_NOMATCH
;
1380 static void *route_match_origin_compile(const char *arg
)
1384 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1386 if (strcmp(arg
, "igp") == 0)
1388 else if (strcmp(arg
, "egp") == 0)
1396 /* Free route map's compiled `ip address' value. */
1397 static void route_match_origin_free(void *rule
)
1399 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1402 /* Route map commands for origin matching. */
1403 struct route_map_rule_cmd route_match_origin_cmd
= {
1404 "origin", route_match_origin
, route_match_origin_compile
,
1405 route_match_origin_free
};
1407 /* match probability { */
1409 static enum route_map_cmd_result_t
1410 route_match_probability(void *rule
, const struct prefix
*prefix
,
1411 route_map_object_t type
, void *object
)
1415 switch (*(long *)rule
) {
1421 if (r
< *(long *)rule
) {
1426 return RMAP_NOMATCH
;
1429 static void *route_match_probability_compile(const char *arg
)
1435 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1445 *lobule
= RAND_MAX
/ 100 * perc
;
1451 static void route_match_probability_free(void *rule
)
1453 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1456 struct route_map_rule_cmd route_match_probability_cmd
= {
1457 "probability", route_match_probability
, route_match_probability_compile
,
1458 route_match_probability_free
};
1460 /* `match interface IFNAME' */
1461 /* Match function should return 1 if match is success else return
1463 static enum route_map_cmd_result_t
1464 route_match_interface(void *rule
, const struct prefix
*prefix
,
1465 route_map_object_t type
, void *object
)
1467 struct interface
*ifp
;
1468 struct bgp_path_info
*path
;
1470 if (type
== RMAP_BGP
) {
1473 if (!path
|| !path
->attr
)
1474 return RMAP_NOMATCH
;
1476 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1478 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1479 return RMAP_NOMATCH
;
1483 return RMAP_NOMATCH
;
1486 /* Route map `interface' match statement. `arg' should be
1488 static void *route_match_interface_compile(const char *arg
)
1490 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1493 /* Free route map's compiled `interface' value. */
1494 static void route_match_interface_free(void *rule
)
1496 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1499 /* Route map commands for ip address matching. */
1500 struct route_map_rule_cmd route_match_interface_cmd
= {
1501 "interface", route_match_interface
, route_match_interface_compile
,
1502 route_match_interface_free
};
1506 /* `set ip next-hop IP_ADDRESS' */
1508 /* Match function return 1 if match is success else return zero. */
1509 static enum route_map_cmd_result_t
1510 route_match_tag(void *rule
, const struct prefix
*prefix
,
1511 route_map_object_t type
, void *object
)
1514 struct bgp_path_info
*path
;
1516 if (type
== RMAP_BGP
) {
1520 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1523 return RMAP_NOMATCH
;
1527 /* Route map commands for tag matching. */
1528 static struct route_map_rule_cmd route_match_tag_cmd
= {
1529 "tag", route_match_tag
, route_map_rule_tag_compile
,
1530 route_map_rule_tag_free
,
1534 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1535 struct rmap_ip_nexthop_set
{
1536 struct in_addr
*address
;
1541 static enum route_map_cmd_result_t
1542 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
,
1543 route_map_object_t type
, void *object
)
1545 struct rmap_ip_nexthop_set
*rins
= rule
;
1546 struct bgp_path_info
*path
;
1549 if (type
!= RMAP_BGP
)
1552 if (prefix
->family
== AF_INET6
)
1558 if (rins
->unchanged
) {
1559 SET_FLAG(path
->attr
->rmap_change_flags
,
1560 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1561 } else if (rins
->peer_address
) {
1562 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1563 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1565 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1566 path
->attr
->nexthop
.s_addr
=
1567 sockunion2ip(peer
->su_remote
);
1568 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1569 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1570 /* The next hop value will be set as part of
1571 * packet rewrite. Set the flags here to indicate
1572 * that rewrite needs to be done.
1573 * Also, clear the value.
1575 SET_FLAG(path
->attr
->rmap_change_flags
,
1576 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1577 path
->attr
->nexthop
.s_addr
= 0;
1580 /* Set next hop value. */
1581 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1582 path
->attr
->nexthop
= *rins
->address
;
1583 SET_FLAG(path
->attr
->rmap_change_flags
,
1584 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1585 /* case for MP-BGP : MPLS VPN */
1586 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1587 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1593 /* Route map `ip nexthop' compile function. Given string is converted
1594 to struct in_addr structure. */
1595 static void *route_set_ip_nexthop_compile(const char *arg
)
1597 struct rmap_ip_nexthop_set
*rins
;
1598 struct in_addr
*address
= NULL
;
1599 int peer_address
= 0;
1603 if (strcmp(arg
, "peer-address") == 0)
1605 else if (strcmp(arg
, "unchanged") == 0)
1608 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1609 sizeof(struct in_addr
));
1610 ret
= inet_aton(arg
, address
);
1613 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1618 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1619 sizeof(struct rmap_ip_nexthop_set
));
1621 rins
->address
= address
;
1622 rins
->peer_address
= peer_address
;
1623 rins
->unchanged
= unchanged
;
1628 /* Free route map's compiled `ip nexthop' value. */
1629 static void route_set_ip_nexthop_free(void *rule
)
1631 struct rmap_ip_nexthop_set
*rins
= rule
;
1633 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1635 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1638 /* Route map commands for ip nexthop set. */
1639 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1640 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1641 route_set_ip_nexthop_free
};
1643 /* `set local-preference LOCAL_PREF' */
1645 /* Set local preference. */
1646 static enum route_map_cmd_result_t
1647 route_set_local_pref(void *rule
, const struct prefix
*prefix
,
1648 route_map_object_t type
, void *object
)
1650 struct rmap_value
*rv
;
1651 struct bgp_path_info
*path
;
1652 uint32_t locpref
= 0;
1654 if (type
== RMAP_BGP
) {
1655 /* Fetch routemap's rule information. */
1659 /* Set local preference value. */
1660 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1661 locpref
= path
->attr
->local_pref
;
1663 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1664 path
->attr
->local_pref
=
1665 route_value_adjust(rv
, locpref
, path
->peer
);
1671 /* Set local preference rule structure. */
1672 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1673 "local-preference", route_set_local_pref
, route_value_compile
,
1677 /* `set weight WEIGHT' */
1680 static enum route_map_cmd_result_t
1681 route_set_weight(void *rule
, const struct prefix
*prefix
,
1682 route_map_object_t type
, void *object
)
1684 struct rmap_value
*rv
;
1685 struct bgp_path_info
*path
;
1687 if (type
== RMAP_BGP
) {
1688 /* Fetch routemap's rule information. */
1692 /* Set weight value. */
1693 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1699 /* Set local preference rule structure. */
1700 struct route_map_rule_cmd route_set_weight_cmd
= {
1701 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1704 /* `set distance DISTANCE */
1705 static enum route_map_cmd_result_t
1706 route_set_distance(void *rule
, const struct prefix
*prefix
,
1707 route_map_object_t type
, void *object
)
1709 struct bgp_path_info
*path
= object
;
1710 struct rmap_value
*rv
= rule
;
1712 if (type
!= RMAP_BGP
)
1715 path
->attr
->distance
= rv
->value
;
1720 /* set distance rule structure */
1721 struct route_map_rule_cmd route_set_distance_cmd
= {
1724 route_value_compile
,
1728 /* `set metric METRIC' */
1730 /* Set metric to attribute. */
1731 static enum route_map_cmd_result_t
1732 route_set_metric(void *rule
, const struct prefix
*prefix
,
1733 route_map_object_t type
, void *object
)
1735 struct rmap_value
*rv
;
1736 struct bgp_path_info
*path
;
1739 if (type
== RMAP_BGP
) {
1740 /* Fetch routemap's rule information. */
1744 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1745 med
= path
->attr
->med
;
1747 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1748 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1753 /* Set metric rule structure. */
1754 struct route_map_rule_cmd route_set_metric_cmd
= {
1755 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1758 /* `set table (1-4294967295)' */
1760 static enum route_map_cmd_result_t
route_set_table_id(void *rule
,
1761 const struct prefix
*prefix
,
1762 route_map_object_t type
,
1765 struct rmap_value
*rv
;
1766 struct bgp_path_info
*path
;
1768 if (type
== RMAP_BGP
) {
1769 /* Fetch routemap's rule information. */
1773 path
->attr
->rmap_table_id
= rv
->value
;
1778 /* Set table_id rule structure. */
1779 static struct route_map_rule_cmd route_set_table_id_cmd
= {
1780 "table", route_set_table_id
,
1781 route_value_compile
, route_value_free
1784 /* `set as-path prepend ASPATH' */
1786 /* For AS path prepend mechanism. */
1787 static enum route_map_cmd_result_t
1788 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
,
1789 route_map_object_t type
, void *object
)
1791 struct aspath
*aspath
;
1793 struct bgp_path_info
*path
;
1795 if (type
== RMAP_BGP
) {
1798 if (path
->attr
->aspath
->refcnt
)
1799 new = aspath_dup(path
->attr
->aspath
);
1801 new = path
->attr
->aspath
;
1803 if ((uintptr_t)rule
> 10) {
1805 aspath_prepend(aspath
, new);
1807 as_t as
= aspath_leftmost(new);
1809 as
= path
->peer
->as
;
1810 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1813 path
->attr
->aspath
= new;
1819 static void *route_set_aspath_prepend_compile(const char *arg
)
1823 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1824 return (void *)(uintptr_t)num
;
1826 return route_aspath_compile(arg
);
1829 static void route_set_aspath_prepend_free(void *rule
)
1831 if ((uintptr_t)rule
> 10)
1832 route_aspath_free(rule
);
1836 /* Set as-path prepend rule structure. */
1837 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1838 "as-path prepend", route_set_aspath_prepend
,
1839 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1842 /* `set as-path exclude ASn' */
1844 /* For ASN exclude mechanism.
1845 * Iterate over ASns requested and filter them from the given AS_PATH one by
1847 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1849 static enum route_map_cmd_result_t
1850 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
,
1851 route_map_object_t type
, void *object
)
1853 struct aspath
*new_path
, *exclude_path
;
1854 struct bgp_path_info
*path
;
1856 if (type
== RMAP_BGP
) {
1857 exclude_path
= rule
;
1859 if (path
->attr
->aspath
->refcnt
)
1860 new_path
= aspath_dup(path
->attr
->aspath
);
1862 new_path
= path
->attr
->aspath
;
1863 path
->attr
->aspath
=
1864 aspath_filter_exclude(new_path
, exclude_path
);
1869 /* Set ASn exlude rule structure. */
1870 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1871 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1875 /* `set community COMMUNITY' */
1876 struct rmap_com_set
{
1877 struct community
*com
;
1882 /* For community set mechanism. */
1883 static enum route_map_cmd_result_t
1884 route_set_community(void *rule
, const struct prefix
*prefix
,
1885 route_map_object_t type
, void *object
)
1887 struct rmap_com_set
*rcs
;
1888 struct bgp_path_info
*path
;
1890 struct community
*new = NULL
;
1891 struct community
*old
;
1892 struct community
*merge
;
1894 if (type
== RMAP_BGP
) {
1898 old
= attr
->community
;
1902 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1903 attr
->community
= NULL
;
1904 /* See the longer comment down below. */
1905 if (old
&& old
->refcnt
== 0)
1906 community_free(&old
);
1910 /* "additive" case. */
1911 if (rcs
->additive
&& old
) {
1912 merge
= community_merge(community_dup(old
), rcs
->com
);
1914 new = community_uniq_sort(merge
);
1915 community_free(&merge
);
1917 new = community_dup(rcs
->com
);
1919 /* HACK: if the old community is not intern'd,
1920 * we should free it here, or all reference to it may be
1922 * Really need to cleanup attribute caching sometime.
1924 if (old
&& old
->refcnt
== 0)
1925 community_free(&old
);
1927 /* will be interned by caller if required */
1928 attr
->community
= new;
1930 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1936 /* Compile function for set community. */
1937 static void *route_set_community_compile(const char *arg
)
1939 struct rmap_com_set
*rcs
;
1940 struct community
*com
= NULL
;
1945 if (strcmp(arg
, "none") == 0)
1948 sp
= strstr(arg
, "additive");
1950 if (sp
&& sp
> arg
) {
1951 /* "additive" keyword is included. */
1956 com
= community_str2com(arg
);
1965 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1967 rcs
->additive
= additive
;
1973 /* Free function for set community. */
1974 static void route_set_community_free(void *rule
)
1976 struct rmap_com_set
*rcs
= rule
;
1979 community_free(&rcs
->com
);
1980 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1983 /* Set community rule structure. */
1984 struct route_map_rule_cmd route_set_community_cmd
= {
1985 "community", route_set_community
, route_set_community_compile
,
1986 route_set_community_free
,
1989 /* `set community COMMUNITY' */
1990 struct rmap_lcom_set
{
1991 struct lcommunity
*lcom
;
1997 /* For lcommunity set mechanism. */
1998 static enum route_map_cmd_result_t
1999 route_set_lcommunity(void *rule
, const struct prefix
*prefix
,
2000 route_map_object_t type
, void *object
)
2002 struct rmap_lcom_set
*rcs
;
2003 struct bgp_path_info
*path
;
2005 struct lcommunity
*new = NULL
;
2006 struct lcommunity
*old
;
2007 struct lcommunity
*merge
;
2009 if (type
== RMAP_BGP
) {
2013 old
= attr
->lcommunity
;
2018 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
2019 attr
->lcommunity
= NULL
;
2021 /* See the longer comment down below. */
2022 if (old
&& old
->refcnt
== 0)
2023 lcommunity_free(&old
);
2027 if (rcs
->additive
&& old
) {
2028 merge
= lcommunity_merge(lcommunity_dup(old
),
2031 new = lcommunity_uniq_sort(merge
);
2032 lcommunity_free(&merge
);
2034 new = lcommunity_dup(rcs
->lcom
);
2036 /* HACK: if the old large-community is not intern'd,
2037 * we should free it here, or all reference to it may be
2039 * Really need to cleanup attribute caching sometime.
2041 if (old
&& old
->refcnt
== 0)
2042 lcommunity_free(&old
);
2044 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2045 attr
->lcommunity
= new;
2047 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
2053 /* Compile function for set community. */
2054 static void *route_set_lcommunity_compile(const char *arg
)
2056 struct rmap_lcom_set
*rcs
;
2057 struct lcommunity
*lcom
= NULL
;
2062 if (strcmp(arg
, "none") == 0)
2065 sp
= strstr(arg
, "additive");
2067 if (sp
&& sp
> arg
) {
2068 /* "additive" keyworkd is included. */
2073 lcom
= lcommunity_str2com(arg
);
2082 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2084 rcs
->additive
= additive
;
2090 /* Free function for set lcommunity. */
2091 static void route_set_lcommunity_free(void *rule
)
2093 struct rmap_lcom_set
*rcs
= rule
;
2096 lcommunity_free(&rcs
->lcom
);
2098 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2101 /* Set community rule structure. */
2102 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2103 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
2104 route_set_lcommunity_free
,
2107 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2109 /* For large community set mechanism. */
2110 static enum route_map_cmd_result_t
2111 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
,
2112 route_map_object_t type
, void *object
)
2114 struct community_list
*list
;
2115 struct lcommunity
*merge
;
2116 struct lcommunity
*new;
2117 struct lcommunity
*old
;
2118 struct bgp_path_info
*path
;
2119 struct rmap_community
*rcom
= rule
;
2121 if (type
== RMAP_BGP
) {
2126 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2128 LARGE_COMMUNITY_LIST_MASTER
);
2129 old
= path
->attr
->lcommunity
;
2132 merge
= lcommunity_list_match_delete(
2133 lcommunity_dup(old
), list
);
2134 new = lcommunity_uniq_sort(merge
);
2135 lcommunity_free(&merge
);
2137 /* HACK: if the old community is not intern'd,
2138 * we should free it here, or all reference to it may be
2140 * Really need to cleanup attribute caching sometime.
2142 if (old
->refcnt
== 0)
2143 lcommunity_free(&old
);
2145 if (new->size
== 0) {
2146 path
->attr
->lcommunity
= NULL
;
2147 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2148 BGP_ATTR_LARGE_COMMUNITIES
);
2149 lcommunity_free(&new);
2151 path
->attr
->lcommunity
= new;
2152 path
->attr
->flag
|= ATTR_FLAG_BIT(
2153 BGP_ATTR_LARGE_COMMUNITIES
);
2161 /* Compile function for set lcommunity. */
2162 static void *route_set_lcommunity_delete_compile(const char *arg
)
2164 struct rmap_community
*rcom
;
2168 frrstr_split(arg
, " ", &splits
, &num
);
2170 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2171 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2172 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2174 for (int i
= 0; i
< num
; i
++)
2175 XFREE(MTYPE_TMP
, splits
[i
]);
2176 XFREE(MTYPE_TMP
, splits
);
2181 /* Free function for set lcommunity. */
2182 static void route_set_lcommunity_delete_free(void *rule
)
2184 struct rmap_community
*rcom
= rule
;
2186 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2187 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2190 /* Set lcommunity rule structure. */
2191 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2192 "large-comm-list", route_set_lcommunity_delete
,
2193 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2197 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2199 /* For community set mechanism. */
2200 static enum route_map_cmd_result_t
2201 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2202 route_map_object_t type
, void *object
)
2204 struct community_list
*list
;
2205 struct community
*merge
;
2206 struct community
*new;
2207 struct community
*old
;
2208 struct bgp_path_info
*path
;
2209 struct rmap_community
*rcom
= rule
;
2211 if (type
== RMAP_BGP
) {
2216 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2218 COMMUNITY_LIST_MASTER
);
2219 old
= path
->attr
->community
;
2222 merge
= community_list_match_delete(community_dup(old
),
2224 new = community_uniq_sort(merge
);
2225 community_free(&merge
);
2227 /* HACK: if the old community is not intern'd,
2228 * we should free it here, or all reference to it may be
2230 * Really need to cleanup attribute caching sometime.
2232 if (old
->refcnt
== 0)
2233 community_free(&old
);
2235 if (new->size
== 0) {
2236 path
->attr
->community
= NULL
;
2238 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2239 community_free(&new);
2241 path
->attr
->community
= new;
2243 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2251 /* Compile function for set community. */
2252 static void *route_set_community_delete_compile(const char *arg
)
2254 struct rmap_community
*rcom
;
2258 frrstr_split(arg
, " ", &splits
, &num
);
2260 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2261 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2262 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2264 for (int i
= 0; i
< num
; i
++)
2265 XFREE(MTYPE_TMP
, splits
[i
]);
2266 XFREE(MTYPE_TMP
, splits
);
2271 /* Free function for set community. */
2272 static void route_set_community_delete_free(void *rule
)
2274 struct rmap_community
*rcom
= rule
;
2276 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2277 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2280 /* Set community rule structure. */
2281 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2282 "comm-list", route_set_community_delete
,
2283 route_set_community_delete_compile
, route_set_community_delete_free
,
2286 /* `set extcommunity rt COMMUNITY' */
2288 /* For community set mechanism. Used by _rt and _soo. */
2289 static enum route_map_cmd_result_t
2290 route_set_ecommunity(void *rule
, const struct prefix
*prefix
,
2291 route_map_object_t type
, void *object
)
2293 struct ecommunity
*ecom
;
2294 struct ecommunity
*new_ecom
;
2295 struct ecommunity
*old_ecom
;
2296 struct bgp_path_info
*path
;
2298 if (type
== RMAP_BGP
) {
2305 /* We assume additive for Extended Community. */
2306 old_ecom
= path
->attr
->ecommunity
;
2309 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2312 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2313 * bgp_update_receive()
2314 * ->refcnt = 0 => set by a previous route-map
2316 if (!old_ecom
->refcnt
)
2317 ecommunity_free(&old_ecom
);
2319 new_ecom
= ecommunity_dup(ecom
);
2321 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2322 path
->attr
->ecommunity
= new_ecom
;
2324 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2329 /* Compile function for set community. */
2330 static void *route_set_ecommunity_rt_compile(const char *arg
)
2332 struct ecommunity
*ecom
;
2334 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2337 return ecommunity_intern(ecom
);
2340 /* Free function for set community. Used by _rt and _soo */
2341 static void route_set_ecommunity_free(void *rule
)
2343 struct ecommunity
*ecom
= rule
;
2344 ecommunity_unintern(&ecom
);
2347 /* Set community rule structure. */
2348 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2349 "extcommunity rt", route_set_ecommunity
,
2350 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2353 /* `set extcommunity soo COMMUNITY' */
2355 /* Compile function for set community. */
2356 static void *route_set_ecommunity_soo_compile(const char *arg
)
2358 struct ecommunity
*ecom
;
2360 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2364 return ecommunity_intern(ecom
);
2367 /* Set community rule structure. */
2368 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2369 "extcommunity soo", route_set_ecommunity
,
2370 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2373 /* `set origin ORIGIN' */
2375 /* For origin set. */
2376 static enum route_map_cmd_result_t
2377 route_set_origin(void *rule
, const struct prefix
*prefix
,
2378 route_map_object_t type
, void *object
)
2381 struct bgp_path_info
*path
;
2383 if (type
== RMAP_BGP
) {
2387 path
->attr
->origin
= *origin
;
2393 /* Compile function for origin set. */
2394 static void *route_set_origin_compile(const char *arg
)
2398 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2400 if (strcmp(arg
, "igp") == 0)
2402 else if (strcmp(arg
, "egp") == 0)
2410 /* Compile function for origin set. */
2411 static void route_set_origin_free(void *rule
)
2413 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2416 /* Set origin rule structure. */
2417 struct route_map_rule_cmd route_set_origin_cmd
= {
2418 "origin", route_set_origin
, route_set_origin_compile
,
2419 route_set_origin_free
,
2422 /* `set atomic-aggregate' */
2424 /* For atomic aggregate set. */
2425 static enum route_map_cmd_result_t
2426 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
,
2427 route_map_object_t type
, void *object
)
2429 struct bgp_path_info
*path
;
2431 if (type
== RMAP_BGP
) {
2433 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2439 /* Compile function for atomic aggregate. */
2440 static void *route_set_atomic_aggregate_compile(const char *arg
)
2445 /* Compile function for atomic aggregate. */
2446 static void route_set_atomic_aggregate_free(void *rule
)
2451 /* Set atomic aggregate rule structure. */
2452 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2453 "atomic-aggregate", route_set_atomic_aggregate
,
2454 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2457 /* `set aggregator as AS A.B.C.D' */
2460 struct in_addr address
;
2463 static enum route_map_cmd_result_t
2464 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
,
2465 route_map_object_t type
, void *object
)
2467 struct bgp_path_info
*path
;
2468 struct aggregator
*aggregator
;
2470 if (type
== RMAP_BGP
) {
2474 path
->attr
->aggregator_as
= aggregator
->as
;
2475 path
->attr
->aggregator_addr
= aggregator
->address
;
2476 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2482 static void *route_set_aggregator_as_compile(const char *arg
)
2484 struct aggregator
*aggregator
;
2490 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2491 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2492 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2496 aggregator
->as
= strtoul(as
, NULL
, 10);
2497 ret
= inet_aton(address
, &aggregator
->address
);
2499 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2505 static void route_set_aggregator_as_free(void *rule
)
2507 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2510 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2511 "aggregator as", route_set_aggregator_as
,
2512 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2515 /* Set tag to object. object must be pointer to struct bgp_path_info */
2516 static enum route_map_cmd_result_t
2517 route_set_tag(void *rule
, const struct prefix
*prefix
,
2518 route_map_object_t type
, void *object
)
2521 struct bgp_path_info
*path
;
2523 if (type
== RMAP_BGP
) {
2528 path
->attr
->tag
= *tag
;
2534 /* Route map commands for tag set. */
2535 static struct route_map_rule_cmd route_set_tag_cmd
= {
2536 "tag", route_set_tag
, route_map_rule_tag_compile
,
2537 route_map_rule_tag_free
,
2540 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2541 static enum route_map_cmd_result_t
2542 route_set_label_index(void *rule
, const struct prefix
*prefix
,
2543 route_map_object_t type
, void *object
)
2545 struct rmap_value
*rv
;
2546 struct bgp_path_info
*path
;
2547 uint32_t label_index
;
2549 if (type
== RMAP_BGP
) {
2550 /* Fetch routemap's rule information. */
2554 /* Set label-index value. */
2555 label_index
= rv
->value
;
2557 path
->attr
->label_index
= label_index
;
2558 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2565 /* Route map commands for label-index set. */
2566 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2567 "label-index", route_set_label_index
, route_value_compile
,
2571 /* `match ipv6 address IP_ACCESS_LIST' */
2573 static enum route_map_cmd_result_t
2574 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
,
2575 route_map_object_t type
, void *object
)
2577 struct access_list
*alist
;
2579 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2580 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2582 return RMAP_NOMATCH
;
2584 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2588 return RMAP_NOMATCH
;
2591 static void *route_match_ipv6_address_compile(const char *arg
)
2593 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2596 static void route_match_ipv6_address_free(void *rule
)
2598 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2601 /* Route map commands for ip address matching. */
2602 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2603 "ipv6 address", route_match_ipv6_address
,
2604 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2606 /* `match ipv6 next-hop IP_ADDRESS' */
2608 static enum route_map_cmd_result_t
2609 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
,
2610 route_map_object_t type
, void *object
)
2612 struct in6_addr
*addr
= rule
;
2613 struct bgp_path_info
*path
;
2615 if (type
== RMAP_BGP
) {
2618 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2621 if (path
->attr
->mp_nexthop_len
2622 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2623 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2626 return RMAP_NOMATCH
;
2629 return RMAP_NOMATCH
;
2632 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2634 struct in6_addr
*address
;
2637 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2639 ret
= inet_pton(AF_INET6
, arg
, address
);
2641 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2648 static void route_match_ipv6_next_hop_free(void *rule
)
2650 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2653 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2654 "ipv6 next-hop", route_match_ipv6_next_hop
,
2655 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2657 /* `match ipv6 address prefix-list PREFIX_LIST' */
2659 static enum route_map_cmd_result_t
2660 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2661 route_map_object_t type
, void *object
)
2663 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, type
,
2667 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2669 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2672 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2674 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2677 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2678 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2679 route_match_ipv6_address_prefix_list_compile
,
2680 route_match_ipv6_address_prefix_list_free
};
2682 /* `match ipv6 next-hop type <TYPE>' */
2684 static enum route_map_cmd_result_t
2685 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2686 route_map_object_t type
, void *object
)
2688 struct bgp_path_info
*path
;
2689 struct in6_addr
*addr
= rule
;
2691 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2692 path
= (struct bgp_path_info
*)object
;
2693 if (!path
|| !path
->attr
)
2694 return RMAP_NOMATCH
;
2696 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2697 && !path
->attr
->nh_ifindex
)
2700 return RMAP_NOMATCH
;
2703 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2705 struct in6_addr
*address
;
2708 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2710 ret
= inet_pton(AF_INET6
, "::0", address
);
2712 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2719 static void route_match_ipv6_next_hop_type_free(void *rule
)
2721 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2724 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2725 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2726 route_match_ipv6_next_hop_type_compile
,
2727 route_match_ipv6_next_hop_type_free
};
2729 /* `set ipv6 nexthop global IP_ADDRESS' */
2731 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2732 static enum route_map_cmd_result_t
2733 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
,
2734 route_map_object_t type
, void *object
)
2736 struct in6_addr
*address
;
2737 struct bgp_path_info
*path
;
2739 if (type
== RMAP_BGP
) {
2740 /* Fetch routemap's rule information. */
2744 /* Set next hop value. */
2745 path
->attr
->mp_nexthop_global
= *address
;
2747 /* Set nexthop length. */
2748 if (path
->attr
->mp_nexthop_len
== 0)
2749 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2751 SET_FLAG(path
->attr
->rmap_change_flags
,
2752 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2758 /* Route map `ip next-hop' compile function. Given string is converted
2759 to struct in_addr structure. */
2760 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2763 struct in6_addr
*address
;
2765 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2767 ret
= inet_pton(AF_INET6
, arg
, address
);
2770 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2777 /* Free route map's compiled `ip next-hop' value. */
2778 static void route_set_ipv6_nexthop_global_free(void *rule
)
2780 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2783 /* Route map commands for ip nexthop set. */
2784 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2785 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2786 route_set_ipv6_nexthop_global_compile
,
2787 route_set_ipv6_nexthop_global_free
};
2789 /* Set next-hop preference value. */
2790 static enum route_map_cmd_result_t
2791 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2792 route_map_object_t type
, void *object
)
2794 struct bgp_path_info
*path
;
2797 if (type
== RMAP_BGP
) {
2798 /* Fetch routemap's rule information. */
2802 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2803 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)) {
2804 /* Set next hop preference to global */
2805 path
->attr
->mp_nexthop_prefer_global
= true;
2806 SET_FLAG(path
->attr
->rmap_change_flags
,
2807 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2809 path
->attr
->mp_nexthop_prefer_global
= false;
2810 SET_FLAG(path
->attr
->rmap_change_flags
,
2811 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2817 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2821 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2827 /* Free route map's compiled `ip next-hop' value. */
2828 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2830 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2833 /* Route map commands for ip nexthop set preferred. */
2834 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2835 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2836 route_set_ipv6_nexthop_prefer_global_compile
,
2837 route_set_ipv6_nexthop_prefer_global_free
};
2839 /* `set ipv6 nexthop local IP_ADDRESS' */
2841 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2842 static enum route_map_cmd_result_t
2843 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
,
2844 route_map_object_t type
, void *object
)
2846 struct in6_addr
*address
;
2847 struct bgp_path_info
*path
;
2849 if (type
== RMAP_BGP
) {
2850 /* Fetch routemap's rule information. */
2854 /* Set next hop value. */
2855 path
->attr
->mp_nexthop_local
= *address
;
2857 /* Set nexthop length. */
2858 if (path
->attr
->mp_nexthop_len
2859 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2860 path
->attr
->mp_nexthop_len
=
2861 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2863 SET_FLAG(path
->attr
->rmap_change_flags
,
2864 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2870 /* Route map `ip nexthop' compile function. Given string is converted
2871 to struct in_addr structure. */
2872 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2875 struct in6_addr
*address
;
2877 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2879 ret
= inet_pton(AF_INET6
, arg
, address
);
2882 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2889 /* Free route map's compiled `ip nexthop' value. */
2890 static void route_set_ipv6_nexthop_local_free(void *rule
)
2892 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2895 /* Route map commands for ip nexthop set. */
2896 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2897 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2898 route_set_ipv6_nexthop_local_compile
,
2899 route_set_ipv6_nexthop_local_free
};
2901 /* `set ipv6 nexthop peer-address' */
2903 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2904 static enum route_map_cmd_result_t
2905 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
,
2906 route_map_object_t type
, void *object
)
2908 struct in6_addr peer_address
;
2909 struct bgp_path_info
*path
;
2912 if (type
== RMAP_BGP
) {
2913 /* Fetch routemap's rule information. */
2917 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2918 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2920 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2921 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2922 /* Set next hop value and length in attribute. */
2923 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2924 path
->attr
->mp_nexthop_local
= peer_address
;
2925 if (path
->attr
->mp_nexthop_len
2926 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2927 path
->attr
->mp_nexthop_len
=
2928 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2930 path
->attr
->mp_nexthop_global
= peer_address
;
2931 if (path
->attr
->mp_nexthop_len
== 0)
2932 path
->attr
->mp_nexthop_len
=
2933 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2936 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2937 /* The next hop value will be set as part of packet
2939 * Set the flags here to indicate that rewrite needs to
2941 * Also, clear the value - we clear both global and
2943 * nexthops, whether we send one or both is determined
2946 SET_FLAG(path
->attr
->rmap_change_flags
,
2947 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2948 /* clear next hop value. */
2949 memset(&(path
->attr
->mp_nexthop_global
), 0,
2950 sizeof(struct in6_addr
));
2951 memset(&(path
->attr
->mp_nexthop_local
), 0,
2952 sizeof(struct in6_addr
));
2959 /* Route map `ip next-hop' compile function. Given string is converted
2960 to struct in_addr structure. */
2961 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2965 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2971 /* Free route map's compiled `ip next-hop' value. */
2972 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2974 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2977 /* Route map commands for ip nexthop set. */
2978 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2979 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2980 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2982 /* `set ipv4 vpn next-hop A.B.C.D' */
2984 static enum route_map_cmd_result_t
2985 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
,
2986 route_map_object_t type
, void *object
)
2988 struct in_addr
*address
;
2989 struct bgp_path_info
*path
;
2991 if (type
== RMAP_BGP
) {
2992 /* Fetch routemap's rule information. */
2996 /* Set next hop value. */
2997 path
->attr
->mp_nexthop_global_in
= *address
;
2998 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
3004 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
3007 struct in_addr
*address
;
3009 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3011 ret
= inet_aton(arg
, address
);
3014 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3021 /* `set ipv6 vpn next-hop A.B.C.D' */
3023 static enum route_map_cmd_result_t
3024 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
,
3025 route_map_object_t type
, void *object
)
3027 struct in6_addr
*address
;
3028 struct bgp_path_info
*path
;
3030 if (type
== RMAP_BGP
) {
3031 /* Fetch routemap's rule information. */
3035 /* Set next hop value. */
3036 memcpy(&path
->attr
->mp_nexthop_global
, address
,
3037 sizeof(struct in6_addr
));
3038 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
3044 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
3047 struct in6_addr
*address
;
3049 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
3050 ret
= inet_pton(AF_INET6
, arg
, address
);
3053 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3060 static void route_set_vpn_nexthop_free(void *rule
)
3062 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3065 /* Route map commands for ipv4 next-hop set. */
3066 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
3067 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
3068 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
3070 /* Route map commands for ipv6 next-hop set. */
3071 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3072 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
3073 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
3075 /* `set originator-id' */
3077 /* For origin set. */
3078 static enum route_map_cmd_result_t
3079 route_set_originator_id(void *rule
, const struct prefix
*prefix
,
3080 route_map_object_t type
, void *object
)
3082 struct in_addr
*address
;
3083 struct bgp_path_info
*path
;
3085 if (type
== RMAP_BGP
) {
3089 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3090 path
->attr
->originator_id
= *address
;
3096 /* Compile function for originator-id set. */
3097 static void *route_set_originator_id_compile(const char *arg
)
3100 struct in_addr
*address
;
3102 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3104 ret
= inet_aton(arg
, address
);
3107 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3114 /* Compile function for originator_id set. */
3115 static void route_set_originator_id_free(void *rule
)
3117 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3120 /* Set originator-id rule structure. */
3121 struct route_map_rule_cmd route_set_originator_id_cmd
= {
3122 "originator-id", route_set_originator_id
,
3123 route_set_originator_id_compile
, route_set_originator_id_free
,
3126 /* Add bgp route map rule. */
3127 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3128 const char *arg
, route_map_event_t type
)
3130 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3131 int retval
= CMD_SUCCESS
;
3132 enum rmap_compile_rets ret
;
3134 ret
= route_map_add_match(index
, command
, arg
, type
);
3136 case RMAP_RULE_MISSING
:
3137 vty_out(vty
, "%% BGP Can't find rule.\n");
3138 retval
= CMD_WARNING_CONFIG_FAILED
;
3140 case RMAP_COMPILE_ERROR
:
3141 vty_out(vty
, "%% BGP Argument is malformed.\n");
3142 retval
= CMD_WARNING_CONFIG_FAILED
;
3144 case RMAP_COMPILE_SUCCESS
:
3146 * Intentionally doing nothing here.
3154 /* Delete bgp route map rule. */
3155 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3156 const char *arg
, route_map_event_t type
)
3158 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3159 enum rmap_compile_rets ret
;
3160 int retval
= CMD_SUCCESS
;
3161 char *dep_name
= NULL
;
3163 char *rmap_name
= NULL
;
3165 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3166 /* ignore the mundane, the types without any dependency */
3168 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3171 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3173 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3175 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3178 ret
= route_map_delete_match(index
, command
, dep_name
, type
);
3180 case RMAP_RULE_MISSING
:
3181 vty_out(vty
, "%% BGP Can't find rule.\n");
3182 retval
= CMD_WARNING_CONFIG_FAILED
;
3184 case RMAP_COMPILE_ERROR
:
3185 vty_out(vty
, "%% BGP Argument is malformed.\n");
3186 retval
= CMD_WARNING_CONFIG_FAILED
;
3188 case RMAP_COMPILE_SUCCESS
:
3190 * Nothing to do here
3195 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3196 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3202 * This is the workhorse routine for processing in/out routemap
3205 static void bgp_route_map_process_peer(const char *rmap_name
,
3206 struct route_map
*map
, struct peer
*peer
,
3207 int afi
, int safi
, int route_update
)
3209 struct bgp_filter
*filter
;
3211 if (!peer
|| !rmap_name
)
3214 filter
= &peer
->filter
[afi
][safi
];
3216 * in is for non-route-server clients,
3217 * out is for all peers
3219 if (filter
->map
[RMAP_IN
].name
3220 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3221 filter
->map
[RMAP_IN
].map
= map
;
3223 if (route_update
&& peer
->status
== Established
) {
3224 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3225 PEER_FLAG_SOFT_RECONFIG
)) {
3226 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3228 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3229 rmap_name
, peer
->host
);
3231 bgp_soft_reconfig_in(peer
, afi
, safi
);
3232 } else if (CHECK_FLAG(peer
->cap
,
3233 PEER_CAP_REFRESH_OLD_RCV
)
3234 || CHECK_FLAG(peer
->cap
,
3235 PEER_CAP_REFRESH_NEW_RCV
)) {
3236 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3238 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3239 rmap_name
, peer
->host
);
3240 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3247 * For outbound, unsuppress and default-originate map change (content or
3248 * map created), merely update the "config" here, the actual route
3249 * announcement happens at the group level.
3251 if (filter
->map
[RMAP_OUT
].name
3252 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3253 filter
->map
[RMAP_OUT
].map
= map
;
3255 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3256 filter
->usmap
.map
= map
;
3258 if (peer
->default_rmap
[afi
][safi
].name
3259 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3260 peer
->default_rmap
[afi
][safi
].map
= map
;
3263 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3264 struct route_map
*map
,
3267 struct peer_group
*group
;
3268 struct listnode
*node
, *nnode
;
3269 struct bgp_filter
*filter
;
3276 /* All the peers have been updated correctly already. This is
3277 * just updating the placeholder data. No real update required.
3279 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3280 FOREACH_AFI_SAFI (afi
, safi
) {
3281 filter
= &group
->conf
->filter
[afi
][safi
];
3283 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3284 if ((filter
->map
[direct
].name
)
3285 && (strcmp(rmap_name
,
3286 filter
->map
[direct
].name
)
3288 filter
->map
[direct
].map
= map
;
3291 if (filter
->usmap
.name
3292 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3293 filter
->usmap
.map
= map
;
3299 * Note that if an extreme number (tens of thousands) of route-maps are in use
3300 * and if bgp has an extreme number of peers, network statements, etc then this
3301 * function can consume a lot of cycles. This is due to this function being
3302 * called for each route-map and within this function we walk the list of peers,
3303 * network statements, etc looking to see if they use this route-map.
3305 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3312 struct bgp_node
*bn
;
3313 struct bgp_static
*bgp_static
;
3314 struct bgp_aggregate
*aggregate
;
3315 struct listnode
*node
, *nnode
;
3316 struct route_map
*map
;
3317 char buf
[INET6_ADDRSTRLEN
];
3319 map
= route_map_lookup_by_name(rmap_name
);
3321 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3323 /* Ignore dummy peer-group structure */
3324 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3327 FOREACH_AFI_SAFI (afi
, safi
) {
3328 /* process in/out/import/export/default-orig
3330 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3331 safi
, route_update
);
3335 /* for outbound/default-orig route-maps, process for groups */
3336 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3339 /* update peer-group config (template) */
3340 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3342 FOREACH_AFI_SAFI (afi
, safi
) {
3343 /* For table route-map updates. */
3344 if (!bgp_fibupd_safi(safi
))
3347 if (bgp
->table_map
[afi
][safi
].name
3348 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3351 /* bgp->table_map[afi][safi].map is NULL.
3352 * i.e Route map creation event.
3353 * So update applied_counter.
3354 * If it is not NULL, i.e It may be routemap updation or
3355 * deletion. so no need to update the counter.
3357 if (!bgp
->table_map
[afi
][safi
].map
)
3358 route_map_counter_increment(map
);
3359 bgp
->table_map
[afi
][safi
].map
= map
;
3361 if (BGP_DEBUG(zebra
, ZEBRA
))
3363 "Processing route_map %s update on "
3367 bgp_zebra_announce_table(bgp
, afi
, safi
);
3370 /* For network route-map updates. */
3371 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3372 bn
= bgp_route_next(bn
)) {
3373 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3377 if (!bgp_static
->rmap
.name
3378 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3381 if (!bgp_static
->rmap
.map
)
3382 route_map_counter_increment(map
);
3384 bgp_static
->rmap
.map
= map
;
3386 if (route_update
&& !bgp_static
->backdoor
) {
3387 if (bgp_debug_zebra(&bn
->p
))
3389 "Processing route_map %s update on static route %s",
3391 inet_ntop(bn
->p
.family
,
3392 &bn
->p
.u
.prefix
, buf
,
3394 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3399 /* For aggregate-address route-map updates. */
3400 for (bn
= bgp_table_top(bgp
->aggregate
[afi
][safi
]); bn
;
3401 bn
= bgp_route_next(bn
)) {
3402 aggregate
= bgp_node_get_bgp_aggregate_info(bn
);
3406 if (!aggregate
->rmap
.name
3407 || (strcmp(rmap_name
, aggregate
->rmap
.name
) != 0))
3410 if (!aggregate
->rmap
.map
)
3411 route_map_counter_increment(map
);
3413 aggregate
->rmap
.map
= map
;
3416 if (bgp_debug_zebra(&bn
->p
))
3418 "Processing route_map %s update on aggregate-address route %s",
3420 inet_ntop(bn
->p
.family
,
3421 &bn
->p
.u
.prefix
, buf
,
3423 bgp_aggregate_route(bgp
, &bn
->p
, afi
, safi
,
3429 /* For redistribute route-map updates. */
3430 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3431 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3432 struct list
*red_list
;
3433 struct bgp_redist
*red
;
3435 red_list
= bgp
->redist
[afi
][i
];
3439 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3441 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3445 route_map_counter_increment(map
);
3447 red
->rmap
.map
= map
;
3452 if (BGP_DEBUG(zebra
, ZEBRA
))
3454 "Processing route_map %s update on redistributed routes",
3457 bgp_redistribute_resend(bgp
, afi
, i
,
3462 /* for type5 command route-maps */
3463 FOREACH_AFI_SAFI (afi
, safi
) {
3464 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3465 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3469 /* Make sure the route-map is populated here if not already done */
3470 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3472 if (BGP_DEBUG(zebra
, ZEBRA
))
3474 "Processing route_map %s update on advertise type5 route command",
3477 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3478 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3479 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3484 static void bgp_route_map_process_update_cb(char *rmap_name
)
3486 struct listnode
*node
, *nnode
;
3489 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3490 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3493 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3494 vnc_routemap_update(bgp
, __func__
);
3498 vpn_policy_routemap_event(rmap_name
);
3501 int bgp_route_map_update_timer(struct thread
*thread
)
3503 bm
->t_rmap_update
= NULL
;
3505 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3510 static void bgp_route_map_mark_update(const char *rmap_name
)
3512 struct listnode
*node
, *nnode
;
3515 /* If new update is received before the current timer timed out,
3516 * turn it off and start a new timer.
3518 if (bm
->t_rmap_update
!= NULL
)
3519 THREAD_OFF(bm
->t_rmap_update
);
3521 /* rmap_update_timer of 0 means don't do route updates */
3522 if (bm
->rmap_update_timer
) {
3523 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3524 NULL
, bm
->rmap_update_timer
,
3525 &bm
->t_rmap_update
);
3527 /* Signal the groups that a route-map update event has
3529 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3530 update_group_policy_update(bgp
,
3531 BGP_POLICY_ROUTE_MAP
,
3534 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3535 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3537 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3538 vnc_routemap_update(bgp
, __func__
);
3543 static void bgp_route_map_add(const char *rmap_name
)
3545 if (route_map_mark_updated(rmap_name
) == 0)
3546 bgp_route_map_mark_update(rmap_name
);
3548 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3551 static void bgp_route_map_delete(const char *rmap_name
)
3553 if (route_map_mark_updated(rmap_name
) == 0)
3554 bgp_route_map_mark_update(rmap_name
);
3556 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3559 static void bgp_route_map_event(const char *rmap_name
)
3561 if (route_map_mark_updated(rmap_name
) == 0)
3562 bgp_route_map_mark_update(rmap_name
);
3564 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3567 DEFUN (match_mac_address
,
3568 match_mac_address_cmd
,
3569 "match mac address WORD",
3572 "Match address of route\n"
3573 "MAC Access-list name\n")
3575 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3576 RMAP_EVENT_FILTER_ADDED
);
3579 DEFUN (no_match_mac_address
,
3580 no_match_mac_address_cmd
,
3581 "no match mac address WORD",
3585 "Match address of route\n"
3586 "MAC acess-list name\n")
3588 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3589 RMAP_EVENT_FILTER_DELETED
);
3592 DEFUN (match_evpn_route_type
,
3593 match_evpn_route_type_cmd
,
3594 "match evpn route-type <macip | multicast | prefix>",
3597 "Match route-type\n"
3602 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3603 RMAP_EVENT_MATCH_ADDED
);
3606 DEFUN (no_match_evpn_route_type
,
3607 no_match_evpn_route_type_cmd
,
3608 "no match evpn route-type <macip | multicast | prefix>",
3612 "Match route-type\n"
3617 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3618 RMAP_EVENT_MATCH_DELETED
);
3622 DEFUN (match_evpn_vni
,
3624 "match evpn vni " CMD_VNI_RANGE
,
3630 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3631 RMAP_EVENT_MATCH_ADDED
);
3634 DEFUN (no_match_evpn_vni
,
3635 no_match_evpn_vni_cmd
,
3636 "no match evpn vni " CMD_VNI_RANGE
,
3643 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3644 RMAP_EVENT_MATCH_DELETED
);
3647 DEFUN (match_evpn_default_route
,
3648 match_evpn_default_route_cmd
,
3649 "match evpn default-route",
3652 "default EVPN type-5 route\n")
3654 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3655 RMAP_EVENT_MATCH_ADDED
);
3658 DEFUN (no_match_evpn_default_route
,
3659 no_match_evpn_default_route_cmd
,
3660 "no match evpn default-route",
3664 "default EVPN type-5 route\n")
3666 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3667 RMAP_EVENT_MATCH_DELETED
);
3670 DEFPY(match_vrl_source_vrf
,
3671 match_vrl_source_vrf_cmd
,
3672 "match source-vrf NAME$vrf_name",
3677 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3678 RMAP_EVENT_MATCH_ADDED
);
3681 DEFPY(no_match_vrl_source_vrf
,
3682 no_match_vrl_source_vrf_cmd
,
3683 "no match source-vrf NAME$vrf_name",
3689 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3690 RMAP_EVENT_MATCH_DELETED
);
3695 "match peer <A.B.C.D|X:X::X:X|WORD>",
3697 "Match peer address\n"
3698 "IP address of peer\n"
3699 "IPv6 address of peer\n"
3700 "Interface name of peer\n")
3703 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3704 RMAP_EVENT_MATCH_ADDED
);
3707 DEFUN (match_peer_local
,
3708 match_peer_local_cmd
,
3711 "Match peer address\n"
3712 "Static or Redistributed routes\n")
3714 return bgp_route_match_add(vty
, "peer", "local",
3715 RMAP_EVENT_MATCH_DELETED
);
3718 DEFUN (no_match_peer
,
3720 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3723 "Match peer address\n"
3724 "Static or Redistributed routes\n"
3725 "IP address of peer\n"
3726 "IPv6 address of peer\n"
3727 "Interface name of peer\n")
3731 if (argc
<= idx_peer
)
3732 return bgp_route_match_delete(vty
, "peer", NULL
,
3733 RMAP_EVENT_MATCH_DELETED
);
3734 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3735 RMAP_EVENT_MATCH_DELETED
);
3738 #if defined(HAVE_LUA)
3739 DEFUN (match_command
,
3741 "match command WORD",
3743 "Run a command to match\n"
3744 "The command to run\n")
3746 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3747 RMAP_EVENT_FILTER_ADDED
);
3750 DEFUN (no_match_command
,
3751 no_match_command_cmd
,
3752 "no match command WORD",
3755 "Run a command to match\n"
3756 "The command to run\n")
3758 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3759 RMAP_EVENT_FILTER_DELETED
);
3763 /* match probability */
3764 DEFUN (match_probability
,
3765 match_probability_cmd
,
3766 "match probability (0-100)",
3768 "Match portion of routes defined by percentage value\n"
3769 "Percentage of routes\n")
3772 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3773 RMAP_EVENT_MATCH_ADDED
);
3777 DEFUN (no_match_probability
,
3778 no_match_probability_cmd
,
3779 "no match probability [(1-99)]",
3782 "Match portion of routes defined by percentage value\n"
3783 "Percentage of routes\n")
3786 if (argc
<= idx_number
)
3787 return bgp_route_match_delete(vty
, "probability", NULL
,
3788 RMAP_EVENT_MATCH_DELETED
);
3789 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3790 RMAP_EVENT_MATCH_DELETED
);
3794 DEFUN (match_ip_route_source
,
3795 match_ip_route_source_cmd
,
3796 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3799 "Match advertising source address of route\n"
3800 "IP access-list number\n"
3801 "IP access-list number (expanded range)\n"
3802 "IP standard access-list name\n")
3805 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3806 RMAP_EVENT_FILTER_ADDED
);
3810 DEFUN (no_match_ip_route_source
,
3811 no_match_ip_route_source_cmd
,
3812 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3816 "Match advertising source address of route\n"
3817 "IP access-list number\n"
3818 "IP access-list number (expanded range)\n"
3819 "IP standard access-list name\n")
3822 if (argc
<= idx_number
)
3823 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3824 RMAP_EVENT_FILTER_DELETED
);
3825 return bgp_route_match_delete(vty
, "ip route-source",
3826 argv
[idx_number
]->arg
,
3827 RMAP_EVENT_FILTER_DELETED
);
3831 DEFUN (match_ip_route_source_prefix_list
,
3832 match_ip_route_source_prefix_list_cmd
,
3833 "match ip route-source prefix-list WORD",
3836 "Match advertising source address of route\n"
3837 "Match entries of prefix-lists\n"
3838 "IP prefix-list name\n")
3841 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3842 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3846 DEFUN (no_match_ip_route_source_prefix_list
,
3847 no_match_ip_route_source_prefix_list_cmd
,
3848 "no match ip route-source prefix-list [WORD]",
3852 "Match advertising source address of route\n"
3853 "Match entries of prefix-lists\n"
3854 "IP prefix-list name\n")
3857 if (argc
<= idx_word
)
3858 return bgp_route_match_delete(vty
,
3859 "ip route-source prefix-list",
3860 NULL
, RMAP_EVENT_PLIST_DELETED
);
3861 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3862 argv
[idx_word
]->arg
,
3863 RMAP_EVENT_PLIST_DELETED
);
3867 DEFUN (match_local_pref
,
3868 match_local_pref_cmd
,
3869 "match local-preference (0-4294967295)",
3871 "Match local-preference of route\n"
3875 return bgp_route_match_add(vty
, "local-preference",
3876 argv
[idx_number
]->arg
,
3877 RMAP_EVENT_MATCH_ADDED
);
3881 DEFUN (no_match_local_pref
,
3882 no_match_local_pref_cmd
,
3883 "no match local-preference [(0-4294967295)]",
3886 "Match local preference of route\n"
3887 "Local preference value\n")
3889 int idx_localpref
= 3;
3890 if (argc
<= idx_localpref
)
3891 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3892 RMAP_EVENT_MATCH_DELETED
);
3893 return bgp_route_match_delete(vty
, "local-preference",
3894 argv
[idx_localpref
]->arg
,
3895 RMAP_EVENT_MATCH_DELETED
);
3899 DEFUN (match_community
,
3900 match_community_cmd
,
3901 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3903 "Match BGP community list\n"
3904 "Community-list number (standard)\n"
3905 "Community-list number (expanded)\n"
3906 "Community-list name\n"
3907 "Do exact matching of communities\n")
3909 int idx_comm_list
= 2;
3914 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3915 strlen(argv
[idx_comm_list
]->arg
)
3916 + strlen("exact-match") + 2);
3918 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3920 argstr
= argv
[idx_comm_list
]->arg
;
3922 ret
= bgp_route_match_add(vty
, "community", argstr
,
3923 RMAP_EVENT_CLIST_ADDED
);
3925 if (argstr
!= argv
[idx_comm_list
]->arg
)
3926 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3931 DEFUN (no_match_community
,
3932 no_match_community_cmd
,
3933 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3936 "Match BGP community list\n"
3937 "Community-list number (standard)\n"
3938 "Community-list number (expanded)\n"
3939 "Community-list name\n"
3940 "Do exact matching of communities\n")
3942 return bgp_route_match_delete(vty
, "community", NULL
,
3943 RMAP_EVENT_CLIST_DELETED
);
3946 DEFUN (match_lcommunity
,
3947 match_lcommunity_cmd
,
3948 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
3950 "Match BGP large community list\n"
3951 "Large Community-list number (standard)\n"
3952 "Large Community-list number (expanded)\n"
3953 "Large Community-list name\n"
3954 "Do exact matching of communities\n")
3956 int idx_lcomm_list
= 2;
3961 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3962 strlen(argv
[idx_lcomm_list
]->arg
)
3963 + strlen("exact-match") + 2);
3965 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
3967 argstr
= argv
[idx_lcomm_list
]->arg
;
3969 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
3970 RMAP_EVENT_LLIST_ADDED
);
3971 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
3972 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3977 DEFUN (no_match_lcommunity
,
3978 no_match_lcommunity_cmd
,
3979 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
3982 "Match BGP large community list\n"
3983 "Large Community-list number (standard)\n"
3984 "Large Community-list number (expanded)\n"
3985 "Large Community-list name\n"
3986 "Do exact matching of communities\n")
3988 return bgp_route_match_delete(vty
, "large-community", NULL
,
3989 RMAP_EVENT_LLIST_DELETED
);
3992 DEFUN (match_ecommunity
,
3993 match_ecommunity_cmd
,
3994 "match extcommunity <(1-99)|(100-500)|WORD>",
3996 "Match BGP/VPN extended community list\n"
3997 "Extended community-list number (standard)\n"
3998 "Extended community-list number (expanded)\n"
3999 "Extended community-list name\n")
4001 int idx_comm_list
= 2;
4002 return bgp_route_match_add(vty
, "extcommunity",
4003 argv
[idx_comm_list
]->arg
,
4004 RMAP_EVENT_ECLIST_ADDED
);
4008 DEFUN (no_match_ecommunity
,
4009 no_match_ecommunity_cmd
,
4010 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
4013 "Match BGP/VPN extended community list\n"
4014 "Extended community-list number (standard)\n"
4015 "Extended community-list number (expanded)\n"
4016 "Extended community-list name\n")
4018 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
4019 RMAP_EVENT_ECLIST_DELETED
);
4023 DEFUN (match_aspath
,
4025 "match as-path WORD",
4027 "Match BGP AS path list\n"
4028 "AS path access-list name\n")
4031 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
4032 RMAP_EVENT_ASLIST_ADDED
);
4036 DEFUN (no_match_aspath
,
4037 no_match_aspath_cmd
,
4038 "no match as-path [WORD]",
4041 "Match BGP AS path list\n"
4042 "AS path access-list name\n")
4044 return bgp_route_match_delete(vty
, "as-path", NULL
,
4045 RMAP_EVENT_ASLIST_DELETED
);
4049 DEFUN (match_origin
,
4051 "match origin <egp|igp|incomplete>",
4056 "unknown heritage\n")
4059 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4060 return bgp_route_match_add(vty
, "origin", "igp",
4061 RMAP_EVENT_MATCH_ADDED
);
4062 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4063 return bgp_route_match_add(vty
, "origin", "egp",
4064 RMAP_EVENT_MATCH_ADDED
);
4065 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4066 return bgp_route_match_add(vty
, "origin", "incomplete",
4067 RMAP_EVENT_MATCH_ADDED
);
4069 vty_out(vty
, "%% Invalid match origin type\n");
4070 return CMD_WARNING_CONFIG_FAILED
;
4074 DEFUN (no_match_origin
,
4075 no_match_origin_cmd
,
4076 "no match origin [<egp|igp|incomplete>]",
4082 "unknown heritage\n")
4084 return bgp_route_match_delete(vty
, "origin", NULL
,
4085 RMAP_EVENT_MATCH_DELETED
);
4088 DEFUN (set_table_id
,
4090 "set table (1-4294967295)",
4092 "export route to non-main kernel table\n"
4093 "Kernel routing table id\n")
4097 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4099 return generic_set_add(vty
, index
, "table", argv
[idx_id
]->arg
);
4102 DEFUN (no_set_table_id
,
4103 no_set_table_id_cmd
,
4107 "export route to non-main kernel table\n")
4109 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
4111 return generic_set_delete(vty
, index
, "table", NULL
);
4114 DEFUN (set_ip_nexthop_peer
,
4115 set_ip_nexthop_peer_cmd
,
4116 "[no] set ip next-hop peer-address",
4120 "Next hop address\n"
4121 "Use peer address (for BGP only)\n")
4123 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4124 const char *) = strmatch(argv
[0]->text
, "no")
4125 ? generic_set_delete
4128 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4132 DEFUN (set_ip_nexthop_unchanged
,
4133 set_ip_nexthop_unchanged_cmd
,
4134 "[no] set ip next-hop unchanged",
4138 "Next hop address\n"
4139 "Don't modify existing Next hop address\n")
4141 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4142 const char *) = strmatch(argv
[0]->text
, "no")
4143 ? generic_set_delete
4146 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4150 DEFUN (set_distance
,
4152 "set distance (0-255)",
4154 "BGP Administrative Distance to use\n"
4159 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4160 "distance", argv
[idx_number
]->arg
);
4163 DEFUN (no_set_distance
,
4164 no_set_distance_cmd
,
4165 "no set distance [(0-255)]",
4167 "BGP Administrative Distance to use\n"
4170 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4174 DEFUN (set_local_pref
,
4176 "set local-preference (0-4294967295)",
4178 "BGP local preference path attribute\n"
4179 "Preference value\n")
4182 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4183 "local-preference", argv
[idx_number
]->arg
);
4187 DEFUN (no_set_local_pref
,
4188 no_set_local_pref_cmd
,
4189 "no set local-preference [(0-4294967295)]",
4192 "BGP local preference path attribute\n"
4193 "Preference value\n")
4195 int idx_localpref
= 3;
4196 if (argc
<= idx_localpref
)
4197 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4198 "local-preference", NULL
);
4199 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4200 "local-preference", argv
[idx_localpref
]->arg
);
4206 "set weight (0-4294967295)",
4208 "BGP weight for routing table\n"
4212 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4213 argv
[idx_number
]->arg
);
4217 DEFUN (no_set_weight
,
4219 "no set weight [(0-4294967295)]",
4222 "BGP weight for routing table\n"
4226 if (argc
<= idx_weight
)
4227 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4229 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4230 "weight", argv
[idx_weight
]->arg
);
4233 DEFUN (set_label_index
,
4234 set_label_index_cmd
,
4235 "set label-index (0-1048560)",
4237 "Label index to associate with the prefix\n"
4238 "Label index value\n")
4241 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4242 "label-index", argv
[idx_number
]->arg
);
4245 DEFUN (no_set_label_index
,
4246 no_set_label_index_cmd
,
4247 "no set label-index [(0-1048560)]",
4250 "Label index to associate with the prefix\n"
4251 "Label index value\n")
4253 int idx_label_index
= 3;
4254 if (argc
<= idx_label_index
)
4255 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4256 "label-index", NULL
);
4257 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4258 "label-index", argv
[idx_label_index
]->arg
);
4261 DEFUN (set_aspath_prepend_asn
,
4262 set_aspath_prepend_asn_cmd
,
4263 "set as-path prepend (1-4294967295)...",
4265 "Transform BGP AS_PATH attribute\n"
4266 "Prepend to the as-path\n"
4273 str
= argv_concat(argv
, argc
, idx_asn
);
4274 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4275 "as-path prepend", str
);
4276 XFREE(MTYPE_TMP
, str
);
4281 DEFUN (set_aspath_prepend_lastas
,
4282 set_aspath_prepend_lastas_cmd
,
4283 "set as-path prepend last-as (1-10)",
4285 "Transform BGP AS_PATH attribute\n"
4286 "Prepend to the as-path\n"
4287 "Use the peer's AS-number\n"
4288 "Number of times to insert\n")
4290 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4293 DEFUN (no_set_aspath_prepend
,
4294 no_set_aspath_prepend_cmd
,
4295 "no set as-path prepend [(1-4294967295)]",
4298 "Transform BGP AS_PATH attribute\n"
4299 "Prepend to the as-path\n"
4306 str
= argv_concat(argv
, argc
, idx_asn
);
4307 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4308 "as-path prepend", str
);
4309 XFREE(MTYPE_TMP
, str
);
4313 DEFUN (no_set_aspath_prepend_lastas
,
4314 no_set_aspath_prepend_lastas_cmd
,
4315 "no set as-path prepend last-as [(1-10)]",
4318 "Transform BGP AS_PATH attribute\n"
4319 "Prepend to the as-path\n"
4320 "Use the peers AS-number\n"
4321 "Number of times to insert\n")
4323 return no_set_aspath_prepend(self
, vty
, argc
, argv
);
4326 DEFUN (set_aspath_exclude
,
4327 set_aspath_exclude_cmd
,
4328 "set as-path exclude (1-4294967295)...",
4330 "Transform BGP AS-path attribute\n"
4331 "Exclude from the as-path\n"
4338 str
= argv_concat(argv
, argc
, idx_asn
);
4339 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4340 "as-path exclude", str
);
4341 XFREE(MTYPE_TMP
, str
);
4345 DEFUN (no_set_aspath_exclude
,
4346 no_set_aspath_exclude_cmd
,
4347 "no set as-path exclude (1-4294967295)...",
4350 "Transform BGP AS_PATH attribute\n"
4351 "Exclude from the as-path\n"
4358 str
= argv_concat(argv
, argc
, idx_asn
);
4359 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4360 "as-path exclude", str
);
4361 XFREE(MTYPE_TMP
, str
);
4365 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4366 "no set as-path exclude",
4368 "Transform BGP AS_PATH attribute\n"
4369 "Exclude from the as-path\n")
4371 DEFUN (set_community
,
4373 "set community AA:NN...",
4375 "BGP community attribute\n"
4383 struct community
*com
= NULL
;
4388 b
= buffer_new(1024);
4390 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4391 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4398 buffer_putc(b
, ' ');
4402 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4404 buffer_putstr(b
, "internet");
4407 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4409 buffer_putstr(b
, "local-AS");
4412 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4413 && strncmp(argv
[i
]->arg
, "no-advertise",
4414 strlen(argv
[i
]->arg
))
4416 buffer_putstr(b
, "no-advertise");
4419 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4420 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4422 buffer_putstr(b
, "no-export");
4425 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4426 strlen(argv
[i
]->arg
))
4428 buffer_putstr(b
, "graceful-shutdown");
4431 buffer_putstr(b
, argv
[i
]->arg
);
4433 buffer_putc(b
, '\0');
4435 /* Fetch result string then compile it to communities attribute. */
4436 str
= buffer_getstr(b
);
4440 com
= community_str2com(str
);
4441 XFREE(MTYPE_TMP
, str
);
4444 /* Can't compile user input into communities attribute. */
4446 vty_out(vty
, "%% Malformed communities attribute\n");
4447 return CMD_WARNING_CONFIG_FAILED
;
4450 /* Set communites attribute string. */
4451 str
= community_str(com
, false);
4454 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4455 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4456 strlcpy(argstr
, str
, argstr_sz
);
4457 strlcat(argstr
, " additive", argstr_sz
);
4458 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4459 "community", argstr
);
4460 XFREE(MTYPE_TMP
, argstr
);
4462 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4465 community_free(&com
);
4470 DEFUN (set_community_none
,
4471 set_community_none_cmd
,
4472 "set community none",
4474 "BGP community attribute\n"
4475 "No community attribute\n")
4477 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4478 "community", "none");
4481 DEFUN (no_set_community
,
4482 no_set_community_cmd
,
4483 "no set community AA:NN...",
4486 "BGP community attribute\n"
4489 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4493 ALIAS (no_set_community
,
4494 no_set_community_short_cmd
,
4498 "BGP community attribute\n")
4501 DEFUN (set_community_delete
,
4502 set_community_delete_cmd
,
4503 "set comm-list <(1-99)|(100-500)|WORD> delete",
4505 "set BGP community list (for deletion)\n"
4506 "Community-list number (standard)\n"
4507 "Community-list number (expanded)\n"
4508 "Community-list name\n"
4509 "Delete matching communities\n")
4511 int idx_comm_list
= 2;
4514 args
= argv_concat(argv
, argc
, idx_comm_list
);
4515 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4517 XFREE(MTYPE_TMP
, args
);
4522 DEFUN (no_set_community_delete
,
4523 no_set_community_delete_cmd
,
4524 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4527 "set BGP community list (for deletion)\n"
4528 "Community-list number (standard)\n"
4529 "Community-list number (expanded)\n"
4530 "Community-list name\n"
4531 "Delete matching communities\n")
4533 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4537 DEFUN (set_lcommunity
,
4539 "set large-community AA:BB:CC...",
4541 "BGP large community attribute\n"
4542 "Large Community number in aa:bb:cc format or additive\n")
4547 str
= argv_concat(argv
, argc
, 2);
4548 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4549 "large-community", str
);
4550 XFREE(MTYPE_TMP
, str
);
4555 DEFUN (set_lcommunity_none
,
4556 set_lcommunity_none_cmd
,
4557 "set large-community none",
4559 "BGP large community attribute\n"
4560 "No large community attribute\n")
4562 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4563 "large-community", "none");
4566 DEFUN (no_set_lcommunity
,
4567 no_set_lcommunity_cmd
,
4568 "no set large-community none",
4571 "BGP large community attribute\n"
4572 "No community attribute\n")
4574 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4575 "large-community", NULL
);
4578 DEFUN (no_set_lcommunity1
,
4579 no_set_lcommunity1_cmd
,
4580 "no set large-community AA:BB:CC...",
4583 "BGP large community attribute\n"
4584 "Large community in AA:BB:CC... format or additive\n")
4586 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4587 "large-community", NULL
);
4590 ALIAS (no_set_lcommunity1
,
4591 no_set_lcommunity1_short_cmd
,
4592 "no set large-community",
4595 "BGP large community attribute\n")
4597 DEFUN (set_lcommunity_delete
,
4598 set_lcommunity_delete_cmd
,
4599 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4601 "set BGP large community list (for deletion)\n"
4602 "Large Community-list number (standard)\n"
4603 "Large Communitly-list number (expanded)\n"
4604 "Large Community-list name\n"
4605 "Delete matching large communities\n")
4607 int idx_lcomm_list
= 2;
4610 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
4611 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4612 "large-comm-list", args
);
4613 XFREE(MTYPE_TMP
, args
);
4618 DEFUN (no_set_lcommunity_delete
,
4619 no_set_lcommunity_delete_cmd
,
4620 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4623 "set BGP large community list (for deletion)\n"
4624 "Large Community-list number (standard)\n"
4625 "Large Communitly-list number (expanded)\n"
4626 "Large Community-list name\n"
4627 "Delete matching large communities\n")
4629 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4630 "large-comm-list", NULL
);
4633 ALIAS (no_set_lcommunity_delete
,
4634 no_set_lcommunity_delete_short_cmd
,
4635 "no set large-comm-list",
4638 "set BGP large community list (for deletion)\n")
4640 DEFUN (set_ecommunity_rt
,
4641 set_ecommunity_rt_cmd
,
4642 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4644 "BGP extended community attribute\n"
4645 "Route Target extended community\n"
4646 "VPN extended community\n")
4652 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4653 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4654 "extcommunity rt", str
);
4655 XFREE(MTYPE_TMP
, str
);
4660 DEFUN (no_set_ecommunity_rt
,
4661 no_set_ecommunity_rt_cmd
,
4662 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4665 "BGP extended community attribute\n"
4666 "Route Target extended community\n"
4667 "VPN extended community\n")
4669 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4670 "extcommunity rt", NULL
);
4673 ALIAS (no_set_ecommunity_rt
,
4674 no_set_ecommunity_rt_short_cmd
,
4675 "no set extcommunity rt",
4678 "BGP extended community attribute\n"
4679 "Route Target extended community\n")
4681 DEFUN (set_ecommunity_soo
,
4682 set_ecommunity_soo_cmd
,
4683 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4685 "BGP extended community attribute\n"
4686 "Site-of-Origin extended community\n"
4687 "VPN extended community\n")
4693 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4694 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4695 "extcommunity soo", str
);
4696 XFREE(MTYPE_TMP
, str
);
4701 DEFUN (no_set_ecommunity_soo
,
4702 no_set_ecommunity_soo_cmd
,
4703 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4706 "BGP extended community attribute\n"
4707 "Site-of-Origin extended community\n"
4708 "VPN extended community\n")
4710 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4711 "extcommunity soo", NULL
);
4714 ALIAS (no_set_ecommunity_soo
,
4715 no_set_ecommunity_soo_short_cmd
,
4716 "no set extcommunity soo",
4719 "GP extended community attribute\n"
4720 "Site-of-Origin extended community\n")
4724 "set origin <egp|igp|incomplete>",
4729 "unknown heritage\n")
4732 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4733 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4735 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4736 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4738 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4739 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4740 "origin", "incomplete");
4742 vty_out(vty
, "%% Invalid set origin type\n");
4743 return CMD_WARNING_CONFIG_FAILED
;
4747 DEFUN (no_set_origin
,
4749 "no set origin [<egp|igp|incomplete>]",
4755 "unknown heritage\n")
4757 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4762 DEFUN (set_atomic_aggregate
,
4763 set_atomic_aggregate_cmd
,
4764 "set atomic-aggregate",
4766 "BGP atomic aggregate attribute\n" )
4768 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4769 "atomic-aggregate", NULL
);
4772 DEFUN (no_set_atomic_aggregate
,
4773 no_set_atomic_aggregate_cmd
,
4774 "no set atomic-aggregate",
4777 "BGP atomic aggregate attribute\n" )
4779 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4780 "atomic-aggregate", NULL
);
4783 DEFUN (set_aggregator_as
,
4784 set_aggregator_as_cmd
,
4785 "set aggregator as (1-4294967295) A.B.C.D",
4787 "BGP aggregator attribute\n"
4788 "AS number of aggregator\n"
4790 "IP address of aggregator\n")
4795 struct in_addr address
;
4798 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4800 vty_out(vty
, "Aggregator IP address is invalid\n");
4801 return CMD_WARNING_CONFIG_FAILED
;
4804 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4805 strlen(argv
[idx_number
]->arg
)
4806 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4808 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4810 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4811 "aggregator as", argstr
);
4813 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4819 DEFUN (no_set_aggregator_as
,
4820 no_set_aggregator_as_cmd
,
4821 "no set aggregator as [(1-4294967295) A.B.C.D]",
4824 "BGP aggregator attribute\n"
4825 "AS number of aggregator\n"
4827 "IP address of aggregator\n")
4832 struct in_addr address
;
4835 if (argc
<= idx_asn
)
4836 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4837 "aggregator as", NULL
);
4839 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4841 vty_out(vty
, "Aggregator IP address is invalid\n");
4842 return CMD_WARNING_CONFIG_FAILED
;
4845 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4846 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4849 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4851 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4852 "aggregator as", argstr
);
4854 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4859 DEFUN (match_ipv6_next_hop
,
4860 match_ipv6_next_hop_cmd
,
4861 "match ipv6 next-hop X:X::X:X",
4864 "Match IPv6 next-hop address of route\n"
4865 "IPv6 address of next hop\n")
4868 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4869 RMAP_EVENT_MATCH_ADDED
);
4872 DEFUN (no_match_ipv6_next_hop
,
4873 no_match_ipv6_next_hop_cmd
,
4874 "no match ipv6 next-hop X:X::X:X",
4878 "Match IPv6 next-hop address of route\n"
4879 "IPv6 address of next hop\n")
4882 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4883 RMAP_EVENT_MATCH_DELETED
);
4887 DEFUN (set_ipv6_nexthop_peer
,
4888 set_ipv6_nexthop_peer_cmd
,
4889 "set ipv6 next-hop peer-address",
4892 "Next hop address\n"
4893 "Use peer address (for BGP only)\n")
4895 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4896 "ipv6 next-hop peer-address", NULL
);
4899 DEFUN (no_set_ipv6_nexthop_peer
,
4900 no_set_ipv6_nexthop_peer_cmd
,
4901 "no set ipv6 next-hop peer-address",
4905 "IPv6 next-hop address\n"
4906 "Use peer address (for BGP only)\n")
4908 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4909 "ipv6 next-hop peer-address", NULL
);
4912 DEFUN (set_ipv6_nexthop_prefer_global
,
4913 set_ipv6_nexthop_prefer_global_cmd
,
4914 "set ipv6 next-hop prefer-global",
4917 "IPv6 next-hop address\n"
4918 "Prefer global over link-local if both exist\n")
4920 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4921 "ipv6 next-hop prefer-global", NULL
);
4925 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4926 no_set_ipv6_nexthop_prefer_global_cmd
,
4927 "no set ipv6 next-hop prefer-global",
4931 "IPv6 next-hop address\n"
4932 "Prefer global over link-local if both exist\n")
4934 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4935 "ipv6 next-hop prefer-global", NULL
);
4938 DEFUN (set_ipv6_nexthop_global
,
4939 set_ipv6_nexthop_global_cmd
,
4940 "set ipv6 next-hop global X:X::X:X",
4943 "IPv6 next-hop address\n"
4944 "IPv6 global address\n"
4945 "IPv6 address of next hop\n")
4948 struct in6_addr addr
;
4951 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4953 vty_out(vty
, "%% Malformed nexthop address\n");
4954 return CMD_WARNING_CONFIG_FAILED
;
4956 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4957 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4958 vty_out(vty
, "%% Invalid global nexthop address\n");
4959 return CMD_WARNING_CONFIG_FAILED
;
4962 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4963 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4967 DEFUN (no_set_ipv6_nexthop_global
,
4968 no_set_ipv6_nexthop_global_cmd
,
4969 "no set ipv6 next-hop global X:X::X:X",
4973 "IPv6 next-hop address\n"
4974 "IPv6 global address\n"
4975 "IPv6 address of next hop\n")
4978 if (argc
<= idx_ipv6
)
4979 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4980 "ipv6 next-hop global", NULL
);
4981 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4982 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4985 #ifdef KEEP_OLD_VPN_COMMANDS
4986 DEFUN (set_vpn_nexthop
,
4987 set_vpn_nexthop_cmd
,
4988 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4990 "VPNv4 information\n"
4991 "VPN next-hop address\n"
4992 "IP address of next hop\n"
4993 "VPNv6 information\n"
4994 "VPN next-hop address\n"
4995 "IPv6 address of next hop\n")
5001 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5003 return generic_set_add(
5004 vty
, VTY_GET_CONTEXT(route_map_index
),
5005 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5007 return generic_set_add(
5008 vty
, VTY_GET_CONTEXT(route_map_index
),
5009 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5014 DEFUN (no_set_vpn_nexthop
,
5015 no_set_vpn_nexthop_cmd
,
5016 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
5019 "VPNv4 information\n"
5020 "VPN next-hop address\n"
5021 "IP address of next hop\n"
5022 "VPNv6 information\n"
5023 "VPN next-hop address\n"
5024 "IPv6 address of next hop\n")
5034 arg
= argv
[idx_ip
]->arg
;
5035 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
5037 return generic_set_delete(
5038 vty
, VTY_GET_CONTEXT(route_map_index
),
5039 "ipv4 vpn next-hop", arg
);
5041 return generic_set_delete(
5042 vty
, VTY_GET_CONTEXT(route_map_index
),
5043 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5047 #endif /* KEEP_OLD_VPN_COMMANDS */
5049 DEFUN (set_ipx_vpn_nexthop
,
5050 set_ipx_vpn_nexthop_cmd
,
5051 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
5053 "IPv4 information\n"
5054 "IPv6 information\n"
5056 "VPN next-hop address\n"
5057 "IP address of next hop\n"
5058 "IPv6 address of next hop\n")
5064 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5066 return generic_set_add(
5067 vty
, VTY_GET_CONTEXT(route_map_index
),
5068 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
5070 return generic_set_add(
5071 vty
, VTY_GET_CONTEXT(route_map_index
),
5072 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
5077 DEFUN (no_set_ipx_vpn_nexthop
,
5078 no_set_ipx_vpn_nexthop_cmd
,
5079 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
5082 "IPv4 information\n"
5083 "IPv6 information\n"
5085 "VPN next-hop address\n"
5086 "IP address of next hop\n"
5087 "IPv6 address of next hop\n")
5097 arg
= argv
[idx_ip
]->arg
;
5098 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
5100 return generic_set_delete(
5101 vty
, VTY_GET_CONTEXT(route_map_index
),
5102 "ipv4 vpn next-hop", arg
);
5104 return generic_set_delete(
5105 vty
, VTY_GET_CONTEXT(route_map_index
),
5106 "ipv6 vpn next-hop", arg
);
5111 DEFUN (set_originator_id
,
5112 set_originator_id_cmd
,
5113 "set originator-id A.B.C.D",
5115 "BGP originator ID attribute\n"
5116 "IP address of originator\n")
5119 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
5120 "originator-id", argv
[idx_ipv4
]->arg
);
5124 DEFUN (no_set_originator_id
,
5125 no_set_originator_id_cmd
,
5126 "no set originator-id [A.B.C.D]",
5129 "BGP originator ID attribute\n"
5130 "IP address of originator\n")
5134 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
5136 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
5137 "originator-id", arg
);
5141 /* Initialization of route map. */
5142 void bgp_route_map_init(void)
5146 route_map_add_hook(bgp_route_map_add
);
5147 route_map_delete_hook(bgp_route_map_delete
);
5148 route_map_event_hook(bgp_route_map_event
);
5150 route_map_match_interface_hook(generic_match_add
);
5151 route_map_no_match_interface_hook(generic_match_delete
);
5153 route_map_match_ip_address_hook(generic_match_add
);
5154 route_map_no_match_ip_address_hook(generic_match_delete
);
5156 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
5157 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
5159 route_map_match_ip_next_hop_hook(generic_match_add
);
5160 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
5162 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
5163 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5165 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5166 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5168 route_map_match_ipv6_address_hook(generic_match_add
);
5169 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5171 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5172 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5174 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5175 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5177 route_map_match_metric_hook(generic_match_add
);
5178 route_map_no_match_metric_hook(generic_match_delete
);
5180 route_map_match_tag_hook(generic_match_add
);
5181 route_map_no_match_tag_hook(generic_match_delete
);
5183 route_map_set_ip_nexthop_hook(generic_set_add
);
5184 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5186 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5187 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5189 route_map_set_metric_hook(generic_set_add
);
5190 route_map_no_set_metric_hook(generic_set_delete
);
5192 route_map_set_tag_hook(generic_set_add
);
5193 route_map_no_set_tag_hook(generic_set_delete
);
5195 route_map_install_match(&route_match_peer_cmd
);
5196 route_map_install_match(&route_match_local_pref_cmd
);
5197 #if defined(HAVE_LUA)
5198 route_map_install_match(&route_match_command_cmd
);
5200 route_map_install_match(&route_match_ip_address_cmd
);
5201 route_map_install_match(&route_match_ip_next_hop_cmd
);
5202 route_map_install_match(&route_match_ip_route_source_cmd
);
5203 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5204 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5205 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5206 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5207 route_map_install_match(&route_match_aspath_cmd
);
5208 route_map_install_match(&route_match_community_cmd
);
5209 route_map_install_match(&route_match_lcommunity_cmd
);
5210 route_map_install_match(&route_match_ecommunity_cmd
);
5211 route_map_install_match(&route_match_local_pref_cmd
);
5212 route_map_install_match(&route_match_metric_cmd
);
5213 route_map_install_match(&route_match_origin_cmd
);
5214 route_map_install_match(&route_match_probability_cmd
);
5215 route_map_install_match(&route_match_interface_cmd
);
5216 route_map_install_match(&route_match_tag_cmd
);
5217 route_map_install_match(&route_match_mac_address_cmd
);
5218 route_map_install_match(&route_match_evpn_vni_cmd
);
5219 route_map_install_match(&route_match_evpn_route_type_cmd
);
5220 route_map_install_match(&route_match_evpn_default_route_cmd
);
5221 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5223 route_map_install_set(&route_set_table_id_cmd
);
5224 route_map_install_set(&route_set_ip_nexthop_cmd
);
5225 route_map_install_set(&route_set_local_pref_cmd
);
5226 route_map_install_set(&route_set_weight_cmd
);
5227 route_map_install_set(&route_set_label_index_cmd
);
5228 route_map_install_set(&route_set_metric_cmd
);
5229 route_map_install_set(&route_set_distance_cmd
);
5230 route_map_install_set(&route_set_aspath_prepend_cmd
);
5231 route_map_install_set(&route_set_aspath_exclude_cmd
);
5232 route_map_install_set(&route_set_origin_cmd
);
5233 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5234 route_map_install_set(&route_set_aggregator_as_cmd
);
5235 route_map_install_set(&route_set_community_cmd
);
5236 route_map_install_set(&route_set_community_delete_cmd
);
5237 route_map_install_set(&route_set_lcommunity_cmd
);
5238 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5239 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5240 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5241 route_map_install_set(&route_set_originator_id_cmd
);
5242 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5243 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5244 route_map_install_set(&route_set_tag_cmd
);
5245 route_map_install_set(&route_set_label_index_cmd
);
5247 install_element(RMAP_NODE
, &match_peer_cmd
);
5248 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5249 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5250 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5251 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5252 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5253 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5254 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5255 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5256 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5257 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5258 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5259 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5260 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5261 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5262 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5263 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5265 install_element(RMAP_NODE
, &match_aspath_cmd
);
5266 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5267 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5268 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5269 install_element(RMAP_NODE
, &match_community_cmd
);
5270 install_element(RMAP_NODE
, &no_match_community_cmd
);
5271 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5272 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5273 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5274 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5275 install_element(RMAP_NODE
, &match_origin_cmd
);
5276 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5277 install_element(RMAP_NODE
, &match_probability_cmd
);
5278 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5280 install_element(RMAP_NODE
, &no_set_table_id_cmd
);
5281 install_element(RMAP_NODE
, &set_table_id_cmd
);
5282 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5283 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5284 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5285 install_element(RMAP_NODE
, &set_distance_cmd
);
5286 install_element(RMAP_NODE
, &no_set_distance_cmd
);
5287 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5288 install_element(RMAP_NODE
, &set_weight_cmd
);
5289 install_element(RMAP_NODE
, &set_label_index_cmd
);
5290 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5291 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5292 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5293 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5294 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5295 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5296 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
5297 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5298 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5299 install_element(RMAP_NODE
, &set_origin_cmd
);
5300 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5301 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5302 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5303 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5304 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5305 install_element(RMAP_NODE
, &set_community_cmd
);
5306 install_element(RMAP_NODE
, &set_community_none_cmd
);
5307 install_element(RMAP_NODE
, &no_set_community_cmd
);
5308 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5309 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5310 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5311 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5312 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5313 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5314 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5315 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5316 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5317 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5318 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5319 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5320 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5321 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5322 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5323 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5324 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5325 #ifdef KEEP_OLD_VPN_COMMANDS
5326 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5327 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5328 #endif /* KEEP_OLD_VPN_COMMANDS */
5329 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5330 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5331 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5332 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5334 route_map_install_match(&route_match_ipv6_address_cmd
);
5335 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5336 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5337 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5338 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5339 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5340 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5341 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5343 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5344 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5345 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5346 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5347 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5348 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5349 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5350 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5351 #if defined(HAVE_LUA)
5352 install_element(RMAP_NODE
, &match_command_cmd
);
5353 install_element(RMAP_NODE
, &no_match_command_cmd
);
5357 void bgp_route_map_terminate(void)
5359 /* ToDo: Cleanup all the used memory */