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"
67 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
70 #ifndef VTYSH_EXTRACT_PL
71 #include "bgpd/bgp_routemap_clippy.c"
74 /* Memo of route-map commands.
83 ip route-source : Done
87 ipv6 route-source: (This will not be implemented by bgpd)
88 ipv6 prefix-list : Done
89 length : (This will not be implemented by bgpd)
91 route-type : (This will not be implemented by bgpd)
93 local-preference : Done
95 set as-path prepend : Done
97 automatic-tag : (This will not be implemented by bgpd)
99 large-community : Done
100 large-comm-list : Done
103 default : (This will not be implemented by bgpd)
104 interface : (This will not be implemented by bgpd)
105 ip default : (This will not be implemented by bgpd)
107 ip precedence : (This will not be implemented by bgpd)
108 ip tos : (This will not be implemented by bgpd)
109 level : (This will not be implemented by bgpd)
110 local-preference : Done
112 metric-type : Not yet
119 set ipv6 next-hop global: Done
120 set ipv6 next-hop prefer-global: Done
121 set ipv6 next-hop local : Done
122 set as-path exclude : Done
126 /* generic value manipulation to be shared in multiple rules */
128 #define RMAP_VALUE_SET 0
129 #define RMAP_VALUE_ADD 1
130 #define RMAP_VALUE_SUB 2
138 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
140 if (rv
->variable
== 0 && value
== rv
->value
)
146 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
151 switch (rv
->variable
) {
160 switch (rv
->action
) {
162 if (current
> UINT32_MAX
- value
)
164 return current
+ value
;
166 if (current
<= value
)
168 return current
- value
;
174 static void *route_value_compile(const char *arg
)
176 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
177 unsigned long larg
= 0;
179 struct rmap_value
*rv
;
182 action
= RMAP_VALUE_ADD
;
184 } else if (arg
[0] == '-') {
185 action
= RMAP_VALUE_SUB
;
189 if (all_digit(arg
)) {
191 larg
= strtoul(arg
, &endptr
, 10);
192 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
195 if (strcmp(arg
, "rtt") == 0)
201 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
209 static void route_value_free(void *rule
)
211 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
214 /* generic as path object to be shared in multiple rules */
216 static void *route_aspath_compile(const char *arg
)
218 struct aspath
*aspath
;
220 aspath
= aspath_str2aspath(arg
);
226 static void route_aspath_free(void *rule
)
228 struct aspath
*aspath
= rule
;
232 struct bgp_match_peer_compiled
{
237 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
239 /* Compares the peer specified in the 'match peer' clause with the peer
240 received in bgp_path_info->peer. If it is the same, or if the peer structure
241 received is a peer_group containing it, returns RMAP_MATCH. */
242 static route_map_result_t
route_match_peer(void *rule
,
243 const struct prefix
*prefix
,
244 route_map_object_t type
,
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 route_map_result_t
route_match_command(void *rule
,
339 const struct prefix
*prefix
,
340 route_map_object_t type
,
343 int status
= RMAP_NOMATCH
;
344 u_int32_t locpref
= 0;
345 u_int32_t newlocpref
= 0;
346 enum lua_rm_status lrm_status
;
347 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
348 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
354 * Setup the prefix information to pass in
356 lua_setup_prefix_table(L
, prefix
);
358 zlog_debug("Set up prefix table");
360 * Setup the bgp_path_info information
363 lua_pushinteger(L
, path
->attr
->med
);
364 lua_setfield(L
, -2, "metric");
365 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
366 lua_setfield(L
, -2, "ifindex");
367 lua_pushstring(L
, path
->attr
->aspath
->str
);
368 lua_setfield(L
, -2, "aspath");
369 lua_pushinteger(L
, path
->attr
->local_pref
);
370 lua_setfield(L
, -2, "localpref");
371 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
372 lua_setglobal(L
, "nexthop");
374 zlog_debug("Set up nexthop information");
378 lrm_status
= lua_run_rm_rule(L
, rule
);
379 switch (lrm_status
) {
381 zlog_debug("RM_FAILURE");
384 zlog_debug("RM_NOMATCH");
386 case LUA_RM_MATCH_AND_CHANGE
:
387 zlog_debug("MATCH AND CHANGE");
388 lua_getglobal(L
, "nexthop");
389 path
->attr
->med
= get_integer(L
, "metric");
391 * This needs to be abstraced with the set function
393 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
394 locpref
= path
->attr
->local_pref
;
395 newlocpref
= get_integer(L
, "localpref");
396 if (newlocpref
!= locpref
) {
397 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
398 path
->attr
->local_pref
= newlocpref
;
403 zlog_debug("MATCH ONLY");
411 static void *route_match_command_compile(const char *arg
)
415 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
420 route_match_command_free(void *rule
)
422 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
425 struct route_map_rule_cmd route_match_command_cmd
= {
428 route_match_command_compile
,
429 route_match_command_free
433 /* `match ip address IP_ACCESS_LIST' */
435 /* Match function should return 1 if match is success else return
437 static route_map_result_t
route_match_ip_address(void *rule
,
438 const struct prefix
*prefix
,
439 route_map_object_t type
,
442 struct access_list
*alist
;
444 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
445 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
449 return (access_list_apply(alist
, prefix
) == FILTER_DENY
456 /* Route map `ip address' match statement. `arg' should be
458 static void *route_match_ip_address_compile(const char *arg
)
460 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
463 /* Free route map's compiled `ip address' value. */
464 static void route_match_ip_address_free(void *rule
)
466 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
469 /* Route map commands for ip address matching. */
470 struct route_map_rule_cmd route_match_ip_address_cmd
= {
471 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
472 route_match_ip_address_free
};
474 /* `match ip next-hop IP_ADDRESS' */
476 /* Match function return 1 if match is success else return zero. */
477 static route_map_result_t
route_match_ip_next_hop(void *rule
,
478 const struct prefix
*prefix
,
479 route_map_object_t type
,
482 struct access_list
*alist
;
483 struct bgp_path_info
*path
;
484 struct prefix_ipv4 p
;
486 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
489 p
.prefix
= path
->attr
->nexthop
;
490 p
.prefixlen
= IPV4_MAX_BITLEN
;
492 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
496 return (access_list_apply(alist
, &p
) == FILTER_DENY
503 /* Route map `ip next-hop' match statement. `arg' is
505 static void *route_match_ip_next_hop_compile(const char *arg
)
507 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
510 /* Free route map's compiled `ip address' value. */
511 static void route_match_ip_next_hop_free(void *rule
)
513 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
516 /* Route map commands for ip next-hop matching. */
517 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
518 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
519 route_match_ip_next_hop_free
};
521 /* `match ip route-source ACCESS-LIST' */
523 /* Match function return 1 if match is success else return zero. */
524 static route_map_result_t
route_match_ip_route_source(void *rule
,
525 const struct prefix
*pfx
,
526 route_map_object_t type
,
529 struct access_list
*alist
;
530 struct bgp_path_info
*path
;
532 struct prefix_ipv4 p
;
534 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
538 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
542 p
.prefix
= peer
->su
.sin
.sin_addr
;
543 p
.prefixlen
= IPV4_MAX_BITLEN
;
545 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
549 return (access_list_apply(alist
, &p
) == FILTER_DENY
556 /* Route map `ip route-source' match statement. `arg' is
558 static void *route_match_ip_route_source_compile(const char *arg
)
560 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
563 /* Free route map's compiled `ip address' value. */
564 static void route_match_ip_route_source_free(void *rule
)
566 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
569 /* Route map commands for ip route-source matching. */
570 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
571 "ip route-source", route_match_ip_route_source
,
572 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
574 static route_map_result_t
route_match_prefix_list_flowspec(afi_t afi
,
575 struct prefix_list
*plist
,
576 const struct prefix
*p
)
579 struct bgp_pbr_entry_main api
;
581 memset(&api
, 0, sizeof(api
));
583 /* extract match from flowspec entries */
584 ret
= bgp_flowspec_match_rules_fill(
585 (uint8_t *)p
->u
.prefix_flowspec
.ptr
,
586 p
->u
.prefix_flowspec
.prefixlen
, &api
);
589 if (api
.match_bitmask
& PREFIX_DST_PRESENT
||
590 api
.match_bitmask_iprule
& PREFIX_DST_PRESENT
) {
591 if (family2afi((&api
.dst_prefix
)->family
) != afi
)
593 return prefix_list_apply(plist
, &api
.dst_prefix
) == PREFIX_DENY
596 } else if (api
.match_bitmask
& PREFIX_SRC_PRESENT
||
597 api
.match_bitmask_iprule
& PREFIX_SRC_PRESENT
) {
598 if (family2afi((&api
.src_prefix
)->family
) != afi
)
600 return (prefix_list_apply(plist
, &api
.src_prefix
) == PREFIX_DENY
607 /* `match ip address prefix-list PREFIX_LIST' */
608 static route_map_result_t
609 route_match_address_prefix_list(void *rule
, afi_t afi
,
610 const struct prefix
*prefix
,
611 route_map_object_t type
, void *object
)
613 struct prefix_list
*plist
;
615 if (type
!= RMAP_BGP
)
618 plist
= prefix_list_lookup(afi
, (char *)rule
);
622 if (prefix
->family
== AF_FLOWSPEC
)
623 return route_match_prefix_list_flowspec(afi
, plist
,
625 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
? RMAP_NOMATCH
629 static route_map_result_t
630 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
631 route_map_object_t type
, void *object
)
633 return route_match_address_prefix_list(rule
, AFI_IP
, prefix
, type
,
637 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
639 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
642 static void route_match_ip_address_prefix_list_free(void *rule
)
644 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
647 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
648 "ip address prefix-list", route_match_ip_address_prefix_list
,
649 route_match_ip_address_prefix_list_compile
,
650 route_match_ip_address_prefix_list_free
};
652 /* `match ip next-hop prefix-list PREFIX_LIST' */
654 static route_map_result_t
655 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
656 route_map_object_t type
, void *object
)
658 struct prefix_list
*plist
;
659 struct bgp_path_info
*path
;
660 struct prefix_ipv4 p
;
662 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
665 p
.prefix
= path
->attr
->nexthop
;
666 p
.prefixlen
= IPV4_MAX_BITLEN
;
668 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
672 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
679 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
681 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
684 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
686 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
689 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
690 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
691 route_match_ip_next_hop_prefix_list_compile
,
692 route_match_ip_next_hop_prefix_list_free
};
694 /* `match ip next-hop type <blackhole>' */
696 static route_map_result_t
697 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
698 route_map_object_t type
, void *object
)
700 struct bgp_path_info
*path
;
702 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
703 path
= (struct bgp_path_info
*)object
;
704 if (!path
|| !path
->attr
)
705 return RMAP_DENYMATCH
;
707 /* If nexthop interface's index can't be resolved and nexthop is
708 set to any address then mark it as type `blackhole`.
709 This logic works for matching kernel/static routes like:
710 `ip route add blackhole 10.0.0.1`. */
711 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
712 && !path
->attr
->nh_ifindex
)
718 static void *route_match_ip_next_hop_type_compile(const char *arg
)
720 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
723 static void route_match_ip_next_hop_type_free(void *rule
)
725 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
728 static struct route_map_rule_cmd route_match_ip_next_hop_type_cmd
= {
729 "ip next-hop type", route_match_ip_next_hop_type
,
730 route_match_ip_next_hop_type_compile
,
731 route_match_ip_next_hop_type_free
};
733 /* `match ip route-source prefix-list PREFIX_LIST' */
735 static route_map_result_t
736 route_match_ip_route_source_prefix_list(void *rule
,
737 const struct prefix
*prefix
,
738 route_map_object_t type
, void *object
)
740 struct prefix_list
*plist
;
741 struct bgp_path_info
*path
;
743 struct prefix_ipv4 p
;
745 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
749 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
753 p
.prefix
= peer
->su
.sin
.sin_addr
;
754 p
.prefixlen
= IPV4_MAX_BITLEN
;
756 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
760 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
767 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
769 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
772 static void route_match_ip_route_source_prefix_list_free(void *rule
)
774 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
777 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
778 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
779 route_match_ip_route_source_prefix_list_compile
,
780 route_match_ip_route_source_prefix_list_free
};
782 /* `match evpn default-route' */
784 /* Match function should return 1 if match is success else 0 */
785 static route_map_result_t
route_match_evpn_default_route(void *rule
,
786 const struct prefix
*p
,
790 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
796 /* Route map commands for default-route matching. */
797 struct route_map_rule_cmd route_match_evpn_default_route_cmd
= {
798 "evpn default-route", route_match_evpn_default_route
, NULL
, NULL
};
800 /* `match mac address MAC_ACCESS_LIST' */
802 /* Match function should return 1 if match is success else return
804 static route_map_result_t
route_match_mac_address(void *rule
,
805 const struct prefix
*prefix
,
806 route_map_object_t type
,
809 struct access_list
*alist
;
812 if (type
== RMAP_BGP
) {
813 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
817 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
820 p
.family
= AF_ETHERNET
;
821 p
.prefixlen
= ETH_ALEN
* 8;
822 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
824 return (access_list_apply(alist
, &p
) == FILTER_DENY
832 /* Route map `mac address' match statement. `arg' should be
834 static void *route_match_mac_address_compile(const char *arg
)
836 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
839 /* Free route map's compiled `ip address' value. */
840 static void route_match_mac_address_free(void *rule
)
842 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
845 /* Route map commands for mac address matching. */
846 struct route_map_rule_cmd route_match_mac_address_cmd
= {
847 "mac address", route_match_mac_address
, route_match_mac_address_compile
,
848 route_match_mac_address_free
};
852 /* Match function should return 1 if match is success else return
854 static route_map_result_t
route_match_vni(void *rule
,
855 const struct prefix
*prefix
,
856 route_map_object_t type
, void *object
)
859 struct bgp_path_info
*path
= NULL
;
861 if (type
== RMAP_BGP
) {
862 vni
= *((vni_t
*)rule
);
863 path
= (struct bgp_path_info
*)object
;
865 if (path
->extra
== NULL
)
868 if (vni
== label2vni(&path
->extra
->label
[0]))
875 /* Route map `vni' match statement. */
876 static void *route_match_vni_compile(const char *arg
)
881 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
883 *vni
= strtoul(arg
, &end
, 10);
885 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
892 /* Free route map's compiled `vni' value. */
893 static void route_match_vni_free(void *rule
)
895 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
898 /* Route map commands for vni matching. */
899 struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
900 "evpn vni", route_match_vni
, route_match_vni_compile
,
901 route_match_vni_free
};
903 /* `match evpn route-type' */
905 /* Match function should return 1 if match is success else return
907 static route_map_result_t
route_match_evpn_route_type(void *rule
,
908 const struct prefix
*pfx
,
909 route_map_object_t type
,
912 uint8_t route_type
= 0;
914 if (type
== RMAP_BGP
) {
915 route_type
= *((uint8_t *)rule
);
917 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
924 /* Route map `route-type' match statement. */
925 static void *route_match_evpn_route_type_compile(const char *arg
)
927 uint8_t *route_type
= NULL
;
929 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
931 if (strncmp(arg
, "ma", 2) == 0)
932 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
933 else if (strncmp(arg
, "mu", 2) == 0)
934 *route_type
= BGP_EVPN_IMET_ROUTE
;
936 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
941 /* Free route map's compiled `route-type' value. */
942 static void route_match_evpn_route_type_free(void *rule
)
944 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
947 /* Route map commands for evpn route-type matching. */
948 struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
949 "evpn route-type", route_match_evpn_route_type
,
950 route_match_evpn_route_type_compile
, route_match_evpn_route_type_free
};
952 /* Route map commands for VRF route leak with source vrf matching */
953 static route_map_result_t
954 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
955 route_map_object_t type
, void *object
)
957 struct bgp_path_info
*path
;
960 if (type
== RMAP_BGP
) {
962 path
= (struct bgp_path_info
*)object
;
964 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
967 if (path
->extra
== NULL
)
970 if (strncmp(vrf_name
, vrf_id_to_name(
971 path
->extra
->bgp_orig
->vrf_id
), VRF_NAMSIZ
)
979 static void *route_match_vrl_source_vrf_compile(const char *arg
)
981 uint8_t *vrf_name
= NULL
;
983 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
988 /* Free route map's compiled `route-type' value. */
989 static void route_match_vrl_source_vrf_free(void *rule
)
991 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
994 struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
995 "source-vrf", route_match_vrl_source_vrf
,
996 route_match_vrl_source_vrf_compile
,
997 route_match_vrl_source_vrf_free
};
999 /* `match local-preference LOCAL-PREF' */
1001 /* Match function return 1 if match is success else return zero. */
1002 static route_map_result_t
route_match_local_pref(void *rule
,
1003 const struct prefix
*prefix
,
1004 route_map_object_t type
,
1007 uint32_t *local_pref
;
1008 struct bgp_path_info
*path
;
1010 if (type
== RMAP_BGP
) {
1014 if (path
->attr
->local_pref
== *local_pref
)
1017 return RMAP_NOMATCH
;
1019 return RMAP_NOMATCH
;
1022 /* Route map `match local-preference' match statement.
1023 `arg' is local-pref value */
1024 static void *route_match_local_pref_compile(const char *arg
)
1026 uint32_t *local_pref
;
1027 char *endptr
= NULL
;
1028 unsigned long tmpval
;
1030 /* Locpref value shoud be integer. */
1031 if (!all_digit(arg
))
1035 tmpval
= strtoul(arg
, &endptr
, 10);
1036 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1039 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1041 *local_pref
= tmpval
;
1045 /* Free route map's compiled `match local-preference' value. */
1046 static void route_match_local_pref_free(void *rule
)
1048 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1051 /* Route map commands for metric matching. */
1052 struct route_map_rule_cmd route_match_local_pref_cmd
= {
1053 "local-preference", route_match_local_pref
,
1054 route_match_local_pref_compile
, route_match_local_pref_free
};
1056 /* `match metric METRIC' */
1058 /* Match function return 1 if match is success else return zero. */
1059 static route_map_result_t
route_match_metric(void *rule
,
1060 const struct prefix
*prefix
,
1061 route_map_object_t type
,
1064 struct rmap_value
*rv
;
1065 struct bgp_path_info
*path
;
1067 if (type
== RMAP_BGP
) {
1070 return route_value_match(rv
, path
->attr
->med
);
1072 return RMAP_NOMATCH
;
1075 /* Route map commands for metric matching. */
1076 struct route_map_rule_cmd route_match_metric_cmd
= {
1077 "metric", route_match_metric
, route_value_compile
, route_value_free
,
1080 /* `match as-path ASPATH' */
1082 /* Match function for as-path match. I assume given object is */
1083 static route_map_result_t
route_match_aspath(void *rule
,
1084 const struct prefix
*prefix
,
1085 route_map_object_t type
,
1089 struct as_list
*as_list
;
1090 struct bgp_path_info
*path
;
1092 if (type
== RMAP_BGP
) {
1093 as_list
= as_list_lookup((char *)rule
);
1094 if (as_list
== NULL
)
1095 return RMAP_NOMATCH
;
1099 /* Perform match. */
1100 return ((as_list_apply(as_list
, path
->attr
->aspath
)
1105 return RMAP_NOMATCH
;
1108 /* Compile function for as-path match. */
1109 static void *route_match_aspath_compile(const char *arg
)
1111 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1114 /* Compile function for as-path match. */
1115 static void route_match_aspath_free(void *rule
)
1117 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1120 /* Route map commands for aspath matching. */
1121 struct route_map_rule_cmd route_match_aspath_cmd
= {
1122 "as-path", route_match_aspath
, route_match_aspath_compile
,
1123 route_match_aspath_free
};
1125 /* `match community COMMUNIY' */
1126 struct rmap_community
{
1132 /* Match function for community match. */
1133 static route_map_result_t
route_match_community(void *rule
,
1134 const struct prefix
*prefix
,
1135 route_map_object_t type
,
1138 struct community_list
*list
;
1139 struct bgp_path_info
*path
;
1140 struct rmap_community
*rcom
= rule
;
1142 if (type
== RMAP_BGP
) {
1146 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1148 COMMUNITY_LIST_MASTER
);
1150 return RMAP_NOMATCH
;
1153 if (community_list_exact_match(path
->attr
->community
,
1157 if (community_list_match(path
->attr
->community
, list
))
1161 return RMAP_NOMATCH
;
1164 /* Compile function for community match. */
1165 static void *route_match_community_compile(const char *arg
)
1167 struct rmap_community
*rcom
;
1171 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1173 p
= strchr(arg
, ' ');
1176 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1177 memcpy(rcom
->name
, arg
, len
);
1180 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1184 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1188 /* Compile function for community match. */
1189 static void route_match_community_free(void *rule
)
1191 struct rmap_community
*rcom
= rule
;
1193 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1194 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1197 /* Route map commands for community matching. */
1198 struct route_map_rule_cmd route_match_community_cmd
= {
1199 "community", route_match_community
, route_match_community_compile
,
1200 route_match_community_free
};
1202 /* Match function for lcommunity match. */
1203 static route_map_result_t
route_match_lcommunity(void *rule
,
1204 const struct prefix
*prefix
,
1205 route_map_object_t type
,
1208 struct community_list
*list
;
1209 struct bgp_path_info
*path
;
1210 struct rmap_community
*rcom
= rule
;
1212 if (type
== RMAP_BGP
) {
1215 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1217 LARGE_COMMUNITY_LIST_MASTER
);
1219 return RMAP_NOMATCH
;
1222 if (lcommunity_list_exact_match(
1223 path
->attr
->lcommunity
,
1227 if (lcommunity_list_match(
1228 path
->attr
->lcommunity
,
1233 return RMAP_NOMATCH
;
1236 /* Compile function for community match. */
1237 static void *route_match_lcommunity_compile(const char *arg
)
1239 struct rmap_community
*rcom
;
1243 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1245 p
= strchr(arg
, ' ');
1248 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1249 memcpy(rcom
->name
, arg
, len
);
1252 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1256 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1260 /* Compile function for community match. */
1261 static void route_match_lcommunity_free(void *rule
)
1263 struct rmap_community
*rcom
= rule
;
1265 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1266 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1269 /* Route map commands for community matching. */
1270 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1271 "large-community", route_match_lcommunity
,
1272 route_match_lcommunity_compile
, route_match_lcommunity_free
};
1275 /* Match function for extcommunity match. */
1276 static route_map_result_t
route_match_ecommunity(void *rule
,
1277 const struct prefix
*prefix
,
1278 route_map_object_t type
,
1281 struct community_list
*list
;
1282 struct bgp_path_info
*path
;
1283 struct rmap_community
*rcom
= rule
;
1285 if (type
== RMAP_BGP
) {
1288 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1290 EXTCOMMUNITY_LIST_MASTER
);
1292 return RMAP_NOMATCH
;
1294 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1297 return RMAP_NOMATCH
;
1300 /* Compile function for extcommunity match. */
1301 static void *route_match_ecommunity_compile(const char *arg
)
1303 struct rmap_community
*rcom
;
1305 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1306 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1307 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1312 /* Compile function for extcommunity match. */
1313 static void route_match_ecommunity_free(void *rule
)
1315 struct rmap_community
*rcom
= rule
;
1317 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1318 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1321 /* Route map commands for community matching. */
1322 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1323 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1324 route_match_ecommunity_free
};
1326 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1327 and `address-family vpnv4'. */
1329 /* `match origin' */
1330 static route_map_result_t
route_match_origin(void *rule
,
1331 const struct prefix
*prefix
,
1332 route_map_object_t type
,
1336 struct bgp_path_info
*path
;
1338 if (type
== RMAP_BGP
) {
1342 if (path
->attr
->origin
== *origin
)
1346 return RMAP_NOMATCH
;
1349 static void *route_match_origin_compile(const char *arg
)
1353 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1355 if (strcmp(arg
, "igp") == 0)
1357 else if (strcmp(arg
, "egp") == 0)
1365 /* Free route map's compiled `ip address' value. */
1366 static void route_match_origin_free(void *rule
)
1368 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1371 /* Route map commands for origin matching. */
1372 struct route_map_rule_cmd route_match_origin_cmd
= {
1373 "origin", route_match_origin
, route_match_origin_compile
,
1374 route_match_origin_free
};
1376 /* match probability { */
1378 static route_map_result_t
route_match_probability(void *rule
,
1379 const struct prefix
*prefix
,
1380 route_map_object_t type
,
1385 switch (*(long *)rule
) {
1391 if (r
< *(long *)rule
) {
1396 return RMAP_NOMATCH
;
1399 static void *route_match_probability_compile(const char *arg
)
1405 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1415 *lobule
= RAND_MAX
/ 100 * perc
;
1421 static void route_match_probability_free(void *rule
)
1423 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1426 struct route_map_rule_cmd route_match_probability_cmd
= {
1427 "probability", route_match_probability
, route_match_probability_compile
,
1428 route_match_probability_free
};
1430 /* `match interface IFNAME' */
1431 /* Match function should return 1 if match is success else return
1433 static route_map_result_t
route_match_interface(void *rule
,
1434 const struct prefix
*prefix
,
1435 route_map_object_t type
,
1438 struct interface
*ifp
;
1439 struct bgp_path_info
*path
;
1441 if (type
== RMAP_BGP
) {
1444 if (!path
|| !path
->attr
)
1445 return RMAP_NOMATCH
;
1447 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1449 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1450 return RMAP_NOMATCH
;
1454 return RMAP_NOMATCH
;
1457 /* Route map `interface' match statement. `arg' should be
1459 static void *route_match_interface_compile(const char *arg
)
1461 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1464 /* Free route map's compiled `interface' value. */
1465 static void route_match_interface_free(void *rule
)
1467 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1470 /* Route map commands for ip address matching. */
1471 struct route_map_rule_cmd route_match_interface_cmd
= {
1472 "interface", route_match_interface
, route_match_interface_compile
,
1473 route_match_interface_free
};
1477 /* `set ip next-hop IP_ADDRESS' */
1479 /* Match function return 1 if match is success else return zero. */
1480 static route_map_result_t
route_match_tag(void *rule
,
1481 const struct prefix
*prefix
,
1482 route_map_object_t type
, void *object
)
1485 struct bgp_path_info
*path
;
1487 if (type
== RMAP_BGP
) {
1491 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1494 return RMAP_NOMATCH
;
1498 /* Route map commands for tag matching. */
1499 static struct route_map_rule_cmd route_match_tag_cmd
= {
1500 "tag", route_match_tag
, route_map_rule_tag_compile
,
1501 route_map_rule_tag_free
,
1505 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1506 struct rmap_ip_nexthop_set
{
1507 struct in_addr
*address
;
1512 static route_map_result_t
route_set_ip_nexthop(void *rule
,
1513 const struct prefix
*prefix
,
1514 route_map_object_t type
,
1517 struct rmap_ip_nexthop_set
*rins
= rule
;
1518 struct bgp_path_info
*path
;
1521 if (type
!= RMAP_BGP
)
1524 if (prefix
->family
== AF_INET6
)
1530 if (rins
->unchanged
) {
1531 SET_FLAG(path
->attr
->rmap_change_flags
,
1532 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1533 } else if (rins
->peer_address
) {
1534 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1535 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1537 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1538 path
->attr
->nexthop
.s_addr
=
1539 sockunion2ip(peer
->su_remote
);
1540 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1541 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1542 /* The next hop value will be set as part of
1543 * packet rewrite. Set the flags here to indicate
1544 * that rewrite needs to be done.
1545 * Also, clear the value.
1547 SET_FLAG(path
->attr
->rmap_change_flags
,
1548 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1549 path
->attr
->nexthop
.s_addr
= 0;
1552 /* Set next hop value. */
1553 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1554 path
->attr
->nexthop
= *rins
->address
;
1555 SET_FLAG(path
->attr
->rmap_change_flags
,
1556 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1557 /* case for MP-BGP : MPLS VPN */
1558 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1559 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1565 /* Route map `ip nexthop' compile function. Given string is converted
1566 to struct in_addr structure. */
1567 static void *route_set_ip_nexthop_compile(const char *arg
)
1569 struct rmap_ip_nexthop_set
*rins
;
1570 struct in_addr
*address
= NULL
;
1571 int peer_address
= 0;
1575 if (strcmp(arg
, "peer-address") == 0)
1577 else if (strcmp(arg
, "unchanged") == 0)
1580 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1581 sizeof(struct in_addr
));
1582 ret
= inet_aton(arg
, address
);
1585 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1590 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1591 sizeof(struct rmap_ip_nexthop_set
));
1593 rins
->address
= address
;
1594 rins
->peer_address
= peer_address
;
1595 rins
->unchanged
= unchanged
;
1600 /* Free route map's compiled `ip nexthop' value. */
1601 static void route_set_ip_nexthop_free(void *rule
)
1603 struct rmap_ip_nexthop_set
*rins
= rule
;
1605 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1607 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1610 /* Route map commands for ip nexthop set. */
1611 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1612 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1613 route_set_ip_nexthop_free
};
1615 /* `set local-preference LOCAL_PREF' */
1617 /* Set local preference. */
1618 static route_map_result_t
route_set_local_pref(void *rule
,
1619 const struct prefix
*prefix
,
1620 route_map_object_t type
,
1623 struct rmap_value
*rv
;
1624 struct bgp_path_info
*path
;
1625 uint32_t locpref
= 0;
1627 if (type
== RMAP_BGP
) {
1628 /* Fetch routemap's rule information. */
1632 /* Set local preference value. */
1633 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1634 locpref
= path
->attr
->local_pref
;
1636 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1637 path
->attr
->local_pref
=
1638 route_value_adjust(rv
, locpref
, path
->peer
);
1644 /* Set local preference rule structure. */
1645 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1646 "local-preference", route_set_local_pref
, route_value_compile
,
1650 /* `set weight WEIGHT' */
1653 static route_map_result_t
route_set_weight(void *rule
,
1654 const struct prefix
*prefix
,
1655 route_map_object_t type
,
1658 struct rmap_value
*rv
;
1659 struct bgp_path_info
*path
;
1661 if (type
== RMAP_BGP
) {
1662 /* Fetch routemap's rule information. */
1666 /* Set weight value. */
1667 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1673 /* Set local preference rule structure. */
1674 struct route_map_rule_cmd route_set_weight_cmd
= {
1675 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1678 /* `set metric METRIC' */
1680 /* Set metric to attribute. */
1681 static route_map_result_t
route_set_metric(void *rule
,
1682 const struct prefix
*prefix
,
1683 route_map_object_t type
,
1686 struct rmap_value
*rv
;
1687 struct bgp_path_info
*path
;
1690 if (type
== RMAP_BGP
) {
1691 /* Fetch routemap's rule information. */
1695 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1696 med
= path
->attr
->med
;
1698 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1699 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1704 /* Set metric rule structure. */
1705 struct route_map_rule_cmd route_set_metric_cmd
= {
1706 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1709 /* `set as-path prepend ASPATH' */
1711 /* For AS path prepend mechanism. */
1712 static route_map_result_t
route_set_aspath_prepend(void *rule
,
1713 const struct prefix
*prefix
,
1714 route_map_object_t type
,
1717 struct aspath
*aspath
;
1719 struct bgp_path_info
*path
;
1721 if (type
== RMAP_BGP
) {
1724 if (path
->attr
->aspath
->refcnt
)
1725 new = aspath_dup(path
->attr
->aspath
);
1727 new = path
->attr
->aspath
;
1729 if ((uintptr_t)rule
> 10) {
1731 aspath_prepend(aspath
, new);
1733 as_t as
= aspath_leftmost(new);
1735 as
= path
->peer
->as
;
1736 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1739 path
->attr
->aspath
= new;
1745 static void *route_set_aspath_prepend_compile(const char *arg
)
1749 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1750 return (void *)(uintptr_t)num
;
1752 return route_aspath_compile(arg
);
1755 static void route_set_aspath_prepend_free(void *rule
)
1757 if ((uintptr_t)rule
> 10)
1758 route_aspath_free(rule
);
1762 /* Set as-path prepend rule structure. */
1763 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1764 "as-path prepend", route_set_aspath_prepend
,
1765 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1768 /* `set as-path exclude ASn' */
1770 /* For ASN exclude mechanism.
1771 * Iterate over ASns requested and filter them from the given AS_PATH one by
1773 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1775 static route_map_result_t
route_set_aspath_exclude(void *rule
,
1776 const struct prefix
*dummy
,
1777 route_map_object_t type
,
1780 struct aspath
*new_path
, *exclude_path
;
1781 struct bgp_path_info
*path
;
1783 if (type
== RMAP_BGP
) {
1784 exclude_path
= rule
;
1786 if (path
->attr
->aspath
->refcnt
)
1787 new_path
= aspath_dup(path
->attr
->aspath
);
1789 new_path
= path
->attr
->aspath
;
1790 path
->attr
->aspath
=
1791 aspath_filter_exclude(new_path
, exclude_path
);
1796 /* Set ASn exlude rule structure. */
1797 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1798 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1802 /* `set community COMMUNITY' */
1803 struct rmap_com_set
{
1804 struct community
*com
;
1809 /* For community set mechanism. */
1810 static route_map_result_t
route_set_community(void *rule
,
1811 const struct prefix
*prefix
,
1812 route_map_object_t type
,
1815 struct rmap_com_set
*rcs
;
1816 struct bgp_path_info
*path
;
1818 struct community
*new = NULL
;
1819 struct community
*old
;
1820 struct community
*merge
;
1822 if (type
== RMAP_BGP
) {
1826 old
= attr
->community
;
1830 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1831 attr
->community
= NULL
;
1832 /* See the longer comment down below. */
1833 if (old
&& old
->refcnt
== 0)
1834 community_free(&old
);
1838 /* "additive" case. */
1839 if (rcs
->additive
&& old
) {
1840 merge
= community_merge(community_dup(old
), rcs
->com
);
1842 new = community_uniq_sort(merge
);
1843 community_free(&merge
);
1845 new = community_dup(rcs
->com
);
1847 /* HACK: if the old community is not intern'd,
1848 * we should free it here, or all reference to it may be
1850 * Really need to cleanup attribute caching sometime.
1852 if (old
&& old
->refcnt
== 0)
1853 community_free(&old
);
1855 /* will be interned by caller if required */
1856 attr
->community
= new;
1858 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1864 /* Compile function for set community. */
1865 static void *route_set_community_compile(const char *arg
)
1867 struct rmap_com_set
*rcs
;
1868 struct community
*com
= NULL
;
1873 if (strcmp(arg
, "none") == 0)
1876 sp
= strstr(arg
, "additive");
1878 if (sp
&& sp
> arg
) {
1879 /* "additive" keyword is included. */
1884 com
= community_str2com(arg
);
1893 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1895 rcs
->additive
= additive
;
1901 /* Free function for set community. */
1902 static void route_set_community_free(void *rule
)
1904 struct rmap_com_set
*rcs
= rule
;
1907 community_free(&rcs
->com
);
1908 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1911 /* Set community rule structure. */
1912 struct route_map_rule_cmd route_set_community_cmd
= {
1913 "community", route_set_community
, route_set_community_compile
,
1914 route_set_community_free
,
1917 /* `set community COMMUNITY' */
1918 struct rmap_lcom_set
{
1919 struct lcommunity
*lcom
;
1925 /* For lcommunity set mechanism. */
1926 static route_map_result_t
route_set_lcommunity(void *rule
,
1927 const struct prefix
*prefix
,
1928 route_map_object_t type
,
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 route_map_result_t
route_set_lcommunity_delete(void *rule
,
2040 const struct prefix
*pfx
,
2041 route_map_object_t type
,
2044 struct community_list
*list
;
2045 struct lcommunity
*merge
;
2046 struct lcommunity
*new;
2047 struct lcommunity
*old
;
2048 struct bgp_path_info
*path
;
2049 struct rmap_community
*rcom
= rule
;
2051 if (type
== RMAP_BGP
) {
2056 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2058 LARGE_COMMUNITY_LIST_MASTER
);
2059 old
= path
->attr
->lcommunity
;
2062 merge
= lcommunity_list_match_delete(
2063 lcommunity_dup(old
), list
);
2064 new = lcommunity_uniq_sort(merge
);
2065 lcommunity_free(&merge
);
2067 /* HACK: if the old community is not intern'd,
2068 * we should free it here, or all reference to it may be
2070 * Really need to cleanup attribute caching sometime.
2072 if (old
->refcnt
== 0)
2073 lcommunity_free(&old
);
2075 if (new->size
== 0) {
2076 path
->attr
->lcommunity
= NULL
;
2077 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2078 BGP_ATTR_LARGE_COMMUNITIES
);
2079 lcommunity_free(&new);
2081 path
->attr
->lcommunity
= new;
2082 path
->attr
->flag
|= ATTR_FLAG_BIT(
2083 BGP_ATTR_LARGE_COMMUNITIES
);
2091 /* Compile function for set lcommunity. */
2092 static void *route_set_lcommunity_delete_compile(const char *arg
)
2094 struct rmap_community
*rcom
;
2096 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2098 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2099 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2104 /* Free function for set lcommunity. */
2105 static void route_set_lcommunity_delete_free(void *rule
)
2107 struct rmap_community
*rcom
= rule
;
2109 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2110 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2113 /* Set lcommunity rule structure. */
2114 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2115 "large-comm-list", route_set_lcommunity_delete
,
2116 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2120 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2122 /* For community set mechanism. */
2123 static route_map_result_t
route_set_community_delete(
2125 const struct prefix
*prefix
,
2126 route_map_object_t type
,
2129 struct community_list
*list
;
2130 struct community
*merge
;
2131 struct community
*new;
2132 struct community
*old
;
2133 struct bgp_path_info
*path
;
2134 struct rmap_community
*rcom
= rule
;
2136 if (type
== RMAP_BGP
) {
2141 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2143 COMMUNITY_LIST_MASTER
);
2144 old
= path
->attr
->community
;
2147 merge
= community_list_match_delete(community_dup(old
),
2149 new = community_uniq_sort(merge
);
2150 community_free(&merge
);
2152 /* HACK: if the old community is not intern'd,
2153 * we should free it here, or all reference to it may be
2155 * Really need to cleanup attribute caching sometime.
2157 if (old
->refcnt
== 0)
2158 community_free(&old
);
2160 if (new->size
== 0) {
2161 path
->attr
->community
= NULL
;
2163 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2164 community_free(&new);
2166 path
->attr
->community
= new;
2168 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2176 /* Compile function for set community. */
2177 static void *route_set_community_delete_compile(const char *arg
)
2179 struct rmap_community
*rcom
;
2181 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2183 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2184 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2189 /* Free function for set community. */
2190 static void route_set_community_delete_free(void *rule
)
2192 struct rmap_community
*rcom
= rule
;
2194 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2195 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2198 /* Set community rule structure. */
2199 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2200 "comm-list", route_set_community_delete
,
2201 route_set_community_delete_compile
, route_set_community_delete_free
,
2204 /* `set extcommunity rt COMMUNITY' */
2206 /* For community set mechanism. Used by _rt and _soo. */
2207 static route_map_result_t
route_set_ecommunity(void *rule
,
2208 const struct prefix
*prefix
,
2209 route_map_object_t type
,
2212 struct ecommunity
*ecom
;
2213 struct ecommunity
*new_ecom
;
2214 struct ecommunity
*old_ecom
;
2215 struct bgp_path_info
*path
;
2217 if (type
== RMAP_BGP
) {
2224 /* We assume additive for Extended Community. */
2225 old_ecom
= path
->attr
->ecommunity
;
2228 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2231 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2232 * bgp_update_receive()
2233 * ->refcnt = 0 => set by a previous route-map
2235 if (!old_ecom
->refcnt
)
2236 ecommunity_free(&old_ecom
);
2238 new_ecom
= ecommunity_dup(ecom
);
2240 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2241 path
->attr
->ecommunity
= new_ecom
;
2243 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2248 /* Compile function for set community. */
2249 static void *route_set_ecommunity_rt_compile(const char *arg
)
2251 struct ecommunity
*ecom
;
2253 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2256 return ecommunity_intern(ecom
);
2259 /* Free function for set community. Used by _rt and _soo */
2260 static void route_set_ecommunity_free(void *rule
)
2262 struct ecommunity
*ecom
= rule
;
2263 ecommunity_unintern(&ecom
);
2266 /* Set community rule structure. */
2267 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2268 "extcommunity rt", route_set_ecommunity
,
2269 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2272 /* `set extcommunity soo COMMUNITY' */
2274 /* Compile function for set community. */
2275 static void *route_set_ecommunity_soo_compile(const char *arg
)
2277 struct ecommunity
*ecom
;
2279 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2283 return ecommunity_intern(ecom
);
2286 /* Set community rule structure. */
2287 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2288 "extcommunity soo", route_set_ecommunity
,
2289 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2292 /* `set origin ORIGIN' */
2294 /* For origin set. */
2295 static route_map_result_t
route_set_origin(void *rule
,
2296 const struct prefix
*prefix
,
2297 route_map_object_t type
,
2301 struct bgp_path_info
*path
;
2303 if (type
== RMAP_BGP
) {
2307 path
->attr
->origin
= *origin
;
2313 /* Compile function for origin set. */
2314 static void *route_set_origin_compile(const char *arg
)
2318 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2320 if (strcmp(arg
, "igp") == 0)
2322 else if (strcmp(arg
, "egp") == 0)
2330 /* Compile function for origin set. */
2331 static void route_set_origin_free(void *rule
)
2333 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2336 /* Set origin rule structure. */
2337 struct route_map_rule_cmd route_set_origin_cmd
= {
2338 "origin", route_set_origin
, route_set_origin_compile
,
2339 route_set_origin_free
,
2342 /* `set atomic-aggregate' */
2344 /* For atomic aggregate set. */
2345 static route_map_result_t
route_set_atomic_aggregate(void *rule
,
2346 const struct prefix
*pfx
,
2347 route_map_object_t type
,
2350 struct bgp_path_info
*path
;
2352 if (type
== RMAP_BGP
) {
2354 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2360 /* Compile function for atomic aggregate. */
2361 static void *route_set_atomic_aggregate_compile(const char *arg
)
2366 /* Compile function for atomic aggregate. */
2367 static void route_set_atomic_aggregate_free(void *rule
)
2372 /* Set atomic aggregate rule structure. */
2373 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2374 "atomic-aggregate", route_set_atomic_aggregate
,
2375 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2378 /* `set aggregator as AS A.B.C.D' */
2381 struct in_addr address
;
2384 static route_map_result_t
route_set_aggregator_as(void *rule
,
2385 const struct prefix
*prefix
,
2386 route_map_object_t type
,
2389 struct bgp_path_info
*path
;
2390 struct aggregator
*aggregator
;
2392 if (type
== RMAP_BGP
) {
2396 path
->attr
->aggregator_as
= aggregator
->as
;
2397 path
->attr
->aggregator_addr
= aggregator
->address
;
2398 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2404 static void *route_set_aggregator_as_compile(const char *arg
)
2406 struct aggregator
*aggregator
;
2412 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2413 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2414 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2418 aggregator
->as
= strtoul(as
, NULL
, 10);
2419 ret
= inet_aton(address
, &aggregator
->address
);
2421 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2427 static void route_set_aggregator_as_free(void *rule
)
2429 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2432 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2433 "aggregator as", route_set_aggregator_as
,
2434 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2437 /* Set tag to object. object must be pointer to struct bgp_path_info */
2438 static route_map_result_t
route_set_tag(void *rule
,
2439 const struct prefix
*prefix
,
2440 route_map_object_t type
, void *object
)
2443 struct bgp_path_info
*path
;
2445 if (type
== RMAP_BGP
) {
2450 path
->attr
->tag
= *tag
;
2456 /* Route map commands for tag set. */
2457 static struct route_map_rule_cmd route_set_tag_cmd
= {
2458 "tag", route_set_tag
, route_map_rule_tag_compile
,
2459 route_map_rule_tag_free
,
2462 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2463 static route_map_result_t
route_set_label_index(void *rule
,
2464 const struct prefix
*prefix
,
2465 route_map_object_t type
,
2468 struct rmap_value
*rv
;
2469 struct bgp_path_info
*path
;
2470 uint32_t label_index
;
2472 if (type
== RMAP_BGP
) {
2473 /* Fetch routemap's rule information. */
2477 /* Set label-index value. */
2478 label_index
= rv
->value
;
2480 path
->attr
->label_index
= label_index
;
2481 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2488 /* Route map commands for label-index set. */
2489 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2490 "label-index", route_set_label_index
, route_value_compile
,
2494 /* `match ipv6 address IP_ACCESS_LIST' */
2496 static route_map_result_t
route_match_ipv6_address(void *rule
,
2497 const struct prefix
*prefix
,
2498 route_map_object_t type
,
2501 struct access_list
*alist
;
2503 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2504 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2506 return RMAP_NOMATCH
;
2508 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2512 return RMAP_NOMATCH
;
2515 static void *route_match_ipv6_address_compile(const char *arg
)
2517 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2520 static void route_match_ipv6_address_free(void *rule
)
2522 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2525 /* Route map commands for ip address matching. */
2526 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2527 "ipv6 address", route_match_ipv6_address
,
2528 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2530 /* `match ipv6 next-hop IP_ADDRESS' */
2532 static route_map_result_t
route_match_ipv6_next_hop(void *rule
,
2533 const struct prefix
*prefix
,
2534 route_map_object_t type
,
2537 struct in6_addr
*addr
= rule
;
2538 struct bgp_path_info
*path
;
2540 if (type
== RMAP_BGP
) {
2543 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2546 if (path
->attr
->mp_nexthop_len
2547 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2548 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2551 return RMAP_NOMATCH
;
2554 return RMAP_NOMATCH
;
2557 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2559 struct in6_addr
*address
;
2562 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2564 ret
= inet_pton(AF_INET6
, arg
, address
);
2566 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2573 static void route_match_ipv6_next_hop_free(void *rule
)
2575 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2578 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2579 "ipv6 next-hop", route_match_ipv6_next_hop
,
2580 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2582 /* `match ipv6 address prefix-list PREFIX_LIST' */
2584 static route_map_result_t
2585 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2586 route_map_object_t type
, void *object
)
2588 return route_match_address_prefix_list(rule
, AFI_IP6
, prefix
, type
,
2592 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2594 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2597 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2599 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2602 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2603 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2604 route_match_ipv6_address_prefix_list_compile
,
2605 route_match_ipv6_address_prefix_list_free
};
2607 /* `match ipv6 next-hop type <TYPE>' */
2609 static route_map_result_t
2610 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2611 route_map_object_t type
, void *object
)
2613 struct bgp_path_info
*path
;
2614 struct in6_addr
*addr
= rule
;
2616 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2617 path
= (struct bgp_path_info
*)object
;
2618 if (!path
|| !path
->attr
)
2619 return RMAP_DENYMATCH
;
2621 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2622 && !path
->attr
->nh_ifindex
)
2625 return RMAP_NOMATCH
;
2628 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2630 struct in6_addr
*address
;
2633 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2635 ret
= inet_pton(AF_INET6
, "::0", address
);
2637 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2644 static void route_match_ipv6_next_hop_type_free(void *rule
)
2646 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2649 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2650 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2651 route_match_ipv6_next_hop_type_compile
,
2652 route_match_ipv6_next_hop_type_free
};
2654 /* `set ipv6 nexthop global IP_ADDRESS' */
2656 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2657 static route_map_result_t
route_set_ipv6_nexthop_global(void *rule
,
2658 const struct prefix
*p
,
2659 route_map_object_t type
,
2662 struct in6_addr
*address
;
2663 struct bgp_path_info
*path
;
2665 if (type
== RMAP_BGP
) {
2666 /* Fetch routemap's rule information. */
2670 /* Set next hop value. */
2671 path
->attr
->mp_nexthop_global
= *address
;
2673 /* Set nexthop length. */
2674 if (path
->attr
->mp_nexthop_len
== 0)
2675 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2677 SET_FLAG(path
->attr
->rmap_change_flags
,
2678 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2684 /* Route map `ip next-hop' compile function. Given string is converted
2685 to struct in_addr structure. */
2686 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2689 struct in6_addr
*address
;
2691 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2693 ret
= inet_pton(AF_INET6
, arg
, address
);
2696 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2703 /* Free route map's compiled `ip next-hop' value. */
2704 static void route_set_ipv6_nexthop_global_free(void *rule
)
2706 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2709 /* Route map commands for ip nexthop set. */
2710 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2711 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2712 route_set_ipv6_nexthop_global_compile
,
2713 route_set_ipv6_nexthop_global_free
};
2715 /* Set next-hop preference value. */
2716 static route_map_result_t
2717 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2718 route_map_object_t type
, void *object
)
2720 struct bgp_path_info
*path
;
2723 if (type
== RMAP_BGP
) {
2724 /* Fetch routemap's rule information. */
2728 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2729 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2731 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2732 /* Set next hop preference to global */
2733 path
->attr
->mp_nexthop_prefer_global
= true;
2734 SET_FLAG(path
->attr
->rmap_change_flags
,
2735 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2737 path
->attr
->mp_nexthop_prefer_global
= false;
2738 SET_FLAG(path
->attr
->rmap_change_flags
,
2739 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2745 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2749 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2755 /* Free route map's compiled `ip next-hop' value. */
2756 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2758 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2761 /* Route map commands for ip nexthop set preferred. */
2762 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2763 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2764 route_set_ipv6_nexthop_prefer_global_compile
,
2765 route_set_ipv6_nexthop_prefer_global_free
};
2767 /* `set ipv6 nexthop local IP_ADDRESS' */
2769 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2770 static route_map_result_t
route_set_ipv6_nexthop_local(void *rule
,
2771 const struct prefix
*p
,
2772 route_map_object_t type
,
2775 struct in6_addr
*address
;
2776 struct bgp_path_info
*path
;
2778 if (type
== RMAP_BGP
) {
2779 /* Fetch routemap's rule information. */
2783 /* Set next hop value. */
2784 path
->attr
->mp_nexthop_local
= *address
;
2786 /* Set nexthop length. */
2787 if (path
->attr
->mp_nexthop_len
2788 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2789 path
->attr
->mp_nexthop_len
=
2790 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2792 SET_FLAG(path
->attr
->rmap_change_flags
,
2793 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2799 /* Route map `ip nexthop' compile function. Given string is converted
2800 to struct in_addr structure. */
2801 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2804 struct in6_addr
*address
;
2806 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2808 ret
= inet_pton(AF_INET6
, arg
, address
);
2811 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2818 /* Free route map's compiled `ip nexthop' value. */
2819 static void route_set_ipv6_nexthop_local_free(void *rule
)
2821 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2824 /* Route map commands for ip nexthop set. */
2825 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2826 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2827 route_set_ipv6_nexthop_local_compile
,
2828 route_set_ipv6_nexthop_local_free
};
2830 /* `set ipv6 nexthop peer-address' */
2832 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2833 static route_map_result_t
route_set_ipv6_nexthop_peer(void *rule
,
2834 const struct prefix
*pfx
,
2835 route_map_object_t type
,
2838 struct in6_addr peer_address
;
2839 struct bgp_path_info
*path
;
2842 if (type
== RMAP_BGP
) {
2843 /* Fetch routemap's rule information. */
2847 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2848 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2850 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2851 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2852 /* Set next hop value and length in attribute. */
2853 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2854 path
->attr
->mp_nexthop_local
= peer_address
;
2855 if (path
->attr
->mp_nexthop_len
!= 32)
2856 path
->attr
->mp_nexthop_len
= 32;
2858 path
->attr
->mp_nexthop_global
= peer_address
;
2859 if (path
->attr
->mp_nexthop_len
== 0)
2860 path
->attr
->mp_nexthop_len
= 16;
2863 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2864 /* The next hop value will be set as part of packet
2866 * Set the flags here to indicate that rewrite needs to
2868 * Also, clear the value - we clear both global and
2870 * nexthops, whether we send one or both is determined
2873 SET_FLAG(path
->attr
->rmap_change_flags
,
2874 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2875 /* clear next hop value. */
2876 memset(&(path
->attr
->mp_nexthop_global
), 0,
2877 sizeof(struct in6_addr
));
2878 memset(&(path
->attr
->mp_nexthop_local
), 0,
2879 sizeof(struct in6_addr
));
2886 /* Route map `ip next-hop' compile function. Given string is converted
2887 to struct in_addr structure. */
2888 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2892 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2898 /* Free route map's compiled `ip next-hop' value. */
2899 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2901 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2904 /* Route map commands for ip nexthop set. */
2905 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2906 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2907 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2909 /* `set ipv4 vpn next-hop A.B.C.D' */
2911 static route_map_result_t
route_set_vpnv4_nexthop(void *rule
,
2912 const struct prefix
*prefix
,
2913 route_map_object_t type
,
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 route_map_result_t
route_set_vpnv6_nexthop(void *rule
,
2952 const struct prefix
*prefix
,
2953 route_map_object_t type
,
2956 struct in6_addr
*address
;
2957 struct bgp_path_info
*path
;
2959 if (type
== RMAP_BGP
) {
2960 /* Fetch routemap's rule information. */
2964 /* Set next hop value. */
2965 memcpy(&path
->attr
->mp_nexthop_global
, address
,
2966 sizeof(struct in6_addr
));
2967 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2973 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2976 struct in6_addr
*address
;
2978 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2979 ret
= inet_pton(AF_INET6
, arg
, address
);
2982 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2989 static void route_set_vpn_nexthop_free(void *rule
)
2991 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2994 /* Route map commands for ipv4 next-hop set. */
2995 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2996 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2997 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
2999 /* Route map commands for ipv6 next-hop set. */
3000 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
3001 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
3002 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
3004 /* `set originator-id' */
3006 /* For origin set. */
3007 static route_map_result_t
route_set_originator_id(void *rule
,
3008 const struct prefix
*prefix
,
3009 route_map_object_t type
,
3012 struct in_addr
*address
;
3013 struct bgp_path_info
*path
;
3015 if (type
== RMAP_BGP
) {
3019 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3020 path
->attr
->originator_id
= *address
;
3026 /* Compile function for originator-id set. */
3027 static void *route_set_originator_id_compile(const char *arg
)
3030 struct in_addr
*address
;
3032 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3034 ret
= inet_aton(arg
, address
);
3037 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3044 /* Compile function for originator_id set. */
3045 static void route_set_originator_id_free(void *rule
)
3047 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3050 /* Set originator-id rule structure. */
3051 struct route_map_rule_cmd route_set_originator_id_cmd
= {
3052 "originator-id", route_set_originator_id
,
3053 route_set_originator_id_compile
, route_set_originator_id_free
,
3056 /* Add bgp route map rule. */
3057 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3058 const char *arg
, route_map_event_t type
)
3060 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3061 int retval
= CMD_SUCCESS
;
3064 ret
= route_map_add_match(index
, command
, arg
, type
);
3066 case RMAP_RULE_MISSING
:
3067 vty_out(vty
, "%% BGP Can't find rule.\n");
3068 retval
= CMD_WARNING_CONFIG_FAILED
;
3070 case RMAP_COMPILE_ERROR
:
3071 vty_out(vty
, "%% BGP Argument is malformed.\n");
3072 retval
= CMD_WARNING_CONFIG_FAILED
;
3074 case RMAP_COMPILE_SUCCESS
:
3075 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
3076 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
3084 /* Delete bgp route map rule. */
3085 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3086 const char *arg
, route_map_event_t type
)
3088 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3090 int retval
= CMD_SUCCESS
;
3091 char *dep_name
= NULL
;
3093 char *rmap_name
= NULL
;
3095 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3096 /* ignore the mundane, the types without any dependency */
3098 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3101 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3103 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3105 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3108 ret
= route_map_delete_match(index
, command
, dep_name
);
3110 case RMAP_RULE_MISSING
:
3111 vty_out(vty
, "%% BGP Can't find rule.\n");
3112 retval
= CMD_WARNING_CONFIG_FAILED
;
3114 case RMAP_COMPILE_ERROR
:
3115 vty_out(vty
, "%% BGP Argument is malformed.\n");
3116 retval
= CMD_WARNING_CONFIG_FAILED
;
3118 case RMAP_COMPILE_SUCCESS
:
3119 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
3120 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
3124 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3125 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3131 * This is the workhorse routine for processing in/out routemap
3134 static void bgp_route_map_process_peer(const char *rmap_name
,
3135 struct route_map
*map
, struct peer
*peer
,
3136 int afi
, int safi
, int route_update
)
3138 struct bgp_filter
*filter
;
3140 if (!peer
|| !rmap_name
)
3143 filter
= &peer
->filter
[afi
][safi
];
3145 * in is for non-route-server clients,
3146 * out is for all peers
3148 if (filter
->map
[RMAP_IN
].name
3149 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3150 filter
->map
[RMAP_IN
].map
= map
;
3152 if (route_update
&& peer
->status
== Established
) {
3153 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3154 PEER_FLAG_SOFT_RECONFIG
)) {
3155 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3157 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3158 rmap_name
, peer
->host
);
3160 bgp_soft_reconfig_in(peer
, afi
, safi
);
3161 } else if (CHECK_FLAG(peer
->cap
,
3162 PEER_CAP_REFRESH_OLD_RCV
)
3163 || CHECK_FLAG(peer
->cap
,
3164 PEER_CAP_REFRESH_NEW_RCV
)) {
3165 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3167 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3168 rmap_name
, peer
->host
);
3169 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3176 * For outbound, unsuppress and default-originate map change (content or
3177 * map created), merely update the "config" here, the actual route
3178 * announcement happens at the group level.
3180 if (filter
->map
[RMAP_OUT
].name
3181 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3182 filter
->map
[RMAP_OUT
].map
= map
;
3184 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3185 filter
->usmap
.map
= map
;
3187 if (peer
->default_rmap
[afi
][safi
].name
3188 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3189 peer
->default_rmap
[afi
][safi
].map
= map
;
3192 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3193 struct route_map
*map
,
3196 struct peer_group
*group
;
3197 struct listnode
*node
, *nnode
;
3198 struct bgp_filter
*filter
;
3205 /* All the peers have been updated correctly already. This is
3206 * just updating the placeholder data. No real update required.
3208 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3209 FOREACH_AFI_SAFI (afi
, safi
) {
3210 filter
= &group
->conf
->filter
[afi
][safi
];
3212 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3213 if ((filter
->map
[direct
].name
)
3214 && (strcmp(rmap_name
,
3215 filter
->map
[direct
].name
)
3217 filter
->map
[direct
].map
= map
;
3220 if (filter
->usmap
.name
3221 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3222 filter
->usmap
.map
= map
;
3228 * Note that if an extreme number (tens of thousands) of route-maps are in use
3229 * and if bgp has an extreme number of peers, network statements, etc then this
3230 * function can consume a lot of cycles. This is due to this function being
3231 * called for each route-map and within this function we walk the list of peers,
3232 * network statements, etc looking to see if they use this route-map.
3234 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3241 struct bgp_node
*bn
;
3242 struct bgp_static
*bgp_static
;
3243 struct listnode
*node
, *nnode
;
3244 struct route_map
*map
;
3245 char buf
[INET6_ADDRSTRLEN
];
3247 map
= route_map_lookup_by_name(rmap_name
);
3249 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3251 /* Ignore dummy peer-group structure */
3252 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3255 FOREACH_AFI_SAFI (afi
, safi
) {
3256 /* process in/out/import/export/default-orig
3258 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3259 safi
, route_update
);
3263 /* for outbound/default-orig route-maps, process for groups */
3264 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3267 /* update peer-group config (template) */
3268 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3270 FOREACH_AFI_SAFI (afi
, safi
) {
3271 /* For table route-map updates. */
3272 if (!bgp_fibupd_safi(safi
))
3275 if (bgp
->table_map
[afi
][safi
].name
3276 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3279 /* bgp->table_map[afi][safi].map is NULL.
3280 * i.e Route map creation event.
3281 * So update applied_counter.
3282 * If it is not NULL, i.e It may be routemap updation or
3283 * deletion. so no need to update the counter.
3285 if (!bgp
->table_map
[afi
][safi
].map
)
3286 route_map_counter_increment(map
);
3287 bgp
->table_map
[afi
][safi
].map
= map
;
3289 if (BGP_DEBUG(zebra
, ZEBRA
))
3291 "Processing route_map %s update on "
3295 bgp_zebra_announce_table(bgp
, afi
, safi
);
3298 /* For network route-map updates. */
3299 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3300 bn
= bgp_route_next(bn
)) {
3301 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3305 if (!bgp_static
->rmap
.name
3306 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3309 if (!bgp_static
->rmap
.map
)
3310 route_map_counter_increment(map
);
3312 bgp_static
->rmap
.map
= map
;
3314 if (route_update
&& !bgp_static
->backdoor
) {
3315 if (bgp_debug_zebra(&bn
->p
))
3317 "Processing route_map %s update on static route %s",
3319 inet_ntop(bn
->p
.family
,
3320 &bn
->p
.u
.prefix
, buf
,
3322 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3328 /* For redistribute route-map updates. */
3329 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3330 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3331 struct list
*red_list
;
3332 struct bgp_redist
*red
;
3334 red_list
= bgp
->redist
[afi
][i
];
3338 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3340 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3344 route_map_counter_increment(map
);
3346 red
->rmap
.map
= map
;
3351 if (BGP_DEBUG(zebra
, ZEBRA
))
3353 "Processing route_map %s update on redistributed routes",
3356 bgp_redistribute_resend(bgp
, afi
, i
,
3361 /* for type5 command route-maps */
3362 FOREACH_AFI_SAFI (afi
, safi
) {
3363 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3364 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3368 /* Make sure the route-map is populated here if not already done */
3369 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3371 if (BGP_DEBUG(zebra
, ZEBRA
))
3373 "Processing route_map %s update on advertise type5 route command",
3376 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3377 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3378 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3383 static void bgp_route_map_process_update_cb(char *rmap_name
)
3385 struct listnode
*node
, *nnode
;
3388 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3389 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3392 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3393 vnc_routemap_update(bgp
, __func__
);
3397 vpn_policy_routemap_event(rmap_name
);
3400 int bgp_route_map_update_timer(struct thread
*thread
)
3402 bm
->t_rmap_update
= NULL
;
3404 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3409 static void bgp_route_map_mark_update(const char *rmap_name
)
3411 if (bm
->t_rmap_update
== NULL
) {
3412 struct listnode
*node
, *nnode
;
3415 /* rmap_update_timer of 0 means don't do route updates */
3416 if (bm
->rmap_update_timer
) {
3417 bm
->t_rmap_update
= NULL
;
3418 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3419 NULL
, bm
->rmap_update_timer
,
3420 &bm
->t_rmap_update
);
3422 /* Signal the groups that a route-map update event has
3424 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3425 update_group_policy_update(bgp
,
3426 BGP_POLICY_ROUTE_MAP
,
3429 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3430 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3432 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3433 vnc_routemap_update(bgp
, __func__
);
3439 static void bgp_route_map_add(const char *rmap_name
)
3441 if (route_map_mark_updated(rmap_name
) == 0)
3442 bgp_route_map_mark_update(rmap_name
);
3444 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3447 static void bgp_route_map_delete(const char *rmap_name
)
3449 if (route_map_mark_updated(rmap_name
) == 0)
3450 bgp_route_map_mark_update(rmap_name
);
3452 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3455 static void bgp_route_map_event(const char *rmap_name
)
3457 if (route_map_mark_updated(rmap_name
) == 0)
3458 bgp_route_map_mark_update(rmap_name
);
3460 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3463 DEFUN (match_mac_address
,
3464 match_mac_address_cmd
,
3465 "match mac address WORD",
3468 "Match address of route\n"
3469 "MAC Access-list name\n")
3471 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3472 RMAP_EVENT_FILTER_ADDED
);
3475 DEFUN (no_match_mac_address
,
3476 no_match_mac_address_cmd
,
3477 "no match mac address WORD",
3481 "Match address of route\n"
3482 "MAC acess-list name\n")
3484 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3485 RMAP_EVENT_FILTER_DELETED
);
3488 DEFUN (match_evpn_route_type
,
3489 match_evpn_route_type_cmd
,
3490 "match evpn route-type <macip | multicast | prefix>",
3493 "Match route-type\n"
3498 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3499 RMAP_EVENT_MATCH_ADDED
);
3502 DEFUN (no_match_evpn_route_type
,
3503 no_match_evpn_route_type_cmd
,
3504 "no match evpn route-type <macip | multicast | prefix>",
3508 "Match route-type\n"
3513 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3514 RMAP_EVENT_MATCH_DELETED
);
3518 DEFUN (match_evpn_vni
,
3520 "match evpn vni " CMD_VNI_RANGE
,
3526 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3527 RMAP_EVENT_MATCH_ADDED
);
3530 DEFUN (no_match_evpn_vni
,
3531 no_match_evpn_vni_cmd
,
3532 "no match evpn vni " CMD_VNI_RANGE
,
3539 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3540 RMAP_EVENT_MATCH_DELETED
);
3543 DEFUN (match_evpn_default_route
,
3544 match_evpn_default_route_cmd
,
3545 "match evpn default-route",
3548 "default EVPN type-5 route\n")
3550 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3551 RMAP_EVENT_MATCH_ADDED
);
3554 DEFUN (no_match_evpn_default_route
,
3555 no_match_evpn_default_route_cmd
,
3556 "no match evpn default-route",
3560 "default EVPN type-5 route\n")
3562 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3563 RMAP_EVENT_MATCH_DELETED
);
3566 DEFPY(match_vrl_source_vrf
,
3567 match_vrl_source_vrf_cmd
,
3568 "match source-vrf NAME$vrf_name",
3573 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3574 RMAP_EVENT_MATCH_ADDED
);
3577 DEFPY(no_match_vrl_source_vrf
,
3578 no_match_vrl_source_vrf_cmd
,
3579 "no match source-vrf NAME$vrf_name",
3585 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3586 RMAP_EVENT_MATCH_DELETED
);
3591 "match peer <A.B.C.D|X:X::X:X|WORD>",
3593 "Match peer address\n"
3594 "IP address of peer\n"
3595 "IPv6 address of peer\n"
3596 "Interface name of peer\n")
3599 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3600 RMAP_EVENT_MATCH_ADDED
);
3603 DEFUN (match_peer_local
,
3604 match_peer_local_cmd
,
3607 "Match peer address\n"
3608 "Static or Redistributed routes\n")
3610 return bgp_route_match_add(vty
, "peer", "local",
3611 RMAP_EVENT_MATCH_DELETED
);
3614 DEFUN (no_match_peer
,
3616 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3619 "Match peer address\n"
3620 "Static or Redistributed routes\n"
3621 "IP address of peer\n"
3622 "IPv6 address of peer\n"
3623 "Interface name of peer\n")
3627 if (argc
<= idx_peer
)
3628 return bgp_route_match_delete(vty
, "peer", NULL
,
3629 RMAP_EVENT_MATCH_DELETED
);
3630 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3631 RMAP_EVENT_MATCH_DELETED
);
3634 #if defined(HAVE_LUA)
3635 DEFUN (match_command
,
3637 "match command WORD",
3639 "Run a command to match\n"
3640 "The command to run\n")
3642 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3643 RMAP_EVENT_FILTER_ADDED
);
3646 DEFUN (no_match_command
,
3647 no_match_command_cmd
,
3648 "no match command WORD",
3651 "Run a command to match\n"
3652 "The command to run\n")
3654 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3655 RMAP_EVENT_FILTER_DELETED
);
3659 /* match probability */
3660 DEFUN (match_probability
,
3661 match_probability_cmd
,
3662 "match probability (0-100)",
3664 "Match portion of routes defined by percentage value\n"
3665 "Percentage of routes\n")
3668 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3669 RMAP_EVENT_MATCH_ADDED
);
3673 DEFUN (no_match_probability
,
3674 no_match_probability_cmd
,
3675 "no match probability [(1-99)]",
3678 "Match portion of routes defined by percentage value\n"
3679 "Percentage of routes\n")
3682 if (argc
<= idx_number
)
3683 return bgp_route_match_delete(vty
, "probability", NULL
,
3684 RMAP_EVENT_MATCH_DELETED
);
3685 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3686 RMAP_EVENT_MATCH_DELETED
);
3690 DEFUN (match_ip_route_source
,
3691 match_ip_route_source_cmd
,
3692 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3695 "Match advertising source address of route\n"
3696 "IP access-list number\n"
3697 "IP access-list number (expanded range)\n"
3698 "IP standard access-list name\n")
3701 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3702 RMAP_EVENT_FILTER_ADDED
);
3706 DEFUN (no_match_ip_route_source
,
3707 no_match_ip_route_source_cmd
,
3708 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3712 "Match advertising source address of route\n"
3713 "IP access-list number\n"
3714 "IP access-list number (expanded range)\n"
3715 "IP standard access-list name\n")
3718 if (argc
<= idx_number
)
3719 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3720 RMAP_EVENT_FILTER_DELETED
);
3721 return bgp_route_match_delete(vty
, "ip route-source",
3722 argv
[idx_number
]->arg
,
3723 RMAP_EVENT_FILTER_DELETED
);
3727 DEFUN (match_ip_route_source_prefix_list
,
3728 match_ip_route_source_prefix_list_cmd
,
3729 "match ip route-source prefix-list WORD",
3732 "Match advertising source address of route\n"
3733 "Match entries of prefix-lists\n"
3734 "IP prefix-list name\n")
3737 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3738 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3742 DEFUN (no_match_ip_route_source_prefix_list
,
3743 no_match_ip_route_source_prefix_list_cmd
,
3744 "no match ip route-source prefix-list [WORD]",
3748 "Match advertising source address of route\n"
3749 "Match entries of prefix-lists\n"
3750 "IP prefix-list name\n")
3753 if (argc
<= idx_word
)
3754 return bgp_route_match_delete(vty
,
3755 "ip route-source prefix-list",
3756 NULL
, RMAP_EVENT_PLIST_DELETED
);
3757 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3758 argv
[idx_word
]->arg
,
3759 RMAP_EVENT_PLIST_DELETED
);
3763 DEFUN (match_local_pref
,
3764 match_local_pref_cmd
,
3765 "match local-preference (0-4294967295)",
3767 "Match local-preference of route\n"
3771 return bgp_route_match_add(vty
, "local-preference",
3772 argv
[idx_number
]->arg
,
3773 RMAP_EVENT_MATCH_ADDED
);
3777 DEFUN (no_match_local_pref
,
3778 no_match_local_pref_cmd
,
3779 "no match local-preference [(0-4294967295)]",
3782 "Match local preference of route\n"
3783 "Local preference value\n")
3785 int idx_localpref
= 3;
3786 if (argc
<= idx_localpref
)
3787 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3788 RMAP_EVENT_MATCH_DELETED
);
3789 return bgp_route_match_delete(vty
, "local-preference",
3790 argv
[idx_localpref
]->arg
,
3791 RMAP_EVENT_MATCH_DELETED
);
3795 DEFUN (match_community
,
3796 match_community_cmd
,
3797 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3799 "Match BGP community list\n"
3800 "Community-list number (standard)\n"
3801 "Community-list number (expanded)\n"
3802 "Community-list name\n"
3803 "Do exact matching of communities\n")
3805 int idx_comm_list
= 2;
3810 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3811 strlen(argv
[idx_comm_list
]->arg
)
3812 + strlen("exact-match") + 2);
3814 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3816 argstr
= argv
[idx_comm_list
]->arg
;
3818 ret
= bgp_route_match_add(vty
, "community", argstr
,
3819 RMAP_EVENT_CLIST_ADDED
);
3821 if (argstr
!= argv
[idx_comm_list
]->arg
)
3822 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3827 DEFUN (no_match_community
,
3828 no_match_community_cmd
,
3829 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3832 "Match BGP community list\n"
3833 "Community-list number (standard)\n"
3834 "Community-list number (expanded)\n"
3835 "Community-list name\n"
3836 "Do exact matching of communities\n")
3838 return bgp_route_match_delete(vty
, "community", NULL
,
3839 RMAP_EVENT_CLIST_DELETED
);
3842 DEFUN (match_lcommunity
,
3843 match_lcommunity_cmd
,
3844 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
3846 "Match BGP large community list\n"
3847 "Large Community-list number (standard)\n"
3848 "Large Community-list number (expanded)\n"
3849 "Large Community-list name\n"
3850 "Do exact matching of communities\n")
3852 int idx_lcomm_list
= 2;
3857 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3858 strlen(argv
[idx_lcomm_list
]->arg
)
3859 + strlen("exact-match") + 2);
3861 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
3863 argstr
= argv
[idx_lcomm_list
]->arg
;
3865 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
3866 RMAP_EVENT_LLIST_ADDED
);
3867 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
3868 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3873 DEFUN (no_match_lcommunity
,
3874 no_match_lcommunity_cmd
,
3875 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
3878 "Match BGP large community list\n"
3879 "Large Community-list number (standard)\n"
3880 "Large Community-list number (expanded)\n"
3881 "Large Community-list name\n"
3882 "Do exact matching of communities\n")
3884 return bgp_route_match_delete(vty
, "large-community", NULL
,
3885 RMAP_EVENT_LLIST_DELETED
);
3888 DEFUN (match_ecommunity
,
3889 match_ecommunity_cmd
,
3890 "match extcommunity <(1-99)|(100-500)|WORD>",
3892 "Match BGP/VPN extended community list\n"
3893 "Extended community-list number (standard)\n"
3894 "Extended community-list number (expanded)\n"
3895 "Extended community-list name\n")
3897 int idx_comm_list
= 2;
3898 return bgp_route_match_add(vty
, "extcommunity",
3899 argv
[idx_comm_list
]->arg
,
3900 RMAP_EVENT_ECLIST_ADDED
);
3904 DEFUN (no_match_ecommunity
,
3905 no_match_ecommunity_cmd
,
3906 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3909 "Match BGP/VPN extended community list\n"
3910 "Extended community-list number (standard)\n"
3911 "Extended community-list number (expanded)\n"
3912 "Extended community-list name\n")
3914 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3915 RMAP_EVENT_ECLIST_DELETED
);
3919 DEFUN (match_aspath
,
3921 "match as-path WORD",
3923 "Match BGP AS path list\n"
3924 "AS path access-list name\n")
3927 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3928 RMAP_EVENT_ASLIST_ADDED
);
3932 DEFUN (no_match_aspath
,
3933 no_match_aspath_cmd
,
3934 "no match as-path [WORD]",
3937 "Match BGP AS path list\n"
3938 "AS path access-list name\n")
3940 return bgp_route_match_delete(vty
, "as-path", NULL
,
3941 RMAP_EVENT_ASLIST_DELETED
);
3945 DEFUN (match_origin
,
3947 "match origin <egp|igp|incomplete>",
3952 "unknown heritage\n")
3955 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3956 return bgp_route_match_add(vty
, "origin", "igp",
3957 RMAP_EVENT_MATCH_ADDED
);
3958 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3959 return bgp_route_match_add(vty
, "origin", "egp",
3960 RMAP_EVENT_MATCH_ADDED
);
3961 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3962 return bgp_route_match_add(vty
, "origin", "incomplete",
3963 RMAP_EVENT_MATCH_ADDED
);
3965 vty_out(vty
, "%% Invalid match origin type\n");
3966 return CMD_WARNING_CONFIG_FAILED
;
3970 DEFUN (no_match_origin
,
3971 no_match_origin_cmd
,
3972 "no match origin [<egp|igp|incomplete>]",
3978 "unknown heritage\n")
3980 return bgp_route_match_delete(vty
, "origin", NULL
,
3981 RMAP_EVENT_MATCH_DELETED
);
3984 DEFUN (set_ip_nexthop_peer
,
3985 set_ip_nexthop_peer_cmd
,
3986 "[no] set ip next-hop peer-address",
3990 "Next hop address\n"
3991 "Use peer address (for BGP only)\n")
3993 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3994 const char *) = strmatch(argv
[0]->text
, "no")
3995 ? generic_set_delete
3998 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4002 DEFUN (set_ip_nexthop_unchanged
,
4003 set_ip_nexthop_unchanged_cmd
,
4004 "[no] set ip next-hop unchanged",
4008 "Next hop address\n"
4009 "Don't modify existing Next hop address\n")
4011 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4012 const char *) = strmatch(argv
[0]->text
, "no")
4013 ? generic_set_delete
4016 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4021 DEFUN (set_local_pref
,
4023 "set local-preference (0-4294967295)",
4025 "BGP local preference path attribute\n"
4026 "Preference value\n")
4029 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4030 "local-preference", argv
[idx_number
]->arg
);
4034 DEFUN (no_set_local_pref
,
4035 no_set_local_pref_cmd
,
4036 "no set local-preference [(0-4294967295)]",
4039 "BGP local preference path attribute\n"
4040 "Preference value\n")
4042 int idx_localpref
= 3;
4043 if (argc
<= idx_localpref
)
4044 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4045 "local-preference", NULL
);
4046 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4047 "local-preference", argv
[idx_localpref
]->arg
);
4053 "set weight (0-4294967295)",
4055 "BGP weight for routing table\n"
4059 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4060 argv
[idx_number
]->arg
);
4064 DEFUN (no_set_weight
,
4066 "no set weight [(0-4294967295)]",
4069 "BGP weight for routing table\n"
4073 if (argc
<= idx_weight
)
4074 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4076 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4077 "weight", argv
[idx_weight
]->arg
);
4080 DEFUN (set_label_index
,
4081 set_label_index_cmd
,
4082 "set label-index (0-1048560)",
4084 "Label index to associate with the prefix\n"
4085 "Label index value\n")
4088 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4089 "label-index", argv
[idx_number
]->arg
);
4092 DEFUN (no_set_label_index
,
4093 no_set_label_index_cmd
,
4094 "no set label-index [(0-1048560)]",
4097 "Label index to associate with the prefix\n"
4098 "Label index value\n")
4100 int idx_label_index
= 3;
4101 if (argc
<= idx_label_index
)
4102 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4103 "label-index", NULL
);
4104 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4105 "label-index", argv
[idx_label_index
]->arg
);
4108 DEFUN (set_aspath_prepend_asn
,
4109 set_aspath_prepend_asn_cmd
,
4110 "set as-path prepend (1-4294967295)...",
4112 "Transform BGP AS_PATH attribute\n"
4113 "Prepend to the as-path\n"
4120 str
= argv_concat(argv
, argc
, idx_asn
);
4121 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4122 "as-path prepend", str
);
4123 XFREE(MTYPE_TMP
, str
);
4128 DEFUN (set_aspath_prepend_lastas
,
4129 set_aspath_prepend_lastas_cmd
,
4130 "set as-path prepend last-as (1-10)",
4132 "Transform BGP AS_PATH attribute\n"
4133 "Prepend to the as-path\n"
4134 "Use the peer's AS-number\n"
4135 "Number of times to insert\n")
4137 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4140 DEFUN (no_set_aspath_prepend
,
4141 no_set_aspath_prepend_cmd
,
4142 "no set as-path prepend [(1-4294967295)]",
4145 "Transform BGP AS_PATH attribute\n"
4146 "Prepend to the as-path\n"
4153 str
= argv_concat(argv
, argc
, idx_asn
);
4154 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4155 "as-path prepend", str
);
4156 XFREE(MTYPE_TMP
, str
);
4161 DEFUN (set_aspath_exclude
,
4162 set_aspath_exclude_cmd
,
4163 "set as-path exclude (1-4294967295)...",
4165 "Transform BGP AS-path attribute\n"
4166 "Exclude from the as-path\n"
4173 str
= argv_concat(argv
, argc
, idx_asn
);
4174 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4175 "as-path exclude", str
);
4176 XFREE(MTYPE_TMP
, str
);
4180 DEFUN (no_set_aspath_exclude
,
4181 no_set_aspath_exclude_cmd
,
4182 "no set as-path exclude (1-4294967295)...",
4185 "Transform BGP AS_PATH attribute\n"
4186 "Exclude from the as-path\n"
4193 str
= argv_concat(argv
, argc
, idx_asn
);
4194 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4195 "as-path exclude", str
);
4196 XFREE(MTYPE_TMP
, str
);
4200 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4201 "no set as-path exclude",
4203 "Transform BGP AS_PATH attribute\n"
4204 "Exclude from the as-path\n")
4206 DEFUN (set_community
,
4208 "set community AA:NN...",
4210 "BGP community attribute\n"
4218 struct community
*com
= NULL
;
4223 b
= buffer_new(1024);
4225 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4226 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4233 buffer_putc(b
, ' ');
4237 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4239 buffer_putstr(b
, "internet");
4242 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4244 buffer_putstr(b
, "local-AS");
4247 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4248 && strncmp(argv
[i
]->arg
, "no-advertise",
4249 strlen(argv
[i
]->arg
))
4251 buffer_putstr(b
, "no-advertise");
4254 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4255 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4257 buffer_putstr(b
, "no-export");
4260 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4261 strlen(argv
[i
]->arg
))
4263 buffer_putstr(b
, "graceful-shutdown");
4266 buffer_putstr(b
, argv
[i
]->arg
);
4268 buffer_putc(b
, '\0');
4270 /* Fetch result string then compile it to communities attribute. */
4271 str
= buffer_getstr(b
);
4275 com
= community_str2com(str
);
4276 XFREE(MTYPE_TMP
, str
);
4279 /* Can't compile user input into communities attribute. */
4281 vty_out(vty
, "%% Malformed communities attribute\n");
4282 return CMD_WARNING_CONFIG_FAILED
;
4285 /* Set communites attribute string. */
4286 str
= community_str(com
, false);
4289 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4290 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4291 strlcpy(argstr
, str
, argstr_sz
);
4292 strlcat(argstr
, " additive", argstr_sz
);
4293 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4294 "community", argstr
);
4295 XFREE(MTYPE_TMP
, argstr
);
4297 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4300 community_free(&com
);
4305 DEFUN (set_community_none
,
4306 set_community_none_cmd
,
4307 "set community none",
4309 "BGP community attribute\n"
4310 "No community attribute\n")
4312 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4313 "community", "none");
4316 DEFUN (no_set_community
,
4317 no_set_community_cmd
,
4318 "no set community AA:NN...",
4321 "BGP community attribute\n"
4324 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4328 ALIAS (no_set_community
,
4329 no_set_community_short_cmd
,
4333 "BGP community attribute\n")
4336 DEFUN (set_community_delete
,
4337 set_community_delete_cmd
,
4338 "set comm-list <(1-99)|(100-500)|WORD> delete",
4340 "set BGP community list (for deletion)\n"
4341 "Community-list number (standard)\n"
4342 "Community-list number (expanded)\n"
4343 "Community-list name\n"
4344 "Delete matching communities\n")
4346 int idx_comm_list
= 2;
4349 args
= argv_concat(argv
, argc
, idx_comm_list
);
4350 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4352 XFREE(MTYPE_TMP
, args
);
4357 DEFUN (no_set_community_delete
,
4358 no_set_community_delete_cmd
,
4359 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4362 "set BGP community list (for deletion)\n"
4363 "Community-list number (standard)\n"
4364 "Community-list number (expanded)\n"
4365 "Community-list name\n"
4366 "Delete matching communities\n")
4368 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4372 DEFUN (set_lcommunity
,
4374 "set large-community AA:BB:CC...",
4376 "BGP large community attribute\n"
4377 "Large Community number in aa:bb:cc format or additive\n")
4382 str
= argv_concat(argv
, argc
, 2);
4383 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4384 "large-community", str
);
4385 XFREE(MTYPE_TMP
, str
);
4390 DEFUN (set_lcommunity_none
,
4391 set_lcommunity_none_cmd
,
4392 "set large-community none",
4394 "BGP large community attribute\n"
4395 "No large community attribute\n")
4397 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4398 "large-community", "none");
4401 DEFUN (no_set_lcommunity
,
4402 no_set_lcommunity_cmd
,
4403 "no set large-community none",
4406 "BGP large community attribute\n"
4407 "No community attribute\n")
4409 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4410 "large-community", NULL
);
4413 DEFUN (no_set_lcommunity1
,
4414 no_set_lcommunity1_cmd
,
4415 "no set large-community AA:BB:CC...",
4418 "BGP large community attribute\n"
4419 "Large community in AA:BB:CC... format or additive\n")
4421 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4422 "large-community", NULL
);
4425 ALIAS (no_set_lcommunity1
,
4426 no_set_lcommunity1_short_cmd
,
4427 "no set large-community",
4430 "BGP large community attribute\n")
4432 DEFUN (set_lcommunity_delete
,
4433 set_lcommunity_delete_cmd
,
4434 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4436 "set BGP large community list (for deletion)\n"
4437 "Large Community-list number (standard)\n"
4438 "Large Communitly-list number (expanded)\n"
4439 "Large Community-list name\n"
4440 "Delete matching large communities\n")
4442 int idx_lcomm_list
= 2;
4445 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
4446 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4447 "large-comm-list", args
);
4448 XFREE(MTYPE_TMP
, args
);
4453 DEFUN (no_set_lcommunity_delete
,
4454 no_set_lcommunity_delete_cmd
,
4455 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4458 "set BGP large community list (for deletion)\n"
4459 "Large Community-list number (standard)\n"
4460 "Large Communitly-list number (expanded)\n"
4461 "Large Community-list name\n"
4462 "Delete matching large communities\n")
4464 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4465 "large-comm-list", NULL
);
4468 ALIAS (no_set_lcommunity_delete
,
4469 no_set_lcommunity_delete_short_cmd
,
4470 "no set large-comm-list",
4473 "set BGP large community list (for deletion)\n")
4475 DEFUN (set_ecommunity_rt
,
4476 set_ecommunity_rt_cmd
,
4477 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4479 "BGP extended community attribute\n"
4480 "Route Target extended community\n"
4481 "VPN extended community\n")
4487 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4488 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4489 "extcommunity rt", str
);
4490 XFREE(MTYPE_TMP
, str
);
4495 DEFUN (no_set_ecommunity_rt
,
4496 no_set_ecommunity_rt_cmd
,
4497 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4500 "BGP extended community attribute\n"
4501 "Route Target extended community\n"
4502 "VPN extended community\n")
4504 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4505 "extcommunity rt", NULL
);
4508 ALIAS (no_set_ecommunity_rt
,
4509 no_set_ecommunity_rt_short_cmd
,
4510 "no set extcommunity rt",
4513 "BGP extended community attribute\n"
4514 "Route Target extended community\n")
4516 DEFUN (set_ecommunity_soo
,
4517 set_ecommunity_soo_cmd
,
4518 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4520 "BGP extended community attribute\n"
4521 "Site-of-Origin extended community\n"
4522 "VPN extended community\n")
4528 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4529 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4530 "extcommunity soo", str
);
4531 XFREE(MTYPE_TMP
, str
);
4536 DEFUN (no_set_ecommunity_soo
,
4537 no_set_ecommunity_soo_cmd
,
4538 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4541 "BGP extended community attribute\n"
4542 "Site-of-Origin extended community\n"
4543 "VPN extended community\n")
4545 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4546 "extcommunity soo", NULL
);
4549 ALIAS (no_set_ecommunity_soo
,
4550 no_set_ecommunity_soo_short_cmd
,
4551 "no set extcommunity soo",
4554 "GP extended community attribute\n"
4555 "Site-of-Origin extended community\n")
4559 "set origin <egp|igp|incomplete>",
4564 "unknown heritage\n")
4567 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4568 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4570 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4571 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4573 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4574 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4575 "origin", "incomplete");
4577 vty_out(vty
, "%% Invalid set origin type\n");
4578 return CMD_WARNING_CONFIG_FAILED
;
4582 DEFUN (no_set_origin
,
4584 "no set origin [<egp|igp|incomplete>]",
4590 "unknown heritage\n")
4592 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4597 DEFUN (set_atomic_aggregate
,
4598 set_atomic_aggregate_cmd
,
4599 "set atomic-aggregate",
4601 "BGP atomic aggregate attribute\n" )
4603 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4604 "atomic-aggregate", NULL
);
4607 DEFUN (no_set_atomic_aggregate
,
4608 no_set_atomic_aggregate_cmd
,
4609 "no set atomic-aggregate",
4612 "BGP atomic aggregate attribute\n" )
4614 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4615 "atomic-aggregate", NULL
);
4618 DEFUN (set_aggregator_as
,
4619 set_aggregator_as_cmd
,
4620 "set aggregator as (1-4294967295) A.B.C.D",
4622 "BGP aggregator attribute\n"
4623 "AS number of aggregator\n"
4625 "IP address of aggregator\n")
4630 struct in_addr address
;
4633 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4635 vty_out(vty
, "Aggregator IP address is invalid\n");
4636 return CMD_WARNING_CONFIG_FAILED
;
4639 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4640 strlen(argv
[idx_number
]->arg
)
4641 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4643 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4645 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4646 "aggregator as", argstr
);
4648 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4654 DEFUN (no_set_aggregator_as
,
4655 no_set_aggregator_as_cmd
,
4656 "no set aggregator as [(1-4294967295) A.B.C.D]",
4659 "BGP aggregator attribute\n"
4660 "AS number of aggregator\n"
4662 "IP address of aggregator\n")
4667 struct in_addr address
;
4670 if (argc
<= idx_asn
)
4671 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4672 "aggregator as", NULL
);
4674 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4676 vty_out(vty
, "Aggregator IP address is invalid\n");
4677 return CMD_WARNING_CONFIG_FAILED
;
4680 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4681 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4684 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4686 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4687 "aggregator as", argstr
);
4689 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4694 DEFUN (match_ipv6_next_hop
,
4695 match_ipv6_next_hop_cmd
,
4696 "match ipv6 next-hop X:X::X:X",
4699 "Match IPv6 next-hop address of route\n"
4700 "IPv6 address of next hop\n")
4703 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4704 RMAP_EVENT_MATCH_ADDED
);
4707 DEFUN (no_match_ipv6_next_hop
,
4708 no_match_ipv6_next_hop_cmd
,
4709 "no match ipv6 next-hop X:X::X:X",
4713 "Match IPv6 next-hop address of route\n"
4714 "IPv6 address of next hop\n")
4717 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4718 RMAP_EVENT_MATCH_DELETED
);
4722 DEFUN (set_ipv6_nexthop_peer
,
4723 set_ipv6_nexthop_peer_cmd
,
4724 "set ipv6 next-hop peer-address",
4727 "Next hop address\n"
4728 "Use peer address (for BGP only)\n")
4730 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4731 "ipv6 next-hop peer-address", NULL
);
4734 DEFUN (no_set_ipv6_nexthop_peer
,
4735 no_set_ipv6_nexthop_peer_cmd
,
4736 "no set ipv6 next-hop peer-address",
4740 "IPv6 next-hop address\n"
4741 "Use peer address (for BGP only)\n")
4743 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4744 "ipv6 next-hop peer-address", NULL
);
4747 DEFUN (set_ipv6_nexthop_prefer_global
,
4748 set_ipv6_nexthop_prefer_global_cmd
,
4749 "set ipv6 next-hop prefer-global",
4752 "IPv6 next-hop address\n"
4753 "Prefer global over link-local if both exist\n")
4755 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4756 "ipv6 next-hop prefer-global", NULL
);
4760 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4761 no_set_ipv6_nexthop_prefer_global_cmd
,
4762 "no set ipv6 next-hop prefer-global",
4766 "IPv6 next-hop address\n"
4767 "Prefer global over link-local if both exist\n")
4769 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4770 "ipv6 next-hop prefer-global", NULL
);
4773 DEFUN (set_ipv6_nexthop_global
,
4774 set_ipv6_nexthop_global_cmd
,
4775 "set ipv6 next-hop global X:X::X:X",
4778 "IPv6 next-hop address\n"
4779 "IPv6 global address\n"
4780 "IPv6 address of next hop\n")
4783 struct in6_addr addr
;
4786 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4788 vty_out(vty
, "%% Malformed nexthop address\n");
4789 return CMD_WARNING_CONFIG_FAILED
;
4791 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4792 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4793 vty_out(vty
, "%% Invalid global nexthop address\n");
4794 return CMD_WARNING_CONFIG_FAILED
;
4797 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4798 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4802 DEFUN (no_set_ipv6_nexthop_global
,
4803 no_set_ipv6_nexthop_global_cmd
,
4804 "no set ipv6 next-hop global X:X::X:X",
4808 "IPv6 next-hop address\n"
4809 "IPv6 global address\n"
4810 "IPv6 address of next hop\n")
4813 if (argc
<= idx_ipv6
)
4814 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4815 "ipv6 next-hop global", NULL
);
4816 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4817 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4820 #ifdef KEEP_OLD_VPN_COMMANDS
4821 DEFUN (set_vpn_nexthop
,
4822 set_vpn_nexthop_cmd
,
4823 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4825 "VPNv4 information\n"
4826 "VPN next-hop address\n"
4827 "IP address of next hop\n"
4828 "VPNv6 information\n"
4829 "VPN next-hop address\n"
4830 "IPv6 address of next hop\n")
4836 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4838 return generic_set_add(
4839 vty
, VTY_GET_CONTEXT(route_map_index
),
4840 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4842 return generic_set_add(
4843 vty
, VTY_GET_CONTEXT(route_map_index
),
4844 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4849 DEFUN (no_set_vpn_nexthop
,
4850 no_set_vpn_nexthop_cmd
,
4851 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4854 "VPNv4 information\n"
4855 "VPN next-hop address\n"
4856 "IP address of next hop\n"
4857 "VPNv6 information\n"
4858 "VPN next-hop address\n"
4859 "IPv6 address of next hop\n")
4869 arg
= argv
[idx_ip
]->arg
;
4870 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4872 return generic_set_delete(
4873 vty
, VTY_GET_CONTEXT(route_map_index
),
4874 "ipv4 vpn next-hop", arg
);
4876 return generic_set_delete(
4877 vty
, VTY_GET_CONTEXT(route_map_index
),
4878 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4882 #endif /* KEEP_OLD_VPN_COMMANDS */
4884 DEFUN (set_ipx_vpn_nexthop
,
4885 set_ipx_vpn_nexthop_cmd
,
4886 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4888 "IPv4 information\n"
4889 "IPv6 information\n"
4891 "VPN next-hop address\n"
4892 "IP address of next hop\n"
4893 "IPv6 address of next hop\n")
4899 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4901 return generic_set_add(
4902 vty
, VTY_GET_CONTEXT(route_map_index
),
4903 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4905 return generic_set_add(
4906 vty
, VTY_GET_CONTEXT(route_map_index
),
4907 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4912 DEFUN (no_set_ipx_vpn_nexthop
,
4913 no_set_ipx_vpn_nexthop_cmd
,
4914 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4917 "IPv4 information\n"
4918 "IPv6 information\n"
4920 "VPN next-hop address\n"
4921 "IP address of next hop\n"
4922 "IPv6 address of next hop\n")
4932 arg
= argv
[idx_ip
]->arg
;
4933 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4935 return generic_set_delete(
4936 vty
, VTY_GET_CONTEXT(route_map_index
),
4937 "ipv4 vpn next-hop", arg
);
4939 return generic_set_delete(
4940 vty
, VTY_GET_CONTEXT(route_map_index
),
4941 "ipv6 vpn next-hop", arg
);
4946 DEFUN (set_originator_id
,
4947 set_originator_id_cmd
,
4948 "set originator-id A.B.C.D",
4950 "BGP originator ID attribute\n"
4951 "IP address of originator\n")
4954 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4955 "originator-id", argv
[idx_ipv4
]->arg
);
4959 DEFUN (no_set_originator_id
,
4960 no_set_originator_id_cmd
,
4961 "no set originator-id [A.B.C.D]",
4964 "BGP originator ID attribute\n"
4965 "IP address of originator\n")
4969 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4971 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4972 "originator-id", arg
);
4976 /* Initialization of route map. */
4977 void bgp_route_map_init(void)
4981 route_map_add_hook(bgp_route_map_add
);
4982 route_map_delete_hook(bgp_route_map_delete
);
4983 route_map_event_hook(bgp_route_map_event
);
4985 route_map_match_interface_hook(generic_match_add
);
4986 route_map_no_match_interface_hook(generic_match_delete
);
4988 route_map_match_ip_address_hook(generic_match_add
);
4989 route_map_no_match_ip_address_hook(generic_match_delete
);
4991 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
4992 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
4994 route_map_match_ip_next_hop_hook(generic_match_add
);
4995 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
4997 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
4998 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5000 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5001 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5003 route_map_match_ipv6_address_hook(generic_match_add
);
5004 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5006 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5007 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5009 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5010 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5012 route_map_match_metric_hook(generic_match_add
);
5013 route_map_no_match_metric_hook(generic_match_delete
);
5015 route_map_match_tag_hook(generic_match_add
);
5016 route_map_no_match_tag_hook(generic_match_delete
);
5018 route_map_set_ip_nexthop_hook(generic_set_add
);
5019 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5021 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5022 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5024 route_map_set_metric_hook(generic_set_add
);
5025 route_map_no_set_metric_hook(generic_set_delete
);
5027 route_map_set_tag_hook(generic_set_add
);
5028 route_map_no_set_tag_hook(generic_set_delete
);
5030 route_map_install_match(&route_match_peer_cmd
);
5031 route_map_install_match(&route_match_local_pref_cmd
);
5032 #if defined(HAVE_LUA)
5033 route_map_install_match(&route_match_command_cmd
);
5035 route_map_install_match(&route_match_ip_address_cmd
);
5036 route_map_install_match(&route_match_ip_next_hop_cmd
);
5037 route_map_install_match(&route_match_ip_route_source_cmd
);
5038 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5039 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5040 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5041 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5042 route_map_install_match(&route_match_aspath_cmd
);
5043 route_map_install_match(&route_match_community_cmd
);
5044 route_map_install_match(&route_match_lcommunity_cmd
);
5045 route_map_install_match(&route_match_ecommunity_cmd
);
5046 route_map_install_match(&route_match_local_pref_cmd
);
5047 route_map_install_match(&route_match_metric_cmd
);
5048 route_map_install_match(&route_match_origin_cmd
);
5049 route_map_install_match(&route_match_probability_cmd
);
5050 route_map_install_match(&route_match_interface_cmd
);
5051 route_map_install_match(&route_match_tag_cmd
);
5052 route_map_install_match(&route_match_mac_address_cmd
);
5053 route_map_install_match(&route_match_evpn_vni_cmd
);
5054 route_map_install_match(&route_match_evpn_route_type_cmd
);
5055 route_map_install_match(&route_match_evpn_default_route_cmd
);
5056 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5058 route_map_install_set(&route_set_ip_nexthop_cmd
);
5059 route_map_install_set(&route_set_local_pref_cmd
);
5060 route_map_install_set(&route_set_weight_cmd
);
5061 route_map_install_set(&route_set_label_index_cmd
);
5062 route_map_install_set(&route_set_metric_cmd
);
5063 route_map_install_set(&route_set_aspath_prepend_cmd
);
5064 route_map_install_set(&route_set_aspath_exclude_cmd
);
5065 route_map_install_set(&route_set_origin_cmd
);
5066 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5067 route_map_install_set(&route_set_aggregator_as_cmd
);
5068 route_map_install_set(&route_set_community_cmd
);
5069 route_map_install_set(&route_set_community_delete_cmd
);
5070 route_map_install_set(&route_set_lcommunity_cmd
);
5071 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5072 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5073 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5074 route_map_install_set(&route_set_originator_id_cmd
);
5075 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5076 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5077 route_map_install_set(&route_set_tag_cmd
);
5078 route_map_install_set(&route_set_label_index_cmd
);
5080 install_element(RMAP_NODE
, &match_peer_cmd
);
5081 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5082 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5083 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5084 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5085 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5086 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5087 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5088 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5089 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5090 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5091 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5092 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5093 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5094 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5095 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5096 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5098 install_element(RMAP_NODE
, &match_aspath_cmd
);
5099 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5100 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5101 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5102 install_element(RMAP_NODE
, &match_community_cmd
);
5103 install_element(RMAP_NODE
, &no_match_community_cmd
);
5104 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5105 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5106 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5107 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5108 install_element(RMAP_NODE
, &match_origin_cmd
);
5109 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5110 install_element(RMAP_NODE
, &match_probability_cmd
);
5111 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5113 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5114 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5115 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5116 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5117 install_element(RMAP_NODE
, &set_weight_cmd
);
5118 install_element(RMAP_NODE
, &set_label_index_cmd
);
5119 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5120 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5121 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5122 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5123 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5124 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5125 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5126 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5127 install_element(RMAP_NODE
, &set_origin_cmd
);
5128 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5129 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5130 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5131 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5132 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5133 install_element(RMAP_NODE
, &set_community_cmd
);
5134 install_element(RMAP_NODE
, &set_community_none_cmd
);
5135 install_element(RMAP_NODE
, &no_set_community_cmd
);
5136 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5137 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5138 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5139 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5140 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5141 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5142 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5143 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5144 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5145 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5146 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5147 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5148 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5149 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5150 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5151 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5152 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5153 #ifdef KEEP_OLD_VPN_COMMANDS
5154 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5155 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5156 #endif /* KEEP_OLD_VPN_COMMANDS */
5157 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5158 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5159 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5160 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5162 route_map_install_match(&route_match_ipv6_address_cmd
);
5163 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5164 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5165 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5166 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5167 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5168 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5169 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5171 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5172 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5173 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5174 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5175 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5176 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5177 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5178 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5179 #if defined(HAVE_LUA)
5180 install_element(RMAP_NODE
, &match_command_cmd
);
5181 install_element(RMAP_NODE
, &no_match_command_cmd
);
5185 void bgp_route_map_terminate(void)
5187 /* ToDo: Cleanup all the used memory */