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"
65 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
68 #ifndef VTYSH_EXTRACT_PL
69 #include "bgpd/bgp_routemap_clippy.c"
72 /* Memo of route-map commands.
81 ip route-source : Done
85 ipv6 route-source: (This will not be implemented by bgpd)
86 ipv6 prefix-list : Done
87 length : (This will not be implemented by bgpd)
89 route-type : (This will not be implemented by bgpd)
91 local-preference : Done
93 set as-path prepend : Done
95 automatic-tag : (This will not be implemented by bgpd)
97 large-community : Done
98 large-comm-list : Done
101 default : (This will not be implemented by bgpd)
102 interface : (This will not be implemented by bgpd)
103 ip default : (This will not be implemented by bgpd)
105 ip precedence : (This will not be implemented by bgpd)
106 ip tos : (This will not be implemented by bgpd)
107 level : (This will not be implemented by bgpd)
108 local-preference : Done
110 metric-type : Not yet
117 set ipv6 next-hop global: Done
118 set ipv6 next-hop prefer-global: Done
119 set ipv6 next-hop local : Done
120 set as-path exclude : Done
124 /* generic value manipulation to be shared in multiple rules */
126 #define RMAP_VALUE_SET 0
127 #define RMAP_VALUE_ADD 1
128 #define RMAP_VALUE_SUB 2
136 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
138 if (rv
->variable
== 0 && value
== rv
->value
)
144 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
149 switch (rv
->variable
) {
158 switch (rv
->action
) {
160 if (current
> UINT32_MAX
- value
)
162 return current
+ value
;
164 if (current
<= value
)
166 return current
- value
;
172 static void *route_value_compile(const char *arg
)
174 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
175 unsigned long larg
= 0;
177 struct rmap_value
*rv
;
180 action
= RMAP_VALUE_ADD
;
182 } else if (arg
[0] == '-') {
183 action
= RMAP_VALUE_SUB
;
187 if (all_digit(arg
)) {
189 larg
= strtoul(arg
, &endptr
, 10);
190 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
193 if (strcmp(arg
, "rtt") == 0)
199 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
;
328 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
330 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
333 /* Route map commands for ip address matching. */
334 struct route_map_rule_cmd route_match_peer_cmd
= {"peer", route_match_peer
,
335 route_match_peer_compile
,
336 route_match_peer_free
};
338 #if defined(HAVE_LUA)
339 static route_map_result_t
route_match_command(void *rule
,
340 const struct prefix
*prefix
,
341 route_map_object_t type
,
344 int status
= RMAP_NOMATCH
;
345 u_int32_t locpref
= 0;
346 u_int32_t newlocpref
= 0;
347 enum lua_rm_status lrm_status
;
348 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
349 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
355 * Setup the prefix information to pass in
357 lua_setup_prefix_table(L
, prefix
);
359 zlog_debug("Set up prefix table");
361 * Setup the bgp_path_info information
364 lua_pushinteger(L
, path
->attr
->med
);
365 lua_setfield(L
, -2, "metric");
366 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
367 lua_setfield(L
, -2, "ifindex");
368 lua_pushstring(L
, path
->attr
->aspath
->str
);
369 lua_setfield(L
, -2, "aspath");
370 lua_pushinteger(L
, path
->attr
->local_pref
);
371 lua_setfield(L
, -2, "localpref");
372 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
373 lua_setglobal(L
, "nexthop");
375 zlog_debug("Set up nexthop information");
379 lrm_status
= lua_run_rm_rule(L
, rule
);
380 switch (lrm_status
) {
382 zlog_debug("RM_FAILURE");
385 zlog_debug("RM_NOMATCH");
387 case LUA_RM_MATCH_AND_CHANGE
:
388 zlog_debug("MATCH AND CHANGE");
389 lua_getglobal(L
, "nexthop");
390 path
->attr
->med
= get_integer(L
, "metric");
392 * This needs to be abstraced with the set function
394 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
395 locpref
= path
->attr
->local_pref
;
396 newlocpref
= get_integer(L
, "localpref");
397 if (newlocpref
!= locpref
) {
398 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
399 path
->attr
->local_pref
= newlocpref
;
404 zlog_debug("MATCH ONLY");
412 static void *route_match_command_compile(const char *arg
)
416 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
421 route_match_command_free(void *rule
)
423 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
426 struct route_map_rule_cmd route_match_command_cmd
= {
429 route_match_command_compile
,
430 route_match_command_free
434 /* `match ip address IP_ACCESS_LIST' */
436 /* Match function should return 1 if match is success else return
438 static route_map_result_t
route_match_ip_address(void *rule
,
439 const struct prefix
*prefix
,
440 route_map_object_t type
,
443 struct access_list
*alist
;
445 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
446 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
450 return (access_list_apply(alist
, prefix
) == FILTER_DENY
457 /* Route map `ip address' match statement. `arg' should be
459 static void *route_match_ip_address_compile(const char *arg
)
461 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
464 /* Free route map's compiled `ip address' value. */
465 static void route_match_ip_address_free(void *rule
)
467 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
470 /* Route map commands for ip address matching. */
471 struct route_map_rule_cmd route_match_ip_address_cmd
= {
472 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
473 route_match_ip_address_free
};
475 /* `match ip next-hop IP_ADDRESS' */
477 /* Match function return 1 if match is success else return zero. */
478 static route_map_result_t
route_match_ip_next_hop(void *rule
,
479 const struct prefix
*prefix
,
480 route_map_object_t type
,
483 struct access_list
*alist
;
484 struct bgp_path_info
*path
;
485 struct prefix_ipv4 p
;
487 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
490 p
.prefix
= path
->attr
->nexthop
;
491 p
.prefixlen
= IPV4_MAX_BITLEN
;
493 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
497 return (access_list_apply(alist
, &p
) == FILTER_DENY
504 /* Route map `ip next-hop' match statement. `arg' is
506 static void *route_match_ip_next_hop_compile(const char *arg
)
508 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
511 /* Free route map's compiled `ip address' value. */
512 static void route_match_ip_next_hop_free(void *rule
)
514 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
517 /* Route map commands for ip next-hop matching. */
518 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
519 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
520 route_match_ip_next_hop_free
};
522 /* `match ip route-source ACCESS-LIST' */
524 /* Match function return 1 if match is success else return zero. */
525 static route_map_result_t
route_match_ip_route_source(void *rule
,
526 const struct prefix
*pfx
,
527 route_map_object_t type
,
530 struct access_list
*alist
;
531 struct bgp_path_info
*path
;
533 struct prefix_ipv4 p
;
535 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
539 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
543 p
.prefix
= peer
->su
.sin
.sin_addr
;
544 p
.prefixlen
= IPV4_MAX_BITLEN
;
546 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
550 return (access_list_apply(alist
, &p
) == FILTER_DENY
557 /* Route map `ip route-source' match statement. `arg' is
559 static void *route_match_ip_route_source_compile(const char *arg
)
561 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
564 /* Free route map's compiled `ip address' value. */
565 static void route_match_ip_route_source_free(void *rule
)
567 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
570 /* Route map commands for ip route-source matching. */
571 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
572 "ip route-source", route_match_ip_route_source
,
573 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
575 /* `match ip address prefix-list PREFIX_LIST' */
577 static route_map_result_t
578 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
579 route_map_object_t type
, void *object
)
581 struct prefix_list
*plist
;
583 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
584 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
588 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
595 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
597 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
600 static void route_match_ip_address_prefix_list_free(void *rule
)
602 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
605 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
606 "ip address prefix-list", route_match_ip_address_prefix_list
,
607 route_match_ip_address_prefix_list_compile
,
608 route_match_ip_address_prefix_list_free
};
610 /* `match ip next-hop prefix-list PREFIX_LIST' */
612 static route_map_result_t
613 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
614 route_map_object_t type
, void *object
)
616 struct prefix_list
*plist
;
617 struct bgp_path_info
*path
;
618 struct prefix_ipv4 p
;
620 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
623 p
.prefix
= path
->attr
->nexthop
;
624 p
.prefixlen
= IPV4_MAX_BITLEN
;
626 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
630 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
637 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
639 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
642 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
644 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
647 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
648 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
649 route_match_ip_next_hop_prefix_list_compile
,
650 route_match_ip_next_hop_prefix_list_free
};
652 /* `match ip next-hop type <blackhole>' */
654 static route_map_result_t
655 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
656 route_map_object_t type
, void *object
)
658 struct bgp_path_info
*path
;
660 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
661 path
= (struct bgp_path_info
*)object
;
662 if (!path
|| !path
->attr
)
663 return RMAP_DENYMATCH
;
665 /* If nexthop interface's index can't be resolved and nexthop is
666 set to any address then mark it as type `blackhole`.
667 This logic works for matching kernel/static routes like:
668 `ip route add blackhole 10.0.0.1`. */
669 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
670 && !path
->attr
->nh_ifindex
)
676 static void *route_match_ip_next_hop_type_compile(const char *arg
)
678 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
681 static void route_match_ip_next_hop_type_free(void *rule
)
683 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
686 static struct route_map_rule_cmd route_match_ip_next_hop_type_cmd
= {
687 "ip next-hop type", route_match_ip_next_hop_type
,
688 route_match_ip_next_hop_type_compile
,
689 route_match_ip_next_hop_type_free
};
691 /* `match ip route-source prefix-list PREFIX_LIST' */
693 static route_map_result_t
694 route_match_ip_route_source_prefix_list(void *rule
,
695 const struct prefix
*prefix
,
696 route_map_object_t type
, void *object
)
698 struct prefix_list
*plist
;
699 struct bgp_path_info
*path
;
701 struct prefix_ipv4 p
;
703 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
707 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
711 p
.prefix
= peer
->su
.sin
.sin_addr
;
712 p
.prefixlen
= IPV4_MAX_BITLEN
;
714 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
718 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
725 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
727 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
730 static void route_match_ip_route_source_prefix_list_free(void *rule
)
732 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
735 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
736 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
737 route_match_ip_route_source_prefix_list_compile
,
738 route_match_ip_route_source_prefix_list_free
};
740 /* `match evpn default-route' */
742 /* Match function should return 1 if match is success else 0 */
743 static route_map_result_t
route_match_evpn_default_route(void *rule
,
744 const struct prefix
*p
,
748 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
754 /* Route map commands for default-route matching. */
755 struct route_map_rule_cmd route_match_evpn_default_route_cmd
= {
756 "evpn default-route", route_match_evpn_default_route
, NULL
, NULL
};
758 /* `match mac address MAC_ACCESS_LIST' */
760 /* Match function should return 1 if match is success else return
762 static route_map_result_t
route_match_mac_address(void *rule
,
763 const struct prefix
*prefix
,
764 route_map_object_t type
,
767 struct access_list
*alist
;
770 if (type
== RMAP_BGP
) {
771 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
775 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
778 p
.family
= AF_ETHERNET
;
779 p
.prefixlen
= ETH_ALEN
* 8;
780 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
782 return (access_list_apply(alist
, &p
) == FILTER_DENY
790 /* Route map `mac address' match statement. `arg' should be
792 static void *route_match_mac_address_compile(const char *arg
)
794 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
797 /* Free route map's compiled `ip address' value. */
798 static void route_match_mac_address_free(void *rule
)
800 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
803 /* Route map commands for mac address matching. */
804 struct route_map_rule_cmd route_match_mac_address_cmd
= {
805 "mac address", route_match_mac_address
, route_match_mac_address_compile
,
806 route_match_mac_address_free
};
810 /* Match function should return 1 if match is success else return
812 static route_map_result_t
route_match_vni(void *rule
,
813 const struct prefix
*prefix
,
814 route_map_object_t type
, void *object
)
817 struct bgp_path_info
*path
= NULL
;
819 if (type
== RMAP_BGP
) {
820 vni
= *((vni_t
*)rule
);
821 path
= (struct bgp_path_info
*)object
;
823 if (path
->extra
== NULL
)
826 if (vni
== label2vni(&path
->extra
->label
[0]))
833 /* Route map `vni' match statement. */
834 static void *route_match_vni_compile(const char *arg
)
839 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
843 *vni
= strtoul(arg
, &end
, 10);
845 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
852 /* Free route map's compiled `vni' value. */
853 static void route_match_vni_free(void *rule
)
855 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
858 /* Route map commands for vni matching. */
859 struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
860 "evpn vni", route_match_vni
, route_match_vni_compile
,
861 route_match_vni_free
};
863 /* `match evpn route-type' */
865 /* Match function should return 1 if match is success else return
867 static route_map_result_t
route_match_evpn_route_type(void *rule
,
868 const struct prefix
*pfx
,
869 route_map_object_t type
,
872 uint8_t route_type
= 0;
874 if (type
== RMAP_BGP
) {
875 route_type
= *((uint8_t *)rule
);
877 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
884 /* Route map `route-type' match statement. */
885 static void *route_match_evpn_route_type_compile(const char *arg
)
887 uint8_t *route_type
= NULL
;
889 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
891 if (strncmp(arg
, "ma", 2) == 0)
892 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
893 else if (strncmp(arg
, "mu", 2) == 0)
894 *route_type
= BGP_EVPN_IMET_ROUTE
;
896 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
901 /* Free route map's compiled `route-type' value. */
902 static void route_match_evpn_route_type_free(void *rule
)
904 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
907 /* Route map commands for evpn route-type matching. */
908 struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
909 "evpn route-type", route_match_evpn_route_type
,
910 route_match_evpn_route_type_compile
, route_match_evpn_route_type_free
};
912 /* Route map commands for VRF route leak with source vrf matching */
913 static route_map_result_t
route_match_vrl_source_vrf(void *rule
,
914 struct prefix
*prefix
,
915 route_map_object_t type
,
918 struct bgp_path_info
*path
;
921 if (type
== RMAP_BGP
) {
923 path
= (struct bgp_path_info
*)object
;
925 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
928 if (path
->extra
== NULL
)
931 if (strncmp(vrf_name
, vrf_id_to_name(
932 path
->extra
->bgp_orig
->vrf_id
), VRF_NAMSIZ
)
940 static void *route_match_vrl_source_vrf_compile(const char *arg
)
942 uint8_t *vrf_name
= NULL
;
944 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
949 /* Free route map's compiled `route-type' value. */
950 static void route_match_vrl_source_vrf_free(void *rule
)
952 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
955 struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
956 "source-vrf", route_match_vrl_source_vrf
,
957 route_match_vrl_source_vrf_compile
,
958 route_match_vrl_source_vrf_free
};
960 /* `match local-preference LOCAL-PREF' */
962 /* Match function return 1 if match is success else return zero. */
963 static route_map_result_t
route_match_local_pref(void *rule
,
964 const struct prefix
*prefix
,
965 route_map_object_t type
,
968 uint32_t *local_pref
;
969 struct bgp_path_info
*path
;
971 if (type
== RMAP_BGP
) {
975 if (path
->attr
->local_pref
== *local_pref
)
983 /* Route map `match local-preference' match statement.
984 `arg' is local-pref value */
985 static void *route_match_local_pref_compile(const char *arg
)
987 uint32_t *local_pref
;
989 unsigned long tmpval
;
991 /* Locpref value shoud be integer. */
996 tmpval
= strtoul(arg
, &endptr
, 10);
997 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
1000 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
1005 *local_pref
= tmpval
;
1009 /* Free route map's compiled `match local-preference' value. */
1010 static void route_match_local_pref_free(void *rule
)
1012 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1015 /* Route map commands for metric matching. */
1016 struct route_map_rule_cmd route_match_local_pref_cmd
= {
1017 "local-preference", route_match_local_pref
,
1018 route_match_local_pref_compile
, route_match_local_pref_free
};
1020 /* `match metric METRIC' */
1022 /* Match function return 1 if match is success else return zero. */
1023 static route_map_result_t
route_match_metric(void *rule
,
1024 const struct prefix
*prefix
,
1025 route_map_object_t type
,
1028 struct rmap_value
*rv
;
1029 struct bgp_path_info
*path
;
1031 if (type
== RMAP_BGP
) {
1034 return route_value_match(rv
, path
->attr
->med
);
1036 return RMAP_NOMATCH
;
1039 /* Route map commands for metric matching. */
1040 struct route_map_rule_cmd route_match_metric_cmd
= {
1041 "metric", route_match_metric
, route_value_compile
, route_value_free
,
1044 /* `match as-path ASPATH' */
1046 /* Match function for as-path match. I assume given object is */
1047 static route_map_result_t
route_match_aspath(void *rule
,
1048 const struct prefix
*prefix
,
1049 route_map_object_t type
,
1053 struct as_list
*as_list
;
1054 struct bgp_path_info
*path
;
1056 if (type
== RMAP_BGP
) {
1057 as_list
= as_list_lookup((char *)rule
);
1058 if (as_list
== NULL
)
1059 return RMAP_NOMATCH
;
1063 /* Perform match. */
1064 return ((as_list_apply(as_list
, path
->attr
->aspath
)
1069 return RMAP_NOMATCH
;
1072 /* Compile function for as-path match. */
1073 static void *route_match_aspath_compile(const char *arg
)
1075 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1078 /* Compile function for as-path match. */
1079 static void route_match_aspath_free(void *rule
)
1081 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1084 /* Route map commands for aspath matching. */
1085 struct route_map_rule_cmd route_match_aspath_cmd
= {
1086 "as-path", route_match_aspath
, route_match_aspath_compile
,
1087 route_match_aspath_free
};
1089 /* `match community COMMUNIY' */
1090 struct rmap_community
{
1096 /* Match function for community match. */
1097 static route_map_result_t
route_match_community(void *rule
,
1098 const struct prefix
*prefix
,
1099 route_map_object_t type
,
1102 struct community_list
*list
;
1103 struct bgp_path_info
*path
;
1104 struct rmap_community
*rcom
= rule
;
1106 if (type
== RMAP_BGP
) {
1110 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1112 COMMUNITY_LIST_MASTER
);
1114 return RMAP_NOMATCH
;
1117 if (community_list_exact_match(path
->attr
->community
,
1121 if (community_list_match(path
->attr
->community
, list
))
1125 return RMAP_NOMATCH
;
1128 /* Compile function for community match. */
1129 static void *route_match_community_compile(const char *arg
)
1131 struct rmap_community
*rcom
;
1135 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1137 p
= strchr(arg
, ' ');
1140 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1141 memcpy(rcom
->name
, arg
, len
);
1144 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1148 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1152 /* Compile function for community match. */
1153 static void route_match_community_free(void *rule
)
1155 struct rmap_community
*rcom
= rule
;
1157 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1158 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1161 /* Route map commands for community matching. */
1162 struct route_map_rule_cmd route_match_community_cmd
= {
1163 "community", route_match_community
, route_match_community_compile
,
1164 route_match_community_free
};
1166 /* Match function for lcommunity match. */
1167 static route_map_result_t
route_match_lcommunity(void *rule
,
1168 const struct prefix
*prefix
,
1169 route_map_object_t type
,
1172 struct community_list
*list
;
1173 struct bgp_path_info
*path
;
1174 struct rmap_community
*rcom
= rule
;
1176 if (type
== RMAP_BGP
) {
1179 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1181 LARGE_COMMUNITY_LIST_MASTER
);
1183 return RMAP_NOMATCH
;
1185 if (lcommunity_list_match(path
->attr
->lcommunity
, list
))
1188 return RMAP_NOMATCH
;
1191 /* Compile function for community match. */
1192 static void *route_match_lcommunity_compile(const char *arg
)
1194 struct rmap_community
*rcom
;
1198 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1200 p
= strchr(arg
, ' ');
1203 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1204 memcpy(rcom
->name
, arg
, len
);
1206 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1210 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1214 /* Compile function for community match. */
1215 static void route_match_lcommunity_free(void *rule
)
1217 struct rmap_community
*rcom
= rule
;
1219 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1220 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1223 /* Route map commands for community matching. */
1224 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1225 "large-community", route_match_lcommunity
,
1226 route_match_lcommunity_compile
, route_match_lcommunity_free
};
1229 /* Match function for extcommunity match. */
1230 static route_map_result_t
route_match_ecommunity(void *rule
,
1231 const struct prefix
*prefix
,
1232 route_map_object_t type
,
1235 struct community_list
*list
;
1236 struct bgp_path_info
*path
;
1237 struct rmap_community
*rcom
= rule
;
1239 if (type
== RMAP_BGP
) {
1242 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1244 EXTCOMMUNITY_LIST_MASTER
);
1246 return RMAP_NOMATCH
;
1248 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1251 return RMAP_NOMATCH
;
1254 /* Compile function for extcommunity match. */
1255 static void *route_match_ecommunity_compile(const char *arg
)
1257 struct rmap_community
*rcom
;
1259 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1260 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1261 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1266 /* Compile function for extcommunity match. */
1267 static void route_match_ecommunity_free(void *rule
)
1269 struct rmap_community
*rcom
= rule
;
1271 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1272 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1275 /* Route map commands for community matching. */
1276 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1277 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1278 route_match_ecommunity_free
};
1280 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1281 and `address-family vpnv4'. */
1283 /* `match origin' */
1284 static route_map_result_t
route_match_origin(void *rule
,
1285 const struct prefix
*prefix
,
1286 route_map_object_t type
,
1290 struct bgp_path_info
*path
;
1292 if (type
== RMAP_BGP
) {
1296 if (path
->attr
->origin
== *origin
)
1300 return RMAP_NOMATCH
;
1303 static void *route_match_origin_compile(const char *arg
)
1307 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1309 if (strcmp(arg
, "igp") == 0)
1311 else if (strcmp(arg
, "egp") == 0)
1319 /* Free route map's compiled `ip address' value. */
1320 static void route_match_origin_free(void *rule
)
1322 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1325 /* Route map commands for origin matching. */
1326 struct route_map_rule_cmd route_match_origin_cmd
= {
1327 "origin", route_match_origin
, route_match_origin_compile
,
1328 route_match_origin_free
};
1330 /* match probability { */
1332 static route_map_result_t
route_match_probability(void *rule
,
1333 const struct prefix
*prefix
,
1334 route_map_object_t type
,
1339 switch (*(long *)rule
) {
1345 if (r
< *(long *)rule
) {
1350 return RMAP_NOMATCH
;
1353 static void *route_match_probability_compile(const char *arg
)
1359 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1369 *lobule
= RAND_MAX
/ 100 * perc
;
1375 static void route_match_probability_free(void *rule
)
1377 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1380 struct route_map_rule_cmd route_match_probability_cmd
= {
1381 "probability", route_match_probability
, route_match_probability_compile
,
1382 route_match_probability_free
};
1384 /* `match interface IFNAME' */
1385 /* Match function should return 1 if match is success else return
1387 static route_map_result_t
route_match_interface(void *rule
,
1388 const struct prefix
*prefix
,
1389 route_map_object_t type
,
1392 struct interface
*ifp
;
1393 struct bgp_path_info
*path
;
1395 if (type
== RMAP_BGP
) {
1398 if (!path
|| !path
->attr
)
1399 return RMAP_NOMATCH
;
1401 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1403 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1404 return RMAP_NOMATCH
;
1408 return RMAP_NOMATCH
;
1411 /* Route map `interface' match statement. `arg' should be
1413 static void *route_match_interface_compile(const char *arg
)
1415 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1418 /* Free route map's compiled `interface' value. */
1419 static void route_match_interface_free(void *rule
)
1421 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1424 /* Route map commands for ip address matching. */
1425 struct route_map_rule_cmd route_match_interface_cmd
= {
1426 "interface", route_match_interface
, route_match_interface_compile
,
1427 route_match_interface_free
};
1431 /* `set ip next-hop IP_ADDRESS' */
1433 /* Match function return 1 if match is success else return zero. */
1434 static route_map_result_t
route_match_tag(void *rule
,
1435 const struct prefix
*prefix
,
1436 route_map_object_t type
, void *object
)
1439 struct bgp_path_info
*path
;
1441 if (type
== RMAP_BGP
) {
1445 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1448 return RMAP_NOMATCH
;
1452 /* Route map commands for tag matching. */
1453 static struct route_map_rule_cmd route_match_tag_cmd
= {
1454 "tag", route_match_tag
, route_map_rule_tag_compile
,
1455 route_map_rule_tag_free
,
1459 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1460 struct rmap_ip_nexthop_set
{
1461 struct in_addr
*address
;
1466 static route_map_result_t
route_set_ip_nexthop(void *rule
,
1467 const struct prefix
*prefix
,
1468 route_map_object_t type
,
1471 struct rmap_ip_nexthop_set
*rins
= rule
;
1472 struct bgp_path_info
*path
;
1475 if (type
!= RMAP_BGP
)
1478 if (prefix
->family
== AF_INET6
)
1484 if (rins
->unchanged
) {
1485 SET_FLAG(path
->attr
->rmap_change_flags
,
1486 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1487 } else if (rins
->peer_address
) {
1488 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1489 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1491 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1492 path
->attr
->nexthop
.s_addr
=
1493 sockunion2ip(peer
->su_remote
);
1494 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1495 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1496 /* The next hop value will be set as part of
1497 * packet rewrite. Set the flags here to indicate
1498 * that rewrite needs to be done.
1499 * Also, clear the value.
1501 SET_FLAG(path
->attr
->rmap_change_flags
,
1502 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1503 path
->attr
->nexthop
.s_addr
= 0;
1506 /* Set next hop value. */
1507 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1508 path
->attr
->nexthop
= *rins
->address
;
1509 SET_FLAG(path
->attr
->rmap_change_flags
,
1510 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1511 /* case for MP-BGP : MPLS VPN */
1512 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1513 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1519 /* Route map `ip nexthop' compile function. Given string is converted
1520 to struct in_addr structure. */
1521 static void *route_set_ip_nexthop_compile(const char *arg
)
1523 struct rmap_ip_nexthop_set
*rins
;
1524 struct in_addr
*address
= NULL
;
1525 int peer_address
= 0;
1529 if (strcmp(arg
, "peer-address") == 0)
1531 else if (strcmp(arg
, "unchanged") == 0)
1534 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1535 sizeof(struct in_addr
));
1536 ret
= inet_aton(arg
, address
);
1539 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1544 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1545 sizeof(struct rmap_ip_nexthop_set
));
1547 rins
->address
= address
;
1548 rins
->peer_address
= peer_address
;
1549 rins
->unchanged
= unchanged
;
1554 /* Free route map's compiled `ip nexthop' value. */
1555 static void route_set_ip_nexthop_free(void *rule
)
1557 struct rmap_ip_nexthop_set
*rins
= rule
;
1560 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1562 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1565 /* Route map commands for ip nexthop set. */
1566 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1567 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1568 route_set_ip_nexthop_free
};
1570 /* `set local-preference LOCAL_PREF' */
1572 /* Set local preference. */
1573 static route_map_result_t
route_set_local_pref(void *rule
,
1574 const struct prefix
*prefix
,
1575 route_map_object_t type
,
1578 struct rmap_value
*rv
;
1579 struct bgp_path_info
*path
;
1580 uint32_t locpref
= 0;
1582 if (type
== RMAP_BGP
) {
1583 /* Fetch routemap's rule information. */
1587 /* Set local preference value. */
1588 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1589 locpref
= path
->attr
->local_pref
;
1591 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1592 path
->attr
->local_pref
=
1593 route_value_adjust(rv
, locpref
, path
->peer
);
1599 /* Set local preference rule structure. */
1600 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1601 "local-preference", route_set_local_pref
, route_value_compile
,
1605 /* `set weight WEIGHT' */
1608 static route_map_result_t
route_set_weight(void *rule
,
1609 const struct prefix
*prefix
,
1610 route_map_object_t type
,
1613 struct rmap_value
*rv
;
1614 struct bgp_path_info
*path
;
1616 if (type
== RMAP_BGP
) {
1617 /* Fetch routemap's rule information. */
1621 /* Set weight value. */
1622 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1628 /* Set local preference rule structure. */
1629 struct route_map_rule_cmd route_set_weight_cmd
= {
1630 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1633 /* `set metric METRIC' */
1635 /* Set metric to attribute. */
1636 static route_map_result_t
route_set_metric(void *rule
,
1637 const struct prefix
*prefix
,
1638 route_map_object_t type
,
1641 struct rmap_value
*rv
;
1642 struct bgp_path_info
*path
;
1645 if (type
== RMAP_BGP
) {
1646 /* Fetch routemap's rule information. */
1650 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1651 med
= path
->attr
->med
;
1653 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1654 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1659 /* Set metric rule structure. */
1660 struct route_map_rule_cmd route_set_metric_cmd
= {
1661 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1664 /* `set as-path prepend ASPATH' */
1666 /* For AS path prepend mechanism. */
1667 static route_map_result_t
route_set_aspath_prepend(void *rule
,
1668 const struct prefix
*prefix
,
1669 route_map_object_t type
,
1672 struct aspath
*aspath
;
1674 struct bgp_path_info
*path
;
1676 if (type
== RMAP_BGP
) {
1679 if (path
->attr
->aspath
->refcnt
)
1680 new = aspath_dup(path
->attr
->aspath
);
1682 new = path
->attr
->aspath
;
1684 if ((uintptr_t)rule
> 10) {
1686 aspath_prepend(aspath
, new);
1688 as_t as
= aspath_leftmost(new);
1690 as
= path
->peer
->as
;
1691 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1694 path
->attr
->aspath
= new;
1700 static void *route_set_aspath_prepend_compile(const char *arg
)
1704 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1705 return (void *)(uintptr_t)num
;
1707 return route_aspath_compile(arg
);
1710 static void route_set_aspath_prepend_free(void *rule
)
1712 if ((uintptr_t)rule
> 10)
1713 route_aspath_free(rule
);
1717 /* Set as-path prepend rule structure. */
1718 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1719 "as-path prepend", route_set_aspath_prepend
,
1720 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1723 /* `set as-path exclude ASn' */
1725 /* For ASN exclude mechanism.
1726 * Iterate over ASns requested and filter them from the given AS_PATH one by
1728 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1730 static route_map_result_t
route_set_aspath_exclude(void *rule
,
1731 const struct prefix
*dummy
,
1732 route_map_object_t type
,
1735 struct aspath
*new_path
, *exclude_path
;
1736 struct bgp_path_info
*path
;
1738 if (type
== RMAP_BGP
) {
1739 exclude_path
= rule
;
1741 if (path
->attr
->aspath
->refcnt
)
1742 new_path
= aspath_dup(path
->attr
->aspath
);
1744 new_path
= path
->attr
->aspath
;
1745 path
->attr
->aspath
=
1746 aspath_filter_exclude(new_path
, exclude_path
);
1751 /* Set ASn exlude rule structure. */
1752 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1753 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1757 /* `set community COMMUNITY' */
1758 struct rmap_com_set
{
1759 struct community
*com
;
1764 /* For community set mechanism. */
1765 static route_map_result_t
route_set_community(void *rule
,
1766 const struct prefix
*prefix
,
1767 route_map_object_t type
,
1770 struct rmap_com_set
*rcs
;
1771 struct bgp_path_info
*path
;
1773 struct community
*new = NULL
;
1774 struct community
*old
;
1775 struct community
*merge
;
1777 if (type
== RMAP_BGP
) {
1781 old
= attr
->community
;
1785 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1786 attr
->community
= NULL
;
1787 /* See the longer comment down below. */
1788 if (old
&& old
->refcnt
== 0)
1789 community_free(&old
);
1793 /* "additive" case. */
1794 if (rcs
->additive
&& old
) {
1795 merge
= community_merge(community_dup(old
), rcs
->com
);
1797 new = community_uniq_sort(merge
);
1798 community_free(&merge
);
1800 new = community_dup(rcs
->com
);
1802 /* HACK: if the old community is not intern'd,
1803 * we should free it here, or all reference to it may be
1805 * Really need to cleanup attribute caching sometime.
1807 if (old
&& old
->refcnt
== 0)
1808 community_free(&old
);
1810 /* will be interned by caller if required */
1811 attr
->community
= new;
1813 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1819 /* Compile function for set community. */
1820 static void *route_set_community_compile(const char *arg
)
1822 struct rmap_com_set
*rcs
;
1823 struct community
*com
= NULL
;
1828 if (strcmp(arg
, "none") == 0)
1831 sp
= strstr(arg
, "additive");
1833 if (sp
&& sp
> arg
) {
1834 /* "additive" keyword is included. */
1839 com
= community_str2com(arg
);
1848 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1850 rcs
->additive
= additive
;
1856 /* Free function for set community. */
1857 static void route_set_community_free(void *rule
)
1859 struct rmap_com_set
*rcs
= rule
;
1862 community_free(&rcs
->com
);
1863 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1866 /* Set community rule structure. */
1867 struct route_map_rule_cmd route_set_community_cmd
= {
1868 "community", route_set_community
, route_set_community_compile
,
1869 route_set_community_free
,
1872 /* `set community COMMUNITY' */
1873 struct rmap_lcom_set
{
1874 struct lcommunity
*lcom
;
1880 /* For lcommunity set mechanism. */
1881 static route_map_result_t
route_set_lcommunity(void *rule
,
1882 const struct prefix
*prefix
,
1883 route_map_object_t type
,
1886 struct rmap_lcom_set
*rcs
;
1887 struct bgp_path_info
*path
;
1889 struct lcommunity
*new = NULL
;
1890 struct lcommunity
*old
;
1891 struct lcommunity
*merge
;
1893 if (type
== RMAP_BGP
) {
1897 old
= attr
->lcommunity
;
1902 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
1903 attr
->lcommunity
= NULL
;
1905 /* See the longer comment down below. */
1906 if (old
&& old
->refcnt
== 0)
1907 lcommunity_free(&old
);
1911 if (rcs
->additive
&& old
) {
1912 merge
= lcommunity_merge(lcommunity_dup(old
),
1915 new = lcommunity_uniq_sort(merge
);
1916 lcommunity_free(&merge
);
1918 new = lcommunity_dup(rcs
->lcom
);
1920 /* HACK: if the old large-community is not intern'd,
1921 * we should free it here, or all reference to it may be
1923 * Really need to cleanup attribute caching sometime.
1925 if (old
&& old
->refcnt
== 0)
1926 lcommunity_free(&old
);
1928 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1929 attr
->lcommunity
= new;
1931 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
1937 /* Compile function for set community. */
1938 static void *route_set_lcommunity_compile(const char *arg
)
1940 struct rmap_lcom_set
*rcs
;
1941 struct lcommunity
*lcom
= NULL
;
1946 if (strcmp(arg
, "none") == 0)
1949 sp
= strstr(arg
, "additive");
1951 if (sp
&& sp
> arg
) {
1952 /* "additive" keyworkd is included. */
1957 lcom
= lcommunity_str2com(arg
);
1966 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1968 rcs
->additive
= additive
;
1974 /* Free function for set lcommunity. */
1975 static void route_set_lcommunity_free(void *rule
)
1977 struct rmap_lcom_set
*rcs
= rule
;
1980 lcommunity_free(&rcs
->lcom
);
1982 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1985 /* Set community rule structure. */
1986 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
1987 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
1988 route_set_lcommunity_free
,
1991 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
1993 /* For large community set mechanism. */
1994 static route_map_result_t
route_set_lcommunity_delete(void *rule
,
1995 const struct prefix
*pfx
,
1996 route_map_object_t type
,
1999 struct community_list
*list
;
2000 struct lcommunity
*merge
;
2001 struct lcommunity
*new;
2002 struct lcommunity
*old
;
2003 struct bgp_path_info
*path
;
2004 struct rmap_community
*rcom
= rule
;
2006 if (type
== RMAP_BGP
) {
2011 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2013 LARGE_COMMUNITY_LIST_MASTER
);
2014 old
= path
->attr
->lcommunity
;
2017 merge
= lcommunity_list_match_delete(
2018 lcommunity_dup(old
), list
);
2019 new = lcommunity_uniq_sort(merge
);
2020 lcommunity_free(&merge
);
2022 /* HACK: if the old community is not intern'd,
2023 * we should free it here, or all reference to it may be
2025 * Really need to cleanup attribute caching sometime.
2027 if (old
->refcnt
== 0)
2028 lcommunity_free(&old
);
2030 if (new->size
== 0) {
2031 path
->attr
->lcommunity
= NULL
;
2032 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2033 BGP_ATTR_LARGE_COMMUNITIES
);
2034 lcommunity_free(&new);
2036 path
->attr
->lcommunity
= new;
2037 path
->attr
->flag
|= ATTR_FLAG_BIT(
2038 BGP_ATTR_LARGE_COMMUNITIES
);
2046 /* Compile function for set lcommunity. */
2047 static void *route_set_lcommunity_delete_compile(const char *arg
)
2049 struct rmap_community
*rcom
;
2054 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2056 p
= strchr(arg
, ' ');
2059 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
2060 memcpy(str
, arg
, len
);
2065 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2069 /* Free function for set lcommunity. */
2070 static void route_set_lcommunity_delete_free(void *rule
)
2072 struct rmap_community
*rcom
= rule
;
2074 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2075 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2078 /* Set lcommunity rule structure. */
2079 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2080 "large-comm-list", route_set_lcommunity_delete
,
2081 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2085 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2087 /* For community set mechanism. */
2088 static route_map_result_t
route_set_community_delete(
2090 const struct prefix
*prefix
,
2091 route_map_object_t type
,
2094 struct community_list
*list
;
2095 struct community
*merge
;
2096 struct community
*new;
2097 struct community
*old
;
2098 struct bgp_path_info
*path
;
2099 struct rmap_community
*rcom
= rule
;
2101 if (type
== RMAP_BGP
) {
2106 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2108 COMMUNITY_LIST_MASTER
);
2109 old
= path
->attr
->community
;
2112 merge
= community_list_match_delete(community_dup(old
),
2114 new = community_uniq_sort(merge
);
2115 community_free(&merge
);
2117 /* HACK: if the old community is not intern'd,
2118 * we should free it here, or all reference to it may be
2120 * Really need to cleanup attribute caching sometime.
2122 if (old
->refcnt
== 0)
2123 community_free(&old
);
2125 if (new->size
== 0) {
2126 path
->attr
->community
= NULL
;
2128 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2129 community_free(&new);
2131 path
->attr
->community
= new;
2133 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2141 /* Compile function for set community. */
2142 static void *route_set_community_delete_compile(const char *arg
)
2144 struct rmap_community
*rcom
;
2149 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2151 p
= strchr(arg
, ' ');
2154 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
2155 memcpy(str
, arg
, len
);
2160 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2164 /* Free function for set community. */
2165 static void route_set_community_delete_free(void *rule
)
2167 struct rmap_community
*rcom
= rule
;
2169 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2170 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2173 /* Set community rule structure. */
2174 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2175 "comm-list", route_set_community_delete
,
2176 route_set_community_delete_compile
, route_set_community_delete_free
,
2179 /* `set extcommunity rt COMMUNITY' */
2181 /* For community set mechanism. Used by _rt and _soo. */
2182 static route_map_result_t
route_set_ecommunity(void *rule
,
2183 const struct prefix
*prefix
,
2184 route_map_object_t type
,
2187 struct ecommunity
*ecom
;
2188 struct ecommunity
*new_ecom
;
2189 struct ecommunity
*old_ecom
;
2190 struct bgp_path_info
*path
;
2192 if (type
== RMAP_BGP
) {
2199 /* We assume additive for Extended Community. */
2200 old_ecom
= path
->attr
->ecommunity
;
2203 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2206 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2207 * bgp_update_receive()
2208 * ->refcnt = 0 => set by a previous route-map
2210 if (!old_ecom
->refcnt
)
2211 ecommunity_free(&old_ecom
);
2213 new_ecom
= ecommunity_dup(ecom
);
2215 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2216 path
->attr
->ecommunity
= new_ecom
;
2218 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2223 /* Compile function for set community. */
2224 static void *route_set_ecommunity_rt_compile(const char *arg
)
2226 struct ecommunity
*ecom
;
2228 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2231 return ecommunity_intern(ecom
);
2234 /* Free function for set community. Used by _rt and _soo */
2235 static void route_set_ecommunity_free(void *rule
)
2237 struct ecommunity
*ecom
= rule
;
2238 ecommunity_unintern(&ecom
);
2241 /* Set community rule structure. */
2242 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2243 "extcommunity rt", route_set_ecommunity
,
2244 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2247 /* `set extcommunity soo COMMUNITY' */
2249 /* Compile function for set community. */
2250 static void *route_set_ecommunity_soo_compile(const char *arg
)
2252 struct ecommunity
*ecom
;
2254 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2258 return ecommunity_intern(ecom
);
2261 /* Set community rule structure. */
2262 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2263 "extcommunity soo", route_set_ecommunity
,
2264 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2267 /* `set origin ORIGIN' */
2269 /* For origin set. */
2270 static route_map_result_t
route_set_origin(void *rule
,
2271 const struct prefix
*prefix
,
2272 route_map_object_t type
,
2276 struct bgp_path_info
*path
;
2278 if (type
== RMAP_BGP
) {
2282 path
->attr
->origin
= *origin
;
2288 /* Compile function for origin set. */
2289 static void *route_set_origin_compile(const char *arg
)
2293 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2295 if (strcmp(arg
, "igp") == 0)
2297 else if (strcmp(arg
, "egp") == 0)
2305 /* Compile function for origin set. */
2306 static void route_set_origin_free(void *rule
)
2308 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2311 /* Set origin rule structure. */
2312 struct route_map_rule_cmd route_set_origin_cmd
= {
2313 "origin", route_set_origin
, route_set_origin_compile
,
2314 route_set_origin_free
,
2317 /* `set atomic-aggregate' */
2319 /* For atomic aggregate set. */
2320 static route_map_result_t
route_set_atomic_aggregate(void *rule
,
2321 const struct prefix
*pfx
,
2322 route_map_object_t type
,
2325 struct bgp_path_info
*path
;
2327 if (type
== RMAP_BGP
) {
2329 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2335 /* Compile function for atomic aggregate. */
2336 static void *route_set_atomic_aggregate_compile(const char *arg
)
2341 /* Compile function for atomic aggregate. */
2342 static void route_set_atomic_aggregate_free(void *rule
)
2347 /* Set atomic aggregate rule structure. */
2348 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2349 "atomic-aggregate", route_set_atomic_aggregate
,
2350 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2353 /* `set aggregator as AS A.B.C.D' */
2356 struct in_addr address
;
2359 static route_map_result_t
route_set_aggregator_as(void *rule
,
2360 const struct prefix
*prefix
,
2361 route_map_object_t type
,
2364 struct bgp_path_info
*path
;
2365 struct aggregator
*aggregator
;
2367 if (type
== RMAP_BGP
) {
2371 path
->attr
->aggregator_as
= aggregator
->as
;
2372 path
->attr
->aggregator_addr
= aggregator
->address
;
2373 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2379 static void *route_set_aggregator_as_compile(const char *arg
)
2381 struct aggregator
*aggregator
;
2387 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2388 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2389 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2393 aggregator
->as
= strtoul(as
, NULL
, 10);
2394 ret
= inet_aton(address
, &aggregator
->address
);
2396 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2402 static void route_set_aggregator_as_free(void *rule
)
2404 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2407 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2408 "aggregator as", route_set_aggregator_as
,
2409 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2412 /* Set tag to object. object must be pointer to struct bgp_path_info */
2413 static route_map_result_t
route_set_tag(void *rule
,
2414 const struct prefix
*prefix
,
2415 route_map_object_t type
, void *object
)
2418 struct bgp_path_info
*path
;
2420 if (type
== RMAP_BGP
) {
2425 path
->attr
->tag
= *tag
;
2431 /* Route map commands for tag set. */
2432 static struct route_map_rule_cmd route_set_tag_cmd
= {
2433 "tag", route_set_tag
, route_map_rule_tag_compile
,
2434 route_map_rule_tag_free
,
2437 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2438 static route_map_result_t
route_set_label_index(void *rule
,
2439 const struct prefix
*prefix
,
2440 route_map_object_t type
,
2443 struct rmap_value
*rv
;
2444 struct bgp_path_info
*path
;
2445 uint32_t label_index
;
2447 if (type
== RMAP_BGP
) {
2448 /* Fetch routemap's rule information. */
2452 /* Set label-index value. */
2453 label_index
= rv
->value
;
2455 path
->attr
->label_index
= label_index
;
2456 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2463 /* Route map commands for label-index set. */
2464 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2465 "label-index", route_set_label_index
, route_value_compile
,
2469 /* `match ipv6 address IP_ACCESS_LIST' */
2471 static route_map_result_t
route_match_ipv6_address(void *rule
,
2472 const struct prefix
*prefix
,
2473 route_map_object_t type
,
2476 struct access_list
*alist
;
2478 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2479 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2481 return RMAP_NOMATCH
;
2483 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2487 return RMAP_NOMATCH
;
2490 static void *route_match_ipv6_address_compile(const char *arg
)
2492 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2495 static void route_match_ipv6_address_free(void *rule
)
2497 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2500 /* Route map commands for ip address matching. */
2501 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2502 "ipv6 address", route_match_ipv6_address
,
2503 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2505 /* `match ipv6 next-hop IP_ADDRESS' */
2507 static route_map_result_t
route_match_ipv6_next_hop(void *rule
,
2508 const struct prefix
*prefix
,
2509 route_map_object_t type
,
2512 struct in6_addr
*addr
= rule
;
2513 struct bgp_path_info
*path
;
2515 if (type
== RMAP_BGP
) {
2518 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2521 if (path
->attr
->mp_nexthop_len
2522 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2523 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2526 return RMAP_NOMATCH
;
2529 return RMAP_NOMATCH
;
2532 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2534 struct in6_addr
*address
;
2537 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2539 ret
= inet_pton(AF_INET6
, arg
, address
);
2541 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2548 static void route_match_ipv6_next_hop_free(void *rule
)
2550 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2553 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2554 "ipv6 next-hop", route_match_ipv6_next_hop
,
2555 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2557 /* `match ipv6 address prefix-list PREFIX_LIST' */
2559 static route_map_result_t
2560 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2561 route_map_object_t type
, void *object
)
2563 struct prefix_list
*plist
;
2565 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2566 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
2568 return RMAP_NOMATCH
;
2570 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
2574 return RMAP_NOMATCH
;
2577 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2579 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2582 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2584 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2587 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2588 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2589 route_match_ipv6_address_prefix_list_compile
,
2590 route_match_ipv6_address_prefix_list_free
};
2592 /* `match ipv6 next-hop type <TYPE>' */
2594 static route_map_result_t
2595 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2596 route_map_object_t type
, void *object
)
2598 struct bgp_path_info
*path
;
2599 struct in6_addr
*addr
= rule
;
2601 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2602 path
= (struct bgp_path_info
*)object
;
2603 if (!path
|| !path
->attr
)
2604 return RMAP_DENYMATCH
;
2606 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2607 && !path
->attr
->nh_ifindex
)
2610 return RMAP_NOMATCH
;
2613 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2615 struct in6_addr
*address
;
2618 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2620 ret
= inet_pton(AF_INET6
, "::0", address
);
2622 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2629 static void route_match_ipv6_next_hop_type_free(void *rule
)
2631 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2634 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2635 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2636 route_match_ipv6_next_hop_type_compile
,
2637 route_match_ipv6_next_hop_type_free
};
2639 /* `set ipv6 nexthop global IP_ADDRESS' */
2641 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2642 static route_map_result_t
route_set_ipv6_nexthop_global(void *rule
,
2643 const struct prefix
*p
,
2644 route_map_object_t type
,
2647 struct in6_addr
*address
;
2648 struct bgp_path_info
*path
;
2650 if (type
== RMAP_BGP
) {
2651 /* Fetch routemap's rule information. */
2655 /* Set next hop value. */
2656 path
->attr
->mp_nexthop_global
= *address
;
2658 /* Set nexthop length. */
2659 if (path
->attr
->mp_nexthop_len
== 0)
2660 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2662 SET_FLAG(path
->attr
->rmap_change_flags
,
2663 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2669 /* Route map `ip next-hop' compile function. Given string is converted
2670 to struct in_addr structure. */
2671 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2674 struct in6_addr
*address
;
2676 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2678 ret
= inet_pton(AF_INET6
, arg
, address
);
2681 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2688 /* Free route map's compiled `ip next-hop' value. */
2689 static void route_set_ipv6_nexthop_global_free(void *rule
)
2691 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2694 /* Route map commands for ip nexthop set. */
2695 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2696 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2697 route_set_ipv6_nexthop_global_compile
,
2698 route_set_ipv6_nexthop_global_free
};
2700 /* Set next-hop preference value. */
2701 static route_map_result_t
2702 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2703 route_map_object_t type
, void *object
)
2705 struct bgp_path_info
*path
;
2708 if (type
== RMAP_BGP
) {
2709 /* Fetch routemap's rule information. */
2713 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2714 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2716 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2717 /* Set next hop preference to global */
2718 path
->attr
->mp_nexthop_prefer_global
= TRUE
;
2719 SET_FLAG(path
->attr
->rmap_change_flags
,
2720 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2722 path
->attr
->mp_nexthop_prefer_global
= FALSE
;
2723 SET_FLAG(path
->attr
->rmap_change_flags
,
2724 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2730 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2734 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2740 /* Free route map's compiled `ip next-hop' value. */
2741 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2743 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2746 /* Route map commands for ip nexthop set preferred. */
2747 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2748 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2749 route_set_ipv6_nexthop_prefer_global_compile
,
2750 route_set_ipv6_nexthop_prefer_global_free
};
2752 /* `set ipv6 nexthop local IP_ADDRESS' */
2754 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2755 static route_map_result_t
route_set_ipv6_nexthop_local(void *rule
,
2756 const struct prefix
*p
,
2757 route_map_object_t type
,
2760 struct in6_addr
*address
;
2761 struct bgp_path_info
*path
;
2763 if (type
== RMAP_BGP
) {
2764 /* Fetch routemap's rule information. */
2768 /* Set next hop value. */
2769 path
->attr
->mp_nexthop_local
= *address
;
2771 /* Set nexthop length. */
2772 if (path
->attr
->mp_nexthop_len
2773 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2774 path
->attr
->mp_nexthop_len
=
2775 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2777 SET_FLAG(path
->attr
->rmap_change_flags
,
2778 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2784 /* Route map `ip nexthop' compile function. Given string is converted
2785 to struct in_addr structure. */
2786 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2789 struct in6_addr
*address
;
2791 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2793 ret
= inet_pton(AF_INET6
, arg
, address
);
2796 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2803 /* Free route map's compiled `ip nexthop' value. */
2804 static void route_set_ipv6_nexthop_local_free(void *rule
)
2806 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2809 /* Route map commands for ip nexthop set. */
2810 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2811 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2812 route_set_ipv6_nexthop_local_compile
,
2813 route_set_ipv6_nexthop_local_free
};
2815 /* `set ipv6 nexthop peer-address' */
2817 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2818 static route_map_result_t
route_set_ipv6_nexthop_peer(void *rule
,
2819 const struct prefix
*pfx
,
2820 route_map_object_t type
,
2823 struct in6_addr peer_address
;
2824 struct bgp_path_info
*path
;
2827 if (type
== RMAP_BGP
) {
2828 /* Fetch routemap's rule information. */
2832 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2833 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2835 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2836 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2837 /* Set next hop value and length in attribute. */
2838 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2839 path
->attr
->mp_nexthop_local
= peer_address
;
2840 if (path
->attr
->mp_nexthop_len
!= 32)
2841 path
->attr
->mp_nexthop_len
= 32;
2843 path
->attr
->mp_nexthop_global
= peer_address
;
2844 if (path
->attr
->mp_nexthop_len
== 0)
2845 path
->attr
->mp_nexthop_len
= 16;
2848 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2849 /* The next hop value will be set as part of packet
2851 * Set the flags here to indicate that rewrite needs to
2853 * Also, clear the value - we clear both global and
2855 * nexthops, whether we send one or both is determined
2858 SET_FLAG(path
->attr
->rmap_change_flags
,
2859 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2860 /* clear next hop value. */
2861 memset(&(path
->attr
->mp_nexthop_global
), 0,
2862 sizeof(struct in6_addr
));
2863 memset(&(path
->attr
->mp_nexthop_local
), 0,
2864 sizeof(struct in6_addr
));
2871 /* Route map `ip next-hop' compile function. Given string is converted
2872 to struct in_addr structure. */
2873 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2877 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2883 /* Free route map's compiled `ip next-hop' value. */
2884 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2886 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2889 /* Route map commands for ip nexthop set. */
2890 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2891 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2892 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2894 /* `set ipv4 vpn next-hop A.B.C.D' */
2896 static route_map_result_t
route_set_vpnv4_nexthop(void *rule
,
2897 const struct prefix
*prefix
,
2898 route_map_object_t type
,
2901 struct in_addr
*address
;
2902 struct bgp_path_info
*path
;
2904 if (type
== RMAP_BGP
) {
2905 /* Fetch routemap's rule information. */
2909 /* Set next hop value. */
2910 path
->attr
->mp_nexthop_global_in
= *address
;
2911 path
->attr
->mp_nexthop_len
= 4;
2917 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2920 struct in_addr
*address
;
2922 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2924 ret
= inet_aton(arg
, address
);
2927 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2934 /* `set ipv6 vpn next-hop A.B.C.D' */
2936 static route_map_result_t
route_set_vpnv6_nexthop(void *rule
,
2937 const struct prefix
*prefix
,
2938 route_map_object_t type
,
2941 struct in6_addr
*address
;
2942 struct bgp_path_info
*path
;
2944 if (type
== RMAP_BGP
) {
2945 /* Fetch routemap's rule information. */
2949 /* Set next hop value. */
2950 memcpy(&path
->attr
->mp_nexthop_global
, address
,
2951 sizeof(struct in6_addr
));
2952 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2958 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2961 struct in6_addr
*address
;
2963 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2964 ret
= inet_pton(AF_INET6
, arg
, address
);
2967 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2974 static void route_set_vpn_nexthop_free(void *rule
)
2976 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2979 /* Route map commands for ipv4 next-hop set. */
2980 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2981 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2982 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
2984 /* Route map commands for ipv6 next-hop set. */
2985 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
2986 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
2987 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
2989 /* `set originator-id' */
2991 /* For origin set. */
2992 static route_map_result_t
route_set_originator_id(void *rule
,
2993 const struct prefix
*prefix
,
2994 route_map_object_t type
,
2997 struct in_addr
*address
;
2998 struct bgp_path_info
*path
;
3000 if (type
== RMAP_BGP
) {
3004 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
3005 path
->attr
->originator_id
= *address
;
3011 /* Compile function for originator-id set. */
3012 static void *route_set_originator_id_compile(const char *arg
)
3015 struct in_addr
*address
;
3017 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3019 ret
= inet_aton(arg
, address
);
3022 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3029 /* Compile function for originator_id set. */
3030 static void route_set_originator_id_free(void *rule
)
3032 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3035 /* Set originator-id rule structure. */
3036 struct route_map_rule_cmd route_set_originator_id_cmd
= {
3037 "originator-id", route_set_originator_id
,
3038 route_set_originator_id_compile
, route_set_originator_id_free
,
3041 /* Add bgp route map rule. */
3042 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3043 const char *arg
, route_map_event_t type
)
3045 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3046 int retval
= CMD_SUCCESS
;
3049 ret
= route_map_add_match(index
, command
, arg
);
3051 case RMAP_RULE_MISSING
:
3052 vty_out(vty
, "%% BGP Can't find rule.\n");
3053 retval
= CMD_WARNING_CONFIG_FAILED
;
3055 case RMAP_COMPILE_ERROR
:
3056 vty_out(vty
, "%% BGP Argument is malformed.\n");
3057 retval
= CMD_WARNING_CONFIG_FAILED
;
3059 case RMAP_COMPILE_SUCCESS
:
3060 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
3061 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
3069 /* Delete bgp route map rule. */
3070 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3071 const char *arg
, route_map_event_t type
)
3073 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3075 int retval
= CMD_SUCCESS
;
3076 char *dep_name
= NULL
;
3078 char *rmap_name
= NULL
;
3080 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3081 /* ignore the mundane, the types without any dependency */
3083 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3086 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3088 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3090 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3093 ret
= route_map_delete_match(index
, command
, dep_name
);
3095 case RMAP_RULE_MISSING
:
3096 vty_out(vty
, "%% BGP Can't find rule.\n");
3097 retval
= CMD_WARNING_CONFIG_FAILED
;
3099 case RMAP_COMPILE_ERROR
:
3100 vty_out(vty
, "%% BGP Argument is malformed.\n");
3101 retval
= CMD_WARNING_CONFIG_FAILED
;
3103 case RMAP_COMPILE_SUCCESS
:
3104 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
3105 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
3110 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3112 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3118 * This is the workhorse routine for processing in/out routemap
3121 static void bgp_route_map_process_peer(const char *rmap_name
,
3122 struct route_map
*map
, struct peer
*peer
,
3123 int afi
, int safi
, int route_update
)
3127 struct bgp_filter
*filter
;
3129 if (!peer
|| !rmap_name
)
3132 filter
= &peer
->filter
[afi
][safi
];
3134 * in is for non-route-server clients,
3135 * out is for all peers
3137 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
3138 if (filter
->map
[RMAP_IN
].name
3139 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3140 filter
->map
[RMAP_IN
].map
= map
;
3142 if (route_update
&& peer
->status
== Established
) {
3143 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3144 PEER_FLAG_SOFT_RECONFIG
)) {
3145 if (bgp_debug_update(peer
, NULL
, NULL
,
3148 "Processing route_map %s update on "
3149 "peer %s (inbound, soft-reconfig)",
3150 rmap_name
, peer
->host
);
3152 bgp_soft_reconfig_in(peer
, afi
, safi
);
3154 CHECK_FLAG(peer
->cap
,
3155 PEER_CAP_REFRESH_OLD_RCV
)
3158 PEER_CAP_REFRESH_NEW_RCV
)) {
3160 if (bgp_debug_update(peer
, NULL
, NULL
,
3163 "Processing route_map %s update on "
3164 "peer %s (inbound, route-refresh)",
3165 rmap_name
, peer
->host
);
3166 bgp_route_refresh_send(peer
, afi
, safi
,
3173 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
3176 if (update
&& route_update
&& peer
->status
== Established
) {
3177 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3178 PEER_FLAG_SOFT_RECONFIG
)) {
3179 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3181 "Processing route_map %s update on "
3182 "peer %s (import, soft-reconfig)",
3183 rmap_name
, peer
->host
);
3185 bgp_soft_reconfig_in(peer
, afi
, safi
);
3186 } else if (CHECK_FLAG(peer
->cap
,
3187 PEER_CAP_REFRESH_OLD_RCV
)
3188 || CHECK_FLAG(peer
->cap
,
3189 PEER_CAP_REFRESH_NEW_RCV
)) {
3190 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3192 "Processing route_map %s update on "
3193 "peer %s (import, route-refresh)",
3194 rmap_name
, peer
->host
);
3195 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3198 /* DD: Else, what else do we do ? Reset peer ? */
3203 * For outbound, unsuppress and default-originate map change (content or
3204 * map created), merely update the "config" here, the actual route
3205 * announcement happens at the group level.
3207 if (filter
->map
[RMAP_OUT
].name
3208 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3209 filter
->map
[RMAP_OUT
].map
= map
;
3211 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3212 filter
->usmap
.map
= map
;
3214 if (peer
->default_rmap
[afi
][safi
].name
3215 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3216 peer
->default_rmap
[afi
][safi
].map
= map
;
3219 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3220 struct route_map
*map
,
3223 struct peer_group
*group
;
3224 struct listnode
*node
, *nnode
;
3225 struct bgp_filter
*filter
;
3232 /* All the peers have been updated correctly already. This is
3233 * just updating the placeholder data. No real update required.
3235 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3236 FOREACH_AFI_SAFI (afi
, safi
) {
3237 filter
= &group
->conf
->filter
[afi
][safi
];
3239 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3240 if ((filter
->map
[direct
].name
)
3241 && (strcmp(rmap_name
,
3242 filter
->map
[direct
].name
)
3244 filter
->map
[direct
].map
= map
;
3247 if (filter
->usmap
.name
3248 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3249 filter
->usmap
.map
= map
;
3255 * Note that if an extreme number (tens of thousands) of route-maps are in use
3256 * and if bgp has an extreme number of peers, network statements, etc then this
3257 * function can consume a lot of cycles. This is due to this function being
3258 * called for each route-map and within this function we walk the list of peers,
3259 * network statements, etc looking to see if they use this route-map.
3261 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3268 struct bgp_node
*bn
;
3269 struct bgp_static
*bgp_static
;
3270 struct listnode
*node
, *nnode
;
3271 struct route_map
*map
;
3272 char buf
[INET6_ADDRSTRLEN
];
3274 map
= route_map_lookup_by_name(rmap_name
);
3276 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3278 /* Ignore dummy peer-group structure */
3279 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3282 FOREACH_AFI_SAFI (afi
, safi
) {
3283 /* process in/out/import/export/default-orig
3285 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3286 safi
, route_update
);
3290 /* for outbound/default-orig route-maps, process for groups */
3291 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3294 /* update peer-group config (template) */
3295 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3297 FOREACH_AFI_SAFI (afi
, safi
) {
3298 /* For table route-map updates. */
3299 if (!bgp_fibupd_safi(safi
))
3302 if (bgp
->table_map
[afi
][safi
].name
3303 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3306 /* bgp->table_map[afi][safi].map is NULL.
3307 * i.e Route map creation event.
3308 * So update applied_counter.
3309 * If it is not NULL, i.e It may be routemap updation or
3310 * deletion. so no need to update the counter.
3312 if (!bgp
->table_map
[afi
][safi
].map
)
3313 route_map_counter_increment(map
);
3314 bgp
->table_map
[afi
][safi
].map
= map
;
3316 if (BGP_DEBUG(zebra
, ZEBRA
))
3318 "Processing route_map %s update on "
3322 bgp_zebra_announce_table(bgp
, afi
, safi
);
3325 /* For network route-map updates. */
3326 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3327 bn
= bgp_route_next(bn
)) {
3328 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3332 if (!bgp_static
->rmap
.name
3333 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3336 if (!bgp_static
->rmap
.map
)
3337 route_map_counter_increment(map
);
3339 bgp_static
->rmap
.map
= map
;
3341 if (route_update
&& !bgp_static
->backdoor
) {
3342 if (bgp_debug_zebra(&bn
->p
))
3344 "Processing route_map %s update on static route %s",
3346 inet_ntop(bn
->p
.family
,
3347 &bn
->p
.u
.prefix
, buf
,
3349 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3355 /* For redistribute route-map updates. */
3356 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3357 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3358 struct list
*red_list
;
3359 struct bgp_redist
*red
;
3361 red_list
= bgp
->redist
[afi
][i
];
3365 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3367 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3371 route_map_counter_increment(map
);
3373 red
->rmap
.map
= map
;
3378 if (BGP_DEBUG(zebra
, ZEBRA
))
3380 "Processing route_map %s update on redistributed routes",
3383 bgp_redistribute_resend(bgp
, afi
, i
,
3388 /* for type5 command route-maps */
3389 FOREACH_AFI_SAFI (afi
, safi
) {
3390 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3391 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3395 /* Make sure the route-map is populated here if not already done */
3396 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3398 if (BGP_DEBUG(zebra
, ZEBRA
))
3400 "Processing route_map %s update on advertise type5 route command",
3404 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3405 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3410 static void bgp_route_map_process_update_cb(char *rmap_name
)
3412 struct listnode
*node
, *nnode
;
3415 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3416 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3419 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3420 vnc_routemap_update(bgp
, __func__
);
3424 vpn_policy_routemap_event(rmap_name
);
3427 int bgp_route_map_update_timer(struct thread
*thread
)
3429 bm
->t_rmap_update
= NULL
;
3431 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3436 static void bgp_route_map_mark_update(const char *rmap_name
)
3438 if (bm
->t_rmap_update
== NULL
) {
3439 struct listnode
*node
, *nnode
;
3442 /* rmap_update_timer of 0 means don't do route updates */
3443 if (bm
->rmap_update_timer
) {
3444 bm
->t_rmap_update
= NULL
;
3445 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3446 NULL
, bm
->rmap_update_timer
,
3447 &bm
->t_rmap_update
);
3449 /* Signal the groups that a route-map update event has
3451 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3452 update_group_policy_update(bgp
,
3453 BGP_POLICY_ROUTE_MAP
,
3456 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3457 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3459 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3460 vnc_routemap_update(bgp
, __func__
);
3466 static void bgp_route_map_add(const char *rmap_name
)
3468 if (route_map_mark_updated(rmap_name
) == 0)
3469 bgp_route_map_mark_update(rmap_name
);
3471 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3474 static void bgp_route_map_delete(const char *rmap_name
)
3476 if (route_map_mark_updated(rmap_name
) == 0)
3477 bgp_route_map_mark_update(rmap_name
);
3479 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3482 static void bgp_route_map_event(route_map_event_t event
, const char *rmap_name
)
3484 if (route_map_mark_updated(rmap_name
) == 0)
3485 bgp_route_map_mark_update(rmap_name
);
3487 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3490 DEFUN (match_mac_address
,
3491 match_mac_address_cmd
,
3492 "match mac address WORD",
3495 "Match address of route\n"
3496 "MAC Access-list name\n")
3498 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3499 RMAP_EVENT_FILTER_ADDED
);
3502 DEFUN (no_match_mac_address
,
3503 no_match_mac_address_cmd
,
3504 "no match mac address WORD",
3508 "Match address of route\n"
3509 "MAC acess-list name\n")
3511 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3512 RMAP_EVENT_FILTER_DELETED
);
3515 DEFUN (match_evpn_route_type
,
3516 match_evpn_route_type_cmd
,
3517 "match evpn route-type <macip | multicast | prefix>",
3520 "Match route-type\n"
3525 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3526 RMAP_EVENT_MATCH_ADDED
);
3529 DEFUN (no_match_evpn_route_type
,
3530 no_match_evpn_route_type_cmd
,
3531 "no match evpn route-type <macip | multicast | prefix>",
3535 "Match route-type\n"
3540 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3541 RMAP_EVENT_MATCH_DELETED
);
3545 DEFUN (match_evpn_vni
,
3547 "match evpn vni " CMD_VNI_RANGE
,
3553 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3554 RMAP_EVENT_MATCH_ADDED
);
3557 DEFUN (no_match_evpn_vni
,
3558 no_match_evpn_vni_cmd
,
3559 "no match evpn vni " CMD_VNI_RANGE
,
3566 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3567 RMAP_EVENT_MATCH_DELETED
);
3570 DEFUN (match_evpn_default_route
,
3571 match_evpn_default_route_cmd
,
3572 "match evpn default-route",
3575 "default EVPN type-5 route\n")
3577 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3578 RMAP_EVENT_MATCH_ADDED
);
3581 DEFUN (no_match_evpn_default_route
,
3582 no_match_evpn_default_route_cmd
,
3583 "no match evpn default-route",
3587 "default EVPN type-5 route\n")
3589 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3590 RMAP_EVENT_MATCH_DELETED
);
3593 DEFPY(match_vrl_source_vrf
,
3594 match_vrl_source_vrf_cmd
,
3595 "match source-vrf NAME$vrf_name",
3600 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3601 RMAP_EVENT_MATCH_ADDED
);
3604 DEFPY(no_match_vrl_source_vrf
,
3605 no_match_vrl_source_vrf_cmd
,
3606 "no match source-vrf NAME$vrf_name",
3612 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3613 RMAP_EVENT_MATCH_DELETED
);
3618 "match peer <A.B.C.D|X:X::X:X|WORD>",
3620 "Match peer address\n"
3621 "IP address of peer\n"
3622 "IPv6 address of peer\n"
3623 "Interface name of peer\n")
3626 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3627 RMAP_EVENT_MATCH_ADDED
);
3630 DEFUN (match_peer_local
,
3631 match_peer_local_cmd
,
3634 "Match peer address\n"
3635 "Static or Redistributed routes\n")
3637 return bgp_route_match_add(vty
, "peer", "local",
3638 RMAP_EVENT_MATCH_DELETED
);
3641 DEFUN (no_match_peer
,
3643 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3646 "Match peer address\n"
3647 "Static or Redistributed routes\n"
3648 "IP address of peer\n"
3649 "IPv6 address of peer\n"
3650 "Interface name of peer\n")
3654 if (argc
<= idx_peer
)
3655 return bgp_route_match_delete(vty
, "peer", NULL
,
3656 RMAP_EVENT_MATCH_DELETED
);
3657 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3658 RMAP_EVENT_MATCH_DELETED
);
3661 #if defined(HAVE_LUA)
3662 DEFUN (match_command
,
3664 "match command WORD",
3666 "Run a command to match\n"
3667 "The command to run\n")
3669 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3670 RMAP_EVENT_FILTER_ADDED
);
3673 DEFUN (no_match_command
,
3674 no_match_command_cmd
,
3675 "no match command WORD",
3678 "Run a command to match\n"
3679 "The command to run\n")
3681 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3682 RMAP_EVENT_FILTER_DELETED
);
3686 /* match probability */
3687 DEFUN (match_probability
,
3688 match_probability_cmd
,
3689 "match probability (0-100)",
3691 "Match portion of routes defined by percentage value\n"
3692 "Percentage of routes\n")
3695 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3696 RMAP_EVENT_MATCH_ADDED
);
3700 DEFUN (no_match_probability
,
3701 no_match_probability_cmd
,
3702 "no match probability [(1-99)]",
3705 "Match portion of routes defined by percentage value\n"
3706 "Percentage of routes\n")
3709 if (argc
<= idx_number
)
3710 return bgp_route_match_delete(vty
, "probability", NULL
,
3711 RMAP_EVENT_MATCH_DELETED
);
3712 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3713 RMAP_EVENT_MATCH_DELETED
);
3717 DEFUN (match_ip_route_source
,
3718 match_ip_route_source_cmd
,
3719 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3722 "Match advertising source address of route\n"
3723 "IP access-list number\n"
3724 "IP access-list number (expanded range)\n"
3725 "IP standard access-list name\n")
3728 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3729 RMAP_EVENT_FILTER_ADDED
);
3733 DEFUN (no_match_ip_route_source
,
3734 no_match_ip_route_source_cmd
,
3735 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3739 "Match advertising source address of route\n"
3740 "IP access-list number\n"
3741 "IP access-list number (expanded range)\n"
3742 "IP standard access-list name\n")
3745 if (argc
<= idx_number
)
3746 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3747 RMAP_EVENT_FILTER_DELETED
);
3748 return bgp_route_match_delete(vty
, "ip route-source",
3749 argv
[idx_number
]->arg
,
3750 RMAP_EVENT_FILTER_DELETED
);
3754 DEFUN (match_ip_route_source_prefix_list
,
3755 match_ip_route_source_prefix_list_cmd
,
3756 "match ip route-source prefix-list WORD",
3759 "Match advertising source address of route\n"
3760 "Match entries of prefix-lists\n"
3761 "IP prefix-list name\n")
3764 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3765 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3769 DEFUN (no_match_ip_route_source_prefix_list
,
3770 no_match_ip_route_source_prefix_list_cmd
,
3771 "no match ip route-source prefix-list [WORD]",
3775 "Match advertising source address of route\n"
3776 "Match entries of prefix-lists\n"
3777 "IP prefix-list name\n")
3780 if (argc
<= idx_word
)
3781 return bgp_route_match_delete(vty
,
3782 "ip route-source prefix-list",
3783 NULL
, RMAP_EVENT_PLIST_DELETED
);
3784 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3785 argv
[idx_word
]->arg
,
3786 RMAP_EVENT_PLIST_DELETED
);
3790 DEFUN (match_local_pref
,
3791 match_local_pref_cmd
,
3792 "match local-preference (0-4294967295)",
3794 "Match local-preference of route\n"
3798 return bgp_route_match_add(vty
, "local-preference",
3799 argv
[idx_number
]->arg
,
3800 RMAP_EVENT_MATCH_ADDED
);
3804 DEFUN (no_match_local_pref
,
3805 no_match_local_pref_cmd
,
3806 "no match local-preference [(0-4294967295)]",
3809 "Match local preference of route\n"
3810 "Local preference value\n")
3812 int idx_localpref
= 3;
3813 if (argc
<= idx_localpref
)
3814 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3815 RMAP_EVENT_MATCH_DELETED
);
3816 return bgp_route_match_delete(vty
, "local-preference",
3817 argv
[idx_localpref
]->arg
,
3818 RMAP_EVENT_MATCH_DELETED
);
3822 DEFUN (match_community
,
3823 match_community_cmd
,
3824 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3826 "Match BGP community list\n"
3827 "Community-list number (standard)\n"
3828 "Community-list number (expanded)\n"
3829 "Community-list name\n"
3830 "Do exact matching of communities\n")
3832 int idx_comm_list
= 2;
3837 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3838 strlen(argv
[idx_comm_list
]->arg
)
3839 + strlen("exact-match") + 2);
3841 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3843 argstr
= argv
[idx_comm_list
]->arg
;
3845 ret
= bgp_route_match_add(vty
, "community", argstr
,
3846 RMAP_EVENT_CLIST_ADDED
);
3848 if (argstr
!= argv
[idx_comm_list
]->arg
)
3849 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3854 DEFUN (no_match_community
,
3855 no_match_community_cmd
,
3856 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3859 "Match BGP community list\n"
3860 "Community-list number (standard)\n"
3861 "Community-list number (expanded)\n"
3862 "Community-list name\n"
3863 "Do exact matching of communities\n")
3865 return bgp_route_match_delete(vty
, "community", NULL
,
3866 RMAP_EVENT_CLIST_DELETED
);
3869 DEFUN (match_lcommunity
,
3870 match_lcommunity_cmd
,
3871 "match large-community <(1-99)|(100-500)|WORD>",
3873 "Match BGP large community list\n"
3874 "Large Community-list number (standard)\n"
3875 "Large Community-list number (expanded)\n"
3876 "Large Community-list name\n")
3878 return bgp_route_match_add(vty
, "large-community", argv
[2]->arg
,
3879 RMAP_EVENT_LLIST_ADDED
);
3882 DEFUN (no_match_lcommunity
,
3883 no_match_lcommunity_cmd
,
3884 "no match large-community [<(1-99)|(100-500)|WORD>]",
3887 "Match BGP large community list\n"
3888 "Large Community-list number (standard)\n"
3889 "Large Community-list number (expanded)\n"
3890 "Large Community-list name\n")
3892 return bgp_route_match_delete(vty
, "large-community", NULL
,
3893 RMAP_EVENT_LLIST_DELETED
);
3896 DEFUN (match_ecommunity
,
3897 match_ecommunity_cmd
,
3898 "match extcommunity <(1-99)|(100-500)|WORD>",
3900 "Match BGP/VPN extended community list\n"
3901 "Extended community-list number (standard)\n"
3902 "Extended community-list number (expanded)\n"
3903 "Extended community-list name\n")
3905 int idx_comm_list
= 2;
3906 return bgp_route_match_add(vty
, "extcommunity",
3907 argv
[idx_comm_list
]->arg
,
3908 RMAP_EVENT_ECLIST_ADDED
);
3912 DEFUN (no_match_ecommunity
,
3913 no_match_ecommunity_cmd
,
3914 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3917 "Match BGP/VPN extended community list\n"
3918 "Extended community-list number (standard)\n"
3919 "Extended community-list number (expanded)\n"
3920 "Extended community-list name\n")
3922 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3923 RMAP_EVENT_ECLIST_DELETED
);
3927 DEFUN (match_aspath
,
3929 "match as-path WORD",
3931 "Match BGP AS path list\n"
3932 "AS path access-list name\n")
3935 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3936 RMAP_EVENT_ASLIST_ADDED
);
3940 DEFUN (no_match_aspath
,
3941 no_match_aspath_cmd
,
3942 "no match as-path [WORD]",
3945 "Match BGP AS path list\n"
3946 "AS path access-list name\n")
3948 return bgp_route_match_delete(vty
, "as-path", NULL
,
3949 RMAP_EVENT_ASLIST_DELETED
);
3953 DEFUN (match_origin
,
3955 "match origin <egp|igp|incomplete>",
3960 "unknown heritage\n")
3963 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3964 return bgp_route_match_add(vty
, "origin", "igp",
3965 RMAP_EVENT_MATCH_ADDED
);
3966 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3967 return bgp_route_match_add(vty
, "origin", "egp",
3968 RMAP_EVENT_MATCH_ADDED
);
3969 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3970 return bgp_route_match_add(vty
, "origin", "incomplete",
3971 RMAP_EVENT_MATCH_ADDED
);
3973 vty_out(vty
, "%% Invalid match origin type\n");
3974 return CMD_WARNING_CONFIG_FAILED
;
3978 DEFUN (no_match_origin
,
3979 no_match_origin_cmd
,
3980 "no match origin [<egp|igp|incomplete>]",
3986 "unknown heritage\n")
3988 return bgp_route_match_delete(vty
, "origin", NULL
,
3989 RMAP_EVENT_MATCH_DELETED
);
3992 DEFUN (set_ip_nexthop_peer
,
3993 set_ip_nexthop_peer_cmd
,
3994 "[no] set ip next-hop peer-address",
3998 "Next hop address\n"
3999 "Use peer address (for BGP only)\n")
4001 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4002 const char *) = strmatch(argv
[0]->text
, "no")
4003 ? generic_set_delete
4006 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4010 DEFUN (set_ip_nexthop_unchanged
,
4011 set_ip_nexthop_unchanged_cmd
,
4012 "[no] set ip next-hop unchanged",
4016 "Next hop address\n"
4017 "Don't modify existing Next hop address\n")
4019 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
4020 const char *) = strmatch(argv
[0]->text
, "no")
4021 ? generic_set_delete
4024 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
4029 DEFUN (set_local_pref
,
4031 "set local-preference (0-4294967295)",
4033 "BGP local preference path attribute\n"
4034 "Preference value\n")
4037 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4038 "local-preference", argv
[idx_number
]->arg
);
4042 DEFUN (no_set_local_pref
,
4043 no_set_local_pref_cmd
,
4044 "no set local-preference [(0-4294967295)]",
4047 "BGP local preference path attribute\n"
4048 "Preference value\n")
4050 int idx_localpref
= 3;
4051 if (argc
<= idx_localpref
)
4052 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4053 "local-preference", NULL
);
4054 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4055 "local-preference", argv
[idx_localpref
]->arg
);
4061 "set weight (0-4294967295)",
4063 "BGP weight for routing table\n"
4067 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4068 argv
[idx_number
]->arg
);
4072 DEFUN (no_set_weight
,
4074 "no set weight [(0-4294967295)]",
4077 "BGP weight for routing table\n"
4081 if (argc
<= idx_weight
)
4082 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4084 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4085 "weight", argv
[idx_weight
]->arg
);
4088 DEFUN (set_label_index
,
4089 set_label_index_cmd
,
4090 "set label-index (0-1048560)",
4092 "Label index to associate with the prefix\n"
4093 "Label index value\n")
4096 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4097 "label-index", argv
[idx_number
]->arg
);
4100 DEFUN (no_set_label_index
,
4101 no_set_label_index_cmd
,
4102 "no set label-index [(0-1048560)]",
4105 "Label index to associate with the prefix\n"
4106 "Label index value\n")
4108 int idx_label_index
= 3;
4109 if (argc
<= idx_label_index
)
4110 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4111 "label-index", NULL
);
4112 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4113 "label-index", argv
[idx_label_index
]->arg
);
4116 DEFUN (set_aspath_prepend_asn
,
4117 set_aspath_prepend_asn_cmd
,
4118 "set as-path prepend (1-4294967295)...",
4120 "Transform BGP AS_PATH attribute\n"
4121 "Prepend to the as-path\n"
4128 str
= argv_concat(argv
, argc
, idx_asn
);
4129 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4130 "as-path prepend", str
);
4131 XFREE(MTYPE_TMP
, str
);
4136 DEFUN (set_aspath_prepend_lastas
,
4137 set_aspath_prepend_lastas_cmd
,
4138 "set as-path prepend last-as (1-10)",
4140 "Transform BGP AS_PATH attribute\n"
4141 "Prepend to the as-path\n"
4142 "Use the peer's AS-number\n"
4143 "Number of times to insert\n")
4145 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4148 DEFUN (no_set_aspath_prepend
,
4149 no_set_aspath_prepend_cmd
,
4150 "no set as-path prepend [(1-4294967295)]",
4153 "Transform BGP AS_PATH attribute\n"
4154 "Prepend to the as-path\n"
4161 str
= argv_concat(argv
, argc
, idx_asn
);
4162 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4163 "as-path prepend", str
);
4164 XFREE(MTYPE_TMP
, str
);
4169 DEFUN (set_aspath_exclude
,
4170 set_aspath_exclude_cmd
,
4171 "set as-path exclude (1-4294967295)...",
4173 "Transform BGP AS-path attribute\n"
4174 "Exclude from the as-path\n"
4181 str
= argv_concat(argv
, argc
, idx_asn
);
4182 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4183 "as-path exclude", str
);
4184 XFREE(MTYPE_TMP
, str
);
4188 DEFUN (no_set_aspath_exclude
,
4189 no_set_aspath_exclude_cmd
,
4190 "no set as-path exclude (1-4294967295)...",
4193 "Transform BGP AS_PATH attribute\n"
4194 "Exclude from the as-path\n"
4201 str
= argv_concat(argv
, argc
, idx_asn
);
4202 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4203 "as-path exclude", str
);
4204 XFREE(MTYPE_TMP
, str
);
4208 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4209 "no set as-path exclude",
4211 "Transform BGP AS_PATH attribute\n"
4212 "Exclude from the as-path\n")
4214 DEFUN (set_community
,
4216 "set community AA:NN...",
4218 "BGP community attribute\n"
4226 struct community
*com
= NULL
;
4231 b
= buffer_new(1024);
4233 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4234 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4241 buffer_putc(b
, ' ');
4245 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4247 buffer_putstr(b
, "internet");
4250 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4252 buffer_putstr(b
, "local-AS");
4255 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4256 && strncmp(argv
[i
]->arg
, "no-advertise",
4257 strlen(argv
[i
]->arg
))
4259 buffer_putstr(b
, "no-advertise");
4262 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4263 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4265 buffer_putstr(b
, "no-export");
4268 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4269 strlen(argv
[i
]->arg
))
4271 buffer_putstr(b
, "graceful-shutdown");
4274 buffer_putstr(b
, argv
[i
]->arg
);
4276 buffer_putc(b
, '\0');
4278 /* Fetch result string then compile it to communities attribute. */
4279 str
= buffer_getstr(b
);
4283 com
= community_str2com(str
);
4284 XFREE(MTYPE_TMP
, str
);
4287 /* Can't compile user input into communities attribute. */
4289 vty_out(vty
, "%% Malformed communities attribute\n");
4290 return CMD_WARNING_CONFIG_FAILED
;
4293 /* Set communites attribute string. */
4294 str
= community_str(com
, false);
4297 argstr
= XCALLOC(MTYPE_TMP
,
4298 strlen(str
) + strlen(" additive") + 1);
4299 strcpy(argstr
, str
);
4300 strcpy(argstr
+ strlen(str
), " additive");
4301 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4302 "community", argstr
);
4303 XFREE(MTYPE_TMP
, argstr
);
4305 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4308 community_free(&com
);
4313 DEFUN (set_community_none
,
4314 set_community_none_cmd
,
4315 "set community none",
4317 "BGP community attribute\n"
4318 "No community attribute\n")
4320 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4321 "community", "none");
4324 DEFUN (no_set_community
,
4325 no_set_community_cmd
,
4326 "no set community AA:NN...",
4329 "BGP community attribute\n"
4332 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4336 ALIAS (no_set_community
,
4337 no_set_community_short_cmd
,
4341 "BGP community attribute\n")
4344 DEFUN (set_community_delete
,
4345 set_community_delete_cmd
,
4346 "set comm-list <(1-99)|(100-500)|WORD> delete",
4348 "set BGP community list (for deletion)\n"
4349 "Community-list number (standard)\n"
4350 "Community-list number (expanded)\n"
4351 "Community-list name\n"
4352 "Delete matching communities\n")
4354 int idx_comm_list
= 2;
4357 str
= XCALLOC(MTYPE_TMP
,
4358 strlen(argv
[idx_comm_list
]->arg
) + strlen(" delete") + 1);
4359 strcpy(str
, argv
[idx_comm_list
]->arg
);
4360 strcpy(str
+ strlen(argv
[idx_comm_list
]->arg
), " delete");
4362 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4365 XFREE(MTYPE_TMP
, str
);
4369 DEFUN (no_set_community_delete
,
4370 no_set_community_delete_cmd
,
4371 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4374 "set BGP community list (for deletion)\n"
4375 "Community-list number (standard)\n"
4376 "Community-list number (expanded)\n"
4377 "Community-list name\n"
4378 "Delete matching communities\n")
4380 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4384 DEFUN (set_lcommunity
,
4386 "set large-community AA:BB:CC...",
4388 "BGP large community attribute\n"
4389 "Large Community number in aa:bb:cc format or additive\n")
4394 str
= argv_concat(argv
, argc
, 2);
4395 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4396 "large-community", str
);
4397 XFREE(MTYPE_TMP
, str
);
4402 DEFUN (set_lcommunity_none
,
4403 set_lcommunity_none_cmd
,
4404 "set large-community none",
4406 "BGP large community attribute\n"
4407 "No large community attribute\n")
4409 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4410 "large-community", "none");
4413 DEFUN (no_set_lcommunity
,
4414 no_set_lcommunity_cmd
,
4415 "no set large-community none",
4418 "BGP large community attribute\n"
4419 "No community attribute\n")
4421 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4422 "large-community", NULL
);
4425 DEFUN (no_set_lcommunity1
,
4426 no_set_lcommunity1_cmd
,
4427 "no set large-community AA:BB:CC...",
4430 "BGP large community attribute\n"
4431 "Large community in AA:BB:CC... format or additive\n")
4433 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4434 "large-community", NULL
);
4437 ALIAS (no_set_lcommunity1
,
4438 no_set_lcommunity1_short_cmd
,
4439 "no set large-community",
4442 "BGP large community attribute\n")
4444 DEFUN (set_lcommunity_delete
,
4445 set_lcommunity_delete_cmd
,
4446 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4448 "set BGP large community list (for deletion)\n"
4449 "Large Community-list number (standard)\n"
4450 "Large Communitly-list number (expanded)\n"
4451 "Large Community-list name\n"
4452 "Delete matching large communities\n")
4456 str
= XCALLOC(MTYPE_TMP
, strlen(argv
[2]->arg
) + strlen(" delete") + 1);
4457 strcpy(str
, argv
[2]->arg
);
4458 strcpy(str
+ strlen(argv
[2]->arg
), " delete");
4460 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4461 "large-comm-list", str
);
4463 XFREE(MTYPE_TMP
, str
);
4467 DEFUN (no_set_lcommunity_delete
,
4468 no_set_lcommunity_delete_cmd
,
4469 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4472 "set BGP large community list (for deletion)\n"
4473 "Large Community-list number (standard)\n"
4474 "Large Communitly-list number (expanded)\n"
4475 "Large Community-list name\n"
4476 "Delete matching large communities\n")
4478 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4479 "large-comm-list", NULL
);
4482 ALIAS (no_set_lcommunity_delete
,
4483 no_set_lcommunity_delete_short_cmd
,
4484 "no set large-comm-list",
4487 "set BGP large community list (for deletion)\n")
4489 DEFUN (set_ecommunity_rt
,
4490 set_ecommunity_rt_cmd
,
4491 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4493 "BGP extended community attribute\n"
4494 "Route Target extended community\n"
4495 "VPN extended community\n")
4501 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4502 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4503 "extcommunity rt", str
);
4504 XFREE(MTYPE_TMP
, str
);
4509 DEFUN (no_set_ecommunity_rt
,
4510 no_set_ecommunity_rt_cmd
,
4511 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4514 "BGP extended community attribute\n"
4515 "Route Target extended community\n"
4516 "VPN extended community\n")
4518 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4519 "extcommunity rt", NULL
);
4522 ALIAS (no_set_ecommunity_rt
,
4523 no_set_ecommunity_rt_short_cmd
,
4524 "no set extcommunity rt",
4527 "BGP extended community attribute\n"
4528 "Route Target extended community\n")
4530 DEFUN (set_ecommunity_soo
,
4531 set_ecommunity_soo_cmd
,
4532 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4534 "BGP extended community attribute\n"
4535 "Site-of-Origin extended community\n"
4536 "VPN extended community\n")
4542 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4543 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4544 "extcommunity soo", str
);
4545 XFREE(MTYPE_TMP
, str
);
4550 DEFUN (no_set_ecommunity_soo
,
4551 no_set_ecommunity_soo_cmd
,
4552 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4555 "BGP extended community attribute\n"
4556 "Site-of-Origin extended community\n"
4557 "VPN extended community\n")
4559 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4560 "extcommunity soo", NULL
);
4563 ALIAS (no_set_ecommunity_soo
,
4564 no_set_ecommunity_soo_short_cmd
,
4565 "no set extcommunity soo",
4568 "GP extended community attribute\n"
4569 "Site-of-Origin extended community\n")
4573 "set origin <egp|igp|incomplete>",
4578 "unknown heritage\n")
4581 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4582 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4584 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4585 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4587 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4588 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4589 "origin", "incomplete");
4591 vty_out(vty
, "%% Invalid set origin type\n");
4592 return CMD_WARNING_CONFIG_FAILED
;
4596 DEFUN (no_set_origin
,
4598 "no set origin [<egp|igp|incomplete>]",
4604 "unknown heritage\n")
4606 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4611 DEFUN (set_atomic_aggregate
,
4612 set_atomic_aggregate_cmd
,
4613 "set atomic-aggregate",
4615 "BGP atomic aggregate attribute\n" )
4617 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4618 "atomic-aggregate", NULL
);
4621 DEFUN (no_set_atomic_aggregate
,
4622 no_set_atomic_aggregate_cmd
,
4623 "no set atomic-aggregate",
4626 "BGP atomic aggregate attribute\n" )
4628 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4629 "atomic-aggregate", NULL
);
4632 DEFUN (set_aggregator_as
,
4633 set_aggregator_as_cmd
,
4634 "set aggregator as (1-4294967295) A.B.C.D",
4636 "BGP aggregator attribute\n"
4637 "AS number of aggregator\n"
4639 "IP address of aggregator\n")
4644 struct in_addr address
;
4647 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4649 vty_out(vty
, "Aggregator IP address is invalid\n");
4650 return CMD_WARNING_CONFIG_FAILED
;
4653 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4654 strlen(argv
[idx_number
]->arg
)
4655 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4657 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4659 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4660 "aggregator as", argstr
);
4662 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4668 DEFUN (no_set_aggregator_as
,
4669 no_set_aggregator_as_cmd
,
4670 "no set aggregator as [(1-4294967295) A.B.C.D]",
4673 "BGP aggregator attribute\n"
4674 "AS number of aggregator\n"
4676 "IP address of aggregator\n")
4681 struct in_addr address
;
4684 if (argc
<= idx_asn
)
4685 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4686 "aggregator as", NULL
);
4688 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4690 vty_out(vty
, "Aggregator IP address is invalid\n");
4691 return CMD_WARNING_CONFIG_FAILED
;
4694 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4695 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4698 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4700 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4701 "aggregator as", argstr
);
4703 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4708 DEFUN (match_ipv6_next_hop
,
4709 match_ipv6_next_hop_cmd
,
4710 "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_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4718 RMAP_EVENT_MATCH_ADDED
);
4721 DEFUN (no_match_ipv6_next_hop
,
4722 no_match_ipv6_next_hop_cmd
,
4723 "no match ipv6 next-hop X:X::X:X",
4727 "Match IPv6 next-hop address of route\n"
4728 "IPv6 address of next hop\n")
4731 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4732 RMAP_EVENT_MATCH_DELETED
);
4736 DEFUN (set_ipv6_nexthop_peer
,
4737 set_ipv6_nexthop_peer_cmd
,
4738 "set ipv6 next-hop peer-address",
4741 "Next hop address\n"
4742 "Use peer address (for BGP only)\n")
4744 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4745 "ipv6 next-hop peer-address", NULL
);
4748 DEFUN (no_set_ipv6_nexthop_peer
,
4749 no_set_ipv6_nexthop_peer_cmd
,
4750 "no set ipv6 next-hop peer-address",
4754 "IPv6 next-hop address\n"
4755 "Use peer address (for BGP only)\n")
4757 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4758 "ipv6 next-hop peer-address", NULL
);
4761 DEFUN (set_ipv6_nexthop_prefer_global
,
4762 set_ipv6_nexthop_prefer_global_cmd
,
4763 "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_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4770 "ipv6 next-hop prefer-global", NULL
);
4774 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4775 no_set_ipv6_nexthop_prefer_global_cmd
,
4776 "no set ipv6 next-hop prefer-global",
4780 "IPv6 next-hop address\n"
4781 "Prefer global over link-local if both exist\n")
4783 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4784 "ipv6 next-hop prefer-global", NULL
);
4787 DEFUN (set_ipv6_nexthop_global
,
4788 set_ipv6_nexthop_global_cmd
,
4789 "set ipv6 next-hop global X:X::X:X",
4792 "IPv6 next-hop address\n"
4793 "IPv6 global address\n"
4794 "IPv6 address of next hop\n")
4797 struct in6_addr addr
;
4800 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4802 vty_out(vty
, "%% Malformed nexthop address\n");
4803 return CMD_WARNING_CONFIG_FAILED
;
4805 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4806 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4807 vty_out(vty
, "%% Invalid global nexthop address\n");
4808 return CMD_WARNING_CONFIG_FAILED
;
4811 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4812 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4816 DEFUN (no_set_ipv6_nexthop_global
,
4817 no_set_ipv6_nexthop_global_cmd
,
4818 "no set ipv6 next-hop global X:X::X:X",
4822 "IPv6 next-hop address\n"
4823 "IPv6 global address\n"
4824 "IPv6 address of next hop\n")
4827 if (argc
<= idx_ipv6
)
4828 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4829 "ipv6 next-hop global", NULL
);
4830 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4831 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4834 #ifdef KEEP_OLD_VPN_COMMANDS
4835 DEFUN (set_vpn_nexthop
,
4836 set_vpn_nexthop_cmd
,
4837 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4839 "VPNv4 information\n"
4840 "VPN next-hop address\n"
4841 "IP address of next hop\n"
4842 "VPNv6 information\n"
4843 "VPN next-hop address\n"
4844 "IPv6 address of next hop\n")
4850 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4852 return generic_set_add(
4853 vty
, VTY_GET_CONTEXT(route_map_index
),
4854 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4856 return generic_set_add(
4857 vty
, VTY_GET_CONTEXT(route_map_index
),
4858 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4863 DEFUN (no_set_vpn_nexthop
,
4864 no_set_vpn_nexthop_cmd
,
4865 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4868 "VPNv4 information\n"
4869 "VPN next-hop address\n"
4870 "IP address of next hop\n"
4871 "VPNv6 information\n"
4872 "VPN next-hop address\n"
4873 "IPv6 address of next hop\n")
4883 arg
= argv
[idx_ip
]->arg
;
4884 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4886 return generic_set_delete(
4887 vty
, VTY_GET_CONTEXT(route_map_index
),
4888 "ipv4 vpn next-hop", arg
);
4890 return generic_set_delete(
4891 vty
, VTY_GET_CONTEXT(route_map_index
),
4892 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4896 #endif /* KEEP_OLD_VPN_COMMANDS */
4898 DEFUN (set_ipx_vpn_nexthop
,
4899 set_ipx_vpn_nexthop_cmd
,
4900 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4902 "IPv4 information\n"
4903 "IPv6 information\n"
4905 "VPN next-hop address\n"
4906 "IP address of next hop\n"
4907 "IPv6 address of next hop\n")
4913 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4915 return generic_set_add(
4916 vty
, VTY_GET_CONTEXT(route_map_index
),
4917 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4919 return generic_set_add(
4920 vty
, VTY_GET_CONTEXT(route_map_index
),
4921 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4926 DEFUN (no_set_ipx_vpn_nexthop
,
4927 no_set_ipx_vpn_nexthop_cmd
,
4928 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4931 "IPv4 information\n"
4932 "IPv6 information\n"
4934 "VPN next-hop address\n"
4935 "IP address of next hop\n"
4936 "IPv6 address of next hop\n")
4946 arg
= argv
[idx_ip
]->arg
;
4947 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4949 return generic_set_delete(
4950 vty
, VTY_GET_CONTEXT(route_map_index
),
4951 "ipv4 vpn next-hop", arg
);
4953 return generic_set_delete(
4954 vty
, VTY_GET_CONTEXT(route_map_index
),
4955 "ipv6 vpn next-hop", arg
);
4960 DEFUN (set_originator_id
,
4961 set_originator_id_cmd
,
4962 "set originator-id A.B.C.D",
4964 "BGP originator ID attribute\n"
4965 "IP address of originator\n")
4968 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4969 "originator-id", argv
[idx_ipv4
]->arg
);
4973 DEFUN (no_set_originator_id
,
4974 no_set_originator_id_cmd
,
4975 "no set originator-id [A.B.C.D]",
4978 "BGP originator ID attribute\n"
4979 "IP address of originator\n")
4983 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4985 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4986 "originator-id", arg
);
4990 /* Initialization of route map. */
4991 void bgp_route_map_init(void)
4995 route_map_add_hook(bgp_route_map_add
);
4996 route_map_delete_hook(bgp_route_map_delete
);
4997 route_map_event_hook(bgp_route_map_event
);
4999 route_map_match_interface_hook(generic_match_add
);
5000 route_map_no_match_interface_hook(generic_match_delete
);
5002 route_map_match_ip_address_hook(generic_match_add
);
5003 route_map_no_match_ip_address_hook(generic_match_delete
);
5005 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
5006 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
5008 route_map_match_ip_next_hop_hook(generic_match_add
);
5009 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
5011 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
5012 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
5014 route_map_match_ip_next_hop_type_hook(generic_match_add
);
5015 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
5017 route_map_match_ipv6_address_hook(generic_match_add
);
5018 route_map_no_match_ipv6_address_hook(generic_match_delete
);
5020 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
5021 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
5023 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5024 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5026 route_map_match_metric_hook(generic_match_add
);
5027 route_map_no_match_metric_hook(generic_match_delete
);
5029 route_map_match_tag_hook(generic_match_add
);
5030 route_map_no_match_tag_hook(generic_match_delete
);
5032 route_map_set_ip_nexthop_hook(generic_set_add
);
5033 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5035 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5036 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5038 route_map_set_metric_hook(generic_set_add
);
5039 route_map_no_set_metric_hook(generic_set_delete
);
5041 route_map_set_tag_hook(generic_set_add
);
5042 route_map_no_set_tag_hook(generic_set_delete
);
5044 route_map_install_match(&route_match_peer_cmd
);
5045 route_map_install_match(&route_match_local_pref_cmd
);
5046 #if defined(HAVE_LUA)
5047 route_map_install_match(&route_match_command_cmd
);
5049 route_map_install_match(&route_match_ip_address_cmd
);
5050 route_map_install_match(&route_match_ip_next_hop_cmd
);
5051 route_map_install_match(&route_match_ip_route_source_cmd
);
5052 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5053 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5054 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5055 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5056 route_map_install_match(&route_match_aspath_cmd
);
5057 route_map_install_match(&route_match_community_cmd
);
5058 route_map_install_match(&route_match_lcommunity_cmd
);
5059 route_map_install_match(&route_match_ecommunity_cmd
);
5060 route_map_install_match(&route_match_local_pref_cmd
);
5061 route_map_install_match(&route_match_metric_cmd
);
5062 route_map_install_match(&route_match_origin_cmd
);
5063 route_map_install_match(&route_match_probability_cmd
);
5064 route_map_install_match(&route_match_interface_cmd
);
5065 route_map_install_match(&route_match_tag_cmd
);
5066 route_map_install_match(&route_match_mac_address_cmd
);
5067 route_map_install_match(&route_match_evpn_vni_cmd
);
5068 route_map_install_match(&route_match_evpn_route_type_cmd
);
5069 route_map_install_match(&route_match_evpn_default_route_cmd
);
5070 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5072 route_map_install_set(&route_set_ip_nexthop_cmd
);
5073 route_map_install_set(&route_set_local_pref_cmd
);
5074 route_map_install_set(&route_set_weight_cmd
);
5075 route_map_install_set(&route_set_label_index_cmd
);
5076 route_map_install_set(&route_set_metric_cmd
);
5077 route_map_install_set(&route_set_aspath_prepend_cmd
);
5078 route_map_install_set(&route_set_aspath_exclude_cmd
);
5079 route_map_install_set(&route_set_origin_cmd
);
5080 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5081 route_map_install_set(&route_set_aggregator_as_cmd
);
5082 route_map_install_set(&route_set_community_cmd
);
5083 route_map_install_set(&route_set_community_delete_cmd
);
5084 route_map_install_set(&route_set_lcommunity_cmd
);
5085 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5086 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5087 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5088 route_map_install_set(&route_set_originator_id_cmd
);
5089 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5090 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5091 route_map_install_set(&route_set_tag_cmd
);
5092 route_map_install_set(&route_set_label_index_cmd
);
5094 install_element(RMAP_NODE
, &match_peer_cmd
);
5095 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5096 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5097 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5098 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5099 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5100 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5101 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5102 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5103 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5104 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5105 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5106 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5107 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5108 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5109 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5110 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5112 install_element(RMAP_NODE
, &match_aspath_cmd
);
5113 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5114 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5115 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5116 install_element(RMAP_NODE
, &match_community_cmd
);
5117 install_element(RMAP_NODE
, &no_match_community_cmd
);
5118 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5119 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5120 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5121 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5122 install_element(RMAP_NODE
, &match_origin_cmd
);
5123 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5124 install_element(RMAP_NODE
, &match_probability_cmd
);
5125 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5127 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5128 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5129 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5130 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5131 install_element(RMAP_NODE
, &set_weight_cmd
);
5132 install_element(RMAP_NODE
, &set_label_index_cmd
);
5133 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5134 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5135 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5136 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5137 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5138 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5139 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5140 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5141 install_element(RMAP_NODE
, &set_origin_cmd
);
5142 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5143 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5144 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5145 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5146 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5147 install_element(RMAP_NODE
, &set_community_cmd
);
5148 install_element(RMAP_NODE
, &set_community_none_cmd
);
5149 install_element(RMAP_NODE
, &no_set_community_cmd
);
5150 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5151 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5152 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5153 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5154 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5155 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5156 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5157 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5158 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5159 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5160 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5161 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5162 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5163 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5164 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5165 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5166 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5167 #ifdef KEEP_OLD_VPN_COMMANDS
5168 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5169 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5170 #endif /* KEEP_OLD_VPN_COMMANDS */
5171 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5172 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5173 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5174 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5176 route_map_install_match(&route_match_ipv6_address_cmd
);
5177 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5178 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5179 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5180 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5181 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5182 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5183 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5185 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5186 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5187 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5188 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5189 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5190 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5191 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5192 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5193 #if defined(HAVE_LUA)
5194 install_element(RMAP_NODE
, &match_command_cmd
);
5195 install_element(RMAP_NODE
, &no_match_command_cmd
);
5199 void bgp_route_map_terminate(void)
5201 /* ToDo: Cleanup all the used memory */