1 /* Route map function of bgpd.
2 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #ifdef HAVE_LIBPCREPOSIX
33 #include <pcreposix.h>
36 #endif /* HAVE_LIBPCREPOSIX */
38 #include "sockunion.h"
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_table.h"
45 #include "bgpd/bgp_attr.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_packet.h"
48 #include "bgpd/bgp_route.h"
49 #include "bgpd/bgp_zebra.h"
50 #include "bgpd/bgp_regex.h"
51 #include "bgpd/bgp_community.h"
52 #include "bgpd/bgp_clist.h"
53 #include "bgpd/bgp_filter.h"
54 #include "bgpd/bgp_mplsvpn.h"
55 #include "bgpd/bgp_ecommunity.h"
56 #include "bgpd/bgp_lcommunity.h"
57 #include "bgpd/bgp_vty.h"
58 #include "bgpd/bgp_debug.h"
59 #include "bgpd/bgp_evpn.h"
60 #include "bgpd/bgp_evpn_private.h"
61 #include "bgpd/bgp_evpn_vty.h"
62 #include "bgpd/bgp_mplsvpn.h"
63 #include "bgpd/bgp_pbr.h"
64 #include "bgpd/bgp_flowspec_util.h"
65 #include "bgpd/bgp_encap_types.h"
68 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
71 #ifndef VTYSH_EXTRACT_PL
72 #include "bgpd/bgp_routemap_clippy.c"
75 /* Memo of route-map commands.
84 ip route-source : Done
88 ipv6 route-source: (This will not be implemented by bgpd)
89 ipv6 prefix-list : Done
90 length : (This will not be implemented by bgpd)
92 route-type : (This will not be implemented by bgpd)
94 local-preference : Done
96 set as-path prepend : Done
98 automatic-tag : (This will not be implemented by bgpd)
100 large-community : Done
101 large-comm-list : Done
104 default : (This will not be implemented by bgpd)
105 interface : (This will not be implemented by bgpd)
106 ip default : (This will not be implemented by bgpd)
108 ip precedence : (This will not be implemented by bgpd)
109 ip tos : (This will not be implemented by bgpd)
110 level : (This will not be implemented by bgpd)
111 local-preference : Done
113 metric-type : Not yet
120 set ipv6 next-hop global: Done
121 set ipv6 next-hop prefer-global: Done
122 set ipv6 next-hop local : Done
123 set as-path exclude : Done
127 /* generic value manipulation to be shared in multiple rules */
129 #define RMAP_VALUE_SET 0
130 #define RMAP_VALUE_ADD 1
131 #define RMAP_VALUE_SUB 2
139 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
141 if (rv
->variable
== 0 && value
== rv
->value
)
147 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
152 switch (rv
->variable
) {
161 switch (rv
->action
) {
163 if (current
> UINT32_MAX
- value
)
165 return current
+ value
;
167 if (current
<= value
)
169 return current
- value
;
175 static void *route_value_compile(const char *arg
)
177 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
178 unsigned long larg
= 0;
180 struct rmap_value
*rv
;
183 action
= RMAP_VALUE_ADD
;
185 } else if (arg
[0] == '-') {
186 action
= RMAP_VALUE_SUB
;
190 if (all_digit(arg
)) {
192 larg
= strtoul(arg
, &endptr
, 10);
193 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
196 if (strcmp(arg
, "rtt") == 0)
202 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
210 static void route_value_free(void *rule
)
212 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
215 /* generic as path object to be shared in multiple rules */
217 static void *route_aspath_compile(const char *arg
)
219 struct aspath
*aspath
;
221 aspath
= aspath_str2aspath(arg
);
227 static void route_aspath_free(void *rule
)
229 struct aspath
*aspath
= rule
;
233 struct bgp_match_peer_compiled
{
238 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
240 /* Compares the peer specified in the 'match peer' clause with the peer
241 received in bgp_path_info->peer. If it is the same, or if the peer structure
242 received is a peer_group containing it, returns RMAP_MATCH. */
243 static enum route_map_cmd_result_t
244 route_match_peer(void *rule
, const struct prefix
*prefix
,
245 route_map_object_t type
, void *object
)
247 struct bgp_match_peer_compiled
*pc
;
249 union sockunion su_def
= {
250 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
251 struct peer_group
*group
;
253 struct listnode
*node
, *nnode
;
255 if (type
== RMAP_BGP
) {
258 peer
= ((struct bgp_path_info
*)object
)->peer
;
264 if (strcmp(peer
->conf_if
, pc
->interface
) == 0)
270 /* If su='0.0.0.0' (command 'match peer local'), and it's a
272 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH
274 if (sockunion_same(su
, &su_def
)) {
276 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
277 || CHECK_FLAG(peer
->rmap_type
,
278 PEER_RMAP_TYPE_REDISTRIBUTE
)
279 || CHECK_FLAG(peer
->rmap_type
,
280 PEER_RMAP_TYPE_DEFAULT
))
287 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
288 if (sockunion_same(su
, &peer
->su
))
294 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
296 if (sockunion_same(su
, &peer
->su
))
305 static void *route_match_peer_compile(const char *arg
)
307 struct bgp_match_peer_compiled
*pc
;
310 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
311 sizeof(struct bgp_match_peer_compiled
));
313 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
315 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
322 /* Free route map's compiled `ip address' value. */
323 static void route_match_peer_free(void *rule
)
325 struct bgp_match_peer_compiled
*pc
= rule
;
327 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
329 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
332 /* Route map commands for ip address matching. */
333 struct route_map_rule_cmd route_match_peer_cmd
= {"peer", route_match_peer
,
334 route_match_peer_compile
,
335 route_match_peer_free
};
337 #if defined(HAVE_LUA)
338 static enum route_map_cmd_result_t
339 route_match_command(void *rule
, const struct prefix
*prefix
,
340 route_map_object_t type
, void *object
)
342 int status
= RMAP_NOMATCH
;
343 u_int32_t locpref
= 0;
344 u_int32_t newlocpref
= 0;
345 enum lua_rm_status lrm_status
;
346 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
347 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
353 * Setup the prefix information to pass in
355 lua_setup_prefix_table(L
, prefix
);
357 zlog_debug("Set up prefix table");
359 * Setup the bgp_path_info information
362 lua_pushinteger(L
, path
->attr
->med
);
363 lua_setfield(L
, -2, "metric");
364 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
365 lua_setfield(L
, -2, "ifindex");
366 lua_pushstring(L
, path
->attr
->aspath
->str
);
367 lua_setfield(L
, -2, "aspath");
368 lua_pushinteger(L
, path
->attr
->local_pref
);
369 lua_setfield(L
, -2, "localpref");
370 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
371 lua_setglobal(L
, "nexthop");
373 zlog_debug("Set up nexthop information");
377 lrm_status
= lua_run_rm_rule(L
, rule
);
378 switch (lrm_status
) {
380 zlog_debug("RM_FAILURE");
383 zlog_debug("RM_NOMATCH");
385 case LUA_RM_MATCH_AND_CHANGE
:
386 zlog_debug("MATCH AND CHANGE");
387 lua_getglobal(L
, "nexthop");
388 path
->attr
->med
= get_integer(L
, "metric");
390 * This needs to be abstraced with the set function
392 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
393 locpref
= path
->attr
->local_pref
;
394 newlocpref
= get_integer(L
, "localpref");
395 if (newlocpref
!= locpref
) {
396 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
397 path
->attr
->local_pref
= newlocpref
;
402 zlog_debug("MATCH ONLY");
410 static void *route_match_command_compile(const char *arg
)
414 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
419 route_match_command_free(void *rule
)
421 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
424 struct route_map_rule_cmd route_match_command_cmd
= {
427 route_match_command_compile
,
428 route_match_command_free
432 /* `match ip address IP_ACCESS_LIST' */
434 /* Match function should return 1 if match is success else return
436 static enum route_map_cmd_result_t
437 route_match_ip_address(void *rule
, const struct prefix
*prefix
,
438 route_map_object_t type
, void *object
)
440 struct access_list
*alist
;
442 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
443 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
447 return (access_list_apply(alist
, prefix
) == FILTER_DENY
454 /* Route map `ip address' match statement. `arg' should be
456 static void *route_match_ip_address_compile(const char *arg
)
458 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
461 /* Free route map's compiled `ip address' value. */
462 static void route_match_ip_address_free(void *rule
)
464 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
467 /* Route map commands for ip address matching. */
468 struct route_map_rule_cmd route_match_ip_address_cmd
= {
469 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
470 route_match_ip_address_free
};
472 /* `match ip next-hop IP_ADDRESS' */
474 /* Match function return 1 if match is success else return zero. */
475 static enum route_map_cmd_result_t
476 route_match_ip_next_hop(void *rule
, const struct prefix
*prefix
,
477 route_map_object_t type
, void *object
)
479 struct access_list
*alist
;
480 struct bgp_path_info
*path
;
481 struct prefix_ipv4 p
;
483 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
486 p
.prefix
= path
->attr
->nexthop
;
487 p
.prefixlen
= IPV4_MAX_BITLEN
;
489 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
493 return (access_list_apply(alist
, &p
) == FILTER_DENY
500 /* Route map `ip next-hop' match statement. `arg' is
502 static void *route_match_ip_next_hop_compile(const char *arg
)
504 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
507 /* Free route map's compiled `ip address' value. */
508 static void route_match_ip_next_hop_free(void *rule
)
510 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
513 /* Route map commands for ip next-hop matching. */
514 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
515 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
516 route_match_ip_next_hop_free
};
518 /* `match ip route-source ACCESS-LIST' */
520 /* Match function return 1 if match is success else return zero. */
521 static enum route_map_cmd_result_t
522 route_match_ip_route_source(void *rule
, const struct prefix
*pfx
,
523 route_map_object_t type
, void *object
)
525 struct access_list
*alist
;
526 struct bgp_path_info
*path
;
528 struct prefix_ipv4 p
;
530 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
534 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
538 p
.prefix
= peer
->su
.sin
.sin_addr
;
539 p
.prefixlen
= IPV4_MAX_BITLEN
;
541 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
545 return (access_list_apply(alist
, &p
) == FILTER_DENY
552 /* Route map `ip route-source' match statement. `arg' is
554 static void *route_match_ip_route_source_compile(const char *arg
)
556 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
559 /* Free route map's compiled `ip address' value. */
560 static void route_match_ip_route_source_free(void *rule
)
562 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
565 /* Route map commands for ip route-source matching. */
566 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
567 "ip route-source", route_match_ip_route_source
,
568 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
570 static enum route_map_cmd_result_t
571 route_match_prefix_list_flowspec(afi_t afi
, struct prefix_list
*plist
,
572 const struct prefix
*p
)
575 struct bgp_pbr_entry_main api
;
577 memset(&api
, 0, sizeof(api
));
579 /* extract match from flowspec entries */
580 ret
= bgp_flowspec_match_rules_fill(
581 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
582 p
->u
.prefix_flowspec
.prefixlen
, &api
);
585 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
586 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
587 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
589 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
592 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
593 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
594 if (family2afi((&api
.src_prefix
)->family
) != afi
)
596 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
603 static enum route_map_cmd_result_t
604 route_match_address_prefix_list(void *rule
, afi_t afi
,
605 const struct prefix
*prefix
,
606 route_map_object_t type
, void *object
)
608 struct prefix_list
*plist
;
610 if (type
!= RMAP_BGP
)
613 plist
= prefix_list_lookup(afi
, (char *)rule
);
617 if (prefix
->family
== AF_FLOWSPEC
)
618 return route_match_prefix_list_flowspec(afi
, plist
,
620 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
624 static enum route_map_cmd_result_t
625 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
626 route_map_object_t type
, void *object
)
628 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, type
,
632 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
634 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
637 static void route_match_ip_address_prefix_list_free(void *rule
)
639 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
642 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
643 "ip address prefix-list", route_match_ip_address_prefix_list
,
644 route_match_ip_address_prefix_list_compile
,
645 route_match_ip_address_prefix_list_free
};
647 /* `match ip next-hop prefix-list PREFIX_LIST' */
649 static enum route_map_cmd_result_t
650 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
651 route_map_object_t type
, void *object
)
653 struct prefix_list
*plist
;
654 struct bgp_path_info
*path
;
655 struct prefix_ipv4 p
;
657 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
660 p
.prefix
= path
->attr
->nexthop
;
661 p
.prefixlen
= IPV4_MAX_BITLEN
;
663 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
667 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
674 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
676 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
679 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
681 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
684 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
685 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
686 route_match_ip_next_hop_prefix_list_compile
,
687 route_match_ip_next_hop_prefix_list_free
};
689 /* `match ip next-hop type <blackhole>' */
691 static enum route_map_cmd_result_t
692 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
693 route_map_object_t type
, void *object
)
695 struct bgp_path_info
*path
;
697 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
698 path
= (struct bgp_path_info
*)object
;
699 if (!path
|| !path
->attr
)
702 /* If nexthop interface's index can't be resolved and nexthop is
703 set to any address then mark it as type `blackhole`.
704 This logic works for matching kernel/static routes like:
705 `ip route add blackhole 10.0.0.1`. */
706 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
707 && !path
->attr
->nh_ifindex
)
713 static void *route_match_ip_next_hop_type_compile(const char *arg
)
715 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
718 static void route_match_ip_next_hop_type_free(void *rule
)
720 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
723 static struct route_map_rule_cmd route_match_ip_next_hop_type_cmd
= {
724 "ip next-hop type", route_match_ip_next_hop_type
,
725 route_match_ip_next_hop_type_compile
,
726 route_match_ip_next_hop_type_free
};
728 /* `match ip route-source prefix-list PREFIX_LIST' */
730 static enum route_map_cmd_result_t
731 route_match_ip_route_source_prefix_list(void *rule
,
732 const struct prefix
*prefix
,
733 route_map_object_t type
, void *object
)
735 struct prefix_list
*plist
;
736 struct bgp_path_info
*path
;
738 struct prefix_ipv4 p
;
740 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
744 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
748 p
.prefix
= peer
->su
.sin
.sin_addr
;
749 p
.prefixlen
= IPV4_MAX_BITLEN
;
751 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
755 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
762 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
764 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
767 static void route_match_ip_route_source_prefix_list_free(void *rule
)
769 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
772 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
773 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
774 route_match_ip_route_source_prefix_list_compile
,
775 route_match_ip_route_source_prefix_list_free
};
777 /* `match evpn default-route' */
779 /* Match function should return 1 if match is success else 0 */
780 static enum route_map_cmd_result_t
781 route_match_evpn_default_route(void *rule
, const struct prefix
*p
,
782 route_map_object_t type
, void *object
)
784 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
790 /* Route map commands for default-route matching. */
791 struct route_map_rule_cmd route_match_evpn_default_route_cmd
= {
792 "evpn default-route", route_match_evpn_default_route
, NULL
, NULL
};
794 /* `match mac address MAC_ACCESS_LIST' */
796 /* Match function should return 1 if match is success else return
798 static enum route_map_cmd_result_t
799 route_match_mac_address(void *rule
, const struct prefix
*prefix
,
800 route_map_object_t type
, void *object
)
802 struct access_list
*alist
;
805 if (type
== RMAP_BGP
) {
806 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
810 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
813 p
.family
= AF_ETHERNET
;
814 p
.prefixlen
= ETH_ALEN
* 8;
815 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
817 return (access_list_apply(alist
, &p
) == FILTER_DENY
825 /* Route map `mac address' match statement. `arg' should be
827 static void *route_match_mac_address_compile(const char *arg
)
829 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
832 /* Free route map's compiled `ip address' value. */
833 static void route_match_mac_address_free(void *rule
)
835 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
838 /* Route map commands for mac address matching. */
839 struct route_map_rule_cmd route_match_mac_address_cmd
= {
840 "mac address", route_match_mac_address
, route_match_mac_address_compile
,
841 route_match_mac_address_free
};
844 * Match function returns:
845 * ...RMAP_MATCH if match is found.
846 * ...RMAP_NOMATCH if match is not found.
847 * ...RMAP_NOOP to ignore this match check.
849 static enum route_map_cmd_result_t
850 route_match_vni(void *rule
, const struct prefix
*prefix
,
851 route_map_object_t type
, void *object
)
854 unsigned int label_cnt
= 0;
855 struct bgp_path_info
*path
= NULL
;
856 struct prefix_evpn
*evp
= (struct prefix_evpn
*) prefix
;
858 if (type
== RMAP_BGP
) {
859 vni
= *((vni_t
*)rule
);
860 path
= (struct bgp_path_info
*)object
;
863 * This rmap filter is valid for vxlan tunnel type only.
864 * For any other tunnel type, return noop to ignore
867 if (path
->attr
&& path
->attr
->encap_tunneltype
!=
868 BGP_ENCAP_TYPE_VXLAN
)
872 * Apply filter to type 1, 2, 5 routes only.
873 * Other route types do not have vni label.
875 if (evp
&& (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
&&
876 evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
&&
877 evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
))
880 if (path
->extra
== NULL
)
883 for ( ; label_cnt
< BGP_MAX_LABELS
&&
884 label_cnt
< path
->extra
->num_labels
; label_cnt
++) {
885 if (vni
== label2vni(&path
->extra
->label
[label_cnt
]))
893 /* Route map `vni' match statement. */
894 static void *route_match_vni_compile(const char *arg
)
899 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
901 *vni
= strtoul(arg
, &end
, 10);
903 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
910 /* Free route map's compiled `vni' value. */
911 static void route_match_vni_free(void *rule
)
913 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
916 /* Route map commands for vni matching. */
917 struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
918 "evpn vni", route_match_vni
, route_match_vni_compile
,
919 route_match_vni_free
};
921 /* `match evpn route-type' */
923 /* Match function should return 1 if match is success else return
925 static enum route_map_cmd_result_t
926 route_match_evpn_route_type(void *rule
, const struct prefix
*pfx
,
927 route_map_object_t type
, void *object
)
929 uint8_t route_type
= 0;
931 if (type
== RMAP_BGP
) {
932 route_type
= *((uint8_t *)rule
);
934 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
941 /* Route map `route-type' match statement. */
942 static void *route_match_evpn_route_type_compile(const char *arg
)
944 uint8_t *route_type
= NULL
;
946 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
948 if (strncmp(arg
, "ma", 2) == 0)
949 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
950 else if (strncmp(arg
, "mu", 2) == 0)
951 *route_type
= BGP_EVPN_IMET_ROUTE
;
953 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
958 /* Free route map's compiled `route-type' value. */
959 static void route_match_evpn_route_type_free(void *rule
)
961 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
964 /* Route map commands for evpn route-type matching. */
965 struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
966 "evpn route-type", route_match_evpn_route_type
,
967 route_match_evpn_route_type_compile
, route_match_evpn_route_type_free
};
969 /* Route map commands for VRF route leak with source vrf matching */
970 static enum route_map_cmd_result_t
971 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
972 route_map_object_t type
, void *object
)
974 struct bgp_path_info
*path
;
977 if (type
== RMAP_BGP
) {
979 path
= (struct bgp_path_info
*)object
;
981 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
984 if (path
->extra
== NULL
)
987 if (strncmp(vrf_name
, vrf_id_to_name(
988 path
->extra
->bgp_orig
->vrf_id
), VRF_NAMSIZ
)
996 static void *route_match_vrl_source_vrf_compile(const char *arg
)
998 uint8_t *vrf_name
= NULL
;
1000 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1005 /* Free route map's compiled `route-type' value. */
1006 static void route_match_vrl_source_vrf_free(void *rule
)
1008 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1011 struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
1012 "source-vrf", route_match_vrl_source_vrf
,
1013 route_match_vrl_source_vrf_compile
,
1014 route_match_vrl_source_vrf_free
};
1016 /* `match local-preference LOCAL-PREF' */
1018 /* Match function return 1 if match is success else return zero. */
1019 static enum route_map_cmd_result_t
1020 route_match_local_pref(void *rule
, const struct prefix
*prefix
,
1021 route_map_object_t type
, void *object
)
1023 uint32_t *local_pref
;
1024 struct bgp_path_info
*path
;
1026 if (type
== RMAP_BGP
) {
1030 if (path
->attr
->local_pref
== *local_pref
)
1033 return RMAP_NOMATCH
;
1035 return RMAP_NOMATCH
;
1038 /* Route map `match local-preference' match statement.
1039 `arg' is local-pref value */
1040 static void *route_match_local_pref_compile(const char *arg
)
1042 uint32_t *local_pref
;
1043 char *endptr
= NULL
;
1044 unsigned long tmpval
;
1046 /* Locpref value shoud be integer. */
1047 if (!all_digit(arg
))
1051 tmpval
= strtoul(arg
, &endptr
, 10);
1052 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1055 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1057 *local_pref
= tmpval
;
1061 /* Free route map's compiled `match local-preference' value. */
1062 static void route_match_local_pref_free(void *rule
)
1064 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1067 /* Route map commands for metric matching. */
1068 struct route_map_rule_cmd route_match_local_pref_cmd
= {
1069 "local-preference", route_match_local_pref
,
1070 route_match_local_pref_compile
, route_match_local_pref_free
};
1072 /* `match metric METRIC' */
1074 /* Match function return 1 if match is success else return zero. */
1075 static enum route_map_cmd_result_t
1076 route_match_metric(void *rule
, const struct prefix
*prefix
,
1077 route_map_object_t type
, void *object
)
1079 struct rmap_value
*rv
;
1080 struct bgp_path_info
*path
;
1082 if (type
== RMAP_BGP
) {
1085 return route_value_match(rv
, path
->attr
->med
);
1087 return RMAP_NOMATCH
;
1090 /* Route map commands for metric matching. */
1091 struct route_map_rule_cmd route_match_metric_cmd
= {
1092 "metric", route_match_metric
, route_value_compile
, route_value_free
,
1095 /* `match as-path ASPATH' */
1097 /* Match function for as-path match. I assume given object is */
1098 static enum route_map_cmd_result_t
1099 route_match_aspath(void *rule
, const struct prefix
*prefix
,
1100 route_map_object_t type
, void *object
)
1103 struct as_list
*as_list
;
1104 struct bgp_path_info
*path
;
1106 if (type
== RMAP_BGP
) {
1107 as_list
= as_list_lookup((char *)rule
);
1108 if (as_list
== NULL
)
1109 return RMAP_NOMATCH
;
1113 /* Perform match. */
1114 return ((as_list_apply(as_list
, path
->attr
->aspath
)
1119 return RMAP_NOMATCH
;
1122 /* Compile function for as-path match. */
1123 static void *route_match_aspath_compile(const char *arg
)
1125 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1128 /* Compile function for as-path match. */
1129 static void route_match_aspath_free(void *rule
)
1131 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1134 /* Route map commands for aspath matching. */
1135 struct route_map_rule_cmd route_match_aspath_cmd
= {
1136 "as-path", route_match_aspath
, route_match_aspath_compile
,
1137 route_match_aspath_free
};
1139 /* `match community COMMUNIY' */
1140 struct rmap_community
{
1146 /* Match function for community match. */
1147 static enum route_map_cmd_result_t
1148 route_match_community(void *rule
, const struct prefix
*prefix
,
1149 route_map_object_t type
, void *object
)
1151 struct community_list
*list
;
1152 struct bgp_path_info
*path
;
1153 struct rmap_community
*rcom
= rule
;
1155 if (type
== RMAP_BGP
) {
1159 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1161 COMMUNITY_LIST_MASTER
);
1163 return RMAP_NOMATCH
;
1166 if (community_list_exact_match(path
->attr
->community
,
1170 if (community_list_match(path
->attr
->community
, list
))
1174 return RMAP_NOMATCH
;
1177 /* Compile function for community match. */
1178 static void *route_match_community_compile(const char *arg
)
1180 struct rmap_community
*rcom
;
1184 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1186 p
= strchr(arg
, ' ');
1189 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1190 memcpy(rcom
->name
, arg
, len
);
1193 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1197 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1201 /* Compile function for community match. */
1202 static void route_match_community_free(void *rule
)
1204 struct rmap_community
*rcom
= rule
;
1206 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1207 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1210 /* Route map commands for community matching. */
1211 struct route_map_rule_cmd route_match_community_cmd
= {
1212 "community", route_match_community
, route_match_community_compile
,
1213 route_match_community_free
};
1215 /* Match function for lcommunity match. */
1216 static enum route_map_cmd_result_t
1217 route_match_lcommunity(void *rule
, const struct prefix
*prefix
,
1218 route_map_object_t type
, void *object
)
1220 struct community_list
*list
;
1221 struct bgp_path_info
*path
;
1222 struct rmap_community
*rcom
= rule
;
1224 if (type
== RMAP_BGP
) {
1227 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1229 LARGE_COMMUNITY_LIST_MASTER
);
1231 return RMAP_NOMATCH
;
1234 if (lcommunity_list_exact_match(
1235 path
->attr
->lcommunity
,
1239 if (lcommunity_list_match(
1240 path
->attr
->lcommunity
,
1245 return RMAP_NOMATCH
;
1248 /* Compile function for community match. */
1249 static void *route_match_lcommunity_compile(const char *arg
)
1251 struct rmap_community
*rcom
;
1255 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1257 p
= strchr(arg
, ' ');
1260 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1261 memcpy(rcom
->name
, arg
, len
);
1264 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1268 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1272 /* Compile function for community match. */
1273 static void route_match_lcommunity_free(void *rule
)
1275 struct rmap_community
*rcom
= rule
;
1277 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1278 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1281 /* Route map commands for community matching. */
1282 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1283 "large-community", route_match_lcommunity
,
1284 route_match_lcommunity_compile
, route_match_lcommunity_free
};
1287 /* Match function for extcommunity match. */
1288 static enum route_map_cmd_result_t
1289 route_match_ecommunity(void *rule
, const struct prefix
*prefix
,
1290 route_map_object_t type
, void *object
)
1292 struct community_list
*list
;
1293 struct bgp_path_info
*path
;
1294 struct rmap_community
*rcom
= rule
;
1296 if (type
== RMAP_BGP
) {
1299 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1301 EXTCOMMUNITY_LIST_MASTER
);
1303 return RMAP_NOMATCH
;
1305 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1308 return RMAP_NOMATCH
;
1311 /* Compile function for extcommunity match. */
1312 static void *route_match_ecommunity_compile(const char *arg
)
1314 struct rmap_community
*rcom
;
1316 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1317 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1318 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1323 /* Compile function for extcommunity match. */
1324 static void route_match_ecommunity_free(void *rule
)
1326 struct rmap_community
*rcom
= rule
;
1328 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1329 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1332 /* Route map commands for community matching. */
1333 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1334 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1335 route_match_ecommunity_free
};
1337 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1338 and `address-family vpnv4'. */
1340 /* `match origin' */
1341 static enum route_map_cmd_result_t
1342 route_match_origin(void *rule
, const struct prefix
*prefix
,
1343 route_map_object_t type
, void *object
)
1346 struct bgp_path_info
*path
;
1348 if (type
== RMAP_BGP
) {
1352 if (path
->attr
->origin
== *origin
)
1356 return RMAP_NOMATCH
;
1359 static void *route_match_origin_compile(const char *arg
)
1363 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1365 if (strcmp(arg
, "igp") == 0)
1367 else if (strcmp(arg
, "egp") == 0)
1375 /* Free route map's compiled `ip address' value. */
1376 static void route_match_origin_free(void *rule
)
1378 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1381 /* Route map commands for origin matching. */
1382 struct route_map_rule_cmd route_match_origin_cmd
= {
1383 "origin", route_match_origin
, route_match_origin_compile
,
1384 route_match_origin_free
};
1386 /* match probability { */
1388 static enum route_map_cmd_result_t
1389 route_match_probability(void *rule
, const struct prefix
*prefix
,
1390 route_map_object_t type
, void *object
)
1394 switch (*(long *)rule
) {
1400 if (r
< *(long *)rule
) {
1405 return RMAP_NOMATCH
;
1408 static void *route_match_probability_compile(const char *arg
)
1414 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1424 *lobule
= RAND_MAX
/ 100 * perc
;
1430 static void route_match_probability_free(void *rule
)
1432 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1435 struct route_map_rule_cmd route_match_probability_cmd
= {
1436 "probability", route_match_probability
, route_match_probability_compile
,
1437 route_match_probability_free
};
1439 /* `match interface IFNAME' */
1440 /* Match function should return 1 if match is success else return
1442 static enum route_map_cmd_result_t
1443 route_match_interface(void *rule
, const struct prefix
*prefix
,
1444 route_map_object_t type
, void *object
)
1446 struct interface
*ifp
;
1447 struct bgp_path_info
*path
;
1449 if (type
== RMAP_BGP
) {
1452 if (!path
|| !path
->attr
)
1453 return RMAP_NOMATCH
;
1455 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1457 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1458 return RMAP_NOMATCH
;
1462 return RMAP_NOMATCH
;
1465 /* Route map `interface' match statement. `arg' should be
1467 static void *route_match_interface_compile(const char *arg
)
1469 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1472 /* Free route map's compiled `interface' value. */
1473 static void route_match_interface_free(void *rule
)
1475 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1478 /* Route map commands for ip address matching. */
1479 struct route_map_rule_cmd route_match_interface_cmd
= {
1480 "interface", route_match_interface
, route_match_interface_compile
,
1481 route_match_interface_free
};
1485 /* `set ip next-hop IP_ADDRESS' */
1487 /* Match function return 1 if match is success else return zero. */
1488 static enum route_map_cmd_result_t
1489 route_match_tag(void *rule
, const struct prefix
*prefix
,
1490 route_map_object_t type
, void *object
)
1493 struct bgp_path_info
*path
;
1495 if (type
== RMAP_BGP
) {
1499 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1502 return RMAP_NOMATCH
;
1506 /* Route map commands for tag matching. */
1507 static struct route_map_rule_cmd route_match_tag_cmd
= {
1508 "tag", route_match_tag
, route_map_rule_tag_compile
,
1509 route_map_rule_tag_free
,
1513 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1514 struct rmap_ip_nexthop_set
{
1515 struct in_addr
*address
;
1520 static enum route_map_cmd_result_t
1521 route_set_ip_nexthop(void *rule
, const struct prefix
*prefix
,
1522 route_map_object_t type
, void *object
)
1524 struct rmap_ip_nexthop_set
*rins
= rule
;
1525 struct bgp_path_info
*path
;
1528 if (type
!= RMAP_BGP
)
1531 if (prefix
->family
== AF_INET6
)
1537 if (rins
->unchanged
) {
1538 SET_FLAG(path
->attr
->rmap_change_flags
,
1539 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1540 } else if (rins
->peer_address
) {
1541 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1542 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1544 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1545 path
->attr
->nexthop
.s_addr
=
1546 sockunion2ip(peer
->su_remote
);
1547 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1548 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1549 /* The next hop value will be set as part of
1550 * packet rewrite. Set the flags here to indicate
1551 * that rewrite needs to be done.
1552 * Also, clear the value.
1554 SET_FLAG(path
->attr
->rmap_change_flags
,
1555 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1556 path
->attr
->nexthop
.s_addr
= 0;
1559 /* Set next hop value. */
1560 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1561 path
->attr
->nexthop
= *rins
->address
;
1562 SET_FLAG(path
->attr
->rmap_change_flags
,
1563 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1564 /* case for MP-BGP : MPLS VPN */
1565 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1566 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1572 /* Route map `ip nexthop' compile function. Given string is converted
1573 to struct in_addr structure. */
1574 static void *route_set_ip_nexthop_compile(const char *arg
)
1576 struct rmap_ip_nexthop_set
*rins
;
1577 struct in_addr
*address
= NULL
;
1578 int peer_address
= 0;
1582 if (strcmp(arg
, "peer-address") == 0)
1584 else if (strcmp(arg
, "unchanged") == 0)
1587 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1588 sizeof(struct in_addr
));
1589 ret
= inet_aton(arg
, address
);
1592 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1597 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1598 sizeof(struct rmap_ip_nexthop_set
));
1600 rins
->address
= address
;
1601 rins
->peer_address
= peer_address
;
1602 rins
->unchanged
= unchanged
;
1607 /* Free route map's compiled `ip nexthop' value. */
1608 static void route_set_ip_nexthop_free(void *rule
)
1610 struct rmap_ip_nexthop_set
*rins
= rule
;
1612 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1614 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1617 /* Route map commands for ip nexthop set. */
1618 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1619 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1620 route_set_ip_nexthop_free
};
1622 /* `set local-preference LOCAL_PREF' */
1624 /* Set local preference. */
1625 static enum route_map_cmd_result_t
1626 route_set_local_pref(void *rule
, const struct prefix
*prefix
,
1627 route_map_object_t type
, void *object
)
1629 struct rmap_value
*rv
;
1630 struct bgp_path_info
*path
;
1631 uint32_t locpref
= 0;
1633 if (type
== RMAP_BGP
) {
1634 /* Fetch routemap's rule information. */
1638 /* Set local preference value. */
1639 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1640 locpref
= path
->attr
->local_pref
;
1642 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1643 path
->attr
->local_pref
=
1644 route_value_adjust(rv
, locpref
, path
->peer
);
1650 /* Set local preference rule structure. */
1651 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1652 "local-preference", route_set_local_pref
, route_value_compile
,
1656 /* `set weight WEIGHT' */
1659 static enum route_map_cmd_result_t
1660 route_set_weight(void *rule
, const struct prefix
*prefix
,
1661 route_map_object_t type
, void *object
)
1663 struct rmap_value
*rv
;
1664 struct bgp_path_info
*path
;
1666 if (type
== RMAP_BGP
) {
1667 /* Fetch routemap's rule information. */
1671 /* Set weight value. */
1672 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1678 /* Set local preference rule structure. */
1679 struct route_map_rule_cmd route_set_weight_cmd
= {
1680 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1683 /* `set metric METRIC' */
1685 /* Set metric to attribute. */
1686 static enum route_map_cmd_result_t
1687 route_set_metric(void *rule
, const struct prefix
*prefix
,
1688 route_map_object_t type
, void *object
)
1690 struct rmap_value
*rv
;
1691 struct bgp_path_info
*path
;
1694 if (type
== RMAP_BGP
) {
1695 /* Fetch routemap's rule information. */
1699 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1700 med
= path
->attr
->med
;
1702 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1703 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1708 /* Set metric rule structure. */
1709 struct route_map_rule_cmd route_set_metric_cmd
= {
1710 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1713 /* `set as-path prepend ASPATH' */
1715 /* For AS path prepend mechanism. */
1716 static enum route_map_cmd_result_t
1717 route_set_aspath_prepend(void *rule
, const struct prefix
*prefix
,
1718 route_map_object_t type
, void *object
)
1720 struct aspath
*aspath
;
1722 struct bgp_path_info
*path
;
1724 if (type
== RMAP_BGP
) {
1727 if (path
->attr
->aspath
->refcnt
)
1728 new = aspath_dup(path
->attr
->aspath
);
1730 new = path
->attr
->aspath
;
1732 if ((uintptr_t)rule
> 10) {
1734 aspath_prepend(aspath
, new);
1736 as_t as
= aspath_leftmost(new);
1738 as
= path
->peer
->as
;
1739 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1742 path
->attr
->aspath
= new;
1748 static void *route_set_aspath_prepend_compile(const char *arg
)
1752 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1753 return (void *)(uintptr_t)num
;
1755 return route_aspath_compile(arg
);
1758 static void route_set_aspath_prepend_free(void *rule
)
1760 if ((uintptr_t)rule
> 10)
1761 route_aspath_free(rule
);
1765 /* Set as-path prepend rule structure. */
1766 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1767 "as-path prepend", route_set_aspath_prepend
,
1768 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1771 /* `set as-path exclude ASn' */
1773 /* For ASN exclude mechanism.
1774 * Iterate over ASns requested and filter them from the given AS_PATH one by
1776 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1778 static enum route_map_cmd_result_t
1779 route_set_aspath_exclude(void *rule
, const struct prefix
*dummy
,
1780 route_map_object_t type
, void *object
)
1782 struct aspath
*new_path
, *exclude_path
;
1783 struct bgp_path_info
*path
;
1785 if (type
== RMAP_BGP
) {
1786 exclude_path
= rule
;
1788 if (path
->attr
->aspath
->refcnt
)
1789 new_path
= aspath_dup(path
->attr
->aspath
);
1791 new_path
= path
->attr
->aspath
;
1792 path
->attr
->aspath
=
1793 aspath_filter_exclude(new_path
, exclude_path
);
1798 /* Set ASn exlude rule structure. */
1799 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1800 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1804 /* `set community COMMUNITY' */
1805 struct rmap_com_set
{
1806 struct community
*com
;
1811 /* For community set mechanism. */
1812 static enum route_map_cmd_result_t
1813 route_set_community(void *rule
, const struct prefix
*prefix
,
1814 route_map_object_t type
, void *object
)
1816 struct rmap_com_set
*rcs
;
1817 struct bgp_path_info
*path
;
1819 struct community
*new = NULL
;
1820 struct community
*old
;
1821 struct community
*merge
;
1823 if (type
== RMAP_BGP
) {
1827 old
= attr
->community
;
1831 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1832 attr
->community
= NULL
;
1833 /* See the longer comment down below. */
1834 if (old
&& old
->refcnt
== 0)
1835 community_free(&old
);
1839 /* "additive" case. */
1840 if (rcs
->additive
&& old
) {
1841 merge
= community_merge(community_dup(old
), rcs
->com
);
1843 new = community_uniq_sort(merge
);
1844 community_free(&merge
);
1846 new = community_dup(rcs
->com
);
1848 /* HACK: if the old community is not intern'd,
1849 * we should free it here, or all reference to it may be
1851 * Really need to cleanup attribute caching sometime.
1853 if (old
&& old
->refcnt
== 0)
1854 community_free(&old
);
1856 /* will be interned by caller if required */
1857 attr
->community
= new;
1859 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1865 /* Compile function for set community. */
1866 static void *route_set_community_compile(const char *arg
)
1868 struct rmap_com_set
*rcs
;
1869 struct community
*com
= NULL
;
1874 if (strcmp(arg
, "none") == 0)
1877 sp
= strstr(arg
, "additive");
1879 if (sp
&& sp
> arg
) {
1880 /* "additive" keyword is included. */
1885 com
= community_str2com(arg
);
1894 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1896 rcs
->additive
= additive
;
1902 /* Free function for set community. */
1903 static void route_set_community_free(void *rule
)
1905 struct rmap_com_set
*rcs
= rule
;
1908 community_free(&rcs
->com
);
1909 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1912 /* Set community rule structure. */
1913 struct route_map_rule_cmd route_set_community_cmd
= {
1914 "community", route_set_community
, route_set_community_compile
,
1915 route_set_community_free
,
1918 /* `set community COMMUNITY' */
1919 struct rmap_lcom_set
{
1920 struct lcommunity
*lcom
;
1926 /* For lcommunity set mechanism. */
1927 static enum route_map_cmd_result_t
1928 route_set_lcommunity(void *rule
, const struct prefix
*prefix
,
1929 route_map_object_t type
, void *object
)
1931 struct rmap_lcom_set
*rcs
;
1932 struct bgp_path_info
*path
;
1934 struct lcommunity
*new = NULL
;
1935 struct lcommunity
*old
;
1936 struct lcommunity
*merge
;
1938 if (type
== RMAP_BGP
) {
1942 old
= attr
->lcommunity
;
1947 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
1948 attr
->lcommunity
= NULL
;
1950 /* See the longer comment down below. */
1951 if (old
&& old
->refcnt
== 0)
1952 lcommunity_free(&old
);
1956 if (rcs
->additive
&& old
) {
1957 merge
= lcommunity_merge(lcommunity_dup(old
),
1960 new = lcommunity_uniq_sort(merge
);
1961 lcommunity_free(&merge
);
1963 new = lcommunity_dup(rcs
->lcom
);
1965 /* HACK: if the old large-community is not intern'd,
1966 * we should free it here, or all reference to it may be
1968 * Really need to cleanup attribute caching sometime.
1970 if (old
&& old
->refcnt
== 0)
1971 lcommunity_free(&old
);
1973 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1974 attr
->lcommunity
= new;
1976 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
1982 /* Compile function for set community. */
1983 static void *route_set_lcommunity_compile(const char *arg
)
1985 struct rmap_lcom_set
*rcs
;
1986 struct lcommunity
*lcom
= NULL
;
1991 if (strcmp(arg
, "none") == 0)
1994 sp
= strstr(arg
, "additive");
1996 if (sp
&& sp
> arg
) {
1997 /* "additive" keyworkd is included. */
2002 lcom
= lcommunity_str2com(arg
);
2011 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
2013 rcs
->additive
= additive
;
2019 /* Free function for set lcommunity. */
2020 static void route_set_lcommunity_free(void *rule
)
2022 struct rmap_lcom_set
*rcs
= rule
;
2025 lcommunity_free(&rcs
->lcom
);
2027 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
2030 /* Set community rule structure. */
2031 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
2032 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
2033 route_set_lcommunity_free
,
2036 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
2038 /* For large community set mechanism. */
2039 static enum route_map_cmd_result_t
2040 route_set_lcommunity_delete(void *rule
, const struct prefix
*pfx
,
2041 route_map_object_t type
, void *object
)
2043 struct community_list
*list
;
2044 struct lcommunity
*merge
;
2045 struct lcommunity
*new;
2046 struct lcommunity
*old
;
2047 struct bgp_path_info
*path
;
2048 struct rmap_community
*rcom
= rule
;
2050 if (type
== RMAP_BGP
) {
2055 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2057 LARGE_COMMUNITY_LIST_MASTER
);
2058 old
= path
->attr
->lcommunity
;
2061 merge
= lcommunity_list_match_delete(
2062 lcommunity_dup(old
), list
);
2063 new = lcommunity_uniq_sort(merge
);
2064 lcommunity_free(&merge
);
2066 /* HACK: if the old community is not intern'd,
2067 * we should free it here, or all reference to it may be
2069 * Really need to cleanup attribute caching sometime.
2071 if (old
->refcnt
== 0)
2072 lcommunity_free(&old
);
2074 if (new->size
== 0) {
2075 path
->attr
->lcommunity
= NULL
;
2076 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2077 BGP_ATTR_LARGE_COMMUNITIES
);
2078 lcommunity_free(&new);
2080 path
->attr
->lcommunity
= new;
2081 path
->attr
->flag
|= ATTR_FLAG_BIT(
2082 BGP_ATTR_LARGE_COMMUNITIES
);
2090 /* Compile function for set lcommunity. */
2091 static void *route_set_lcommunity_delete_compile(const char *arg
)
2093 struct rmap_community
*rcom
;
2097 frrstr_split(arg
, " ", &splits
, &num
);
2099 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2100 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2101 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2103 for (int i
= 0; i
< num
; i
++)
2104 XFREE(MTYPE_TMP
, splits
[i
]);
2105 XFREE(MTYPE_TMP
, splits
);
2110 /* Free function for set lcommunity. */
2111 static void route_set_lcommunity_delete_free(void *rule
)
2113 struct rmap_community
*rcom
= rule
;
2115 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2116 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2119 /* Set lcommunity rule structure. */
2120 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2121 "large-comm-list", route_set_lcommunity_delete
,
2122 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2126 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2128 /* For community set mechanism. */
2129 static enum route_map_cmd_result_t
2130 route_set_community_delete(void *rule
, const struct prefix
*prefix
,
2131 route_map_object_t type
, void *object
)
2133 struct community_list
*list
;
2134 struct community
*merge
;
2135 struct community
*new;
2136 struct community
*old
;
2137 struct bgp_path_info
*path
;
2138 struct rmap_community
*rcom
= rule
;
2140 if (type
== RMAP_BGP
) {
2145 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2147 COMMUNITY_LIST_MASTER
);
2148 old
= path
->attr
->community
;
2151 merge
= community_list_match_delete(community_dup(old
),
2153 new = community_uniq_sort(merge
);
2154 community_free(&merge
);
2156 /* HACK: if the old community is not intern'd,
2157 * we should free it here, or all reference to it may be
2159 * Really need to cleanup attribute caching sometime.
2161 if (old
->refcnt
== 0)
2162 community_free(&old
);
2164 if (new->size
== 0) {
2165 path
->attr
->community
= NULL
;
2167 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2168 community_free(&new);
2170 path
->attr
->community
= new;
2172 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2180 /* Compile function for set community. */
2181 static void *route_set_community_delete_compile(const char *arg
)
2183 struct rmap_community
*rcom
;
2187 frrstr_split(arg
, " ", &splits
, &num
);
2189 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2190 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2191 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2193 for (int i
= 0; i
< num
; i
++)
2194 XFREE(MTYPE_TMP
, splits
[i
]);
2195 XFREE(MTYPE_TMP
, splits
);
2200 /* Free function for set community. */
2201 static void route_set_community_delete_free(void *rule
)
2203 struct rmap_community
*rcom
= rule
;
2205 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2206 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2209 /* Set community rule structure. */
2210 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2211 "comm-list", route_set_community_delete
,
2212 route_set_community_delete_compile
, route_set_community_delete_free
,
2215 /* `set extcommunity rt COMMUNITY' */
2217 /* For community set mechanism. Used by _rt and _soo. */
2218 static enum route_map_cmd_result_t
2219 route_set_ecommunity(void *rule
, const struct prefix
*prefix
,
2220 route_map_object_t type
, void *object
)
2222 struct ecommunity
*ecom
;
2223 struct ecommunity
*new_ecom
;
2224 struct ecommunity
*old_ecom
;
2225 struct bgp_path_info
*path
;
2227 if (type
== RMAP_BGP
) {
2234 /* We assume additive for Extended Community. */
2235 old_ecom
= path
->attr
->ecommunity
;
2238 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2241 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2242 * bgp_update_receive()
2243 * ->refcnt = 0 => set by a previous route-map
2245 if (!old_ecom
->refcnt
)
2246 ecommunity_free(&old_ecom
);
2248 new_ecom
= ecommunity_dup(ecom
);
2250 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2251 path
->attr
->ecommunity
= new_ecom
;
2253 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2258 /* Compile function for set community. */
2259 static void *route_set_ecommunity_rt_compile(const char *arg
)
2261 struct ecommunity
*ecom
;
2263 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2266 return ecommunity_intern(ecom
);
2269 /* Free function for set community. Used by _rt and _soo */
2270 static void route_set_ecommunity_free(void *rule
)
2272 struct ecommunity
*ecom
= rule
;
2273 ecommunity_unintern(&ecom
);
2276 /* Set community rule structure. */
2277 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2278 "extcommunity rt", route_set_ecommunity
,
2279 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2282 /* `set extcommunity soo COMMUNITY' */
2284 /* Compile function for set community. */
2285 static void *route_set_ecommunity_soo_compile(const char *arg
)
2287 struct ecommunity
*ecom
;
2289 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2293 return ecommunity_intern(ecom
);
2296 /* Set community rule structure. */
2297 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2298 "extcommunity soo", route_set_ecommunity
,
2299 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2302 /* `set origin ORIGIN' */
2304 /* For origin set. */
2305 static enum route_map_cmd_result_t
2306 route_set_origin(void *rule
, const struct prefix
*prefix
,
2307 route_map_object_t type
, void *object
)
2310 struct bgp_path_info
*path
;
2312 if (type
== RMAP_BGP
) {
2316 path
->attr
->origin
= *origin
;
2322 /* Compile function for origin set. */
2323 static void *route_set_origin_compile(const char *arg
)
2327 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2329 if (strcmp(arg
, "igp") == 0)
2331 else if (strcmp(arg
, "egp") == 0)
2339 /* Compile function for origin set. */
2340 static void route_set_origin_free(void *rule
)
2342 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2345 /* Set origin rule structure. */
2346 struct route_map_rule_cmd route_set_origin_cmd
= {
2347 "origin", route_set_origin
, route_set_origin_compile
,
2348 route_set_origin_free
,
2351 /* `set atomic-aggregate' */
2353 /* For atomic aggregate set. */
2354 static enum route_map_cmd_result_t
2355 route_set_atomic_aggregate(void *rule
, const struct prefix
*pfx
,
2356 route_map_object_t type
, void *object
)
2358 struct bgp_path_info
*path
;
2360 if (type
== RMAP_BGP
) {
2362 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2368 /* Compile function for atomic aggregate. */
2369 static void *route_set_atomic_aggregate_compile(const char *arg
)
2374 /* Compile function for atomic aggregate. */
2375 static void route_set_atomic_aggregate_free(void *rule
)
2380 /* Set atomic aggregate rule structure. */
2381 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2382 "atomic-aggregate", route_set_atomic_aggregate
,
2383 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2386 /* `set aggregator as AS A.B.C.D' */
2389 struct in_addr address
;
2392 static enum route_map_cmd_result_t
2393 route_set_aggregator_as(void *rule
, const struct prefix
*prefix
,
2394 route_map_object_t type
, void *object
)
2396 struct bgp_path_info
*path
;
2397 struct aggregator
*aggregator
;
2399 if (type
== RMAP_BGP
) {
2403 path
->attr
->aggregator_as
= aggregator
->as
;
2404 path
->attr
->aggregator_addr
= aggregator
->address
;
2405 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2411 static void *route_set_aggregator_as_compile(const char *arg
)
2413 struct aggregator
*aggregator
;
2419 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2420 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2421 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2425 aggregator
->as
= strtoul(as
, NULL
, 10);
2426 ret
= inet_aton(address
, &aggregator
->address
);
2428 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2434 static void route_set_aggregator_as_free(void *rule
)
2436 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2439 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2440 "aggregator as", route_set_aggregator_as
,
2441 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2444 /* Set tag to object. object must be pointer to struct bgp_path_info */
2445 static enum route_map_cmd_result_t
2446 route_set_tag(void *rule
, const struct prefix
*prefix
,
2447 route_map_object_t type
, void *object
)
2450 struct bgp_path_info
*path
;
2452 if (type
== RMAP_BGP
) {
2457 path
->attr
->tag
= *tag
;
2463 /* Route map commands for tag set. */
2464 static struct route_map_rule_cmd route_set_tag_cmd
= {
2465 "tag", route_set_tag
, route_map_rule_tag_compile
,
2466 route_map_rule_tag_free
,
2469 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2470 static enum route_map_cmd_result_t
2471 route_set_label_index(void *rule
, const struct prefix
*prefix
,
2472 route_map_object_t type
, void *object
)
2474 struct rmap_value
*rv
;
2475 struct bgp_path_info
*path
;
2476 uint32_t label_index
;
2478 if (type
== RMAP_BGP
) {
2479 /* Fetch routemap's rule information. */
2483 /* Set label-index value. */
2484 label_index
= rv
->value
;
2486 path
->attr
->label_index
= label_index
;
2487 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2494 /* Route map commands for label-index set. */
2495 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2496 "label-index", route_set_label_index
, route_value_compile
,
2500 /* `match ipv6 address IP_ACCESS_LIST' */
2502 static enum route_map_cmd_result_t
2503 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
,
2504 route_map_object_t type
, void *object
)
2506 struct access_list
*alist
;
2508 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2509 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2511 return RMAP_NOMATCH
;
2513 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2517 return RMAP_NOMATCH
;
2520 static void *route_match_ipv6_address_compile(const char *arg
)
2522 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2525 static void route_match_ipv6_address_free(void *rule
)
2527 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2530 /* Route map commands for ip address matching. */
2531 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2532 "ipv6 address", route_match_ipv6_address
,
2533 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2535 /* `match ipv6 next-hop IP_ADDRESS' */
2537 static enum route_map_cmd_result_t
2538 route_match_ipv6_next_hop(void *rule
, const struct prefix
*prefix
,
2539 route_map_object_t type
, void *object
)
2541 struct in6_addr
*addr
= rule
;
2542 struct bgp_path_info
*path
;
2544 if (type
== RMAP_BGP
) {
2547 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2550 if (path
->attr
->mp_nexthop_len
2551 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2552 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2555 return RMAP_NOMATCH
;
2558 return RMAP_NOMATCH
;
2561 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2563 struct in6_addr
*address
;
2566 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2568 ret
= inet_pton(AF_INET6
, arg
, address
);
2570 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2577 static void route_match_ipv6_next_hop_free(void *rule
)
2579 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2582 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2583 "ipv6 next-hop", route_match_ipv6_next_hop
,
2584 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2586 /* `match ipv6 address prefix-list PREFIX_LIST' */
2588 static enum route_map_cmd_result_t
2589 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2590 route_map_object_t type
, void *object
)
2592 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, type
,
2596 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2598 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2601 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2603 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2606 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2607 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2608 route_match_ipv6_address_prefix_list_compile
,
2609 route_match_ipv6_address_prefix_list_free
};
2611 /* `match ipv6 next-hop type <TYPE>' */
2613 static enum route_map_cmd_result_t
2614 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2615 route_map_object_t type
, void *object
)
2617 struct bgp_path_info
*path
;
2618 struct in6_addr
*addr
= rule
;
2620 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2621 path
= (struct bgp_path_info
*)object
;
2622 if (!path
|| !path
->attr
)
2623 return RMAP_NOMATCH
;
2625 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2626 && !path
->attr
->nh_ifindex
)
2629 return RMAP_NOMATCH
;
2632 static void *route_match_ipv6_next_hop_type_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
, "::0", address
);
2641 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2648 static void route_match_ipv6_next_hop_type_free(void *rule
)
2650 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2653 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2654 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2655 route_match_ipv6_next_hop_type_compile
,
2656 route_match_ipv6_next_hop_type_free
};
2658 /* `set ipv6 nexthop global IP_ADDRESS' */
2660 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2661 static enum route_map_cmd_result_t
2662 route_set_ipv6_nexthop_global(void *rule
, const struct prefix
*p
,
2663 route_map_object_t type
, void *object
)
2665 struct in6_addr
*address
;
2666 struct bgp_path_info
*path
;
2668 if (type
== RMAP_BGP
) {
2669 /* Fetch routemap's rule information. */
2673 /* Set next hop value. */
2674 path
->attr
->mp_nexthop_global
= *address
;
2676 /* Set nexthop length. */
2677 if (path
->attr
->mp_nexthop_len
== 0)
2678 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2680 SET_FLAG(path
->attr
->rmap_change_flags
,
2681 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2687 /* Route map `ip next-hop' compile function. Given string is converted
2688 to struct in_addr structure. */
2689 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2692 struct in6_addr
*address
;
2694 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2696 ret
= inet_pton(AF_INET6
, arg
, address
);
2699 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2706 /* Free route map's compiled `ip next-hop' value. */
2707 static void route_set_ipv6_nexthop_global_free(void *rule
)
2709 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2712 /* Route map commands for ip nexthop set. */
2713 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2714 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2715 route_set_ipv6_nexthop_global_compile
,
2716 route_set_ipv6_nexthop_global_free
};
2718 /* Set next-hop preference value. */
2719 static enum route_map_cmd_result_t
2720 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2721 route_map_object_t type
, void *object
)
2723 struct bgp_path_info
*path
;
2726 if (type
== RMAP_BGP
) {
2727 /* Fetch routemap's rule information. */
2731 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2732 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2734 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2735 /* Set next hop preference to global */
2736 path
->attr
->mp_nexthop_prefer_global
= true;
2737 SET_FLAG(path
->attr
->rmap_change_flags
,
2738 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2740 path
->attr
->mp_nexthop_prefer_global
= false;
2741 SET_FLAG(path
->attr
->rmap_change_flags
,
2742 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2748 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2752 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2758 /* Free route map's compiled `ip next-hop' value. */
2759 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2761 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2764 /* Route map commands for ip nexthop set preferred. */
2765 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2766 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2767 route_set_ipv6_nexthop_prefer_global_compile
,
2768 route_set_ipv6_nexthop_prefer_global_free
};
2770 /* `set ipv6 nexthop local IP_ADDRESS' */
2772 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2773 static enum route_map_cmd_result_t
2774 route_set_ipv6_nexthop_local(void *rule
, const struct prefix
*p
,
2775 route_map_object_t type
, void *object
)
2777 struct in6_addr
*address
;
2778 struct bgp_path_info
*path
;
2780 if (type
== RMAP_BGP
) {
2781 /* Fetch routemap's rule information. */
2785 /* Set next hop value. */
2786 path
->attr
->mp_nexthop_local
= *address
;
2788 /* Set nexthop length. */
2789 if (path
->attr
->mp_nexthop_len
2790 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2791 path
->attr
->mp_nexthop_len
=
2792 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2794 SET_FLAG(path
->attr
->rmap_change_flags
,
2795 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2801 /* Route map `ip nexthop' compile function. Given string is converted
2802 to struct in_addr structure. */
2803 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2806 struct in6_addr
*address
;
2808 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2810 ret
= inet_pton(AF_INET6
, arg
, address
);
2813 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2820 /* Free route map's compiled `ip nexthop' value. */
2821 static void route_set_ipv6_nexthop_local_free(void *rule
)
2823 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2826 /* Route map commands for ip nexthop set. */
2827 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2828 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2829 route_set_ipv6_nexthop_local_compile
,
2830 route_set_ipv6_nexthop_local_free
};
2832 /* `set ipv6 nexthop peer-address' */
2834 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2835 static enum route_map_cmd_result_t
2836 route_set_ipv6_nexthop_peer(void *rule
, const struct prefix
*pfx
,
2837 route_map_object_t type
, void *object
)
2839 struct in6_addr peer_address
;
2840 struct bgp_path_info
*path
;
2843 if (type
== RMAP_BGP
) {
2844 /* Fetch routemap's rule information. */
2848 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2849 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2851 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2852 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2853 /* Set next hop value and length in attribute. */
2854 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2855 path
->attr
->mp_nexthop_local
= peer_address
;
2856 if (path
->attr
->mp_nexthop_len
!= 32)
2857 path
->attr
->mp_nexthop_len
= 32;
2859 path
->attr
->mp_nexthop_global
= peer_address
;
2860 if (path
->attr
->mp_nexthop_len
== 0)
2861 path
->attr
->mp_nexthop_len
= 16;
2864 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2865 /* The next hop value will be set as part of packet
2867 * Set the flags here to indicate that rewrite needs to
2869 * Also, clear the value - we clear both global and
2871 * nexthops, whether we send one or both is determined
2874 SET_FLAG(path
->attr
->rmap_change_flags
,
2875 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2876 /* clear next hop value. */
2877 memset(&(path
->attr
->mp_nexthop_global
), 0,
2878 sizeof(struct in6_addr
));
2879 memset(&(path
->attr
->mp_nexthop_local
), 0,
2880 sizeof(struct in6_addr
));
2887 /* Route map `ip next-hop' compile function. Given string is converted
2888 to struct in_addr structure. */
2889 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2893 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2899 /* Free route map's compiled `ip next-hop' value. */
2900 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2902 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2905 /* Route map commands for ip nexthop set. */
2906 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2907 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2908 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2910 /* `set ipv4 vpn next-hop A.B.C.D' */
2912 static enum route_map_cmd_result_t
2913 route_set_vpnv4_nexthop(void *rule
, const struct prefix
*prefix
,
2914 route_map_object_t type
, void *object
)
2916 struct in_addr
*address
;
2917 struct bgp_path_info
*path
;
2919 if (type
== RMAP_BGP
) {
2920 /* Fetch routemap's rule information. */
2924 /* Set next hop value. */
2925 path
->attr
->mp_nexthop_global_in
= *address
;
2926 path
->attr
->mp_nexthop_len
= 4;
2932 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2935 struct in_addr
*address
;
2937 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2939 ret
= inet_aton(arg
, address
);
2942 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2949 /* `set ipv6 vpn next-hop A.B.C.D' */
2951 static enum route_map_cmd_result_t
2952 route_set_vpnv6_nexthop(void *rule
, const struct prefix
*prefix
,
2953 route_map_object_t type
, void *object
)
2955 struct in6_addr
*address
;
2956 struct bgp_path_info
*path
;
2958 if (type
== RMAP_BGP
) {
2959 /* Fetch routemap's rule information. */
2963 /* Set next hop value. */
2964 memcpy(&path
->attr
->mp_nexthop_global
, address
,
2965 sizeof(struct in6_addr
));
2966 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2972 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2975 struct in6_addr
*address
;
2977 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2978 ret
= inet_pton(AF_INET6
, arg
, address
);
2981 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2988 static void route_set_vpn_nexthop_free(void *rule
)
2990 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2993 /* Route map commands for ipv4 next-hop set. */
2994 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2995 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2996 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
2998 /* Route map commands for ipv6 next-hop set. */
2999 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3000 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
3001 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
3003 /* `set originator-id' */
3005 /* For origin set. */
3006 static enum route_map_cmd_result_t
3007 route_set_originator_id(void *rule
, const struct prefix
*prefix
,
3008 route_map_object_t type
, void *object
)
3010 struct in_addr
*address
;
3011 struct bgp_path_info
*path
;
3013 if (type
== RMAP_BGP
) {
3017 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3018 path
->attr
->originator_id
= *address
;
3024 /* Compile function for originator-id set. */
3025 static void *route_set_originator_id_compile(const char *arg
)
3028 struct in_addr
*address
;
3030 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3032 ret
= inet_aton(arg
, address
);
3035 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3042 /* Compile function for originator_id set. */
3043 static void route_set_originator_id_free(void *rule
)
3045 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3048 /* Set originator-id rule structure. */
3049 struct route_map_rule_cmd route_set_originator_id_cmd
= {
3050 "originator-id", route_set_originator_id
,
3051 route_set_originator_id_compile
, route_set_originator_id_free
,
3054 /* Add bgp route map rule. */
3055 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3056 const char *arg
, route_map_event_t type
)
3058 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3059 int retval
= CMD_SUCCESS
;
3060 enum rmap_compile_rets ret
;
3062 ret
= route_map_add_match(index
, command
, arg
, type
);
3064 case RMAP_RULE_MISSING
:
3065 vty_out(vty
, "%% BGP Can't find rule.\n");
3066 retval
= CMD_WARNING_CONFIG_FAILED
;
3068 case RMAP_COMPILE_ERROR
:
3069 vty_out(vty
, "%% BGP Argument is malformed.\n");
3070 retval
= CMD_WARNING_CONFIG_FAILED
;
3072 case RMAP_COMPILE_SUCCESS
:
3073 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
3074 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
3077 case RMAP_DUPLICATE_RULE
:
3079 * Intentionally doing nothing here.
3087 /* Delete bgp route map rule. */
3088 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3089 const char *arg
, route_map_event_t type
)
3091 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3092 enum rmap_compile_rets ret
;
3093 int retval
= CMD_SUCCESS
;
3094 char *dep_name
= NULL
;
3096 char *rmap_name
= NULL
;
3098 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3099 /* ignore the mundane, the types without any dependency */
3101 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3104 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3106 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3108 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3111 ret
= route_map_delete_match(index
, command
, dep_name
);
3113 case RMAP_RULE_MISSING
:
3114 vty_out(vty
, "%% BGP Can't find rule.\n");
3115 retval
= CMD_WARNING_CONFIG_FAILED
;
3117 case RMAP_COMPILE_ERROR
:
3118 vty_out(vty
, "%% BGP Argument is malformed.\n");
3119 retval
= CMD_WARNING_CONFIG_FAILED
;
3121 case RMAP_COMPILE_SUCCESS
:
3122 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
3123 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
3125 case RMAP_DUPLICATE_RULE
:
3127 * Nothing to do here
3132 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3133 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3139 * This is the workhorse routine for processing in/out routemap
3142 static void bgp_route_map_process_peer(const char *rmap_name
,
3143 struct route_map
*map
, struct peer
*peer
,
3144 int afi
, int safi
, int route_update
)
3146 struct bgp_filter
*filter
;
3148 if (!peer
|| !rmap_name
)
3151 filter
= &peer
->filter
[afi
][safi
];
3153 * in is for non-route-server clients,
3154 * out is for all peers
3156 if (filter
->map
[RMAP_IN
].name
3157 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3158 filter
->map
[RMAP_IN
].map
= map
;
3160 if (route_update
&& peer
->status
== Established
) {
3161 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3162 PEER_FLAG_SOFT_RECONFIG
)) {
3163 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3165 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3166 rmap_name
, peer
->host
);
3168 bgp_soft_reconfig_in(peer
, afi
, safi
);
3169 } else if (CHECK_FLAG(peer
->cap
,
3170 PEER_CAP_REFRESH_OLD_RCV
)
3171 || CHECK_FLAG(peer
->cap
,
3172 PEER_CAP_REFRESH_NEW_RCV
)) {
3173 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3175 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3176 rmap_name
, peer
->host
);
3177 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3184 * For outbound, unsuppress and default-originate map change (content or
3185 * map created), merely update the "config" here, the actual route
3186 * announcement happens at the group level.
3188 if (filter
->map
[RMAP_OUT
].name
3189 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3190 filter
->map
[RMAP_OUT
].map
= map
;
3192 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3193 filter
->usmap
.map
= map
;
3195 if (peer
->default_rmap
[afi
][safi
].name
3196 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3197 peer
->default_rmap
[afi
][safi
].map
= map
;
3200 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3201 struct route_map
*map
,
3204 struct peer_group
*group
;
3205 struct listnode
*node
, *nnode
;
3206 struct bgp_filter
*filter
;
3213 /* All the peers have been updated correctly already. This is
3214 * just updating the placeholder data. No real update required.
3216 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3217 FOREACH_AFI_SAFI (afi
, safi
) {
3218 filter
= &group
->conf
->filter
[afi
][safi
];
3220 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3221 if ((filter
->map
[direct
].name
)
3222 && (strcmp(rmap_name
,
3223 filter
->map
[direct
].name
)
3225 filter
->map
[direct
].map
= map
;
3228 if (filter
->usmap
.name
3229 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3230 filter
->usmap
.map
= map
;
3236 * Note that if an extreme number (tens of thousands) of route-maps are in use
3237 * and if bgp has an extreme number of peers, network statements, etc then this
3238 * function can consume a lot of cycles. This is due to this function being
3239 * called for each route-map and within this function we walk the list of peers,
3240 * network statements, etc looking to see if they use this route-map.
3242 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3249 struct bgp_node
*bn
;
3250 struct bgp_static
*bgp_static
;
3251 struct listnode
*node
, *nnode
;
3252 struct route_map
*map
;
3253 char buf
[INET6_ADDRSTRLEN
];
3255 map
= route_map_lookup_by_name(rmap_name
);
3257 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3259 /* Ignore dummy peer-group structure */
3260 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3263 FOREACH_AFI_SAFI (afi
, safi
) {
3264 /* process in/out/import/export/default-orig
3266 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3267 safi
, route_update
);
3271 /* for outbound/default-orig route-maps, process for groups */
3272 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3275 /* update peer-group config (template) */
3276 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3278 FOREACH_AFI_SAFI (afi
, safi
) {
3279 /* For table route-map updates. */
3280 if (!bgp_fibupd_safi(safi
))
3283 if (bgp
->table_map
[afi
][safi
].name
3284 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3287 /* bgp->table_map[afi][safi].map is NULL.
3288 * i.e Route map creation event.
3289 * So update applied_counter.
3290 * If it is not NULL, i.e It may be routemap updation or
3291 * deletion. so no need to update the counter.
3293 if (!bgp
->table_map
[afi
][safi
].map
)
3294 route_map_counter_increment(map
);
3295 bgp
->table_map
[afi
][safi
].map
= map
;
3297 if (BGP_DEBUG(zebra
, ZEBRA
))
3299 "Processing route_map %s update on "
3303 bgp_zebra_announce_table(bgp
, afi
, safi
);
3306 /* For network route-map updates. */
3307 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3308 bn
= bgp_route_next(bn
)) {
3309 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3313 if (!bgp_static
->rmap
.name
3314 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3317 if (!bgp_static
->rmap
.map
)
3318 route_map_counter_increment(map
);
3320 bgp_static
->rmap
.map
= map
;
3322 if (route_update
&& !bgp_static
->backdoor
) {
3323 if (bgp_debug_zebra(&bn
->p
))
3325 "Processing route_map %s update on static route %s",
3327 inet_ntop(bn
->p
.family
,
3328 &bn
->p
.u
.prefix
, buf
,
3330 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3336 /* For redistribute route-map updates. */
3337 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3338 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3339 struct list
*red_list
;
3340 struct bgp_redist
*red
;
3342 red_list
= bgp
->redist
[afi
][i
];
3346 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3348 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3352 route_map_counter_increment(map
);
3354 red
->rmap
.map
= map
;
3359 if (BGP_DEBUG(zebra
, ZEBRA
))
3361 "Processing route_map %s update on redistributed routes",
3364 bgp_redistribute_resend(bgp
, afi
, i
,
3369 /* for type5 command route-maps */
3370 FOREACH_AFI_SAFI (afi
, safi
) {
3371 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3372 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3376 /* Make sure the route-map is populated here if not already done */
3377 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3379 if (BGP_DEBUG(zebra
, ZEBRA
))
3381 "Processing route_map %s update on advertise type5 route command",
3384 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3385 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3386 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3391 static void bgp_route_map_process_update_cb(char *rmap_name
)
3393 struct listnode
*node
, *nnode
;
3396 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3397 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3400 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3401 vnc_routemap_update(bgp
, __func__
);
3405 vpn_policy_routemap_event(rmap_name
);
3408 int bgp_route_map_update_timer(struct thread
*thread
)
3410 bm
->t_rmap_update
= NULL
;
3412 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3417 static void bgp_route_map_mark_update(const char *rmap_name
)
3419 struct listnode
*node
, *nnode
;
3422 /* If new update is received before the current timer timed out,
3423 * turn it off and start a new timer.
3425 if (bm
->t_rmap_update
!= NULL
)
3426 THREAD_OFF(bm
->t_rmap_update
);
3428 /* rmap_update_timer of 0 means don't do route updates */
3429 if (bm
->rmap_update_timer
) {
3430 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3431 NULL
, bm
->rmap_update_timer
,
3432 &bm
->t_rmap_update
);
3434 /* Signal the groups that a route-map update event has
3436 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3437 update_group_policy_update(bgp
,
3438 BGP_POLICY_ROUTE_MAP
,
3441 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3442 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3444 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3445 vnc_routemap_update(bgp
, __func__
);
3450 static void bgp_route_map_add(const char *rmap_name
)
3452 if (route_map_mark_updated(rmap_name
) == 0)
3453 bgp_route_map_mark_update(rmap_name
);
3455 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3458 static void bgp_route_map_delete(const char *rmap_name
)
3460 if (route_map_mark_updated(rmap_name
) == 0)
3461 bgp_route_map_mark_update(rmap_name
);
3463 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3466 static void bgp_route_map_event(const char *rmap_name
)
3468 if (route_map_mark_updated(rmap_name
) == 0)
3469 bgp_route_map_mark_update(rmap_name
);
3471 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3474 DEFUN (match_mac_address
,
3475 match_mac_address_cmd
,
3476 "match mac address WORD",
3479 "Match address of route\n"
3480 "MAC Access-list name\n")
3482 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3483 RMAP_EVENT_FILTER_ADDED
);
3486 DEFUN (no_match_mac_address
,
3487 no_match_mac_address_cmd
,
3488 "no match mac address WORD",
3492 "Match address of route\n"
3493 "MAC acess-list name\n")
3495 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3496 RMAP_EVENT_FILTER_DELETED
);
3499 DEFUN (match_evpn_route_type
,
3500 match_evpn_route_type_cmd
,
3501 "match evpn route-type <macip | multicast | prefix>",
3504 "Match route-type\n"
3509 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3510 RMAP_EVENT_MATCH_ADDED
);
3513 DEFUN (no_match_evpn_route_type
,
3514 no_match_evpn_route_type_cmd
,
3515 "no match evpn route-type <macip | multicast | prefix>",
3519 "Match route-type\n"
3524 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3525 RMAP_EVENT_MATCH_DELETED
);
3529 DEFUN (match_evpn_vni
,
3531 "match evpn vni " CMD_VNI_RANGE
,
3537 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3538 RMAP_EVENT_MATCH_ADDED
);
3541 DEFUN (no_match_evpn_vni
,
3542 no_match_evpn_vni_cmd
,
3543 "no match evpn vni " CMD_VNI_RANGE
,
3550 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3551 RMAP_EVENT_MATCH_DELETED
);
3554 DEFUN (match_evpn_default_route
,
3555 match_evpn_default_route_cmd
,
3556 "match evpn default-route",
3559 "default EVPN type-5 route\n")
3561 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3562 RMAP_EVENT_MATCH_ADDED
);
3565 DEFUN (no_match_evpn_default_route
,
3566 no_match_evpn_default_route_cmd
,
3567 "no match evpn default-route",
3571 "default EVPN type-5 route\n")
3573 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3574 RMAP_EVENT_MATCH_DELETED
);
3577 DEFPY(match_vrl_source_vrf
,
3578 match_vrl_source_vrf_cmd
,
3579 "match source-vrf NAME$vrf_name",
3584 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3585 RMAP_EVENT_MATCH_ADDED
);
3588 DEFPY(no_match_vrl_source_vrf
,
3589 no_match_vrl_source_vrf_cmd
,
3590 "no match source-vrf NAME$vrf_name",
3596 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3597 RMAP_EVENT_MATCH_DELETED
);
3602 "match peer <A.B.C.D|X:X::X:X|WORD>",
3604 "Match peer address\n"
3605 "IP address of peer\n"
3606 "IPv6 address of peer\n"
3607 "Interface name of peer\n")
3610 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3611 RMAP_EVENT_MATCH_ADDED
);
3614 DEFUN (match_peer_local
,
3615 match_peer_local_cmd
,
3618 "Match peer address\n"
3619 "Static or Redistributed routes\n")
3621 return bgp_route_match_add(vty
, "peer", "local",
3622 RMAP_EVENT_MATCH_DELETED
);
3625 DEFUN (no_match_peer
,
3627 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3630 "Match peer address\n"
3631 "Static or Redistributed routes\n"
3632 "IP address of peer\n"
3633 "IPv6 address of peer\n"
3634 "Interface name of peer\n")
3638 if (argc
<= idx_peer
)
3639 return bgp_route_match_delete(vty
, "peer", NULL
,
3640 RMAP_EVENT_MATCH_DELETED
);
3641 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3642 RMAP_EVENT_MATCH_DELETED
);
3645 #if defined(HAVE_LUA)
3646 DEFUN (match_command
,
3648 "match command WORD",
3650 "Run a command to match\n"
3651 "The command to run\n")
3653 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3654 RMAP_EVENT_FILTER_ADDED
);
3657 DEFUN (no_match_command
,
3658 no_match_command_cmd
,
3659 "no match command WORD",
3662 "Run a command to match\n"
3663 "The command to run\n")
3665 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3666 RMAP_EVENT_FILTER_DELETED
);
3670 /* match probability */
3671 DEFUN (match_probability
,
3672 match_probability_cmd
,
3673 "match probability (0-100)",
3675 "Match portion of routes defined by percentage value\n"
3676 "Percentage of routes\n")
3679 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3680 RMAP_EVENT_MATCH_ADDED
);
3684 DEFUN (no_match_probability
,
3685 no_match_probability_cmd
,
3686 "no match probability [(1-99)]",
3689 "Match portion of routes defined by percentage value\n"
3690 "Percentage of routes\n")
3693 if (argc
<= idx_number
)
3694 return bgp_route_match_delete(vty
, "probability", NULL
,
3695 RMAP_EVENT_MATCH_DELETED
);
3696 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3697 RMAP_EVENT_MATCH_DELETED
);
3701 DEFUN (match_ip_route_source
,
3702 match_ip_route_source_cmd
,
3703 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3706 "Match advertising source address of route\n"
3707 "IP access-list number\n"
3708 "IP access-list number (expanded range)\n"
3709 "IP standard access-list name\n")
3712 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3713 RMAP_EVENT_FILTER_ADDED
);
3717 DEFUN (no_match_ip_route_source
,
3718 no_match_ip_route_source_cmd
,
3719 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3723 "Match advertising source address of route\n"
3724 "IP access-list number\n"
3725 "IP access-list number (expanded range)\n"
3726 "IP standard access-list name\n")
3729 if (argc
<= idx_number
)
3730 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3731 RMAP_EVENT_FILTER_DELETED
);
3732 return bgp_route_match_delete(vty
, "ip route-source",
3733 argv
[idx_number
]->arg
,
3734 RMAP_EVENT_FILTER_DELETED
);
3738 DEFUN (match_ip_route_source_prefix_list
,
3739 match_ip_route_source_prefix_list_cmd
,
3740 "match ip route-source prefix-list WORD",
3743 "Match advertising source address of route\n"
3744 "Match entries of prefix-lists\n"
3745 "IP prefix-list name\n")
3748 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3749 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3753 DEFUN (no_match_ip_route_source_prefix_list
,
3754 no_match_ip_route_source_prefix_list_cmd
,
3755 "no match ip route-source prefix-list [WORD]",
3759 "Match advertising source address of route\n"
3760 "Match entries of prefix-lists\n"
3761 "IP prefix-list name\n")
3764 if (argc
<= idx_word
)
3765 return bgp_route_match_delete(vty
,
3766 "ip route-source prefix-list",
3767 NULL
, RMAP_EVENT_PLIST_DELETED
);
3768 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3769 argv
[idx_word
]->arg
,
3770 RMAP_EVENT_PLIST_DELETED
);
3774 DEFUN (match_local_pref
,
3775 match_local_pref_cmd
,
3776 "match local-preference (0-4294967295)",
3778 "Match local-preference of route\n"
3782 return bgp_route_match_add(vty
, "local-preference",
3783 argv
[idx_number
]->arg
,
3784 RMAP_EVENT_MATCH_ADDED
);
3788 DEFUN (no_match_local_pref
,
3789 no_match_local_pref_cmd
,
3790 "no match local-preference [(0-4294967295)]",
3793 "Match local preference of route\n"
3794 "Local preference value\n")
3796 int idx_localpref
= 3;
3797 if (argc
<= idx_localpref
)
3798 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3799 RMAP_EVENT_MATCH_DELETED
);
3800 return bgp_route_match_delete(vty
, "local-preference",
3801 argv
[idx_localpref
]->arg
,
3802 RMAP_EVENT_MATCH_DELETED
);
3806 DEFUN (match_community
,
3807 match_community_cmd
,
3808 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3810 "Match BGP community list\n"
3811 "Community-list number (standard)\n"
3812 "Community-list number (expanded)\n"
3813 "Community-list name\n"
3814 "Do exact matching of communities\n")
3816 int idx_comm_list
= 2;
3821 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3822 strlen(argv
[idx_comm_list
]->arg
)
3823 + strlen("exact-match") + 2);
3825 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3827 argstr
= argv
[idx_comm_list
]->arg
;
3829 ret
= bgp_route_match_add(vty
, "community", argstr
,
3830 RMAP_EVENT_CLIST_ADDED
);
3832 if (argstr
!= argv
[idx_comm_list
]->arg
)
3833 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3838 DEFUN (no_match_community
,
3839 no_match_community_cmd
,
3840 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3843 "Match BGP community list\n"
3844 "Community-list number (standard)\n"
3845 "Community-list number (expanded)\n"
3846 "Community-list name\n"
3847 "Do exact matching of communities\n")
3849 return bgp_route_match_delete(vty
, "community", NULL
,
3850 RMAP_EVENT_CLIST_DELETED
);
3853 DEFUN (match_lcommunity
,
3854 match_lcommunity_cmd
,
3855 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
3857 "Match BGP large community list\n"
3858 "Large Community-list number (standard)\n"
3859 "Large Community-list number (expanded)\n"
3860 "Large Community-list name\n"
3861 "Do exact matching of communities\n")
3863 int idx_lcomm_list
= 2;
3868 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3869 strlen(argv
[idx_lcomm_list
]->arg
)
3870 + strlen("exact-match") + 2);
3872 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
3874 argstr
= argv
[idx_lcomm_list
]->arg
;
3876 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
3877 RMAP_EVENT_LLIST_ADDED
);
3878 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
3879 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3884 DEFUN (no_match_lcommunity
,
3885 no_match_lcommunity_cmd
,
3886 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
3889 "Match BGP large community list\n"
3890 "Large Community-list number (standard)\n"
3891 "Large Community-list number (expanded)\n"
3892 "Large Community-list name\n"
3893 "Do exact matching of communities\n")
3895 return bgp_route_match_delete(vty
, "large-community", NULL
,
3896 RMAP_EVENT_LLIST_DELETED
);
3899 DEFUN (match_ecommunity
,
3900 match_ecommunity_cmd
,
3901 "match extcommunity <(1-99)|(100-500)|WORD>",
3903 "Match BGP/VPN extended community list\n"
3904 "Extended community-list number (standard)\n"
3905 "Extended community-list number (expanded)\n"
3906 "Extended community-list name\n")
3908 int idx_comm_list
= 2;
3909 return bgp_route_match_add(vty
, "extcommunity",
3910 argv
[idx_comm_list
]->arg
,
3911 RMAP_EVENT_ECLIST_ADDED
);
3915 DEFUN (no_match_ecommunity
,
3916 no_match_ecommunity_cmd
,
3917 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3920 "Match BGP/VPN extended community list\n"
3921 "Extended community-list number (standard)\n"
3922 "Extended community-list number (expanded)\n"
3923 "Extended community-list name\n")
3925 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3926 RMAP_EVENT_ECLIST_DELETED
);
3930 DEFUN (match_aspath
,
3932 "match as-path WORD",
3934 "Match BGP AS path list\n"
3935 "AS path access-list name\n")
3938 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3939 RMAP_EVENT_ASLIST_ADDED
);
3943 DEFUN (no_match_aspath
,
3944 no_match_aspath_cmd
,
3945 "no match as-path [WORD]",
3948 "Match BGP AS path list\n"
3949 "AS path access-list name\n")
3951 return bgp_route_match_delete(vty
, "as-path", NULL
,
3952 RMAP_EVENT_ASLIST_DELETED
);
3956 DEFUN (match_origin
,
3958 "match origin <egp|igp|incomplete>",
3963 "unknown heritage\n")
3966 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3967 return bgp_route_match_add(vty
, "origin", "igp",
3968 RMAP_EVENT_MATCH_ADDED
);
3969 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3970 return bgp_route_match_add(vty
, "origin", "egp",
3971 RMAP_EVENT_MATCH_ADDED
);
3972 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3973 return bgp_route_match_add(vty
, "origin", "incomplete",
3974 RMAP_EVENT_MATCH_ADDED
);
3976 vty_out(vty
, "%% Invalid match origin type\n");
3977 return CMD_WARNING_CONFIG_FAILED
;
3981 DEFUN (no_match_origin
,
3982 no_match_origin_cmd
,
3983 "no match origin [<egp|igp|incomplete>]",
3989 "unknown heritage\n")
3991 return bgp_route_match_delete(vty
, "origin", NULL
,
3992 RMAP_EVENT_MATCH_DELETED
);
3995 DEFUN (set_ip_nexthop_peer
,
3996 set_ip_nexthop_peer_cmd
,
3997 "[no] set ip next-hop peer-address",
4001 "Next hop address\n"
4002 "Use peer address (for BGP only)\n")
4004 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4005 const char *) = strmatch(argv
[0]->text
, "no")
4006 ? generic_set_delete
4009 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4013 DEFUN (set_ip_nexthop_unchanged
,
4014 set_ip_nexthop_unchanged_cmd
,
4015 "[no] set ip next-hop unchanged",
4019 "Next hop address\n"
4020 "Don't modify existing Next hop address\n")
4022 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4023 const char *) = strmatch(argv
[0]->text
, "no")
4024 ? generic_set_delete
4027 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4032 DEFUN (set_local_pref
,
4034 "set local-preference (0-4294967295)",
4036 "BGP local preference path attribute\n"
4037 "Preference value\n")
4040 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4041 "local-preference", argv
[idx_number
]->arg
);
4045 DEFUN (no_set_local_pref
,
4046 no_set_local_pref_cmd
,
4047 "no set local-preference [(0-4294967295)]",
4050 "BGP local preference path attribute\n"
4051 "Preference value\n")
4053 int idx_localpref
= 3;
4054 if (argc
<= idx_localpref
)
4055 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4056 "local-preference", NULL
);
4057 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4058 "local-preference", argv
[idx_localpref
]->arg
);
4064 "set weight (0-4294967295)",
4066 "BGP weight for routing table\n"
4070 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4071 argv
[idx_number
]->arg
);
4075 DEFUN (no_set_weight
,
4077 "no set weight [(0-4294967295)]",
4080 "BGP weight for routing table\n"
4084 if (argc
<= idx_weight
)
4085 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4087 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4088 "weight", argv
[idx_weight
]->arg
);
4091 DEFUN (set_label_index
,
4092 set_label_index_cmd
,
4093 "set label-index (0-1048560)",
4095 "Label index to associate with the prefix\n"
4096 "Label index value\n")
4099 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4100 "label-index", argv
[idx_number
]->arg
);
4103 DEFUN (no_set_label_index
,
4104 no_set_label_index_cmd
,
4105 "no set label-index [(0-1048560)]",
4108 "Label index to associate with the prefix\n"
4109 "Label index value\n")
4111 int idx_label_index
= 3;
4112 if (argc
<= idx_label_index
)
4113 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4114 "label-index", NULL
);
4115 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4116 "label-index", argv
[idx_label_index
]->arg
);
4119 DEFUN (set_aspath_prepend_asn
,
4120 set_aspath_prepend_asn_cmd
,
4121 "set as-path prepend (1-4294967295)...",
4123 "Transform BGP AS_PATH attribute\n"
4124 "Prepend to the as-path\n"
4131 str
= argv_concat(argv
, argc
, idx_asn
);
4132 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4133 "as-path prepend", str
);
4134 XFREE(MTYPE_TMP
, str
);
4139 DEFUN (set_aspath_prepend_lastas
,
4140 set_aspath_prepend_lastas_cmd
,
4141 "set as-path prepend last-as (1-10)",
4143 "Transform BGP AS_PATH attribute\n"
4144 "Prepend to the as-path\n"
4145 "Use the peer's AS-number\n"
4146 "Number of times to insert\n")
4148 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4151 DEFUN (no_set_aspath_prepend
,
4152 no_set_aspath_prepend_cmd
,
4153 "no set as-path prepend [(1-4294967295)]",
4156 "Transform BGP AS_PATH attribute\n"
4157 "Prepend to the as-path\n"
4164 str
= argv_concat(argv
, argc
, idx_asn
);
4165 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4166 "as-path prepend", str
);
4167 XFREE(MTYPE_TMP
, str
);
4171 DEFUN (no_set_aspath_prepend_lastas
,
4172 no_set_aspath_prepend_lastas_cmd
,
4173 "no set as-path prepend last-as [(1-10)]",
4176 "Transform BGP AS_PATH attribute\n"
4177 "Prepend to the as-path\n"
4178 "Use the peers AS-number\n"
4179 "Number of times to insert\n")
4181 return no_set_aspath_prepend(self
, vty
, argc
, argv
);
4184 DEFUN (set_aspath_exclude
,
4185 set_aspath_exclude_cmd
,
4186 "set as-path exclude (1-4294967295)...",
4188 "Transform BGP AS-path attribute\n"
4189 "Exclude from the as-path\n"
4196 str
= argv_concat(argv
, argc
, idx_asn
);
4197 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4198 "as-path exclude", str
);
4199 XFREE(MTYPE_TMP
, str
);
4203 DEFUN (no_set_aspath_exclude
,
4204 no_set_aspath_exclude_cmd
,
4205 "no set as-path exclude (1-4294967295)...",
4208 "Transform BGP AS_PATH attribute\n"
4209 "Exclude from the as-path\n"
4216 str
= argv_concat(argv
, argc
, idx_asn
);
4217 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4218 "as-path exclude", str
);
4219 XFREE(MTYPE_TMP
, str
);
4223 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4224 "no set as-path exclude",
4226 "Transform BGP AS_PATH attribute\n"
4227 "Exclude from the as-path\n")
4229 DEFUN (set_community
,
4231 "set community AA:NN...",
4233 "BGP community attribute\n"
4241 struct community
*com
= NULL
;
4246 b
= buffer_new(1024);
4248 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4249 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4256 buffer_putc(b
, ' ');
4260 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4262 buffer_putstr(b
, "internet");
4265 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4267 buffer_putstr(b
, "local-AS");
4270 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4271 && strncmp(argv
[i
]->arg
, "no-advertise",
4272 strlen(argv
[i
]->arg
))
4274 buffer_putstr(b
, "no-advertise");
4277 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4278 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4280 buffer_putstr(b
, "no-export");
4283 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4284 strlen(argv
[i
]->arg
))
4286 buffer_putstr(b
, "graceful-shutdown");
4289 buffer_putstr(b
, argv
[i
]->arg
);
4291 buffer_putc(b
, '\0');
4293 /* Fetch result string then compile it to communities attribute. */
4294 str
= buffer_getstr(b
);
4298 com
= community_str2com(str
);
4299 XFREE(MTYPE_TMP
, str
);
4302 /* Can't compile user input into communities attribute. */
4304 vty_out(vty
, "%% Malformed communities attribute\n");
4305 return CMD_WARNING_CONFIG_FAILED
;
4308 /* Set communites attribute string. */
4309 str
= community_str(com
, false);
4312 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4313 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4314 strlcpy(argstr
, str
, argstr_sz
);
4315 strlcat(argstr
, " additive", argstr_sz
);
4316 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4317 "community", argstr
);
4318 XFREE(MTYPE_TMP
, argstr
);
4320 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4323 community_free(&com
);
4328 DEFUN (set_community_none
,
4329 set_community_none_cmd
,
4330 "set community none",
4332 "BGP community attribute\n"
4333 "No community attribute\n")
4335 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4336 "community", "none");
4339 DEFUN (no_set_community
,
4340 no_set_community_cmd
,
4341 "no set community AA:NN...",
4344 "BGP community attribute\n"
4347 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4351 ALIAS (no_set_community
,
4352 no_set_community_short_cmd
,
4356 "BGP community attribute\n")
4359 DEFUN (set_community_delete
,
4360 set_community_delete_cmd
,
4361 "set comm-list <(1-99)|(100-500)|WORD> delete",
4363 "set BGP community list (for deletion)\n"
4364 "Community-list number (standard)\n"
4365 "Community-list number (expanded)\n"
4366 "Community-list name\n"
4367 "Delete matching communities\n")
4369 int idx_comm_list
= 2;
4372 args
= argv_concat(argv
, argc
, idx_comm_list
);
4373 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4375 XFREE(MTYPE_TMP
, args
);
4380 DEFUN (no_set_community_delete
,
4381 no_set_community_delete_cmd
,
4382 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4385 "set BGP community list (for deletion)\n"
4386 "Community-list number (standard)\n"
4387 "Community-list number (expanded)\n"
4388 "Community-list name\n"
4389 "Delete matching communities\n")
4391 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4395 DEFUN (set_lcommunity
,
4397 "set large-community AA:BB:CC...",
4399 "BGP large community attribute\n"
4400 "Large Community number in aa:bb:cc format or additive\n")
4405 str
= argv_concat(argv
, argc
, 2);
4406 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4407 "large-community", str
);
4408 XFREE(MTYPE_TMP
, str
);
4413 DEFUN (set_lcommunity_none
,
4414 set_lcommunity_none_cmd
,
4415 "set large-community none",
4417 "BGP large community attribute\n"
4418 "No large community attribute\n")
4420 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4421 "large-community", "none");
4424 DEFUN (no_set_lcommunity
,
4425 no_set_lcommunity_cmd
,
4426 "no set large-community none",
4429 "BGP large community attribute\n"
4430 "No community attribute\n")
4432 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4433 "large-community", NULL
);
4436 DEFUN (no_set_lcommunity1
,
4437 no_set_lcommunity1_cmd
,
4438 "no set large-community AA:BB:CC...",
4441 "BGP large community attribute\n"
4442 "Large community in AA:BB:CC... format or additive\n")
4444 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4445 "large-community", NULL
);
4448 ALIAS (no_set_lcommunity1
,
4449 no_set_lcommunity1_short_cmd
,
4450 "no set large-community",
4453 "BGP large community attribute\n")
4455 DEFUN (set_lcommunity_delete
,
4456 set_lcommunity_delete_cmd
,
4457 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4459 "set BGP large community list (for deletion)\n"
4460 "Large Community-list number (standard)\n"
4461 "Large Communitly-list number (expanded)\n"
4462 "Large Community-list name\n"
4463 "Delete matching large communities\n")
4465 int idx_lcomm_list
= 2;
4468 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
4469 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4470 "large-comm-list", args
);
4471 XFREE(MTYPE_TMP
, args
);
4476 DEFUN (no_set_lcommunity_delete
,
4477 no_set_lcommunity_delete_cmd
,
4478 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4481 "set BGP large community list (for deletion)\n"
4482 "Large Community-list number (standard)\n"
4483 "Large Communitly-list number (expanded)\n"
4484 "Large Community-list name\n"
4485 "Delete matching large communities\n")
4487 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4488 "large-comm-list", NULL
);
4491 ALIAS (no_set_lcommunity_delete
,
4492 no_set_lcommunity_delete_short_cmd
,
4493 "no set large-comm-list",
4496 "set BGP large community list (for deletion)\n")
4498 DEFUN (set_ecommunity_rt
,
4499 set_ecommunity_rt_cmd
,
4500 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4502 "BGP extended community attribute\n"
4503 "Route Target extended community\n"
4504 "VPN extended community\n")
4510 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4511 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4512 "extcommunity rt", str
);
4513 XFREE(MTYPE_TMP
, str
);
4518 DEFUN (no_set_ecommunity_rt
,
4519 no_set_ecommunity_rt_cmd
,
4520 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4523 "BGP extended community attribute\n"
4524 "Route Target extended community\n"
4525 "VPN extended community\n")
4527 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4528 "extcommunity rt", NULL
);
4531 ALIAS (no_set_ecommunity_rt
,
4532 no_set_ecommunity_rt_short_cmd
,
4533 "no set extcommunity rt",
4536 "BGP extended community attribute\n"
4537 "Route Target extended community\n")
4539 DEFUN (set_ecommunity_soo
,
4540 set_ecommunity_soo_cmd
,
4541 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4543 "BGP extended community attribute\n"
4544 "Site-of-Origin extended community\n"
4545 "VPN extended community\n")
4551 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4552 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4553 "extcommunity soo", str
);
4554 XFREE(MTYPE_TMP
, str
);
4559 DEFUN (no_set_ecommunity_soo
,
4560 no_set_ecommunity_soo_cmd
,
4561 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4564 "BGP extended community attribute\n"
4565 "Site-of-Origin extended community\n"
4566 "VPN extended community\n")
4568 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4569 "extcommunity soo", NULL
);
4572 ALIAS (no_set_ecommunity_soo
,
4573 no_set_ecommunity_soo_short_cmd
,
4574 "no set extcommunity soo",
4577 "GP extended community attribute\n"
4578 "Site-of-Origin extended community\n")
4582 "set origin <egp|igp|incomplete>",
4587 "unknown heritage\n")
4590 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4591 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4593 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4594 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4596 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4597 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4598 "origin", "incomplete");
4600 vty_out(vty
, "%% Invalid set origin type\n");
4601 return CMD_WARNING_CONFIG_FAILED
;
4605 DEFUN (no_set_origin
,
4607 "no set origin [<egp|igp|incomplete>]",
4613 "unknown heritage\n")
4615 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4620 DEFUN (set_atomic_aggregate
,
4621 set_atomic_aggregate_cmd
,
4622 "set atomic-aggregate",
4624 "BGP atomic aggregate attribute\n" )
4626 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4627 "atomic-aggregate", NULL
);
4630 DEFUN (no_set_atomic_aggregate
,
4631 no_set_atomic_aggregate_cmd
,
4632 "no set atomic-aggregate",
4635 "BGP atomic aggregate attribute\n" )
4637 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4638 "atomic-aggregate", NULL
);
4641 DEFUN (set_aggregator_as
,
4642 set_aggregator_as_cmd
,
4643 "set aggregator as (1-4294967295) A.B.C.D",
4645 "BGP aggregator attribute\n"
4646 "AS number of aggregator\n"
4648 "IP address of aggregator\n")
4653 struct in_addr address
;
4656 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4658 vty_out(vty
, "Aggregator IP address is invalid\n");
4659 return CMD_WARNING_CONFIG_FAILED
;
4662 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4663 strlen(argv
[idx_number
]->arg
)
4664 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4666 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4668 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4669 "aggregator as", argstr
);
4671 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4677 DEFUN (no_set_aggregator_as
,
4678 no_set_aggregator_as_cmd
,
4679 "no set aggregator as [(1-4294967295) A.B.C.D]",
4682 "BGP aggregator attribute\n"
4683 "AS number of aggregator\n"
4685 "IP address of aggregator\n")
4690 struct in_addr address
;
4693 if (argc
<= idx_asn
)
4694 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4695 "aggregator as", NULL
);
4697 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4699 vty_out(vty
, "Aggregator IP address is invalid\n");
4700 return CMD_WARNING_CONFIG_FAILED
;
4703 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4704 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4707 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4709 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4710 "aggregator as", argstr
);
4712 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4717 DEFUN (match_ipv6_next_hop
,
4718 match_ipv6_next_hop_cmd
,
4719 "match ipv6 next-hop X:X::X:X",
4722 "Match IPv6 next-hop address of route\n"
4723 "IPv6 address of next hop\n")
4726 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4727 RMAP_EVENT_MATCH_ADDED
);
4730 DEFUN (no_match_ipv6_next_hop
,
4731 no_match_ipv6_next_hop_cmd
,
4732 "no match ipv6 next-hop X:X::X:X",
4736 "Match IPv6 next-hop address of route\n"
4737 "IPv6 address of next hop\n")
4740 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4741 RMAP_EVENT_MATCH_DELETED
);
4745 DEFUN (set_ipv6_nexthop_peer
,
4746 set_ipv6_nexthop_peer_cmd
,
4747 "set ipv6 next-hop peer-address",
4750 "Next hop address\n"
4751 "Use peer address (for BGP only)\n")
4753 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4754 "ipv6 next-hop peer-address", NULL
);
4757 DEFUN (no_set_ipv6_nexthop_peer
,
4758 no_set_ipv6_nexthop_peer_cmd
,
4759 "no set ipv6 next-hop peer-address",
4763 "IPv6 next-hop address\n"
4764 "Use peer address (for BGP only)\n")
4766 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4767 "ipv6 next-hop peer-address", NULL
);
4770 DEFUN (set_ipv6_nexthop_prefer_global
,
4771 set_ipv6_nexthop_prefer_global_cmd
,
4772 "set ipv6 next-hop prefer-global",
4775 "IPv6 next-hop address\n"
4776 "Prefer global over link-local if both exist\n")
4778 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4779 "ipv6 next-hop prefer-global", NULL
);
4783 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4784 no_set_ipv6_nexthop_prefer_global_cmd
,
4785 "no set ipv6 next-hop prefer-global",
4789 "IPv6 next-hop address\n"
4790 "Prefer global over link-local if both exist\n")
4792 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4793 "ipv6 next-hop prefer-global", NULL
);
4796 DEFUN (set_ipv6_nexthop_global
,
4797 set_ipv6_nexthop_global_cmd
,
4798 "set ipv6 next-hop global X:X::X:X",
4801 "IPv6 next-hop address\n"
4802 "IPv6 global address\n"
4803 "IPv6 address of next hop\n")
4806 struct in6_addr addr
;
4809 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4811 vty_out(vty
, "%% Malformed nexthop address\n");
4812 return CMD_WARNING_CONFIG_FAILED
;
4814 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4815 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4816 vty_out(vty
, "%% Invalid global nexthop address\n");
4817 return CMD_WARNING_CONFIG_FAILED
;
4820 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4821 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4825 DEFUN (no_set_ipv6_nexthop_global
,
4826 no_set_ipv6_nexthop_global_cmd
,
4827 "no set ipv6 next-hop global X:X::X:X",
4831 "IPv6 next-hop address\n"
4832 "IPv6 global address\n"
4833 "IPv6 address of next hop\n")
4836 if (argc
<= idx_ipv6
)
4837 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4838 "ipv6 next-hop global", NULL
);
4839 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4840 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4843 #ifdef KEEP_OLD_VPN_COMMANDS
4844 DEFUN (set_vpn_nexthop
,
4845 set_vpn_nexthop_cmd
,
4846 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4848 "VPNv4 information\n"
4849 "VPN next-hop address\n"
4850 "IP address of next hop\n"
4851 "VPNv6 information\n"
4852 "VPN next-hop address\n"
4853 "IPv6 address of next hop\n")
4859 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4861 return generic_set_add(
4862 vty
, VTY_GET_CONTEXT(route_map_index
),
4863 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4865 return generic_set_add(
4866 vty
, VTY_GET_CONTEXT(route_map_index
),
4867 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4872 DEFUN (no_set_vpn_nexthop
,
4873 no_set_vpn_nexthop_cmd
,
4874 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4877 "VPNv4 information\n"
4878 "VPN next-hop address\n"
4879 "IP address of next hop\n"
4880 "VPNv6 information\n"
4881 "VPN next-hop address\n"
4882 "IPv6 address of next hop\n")
4892 arg
= argv
[idx_ip
]->arg
;
4893 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4895 return generic_set_delete(
4896 vty
, VTY_GET_CONTEXT(route_map_index
),
4897 "ipv4 vpn next-hop", arg
);
4899 return generic_set_delete(
4900 vty
, VTY_GET_CONTEXT(route_map_index
),
4901 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4905 #endif /* KEEP_OLD_VPN_COMMANDS */
4907 DEFUN (set_ipx_vpn_nexthop
,
4908 set_ipx_vpn_nexthop_cmd
,
4909 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4911 "IPv4 information\n"
4912 "IPv6 information\n"
4914 "VPN next-hop address\n"
4915 "IP address of next hop\n"
4916 "IPv6 address of next hop\n")
4922 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4924 return generic_set_add(
4925 vty
, VTY_GET_CONTEXT(route_map_index
),
4926 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4928 return generic_set_add(
4929 vty
, VTY_GET_CONTEXT(route_map_index
),
4930 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4935 DEFUN (no_set_ipx_vpn_nexthop
,
4936 no_set_ipx_vpn_nexthop_cmd
,
4937 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4940 "IPv4 information\n"
4941 "IPv6 information\n"
4943 "VPN next-hop address\n"
4944 "IP address of next hop\n"
4945 "IPv6 address of next hop\n")
4955 arg
= argv
[idx_ip
]->arg
;
4956 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4958 return generic_set_delete(
4959 vty
, VTY_GET_CONTEXT(route_map_index
),
4960 "ipv4 vpn next-hop", arg
);
4962 return generic_set_delete(
4963 vty
, VTY_GET_CONTEXT(route_map_index
),
4964 "ipv6 vpn next-hop", arg
);
4969 DEFUN (set_originator_id
,
4970 set_originator_id_cmd
,
4971 "set originator-id A.B.C.D",
4973 "BGP originator ID attribute\n"
4974 "IP address of originator\n")
4977 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4978 "originator-id", argv
[idx_ipv4
]->arg
);
4982 DEFUN (no_set_originator_id
,
4983 no_set_originator_id_cmd
,
4984 "no set originator-id [A.B.C.D]",
4987 "BGP originator ID attribute\n"
4988 "IP address of originator\n")
4992 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4994 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4995 "originator-id", arg
);
4999 /* Initialization of route map. */
5000 void bgp_route_map_init(void)
5004 route_map_add_hook(bgp_route_map_add
);
5005 route_map_delete_hook(bgp_route_map_delete
);
5006 route_map_event_hook(bgp_route_map_event
);
5008 route_map_match_interface_hook(generic_match_add
);
5009 route_map_no_match_interface_hook(generic_match_delete
);
5011 route_map_match_ip_address_hook(generic_match_add
);
5012 route_map_no_match_ip_address_hook(generic_match_delete
);
5014 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
5015 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
5017 route_map_match_ip_next_hop_hook(generic_match_add
);
5018 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
5020 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
5021 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5023 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5024 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5026 route_map_match_ipv6_address_hook(generic_match_add
);
5027 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5029 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5030 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5032 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5033 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5035 route_map_match_metric_hook(generic_match_add
);
5036 route_map_no_match_metric_hook(generic_match_delete
);
5038 route_map_match_tag_hook(generic_match_add
);
5039 route_map_no_match_tag_hook(generic_match_delete
);
5041 route_map_set_ip_nexthop_hook(generic_set_add
);
5042 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5044 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5045 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5047 route_map_set_metric_hook(generic_set_add
);
5048 route_map_no_set_metric_hook(generic_set_delete
);
5050 route_map_set_tag_hook(generic_set_add
);
5051 route_map_no_set_tag_hook(generic_set_delete
);
5053 route_map_install_match(&route_match_peer_cmd
);
5054 route_map_install_match(&route_match_local_pref_cmd
);
5055 #if defined(HAVE_LUA)
5056 route_map_install_match(&route_match_command_cmd
);
5058 route_map_install_match(&route_match_ip_address_cmd
);
5059 route_map_install_match(&route_match_ip_next_hop_cmd
);
5060 route_map_install_match(&route_match_ip_route_source_cmd
);
5061 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5062 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5063 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5064 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5065 route_map_install_match(&route_match_aspath_cmd
);
5066 route_map_install_match(&route_match_community_cmd
);
5067 route_map_install_match(&route_match_lcommunity_cmd
);
5068 route_map_install_match(&route_match_ecommunity_cmd
);
5069 route_map_install_match(&route_match_local_pref_cmd
);
5070 route_map_install_match(&route_match_metric_cmd
);
5071 route_map_install_match(&route_match_origin_cmd
);
5072 route_map_install_match(&route_match_probability_cmd
);
5073 route_map_install_match(&route_match_interface_cmd
);
5074 route_map_install_match(&route_match_tag_cmd
);
5075 route_map_install_match(&route_match_mac_address_cmd
);
5076 route_map_install_match(&route_match_evpn_vni_cmd
);
5077 route_map_install_match(&route_match_evpn_route_type_cmd
);
5078 route_map_install_match(&route_match_evpn_default_route_cmd
);
5079 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5081 route_map_install_set(&route_set_ip_nexthop_cmd
);
5082 route_map_install_set(&route_set_local_pref_cmd
);
5083 route_map_install_set(&route_set_weight_cmd
);
5084 route_map_install_set(&route_set_label_index_cmd
);
5085 route_map_install_set(&route_set_metric_cmd
);
5086 route_map_install_set(&route_set_aspath_prepend_cmd
);
5087 route_map_install_set(&route_set_aspath_exclude_cmd
);
5088 route_map_install_set(&route_set_origin_cmd
);
5089 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5090 route_map_install_set(&route_set_aggregator_as_cmd
);
5091 route_map_install_set(&route_set_community_cmd
);
5092 route_map_install_set(&route_set_community_delete_cmd
);
5093 route_map_install_set(&route_set_lcommunity_cmd
);
5094 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5095 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5096 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5097 route_map_install_set(&route_set_originator_id_cmd
);
5098 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5099 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5100 route_map_install_set(&route_set_tag_cmd
);
5101 route_map_install_set(&route_set_label_index_cmd
);
5103 install_element(RMAP_NODE
, &match_peer_cmd
);
5104 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5105 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5106 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5107 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5108 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5109 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5110 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5111 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5112 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5113 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5114 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5115 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5116 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5117 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5118 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5119 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5121 install_element(RMAP_NODE
, &match_aspath_cmd
);
5122 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5123 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5124 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5125 install_element(RMAP_NODE
, &match_community_cmd
);
5126 install_element(RMAP_NODE
, &no_match_community_cmd
);
5127 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5128 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5129 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5130 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5131 install_element(RMAP_NODE
, &match_origin_cmd
);
5132 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5133 install_element(RMAP_NODE
, &match_probability_cmd
);
5134 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5136 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5137 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5138 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5139 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5140 install_element(RMAP_NODE
, &set_weight_cmd
);
5141 install_element(RMAP_NODE
, &set_label_index_cmd
);
5142 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5143 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5144 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5145 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5146 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5147 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5148 install_element(RMAP_NODE
, &no_set_aspath_prepend_lastas_cmd
);
5149 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5150 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5151 install_element(RMAP_NODE
, &set_origin_cmd
);
5152 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5153 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5154 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5155 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5156 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5157 install_element(RMAP_NODE
, &set_community_cmd
);
5158 install_element(RMAP_NODE
, &set_community_none_cmd
);
5159 install_element(RMAP_NODE
, &no_set_community_cmd
);
5160 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5161 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5162 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5163 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5164 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5165 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5166 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5167 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5168 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5169 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5170 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5171 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5172 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5173 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5174 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5175 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5176 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5177 #ifdef KEEP_OLD_VPN_COMMANDS
5178 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5179 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5180 #endif /* KEEP_OLD_VPN_COMMANDS */
5181 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5182 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5183 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5184 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5186 route_map_install_match(&route_match_ipv6_address_cmd
);
5187 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5188 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5189 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5190 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5191 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5192 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5193 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5195 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5196 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5197 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5198 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5199 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5200 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5201 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5202 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5203 #if defined(HAVE_LUA)
5204 install_element(RMAP_NODE
, &match_command_cmd
);
5205 install_element(RMAP_NODE
, &no_match_command_cmd
);
5209 void bgp_route_map_terminate(void)
5211 /* ToDo: Cleanup all the used memory */