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
));
207 static void route_value_free(void *rule
)
209 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
212 /* generic as path object to be shared in multiple rules */
214 static void *route_aspath_compile(const char *arg
)
216 struct aspath
*aspath
;
218 aspath
= aspath_str2aspath(arg
);
224 static void route_aspath_free(void *rule
)
226 struct aspath
*aspath
= rule
;
230 struct bgp_match_peer_compiled
{
235 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
237 /* Compares the peer specified in the 'match peer' clause with the peer
238 received in bgp_path_info->peer. If it is the same, or if the peer structure
239 received is a peer_group containing it, returns RMAP_MATCH. */
240 static route_map_result_t
route_match_peer(void *rule
,
241 const struct prefix
*prefix
,
242 route_map_object_t type
,
245 struct bgp_match_peer_compiled
*pc
;
247 union sockunion su_def
= {
248 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
249 struct peer_group
*group
;
251 struct listnode
*node
, *nnode
;
253 if (type
== RMAP_BGP
) {
256 peer
= ((struct bgp_path_info
*)object
)->peer
;
262 if (strcmp(peer
->conf_if
, pc
->interface
) == 0)
268 /* If su='0.0.0.0' (command 'match peer local'), and it's a
270 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH
272 if (sockunion_same(su
, &su_def
)) {
274 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
275 || CHECK_FLAG(peer
->rmap_type
,
276 PEER_RMAP_TYPE_REDISTRIBUTE
)
277 || CHECK_FLAG(peer
->rmap_type
,
278 PEER_RMAP_TYPE_DEFAULT
))
285 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
286 if (sockunion_same(su
, &peer
->su
))
292 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
294 if (sockunion_same(su
, &peer
->su
))
303 static void *route_match_peer_compile(const char *arg
)
305 struct bgp_match_peer_compiled
*pc
;
308 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
309 sizeof(struct bgp_match_peer_compiled
));
311 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
313 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
320 /* Free route map's compiled `ip address' value. */
321 static void route_match_peer_free(void *rule
)
323 struct bgp_match_peer_compiled
*pc
= rule
;
325 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
327 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
330 /* Route map commands for ip address matching. */
331 struct route_map_rule_cmd route_match_peer_cmd
= {"peer", route_match_peer
,
332 route_match_peer_compile
,
333 route_match_peer_free
};
335 #if defined(HAVE_LUA)
336 static route_map_result_t
route_match_command(void *rule
,
337 const struct prefix
*prefix
,
338 route_map_object_t type
,
341 int status
= RMAP_NOMATCH
;
342 u_int32_t locpref
= 0;
343 u_int32_t newlocpref
= 0;
344 enum lua_rm_status lrm_status
;
345 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
346 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
352 * Setup the prefix information to pass in
354 lua_setup_prefix_table(L
, prefix
);
356 zlog_debug("Set up prefix table");
358 * Setup the bgp_path_info information
361 lua_pushinteger(L
, path
->attr
->med
);
362 lua_setfield(L
, -2, "metric");
363 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
364 lua_setfield(L
, -2, "ifindex");
365 lua_pushstring(L
, path
->attr
->aspath
->str
);
366 lua_setfield(L
, -2, "aspath");
367 lua_pushinteger(L
, path
->attr
->local_pref
);
368 lua_setfield(L
, -2, "localpref");
369 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
370 lua_setglobal(L
, "nexthop");
372 zlog_debug("Set up nexthop information");
376 lrm_status
= lua_run_rm_rule(L
, rule
);
377 switch (lrm_status
) {
379 zlog_debug("RM_FAILURE");
382 zlog_debug("RM_NOMATCH");
384 case LUA_RM_MATCH_AND_CHANGE
:
385 zlog_debug("MATCH AND CHANGE");
386 lua_getglobal(L
, "nexthop");
387 path
->attr
->med
= get_integer(L
, "metric");
389 * This needs to be abstraced with the set function
391 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
392 locpref
= path
->attr
->local_pref
;
393 newlocpref
= get_integer(L
, "localpref");
394 if (newlocpref
!= locpref
) {
395 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
396 path
->attr
->local_pref
= newlocpref
;
401 zlog_debug("MATCH ONLY");
409 static void *route_match_command_compile(const char *arg
)
413 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
418 route_match_command_free(void *rule
)
420 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
423 struct route_map_rule_cmd route_match_command_cmd
= {
426 route_match_command_compile
,
427 route_match_command_free
431 /* `match ip address IP_ACCESS_LIST' */
433 /* Match function should return 1 if match is success else return
435 static route_map_result_t
route_match_ip_address(void *rule
,
436 const struct prefix
*prefix
,
437 route_map_object_t type
,
440 struct access_list
*alist
;
442 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
443 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
447 return (access_list_apply(alist
, prefix
) == FILTER_DENY
454 /* Route map `ip address' match statement. `arg' should be
456 static void *route_match_ip_address_compile(const char *arg
)
458 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
461 /* Free route map's compiled `ip address' value. */
462 static void route_match_ip_address_free(void *rule
)
464 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
467 /* Route map commands for ip address matching. */
468 struct route_map_rule_cmd route_match_ip_address_cmd
= {
469 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
470 route_match_ip_address_free
};
472 /* `match ip next-hop IP_ADDRESS' */
474 /* Match function return 1 if match is success else return zero. */
475 static route_map_result_t
route_match_ip_next_hop(void *rule
,
476 const struct prefix
*prefix
,
477 route_map_object_t type
,
480 struct access_list
*alist
;
481 struct bgp_path_info
*path
;
482 struct prefix_ipv4 p
;
484 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
487 p
.prefix
= path
->attr
->nexthop
;
488 p
.prefixlen
= IPV4_MAX_BITLEN
;
490 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
494 return (access_list_apply(alist
, &p
) == FILTER_DENY
501 /* Route map `ip next-hop' match statement. `arg' is
503 static void *route_match_ip_next_hop_compile(const char *arg
)
505 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
508 /* Free route map's compiled `ip address' value. */
509 static void route_match_ip_next_hop_free(void *rule
)
511 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
514 /* Route map commands for ip next-hop matching. */
515 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
516 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
517 route_match_ip_next_hop_free
};
519 /* `match ip route-source ACCESS-LIST' */
521 /* Match function return 1 if match is success else return zero. */
522 static route_map_result_t
route_match_ip_route_source(void *rule
,
523 const struct prefix
*pfx
,
524 route_map_object_t type
,
527 struct access_list
*alist
;
528 struct bgp_path_info
*path
;
530 struct prefix_ipv4 p
;
532 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
536 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
540 p
.prefix
= peer
->su
.sin
.sin_addr
;
541 p
.prefixlen
= IPV4_MAX_BITLEN
;
543 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
547 return (access_list_apply(alist
, &p
) == FILTER_DENY
554 /* Route map `ip route-source' match statement. `arg' is
556 static void *route_match_ip_route_source_compile(const char *arg
)
558 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
561 /* Free route map's compiled `ip address' value. */
562 static void route_match_ip_route_source_free(void *rule
)
564 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
567 /* Route map commands for ip route-source matching. */
568 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
569 "ip route-source", route_match_ip_route_source
,
570 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
572 /* `match ip address prefix-list PREFIX_LIST' */
574 static route_map_result_t
575 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
576 route_map_object_t type
, void *object
)
578 struct prefix_list
*plist
;
580 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
581 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
585 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
592 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
594 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
597 static void route_match_ip_address_prefix_list_free(void *rule
)
599 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
602 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
603 "ip address prefix-list", route_match_ip_address_prefix_list
,
604 route_match_ip_address_prefix_list_compile
,
605 route_match_ip_address_prefix_list_free
};
607 /* `match ip next-hop prefix-list PREFIX_LIST' */
609 static route_map_result_t
610 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
611 route_map_object_t type
, void *object
)
613 struct prefix_list
*plist
;
614 struct bgp_path_info
*path
;
615 struct prefix_ipv4 p
;
617 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
620 p
.prefix
= path
->attr
->nexthop
;
621 p
.prefixlen
= IPV4_MAX_BITLEN
;
623 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
627 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
634 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
636 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
639 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
641 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
644 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
645 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
646 route_match_ip_next_hop_prefix_list_compile
,
647 route_match_ip_next_hop_prefix_list_free
};
649 /* `match ip next-hop type <blackhole>' */
651 static route_map_result_t
652 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
653 route_map_object_t type
, void *object
)
655 struct bgp_path_info
*path
;
657 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
658 path
= (struct bgp_path_info
*)object
;
659 if (!path
|| !path
->attr
)
660 return RMAP_DENYMATCH
;
662 /* If nexthop interface's index can't be resolved and nexthop is
663 set to any address then mark it as type `blackhole`.
664 This logic works for matching kernel/static routes like:
665 `ip route add blackhole 10.0.0.1`. */
666 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
667 && !path
->attr
->nh_ifindex
)
673 static void *route_match_ip_next_hop_type_compile(const char *arg
)
675 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
678 static void route_match_ip_next_hop_type_free(void *rule
)
680 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
683 static struct route_map_rule_cmd route_match_ip_next_hop_type_cmd
= {
684 "ip next-hop type", route_match_ip_next_hop_type
,
685 route_match_ip_next_hop_type_compile
,
686 route_match_ip_next_hop_type_free
};
688 /* `match ip route-source prefix-list PREFIX_LIST' */
690 static route_map_result_t
691 route_match_ip_route_source_prefix_list(void *rule
,
692 const struct prefix
*prefix
,
693 route_map_object_t type
, void *object
)
695 struct prefix_list
*plist
;
696 struct bgp_path_info
*path
;
698 struct prefix_ipv4 p
;
700 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
704 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
708 p
.prefix
= peer
->su
.sin
.sin_addr
;
709 p
.prefixlen
= IPV4_MAX_BITLEN
;
711 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
715 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
722 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
724 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
727 static void route_match_ip_route_source_prefix_list_free(void *rule
)
729 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
732 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
733 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
734 route_match_ip_route_source_prefix_list_compile
,
735 route_match_ip_route_source_prefix_list_free
};
737 /* `match evpn default-route' */
739 /* Match function should return 1 if match is success else 0 */
740 static route_map_result_t
route_match_evpn_default_route(void *rule
,
741 const struct prefix
*p
,
745 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
751 /* Route map commands for default-route matching. */
752 struct route_map_rule_cmd route_match_evpn_default_route_cmd
= {
753 "evpn default-route", route_match_evpn_default_route
, NULL
, NULL
};
755 /* `match mac address MAC_ACCESS_LIST' */
757 /* Match function should return 1 if match is success else return
759 static route_map_result_t
route_match_mac_address(void *rule
,
760 const struct prefix
*prefix
,
761 route_map_object_t type
,
764 struct access_list
*alist
;
767 if (type
== RMAP_BGP
) {
768 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
772 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
775 p
.family
= AF_ETHERNET
;
776 p
.prefixlen
= ETH_ALEN
* 8;
777 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
779 return (access_list_apply(alist
, &p
) == FILTER_DENY
787 /* Route map `mac address' match statement. `arg' should be
789 static void *route_match_mac_address_compile(const char *arg
)
791 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
794 /* Free route map's compiled `ip address' value. */
795 static void route_match_mac_address_free(void *rule
)
797 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
800 /* Route map commands for mac address matching. */
801 struct route_map_rule_cmd route_match_mac_address_cmd
= {
802 "mac address", route_match_mac_address
, route_match_mac_address_compile
,
803 route_match_mac_address_free
};
807 /* Match function should return 1 if match is success else return
809 static route_map_result_t
route_match_vni(void *rule
,
810 const struct prefix
*prefix
,
811 route_map_object_t type
, void *object
)
814 struct bgp_path_info
*path
= NULL
;
816 if (type
== RMAP_BGP
) {
817 vni
= *((vni_t
*)rule
);
818 path
= (struct bgp_path_info
*)object
;
820 if (path
->extra
== NULL
)
823 if (vni
== label2vni(&path
->extra
->label
[0]))
830 /* Route map `vni' match statement. */
831 static void *route_match_vni_compile(const char *arg
)
836 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
838 *vni
= strtoul(arg
, &end
, 10);
840 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
847 /* Free route map's compiled `vni' value. */
848 static void route_match_vni_free(void *rule
)
850 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
853 /* Route map commands for vni matching. */
854 struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
855 "evpn vni", route_match_vni
, route_match_vni_compile
,
856 route_match_vni_free
};
858 /* `match evpn route-type' */
860 /* Match function should return 1 if match is success else return
862 static route_map_result_t
route_match_evpn_route_type(void *rule
,
863 const struct prefix
*pfx
,
864 route_map_object_t type
,
867 uint8_t route_type
= 0;
869 if (type
== RMAP_BGP
) {
870 route_type
= *((uint8_t *)rule
);
872 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
879 /* Route map `route-type' match statement. */
880 static void *route_match_evpn_route_type_compile(const char *arg
)
882 uint8_t *route_type
= NULL
;
884 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
886 if (strncmp(arg
, "ma", 2) == 0)
887 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
888 else if (strncmp(arg
, "mu", 2) == 0)
889 *route_type
= BGP_EVPN_IMET_ROUTE
;
891 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
896 /* Free route map's compiled `route-type' value. */
897 static void route_match_evpn_route_type_free(void *rule
)
899 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
902 /* Route map commands for evpn route-type matching. */
903 struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
904 "evpn route-type", route_match_evpn_route_type
,
905 route_match_evpn_route_type_compile
, route_match_evpn_route_type_free
};
907 /* Route map commands for VRF route leak with source vrf matching */
908 static route_map_result_t
909 route_match_vrl_source_vrf(void *rule
, const struct prefix
*prefix
,
910 route_map_object_t type
, void *object
)
912 struct bgp_path_info
*path
;
915 if (type
== RMAP_BGP
) {
917 path
= (struct bgp_path_info
*)object
;
919 if (strncmp(vrf_name
, "n/a", VRF_NAMSIZ
) == 0)
922 if (path
->extra
== NULL
)
925 if (strncmp(vrf_name
, vrf_id_to_name(
926 path
->extra
->bgp_orig
->vrf_id
), VRF_NAMSIZ
)
934 static void *route_match_vrl_source_vrf_compile(const char *arg
)
936 uint8_t *vrf_name
= NULL
;
938 vrf_name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
943 /* Free route map's compiled `route-type' value. */
944 static void route_match_vrl_source_vrf_free(void *rule
)
946 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
949 struct route_map_rule_cmd route_match_vrl_source_vrf_cmd
= {
950 "source-vrf", route_match_vrl_source_vrf
,
951 route_match_vrl_source_vrf_compile
,
952 route_match_vrl_source_vrf_free
};
954 /* `match local-preference LOCAL-PREF' */
956 /* Match function return 1 if match is success else return zero. */
957 static route_map_result_t
route_match_local_pref(void *rule
,
958 const struct prefix
*prefix
,
959 route_map_object_t type
,
962 uint32_t *local_pref
;
963 struct bgp_path_info
*path
;
965 if (type
== RMAP_BGP
) {
969 if (path
->attr
->local_pref
== *local_pref
)
977 /* Route map `match local-preference' match statement.
978 `arg' is local-pref value */
979 static void *route_match_local_pref_compile(const char *arg
)
981 uint32_t *local_pref
;
983 unsigned long tmpval
;
985 /* Locpref value shoud be integer. */
990 tmpval
= strtoul(arg
, &endptr
, 10);
991 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
994 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
996 *local_pref
= tmpval
;
1000 /* Free route map's compiled `match local-preference' value. */
1001 static void route_match_local_pref_free(void *rule
)
1003 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1006 /* Route map commands for metric matching. */
1007 struct route_map_rule_cmd route_match_local_pref_cmd
= {
1008 "local-preference", route_match_local_pref
,
1009 route_match_local_pref_compile
, route_match_local_pref_free
};
1011 /* `match metric METRIC' */
1013 /* Match function return 1 if match is success else return zero. */
1014 static route_map_result_t
route_match_metric(void *rule
,
1015 const struct prefix
*prefix
,
1016 route_map_object_t type
,
1019 struct rmap_value
*rv
;
1020 struct bgp_path_info
*path
;
1022 if (type
== RMAP_BGP
) {
1025 return route_value_match(rv
, path
->attr
->med
);
1027 return RMAP_NOMATCH
;
1030 /* Route map commands for metric matching. */
1031 struct route_map_rule_cmd route_match_metric_cmd
= {
1032 "metric", route_match_metric
, route_value_compile
, route_value_free
,
1035 /* `match as-path ASPATH' */
1037 /* Match function for as-path match. I assume given object is */
1038 static route_map_result_t
route_match_aspath(void *rule
,
1039 const struct prefix
*prefix
,
1040 route_map_object_t type
,
1044 struct as_list
*as_list
;
1045 struct bgp_path_info
*path
;
1047 if (type
== RMAP_BGP
) {
1048 as_list
= as_list_lookup((char *)rule
);
1049 if (as_list
== NULL
)
1050 return RMAP_NOMATCH
;
1054 /* Perform match. */
1055 return ((as_list_apply(as_list
, path
->attr
->aspath
)
1060 return RMAP_NOMATCH
;
1063 /* Compile function for as-path match. */
1064 static void *route_match_aspath_compile(const char *arg
)
1066 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1069 /* Compile function for as-path match. */
1070 static void route_match_aspath_free(void *rule
)
1072 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1075 /* Route map commands for aspath matching. */
1076 struct route_map_rule_cmd route_match_aspath_cmd
= {
1077 "as-path", route_match_aspath
, route_match_aspath_compile
,
1078 route_match_aspath_free
};
1080 /* `match community COMMUNIY' */
1081 struct rmap_community
{
1087 /* Match function for community match. */
1088 static route_map_result_t
route_match_community(void *rule
,
1089 const struct prefix
*prefix
,
1090 route_map_object_t type
,
1093 struct community_list
*list
;
1094 struct bgp_path_info
*path
;
1095 struct rmap_community
*rcom
= rule
;
1097 if (type
== RMAP_BGP
) {
1101 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1103 COMMUNITY_LIST_MASTER
);
1105 return RMAP_NOMATCH
;
1108 if (community_list_exact_match(path
->attr
->community
,
1112 if (community_list_match(path
->attr
->community
, list
))
1116 return RMAP_NOMATCH
;
1119 /* Compile function for community match. */
1120 static void *route_match_community_compile(const char *arg
)
1122 struct rmap_community
*rcom
;
1126 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1128 p
= strchr(arg
, ' ');
1131 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1132 memcpy(rcom
->name
, arg
, len
);
1135 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1139 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1143 /* Compile function for community match. */
1144 static void route_match_community_free(void *rule
)
1146 struct rmap_community
*rcom
= rule
;
1148 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1149 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1152 /* Route map commands for community matching. */
1153 struct route_map_rule_cmd route_match_community_cmd
= {
1154 "community", route_match_community
, route_match_community_compile
,
1155 route_match_community_free
};
1157 /* Match function for lcommunity match. */
1158 static route_map_result_t
route_match_lcommunity(void *rule
,
1159 const struct prefix
*prefix
,
1160 route_map_object_t type
,
1163 struct community_list
*list
;
1164 struct bgp_path_info
*path
;
1165 struct rmap_community
*rcom
= rule
;
1167 if (type
== RMAP_BGP
) {
1170 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1172 LARGE_COMMUNITY_LIST_MASTER
);
1174 return RMAP_NOMATCH
;
1176 if (lcommunity_list_match(path
->attr
->lcommunity
, list
))
1179 return RMAP_NOMATCH
;
1182 /* Compile function for community match. */
1183 static void *route_match_lcommunity_compile(const char *arg
)
1185 struct rmap_community
*rcom
;
1189 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1191 p
= strchr(arg
, ' ');
1194 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1195 memcpy(rcom
->name
, arg
, len
);
1197 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1201 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1205 /* Compile function for community match. */
1206 static void route_match_lcommunity_free(void *rule
)
1208 struct rmap_community
*rcom
= rule
;
1210 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1211 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1214 /* Route map commands for community matching. */
1215 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1216 "large-community", route_match_lcommunity
,
1217 route_match_lcommunity_compile
, route_match_lcommunity_free
};
1220 /* Match function for extcommunity match. */
1221 static route_map_result_t
route_match_ecommunity(void *rule
,
1222 const struct prefix
*prefix
,
1223 route_map_object_t type
,
1226 struct community_list
*list
;
1227 struct bgp_path_info
*path
;
1228 struct rmap_community
*rcom
= rule
;
1230 if (type
== RMAP_BGP
) {
1233 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1235 EXTCOMMUNITY_LIST_MASTER
);
1237 return RMAP_NOMATCH
;
1239 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1242 return RMAP_NOMATCH
;
1245 /* Compile function for extcommunity match. */
1246 static void *route_match_ecommunity_compile(const char *arg
)
1248 struct rmap_community
*rcom
;
1250 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1251 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1252 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1257 /* Compile function for extcommunity match. */
1258 static void route_match_ecommunity_free(void *rule
)
1260 struct rmap_community
*rcom
= rule
;
1262 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1263 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1266 /* Route map commands for community matching. */
1267 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1268 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1269 route_match_ecommunity_free
};
1271 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1272 and `address-family vpnv4'. */
1274 /* `match origin' */
1275 static route_map_result_t
route_match_origin(void *rule
,
1276 const struct prefix
*prefix
,
1277 route_map_object_t type
,
1281 struct bgp_path_info
*path
;
1283 if (type
== RMAP_BGP
) {
1287 if (path
->attr
->origin
== *origin
)
1291 return RMAP_NOMATCH
;
1294 static void *route_match_origin_compile(const char *arg
)
1298 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1300 if (strcmp(arg
, "igp") == 0)
1302 else if (strcmp(arg
, "egp") == 0)
1310 /* Free route map's compiled `ip address' value. */
1311 static void route_match_origin_free(void *rule
)
1313 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1316 /* Route map commands for origin matching. */
1317 struct route_map_rule_cmd route_match_origin_cmd
= {
1318 "origin", route_match_origin
, route_match_origin_compile
,
1319 route_match_origin_free
};
1321 /* match probability { */
1323 static route_map_result_t
route_match_probability(void *rule
,
1324 const struct prefix
*prefix
,
1325 route_map_object_t type
,
1330 switch (*(long *)rule
) {
1336 if (r
< *(long *)rule
) {
1341 return RMAP_NOMATCH
;
1344 static void *route_match_probability_compile(const char *arg
)
1350 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1360 *lobule
= RAND_MAX
/ 100 * perc
;
1366 static void route_match_probability_free(void *rule
)
1368 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1371 struct route_map_rule_cmd route_match_probability_cmd
= {
1372 "probability", route_match_probability
, route_match_probability_compile
,
1373 route_match_probability_free
};
1375 /* `match interface IFNAME' */
1376 /* Match function should return 1 if match is success else return
1378 static route_map_result_t
route_match_interface(void *rule
,
1379 const struct prefix
*prefix
,
1380 route_map_object_t type
,
1383 struct interface
*ifp
;
1384 struct bgp_path_info
*path
;
1386 if (type
== RMAP_BGP
) {
1389 if (!path
|| !path
->attr
)
1390 return RMAP_NOMATCH
;
1392 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1394 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1395 return RMAP_NOMATCH
;
1399 return RMAP_NOMATCH
;
1402 /* Route map `interface' match statement. `arg' should be
1404 static void *route_match_interface_compile(const char *arg
)
1406 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1409 /* Free route map's compiled `interface' value. */
1410 static void route_match_interface_free(void *rule
)
1412 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1415 /* Route map commands for ip address matching. */
1416 struct route_map_rule_cmd route_match_interface_cmd
= {
1417 "interface", route_match_interface
, route_match_interface_compile
,
1418 route_match_interface_free
};
1422 /* `set ip next-hop IP_ADDRESS' */
1424 /* Match function return 1 if match is success else return zero. */
1425 static route_map_result_t
route_match_tag(void *rule
,
1426 const struct prefix
*prefix
,
1427 route_map_object_t type
, void *object
)
1430 struct bgp_path_info
*path
;
1432 if (type
== RMAP_BGP
) {
1436 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1439 return RMAP_NOMATCH
;
1443 /* Route map commands for tag matching. */
1444 static struct route_map_rule_cmd route_match_tag_cmd
= {
1445 "tag", route_match_tag
, route_map_rule_tag_compile
,
1446 route_map_rule_tag_free
,
1450 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1451 struct rmap_ip_nexthop_set
{
1452 struct in_addr
*address
;
1457 static route_map_result_t
route_set_ip_nexthop(void *rule
,
1458 const struct prefix
*prefix
,
1459 route_map_object_t type
,
1462 struct rmap_ip_nexthop_set
*rins
= rule
;
1463 struct bgp_path_info
*path
;
1466 if (type
!= RMAP_BGP
)
1469 if (prefix
->family
== AF_INET6
)
1475 if (rins
->unchanged
) {
1476 SET_FLAG(path
->attr
->rmap_change_flags
,
1477 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1478 } else if (rins
->peer_address
) {
1479 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1480 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1482 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1483 path
->attr
->nexthop
.s_addr
=
1484 sockunion2ip(peer
->su_remote
);
1485 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1486 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1487 /* The next hop value will be set as part of
1488 * packet rewrite. Set the flags here to indicate
1489 * that rewrite needs to be done.
1490 * Also, clear the value.
1492 SET_FLAG(path
->attr
->rmap_change_flags
,
1493 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1494 path
->attr
->nexthop
.s_addr
= 0;
1497 /* Set next hop value. */
1498 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1499 path
->attr
->nexthop
= *rins
->address
;
1500 SET_FLAG(path
->attr
->rmap_change_flags
,
1501 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1502 /* case for MP-BGP : MPLS VPN */
1503 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1504 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1510 /* Route map `ip nexthop' compile function. Given string is converted
1511 to struct in_addr structure. */
1512 static void *route_set_ip_nexthop_compile(const char *arg
)
1514 struct rmap_ip_nexthop_set
*rins
;
1515 struct in_addr
*address
= NULL
;
1516 int peer_address
= 0;
1520 if (strcmp(arg
, "peer-address") == 0)
1522 else if (strcmp(arg
, "unchanged") == 0)
1525 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1526 sizeof(struct in_addr
));
1527 ret
= inet_aton(arg
, address
);
1530 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1535 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1536 sizeof(struct rmap_ip_nexthop_set
));
1538 rins
->address
= address
;
1539 rins
->peer_address
= peer_address
;
1540 rins
->unchanged
= unchanged
;
1545 /* Free route map's compiled `ip nexthop' value. */
1546 static void route_set_ip_nexthop_free(void *rule
)
1548 struct rmap_ip_nexthop_set
*rins
= rule
;
1550 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1552 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1555 /* Route map commands for ip nexthop set. */
1556 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1557 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1558 route_set_ip_nexthop_free
};
1560 /* `set local-preference LOCAL_PREF' */
1562 /* Set local preference. */
1563 static route_map_result_t
route_set_local_pref(void *rule
,
1564 const struct prefix
*prefix
,
1565 route_map_object_t type
,
1568 struct rmap_value
*rv
;
1569 struct bgp_path_info
*path
;
1570 uint32_t locpref
= 0;
1572 if (type
== RMAP_BGP
) {
1573 /* Fetch routemap's rule information. */
1577 /* Set local preference value. */
1578 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1579 locpref
= path
->attr
->local_pref
;
1581 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1582 path
->attr
->local_pref
=
1583 route_value_adjust(rv
, locpref
, path
->peer
);
1589 /* Set local preference rule structure. */
1590 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1591 "local-preference", route_set_local_pref
, route_value_compile
,
1595 /* `set weight WEIGHT' */
1598 static route_map_result_t
route_set_weight(void *rule
,
1599 const struct prefix
*prefix
,
1600 route_map_object_t type
,
1603 struct rmap_value
*rv
;
1604 struct bgp_path_info
*path
;
1606 if (type
== RMAP_BGP
) {
1607 /* Fetch routemap's rule information. */
1611 /* Set weight value. */
1612 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1618 /* Set local preference rule structure. */
1619 struct route_map_rule_cmd route_set_weight_cmd
= {
1620 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1623 /* `set metric METRIC' */
1625 /* Set metric to attribute. */
1626 static route_map_result_t
route_set_metric(void *rule
,
1627 const struct prefix
*prefix
,
1628 route_map_object_t type
,
1631 struct rmap_value
*rv
;
1632 struct bgp_path_info
*path
;
1635 if (type
== RMAP_BGP
) {
1636 /* Fetch routemap's rule information. */
1640 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1641 med
= path
->attr
->med
;
1643 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1644 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1649 /* Set metric rule structure. */
1650 struct route_map_rule_cmd route_set_metric_cmd
= {
1651 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1654 /* `set as-path prepend ASPATH' */
1656 /* For AS path prepend mechanism. */
1657 static route_map_result_t
route_set_aspath_prepend(void *rule
,
1658 const struct prefix
*prefix
,
1659 route_map_object_t type
,
1662 struct aspath
*aspath
;
1664 struct bgp_path_info
*path
;
1666 if (type
== RMAP_BGP
) {
1669 if (path
->attr
->aspath
->refcnt
)
1670 new = aspath_dup(path
->attr
->aspath
);
1672 new = path
->attr
->aspath
;
1674 if ((uintptr_t)rule
> 10) {
1676 aspath_prepend(aspath
, new);
1678 as_t as
= aspath_leftmost(new);
1680 as
= path
->peer
->as
;
1681 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1684 path
->attr
->aspath
= new;
1690 static void *route_set_aspath_prepend_compile(const char *arg
)
1694 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1695 return (void *)(uintptr_t)num
;
1697 return route_aspath_compile(arg
);
1700 static void route_set_aspath_prepend_free(void *rule
)
1702 if ((uintptr_t)rule
> 10)
1703 route_aspath_free(rule
);
1707 /* Set as-path prepend rule structure. */
1708 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1709 "as-path prepend", route_set_aspath_prepend
,
1710 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1713 /* `set as-path exclude ASn' */
1715 /* For ASN exclude mechanism.
1716 * Iterate over ASns requested and filter them from the given AS_PATH one by
1718 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1720 static route_map_result_t
route_set_aspath_exclude(void *rule
,
1721 const struct prefix
*dummy
,
1722 route_map_object_t type
,
1725 struct aspath
*new_path
, *exclude_path
;
1726 struct bgp_path_info
*path
;
1728 if (type
== RMAP_BGP
) {
1729 exclude_path
= rule
;
1731 if (path
->attr
->aspath
->refcnt
)
1732 new_path
= aspath_dup(path
->attr
->aspath
);
1734 new_path
= path
->attr
->aspath
;
1735 path
->attr
->aspath
=
1736 aspath_filter_exclude(new_path
, exclude_path
);
1741 /* Set ASn exlude rule structure. */
1742 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1743 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1747 /* `set community COMMUNITY' */
1748 struct rmap_com_set
{
1749 struct community
*com
;
1754 /* For community set mechanism. */
1755 static route_map_result_t
route_set_community(void *rule
,
1756 const struct prefix
*prefix
,
1757 route_map_object_t type
,
1760 struct rmap_com_set
*rcs
;
1761 struct bgp_path_info
*path
;
1763 struct community
*new = NULL
;
1764 struct community
*old
;
1765 struct community
*merge
;
1767 if (type
== RMAP_BGP
) {
1771 old
= attr
->community
;
1775 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1776 attr
->community
= NULL
;
1777 /* See the longer comment down below. */
1778 if (old
&& old
->refcnt
== 0)
1779 community_free(&old
);
1783 /* "additive" case. */
1784 if (rcs
->additive
&& old
) {
1785 merge
= community_merge(community_dup(old
), rcs
->com
);
1787 new = community_uniq_sort(merge
);
1788 community_free(&merge
);
1790 new = community_dup(rcs
->com
);
1792 /* HACK: if the old community is not intern'd,
1793 * we should free it here, or all reference to it may be
1795 * Really need to cleanup attribute caching sometime.
1797 if (old
&& old
->refcnt
== 0)
1798 community_free(&old
);
1800 /* will be interned by caller if required */
1801 attr
->community
= new;
1803 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1809 /* Compile function for set community. */
1810 static void *route_set_community_compile(const char *arg
)
1812 struct rmap_com_set
*rcs
;
1813 struct community
*com
= NULL
;
1818 if (strcmp(arg
, "none") == 0)
1821 sp
= strstr(arg
, "additive");
1823 if (sp
&& sp
> arg
) {
1824 /* "additive" keyword is included. */
1829 com
= community_str2com(arg
);
1838 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1840 rcs
->additive
= additive
;
1846 /* Free function for set community. */
1847 static void route_set_community_free(void *rule
)
1849 struct rmap_com_set
*rcs
= rule
;
1852 community_free(&rcs
->com
);
1853 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1856 /* Set community rule structure. */
1857 struct route_map_rule_cmd route_set_community_cmd
= {
1858 "community", route_set_community
, route_set_community_compile
,
1859 route_set_community_free
,
1862 /* `set community COMMUNITY' */
1863 struct rmap_lcom_set
{
1864 struct lcommunity
*lcom
;
1870 /* For lcommunity set mechanism. */
1871 static route_map_result_t
route_set_lcommunity(void *rule
,
1872 const struct prefix
*prefix
,
1873 route_map_object_t type
,
1876 struct rmap_lcom_set
*rcs
;
1877 struct bgp_path_info
*path
;
1879 struct lcommunity
*new = NULL
;
1880 struct lcommunity
*old
;
1881 struct lcommunity
*merge
;
1883 if (type
== RMAP_BGP
) {
1887 old
= attr
->lcommunity
;
1892 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
1893 attr
->lcommunity
= NULL
;
1895 /* See the longer comment down below. */
1896 if (old
&& old
->refcnt
== 0)
1897 lcommunity_free(&old
);
1901 if (rcs
->additive
&& old
) {
1902 merge
= lcommunity_merge(lcommunity_dup(old
),
1905 new = lcommunity_uniq_sort(merge
);
1906 lcommunity_free(&merge
);
1908 new = lcommunity_dup(rcs
->lcom
);
1910 /* HACK: if the old large-community is not intern'd,
1911 * we should free it here, or all reference to it may be
1913 * Really need to cleanup attribute caching sometime.
1915 if (old
&& old
->refcnt
== 0)
1916 lcommunity_free(&old
);
1918 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1919 attr
->lcommunity
= new;
1921 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
1927 /* Compile function for set community. */
1928 static void *route_set_lcommunity_compile(const char *arg
)
1930 struct rmap_lcom_set
*rcs
;
1931 struct lcommunity
*lcom
= NULL
;
1936 if (strcmp(arg
, "none") == 0)
1939 sp
= strstr(arg
, "additive");
1941 if (sp
&& sp
> arg
) {
1942 /* "additive" keyworkd is included. */
1947 lcom
= lcommunity_str2com(arg
);
1956 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1958 rcs
->additive
= additive
;
1964 /* Free function for set lcommunity. */
1965 static void route_set_lcommunity_free(void *rule
)
1967 struct rmap_lcom_set
*rcs
= rule
;
1970 lcommunity_free(&rcs
->lcom
);
1972 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1975 /* Set community rule structure. */
1976 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
1977 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
1978 route_set_lcommunity_free
,
1981 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
1983 /* For large community set mechanism. */
1984 static route_map_result_t
route_set_lcommunity_delete(void *rule
,
1985 const struct prefix
*pfx
,
1986 route_map_object_t type
,
1989 struct community_list
*list
;
1990 struct lcommunity
*merge
;
1991 struct lcommunity
*new;
1992 struct lcommunity
*old
;
1993 struct bgp_path_info
*path
;
1994 struct rmap_community
*rcom
= rule
;
1996 if (type
== RMAP_BGP
) {
2001 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2003 LARGE_COMMUNITY_LIST_MASTER
);
2004 old
= path
->attr
->lcommunity
;
2007 merge
= lcommunity_list_match_delete(
2008 lcommunity_dup(old
), list
);
2009 new = lcommunity_uniq_sort(merge
);
2010 lcommunity_free(&merge
);
2012 /* HACK: if the old community is not intern'd,
2013 * we should free it here, or all reference to it may be
2015 * Really need to cleanup attribute caching sometime.
2017 if (old
->refcnt
== 0)
2018 lcommunity_free(&old
);
2020 if (new->size
== 0) {
2021 path
->attr
->lcommunity
= NULL
;
2022 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2023 BGP_ATTR_LARGE_COMMUNITIES
);
2024 lcommunity_free(&new);
2026 path
->attr
->lcommunity
= new;
2027 path
->attr
->flag
|= ATTR_FLAG_BIT(
2028 BGP_ATTR_LARGE_COMMUNITIES
);
2036 /* Compile function for set lcommunity. */
2037 static void *route_set_lcommunity_delete_compile(const char *arg
)
2039 struct rmap_community
*rcom
;
2043 frrstr_split(arg
, " ", &splits
, &num
);
2045 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2046 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2047 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2049 for (int i
= 0; i
< num
; i
++)
2050 XFREE(MTYPE_TMP
, splits
[i
]);
2051 XFREE(MTYPE_TMP
, splits
);
2056 /* Free function for set lcommunity. */
2057 static void route_set_lcommunity_delete_free(void *rule
)
2059 struct rmap_community
*rcom
= rule
;
2061 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2062 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2065 /* Set lcommunity rule structure. */
2066 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2067 "large-comm-list", route_set_lcommunity_delete
,
2068 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2072 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2074 /* For community set mechanism. */
2075 static route_map_result_t
route_set_community_delete(
2077 const struct prefix
*prefix
,
2078 route_map_object_t type
,
2081 struct community_list
*list
;
2082 struct community
*merge
;
2083 struct community
*new;
2084 struct community
*old
;
2085 struct bgp_path_info
*path
;
2086 struct rmap_community
*rcom
= rule
;
2088 if (type
== RMAP_BGP
) {
2093 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2095 COMMUNITY_LIST_MASTER
);
2096 old
= path
->attr
->community
;
2099 merge
= community_list_match_delete(community_dup(old
),
2101 new = community_uniq_sort(merge
);
2102 community_free(&merge
);
2104 /* HACK: if the old community is not intern'd,
2105 * we should free it here, or all reference to it may be
2107 * Really need to cleanup attribute caching sometime.
2109 if (old
->refcnt
== 0)
2110 community_free(&old
);
2112 if (new->size
== 0) {
2113 path
->attr
->community
= NULL
;
2115 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2116 community_free(&new);
2118 path
->attr
->community
= new;
2120 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2128 /* Compile function for set community. */
2129 static void *route_set_community_delete_compile(const char *arg
)
2131 struct rmap_community
*rcom
;
2135 frrstr_split(arg
, " ", &splits
, &num
);
2137 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2138 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, splits
[0]);
2139 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2141 for (int i
= 0; i
< num
; i
++)
2142 XFREE(MTYPE_TMP
, splits
[i
]);
2143 XFREE(MTYPE_TMP
, splits
);
2148 /* Free function for set community. */
2149 static void route_set_community_delete_free(void *rule
)
2151 struct rmap_community
*rcom
= rule
;
2153 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2154 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2157 /* Set community rule structure. */
2158 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2159 "comm-list", route_set_community_delete
,
2160 route_set_community_delete_compile
, route_set_community_delete_free
,
2163 /* `set extcommunity rt COMMUNITY' */
2165 /* For community set mechanism. Used by _rt and _soo. */
2166 static route_map_result_t
route_set_ecommunity(void *rule
,
2167 const struct prefix
*prefix
,
2168 route_map_object_t type
,
2171 struct ecommunity
*ecom
;
2172 struct ecommunity
*new_ecom
;
2173 struct ecommunity
*old_ecom
;
2174 struct bgp_path_info
*path
;
2176 if (type
== RMAP_BGP
) {
2183 /* We assume additive for Extended Community. */
2184 old_ecom
= path
->attr
->ecommunity
;
2187 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2190 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2191 * bgp_update_receive()
2192 * ->refcnt = 0 => set by a previous route-map
2194 if (!old_ecom
->refcnt
)
2195 ecommunity_free(&old_ecom
);
2197 new_ecom
= ecommunity_dup(ecom
);
2199 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2200 path
->attr
->ecommunity
= new_ecom
;
2202 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2207 /* Compile function for set community. */
2208 static void *route_set_ecommunity_rt_compile(const char *arg
)
2210 struct ecommunity
*ecom
;
2212 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2215 return ecommunity_intern(ecom
);
2218 /* Free function for set community. Used by _rt and _soo */
2219 static void route_set_ecommunity_free(void *rule
)
2221 struct ecommunity
*ecom
= rule
;
2222 ecommunity_unintern(&ecom
);
2225 /* Set community rule structure. */
2226 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2227 "extcommunity rt", route_set_ecommunity
,
2228 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2231 /* `set extcommunity soo COMMUNITY' */
2233 /* Compile function for set community. */
2234 static void *route_set_ecommunity_soo_compile(const char *arg
)
2236 struct ecommunity
*ecom
;
2238 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2242 return ecommunity_intern(ecom
);
2245 /* Set community rule structure. */
2246 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2247 "extcommunity soo", route_set_ecommunity
,
2248 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2251 /* `set origin ORIGIN' */
2253 /* For origin set. */
2254 static route_map_result_t
route_set_origin(void *rule
,
2255 const struct prefix
*prefix
,
2256 route_map_object_t type
,
2260 struct bgp_path_info
*path
;
2262 if (type
== RMAP_BGP
) {
2266 path
->attr
->origin
= *origin
;
2272 /* Compile function for origin set. */
2273 static void *route_set_origin_compile(const char *arg
)
2277 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2279 if (strcmp(arg
, "igp") == 0)
2281 else if (strcmp(arg
, "egp") == 0)
2289 /* Compile function for origin set. */
2290 static void route_set_origin_free(void *rule
)
2292 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2295 /* Set origin rule structure. */
2296 struct route_map_rule_cmd route_set_origin_cmd
= {
2297 "origin", route_set_origin
, route_set_origin_compile
,
2298 route_set_origin_free
,
2301 /* `set atomic-aggregate' */
2303 /* For atomic aggregate set. */
2304 static route_map_result_t
route_set_atomic_aggregate(void *rule
,
2305 const struct prefix
*pfx
,
2306 route_map_object_t type
,
2309 struct bgp_path_info
*path
;
2311 if (type
== RMAP_BGP
) {
2313 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2319 /* Compile function for atomic aggregate. */
2320 static void *route_set_atomic_aggregate_compile(const char *arg
)
2325 /* Compile function for atomic aggregate. */
2326 static void route_set_atomic_aggregate_free(void *rule
)
2331 /* Set atomic aggregate rule structure. */
2332 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2333 "atomic-aggregate", route_set_atomic_aggregate
,
2334 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2337 /* `set aggregator as AS A.B.C.D' */
2340 struct in_addr address
;
2343 static route_map_result_t
route_set_aggregator_as(void *rule
,
2344 const struct prefix
*prefix
,
2345 route_map_object_t type
,
2348 struct bgp_path_info
*path
;
2349 struct aggregator
*aggregator
;
2351 if (type
== RMAP_BGP
) {
2355 path
->attr
->aggregator_as
= aggregator
->as
;
2356 path
->attr
->aggregator_addr
= aggregator
->address
;
2357 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2363 static void *route_set_aggregator_as_compile(const char *arg
)
2365 struct aggregator
*aggregator
;
2371 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2372 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2373 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2377 aggregator
->as
= strtoul(as
, NULL
, 10);
2378 ret
= inet_aton(address
, &aggregator
->address
);
2380 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2386 static void route_set_aggregator_as_free(void *rule
)
2388 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2391 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2392 "aggregator as", route_set_aggregator_as
,
2393 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2396 /* Set tag to object. object must be pointer to struct bgp_path_info */
2397 static route_map_result_t
route_set_tag(void *rule
,
2398 const struct prefix
*prefix
,
2399 route_map_object_t type
, void *object
)
2402 struct bgp_path_info
*path
;
2404 if (type
== RMAP_BGP
) {
2409 path
->attr
->tag
= *tag
;
2415 /* Route map commands for tag set. */
2416 static struct route_map_rule_cmd route_set_tag_cmd
= {
2417 "tag", route_set_tag
, route_map_rule_tag_compile
,
2418 route_map_rule_tag_free
,
2421 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2422 static route_map_result_t
route_set_label_index(void *rule
,
2423 const struct prefix
*prefix
,
2424 route_map_object_t type
,
2427 struct rmap_value
*rv
;
2428 struct bgp_path_info
*path
;
2429 uint32_t label_index
;
2431 if (type
== RMAP_BGP
) {
2432 /* Fetch routemap's rule information. */
2436 /* Set label-index value. */
2437 label_index
= rv
->value
;
2439 path
->attr
->label_index
= label_index
;
2440 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2447 /* Route map commands for label-index set. */
2448 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2449 "label-index", route_set_label_index
, route_value_compile
,
2453 /* `match ipv6 address IP_ACCESS_LIST' */
2455 static route_map_result_t
route_match_ipv6_address(void *rule
,
2456 const struct prefix
*prefix
,
2457 route_map_object_t type
,
2460 struct access_list
*alist
;
2462 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2463 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2465 return RMAP_NOMATCH
;
2467 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2471 return RMAP_NOMATCH
;
2474 static void *route_match_ipv6_address_compile(const char *arg
)
2476 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2479 static void route_match_ipv6_address_free(void *rule
)
2481 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2484 /* Route map commands for ip address matching. */
2485 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2486 "ipv6 address", route_match_ipv6_address
,
2487 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2489 /* `match ipv6 next-hop IP_ADDRESS' */
2491 static route_map_result_t
route_match_ipv6_next_hop(void *rule
,
2492 const struct prefix
*prefix
,
2493 route_map_object_t type
,
2496 struct in6_addr
*addr
= rule
;
2497 struct bgp_path_info
*path
;
2499 if (type
== RMAP_BGP
) {
2502 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2505 if (path
->attr
->mp_nexthop_len
2506 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2507 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2510 return RMAP_NOMATCH
;
2513 return RMAP_NOMATCH
;
2516 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2518 struct in6_addr
*address
;
2521 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2523 ret
= inet_pton(AF_INET6
, arg
, address
);
2525 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2532 static void route_match_ipv6_next_hop_free(void *rule
)
2534 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2537 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2538 "ipv6 next-hop", route_match_ipv6_next_hop
,
2539 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2541 /* `match ipv6 address prefix-list PREFIX_LIST' */
2543 static route_map_result_t
2544 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2545 route_map_object_t type
, void *object
)
2547 struct prefix_list
*plist
;
2549 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2550 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
2552 return RMAP_NOMATCH
;
2554 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
2558 return RMAP_NOMATCH
;
2561 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2563 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2566 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2568 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2571 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2572 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2573 route_match_ipv6_address_prefix_list_compile
,
2574 route_match_ipv6_address_prefix_list_free
};
2576 /* `match ipv6 next-hop type <TYPE>' */
2578 static route_map_result_t
2579 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2580 route_map_object_t type
, void *object
)
2582 struct bgp_path_info
*path
;
2583 struct in6_addr
*addr
= rule
;
2585 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2586 path
= (struct bgp_path_info
*)object
;
2587 if (!path
|| !path
->attr
)
2588 return RMAP_DENYMATCH
;
2590 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2591 && !path
->attr
->nh_ifindex
)
2594 return RMAP_NOMATCH
;
2597 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2599 struct in6_addr
*address
;
2602 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2604 ret
= inet_pton(AF_INET6
, "::0", address
);
2606 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2613 static void route_match_ipv6_next_hop_type_free(void *rule
)
2615 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2618 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2619 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2620 route_match_ipv6_next_hop_type_compile
,
2621 route_match_ipv6_next_hop_type_free
};
2623 /* `set ipv6 nexthop global IP_ADDRESS' */
2625 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2626 static route_map_result_t
route_set_ipv6_nexthop_global(void *rule
,
2627 const struct prefix
*p
,
2628 route_map_object_t type
,
2631 struct in6_addr
*address
;
2632 struct bgp_path_info
*path
;
2634 if (type
== RMAP_BGP
) {
2635 /* Fetch routemap's rule information. */
2639 /* Set next hop value. */
2640 path
->attr
->mp_nexthop_global
= *address
;
2642 /* Set nexthop length. */
2643 if (path
->attr
->mp_nexthop_len
== 0)
2644 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2646 SET_FLAG(path
->attr
->rmap_change_flags
,
2647 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2653 /* Route map `ip next-hop' compile function. Given string is converted
2654 to struct in_addr structure. */
2655 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2658 struct in6_addr
*address
;
2660 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2662 ret
= inet_pton(AF_INET6
, arg
, address
);
2665 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2672 /* Free route map's compiled `ip next-hop' value. */
2673 static void route_set_ipv6_nexthop_global_free(void *rule
)
2675 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2678 /* Route map commands for ip nexthop set. */
2679 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2680 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2681 route_set_ipv6_nexthop_global_compile
,
2682 route_set_ipv6_nexthop_global_free
};
2684 /* Set next-hop preference value. */
2685 static route_map_result_t
2686 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2687 route_map_object_t type
, void *object
)
2689 struct bgp_path_info
*path
;
2692 if (type
== RMAP_BGP
) {
2693 /* Fetch routemap's rule information. */
2697 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2698 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2700 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2701 /* Set next hop preference to global */
2702 path
->attr
->mp_nexthop_prefer_global
= true;
2703 SET_FLAG(path
->attr
->rmap_change_flags
,
2704 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2706 path
->attr
->mp_nexthop_prefer_global
= false;
2707 SET_FLAG(path
->attr
->rmap_change_flags
,
2708 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2714 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2718 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2724 /* Free route map's compiled `ip next-hop' value. */
2725 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2727 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2730 /* Route map commands for ip nexthop set preferred. */
2731 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2732 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2733 route_set_ipv6_nexthop_prefer_global_compile
,
2734 route_set_ipv6_nexthop_prefer_global_free
};
2736 /* `set ipv6 nexthop local IP_ADDRESS' */
2738 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2739 static route_map_result_t
route_set_ipv6_nexthop_local(void *rule
,
2740 const struct prefix
*p
,
2741 route_map_object_t type
,
2744 struct in6_addr
*address
;
2745 struct bgp_path_info
*path
;
2747 if (type
== RMAP_BGP
) {
2748 /* Fetch routemap's rule information. */
2752 /* Set next hop value. */
2753 path
->attr
->mp_nexthop_local
= *address
;
2755 /* Set nexthop length. */
2756 if (path
->attr
->mp_nexthop_len
2757 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2758 path
->attr
->mp_nexthop_len
=
2759 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2761 SET_FLAG(path
->attr
->rmap_change_flags
,
2762 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2768 /* Route map `ip nexthop' compile function. Given string is converted
2769 to struct in_addr structure. */
2770 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2773 struct in6_addr
*address
;
2775 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2777 ret
= inet_pton(AF_INET6
, arg
, address
);
2780 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2787 /* Free route map's compiled `ip nexthop' value. */
2788 static void route_set_ipv6_nexthop_local_free(void *rule
)
2790 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2793 /* Route map commands for ip nexthop set. */
2794 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2795 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2796 route_set_ipv6_nexthop_local_compile
,
2797 route_set_ipv6_nexthop_local_free
};
2799 /* `set ipv6 nexthop peer-address' */
2801 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2802 static route_map_result_t
route_set_ipv6_nexthop_peer(void *rule
,
2803 const struct prefix
*pfx
,
2804 route_map_object_t type
,
2807 struct in6_addr peer_address
;
2808 struct bgp_path_info
*path
;
2811 if (type
== RMAP_BGP
) {
2812 /* Fetch routemap's rule information. */
2816 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2817 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2819 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2820 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2821 /* Set next hop value and length in attribute. */
2822 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2823 path
->attr
->mp_nexthop_local
= peer_address
;
2824 if (path
->attr
->mp_nexthop_len
!= 32)
2825 path
->attr
->mp_nexthop_len
= 32;
2827 path
->attr
->mp_nexthop_global
= peer_address
;
2828 if (path
->attr
->mp_nexthop_len
== 0)
2829 path
->attr
->mp_nexthop_len
= 16;
2832 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2833 /* The next hop value will be set as part of packet
2835 * Set the flags here to indicate that rewrite needs to
2837 * Also, clear the value - we clear both global and
2839 * nexthops, whether we send one or both is determined
2842 SET_FLAG(path
->attr
->rmap_change_flags
,
2843 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2844 /* clear next hop value. */
2845 memset(&(path
->attr
->mp_nexthop_global
), 0,
2846 sizeof(struct in6_addr
));
2847 memset(&(path
->attr
->mp_nexthop_local
), 0,
2848 sizeof(struct in6_addr
));
2855 /* Route map `ip next-hop' compile function. Given string is converted
2856 to struct in_addr structure. */
2857 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2861 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2867 /* Free route map's compiled `ip next-hop' value. */
2868 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2870 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2873 /* Route map commands for ip nexthop set. */
2874 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2875 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2876 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2878 /* `set ipv4 vpn next-hop A.B.C.D' */
2880 static route_map_result_t
route_set_vpnv4_nexthop(void *rule
,
2881 const struct prefix
*prefix
,
2882 route_map_object_t type
,
2885 struct in_addr
*address
;
2886 struct bgp_path_info
*path
;
2888 if (type
== RMAP_BGP
) {
2889 /* Fetch routemap's rule information. */
2893 /* Set next hop value. */
2894 path
->attr
->mp_nexthop_global_in
= *address
;
2895 path
->attr
->mp_nexthop_len
= 4;
2901 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2904 struct in_addr
*address
;
2906 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2908 ret
= inet_aton(arg
, address
);
2911 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2918 /* `set ipv6 vpn next-hop A.B.C.D' */
2920 static route_map_result_t
route_set_vpnv6_nexthop(void *rule
,
2921 const struct prefix
*prefix
,
2922 route_map_object_t type
,
2925 struct in6_addr
*address
;
2926 struct bgp_path_info
*path
;
2928 if (type
== RMAP_BGP
) {
2929 /* Fetch routemap's rule information. */
2933 /* Set next hop value. */
2934 memcpy(&path
->attr
->mp_nexthop_global
, address
,
2935 sizeof(struct in6_addr
));
2936 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2942 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2945 struct in6_addr
*address
;
2947 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2948 ret
= inet_pton(AF_INET6
, arg
, address
);
2951 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2958 static void route_set_vpn_nexthop_free(void *rule
)
2960 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2963 /* Route map commands for ipv4 next-hop set. */
2964 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2965 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2966 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
2968 /* Route map commands for ipv6 next-hop set. */
2969 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
2970 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
2971 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
2973 /* `set originator-id' */
2975 /* For origin set. */
2976 static route_map_result_t
route_set_originator_id(void *rule
,
2977 const struct prefix
*prefix
,
2978 route_map_object_t type
,
2981 struct in_addr
*address
;
2982 struct bgp_path_info
*path
;
2984 if (type
== RMAP_BGP
) {
2988 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
2989 path
->attr
->originator_id
= *address
;
2995 /* Compile function for originator-id set. */
2996 static void *route_set_originator_id_compile(const char *arg
)
2999 struct in_addr
*address
;
3001 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
3003 ret
= inet_aton(arg
, address
);
3006 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3013 /* Compile function for originator_id set. */
3014 static void route_set_originator_id_free(void *rule
)
3016 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3019 /* Set originator-id rule structure. */
3020 struct route_map_rule_cmd route_set_originator_id_cmd
= {
3021 "originator-id", route_set_originator_id
,
3022 route_set_originator_id_compile
, route_set_originator_id_free
,
3025 /* Add bgp route map rule. */
3026 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3027 const char *arg
, route_map_event_t type
)
3029 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3030 int retval
= CMD_SUCCESS
;
3033 ret
= route_map_add_match(index
, command
, arg
);
3035 case RMAP_RULE_MISSING
:
3036 vty_out(vty
, "%% BGP Can't find rule.\n");
3037 retval
= CMD_WARNING_CONFIG_FAILED
;
3039 case RMAP_COMPILE_ERROR
:
3040 vty_out(vty
, "%% BGP Argument is malformed.\n");
3041 retval
= CMD_WARNING_CONFIG_FAILED
;
3043 case RMAP_COMPILE_SUCCESS
:
3044 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
3045 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
3053 /* Delete bgp route map rule. */
3054 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3055 const char *arg
, route_map_event_t type
)
3057 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3059 int retval
= CMD_SUCCESS
;
3060 char *dep_name
= NULL
;
3062 char *rmap_name
= NULL
;
3064 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3065 /* ignore the mundane, the types without any dependency */
3067 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3070 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3072 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3074 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3077 ret
= route_map_delete_match(index
, command
, dep_name
);
3079 case RMAP_RULE_MISSING
:
3080 vty_out(vty
, "%% BGP Can't find rule.\n");
3081 retval
= CMD_WARNING_CONFIG_FAILED
;
3083 case RMAP_COMPILE_ERROR
:
3084 vty_out(vty
, "%% BGP Argument is malformed.\n");
3085 retval
= CMD_WARNING_CONFIG_FAILED
;
3087 case RMAP_COMPILE_SUCCESS
:
3088 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
3089 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
3093 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3094 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3100 * This is the workhorse routine for processing in/out routemap
3103 static void bgp_route_map_process_peer(const char *rmap_name
,
3104 struct route_map
*map
, struct peer
*peer
,
3105 int afi
, int safi
, int route_update
)
3109 struct bgp_filter
*filter
;
3111 if (!peer
|| !rmap_name
)
3114 filter
= &peer
->filter
[afi
][safi
];
3116 * in is for non-route-server clients,
3117 * out is for all peers
3119 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
3120 if (filter
->map
[RMAP_IN
].name
3121 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3122 filter
->map
[RMAP_IN
].map
= map
;
3124 if (route_update
&& peer
->status
== Established
) {
3125 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3126 PEER_FLAG_SOFT_RECONFIG
)) {
3127 if (bgp_debug_update(peer
, NULL
, NULL
,
3130 "Processing route_map %s update on "
3131 "peer %s (inbound, soft-reconfig)",
3132 rmap_name
, peer
->host
);
3134 bgp_soft_reconfig_in(peer
, afi
, safi
);
3136 CHECK_FLAG(peer
->cap
,
3137 PEER_CAP_REFRESH_OLD_RCV
)
3140 PEER_CAP_REFRESH_NEW_RCV
)) {
3142 if (bgp_debug_update(peer
, NULL
, NULL
,
3145 "Processing route_map %s update on "
3146 "peer %s (inbound, route-refresh)",
3147 rmap_name
, peer
->host
);
3148 bgp_route_refresh_send(peer
, afi
, safi
,
3155 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
3158 if (update
&& route_update
&& peer
->status
== Established
) {
3159 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3160 PEER_FLAG_SOFT_RECONFIG
)) {
3161 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3163 "Processing route_map %s update on "
3164 "peer %s (import, soft-reconfig)",
3165 rmap_name
, peer
->host
);
3167 bgp_soft_reconfig_in(peer
, afi
, safi
);
3168 } else if (CHECK_FLAG(peer
->cap
,
3169 PEER_CAP_REFRESH_OLD_RCV
)
3170 || CHECK_FLAG(peer
->cap
,
3171 PEER_CAP_REFRESH_NEW_RCV
)) {
3172 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3174 "Processing route_map %s update on "
3175 "peer %s (import, route-refresh)",
3176 rmap_name
, peer
->host
);
3177 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3180 /* DD: Else, what else do we do ? Reset peer ? */
3185 * For outbound, unsuppress and default-originate map change (content or
3186 * map created), merely update the "config" here, the actual route
3187 * announcement happens at the group level.
3189 if (filter
->map
[RMAP_OUT
].name
3190 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3191 filter
->map
[RMAP_OUT
].map
= map
;
3193 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3194 filter
->usmap
.map
= map
;
3196 if (peer
->default_rmap
[afi
][safi
].name
3197 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3198 peer
->default_rmap
[afi
][safi
].map
= map
;
3201 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3202 struct route_map
*map
,
3205 struct peer_group
*group
;
3206 struct listnode
*node
, *nnode
;
3207 struct bgp_filter
*filter
;
3214 /* All the peers have been updated correctly already. This is
3215 * just updating the placeholder data. No real update required.
3217 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3218 FOREACH_AFI_SAFI (afi
, safi
) {
3219 filter
= &group
->conf
->filter
[afi
][safi
];
3221 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3222 if ((filter
->map
[direct
].name
)
3223 && (strcmp(rmap_name
,
3224 filter
->map
[direct
].name
)
3226 filter
->map
[direct
].map
= map
;
3229 if (filter
->usmap
.name
3230 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3231 filter
->usmap
.map
= map
;
3237 * Note that if an extreme number (tens of thousands) of route-maps are in use
3238 * and if bgp has an extreme number of peers, network statements, etc then this
3239 * function can consume a lot of cycles. This is due to this function being
3240 * called for each route-map and within this function we walk the list of peers,
3241 * network statements, etc looking to see if they use this route-map.
3243 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3250 struct bgp_node
*bn
;
3251 struct bgp_static
*bgp_static
;
3252 struct listnode
*node
, *nnode
;
3253 struct route_map
*map
;
3254 char buf
[INET6_ADDRSTRLEN
];
3256 map
= route_map_lookup_by_name(rmap_name
);
3258 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3260 /* Ignore dummy peer-group structure */
3261 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3264 FOREACH_AFI_SAFI (afi
, safi
) {
3265 /* process in/out/import/export/default-orig
3267 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3268 safi
, route_update
);
3272 /* for outbound/default-orig route-maps, process for groups */
3273 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3276 /* update peer-group config (template) */
3277 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3279 FOREACH_AFI_SAFI (afi
, safi
) {
3280 /* For table route-map updates. */
3281 if (!bgp_fibupd_safi(safi
))
3284 if (bgp
->table_map
[afi
][safi
].name
3285 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3288 /* bgp->table_map[afi][safi].map is NULL.
3289 * i.e Route map creation event.
3290 * So update applied_counter.
3291 * If it is not NULL, i.e It may be routemap updation or
3292 * deletion. so no need to update the counter.
3294 if (!bgp
->table_map
[afi
][safi
].map
)
3295 route_map_counter_increment(map
);
3296 bgp
->table_map
[afi
][safi
].map
= map
;
3298 if (BGP_DEBUG(zebra
, ZEBRA
))
3300 "Processing route_map %s update on "
3304 bgp_zebra_announce_table(bgp
, afi
, safi
);
3307 /* For network route-map updates. */
3308 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3309 bn
= bgp_route_next(bn
)) {
3310 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3314 if (!bgp_static
->rmap
.name
3315 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3318 if (!bgp_static
->rmap
.map
)
3319 route_map_counter_increment(map
);
3321 bgp_static
->rmap
.map
= map
;
3323 if (route_update
&& !bgp_static
->backdoor
) {
3324 if (bgp_debug_zebra(&bn
->p
))
3326 "Processing route_map %s update on static route %s",
3328 inet_ntop(bn
->p
.family
,
3329 &bn
->p
.u
.prefix
, buf
,
3331 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3337 /* For redistribute route-map updates. */
3338 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3339 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3340 struct list
*red_list
;
3341 struct bgp_redist
*red
;
3343 red_list
= bgp
->redist
[afi
][i
];
3347 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3349 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3353 route_map_counter_increment(map
);
3355 red
->rmap
.map
= map
;
3360 if (BGP_DEBUG(zebra
, ZEBRA
))
3362 "Processing route_map %s update on redistributed routes",
3365 bgp_redistribute_resend(bgp
, afi
, i
,
3370 /* for type5 command route-maps */
3371 FOREACH_AFI_SAFI (afi
, safi
) {
3372 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3373 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3377 /* Make sure the route-map is populated here if not already done */
3378 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3380 if (BGP_DEBUG(zebra
, ZEBRA
))
3382 "Processing route_map %s update on advertise type5 route command",
3385 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3386 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3387 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3392 static void bgp_route_map_process_update_cb(char *rmap_name
)
3394 struct listnode
*node
, *nnode
;
3397 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3398 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3401 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3402 vnc_routemap_update(bgp
, __func__
);
3406 vpn_policy_routemap_event(rmap_name
);
3409 int bgp_route_map_update_timer(struct thread
*thread
)
3411 bm
->t_rmap_update
= NULL
;
3413 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3418 static void bgp_route_map_mark_update(const char *rmap_name
)
3420 if (bm
->t_rmap_update
== NULL
) {
3421 struct listnode
*node
, *nnode
;
3424 /* rmap_update_timer of 0 means don't do route updates */
3425 if (bm
->rmap_update_timer
) {
3426 bm
->t_rmap_update
= NULL
;
3427 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3428 NULL
, bm
->rmap_update_timer
,
3429 &bm
->t_rmap_update
);
3431 /* Signal the groups that a route-map update event has
3433 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3434 update_group_policy_update(bgp
,
3435 BGP_POLICY_ROUTE_MAP
,
3438 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3439 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3441 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3442 vnc_routemap_update(bgp
, __func__
);
3448 static void bgp_route_map_add(const char *rmap_name
)
3450 if (route_map_mark_updated(rmap_name
) == 0)
3451 bgp_route_map_mark_update(rmap_name
);
3453 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3456 static void bgp_route_map_delete(const char *rmap_name
)
3458 if (route_map_mark_updated(rmap_name
) == 0)
3459 bgp_route_map_mark_update(rmap_name
);
3461 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3464 static void bgp_route_map_event(route_map_event_t event
, const char *rmap_name
)
3466 if (route_map_mark_updated(rmap_name
) == 0)
3467 bgp_route_map_mark_update(rmap_name
);
3469 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3472 DEFUN (match_mac_address
,
3473 match_mac_address_cmd
,
3474 "match mac address WORD",
3477 "Match address of route\n"
3478 "MAC Access-list name\n")
3480 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3481 RMAP_EVENT_FILTER_ADDED
);
3484 DEFUN (no_match_mac_address
,
3485 no_match_mac_address_cmd
,
3486 "no match mac address WORD",
3490 "Match address of route\n"
3491 "MAC acess-list name\n")
3493 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3494 RMAP_EVENT_FILTER_DELETED
);
3497 DEFUN (match_evpn_route_type
,
3498 match_evpn_route_type_cmd
,
3499 "match evpn route-type <macip | multicast | prefix>",
3502 "Match route-type\n"
3507 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3508 RMAP_EVENT_MATCH_ADDED
);
3511 DEFUN (no_match_evpn_route_type
,
3512 no_match_evpn_route_type_cmd
,
3513 "no match evpn route-type <macip | multicast | prefix>",
3517 "Match route-type\n"
3522 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3523 RMAP_EVENT_MATCH_DELETED
);
3527 DEFUN (match_evpn_vni
,
3529 "match evpn vni " CMD_VNI_RANGE
,
3535 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3536 RMAP_EVENT_MATCH_ADDED
);
3539 DEFUN (no_match_evpn_vni
,
3540 no_match_evpn_vni_cmd
,
3541 "no match evpn vni " CMD_VNI_RANGE
,
3548 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3549 RMAP_EVENT_MATCH_DELETED
);
3552 DEFUN (match_evpn_default_route
,
3553 match_evpn_default_route_cmd
,
3554 "match evpn default-route",
3557 "default EVPN type-5 route\n")
3559 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3560 RMAP_EVENT_MATCH_ADDED
);
3563 DEFUN (no_match_evpn_default_route
,
3564 no_match_evpn_default_route_cmd
,
3565 "no match evpn default-route",
3569 "default EVPN type-5 route\n")
3571 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3572 RMAP_EVENT_MATCH_DELETED
);
3575 DEFPY(match_vrl_source_vrf
,
3576 match_vrl_source_vrf_cmd
,
3577 "match source-vrf NAME$vrf_name",
3582 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3583 RMAP_EVENT_MATCH_ADDED
);
3586 DEFPY(no_match_vrl_source_vrf
,
3587 no_match_vrl_source_vrf_cmd
,
3588 "no match source-vrf NAME$vrf_name",
3594 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3595 RMAP_EVENT_MATCH_DELETED
);
3600 "match peer <A.B.C.D|X:X::X:X|WORD>",
3602 "Match peer address\n"
3603 "IP address of peer\n"
3604 "IPv6 address of peer\n"
3605 "Interface name of peer\n")
3608 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3609 RMAP_EVENT_MATCH_ADDED
);
3612 DEFUN (match_peer_local
,
3613 match_peer_local_cmd
,
3616 "Match peer address\n"
3617 "Static or Redistributed routes\n")
3619 return bgp_route_match_add(vty
, "peer", "local",
3620 RMAP_EVENT_MATCH_DELETED
);
3623 DEFUN (no_match_peer
,
3625 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3628 "Match peer address\n"
3629 "Static or Redistributed routes\n"
3630 "IP address of peer\n"
3631 "IPv6 address of peer\n"
3632 "Interface name of peer\n")
3636 if (argc
<= idx_peer
)
3637 return bgp_route_match_delete(vty
, "peer", NULL
,
3638 RMAP_EVENT_MATCH_DELETED
);
3639 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3640 RMAP_EVENT_MATCH_DELETED
);
3643 #if defined(HAVE_LUA)
3644 DEFUN (match_command
,
3646 "match command WORD",
3648 "Run a command to match\n"
3649 "The command to run\n")
3651 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3652 RMAP_EVENT_FILTER_ADDED
);
3655 DEFUN (no_match_command
,
3656 no_match_command_cmd
,
3657 "no match command WORD",
3660 "Run a command to match\n"
3661 "The command to run\n")
3663 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3664 RMAP_EVENT_FILTER_DELETED
);
3668 /* match probability */
3669 DEFUN (match_probability
,
3670 match_probability_cmd
,
3671 "match probability (0-100)",
3673 "Match portion of routes defined by percentage value\n"
3674 "Percentage of routes\n")
3677 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3678 RMAP_EVENT_MATCH_ADDED
);
3682 DEFUN (no_match_probability
,
3683 no_match_probability_cmd
,
3684 "no match probability [(1-99)]",
3687 "Match portion of routes defined by percentage value\n"
3688 "Percentage of routes\n")
3691 if (argc
<= idx_number
)
3692 return bgp_route_match_delete(vty
, "probability", NULL
,
3693 RMAP_EVENT_MATCH_DELETED
);
3694 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3695 RMAP_EVENT_MATCH_DELETED
);
3699 DEFUN (match_ip_route_source
,
3700 match_ip_route_source_cmd
,
3701 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3704 "Match advertising source address of route\n"
3705 "IP access-list number\n"
3706 "IP access-list number (expanded range)\n"
3707 "IP standard access-list name\n")
3710 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3711 RMAP_EVENT_FILTER_ADDED
);
3715 DEFUN (no_match_ip_route_source
,
3716 no_match_ip_route_source_cmd
,
3717 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3721 "Match advertising source address of route\n"
3722 "IP access-list number\n"
3723 "IP access-list number (expanded range)\n"
3724 "IP standard access-list name\n")
3727 if (argc
<= idx_number
)
3728 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3729 RMAP_EVENT_FILTER_DELETED
);
3730 return bgp_route_match_delete(vty
, "ip route-source",
3731 argv
[idx_number
]->arg
,
3732 RMAP_EVENT_FILTER_DELETED
);
3736 DEFUN (match_ip_route_source_prefix_list
,
3737 match_ip_route_source_prefix_list_cmd
,
3738 "match ip route-source prefix-list WORD",
3741 "Match advertising source address of route\n"
3742 "Match entries of prefix-lists\n"
3743 "IP prefix-list name\n")
3746 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3747 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3751 DEFUN (no_match_ip_route_source_prefix_list
,
3752 no_match_ip_route_source_prefix_list_cmd
,
3753 "no match ip route-source prefix-list [WORD]",
3757 "Match advertising source address of route\n"
3758 "Match entries of prefix-lists\n"
3759 "IP prefix-list name\n")
3762 if (argc
<= idx_word
)
3763 return bgp_route_match_delete(vty
,
3764 "ip route-source prefix-list",
3765 NULL
, RMAP_EVENT_PLIST_DELETED
);
3766 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3767 argv
[idx_word
]->arg
,
3768 RMAP_EVENT_PLIST_DELETED
);
3772 DEFUN (match_local_pref
,
3773 match_local_pref_cmd
,
3774 "match local-preference (0-4294967295)",
3776 "Match local-preference of route\n"
3780 return bgp_route_match_add(vty
, "local-preference",
3781 argv
[idx_number
]->arg
,
3782 RMAP_EVENT_MATCH_ADDED
);
3786 DEFUN (no_match_local_pref
,
3787 no_match_local_pref_cmd
,
3788 "no match local-preference [(0-4294967295)]",
3791 "Match local preference of route\n"
3792 "Local preference value\n")
3794 int idx_localpref
= 3;
3795 if (argc
<= idx_localpref
)
3796 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3797 RMAP_EVENT_MATCH_DELETED
);
3798 return bgp_route_match_delete(vty
, "local-preference",
3799 argv
[idx_localpref
]->arg
,
3800 RMAP_EVENT_MATCH_DELETED
);
3804 DEFUN (match_community
,
3805 match_community_cmd
,
3806 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3808 "Match BGP community list\n"
3809 "Community-list number (standard)\n"
3810 "Community-list number (expanded)\n"
3811 "Community-list name\n"
3812 "Do exact matching of communities\n")
3814 int idx_comm_list
= 2;
3819 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3820 strlen(argv
[idx_comm_list
]->arg
)
3821 + strlen("exact-match") + 2);
3823 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3825 argstr
= argv
[idx_comm_list
]->arg
;
3827 ret
= bgp_route_match_add(vty
, "community", argstr
,
3828 RMAP_EVENT_CLIST_ADDED
);
3830 if (argstr
!= argv
[idx_comm_list
]->arg
)
3831 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3836 DEFUN (no_match_community
,
3837 no_match_community_cmd
,
3838 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3841 "Match BGP community list\n"
3842 "Community-list number (standard)\n"
3843 "Community-list number (expanded)\n"
3844 "Community-list name\n"
3845 "Do exact matching of communities\n")
3847 return bgp_route_match_delete(vty
, "community", NULL
,
3848 RMAP_EVENT_CLIST_DELETED
);
3851 DEFUN (match_lcommunity
,
3852 match_lcommunity_cmd
,
3853 "match large-community <(1-99)|(100-500)|WORD>",
3855 "Match BGP large community list\n"
3856 "Large Community-list number (standard)\n"
3857 "Large Community-list number (expanded)\n"
3858 "Large Community-list name\n")
3860 return bgp_route_match_add(vty
, "large-community", argv
[2]->arg
,
3861 RMAP_EVENT_LLIST_ADDED
);
3864 DEFUN (no_match_lcommunity
,
3865 no_match_lcommunity_cmd
,
3866 "no match large-community [<(1-99)|(100-500)|WORD>]",
3869 "Match BGP large community list\n"
3870 "Large Community-list number (standard)\n"
3871 "Large Community-list number (expanded)\n"
3872 "Large Community-list name\n")
3874 return bgp_route_match_delete(vty
, "large-community", NULL
,
3875 RMAP_EVENT_LLIST_DELETED
);
3878 DEFUN (match_ecommunity
,
3879 match_ecommunity_cmd
,
3880 "match extcommunity <(1-99)|(100-500)|WORD>",
3882 "Match BGP/VPN extended community list\n"
3883 "Extended community-list number (standard)\n"
3884 "Extended community-list number (expanded)\n"
3885 "Extended community-list name\n")
3887 int idx_comm_list
= 2;
3888 return bgp_route_match_add(vty
, "extcommunity",
3889 argv
[idx_comm_list
]->arg
,
3890 RMAP_EVENT_ECLIST_ADDED
);
3894 DEFUN (no_match_ecommunity
,
3895 no_match_ecommunity_cmd
,
3896 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3899 "Match BGP/VPN extended community list\n"
3900 "Extended community-list number (standard)\n"
3901 "Extended community-list number (expanded)\n"
3902 "Extended community-list name\n")
3904 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3905 RMAP_EVENT_ECLIST_DELETED
);
3909 DEFUN (match_aspath
,
3911 "match as-path WORD",
3913 "Match BGP AS path list\n"
3914 "AS path access-list name\n")
3917 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3918 RMAP_EVENT_ASLIST_ADDED
);
3922 DEFUN (no_match_aspath
,
3923 no_match_aspath_cmd
,
3924 "no match as-path [WORD]",
3927 "Match BGP AS path list\n"
3928 "AS path access-list name\n")
3930 return bgp_route_match_delete(vty
, "as-path", NULL
,
3931 RMAP_EVENT_ASLIST_DELETED
);
3935 DEFUN (match_origin
,
3937 "match origin <egp|igp|incomplete>",
3942 "unknown heritage\n")
3945 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3946 return bgp_route_match_add(vty
, "origin", "igp",
3947 RMAP_EVENT_MATCH_ADDED
);
3948 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3949 return bgp_route_match_add(vty
, "origin", "egp",
3950 RMAP_EVENT_MATCH_ADDED
);
3951 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3952 return bgp_route_match_add(vty
, "origin", "incomplete",
3953 RMAP_EVENT_MATCH_ADDED
);
3955 vty_out(vty
, "%% Invalid match origin type\n");
3956 return CMD_WARNING_CONFIG_FAILED
;
3960 DEFUN (no_match_origin
,
3961 no_match_origin_cmd
,
3962 "no match origin [<egp|igp|incomplete>]",
3968 "unknown heritage\n")
3970 return bgp_route_match_delete(vty
, "origin", NULL
,
3971 RMAP_EVENT_MATCH_DELETED
);
3974 DEFUN (set_ip_nexthop_peer
,
3975 set_ip_nexthop_peer_cmd
,
3976 "[no] set ip next-hop peer-address",
3980 "Next hop address\n"
3981 "Use peer address (for BGP only)\n")
3983 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3984 const char *) = strmatch(argv
[0]->text
, "no")
3985 ? generic_set_delete
3988 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3992 DEFUN (set_ip_nexthop_unchanged
,
3993 set_ip_nexthop_unchanged_cmd
,
3994 "[no] set ip next-hop unchanged",
3998 "Next hop address\n"
3999 "Don't modify existing Next hop address\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",
4011 DEFUN (set_local_pref
,
4013 "set local-preference (0-4294967295)",
4015 "BGP local preference path attribute\n"
4016 "Preference value\n")
4019 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4020 "local-preference", argv
[idx_number
]->arg
);
4024 DEFUN (no_set_local_pref
,
4025 no_set_local_pref_cmd
,
4026 "no set local-preference [(0-4294967295)]",
4029 "BGP local preference path attribute\n"
4030 "Preference value\n")
4032 int idx_localpref
= 3;
4033 if (argc
<= idx_localpref
)
4034 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4035 "local-preference", NULL
);
4036 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4037 "local-preference", argv
[idx_localpref
]->arg
);
4043 "set weight (0-4294967295)",
4045 "BGP weight for routing table\n"
4049 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4050 argv
[idx_number
]->arg
);
4054 DEFUN (no_set_weight
,
4056 "no set weight [(0-4294967295)]",
4059 "BGP weight for routing table\n"
4063 if (argc
<= idx_weight
)
4064 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4066 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4067 "weight", argv
[idx_weight
]->arg
);
4070 DEFUN (set_label_index
,
4071 set_label_index_cmd
,
4072 "set label-index (0-1048560)",
4074 "Label index to associate with the prefix\n"
4075 "Label index value\n")
4078 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4079 "label-index", argv
[idx_number
]->arg
);
4082 DEFUN (no_set_label_index
,
4083 no_set_label_index_cmd
,
4084 "no set label-index [(0-1048560)]",
4087 "Label index to associate with the prefix\n"
4088 "Label index value\n")
4090 int idx_label_index
= 3;
4091 if (argc
<= idx_label_index
)
4092 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4093 "label-index", NULL
);
4094 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4095 "label-index", argv
[idx_label_index
]->arg
);
4098 DEFUN (set_aspath_prepend_asn
,
4099 set_aspath_prepend_asn_cmd
,
4100 "set as-path prepend (1-4294967295)...",
4102 "Transform BGP AS_PATH attribute\n"
4103 "Prepend to the as-path\n"
4110 str
= argv_concat(argv
, argc
, idx_asn
);
4111 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4112 "as-path prepend", str
);
4113 XFREE(MTYPE_TMP
, str
);
4118 DEFUN (set_aspath_prepend_lastas
,
4119 set_aspath_prepend_lastas_cmd
,
4120 "set as-path prepend last-as (1-10)",
4122 "Transform BGP AS_PATH attribute\n"
4123 "Prepend to the as-path\n"
4124 "Use the peer's AS-number\n"
4125 "Number of times to insert\n")
4127 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4130 DEFUN (no_set_aspath_prepend
,
4131 no_set_aspath_prepend_cmd
,
4132 "no set as-path prepend [(1-4294967295)]",
4135 "Transform BGP AS_PATH attribute\n"
4136 "Prepend to the as-path\n"
4143 str
= argv_concat(argv
, argc
, idx_asn
);
4144 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4145 "as-path prepend", str
);
4146 XFREE(MTYPE_TMP
, str
);
4151 DEFUN (set_aspath_exclude
,
4152 set_aspath_exclude_cmd
,
4153 "set as-path exclude (1-4294967295)...",
4155 "Transform BGP AS-path attribute\n"
4156 "Exclude from the as-path\n"
4163 str
= argv_concat(argv
, argc
, idx_asn
);
4164 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4165 "as-path exclude", str
);
4166 XFREE(MTYPE_TMP
, str
);
4170 DEFUN (no_set_aspath_exclude
,
4171 no_set_aspath_exclude_cmd
,
4172 "no set as-path exclude (1-4294967295)...",
4175 "Transform BGP AS_PATH attribute\n"
4176 "Exclude from the as-path\n"
4183 str
= argv_concat(argv
, argc
, idx_asn
);
4184 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4185 "as-path exclude", str
);
4186 XFREE(MTYPE_TMP
, str
);
4190 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4191 "no set as-path exclude",
4193 "Transform BGP AS_PATH attribute\n"
4194 "Exclude from the as-path\n")
4196 DEFUN (set_community
,
4198 "set community AA:NN...",
4200 "BGP community attribute\n"
4208 struct community
*com
= NULL
;
4213 b
= buffer_new(1024);
4215 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4216 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4223 buffer_putc(b
, ' ');
4227 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4229 buffer_putstr(b
, "internet");
4232 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4234 buffer_putstr(b
, "local-AS");
4237 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4238 && strncmp(argv
[i
]->arg
, "no-advertise",
4239 strlen(argv
[i
]->arg
))
4241 buffer_putstr(b
, "no-advertise");
4244 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4245 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4247 buffer_putstr(b
, "no-export");
4250 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4251 strlen(argv
[i
]->arg
))
4253 buffer_putstr(b
, "graceful-shutdown");
4256 buffer_putstr(b
, argv
[i
]->arg
);
4258 buffer_putc(b
, '\0');
4260 /* Fetch result string then compile it to communities attribute. */
4261 str
= buffer_getstr(b
);
4265 com
= community_str2com(str
);
4266 XFREE(MTYPE_TMP
, str
);
4269 /* Can't compile user input into communities attribute. */
4271 vty_out(vty
, "%% Malformed communities attribute\n");
4272 return CMD_WARNING_CONFIG_FAILED
;
4275 /* Set communites attribute string. */
4276 str
= community_str(com
, false);
4279 argstr
= XCALLOC(MTYPE_TMP
,
4280 strlen(str
) + strlen(" additive") + 1);
4281 strcpy(argstr
, str
);
4282 strcpy(argstr
+ strlen(str
), " additive");
4283 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4284 "community", argstr
);
4285 XFREE(MTYPE_TMP
, argstr
);
4287 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4290 community_free(&com
);
4295 DEFUN (set_community_none
,
4296 set_community_none_cmd
,
4297 "set community none",
4299 "BGP community attribute\n"
4300 "No community attribute\n")
4302 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4303 "community", "none");
4306 DEFUN (no_set_community
,
4307 no_set_community_cmd
,
4308 "no set community AA:NN...",
4311 "BGP community attribute\n"
4314 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4318 ALIAS (no_set_community
,
4319 no_set_community_short_cmd
,
4323 "BGP community attribute\n")
4326 DEFUN (set_community_delete
,
4327 set_community_delete_cmd
,
4328 "set comm-list <(1-99)|(100-500)|WORD> delete",
4330 "set BGP community list (for deletion)\n"
4331 "Community-list number (standard)\n"
4332 "Community-list number (expanded)\n"
4333 "Community-list name\n"
4334 "Delete matching communities\n")
4336 int idx_comm_list
= 2;
4339 args
= argv_concat(argv
, argc
, idx_comm_list
);
4340 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4342 XFREE(MTYPE_TMP
, args
);
4347 DEFUN (no_set_community_delete
,
4348 no_set_community_delete_cmd
,
4349 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4352 "set BGP community list (for deletion)\n"
4353 "Community-list number (standard)\n"
4354 "Community-list number (expanded)\n"
4355 "Community-list name\n"
4356 "Delete matching communities\n")
4358 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4362 DEFUN (set_lcommunity
,
4364 "set large-community AA:BB:CC...",
4366 "BGP large community attribute\n"
4367 "Large Community number in aa:bb:cc format or additive\n")
4372 str
= argv_concat(argv
, argc
, 2);
4373 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4374 "large-community", str
);
4375 XFREE(MTYPE_TMP
, str
);
4380 DEFUN (set_lcommunity_none
,
4381 set_lcommunity_none_cmd
,
4382 "set large-community none",
4384 "BGP large community attribute\n"
4385 "No large community attribute\n")
4387 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4388 "large-community", "none");
4391 DEFUN (no_set_lcommunity
,
4392 no_set_lcommunity_cmd
,
4393 "no set large-community none",
4396 "BGP large community attribute\n"
4397 "No community attribute\n")
4399 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4400 "large-community", NULL
);
4403 DEFUN (no_set_lcommunity1
,
4404 no_set_lcommunity1_cmd
,
4405 "no set large-community AA:BB:CC...",
4408 "BGP large community attribute\n"
4409 "Large community in AA:BB:CC... format or additive\n")
4411 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4412 "large-community", NULL
);
4415 ALIAS (no_set_lcommunity1
,
4416 no_set_lcommunity1_short_cmd
,
4417 "no set large-community",
4420 "BGP large community attribute\n")
4422 DEFUN (set_lcommunity_delete
,
4423 set_lcommunity_delete_cmd
,
4424 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4426 "set BGP large community list (for deletion)\n"
4427 "Large Community-list number (standard)\n"
4428 "Large Communitly-list number (expanded)\n"
4429 "Large Community-list name\n"
4430 "Delete matching large communities\n")
4432 int idx_lcomm_list
= 2;
4435 args
= argv_concat(argv
, argc
, idx_lcomm_list
);
4436 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4437 "large-comm-list", args
);
4438 XFREE(MTYPE_TMP
, args
);
4443 DEFUN (no_set_lcommunity_delete
,
4444 no_set_lcommunity_delete_cmd
,
4445 "no 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")
4454 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4455 "large-comm-list", NULL
);
4458 ALIAS (no_set_lcommunity_delete
,
4459 no_set_lcommunity_delete_short_cmd
,
4460 "no set large-comm-list",
4463 "set BGP large community list (for deletion)\n")
4465 DEFUN (set_ecommunity_rt
,
4466 set_ecommunity_rt_cmd
,
4467 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4469 "BGP extended community attribute\n"
4470 "Route Target extended community\n"
4471 "VPN extended community\n")
4477 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4478 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4479 "extcommunity rt", str
);
4480 XFREE(MTYPE_TMP
, str
);
4485 DEFUN (no_set_ecommunity_rt
,
4486 no_set_ecommunity_rt_cmd
,
4487 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4490 "BGP extended community attribute\n"
4491 "Route Target extended community\n"
4492 "VPN extended community\n")
4494 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4495 "extcommunity rt", NULL
);
4498 ALIAS (no_set_ecommunity_rt
,
4499 no_set_ecommunity_rt_short_cmd
,
4500 "no set extcommunity rt",
4503 "BGP extended community attribute\n"
4504 "Route Target extended community\n")
4506 DEFUN (set_ecommunity_soo
,
4507 set_ecommunity_soo_cmd
,
4508 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4510 "BGP extended community attribute\n"
4511 "Site-of-Origin extended community\n"
4512 "VPN extended community\n")
4518 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4519 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4520 "extcommunity soo", str
);
4521 XFREE(MTYPE_TMP
, str
);
4526 DEFUN (no_set_ecommunity_soo
,
4527 no_set_ecommunity_soo_cmd
,
4528 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4531 "BGP extended community attribute\n"
4532 "Site-of-Origin extended community\n"
4533 "VPN extended community\n")
4535 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4536 "extcommunity soo", NULL
);
4539 ALIAS (no_set_ecommunity_soo
,
4540 no_set_ecommunity_soo_short_cmd
,
4541 "no set extcommunity soo",
4544 "GP extended community attribute\n"
4545 "Site-of-Origin extended community\n")
4549 "set origin <egp|igp|incomplete>",
4554 "unknown heritage\n")
4557 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4558 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4560 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4561 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4563 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4564 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4565 "origin", "incomplete");
4567 vty_out(vty
, "%% Invalid set origin type\n");
4568 return CMD_WARNING_CONFIG_FAILED
;
4572 DEFUN (no_set_origin
,
4574 "no set origin [<egp|igp|incomplete>]",
4580 "unknown heritage\n")
4582 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4587 DEFUN (set_atomic_aggregate
,
4588 set_atomic_aggregate_cmd
,
4589 "set atomic-aggregate",
4591 "BGP atomic aggregate attribute\n" )
4593 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4594 "atomic-aggregate", NULL
);
4597 DEFUN (no_set_atomic_aggregate
,
4598 no_set_atomic_aggregate_cmd
,
4599 "no set atomic-aggregate",
4602 "BGP atomic aggregate attribute\n" )
4604 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4605 "atomic-aggregate", NULL
);
4608 DEFUN (set_aggregator_as
,
4609 set_aggregator_as_cmd
,
4610 "set aggregator as (1-4294967295) A.B.C.D",
4612 "BGP aggregator attribute\n"
4613 "AS number of aggregator\n"
4615 "IP address of aggregator\n")
4620 struct in_addr address
;
4623 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4625 vty_out(vty
, "Aggregator IP address is invalid\n");
4626 return CMD_WARNING_CONFIG_FAILED
;
4629 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4630 strlen(argv
[idx_number
]->arg
)
4631 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4633 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4635 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4636 "aggregator as", argstr
);
4638 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4644 DEFUN (no_set_aggregator_as
,
4645 no_set_aggregator_as_cmd
,
4646 "no set aggregator as [(1-4294967295) A.B.C.D]",
4649 "BGP aggregator attribute\n"
4650 "AS number of aggregator\n"
4652 "IP address of aggregator\n")
4657 struct in_addr address
;
4660 if (argc
<= idx_asn
)
4661 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4662 "aggregator as", NULL
);
4664 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4666 vty_out(vty
, "Aggregator IP address is invalid\n");
4667 return CMD_WARNING_CONFIG_FAILED
;
4670 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4671 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4674 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4676 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4677 "aggregator as", argstr
);
4679 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4684 DEFUN (match_ipv6_next_hop
,
4685 match_ipv6_next_hop_cmd
,
4686 "match ipv6 next-hop X:X::X:X",
4689 "Match IPv6 next-hop address of route\n"
4690 "IPv6 address of next hop\n")
4693 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4694 RMAP_EVENT_MATCH_ADDED
);
4697 DEFUN (no_match_ipv6_next_hop
,
4698 no_match_ipv6_next_hop_cmd
,
4699 "no match ipv6 next-hop X:X::X:X",
4703 "Match IPv6 next-hop address of route\n"
4704 "IPv6 address of next hop\n")
4707 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4708 RMAP_EVENT_MATCH_DELETED
);
4712 DEFUN (set_ipv6_nexthop_peer
,
4713 set_ipv6_nexthop_peer_cmd
,
4714 "set ipv6 next-hop peer-address",
4717 "Next hop address\n"
4718 "Use peer address (for BGP only)\n")
4720 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4721 "ipv6 next-hop peer-address", NULL
);
4724 DEFUN (no_set_ipv6_nexthop_peer
,
4725 no_set_ipv6_nexthop_peer_cmd
,
4726 "no set ipv6 next-hop peer-address",
4730 "IPv6 next-hop address\n"
4731 "Use peer address (for BGP only)\n")
4733 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4734 "ipv6 next-hop peer-address", NULL
);
4737 DEFUN (set_ipv6_nexthop_prefer_global
,
4738 set_ipv6_nexthop_prefer_global_cmd
,
4739 "set ipv6 next-hop prefer-global",
4742 "IPv6 next-hop address\n"
4743 "Prefer global over link-local if both exist\n")
4745 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4746 "ipv6 next-hop prefer-global", NULL
);
4750 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4751 no_set_ipv6_nexthop_prefer_global_cmd
,
4752 "no set ipv6 next-hop prefer-global",
4756 "IPv6 next-hop address\n"
4757 "Prefer global over link-local if both exist\n")
4759 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4760 "ipv6 next-hop prefer-global", NULL
);
4763 DEFUN (set_ipv6_nexthop_global
,
4764 set_ipv6_nexthop_global_cmd
,
4765 "set ipv6 next-hop global X:X::X:X",
4768 "IPv6 next-hop address\n"
4769 "IPv6 global address\n"
4770 "IPv6 address of next hop\n")
4773 struct in6_addr addr
;
4776 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4778 vty_out(vty
, "%% Malformed nexthop address\n");
4779 return CMD_WARNING_CONFIG_FAILED
;
4781 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4782 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4783 vty_out(vty
, "%% Invalid global nexthop address\n");
4784 return CMD_WARNING_CONFIG_FAILED
;
4787 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4788 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4792 DEFUN (no_set_ipv6_nexthop_global
,
4793 no_set_ipv6_nexthop_global_cmd
,
4794 "no set ipv6 next-hop global X:X::X:X",
4798 "IPv6 next-hop address\n"
4799 "IPv6 global address\n"
4800 "IPv6 address of next hop\n")
4803 if (argc
<= idx_ipv6
)
4804 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4805 "ipv6 next-hop global", NULL
);
4806 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4807 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4810 #ifdef KEEP_OLD_VPN_COMMANDS
4811 DEFUN (set_vpn_nexthop
,
4812 set_vpn_nexthop_cmd
,
4813 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4815 "VPNv4 information\n"
4816 "VPN next-hop address\n"
4817 "IP address of next hop\n"
4818 "VPNv6 information\n"
4819 "VPN next-hop address\n"
4820 "IPv6 address of next hop\n")
4826 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4828 return generic_set_add(
4829 vty
, VTY_GET_CONTEXT(route_map_index
),
4830 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4832 return generic_set_add(
4833 vty
, VTY_GET_CONTEXT(route_map_index
),
4834 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4839 DEFUN (no_set_vpn_nexthop
,
4840 no_set_vpn_nexthop_cmd
,
4841 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4844 "VPNv4 information\n"
4845 "VPN next-hop address\n"
4846 "IP address of next hop\n"
4847 "VPNv6 information\n"
4848 "VPN next-hop address\n"
4849 "IPv6 address of next hop\n")
4859 arg
= argv
[idx_ip
]->arg
;
4860 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4862 return generic_set_delete(
4863 vty
, VTY_GET_CONTEXT(route_map_index
),
4864 "ipv4 vpn next-hop", arg
);
4866 return generic_set_delete(
4867 vty
, VTY_GET_CONTEXT(route_map_index
),
4868 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4872 #endif /* KEEP_OLD_VPN_COMMANDS */
4874 DEFUN (set_ipx_vpn_nexthop
,
4875 set_ipx_vpn_nexthop_cmd
,
4876 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4878 "IPv4 information\n"
4879 "IPv6 information\n"
4881 "VPN next-hop address\n"
4882 "IP address of next hop\n"
4883 "IPv6 address of next hop\n")
4889 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4891 return generic_set_add(
4892 vty
, VTY_GET_CONTEXT(route_map_index
),
4893 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4895 return generic_set_add(
4896 vty
, VTY_GET_CONTEXT(route_map_index
),
4897 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4902 DEFUN (no_set_ipx_vpn_nexthop
,
4903 no_set_ipx_vpn_nexthop_cmd
,
4904 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4907 "IPv4 information\n"
4908 "IPv6 information\n"
4910 "VPN next-hop address\n"
4911 "IP address of next hop\n"
4912 "IPv6 address of next hop\n")
4922 arg
= argv
[idx_ip
]->arg
;
4923 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4925 return generic_set_delete(
4926 vty
, VTY_GET_CONTEXT(route_map_index
),
4927 "ipv4 vpn next-hop", arg
);
4929 return generic_set_delete(
4930 vty
, VTY_GET_CONTEXT(route_map_index
),
4931 "ipv6 vpn next-hop", arg
);
4936 DEFUN (set_originator_id
,
4937 set_originator_id_cmd
,
4938 "set originator-id A.B.C.D",
4940 "BGP originator ID attribute\n"
4941 "IP address of originator\n")
4944 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4945 "originator-id", argv
[idx_ipv4
]->arg
);
4949 DEFUN (no_set_originator_id
,
4950 no_set_originator_id_cmd
,
4951 "no set originator-id [A.B.C.D]",
4954 "BGP originator ID attribute\n"
4955 "IP address of originator\n")
4959 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4961 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4962 "originator-id", arg
);
4966 /* Initialization of route map. */
4967 void bgp_route_map_init(void)
4971 route_map_add_hook(bgp_route_map_add
);
4972 route_map_delete_hook(bgp_route_map_delete
);
4973 route_map_event_hook(bgp_route_map_event
);
4975 route_map_match_interface_hook(generic_match_add
);
4976 route_map_no_match_interface_hook(generic_match_delete
);
4978 route_map_match_ip_address_hook(generic_match_add
);
4979 route_map_no_match_ip_address_hook(generic_match_delete
);
4981 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
4982 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
4984 route_map_match_ip_next_hop_hook(generic_match_add
);
4985 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
4987 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
4988 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
4990 route_map_match_ip_next_hop_type_hook(generic_match_add
);
4991 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
4993 route_map_match_ipv6_address_hook(generic_match_add
);
4994 route_map_no_match_ipv6_address_hook(generic_match_delete
);
4996 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
4997 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
4999 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
5000 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
5002 route_map_match_metric_hook(generic_match_add
);
5003 route_map_no_match_metric_hook(generic_match_delete
);
5005 route_map_match_tag_hook(generic_match_add
);
5006 route_map_no_match_tag_hook(generic_match_delete
);
5008 route_map_set_ip_nexthop_hook(generic_set_add
);
5009 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
5011 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
5012 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
5014 route_map_set_metric_hook(generic_set_add
);
5015 route_map_no_set_metric_hook(generic_set_delete
);
5017 route_map_set_tag_hook(generic_set_add
);
5018 route_map_no_set_tag_hook(generic_set_delete
);
5020 route_map_install_match(&route_match_peer_cmd
);
5021 route_map_install_match(&route_match_local_pref_cmd
);
5022 #if defined(HAVE_LUA)
5023 route_map_install_match(&route_match_command_cmd
);
5025 route_map_install_match(&route_match_ip_address_cmd
);
5026 route_map_install_match(&route_match_ip_next_hop_cmd
);
5027 route_map_install_match(&route_match_ip_route_source_cmd
);
5028 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
5029 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
5030 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
5031 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
5032 route_map_install_match(&route_match_aspath_cmd
);
5033 route_map_install_match(&route_match_community_cmd
);
5034 route_map_install_match(&route_match_lcommunity_cmd
);
5035 route_map_install_match(&route_match_ecommunity_cmd
);
5036 route_map_install_match(&route_match_local_pref_cmd
);
5037 route_map_install_match(&route_match_metric_cmd
);
5038 route_map_install_match(&route_match_origin_cmd
);
5039 route_map_install_match(&route_match_probability_cmd
);
5040 route_map_install_match(&route_match_interface_cmd
);
5041 route_map_install_match(&route_match_tag_cmd
);
5042 route_map_install_match(&route_match_mac_address_cmd
);
5043 route_map_install_match(&route_match_evpn_vni_cmd
);
5044 route_map_install_match(&route_match_evpn_route_type_cmd
);
5045 route_map_install_match(&route_match_evpn_default_route_cmd
);
5046 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5048 route_map_install_set(&route_set_ip_nexthop_cmd
);
5049 route_map_install_set(&route_set_local_pref_cmd
);
5050 route_map_install_set(&route_set_weight_cmd
);
5051 route_map_install_set(&route_set_label_index_cmd
);
5052 route_map_install_set(&route_set_metric_cmd
);
5053 route_map_install_set(&route_set_aspath_prepend_cmd
);
5054 route_map_install_set(&route_set_aspath_exclude_cmd
);
5055 route_map_install_set(&route_set_origin_cmd
);
5056 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5057 route_map_install_set(&route_set_aggregator_as_cmd
);
5058 route_map_install_set(&route_set_community_cmd
);
5059 route_map_install_set(&route_set_community_delete_cmd
);
5060 route_map_install_set(&route_set_lcommunity_cmd
);
5061 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5062 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5063 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5064 route_map_install_set(&route_set_originator_id_cmd
);
5065 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5066 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5067 route_map_install_set(&route_set_tag_cmd
);
5068 route_map_install_set(&route_set_label_index_cmd
);
5070 install_element(RMAP_NODE
, &match_peer_cmd
);
5071 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5072 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5073 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5074 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5075 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5076 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5077 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5078 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5079 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5080 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5081 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5082 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5083 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5084 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5085 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5086 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5088 install_element(RMAP_NODE
, &match_aspath_cmd
);
5089 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5090 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5091 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5092 install_element(RMAP_NODE
, &match_community_cmd
);
5093 install_element(RMAP_NODE
, &no_match_community_cmd
);
5094 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5095 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5096 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5097 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5098 install_element(RMAP_NODE
, &match_origin_cmd
);
5099 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5100 install_element(RMAP_NODE
, &match_probability_cmd
);
5101 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5103 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5104 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5105 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5106 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5107 install_element(RMAP_NODE
, &set_weight_cmd
);
5108 install_element(RMAP_NODE
, &set_label_index_cmd
);
5109 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5110 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5111 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5112 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5113 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5114 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5115 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5116 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5117 install_element(RMAP_NODE
, &set_origin_cmd
);
5118 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5119 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5120 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5121 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5122 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5123 install_element(RMAP_NODE
, &set_community_cmd
);
5124 install_element(RMAP_NODE
, &set_community_none_cmd
);
5125 install_element(RMAP_NODE
, &no_set_community_cmd
);
5126 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5127 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5128 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5129 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5130 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5131 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5132 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5133 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5134 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5135 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5136 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5137 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5138 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5139 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5140 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5141 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5142 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5143 #ifdef KEEP_OLD_VPN_COMMANDS
5144 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5145 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5146 #endif /* KEEP_OLD_VPN_COMMANDS */
5147 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5148 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5149 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5150 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5152 route_map_install_match(&route_match_ipv6_address_cmd
);
5153 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5154 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5155 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5156 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5157 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5158 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5159 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5161 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5162 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5163 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5164 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5165 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5166 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5167 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5168 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5169 #if defined(HAVE_LUA)
5170 install_element(RMAP_NODE
, &match_command_cmd
);
5171 install_element(RMAP_NODE
, &no_match_command_cmd
);
5175 void bgp_route_map_terminate(void)
5177 /* ToDo: Cleanup all the used memory */