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
;
1177 if (lcommunity_list_exact_match(
1178 path
->attr
->lcommunity
,
1182 if (lcommunity_list_match(
1183 path
->attr
->lcommunity
,
1188 return RMAP_NOMATCH
;
1191 /* Compile function for community match. */
1192 static void *route_match_lcommunity_compile(const char *arg
)
1194 struct rmap_community
*rcom
;
1198 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1200 p
= strchr(arg
, ' ');
1203 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1204 memcpy(rcom
->name
, arg
, len
);
1207 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1211 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1215 /* Compile function for community match. */
1216 static void route_match_lcommunity_free(void *rule
)
1218 struct rmap_community
*rcom
= rule
;
1220 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1221 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1224 /* Route map commands for community matching. */
1225 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1226 "large-community", route_match_lcommunity
,
1227 route_match_lcommunity_compile
, route_match_lcommunity_free
};
1230 /* Match function for extcommunity match. */
1231 static route_map_result_t
route_match_ecommunity(void *rule
,
1232 const struct prefix
*prefix
,
1233 route_map_object_t type
,
1236 struct community_list
*list
;
1237 struct bgp_path_info
*path
;
1238 struct rmap_community
*rcom
= rule
;
1240 if (type
== RMAP_BGP
) {
1243 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1245 EXTCOMMUNITY_LIST_MASTER
);
1247 return RMAP_NOMATCH
;
1249 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1252 return RMAP_NOMATCH
;
1255 /* Compile function for extcommunity match. */
1256 static void *route_match_ecommunity_compile(const char *arg
)
1258 struct rmap_community
*rcom
;
1260 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1261 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1262 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1267 /* Compile function for extcommunity match. */
1268 static void route_match_ecommunity_free(void *rule
)
1270 struct rmap_community
*rcom
= rule
;
1272 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1273 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1276 /* Route map commands for community matching. */
1277 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1278 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1279 route_match_ecommunity_free
};
1281 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1282 and `address-family vpnv4'. */
1284 /* `match origin' */
1285 static route_map_result_t
route_match_origin(void *rule
,
1286 const struct prefix
*prefix
,
1287 route_map_object_t type
,
1291 struct bgp_path_info
*path
;
1293 if (type
== RMAP_BGP
) {
1297 if (path
->attr
->origin
== *origin
)
1301 return RMAP_NOMATCH
;
1304 static void *route_match_origin_compile(const char *arg
)
1308 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1310 if (strcmp(arg
, "igp") == 0)
1312 else if (strcmp(arg
, "egp") == 0)
1320 /* Free route map's compiled `ip address' value. */
1321 static void route_match_origin_free(void *rule
)
1323 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1326 /* Route map commands for origin matching. */
1327 struct route_map_rule_cmd route_match_origin_cmd
= {
1328 "origin", route_match_origin
, route_match_origin_compile
,
1329 route_match_origin_free
};
1331 /* match probability { */
1333 static route_map_result_t
route_match_probability(void *rule
,
1334 const struct prefix
*prefix
,
1335 route_map_object_t type
,
1340 switch (*(long *)rule
) {
1346 if (r
< *(long *)rule
) {
1351 return RMAP_NOMATCH
;
1354 static void *route_match_probability_compile(const char *arg
)
1360 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1370 *lobule
= RAND_MAX
/ 100 * perc
;
1376 static void route_match_probability_free(void *rule
)
1378 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1381 struct route_map_rule_cmd route_match_probability_cmd
= {
1382 "probability", route_match_probability
, route_match_probability_compile
,
1383 route_match_probability_free
};
1385 /* `match interface IFNAME' */
1386 /* Match function should return 1 if match is success else return
1388 static route_map_result_t
route_match_interface(void *rule
,
1389 const struct prefix
*prefix
,
1390 route_map_object_t type
,
1393 struct interface
*ifp
;
1394 struct bgp_path_info
*path
;
1396 if (type
== RMAP_BGP
) {
1399 if (!path
|| !path
->attr
)
1400 return RMAP_NOMATCH
;
1402 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1404 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1405 return RMAP_NOMATCH
;
1409 return RMAP_NOMATCH
;
1412 /* Route map `interface' match statement. `arg' should be
1414 static void *route_match_interface_compile(const char *arg
)
1416 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1419 /* Free route map's compiled `interface' value. */
1420 static void route_match_interface_free(void *rule
)
1422 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1425 /* Route map commands for ip address matching. */
1426 struct route_map_rule_cmd route_match_interface_cmd
= {
1427 "interface", route_match_interface
, route_match_interface_compile
,
1428 route_match_interface_free
};
1432 /* `set ip next-hop IP_ADDRESS' */
1434 /* Match function return 1 if match is success else return zero. */
1435 static route_map_result_t
route_match_tag(void *rule
,
1436 const struct prefix
*prefix
,
1437 route_map_object_t type
, void *object
)
1440 struct bgp_path_info
*path
;
1442 if (type
== RMAP_BGP
) {
1446 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1449 return RMAP_NOMATCH
;
1453 /* Route map commands for tag matching. */
1454 static struct route_map_rule_cmd route_match_tag_cmd
= {
1455 "tag", route_match_tag
, route_map_rule_tag_compile
,
1456 route_map_rule_tag_free
,
1460 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1461 struct rmap_ip_nexthop_set
{
1462 struct in_addr
*address
;
1467 static route_map_result_t
route_set_ip_nexthop(void *rule
,
1468 const struct prefix
*prefix
,
1469 route_map_object_t type
,
1472 struct rmap_ip_nexthop_set
*rins
= rule
;
1473 struct bgp_path_info
*path
;
1476 if (type
!= RMAP_BGP
)
1479 if (prefix
->family
== AF_INET6
)
1485 if (rins
->unchanged
) {
1486 SET_FLAG(path
->attr
->rmap_change_flags
,
1487 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1488 } else if (rins
->peer_address
) {
1489 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1490 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1492 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1493 path
->attr
->nexthop
.s_addr
=
1494 sockunion2ip(peer
->su_remote
);
1495 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1496 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1497 /* The next hop value will be set as part of
1498 * packet rewrite. Set the flags here to indicate
1499 * that rewrite needs to be done.
1500 * Also, clear the value.
1502 SET_FLAG(path
->attr
->rmap_change_flags
,
1503 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1504 path
->attr
->nexthop
.s_addr
= 0;
1507 /* Set next hop value. */
1508 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1509 path
->attr
->nexthop
= *rins
->address
;
1510 SET_FLAG(path
->attr
->rmap_change_flags
,
1511 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1512 /* case for MP-BGP : MPLS VPN */
1513 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1514 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1520 /* Route map `ip nexthop' compile function. Given string is converted
1521 to struct in_addr structure. */
1522 static void *route_set_ip_nexthop_compile(const char *arg
)
1524 struct rmap_ip_nexthop_set
*rins
;
1525 struct in_addr
*address
= NULL
;
1526 int peer_address
= 0;
1530 if (strcmp(arg
, "peer-address") == 0)
1532 else if (strcmp(arg
, "unchanged") == 0)
1535 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1536 sizeof(struct in_addr
));
1537 ret
= inet_aton(arg
, address
);
1540 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1545 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1546 sizeof(struct rmap_ip_nexthop_set
));
1548 rins
->address
= address
;
1549 rins
->peer_address
= peer_address
;
1550 rins
->unchanged
= unchanged
;
1555 /* Free route map's compiled `ip nexthop' value. */
1556 static void route_set_ip_nexthop_free(void *rule
)
1558 struct rmap_ip_nexthop_set
*rins
= rule
;
1560 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1562 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1565 /* Route map commands for ip nexthop set. */
1566 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1567 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1568 route_set_ip_nexthop_free
};
1570 /* `set local-preference LOCAL_PREF' */
1572 /* Set local preference. */
1573 static route_map_result_t
route_set_local_pref(void *rule
,
1574 const struct prefix
*prefix
,
1575 route_map_object_t type
,
1578 struct rmap_value
*rv
;
1579 struct bgp_path_info
*path
;
1580 uint32_t locpref
= 0;
1582 if (type
== RMAP_BGP
) {
1583 /* Fetch routemap's rule information. */
1587 /* Set local preference value. */
1588 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1589 locpref
= path
->attr
->local_pref
;
1591 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1592 path
->attr
->local_pref
=
1593 route_value_adjust(rv
, locpref
, path
->peer
);
1599 /* Set local preference rule structure. */
1600 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1601 "local-preference", route_set_local_pref
, route_value_compile
,
1605 /* `set weight WEIGHT' */
1608 static route_map_result_t
route_set_weight(void *rule
,
1609 const struct prefix
*prefix
,
1610 route_map_object_t type
,
1613 struct rmap_value
*rv
;
1614 struct bgp_path_info
*path
;
1616 if (type
== RMAP_BGP
) {
1617 /* Fetch routemap's rule information. */
1621 /* Set weight value. */
1622 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1628 /* Set local preference rule structure. */
1629 struct route_map_rule_cmd route_set_weight_cmd
= {
1630 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1633 /* `set metric METRIC' */
1635 /* Set metric to attribute. */
1636 static route_map_result_t
route_set_metric(void *rule
,
1637 const struct prefix
*prefix
,
1638 route_map_object_t type
,
1641 struct rmap_value
*rv
;
1642 struct bgp_path_info
*path
;
1645 if (type
== RMAP_BGP
) {
1646 /* Fetch routemap's rule information. */
1650 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1651 med
= path
->attr
->med
;
1653 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1654 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1659 /* Set metric rule structure. */
1660 struct route_map_rule_cmd route_set_metric_cmd
= {
1661 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1664 /* `set as-path prepend ASPATH' */
1666 /* For AS path prepend mechanism. */
1667 static route_map_result_t
route_set_aspath_prepend(void *rule
,
1668 const struct prefix
*prefix
,
1669 route_map_object_t type
,
1672 struct aspath
*aspath
;
1674 struct bgp_path_info
*path
;
1676 if (type
== RMAP_BGP
) {
1679 if (path
->attr
->aspath
->refcnt
)
1680 new = aspath_dup(path
->attr
->aspath
);
1682 new = path
->attr
->aspath
;
1684 if ((uintptr_t)rule
> 10) {
1686 aspath_prepend(aspath
, new);
1688 as_t as
= aspath_leftmost(new);
1690 as
= path
->peer
->as
;
1691 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1694 path
->attr
->aspath
= new;
1700 static void *route_set_aspath_prepend_compile(const char *arg
)
1704 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1705 return (void *)(uintptr_t)num
;
1707 return route_aspath_compile(arg
);
1710 static void route_set_aspath_prepend_free(void *rule
)
1712 if ((uintptr_t)rule
> 10)
1713 route_aspath_free(rule
);
1717 /* Set as-path prepend rule structure. */
1718 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1719 "as-path prepend", route_set_aspath_prepend
,
1720 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1723 /* `set as-path exclude ASn' */
1725 /* For ASN exclude mechanism.
1726 * Iterate over ASns requested and filter them from the given AS_PATH one by
1728 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1730 static route_map_result_t
route_set_aspath_exclude(void *rule
,
1731 const struct prefix
*dummy
,
1732 route_map_object_t type
,
1735 struct aspath
*new_path
, *exclude_path
;
1736 struct bgp_path_info
*path
;
1738 if (type
== RMAP_BGP
) {
1739 exclude_path
= rule
;
1741 if (path
->attr
->aspath
->refcnt
)
1742 new_path
= aspath_dup(path
->attr
->aspath
);
1744 new_path
= path
->attr
->aspath
;
1745 path
->attr
->aspath
=
1746 aspath_filter_exclude(new_path
, exclude_path
);
1751 /* Set ASn exlude rule structure. */
1752 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1753 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1757 /* `set community COMMUNITY' */
1758 struct rmap_com_set
{
1759 struct community
*com
;
1764 /* For community set mechanism. */
1765 static route_map_result_t
route_set_community(void *rule
,
1766 const struct prefix
*prefix
,
1767 route_map_object_t type
,
1770 struct rmap_com_set
*rcs
;
1771 struct bgp_path_info
*path
;
1773 struct community
*new = NULL
;
1774 struct community
*old
;
1775 struct community
*merge
;
1777 if (type
== RMAP_BGP
) {
1781 old
= attr
->community
;
1785 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1786 attr
->community
= NULL
;
1787 /* See the longer comment down below. */
1788 if (old
&& old
->refcnt
== 0)
1789 community_free(&old
);
1793 /* "additive" case. */
1794 if (rcs
->additive
&& old
) {
1795 merge
= community_merge(community_dup(old
), rcs
->com
);
1797 new = community_uniq_sort(merge
);
1798 community_free(&merge
);
1800 new = community_dup(rcs
->com
);
1802 /* HACK: if the old community is not intern'd,
1803 * we should free it here, or all reference to it may be
1805 * Really need to cleanup attribute caching sometime.
1807 if (old
&& old
->refcnt
== 0)
1808 community_free(&old
);
1810 /* will be interned by caller if required */
1811 attr
->community
= new;
1813 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1819 /* Compile function for set community. */
1820 static void *route_set_community_compile(const char *arg
)
1822 struct rmap_com_set
*rcs
;
1823 struct community
*com
= NULL
;
1828 if (strcmp(arg
, "none") == 0)
1831 sp
= strstr(arg
, "additive");
1833 if (sp
&& sp
> arg
) {
1834 /* "additive" keyword is included. */
1839 com
= community_str2com(arg
);
1848 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1850 rcs
->additive
= additive
;
1856 /* Free function for set community. */
1857 static void route_set_community_free(void *rule
)
1859 struct rmap_com_set
*rcs
= rule
;
1862 community_free(&rcs
->com
);
1863 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1866 /* Set community rule structure. */
1867 struct route_map_rule_cmd route_set_community_cmd
= {
1868 "community", route_set_community
, route_set_community_compile
,
1869 route_set_community_free
,
1872 /* `set community COMMUNITY' */
1873 struct rmap_lcom_set
{
1874 struct lcommunity
*lcom
;
1880 /* For lcommunity set mechanism. */
1881 static route_map_result_t
route_set_lcommunity(void *rule
,
1882 const struct prefix
*prefix
,
1883 route_map_object_t type
,
1886 struct rmap_lcom_set
*rcs
;
1887 struct bgp_path_info
*path
;
1889 struct lcommunity
*new = NULL
;
1890 struct lcommunity
*old
;
1891 struct lcommunity
*merge
;
1893 if (type
== RMAP_BGP
) {
1897 old
= attr
->lcommunity
;
1902 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
1903 attr
->lcommunity
= NULL
;
1905 /* See the longer comment down below. */
1906 if (old
&& old
->refcnt
== 0)
1907 lcommunity_free(&old
);
1911 if (rcs
->additive
&& old
) {
1912 merge
= lcommunity_merge(lcommunity_dup(old
),
1915 new = lcommunity_uniq_sort(merge
);
1916 lcommunity_free(&merge
);
1918 new = lcommunity_dup(rcs
->lcom
);
1920 /* HACK: if the old large-community is not intern'd,
1921 * we should free it here, or all reference to it may be
1923 * Really need to cleanup attribute caching sometime.
1925 if (old
&& old
->refcnt
== 0)
1926 lcommunity_free(&old
);
1928 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1929 attr
->lcommunity
= new;
1931 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
1937 /* Compile function for set community. */
1938 static void *route_set_lcommunity_compile(const char *arg
)
1940 struct rmap_lcom_set
*rcs
;
1941 struct lcommunity
*lcom
= NULL
;
1946 if (strcmp(arg
, "none") == 0)
1949 sp
= strstr(arg
, "additive");
1951 if (sp
&& sp
> arg
) {
1952 /* "additive" keyworkd is included. */
1957 lcom
= lcommunity_str2com(arg
);
1966 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1968 rcs
->additive
= additive
;
1974 /* Free function for set lcommunity. */
1975 static void route_set_lcommunity_free(void *rule
)
1977 struct rmap_lcom_set
*rcs
= rule
;
1980 lcommunity_free(&rcs
->lcom
);
1982 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1985 /* Set community rule structure. */
1986 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
1987 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
1988 route_set_lcommunity_free
,
1991 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
1993 /* For large community set mechanism. */
1994 static route_map_result_t
route_set_lcommunity_delete(void *rule
,
1995 const struct prefix
*pfx
,
1996 route_map_object_t type
,
1999 struct community_list
*list
;
2000 struct lcommunity
*merge
;
2001 struct lcommunity
*new;
2002 struct lcommunity
*old
;
2003 struct bgp_path_info
*path
;
2004 struct rmap_community
*rcom
= rule
;
2006 if (type
== RMAP_BGP
) {
2011 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2013 LARGE_COMMUNITY_LIST_MASTER
);
2014 old
= path
->attr
->lcommunity
;
2017 merge
= lcommunity_list_match_delete(
2018 lcommunity_dup(old
), list
);
2019 new = lcommunity_uniq_sort(merge
);
2020 lcommunity_free(&merge
);
2022 /* HACK: if the old community is not intern'd,
2023 * we should free it here, or all reference to it may be
2025 * Really need to cleanup attribute caching sometime.
2027 if (old
->refcnt
== 0)
2028 lcommunity_free(&old
);
2030 if (new->size
== 0) {
2031 path
->attr
->lcommunity
= NULL
;
2032 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
2033 BGP_ATTR_LARGE_COMMUNITIES
);
2034 lcommunity_free(&new);
2036 path
->attr
->lcommunity
= new;
2037 path
->attr
->flag
|= ATTR_FLAG_BIT(
2038 BGP_ATTR_LARGE_COMMUNITIES
);
2046 /* Compile function for set lcommunity. */
2047 static void *route_set_lcommunity_delete_compile(const char *arg
)
2049 struct rmap_community
*rcom
;
2051 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2053 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2054 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2059 /* Free function for set lcommunity. */
2060 static void route_set_lcommunity_delete_free(void *rule
)
2062 struct rmap_community
*rcom
= rule
;
2064 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2065 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2068 /* Set lcommunity rule structure. */
2069 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2070 "large-comm-list", route_set_lcommunity_delete
,
2071 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2075 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2077 /* For community set mechanism. */
2078 static route_map_result_t
route_set_community_delete(
2080 const struct prefix
*prefix
,
2081 route_map_object_t type
,
2084 struct community_list
*list
;
2085 struct community
*merge
;
2086 struct community
*new;
2087 struct community
*old
;
2088 struct bgp_path_info
*path
;
2089 struct rmap_community
*rcom
= rule
;
2091 if (type
== RMAP_BGP
) {
2096 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2098 COMMUNITY_LIST_MASTER
);
2099 old
= path
->attr
->community
;
2102 merge
= community_list_match_delete(community_dup(old
),
2104 new = community_uniq_sort(merge
);
2105 community_free(&merge
);
2107 /* HACK: if the old community is not intern'd,
2108 * we should free it here, or all reference to it may be
2110 * Really need to cleanup attribute caching sometime.
2112 if (old
->refcnt
== 0)
2113 community_free(&old
);
2115 if (new->size
== 0) {
2116 path
->attr
->community
= NULL
;
2118 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2119 community_free(&new);
2121 path
->attr
->community
= new;
2123 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2131 /* Compile function for set community. */
2132 static void *route_set_community_delete_compile(const char *arg
)
2134 struct rmap_community
*rcom
;
2136 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2138 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2139 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2144 /* Free function for set community. */
2145 static void route_set_community_delete_free(void *rule
)
2147 struct rmap_community
*rcom
= rule
;
2149 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2150 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2153 /* Set community rule structure. */
2154 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2155 "comm-list", route_set_community_delete
,
2156 route_set_community_delete_compile
, route_set_community_delete_free
,
2159 /* `set extcommunity rt COMMUNITY' */
2161 /* For community set mechanism. Used by _rt and _soo. */
2162 static route_map_result_t
route_set_ecommunity(void *rule
,
2163 const struct prefix
*prefix
,
2164 route_map_object_t type
,
2167 struct ecommunity
*ecom
;
2168 struct ecommunity
*new_ecom
;
2169 struct ecommunity
*old_ecom
;
2170 struct bgp_path_info
*path
;
2172 if (type
== RMAP_BGP
) {
2179 /* We assume additive for Extended Community. */
2180 old_ecom
= path
->attr
->ecommunity
;
2183 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2186 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2187 * bgp_update_receive()
2188 * ->refcnt = 0 => set by a previous route-map
2190 if (!old_ecom
->refcnt
)
2191 ecommunity_free(&old_ecom
);
2193 new_ecom
= ecommunity_dup(ecom
);
2195 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2196 path
->attr
->ecommunity
= new_ecom
;
2198 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2203 /* Compile function for set community. */
2204 static void *route_set_ecommunity_rt_compile(const char *arg
)
2206 struct ecommunity
*ecom
;
2208 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2211 return ecommunity_intern(ecom
);
2214 /* Free function for set community. Used by _rt and _soo */
2215 static void route_set_ecommunity_free(void *rule
)
2217 struct ecommunity
*ecom
= rule
;
2218 ecommunity_unintern(&ecom
);
2221 /* Set community rule structure. */
2222 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2223 "extcommunity rt", route_set_ecommunity
,
2224 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2227 /* `set extcommunity soo COMMUNITY' */
2229 /* Compile function for set community. */
2230 static void *route_set_ecommunity_soo_compile(const char *arg
)
2232 struct ecommunity
*ecom
;
2234 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2238 return ecommunity_intern(ecom
);
2241 /* Set community rule structure. */
2242 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2243 "extcommunity soo", route_set_ecommunity
,
2244 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2247 /* `set origin ORIGIN' */
2249 /* For origin set. */
2250 static route_map_result_t
route_set_origin(void *rule
,
2251 const struct prefix
*prefix
,
2252 route_map_object_t type
,
2256 struct bgp_path_info
*path
;
2258 if (type
== RMAP_BGP
) {
2262 path
->attr
->origin
= *origin
;
2268 /* Compile function for origin set. */
2269 static void *route_set_origin_compile(const char *arg
)
2273 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2275 if (strcmp(arg
, "igp") == 0)
2277 else if (strcmp(arg
, "egp") == 0)
2285 /* Compile function for origin set. */
2286 static void route_set_origin_free(void *rule
)
2288 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2291 /* Set origin rule structure. */
2292 struct route_map_rule_cmd route_set_origin_cmd
= {
2293 "origin", route_set_origin
, route_set_origin_compile
,
2294 route_set_origin_free
,
2297 /* `set atomic-aggregate' */
2299 /* For atomic aggregate set. */
2300 static route_map_result_t
route_set_atomic_aggregate(void *rule
,
2301 const struct prefix
*pfx
,
2302 route_map_object_t type
,
2305 struct bgp_path_info
*path
;
2307 if (type
== RMAP_BGP
) {
2309 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2315 /* Compile function for atomic aggregate. */
2316 static void *route_set_atomic_aggregate_compile(const char *arg
)
2321 /* Compile function for atomic aggregate. */
2322 static void route_set_atomic_aggregate_free(void *rule
)
2327 /* Set atomic aggregate rule structure. */
2328 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2329 "atomic-aggregate", route_set_atomic_aggregate
,
2330 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2333 /* `set aggregator as AS A.B.C.D' */
2336 struct in_addr address
;
2339 static route_map_result_t
route_set_aggregator_as(void *rule
,
2340 const struct prefix
*prefix
,
2341 route_map_object_t type
,
2344 struct bgp_path_info
*path
;
2345 struct aggregator
*aggregator
;
2347 if (type
== RMAP_BGP
) {
2351 path
->attr
->aggregator_as
= aggregator
->as
;
2352 path
->attr
->aggregator_addr
= aggregator
->address
;
2353 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2359 static void *route_set_aggregator_as_compile(const char *arg
)
2361 struct aggregator
*aggregator
;
2367 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2368 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2369 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2373 aggregator
->as
= strtoul(as
, NULL
, 10);
2374 ret
= inet_aton(address
, &aggregator
->address
);
2376 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2382 static void route_set_aggregator_as_free(void *rule
)
2384 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2387 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2388 "aggregator as", route_set_aggregator_as
,
2389 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2392 /* Set tag to object. object must be pointer to struct bgp_path_info */
2393 static route_map_result_t
route_set_tag(void *rule
,
2394 const struct prefix
*prefix
,
2395 route_map_object_t type
, void *object
)
2398 struct bgp_path_info
*path
;
2400 if (type
== RMAP_BGP
) {
2405 path
->attr
->tag
= *tag
;
2411 /* Route map commands for tag set. */
2412 static struct route_map_rule_cmd route_set_tag_cmd
= {
2413 "tag", route_set_tag
, route_map_rule_tag_compile
,
2414 route_map_rule_tag_free
,
2417 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2418 static route_map_result_t
route_set_label_index(void *rule
,
2419 const struct prefix
*prefix
,
2420 route_map_object_t type
,
2423 struct rmap_value
*rv
;
2424 struct bgp_path_info
*path
;
2425 uint32_t label_index
;
2427 if (type
== RMAP_BGP
) {
2428 /* Fetch routemap's rule information. */
2432 /* Set label-index value. */
2433 label_index
= rv
->value
;
2435 path
->attr
->label_index
= label_index
;
2436 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2443 /* Route map commands for label-index set. */
2444 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2445 "label-index", route_set_label_index
, route_value_compile
,
2449 /* `match ipv6 address IP_ACCESS_LIST' */
2451 static route_map_result_t
route_match_ipv6_address(void *rule
,
2452 const struct prefix
*prefix
,
2453 route_map_object_t type
,
2456 struct access_list
*alist
;
2458 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2459 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2461 return RMAP_NOMATCH
;
2463 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2467 return RMAP_NOMATCH
;
2470 static void *route_match_ipv6_address_compile(const char *arg
)
2472 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2475 static void route_match_ipv6_address_free(void *rule
)
2477 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2480 /* Route map commands for ip address matching. */
2481 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2482 "ipv6 address", route_match_ipv6_address
,
2483 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2485 /* `match ipv6 next-hop IP_ADDRESS' */
2487 static route_map_result_t
route_match_ipv6_next_hop(void *rule
,
2488 const struct prefix
*prefix
,
2489 route_map_object_t type
,
2492 struct in6_addr
*addr
= rule
;
2493 struct bgp_path_info
*path
;
2495 if (type
== RMAP_BGP
) {
2498 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2501 if (path
->attr
->mp_nexthop_len
2502 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2503 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2506 return RMAP_NOMATCH
;
2509 return RMAP_NOMATCH
;
2512 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2514 struct in6_addr
*address
;
2517 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2519 ret
= inet_pton(AF_INET6
, arg
, address
);
2521 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2528 static void route_match_ipv6_next_hop_free(void *rule
)
2530 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2533 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2534 "ipv6 next-hop", route_match_ipv6_next_hop
,
2535 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2537 /* `match ipv6 address prefix-list PREFIX_LIST' */
2539 static route_map_result_t
2540 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2541 route_map_object_t type
, void *object
)
2543 struct prefix_list
*plist
;
2545 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2546 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
2548 return RMAP_NOMATCH
;
2550 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
2554 return RMAP_NOMATCH
;
2557 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2559 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2562 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2564 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2567 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2568 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2569 route_match_ipv6_address_prefix_list_compile
,
2570 route_match_ipv6_address_prefix_list_free
};
2572 /* `match ipv6 next-hop type <TYPE>' */
2574 static route_map_result_t
2575 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2576 route_map_object_t type
, void *object
)
2578 struct bgp_path_info
*path
;
2579 struct in6_addr
*addr
= rule
;
2581 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2582 path
= (struct bgp_path_info
*)object
;
2583 if (!path
|| !path
->attr
)
2584 return RMAP_DENYMATCH
;
2586 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2587 && !path
->attr
->nh_ifindex
)
2590 return RMAP_NOMATCH
;
2593 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2595 struct in6_addr
*address
;
2598 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2600 ret
= inet_pton(AF_INET6
, "::0", address
);
2602 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2609 static void route_match_ipv6_next_hop_type_free(void *rule
)
2611 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2614 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2615 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2616 route_match_ipv6_next_hop_type_compile
,
2617 route_match_ipv6_next_hop_type_free
};
2619 /* `set ipv6 nexthop global IP_ADDRESS' */
2621 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2622 static route_map_result_t
route_set_ipv6_nexthop_global(void *rule
,
2623 const struct prefix
*p
,
2624 route_map_object_t type
,
2627 struct in6_addr
*address
;
2628 struct bgp_path_info
*path
;
2630 if (type
== RMAP_BGP
) {
2631 /* Fetch routemap's rule information. */
2635 /* Set next hop value. */
2636 path
->attr
->mp_nexthop_global
= *address
;
2638 /* Set nexthop length. */
2639 if (path
->attr
->mp_nexthop_len
== 0)
2640 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2642 SET_FLAG(path
->attr
->rmap_change_flags
,
2643 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2649 /* Route map `ip next-hop' compile function. Given string is converted
2650 to struct in_addr structure. */
2651 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2654 struct in6_addr
*address
;
2656 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2658 ret
= inet_pton(AF_INET6
, arg
, address
);
2661 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2668 /* Free route map's compiled `ip next-hop' value. */
2669 static void route_set_ipv6_nexthop_global_free(void *rule
)
2671 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2674 /* Route map commands for ip nexthop set. */
2675 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2676 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2677 route_set_ipv6_nexthop_global_compile
,
2678 route_set_ipv6_nexthop_global_free
};
2680 /* Set next-hop preference value. */
2681 static route_map_result_t
2682 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2683 route_map_object_t type
, void *object
)
2685 struct bgp_path_info
*path
;
2688 if (type
== RMAP_BGP
) {
2689 /* Fetch routemap's rule information. */
2693 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2694 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2696 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2697 /* Set next hop preference to global */
2698 path
->attr
->mp_nexthop_prefer_global
= true;
2699 SET_FLAG(path
->attr
->rmap_change_flags
,
2700 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2702 path
->attr
->mp_nexthop_prefer_global
= false;
2703 SET_FLAG(path
->attr
->rmap_change_flags
,
2704 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2710 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2714 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2720 /* Free route map's compiled `ip next-hop' value. */
2721 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2723 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2726 /* Route map commands for ip nexthop set preferred. */
2727 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2728 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2729 route_set_ipv6_nexthop_prefer_global_compile
,
2730 route_set_ipv6_nexthop_prefer_global_free
};
2732 /* `set ipv6 nexthop local IP_ADDRESS' */
2734 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2735 static route_map_result_t
route_set_ipv6_nexthop_local(void *rule
,
2736 const struct prefix
*p
,
2737 route_map_object_t type
,
2740 struct in6_addr
*address
;
2741 struct bgp_path_info
*path
;
2743 if (type
== RMAP_BGP
) {
2744 /* Fetch routemap's rule information. */
2748 /* Set next hop value. */
2749 path
->attr
->mp_nexthop_local
= *address
;
2751 /* Set nexthop length. */
2752 if (path
->attr
->mp_nexthop_len
2753 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2754 path
->attr
->mp_nexthop_len
=
2755 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2757 SET_FLAG(path
->attr
->rmap_change_flags
,
2758 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2764 /* Route map `ip nexthop' compile function. Given string is converted
2765 to struct in_addr structure. */
2766 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2769 struct in6_addr
*address
;
2771 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2773 ret
= inet_pton(AF_INET6
, arg
, address
);
2776 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2783 /* Free route map's compiled `ip nexthop' value. */
2784 static void route_set_ipv6_nexthop_local_free(void *rule
)
2786 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2789 /* Route map commands for ip nexthop set. */
2790 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2791 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2792 route_set_ipv6_nexthop_local_compile
,
2793 route_set_ipv6_nexthop_local_free
};
2795 /* `set ipv6 nexthop peer-address' */
2797 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2798 static route_map_result_t
route_set_ipv6_nexthop_peer(void *rule
,
2799 const struct prefix
*pfx
,
2800 route_map_object_t type
,
2803 struct in6_addr peer_address
;
2804 struct bgp_path_info
*path
;
2807 if (type
== RMAP_BGP
) {
2808 /* Fetch routemap's rule information. */
2812 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2813 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2815 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2816 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2817 /* Set next hop value and length in attribute. */
2818 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2819 path
->attr
->mp_nexthop_local
= peer_address
;
2820 if (path
->attr
->mp_nexthop_len
!= 32)
2821 path
->attr
->mp_nexthop_len
= 32;
2823 path
->attr
->mp_nexthop_global
= peer_address
;
2824 if (path
->attr
->mp_nexthop_len
== 0)
2825 path
->attr
->mp_nexthop_len
= 16;
2828 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2829 /* The next hop value will be set as part of packet
2831 * Set the flags here to indicate that rewrite needs to
2833 * Also, clear the value - we clear both global and
2835 * nexthops, whether we send one or both is determined
2838 SET_FLAG(path
->attr
->rmap_change_flags
,
2839 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2840 /* clear next hop value. */
2841 memset(&(path
->attr
->mp_nexthop_global
), 0,
2842 sizeof(struct in6_addr
));
2843 memset(&(path
->attr
->mp_nexthop_local
), 0,
2844 sizeof(struct in6_addr
));
2851 /* Route map `ip next-hop' compile function. Given string is converted
2852 to struct in_addr structure. */
2853 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2857 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2863 /* Free route map's compiled `ip next-hop' value. */
2864 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2866 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2869 /* Route map commands for ip nexthop set. */
2870 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2871 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2872 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2874 /* `set ipv4 vpn next-hop A.B.C.D' */
2876 static route_map_result_t
route_set_vpnv4_nexthop(void *rule
,
2877 const struct prefix
*prefix
,
2878 route_map_object_t type
,
2881 struct in_addr
*address
;
2882 struct bgp_path_info
*path
;
2884 if (type
== RMAP_BGP
) {
2885 /* Fetch routemap's rule information. */
2889 /* Set next hop value. */
2890 path
->attr
->mp_nexthop_global_in
= *address
;
2891 path
->attr
->mp_nexthop_len
= 4;
2897 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2900 struct in_addr
*address
;
2902 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2904 ret
= inet_aton(arg
, address
);
2907 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2914 /* `set ipv6 vpn next-hop A.B.C.D' */
2916 static route_map_result_t
route_set_vpnv6_nexthop(void *rule
,
2917 const struct prefix
*prefix
,
2918 route_map_object_t type
,
2921 struct in6_addr
*address
;
2922 struct bgp_path_info
*path
;
2924 if (type
== RMAP_BGP
) {
2925 /* Fetch routemap's rule information. */
2929 /* Set next hop value. */
2930 memcpy(&path
->attr
->mp_nexthop_global
, address
,
2931 sizeof(struct in6_addr
));
2932 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2938 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2941 struct in6_addr
*address
;
2943 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2944 ret
= inet_pton(AF_INET6
, arg
, address
);
2947 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2954 static void route_set_vpn_nexthop_free(void *rule
)
2956 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2959 /* Route map commands for ipv4 next-hop set. */
2960 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2961 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2962 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
2964 /* Route map commands for ipv6 next-hop set. */
2965 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
2966 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
2967 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
2969 /* `set originator-id' */
2971 /* For origin set. */
2972 static route_map_result_t
route_set_originator_id(void *rule
,
2973 const struct prefix
*prefix
,
2974 route_map_object_t type
,
2977 struct in_addr
*address
;
2978 struct bgp_path_info
*path
;
2980 if (type
== RMAP_BGP
) {
2984 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
2985 path
->attr
->originator_id
= *address
;
2991 /* Compile function for originator-id set. */
2992 static void *route_set_originator_id_compile(const char *arg
)
2995 struct in_addr
*address
;
2997 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2999 ret
= inet_aton(arg
, address
);
3002 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
3009 /* Compile function for originator_id set. */
3010 static void route_set_originator_id_free(void *rule
)
3012 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
3015 /* Set originator-id rule structure. */
3016 struct route_map_rule_cmd route_set_originator_id_cmd
= {
3017 "originator-id", route_set_originator_id
,
3018 route_set_originator_id_compile
, route_set_originator_id_free
,
3021 /* Add bgp route map rule. */
3022 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
3023 const char *arg
, route_map_event_t type
)
3025 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3026 int retval
= CMD_SUCCESS
;
3029 ret
= route_map_add_match(index
, command
, arg
, type
);
3031 case RMAP_RULE_MISSING
:
3032 vty_out(vty
, "%% BGP Can't find rule.\n");
3033 retval
= CMD_WARNING_CONFIG_FAILED
;
3035 case RMAP_COMPILE_ERROR
:
3036 vty_out(vty
, "%% BGP Argument is malformed.\n");
3037 retval
= CMD_WARNING_CONFIG_FAILED
;
3039 case RMAP_COMPILE_SUCCESS
:
3040 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
3041 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
3049 /* Delete bgp route map rule. */
3050 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3051 const char *arg
, route_map_event_t type
)
3053 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3055 int retval
= CMD_SUCCESS
;
3056 char *dep_name
= NULL
;
3058 char *rmap_name
= NULL
;
3060 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3061 /* ignore the mundane, the types without any dependency */
3063 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3066 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3068 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3070 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3073 ret
= route_map_delete_match(index
, command
, dep_name
);
3075 case RMAP_RULE_MISSING
:
3076 vty_out(vty
, "%% BGP Can't find rule.\n");
3077 retval
= CMD_WARNING_CONFIG_FAILED
;
3079 case RMAP_COMPILE_ERROR
:
3080 vty_out(vty
, "%% BGP Argument is malformed.\n");
3081 retval
= CMD_WARNING_CONFIG_FAILED
;
3083 case RMAP_COMPILE_SUCCESS
:
3084 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
3085 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
3089 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3090 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3096 * This is the workhorse routine for processing in/out routemap
3099 static void bgp_route_map_process_peer(const char *rmap_name
,
3100 struct route_map
*map
, struct peer
*peer
,
3101 int afi
, int safi
, int route_update
)
3103 struct bgp_filter
*filter
;
3105 if (!peer
|| !rmap_name
)
3108 filter
= &peer
->filter
[afi
][safi
];
3110 * in is for non-route-server clients,
3111 * out is for all peers
3113 if (filter
->map
[RMAP_IN
].name
3114 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3115 filter
->map
[RMAP_IN
].map
= map
;
3117 if (route_update
&& peer
->status
== Established
) {
3118 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3119 PEER_FLAG_SOFT_RECONFIG
)) {
3120 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3122 "Processing route_map %s update on peer %s (inbound, soft-reconfig)",
3123 rmap_name
, peer
->host
);
3125 bgp_soft_reconfig_in(peer
, afi
, safi
);
3126 } else if (CHECK_FLAG(peer
->cap
,
3127 PEER_CAP_REFRESH_OLD_RCV
)
3128 || CHECK_FLAG(peer
->cap
,
3129 PEER_CAP_REFRESH_NEW_RCV
)) {
3130 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3132 "Processing route_map %s update on peer %s (inbound, route-refresh)",
3133 rmap_name
, peer
->host
);
3134 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3141 * For outbound, unsuppress and default-originate map change (content or
3142 * map created), merely update the "config" here, the actual route
3143 * announcement happens at the group level.
3145 if (filter
->map
[RMAP_OUT
].name
3146 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3147 filter
->map
[RMAP_OUT
].map
= map
;
3149 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3150 filter
->usmap
.map
= map
;
3152 if (peer
->default_rmap
[afi
][safi
].name
3153 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3154 peer
->default_rmap
[afi
][safi
].map
= map
;
3157 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3158 struct route_map
*map
,
3161 struct peer_group
*group
;
3162 struct listnode
*node
, *nnode
;
3163 struct bgp_filter
*filter
;
3170 /* All the peers have been updated correctly already. This is
3171 * just updating the placeholder data. No real update required.
3173 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3174 FOREACH_AFI_SAFI (afi
, safi
) {
3175 filter
= &group
->conf
->filter
[afi
][safi
];
3177 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3178 if ((filter
->map
[direct
].name
)
3179 && (strcmp(rmap_name
,
3180 filter
->map
[direct
].name
)
3182 filter
->map
[direct
].map
= map
;
3185 if (filter
->usmap
.name
3186 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3187 filter
->usmap
.map
= map
;
3193 * Note that if an extreme number (tens of thousands) of route-maps are in use
3194 * and if bgp has an extreme number of peers, network statements, etc then this
3195 * function can consume a lot of cycles. This is due to this function being
3196 * called for each route-map and within this function we walk the list of peers,
3197 * network statements, etc looking to see if they use this route-map.
3199 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3206 struct bgp_node
*bn
;
3207 struct bgp_static
*bgp_static
;
3208 struct listnode
*node
, *nnode
;
3209 struct route_map
*map
;
3210 char buf
[INET6_ADDRSTRLEN
];
3212 map
= route_map_lookup_by_name(rmap_name
);
3214 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3216 /* Ignore dummy peer-group structure */
3217 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3220 FOREACH_AFI_SAFI (afi
, safi
) {
3221 /* process in/out/import/export/default-orig
3223 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3224 safi
, route_update
);
3228 /* for outbound/default-orig route-maps, process for groups */
3229 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3232 /* update peer-group config (template) */
3233 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3235 FOREACH_AFI_SAFI (afi
, safi
) {
3236 /* For table route-map updates. */
3237 if (!bgp_fibupd_safi(safi
))
3240 if (bgp
->table_map
[afi
][safi
].name
3241 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3244 /* bgp->table_map[afi][safi].map is NULL.
3245 * i.e Route map creation event.
3246 * So update applied_counter.
3247 * If it is not NULL, i.e It may be routemap updation or
3248 * deletion. so no need to update the counter.
3250 if (!bgp
->table_map
[afi
][safi
].map
)
3251 route_map_counter_increment(map
);
3252 bgp
->table_map
[afi
][safi
].map
= map
;
3254 if (BGP_DEBUG(zebra
, ZEBRA
))
3256 "Processing route_map %s update on "
3260 bgp_zebra_announce_table(bgp
, afi
, safi
);
3263 /* For network route-map updates. */
3264 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3265 bn
= bgp_route_next(bn
)) {
3266 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3270 if (!bgp_static
->rmap
.name
3271 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3274 if (!bgp_static
->rmap
.map
)
3275 route_map_counter_increment(map
);
3277 bgp_static
->rmap
.map
= map
;
3279 if (route_update
&& !bgp_static
->backdoor
) {
3280 if (bgp_debug_zebra(&bn
->p
))
3282 "Processing route_map %s update on static route %s",
3284 inet_ntop(bn
->p
.family
,
3285 &bn
->p
.u
.prefix
, buf
,
3287 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3293 /* For redistribute route-map updates. */
3294 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3295 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3296 struct list
*red_list
;
3297 struct bgp_redist
*red
;
3299 red_list
= bgp
->redist
[afi
][i
];
3303 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3305 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3309 route_map_counter_increment(map
);
3311 red
->rmap
.map
= map
;
3316 if (BGP_DEBUG(zebra
, ZEBRA
))
3318 "Processing route_map %s update on redistributed routes",
3321 bgp_redistribute_resend(bgp
, afi
, i
,
3326 /* for type5 command route-maps */
3327 FOREACH_AFI_SAFI (afi
, safi
) {
3328 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3329 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3333 /* Make sure the route-map is populated here if not already done */
3334 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3336 if (BGP_DEBUG(zebra
, ZEBRA
))
3338 "Processing route_map %s update on advertise type5 route command",
3341 if (route_update
&& advertise_type5_routes(bgp
, afi
)) {
3342 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3343 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3348 static void bgp_route_map_process_update_cb(char *rmap_name
)
3350 struct listnode
*node
, *nnode
;
3353 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3354 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3357 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3358 vnc_routemap_update(bgp
, __func__
);
3362 vpn_policy_routemap_event(rmap_name
);
3365 int bgp_route_map_update_timer(struct thread
*thread
)
3367 bm
->t_rmap_update
= NULL
;
3369 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3374 static void bgp_route_map_mark_update(const char *rmap_name
)
3376 if (bm
->t_rmap_update
== NULL
) {
3377 struct listnode
*node
, *nnode
;
3380 /* rmap_update_timer of 0 means don't do route updates */
3381 if (bm
->rmap_update_timer
) {
3382 bm
->t_rmap_update
= NULL
;
3383 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3384 NULL
, bm
->rmap_update_timer
,
3385 &bm
->t_rmap_update
);
3387 /* Signal the groups that a route-map update event has
3389 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3390 update_group_policy_update(bgp
,
3391 BGP_POLICY_ROUTE_MAP
,
3394 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3395 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3397 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3398 vnc_routemap_update(bgp
, __func__
);
3404 static void bgp_route_map_add(const char *rmap_name
)
3406 if (route_map_mark_updated(rmap_name
) == 0)
3407 bgp_route_map_mark_update(rmap_name
);
3409 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3412 static void bgp_route_map_delete(const char *rmap_name
)
3414 if (route_map_mark_updated(rmap_name
) == 0)
3415 bgp_route_map_mark_update(rmap_name
);
3417 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3420 static void bgp_route_map_event(const char *rmap_name
)
3422 if (route_map_mark_updated(rmap_name
) == 0)
3423 bgp_route_map_mark_update(rmap_name
);
3425 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3428 DEFUN (match_mac_address
,
3429 match_mac_address_cmd
,
3430 "match mac address WORD",
3433 "Match address of route\n"
3434 "MAC Access-list name\n")
3436 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3437 RMAP_EVENT_FILTER_ADDED
);
3440 DEFUN (no_match_mac_address
,
3441 no_match_mac_address_cmd
,
3442 "no match mac address WORD",
3446 "Match address of route\n"
3447 "MAC acess-list name\n")
3449 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3450 RMAP_EVENT_FILTER_DELETED
);
3453 DEFUN (match_evpn_route_type
,
3454 match_evpn_route_type_cmd
,
3455 "match evpn route-type <macip | multicast | prefix>",
3458 "Match route-type\n"
3463 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3464 RMAP_EVENT_MATCH_ADDED
);
3467 DEFUN (no_match_evpn_route_type
,
3468 no_match_evpn_route_type_cmd
,
3469 "no match evpn route-type <macip | multicast | prefix>",
3473 "Match route-type\n"
3478 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3479 RMAP_EVENT_MATCH_DELETED
);
3483 DEFUN (match_evpn_vni
,
3485 "match evpn vni " CMD_VNI_RANGE
,
3491 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3492 RMAP_EVENT_MATCH_ADDED
);
3495 DEFUN (no_match_evpn_vni
,
3496 no_match_evpn_vni_cmd
,
3497 "no match evpn vni " CMD_VNI_RANGE
,
3504 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3505 RMAP_EVENT_MATCH_DELETED
);
3508 DEFUN (match_evpn_default_route
,
3509 match_evpn_default_route_cmd
,
3510 "match evpn default-route",
3513 "default EVPN type-5 route\n")
3515 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3516 RMAP_EVENT_MATCH_ADDED
);
3519 DEFUN (no_match_evpn_default_route
,
3520 no_match_evpn_default_route_cmd
,
3521 "no match evpn default-route",
3525 "default EVPN type-5 route\n")
3527 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3528 RMAP_EVENT_MATCH_DELETED
);
3531 DEFPY(match_vrl_source_vrf
,
3532 match_vrl_source_vrf_cmd
,
3533 "match source-vrf NAME$vrf_name",
3538 return bgp_route_match_add(vty
, "source-vrf", vrf_name
,
3539 RMAP_EVENT_MATCH_ADDED
);
3542 DEFPY(no_match_vrl_source_vrf
,
3543 no_match_vrl_source_vrf_cmd
,
3544 "no match source-vrf NAME$vrf_name",
3550 return bgp_route_match_delete(vty
, "source-vrf", vrf_name
,
3551 RMAP_EVENT_MATCH_DELETED
);
3556 "match peer <A.B.C.D|X:X::X:X|WORD>",
3558 "Match peer address\n"
3559 "IP address of peer\n"
3560 "IPv6 address of peer\n"
3561 "Interface name of peer\n")
3564 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3565 RMAP_EVENT_MATCH_ADDED
);
3568 DEFUN (match_peer_local
,
3569 match_peer_local_cmd
,
3572 "Match peer address\n"
3573 "Static or Redistributed routes\n")
3575 return bgp_route_match_add(vty
, "peer", "local",
3576 RMAP_EVENT_MATCH_DELETED
);
3579 DEFUN (no_match_peer
,
3581 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3584 "Match peer address\n"
3585 "Static or Redistributed routes\n"
3586 "IP address of peer\n"
3587 "IPv6 address of peer\n"
3588 "Interface name of peer\n")
3592 if (argc
<= idx_peer
)
3593 return bgp_route_match_delete(vty
, "peer", NULL
,
3594 RMAP_EVENT_MATCH_DELETED
);
3595 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3596 RMAP_EVENT_MATCH_DELETED
);
3599 #if defined(HAVE_LUA)
3600 DEFUN (match_command
,
3602 "match command WORD",
3604 "Run a command to match\n"
3605 "The command to run\n")
3607 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3608 RMAP_EVENT_FILTER_ADDED
);
3611 DEFUN (no_match_command
,
3612 no_match_command_cmd
,
3613 "no match command WORD",
3616 "Run a command to match\n"
3617 "The command to run\n")
3619 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3620 RMAP_EVENT_FILTER_DELETED
);
3624 /* match probability */
3625 DEFUN (match_probability
,
3626 match_probability_cmd
,
3627 "match probability (0-100)",
3629 "Match portion of routes defined by percentage value\n"
3630 "Percentage of routes\n")
3633 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3634 RMAP_EVENT_MATCH_ADDED
);
3638 DEFUN (no_match_probability
,
3639 no_match_probability_cmd
,
3640 "no match probability [(1-99)]",
3643 "Match portion of routes defined by percentage value\n"
3644 "Percentage of routes\n")
3647 if (argc
<= idx_number
)
3648 return bgp_route_match_delete(vty
, "probability", NULL
,
3649 RMAP_EVENT_MATCH_DELETED
);
3650 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3651 RMAP_EVENT_MATCH_DELETED
);
3655 DEFUN (match_ip_route_source
,
3656 match_ip_route_source_cmd
,
3657 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3660 "Match advertising source address of route\n"
3661 "IP access-list number\n"
3662 "IP access-list number (expanded range)\n"
3663 "IP standard access-list name\n")
3666 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3667 RMAP_EVENT_FILTER_ADDED
);
3671 DEFUN (no_match_ip_route_source
,
3672 no_match_ip_route_source_cmd
,
3673 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3677 "Match advertising source address of route\n"
3678 "IP access-list number\n"
3679 "IP access-list number (expanded range)\n"
3680 "IP standard access-list name\n")
3683 if (argc
<= idx_number
)
3684 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3685 RMAP_EVENT_FILTER_DELETED
);
3686 return bgp_route_match_delete(vty
, "ip route-source",
3687 argv
[idx_number
]->arg
,
3688 RMAP_EVENT_FILTER_DELETED
);
3692 DEFUN (match_ip_route_source_prefix_list
,
3693 match_ip_route_source_prefix_list_cmd
,
3694 "match ip route-source prefix-list WORD",
3697 "Match advertising source address of route\n"
3698 "Match entries of prefix-lists\n"
3699 "IP prefix-list name\n")
3702 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3703 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3707 DEFUN (no_match_ip_route_source_prefix_list
,
3708 no_match_ip_route_source_prefix_list_cmd
,
3709 "no match ip route-source prefix-list [WORD]",
3713 "Match advertising source address of route\n"
3714 "Match entries of prefix-lists\n"
3715 "IP prefix-list name\n")
3718 if (argc
<= idx_word
)
3719 return bgp_route_match_delete(vty
,
3720 "ip route-source prefix-list",
3721 NULL
, RMAP_EVENT_PLIST_DELETED
);
3722 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3723 argv
[idx_word
]->arg
,
3724 RMAP_EVENT_PLIST_DELETED
);
3728 DEFUN (match_local_pref
,
3729 match_local_pref_cmd
,
3730 "match local-preference (0-4294967295)",
3732 "Match local-preference of route\n"
3736 return bgp_route_match_add(vty
, "local-preference",
3737 argv
[idx_number
]->arg
,
3738 RMAP_EVENT_MATCH_ADDED
);
3742 DEFUN (no_match_local_pref
,
3743 no_match_local_pref_cmd
,
3744 "no match local-preference [(0-4294967295)]",
3747 "Match local preference of route\n"
3748 "Local preference value\n")
3750 int idx_localpref
= 3;
3751 if (argc
<= idx_localpref
)
3752 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3753 RMAP_EVENT_MATCH_DELETED
);
3754 return bgp_route_match_delete(vty
, "local-preference",
3755 argv
[idx_localpref
]->arg
,
3756 RMAP_EVENT_MATCH_DELETED
);
3760 DEFUN (match_community
,
3761 match_community_cmd
,
3762 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3764 "Match BGP community list\n"
3765 "Community-list number (standard)\n"
3766 "Community-list number (expanded)\n"
3767 "Community-list name\n"
3768 "Do exact matching of communities\n")
3770 int idx_comm_list
= 2;
3775 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3776 strlen(argv
[idx_comm_list
]->arg
)
3777 + strlen("exact-match") + 2);
3779 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3781 argstr
= argv
[idx_comm_list
]->arg
;
3783 ret
= bgp_route_match_add(vty
, "community", argstr
,
3784 RMAP_EVENT_CLIST_ADDED
);
3786 if (argstr
!= argv
[idx_comm_list
]->arg
)
3787 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3792 DEFUN (no_match_community
,
3793 no_match_community_cmd
,
3794 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3797 "Match BGP community list\n"
3798 "Community-list number (standard)\n"
3799 "Community-list number (expanded)\n"
3800 "Community-list name\n"
3801 "Do exact matching of communities\n")
3803 return bgp_route_match_delete(vty
, "community", NULL
,
3804 RMAP_EVENT_CLIST_DELETED
);
3807 DEFUN (match_lcommunity
,
3808 match_lcommunity_cmd
,
3809 "match large-community <(1-99)|(100-500)|WORD> [exact-match]",
3811 "Match BGP large community list\n"
3812 "Large Community-list number (standard)\n"
3813 "Large Community-list number (expanded)\n"
3814 "Large Community-list name\n"
3815 "Do exact matching of communities\n")
3817 int idx_lcomm_list
= 2;
3822 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3823 strlen(argv
[idx_lcomm_list
]->arg
)
3824 + strlen("exact-match") + 2);
3826 sprintf(argstr
, "%s exact-match", argv
[idx_lcomm_list
]->arg
);
3828 argstr
= argv
[idx_lcomm_list
]->arg
;
3830 ret
= bgp_route_match_add(vty
, "large-community", argstr
,
3831 RMAP_EVENT_LLIST_ADDED
);
3832 if (argstr
!= argv
[idx_lcomm_list
]->arg
)
3833 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3838 DEFUN (no_match_lcommunity
,
3839 no_match_lcommunity_cmd
,
3840 "no match large-community [<(1-99)|(100-500)|WORD> [exact-match]]",
3843 "Match BGP large community list\n"
3844 "Large Community-list number (standard)\n"
3845 "Large Community-list number (expanded)\n"
3846 "Large Community-list name\n"
3847 "Do exact matching of communities\n")
3849 return bgp_route_match_delete(vty
, "large-community", NULL
,
3850 RMAP_EVENT_LLIST_DELETED
);
3853 DEFUN (match_ecommunity
,
3854 match_ecommunity_cmd
,
3855 "match extcommunity <(1-99)|(100-500)|WORD>",
3857 "Match BGP/VPN extended community list\n"
3858 "Extended community-list number (standard)\n"
3859 "Extended community-list number (expanded)\n"
3860 "Extended community-list name\n")
3862 int idx_comm_list
= 2;
3863 return bgp_route_match_add(vty
, "extcommunity",
3864 argv
[idx_comm_list
]->arg
,
3865 RMAP_EVENT_ECLIST_ADDED
);
3869 DEFUN (no_match_ecommunity
,
3870 no_match_ecommunity_cmd
,
3871 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3874 "Match BGP/VPN extended community list\n"
3875 "Extended community-list number (standard)\n"
3876 "Extended community-list number (expanded)\n"
3877 "Extended community-list name\n")
3879 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3880 RMAP_EVENT_ECLIST_DELETED
);
3884 DEFUN (match_aspath
,
3886 "match as-path WORD",
3888 "Match BGP AS path list\n"
3889 "AS path access-list name\n")
3892 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3893 RMAP_EVENT_ASLIST_ADDED
);
3897 DEFUN (no_match_aspath
,
3898 no_match_aspath_cmd
,
3899 "no match as-path [WORD]",
3902 "Match BGP AS path list\n"
3903 "AS path access-list name\n")
3905 return bgp_route_match_delete(vty
, "as-path", NULL
,
3906 RMAP_EVENT_ASLIST_DELETED
);
3910 DEFUN (match_origin
,
3912 "match origin <egp|igp|incomplete>",
3917 "unknown heritage\n")
3920 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3921 return bgp_route_match_add(vty
, "origin", "igp",
3922 RMAP_EVENT_MATCH_ADDED
);
3923 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3924 return bgp_route_match_add(vty
, "origin", "egp",
3925 RMAP_EVENT_MATCH_ADDED
);
3926 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3927 return bgp_route_match_add(vty
, "origin", "incomplete",
3928 RMAP_EVENT_MATCH_ADDED
);
3930 vty_out(vty
, "%% Invalid match origin type\n");
3931 return CMD_WARNING_CONFIG_FAILED
;
3935 DEFUN (no_match_origin
,
3936 no_match_origin_cmd
,
3937 "no match origin [<egp|igp|incomplete>]",
3943 "unknown heritage\n")
3945 return bgp_route_match_delete(vty
, "origin", NULL
,
3946 RMAP_EVENT_MATCH_DELETED
);
3949 DEFUN (set_ip_nexthop_peer
,
3950 set_ip_nexthop_peer_cmd
,
3951 "[no] set ip next-hop peer-address",
3955 "Next hop address\n"
3956 "Use peer address (for BGP only)\n")
3958 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3959 const char *) = strmatch(argv
[0]->text
, "no")
3960 ? generic_set_delete
3963 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3967 DEFUN (set_ip_nexthop_unchanged
,
3968 set_ip_nexthop_unchanged_cmd
,
3969 "[no] set ip next-hop unchanged",
3973 "Next hop address\n"
3974 "Don't modify existing Next hop address\n")
3976 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3977 const char *) = strmatch(argv
[0]->text
, "no")
3978 ? generic_set_delete
3981 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3986 DEFUN (set_local_pref
,
3988 "set local-preference (0-4294967295)",
3990 "BGP local preference path attribute\n"
3991 "Preference value\n")
3994 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3995 "local-preference", argv
[idx_number
]->arg
);
3999 DEFUN (no_set_local_pref
,
4000 no_set_local_pref_cmd
,
4001 "no set local-preference [(0-4294967295)]",
4004 "BGP local preference path attribute\n"
4005 "Preference value\n")
4007 int idx_localpref
= 3;
4008 if (argc
<= idx_localpref
)
4009 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4010 "local-preference", NULL
);
4011 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4012 "local-preference", argv
[idx_localpref
]->arg
);
4018 "set weight (0-4294967295)",
4020 "BGP weight for routing table\n"
4024 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
4025 argv
[idx_number
]->arg
);
4029 DEFUN (no_set_weight
,
4031 "no set weight [(0-4294967295)]",
4034 "BGP weight for routing table\n"
4038 if (argc
<= idx_weight
)
4039 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4041 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4042 "weight", argv
[idx_weight
]->arg
);
4045 DEFUN (set_label_index
,
4046 set_label_index_cmd
,
4047 "set label-index (0-1048560)",
4049 "Label index to associate with the prefix\n"
4050 "Label index value\n")
4053 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4054 "label-index", argv
[idx_number
]->arg
);
4057 DEFUN (no_set_label_index
,
4058 no_set_label_index_cmd
,
4059 "no set label-index [(0-1048560)]",
4062 "Label index to associate with the prefix\n"
4063 "Label index value\n")
4065 int idx_label_index
= 3;
4066 if (argc
<= idx_label_index
)
4067 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4068 "label-index", NULL
);
4069 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4070 "label-index", argv
[idx_label_index
]->arg
);
4073 DEFUN (set_aspath_prepend_asn
,
4074 set_aspath_prepend_asn_cmd
,
4075 "set as-path prepend (1-4294967295)...",
4077 "Transform BGP AS_PATH attribute\n"
4078 "Prepend to the as-path\n"
4085 str
= argv_concat(argv
, argc
, idx_asn
);
4086 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4087 "as-path prepend", str
);
4088 XFREE(MTYPE_TMP
, str
);
4093 DEFUN (set_aspath_prepend_lastas
,
4094 set_aspath_prepend_lastas_cmd
,
4095 "set as-path prepend last-as (1-10)",
4097 "Transform BGP AS_PATH attribute\n"
4098 "Prepend to the as-path\n"
4099 "Use the peer's AS-number\n"
4100 "Number of times to insert\n")
4102 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4105 DEFUN (no_set_aspath_prepend
,
4106 no_set_aspath_prepend_cmd
,
4107 "no set as-path prepend [(1-4294967295)]",
4110 "Transform BGP AS_PATH attribute\n"
4111 "Prepend to the as-path\n"
4118 str
= argv_concat(argv
, argc
, idx_asn
);
4119 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4120 "as-path prepend", str
);
4121 XFREE(MTYPE_TMP
, str
);
4126 DEFUN (set_aspath_exclude
,
4127 set_aspath_exclude_cmd
,
4128 "set as-path exclude (1-4294967295)...",
4130 "Transform BGP AS-path attribute\n"
4131 "Exclude from the as-path\n"
4138 str
= argv_concat(argv
, argc
, idx_asn
);
4139 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4140 "as-path exclude", str
);
4141 XFREE(MTYPE_TMP
, str
);
4145 DEFUN (no_set_aspath_exclude
,
4146 no_set_aspath_exclude_cmd
,
4147 "no set as-path exclude (1-4294967295)...",
4150 "Transform BGP AS_PATH attribute\n"
4151 "Exclude from the as-path\n"
4158 str
= argv_concat(argv
, argc
, idx_asn
);
4159 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4160 "as-path exclude", str
);
4161 XFREE(MTYPE_TMP
, str
);
4165 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4166 "no set as-path exclude",
4168 "Transform BGP AS_PATH attribute\n"
4169 "Exclude from the as-path\n")
4171 DEFUN (set_community
,
4173 "set community AA:NN...",
4175 "BGP community attribute\n"
4183 struct community
*com
= NULL
;
4188 b
= buffer_new(1024);
4190 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4191 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4198 buffer_putc(b
, ' ');
4202 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4204 buffer_putstr(b
, "internet");
4207 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4209 buffer_putstr(b
, "local-AS");
4212 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4213 && strncmp(argv
[i
]->arg
, "no-advertise",
4214 strlen(argv
[i
]->arg
))
4216 buffer_putstr(b
, "no-advertise");
4219 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4220 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4222 buffer_putstr(b
, "no-export");
4225 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4226 strlen(argv
[i
]->arg
))
4228 buffer_putstr(b
, "graceful-shutdown");
4231 buffer_putstr(b
, argv
[i
]->arg
);
4233 buffer_putc(b
, '\0');
4235 /* Fetch result string then compile it to communities attribute. */
4236 str
= buffer_getstr(b
);
4240 com
= community_str2com(str
);
4241 XFREE(MTYPE_TMP
, str
);
4244 /* Can't compile user input into communities attribute. */
4246 vty_out(vty
, "%% Malformed communities attribute\n");
4247 return CMD_WARNING_CONFIG_FAILED
;
4250 /* Set communites attribute string. */
4251 str
= community_str(com
, false);
4254 size_t argstr_sz
= strlen(str
) + strlen(" additive") + 1;
4255 argstr
= XCALLOC(MTYPE_TMP
, argstr_sz
);
4256 strlcpy(argstr
, str
, argstr_sz
);
4257 strlcat(argstr
, " additive", argstr_sz
);
4258 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4259 "community", argstr
);
4260 XFREE(MTYPE_TMP
, argstr
);
4262 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4265 community_free(&com
);
4270 DEFUN (set_community_none
,
4271 set_community_none_cmd
,
4272 "set community none",
4274 "BGP community attribute\n"
4275 "No community attribute\n")
4277 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4278 "community", "none");
4281 DEFUN (no_set_community
,
4282 no_set_community_cmd
,
4283 "no set community AA:NN...",
4286 "BGP community attribute\n"
4289 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4293 ALIAS (no_set_community
,
4294 no_set_community_short_cmd
,
4298 "BGP community attribute\n")
4301 DEFUN (set_community_delete
,
4302 set_community_delete_cmd
,
4303 "set comm-list <(1-99)|(100-500)|WORD> delete",
4305 "set BGP community list (for deletion)\n"
4306 "Community-list number (standard)\n"
4307 "Community-list number (expanded)\n"
4308 "Community-list name\n"
4309 "Delete matching communities\n")
4311 int idx_comm_list
= 2;
4313 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4314 argv
[idx_comm_list
]->arg
);
4319 DEFUN (no_set_community_delete
,
4320 no_set_community_delete_cmd
,
4321 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4324 "set BGP community list (for deletion)\n"
4325 "Community-list number (standard)\n"
4326 "Community-list number (expanded)\n"
4327 "Community-list name\n"
4328 "Delete matching communities\n")
4330 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4334 DEFUN (set_lcommunity
,
4336 "set large-community AA:BB:CC...",
4338 "BGP large community attribute\n"
4339 "Large Community number in aa:bb:cc format or additive\n")
4344 str
= argv_concat(argv
, argc
, 2);
4345 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4346 "large-community", str
);
4347 XFREE(MTYPE_TMP
, str
);
4352 DEFUN (set_lcommunity_none
,
4353 set_lcommunity_none_cmd
,
4354 "set large-community none",
4356 "BGP large community attribute\n"
4357 "No large community attribute\n")
4359 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4360 "large-community", "none");
4363 DEFUN (no_set_lcommunity
,
4364 no_set_lcommunity_cmd
,
4365 "no set large-community none",
4368 "BGP large community attribute\n"
4369 "No community attribute\n")
4371 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4372 "large-community", NULL
);
4375 DEFUN (no_set_lcommunity1
,
4376 no_set_lcommunity1_cmd
,
4377 "no set large-community AA:BB:CC...",
4380 "BGP large community attribute\n"
4381 "Large community in AA:BB:CC... format or additive\n")
4383 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4384 "large-community", NULL
);
4387 ALIAS (no_set_lcommunity1
,
4388 no_set_lcommunity1_short_cmd
,
4389 "no set large-community",
4392 "BGP large community attribute\n")
4394 DEFUN (set_lcommunity_delete
,
4395 set_lcommunity_delete_cmd
,
4396 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4398 "set BGP large community list (for deletion)\n"
4399 "Large Community-list number (standard)\n"
4400 "Large Communitly-list number (expanded)\n"
4401 "Large Community-list name\n"
4402 "Delete matching large communities\n")
4404 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4405 "large-comm-list", argv
[2]->arg
);
4410 DEFUN (no_set_lcommunity_delete
,
4411 no_set_lcommunity_delete_cmd
,
4412 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4415 "set BGP large community list (for deletion)\n"
4416 "Large Community-list number (standard)\n"
4417 "Large Communitly-list number (expanded)\n"
4418 "Large Community-list name\n"
4419 "Delete matching large communities\n")
4421 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4422 "large-comm-list", NULL
);
4425 ALIAS (no_set_lcommunity_delete
,
4426 no_set_lcommunity_delete_short_cmd
,
4427 "no set large-comm-list",
4430 "set BGP large community list (for deletion)\n")
4432 DEFUN (set_ecommunity_rt
,
4433 set_ecommunity_rt_cmd
,
4434 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4436 "BGP extended community attribute\n"
4437 "Route Target extended community\n"
4438 "VPN extended community\n")
4444 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4445 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4446 "extcommunity rt", str
);
4447 XFREE(MTYPE_TMP
, str
);
4452 DEFUN (no_set_ecommunity_rt
,
4453 no_set_ecommunity_rt_cmd
,
4454 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4457 "BGP extended community attribute\n"
4458 "Route Target extended community\n"
4459 "VPN extended community\n")
4461 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4462 "extcommunity rt", NULL
);
4465 ALIAS (no_set_ecommunity_rt
,
4466 no_set_ecommunity_rt_short_cmd
,
4467 "no set extcommunity rt",
4470 "BGP extended community attribute\n"
4471 "Route Target extended community\n")
4473 DEFUN (set_ecommunity_soo
,
4474 set_ecommunity_soo_cmd
,
4475 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4477 "BGP extended community attribute\n"
4478 "Site-of-Origin extended community\n"
4479 "VPN extended community\n")
4485 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4486 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4487 "extcommunity soo", str
);
4488 XFREE(MTYPE_TMP
, str
);
4493 DEFUN (no_set_ecommunity_soo
,
4494 no_set_ecommunity_soo_cmd
,
4495 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4498 "BGP extended community attribute\n"
4499 "Site-of-Origin extended community\n"
4500 "VPN extended community\n")
4502 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4503 "extcommunity soo", NULL
);
4506 ALIAS (no_set_ecommunity_soo
,
4507 no_set_ecommunity_soo_short_cmd
,
4508 "no set extcommunity soo",
4511 "GP extended community attribute\n"
4512 "Site-of-Origin extended community\n")
4516 "set origin <egp|igp|incomplete>",
4521 "unknown heritage\n")
4524 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4525 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4527 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4528 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4530 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4531 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4532 "origin", "incomplete");
4534 vty_out(vty
, "%% Invalid set origin type\n");
4535 return CMD_WARNING_CONFIG_FAILED
;
4539 DEFUN (no_set_origin
,
4541 "no set origin [<egp|igp|incomplete>]",
4547 "unknown heritage\n")
4549 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4554 DEFUN (set_atomic_aggregate
,
4555 set_atomic_aggregate_cmd
,
4556 "set atomic-aggregate",
4558 "BGP atomic aggregate attribute\n" )
4560 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4561 "atomic-aggregate", NULL
);
4564 DEFUN (no_set_atomic_aggregate
,
4565 no_set_atomic_aggregate_cmd
,
4566 "no set atomic-aggregate",
4569 "BGP atomic aggregate attribute\n" )
4571 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4572 "atomic-aggregate", NULL
);
4575 DEFUN (set_aggregator_as
,
4576 set_aggregator_as_cmd
,
4577 "set aggregator as (1-4294967295) A.B.C.D",
4579 "BGP aggregator attribute\n"
4580 "AS number of aggregator\n"
4582 "IP address of aggregator\n")
4587 struct in_addr address
;
4590 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4592 vty_out(vty
, "Aggregator IP address is invalid\n");
4593 return CMD_WARNING_CONFIG_FAILED
;
4596 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4597 strlen(argv
[idx_number
]->arg
)
4598 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4600 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4602 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4603 "aggregator as", argstr
);
4605 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4611 DEFUN (no_set_aggregator_as
,
4612 no_set_aggregator_as_cmd
,
4613 "no set aggregator as [(1-4294967295) A.B.C.D]",
4616 "BGP aggregator attribute\n"
4617 "AS number of aggregator\n"
4619 "IP address of aggregator\n")
4624 struct in_addr address
;
4627 if (argc
<= idx_asn
)
4628 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4629 "aggregator as", NULL
);
4631 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4633 vty_out(vty
, "Aggregator IP address is invalid\n");
4634 return CMD_WARNING_CONFIG_FAILED
;
4637 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4638 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4641 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4643 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4644 "aggregator as", argstr
);
4646 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4651 DEFUN (match_ipv6_next_hop
,
4652 match_ipv6_next_hop_cmd
,
4653 "match ipv6 next-hop X:X::X:X",
4656 "Match IPv6 next-hop address of route\n"
4657 "IPv6 address of next hop\n")
4660 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4661 RMAP_EVENT_MATCH_ADDED
);
4664 DEFUN (no_match_ipv6_next_hop
,
4665 no_match_ipv6_next_hop_cmd
,
4666 "no match ipv6 next-hop X:X::X:X",
4670 "Match IPv6 next-hop address of route\n"
4671 "IPv6 address of next hop\n")
4674 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4675 RMAP_EVENT_MATCH_DELETED
);
4679 DEFUN (set_ipv6_nexthop_peer
,
4680 set_ipv6_nexthop_peer_cmd
,
4681 "set ipv6 next-hop peer-address",
4684 "Next hop address\n"
4685 "Use peer address (for BGP only)\n")
4687 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4688 "ipv6 next-hop peer-address", NULL
);
4691 DEFUN (no_set_ipv6_nexthop_peer
,
4692 no_set_ipv6_nexthop_peer_cmd
,
4693 "no set ipv6 next-hop peer-address",
4697 "IPv6 next-hop address\n"
4698 "Use peer address (for BGP only)\n")
4700 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4701 "ipv6 next-hop peer-address", NULL
);
4704 DEFUN (set_ipv6_nexthop_prefer_global
,
4705 set_ipv6_nexthop_prefer_global_cmd
,
4706 "set ipv6 next-hop prefer-global",
4709 "IPv6 next-hop address\n"
4710 "Prefer global over link-local if both exist\n")
4712 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4713 "ipv6 next-hop prefer-global", NULL
);
4717 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4718 no_set_ipv6_nexthop_prefer_global_cmd
,
4719 "no set ipv6 next-hop prefer-global",
4723 "IPv6 next-hop address\n"
4724 "Prefer global over link-local if both exist\n")
4726 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4727 "ipv6 next-hop prefer-global", NULL
);
4730 DEFUN (set_ipv6_nexthop_global
,
4731 set_ipv6_nexthop_global_cmd
,
4732 "set ipv6 next-hop global X:X::X:X",
4735 "IPv6 next-hop address\n"
4736 "IPv6 global address\n"
4737 "IPv6 address of next hop\n")
4740 struct in6_addr addr
;
4743 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4745 vty_out(vty
, "%% Malformed nexthop address\n");
4746 return CMD_WARNING_CONFIG_FAILED
;
4748 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4749 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4750 vty_out(vty
, "%% Invalid global nexthop address\n");
4751 return CMD_WARNING_CONFIG_FAILED
;
4754 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4755 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4759 DEFUN (no_set_ipv6_nexthop_global
,
4760 no_set_ipv6_nexthop_global_cmd
,
4761 "no set ipv6 next-hop global X:X::X:X",
4765 "IPv6 next-hop address\n"
4766 "IPv6 global address\n"
4767 "IPv6 address of next hop\n")
4770 if (argc
<= idx_ipv6
)
4771 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4772 "ipv6 next-hop global", NULL
);
4773 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4774 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4777 #ifdef KEEP_OLD_VPN_COMMANDS
4778 DEFUN (set_vpn_nexthop
,
4779 set_vpn_nexthop_cmd
,
4780 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4782 "VPNv4 information\n"
4783 "VPN next-hop address\n"
4784 "IP address of next hop\n"
4785 "VPNv6 information\n"
4786 "VPN next-hop address\n"
4787 "IPv6 address of next hop\n")
4793 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4795 return generic_set_add(
4796 vty
, VTY_GET_CONTEXT(route_map_index
),
4797 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4799 return generic_set_add(
4800 vty
, VTY_GET_CONTEXT(route_map_index
),
4801 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4806 DEFUN (no_set_vpn_nexthop
,
4807 no_set_vpn_nexthop_cmd
,
4808 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4811 "VPNv4 information\n"
4812 "VPN next-hop address\n"
4813 "IP address of next hop\n"
4814 "VPNv6 information\n"
4815 "VPN next-hop address\n"
4816 "IPv6 address of next hop\n")
4826 arg
= argv
[idx_ip
]->arg
;
4827 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4829 return generic_set_delete(
4830 vty
, VTY_GET_CONTEXT(route_map_index
),
4831 "ipv4 vpn next-hop", arg
);
4833 return generic_set_delete(
4834 vty
, VTY_GET_CONTEXT(route_map_index
),
4835 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4839 #endif /* KEEP_OLD_VPN_COMMANDS */
4841 DEFUN (set_ipx_vpn_nexthop
,
4842 set_ipx_vpn_nexthop_cmd
,
4843 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4845 "IPv4 information\n"
4846 "IPv6 information\n"
4848 "VPN next-hop address\n"
4849 "IP address of next hop\n"
4850 "IPv6 address of next hop\n")
4856 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4858 return generic_set_add(
4859 vty
, VTY_GET_CONTEXT(route_map_index
),
4860 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4862 return generic_set_add(
4863 vty
, VTY_GET_CONTEXT(route_map_index
),
4864 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4869 DEFUN (no_set_ipx_vpn_nexthop
,
4870 no_set_ipx_vpn_nexthop_cmd
,
4871 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4874 "IPv4 information\n"
4875 "IPv6 information\n"
4877 "VPN next-hop address\n"
4878 "IP address of next hop\n"
4879 "IPv6 address of next hop\n")
4889 arg
= argv
[idx_ip
]->arg
;
4890 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4892 return generic_set_delete(
4893 vty
, VTY_GET_CONTEXT(route_map_index
),
4894 "ipv4 vpn next-hop", arg
);
4896 return generic_set_delete(
4897 vty
, VTY_GET_CONTEXT(route_map_index
),
4898 "ipv6 vpn next-hop", arg
);
4903 DEFUN (set_originator_id
,
4904 set_originator_id_cmd
,
4905 "set originator-id A.B.C.D",
4907 "BGP originator ID attribute\n"
4908 "IP address of originator\n")
4911 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4912 "originator-id", argv
[idx_ipv4
]->arg
);
4916 DEFUN (no_set_originator_id
,
4917 no_set_originator_id_cmd
,
4918 "no set originator-id [A.B.C.D]",
4921 "BGP originator ID attribute\n"
4922 "IP address of originator\n")
4926 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4928 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4929 "originator-id", arg
);
4933 /* Initialization of route map. */
4934 void bgp_route_map_init(void)
4938 route_map_add_hook(bgp_route_map_add
);
4939 route_map_delete_hook(bgp_route_map_delete
);
4940 route_map_event_hook(bgp_route_map_event
);
4942 route_map_match_interface_hook(generic_match_add
);
4943 route_map_no_match_interface_hook(generic_match_delete
);
4945 route_map_match_ip_address_hook(generic_match_add
);
4946 route_map_no_match_ip_address_hook(generic_match_delete
);
4948 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
4949 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
4951 route_map_match_ip_next_hop_hook(generic_match_add
);
4952 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
4954 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
4955 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
4957 route_map_match_ip_next_hop_type_hook(generic_match_add
);
4958 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
4960 route_map_match_ipv6_address_hook(generic_match_add
);
4961 route_map_no_match_ipv6_address_hook(generic_match_delete
);
4963 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
4964 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
4966 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
4967 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
4969 route_map_match_metric_hook(generic_match_add
);
4970 route_map_no_match_metric_hook(generic_match_delete
);
4972 route_map_match_tag_hook(generic_match_add
);
4973 route_map_no_match_tag_hook(generic_match_delete
);
4975 route_map_set_ip_nexthop_hook(generic_set_add
);
4976 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
4978 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
4979 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
4981 route_map_set_metric_hook(generic_set_add
);
4982 route_map_no_set_metric_hook(generic_set_delete
);
4984 route_map_set_tag_hook(generic_set_add
);
4985 route_map_no_set_tag_hook(generic_set_delete
);
4987 route_map_install_match(&route_match_peer_cmd
);
4988 route_map_install_match(&route_match_local_pref_cmd
);
4989 #if defined(HAVE_LUA)
4990 route_map_install_match(&route_match_command_cmd
);
4992 route_map_install_match(&route_match_ip_address_cmd
);
4993 route_map_install_match(&route_match_ip_next_hop_cmd
);
4994 route_map_install_match(&route_match_ip_route_source_cmd
);
4995 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
4996 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
4997 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
4998 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
4999 route_map_install_match(&route_match_aspath_cmd
);
5000 route_map_install_match(&route_match_community_cmd
);
5001 route_map_install_match(&route_match_lcommunity_cmd
);
5002 route_map_install_match(&route_match_ecommunity_cmd
);
5003 route_map_install_match(&route_match_local_pref_cmd
);
5004 route_map_install_match(&route_match_metric_cmd
);
5005 route_map_install_match(&route_match_origin_cmd
);
5006 route_map_install_match(&route_match_probability_cmd
);
5007 route_map_install_match(&route_match_interface_cmd
);
5008 route_map_install_match(&route_match_tag_cmd
);
5009 route_map_install_match(&route_match_mac_address_cmd
);
5010 route_map_install_match(&route_match_evpn_vni_cmd
);
5011 route_map_install_match(&route_match_evpn_route_type_cmd
);
5012 route_map_install_match(&route_match_evpn_default_route_cmd
);
5013 route_map_install_match(&route_match_vrl_source_vrf_cmd
);
5015 route_map_install_set(&route_set_ip_nexthop_cmd
);
5016 route_map_install_set(&route_set_local_pref_cmd
);
5017 route_map_install_set(&route_set_weight_cmd
);
5018 route_map_install_set(&route_set_label_index_cmd
);
5019 route_map_install_set(&route_set_metric_cmd
);
5020 route_map_install_set(&route_set_aspath_prepend_cmd
);
5021 route_map_install_set(&route_set_aspath_exclude_cmd
);
5022 route_map_install_set(&route_set_origin_cmd
);
5023 route_map_install_set(&route_set_atomic_aggregate_cmd
);
5024 route_map_install_set(&route_set_aggregator_as_cmd
);
5025 route_map_install_set(&route_set_community_cmd
);
5026 route_map_install_set(&route_set_community_delete_cmd
);
5027 route_map_install_set(&route_set_lcommunity_cmd
);
5028 route_map_install_set(&route_set_lcommunity_delete_cmd
);
5029 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
5030 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
5031 route_map_install_set(&route_set_originator_id_cmd
);
5032 route_map_install_set(&route_set_ecommunity_rt_cmd
);
5033 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5034 route_map_install_set(&route_set_tag_cmd
);
5035 route_map_install_set(&route_set_label_index_cmd
);
5037 install_element(RMAP_NODE
, &match_peer_cmd
);
5038 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5039 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5040 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5041 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5042 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5043 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5044 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5045 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5046 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5047 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5048 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5049 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5050 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5051 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5052 install_element(RMAP_NODE
, &match_vrl_source_vrf_cmd
);
5053 install_element(RMAP_NODE
, &no_match_vrl_source_vrf_cmd
);
5055 install_element(RMAP_NODE
, &match_aspath_cmd
);
5056 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5057 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5058 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5059 install_element(RMAP_NODE
, &match_community_cmd
);
5060 install_element(RMAP_NODE
, &no_match_community_cmd
);
5061 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5062 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5063 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5064 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5065 install_element(RMAP_NODE
, &match_origin_cmd
);
5066 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5067 install_element(RMAP_NODE
, &match_probability_cmd
);
5068 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5070 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5071 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5072 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5073 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5074 install_element(RMAP_NODE
, &set_weight_cmd
);
5075 install_element(RMAP_NODE
, &set_label_index_cmd
);
5076 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5077 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5078 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5079 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5080 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5081 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5082 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5083 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5084 install_element(RMAP_NODE
, &set_origin_cmd
);
5085 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5086 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5087 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5088 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5089 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5090 install_element(RMAP_NODE
, &set_community_cmd
);
5091 install_element(RMAP_NODE
, &set_community_none_cmd
);
5092 install_element(RMAP_NODE
, &no_set_community_cmd
);
5093 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5094 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5095 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5096 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5097 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5098 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5099 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5100 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5101 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5102 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5103 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5104 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5105 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5106 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5107 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5108 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5109 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5110 #ifdef KEEP_OLD_VPN_COMMANDS
5111 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5112 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5113 #endif /* KEEP_OLD_VPN_COMMANDS */
5114 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5115 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5116 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5117 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5119 route_map_install_match(&route_match_ipv6_address_cmd
);
5120 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5121 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5122 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5123 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5124 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5125 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5126 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5128 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5129 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5130 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5131 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5132 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5133 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5134 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5135 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5136 #if defined(HAVE_LUA)
5137 install_element(RMAP_NODE
, &match_command_cmd
);
5138 install_element(RMAP_NODE
, &no_match_command_cmd
);
5142 void bgp_route_map_terminate(void)
5144 /* ToDo: Cleanup all the used memory */