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 /* Memo of route-map commands.
77 ip route-source : Done
81 ipv6 route-source: (This will not be implemented by bgpd)
82 ipv6 prefix-list : Done
83 length : (This will not be implemented by bgpd)
85 route-type : (This will not be implemented by bgpd)
87 local-preference : Done
89 set as-path prepend : Done
91 automatic-tag : (This will not be implemented by bgpd)
93 large-community : Done
94 large-comm-list : Done
97 default : (This will not be implemented by bgpd)
98 interface : (This will not be implemented by bgpd)
99 ip default : (This will not be implemented by bgpd)
101 ip precedence : (This will not be implemented by bgpd)
102 ip tos : (This will not be implemented by bgpd)
103 level : (This will not be implemented by bgpd)
104 local-preference : Done
106 metric-type : Not yet
113 set ipv6 next-hop global: Done
114 set ipv6 next-hop prefer-global: Done
115 set ipv6 next-hop local : Done
116 set as-path exclude : Done
120 /* generic value manipulation to be shared in multiple rules */
122 #define RMAP_VALUE_SET 0
123 #define RMAP_VALUE_ADD 1
124 #define RMAP_VALUE_SUB 2
132 static int route_value_match(struct rmap_value
*rv
, uint32_t value
)
134 if (rv
->variable
== 0 && value
== rv
->value
)
140 static uint32_t route_value_adjust(struct rmap_value
*rv
, uint32_t current
,
145 switch (rv
->variable
) {
154 switch (rv
->action
) {
156 if (current
> UINT32_MAX
- value
)
158 return current
+ value
;
160 if (current
<= value
)
162 return current
- value
;
168 static void *route_value_compile(const char *arg
)
170 uint8_t action
= RMAP_VALUE_SET
, var
= 0;
171 unsigned long larg
= 0;
173 struct rmap_value
*rv
;
176 action
= RMAP_VALUE_ADD
;
178 } else if (arg
[0] == '-') {
179 action
= RMAP_VALUE_SUB
;
183 if (all_digit(arg
)) {
185 larg
= strtoul(arg
, &endptr
, 10);
186 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
189 if (strcmp(arg
, "rtt") == 0)
195 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
205 static void route_value_free(void *rule
)
207 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
210 /* generic as path object to be shared in multiple rules */
212 static void *route_aspath_compile(const char *arg
)
214 struct aspath
*aspath
;
216 aspath
= aspath_str2aspath(arg
);
222 static void route_aspath_free(void *rule
)
224 struct aspath
*aspath
= rule
;
228 struct bgp_match_peer_compiled
{
233 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
235 /* Compares the peer specified in the 'match peer' clause with the peer
236 received in bgp_path_info->peer. If it is the same, or if the peer structure
237 received is a peer_group containing it, returns RMAP_MATCH. */
238 static route_map_result_t
route_match_peer(void *rule
,
239 const struct prefix
*prefix
,
240 route_map_object_t type
,
243 struct bgp_match_peer_compiled
*pc
;
245 union sockunion su_def
= {
246 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
247 struct peer_group
*group
;
249 struct listnode
*node
, *nnode
;
251 if (type
== RMAP_BGP
) {
254 peer
= ((struct bgp_path_info
*)object
)->peer
;
260 if (strcmp(peer
->conf_if
, pc
->interface
) == 0)
266 /* If su='0.0.0.0' (command 'match peer local'), and it's a
268 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH
270 if (sockunion_same(su
, &su_def
)) {
272 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
273 || CHECK_FLAG(peer
->rmap_type
,
274 PEER_RMAP_TYPE_REDISTRIBUTE
)
275 || CHECK_FLAG(peer
->rmap_type
,
276 PEER_RMAP_TYPE_DEFAULT
))
283 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
284 if (sockunion_same(su
, &peer
->su
))
290 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
292 if (sockunion_same(su
, &peer
->su
))
301 static void *route_match_peer_compile(const char *arg
)
303 struct bgp_match_peer_compiled
*pc
;
306 pc
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
307 sizeof(struct bgp_match_peer_compiled
));
309 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
311 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
318 /* Free route map's compiled `ip address' value. */
319 static void route_match_peer_free(void *rule
)
321 struct bgp_match_peer_compiled
*pc
= rule
;
324 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
326 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
329 /* Route map commands for ip address matching. */
330 struct route_map_rule_cmd route_match_peer_cmd
= {"peer", route_match_peer
,
331 route_match_peer_compile
,
332 route_match_peer_free
};
334 #if defined(HAVE_LUA)
335 static route_map_result_t
route_match_command(void *rule
,
336 const struct prefix
*prefix
,
337 route_map_object_t type
,
340 int status
= RMAP_NOMATCH
;
341 u_int32_t locpref
= 0;
342 u_int32_t newlocpref
= 0;
343 enum lua_rm_status lrm_status
;
344 struct bgp_path_info
*path
= (struct bgp_path_info
*)object
;
345 lua_State
*L
= lua_initialize("/etc/frr/lua.scr");
351 * Setup the prefix information to pass in
353 lua_setup_prefix_table(L
, prefix
);
355 zlog_debug("Set up prefix table");
357 * Setup the bgp_path_info information
360 lua_pushinteger(L
, path
->attr
->med
);
361 lua_setfield(L
, -2, "metric");
362 lua_pushinteger(L
, path
->attr
->nh_ifindex
);
363 lua_setfield(L
, -2, "ifindex");
364 lua_pushstring(L
, path
->attr
->aspath
->str
);
365 lua_setfield(L
, -2, "aspath");
366 lua_pushinteger(L
, path
->attr
->local_pref
);
367 lua_setfield(L
, -2, "localpref");
368 zlog_debug("%s %d", path
->attr
->aspath
->str
, path
->attr
->nh_ifindex
);
369 lua_setglobal(L
, "nexthop");
371 zlog_debug("Set up nexthop information");
375 lrm_status
= lua_run_rm_rule(L
, rule
);
376 switch (lrm_status
) {
378 zlog_debug("RM_FAILURE");
381 zlog_debug("RM_NOMATCH");
383 case LUA_RM_MATCH_AND_CHANGE
:
384 zlog_debug("MATCH AND CHANGE");
385 lua_getglobal(L
, "nexthop");
386 path
->attr
->med
= get_integer(L
, "metric");
388 * This needs to be abstraced with the set function
390 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
391 locpref
= path
->attr
->local_pref
;
392 newlocpref
= get_integer(L
, "localpref");
393 if (newlocpref
!= locpref
) {
394 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
395 path
->attr
->local_pref
= newlocpref
;
400 zlog_debug("MATCH ONLY");
408 static void *route_match_command_compile(const char *arg
)
412 command
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
417 route_match_command_free(void *rule
)
419 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
422 struct route_map_rule_cmd route_match_command_cmd
= {
425 route_match_command_compile
,
426 route_match_command_free
430 /* `match ip address IP_ACCESS_LIST' */
432 /* Match function should return 1 if match is success else return
434 static route_map_result_t
route_match_ip_address(void *rule
,
435 const struct prefix
*prefix
,
436 route_map_object_t type
,
439 struct access_list
*alist
;
441 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
442 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
446 return (access_list_apply(alist
, prefix
) == FILTER_DENY
453 /* Route map `ip address' match statement. `arg' should be
455 static void *route_match_ip_address_compile(const char *arg
)
457 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
460 /* Free route map's compiled `ip address' value. */
461 static void route_match_ip_address_free(void *rule
)
463 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
466 /* Route map commands for ip address matching. */
467 struct route_map_rule_cmd route_match_ip_address_cmd
= {
468 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
469 route_match_ip_address_free
};
471 /* `match ip next-hop IP_ADDRESS' */
473 /* Match function return 1 if match is success else return zero. */
474 static route_map_result_t
route_match_ip_next_hop(void *rule
,
475 const struct prefix
*prefix
,
476 route_map_object_t type
,
479 struct access_list
*alist
;
480 struct bgp_path_info
*path
;
481 struct prefix_ipv4 p
;
483 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
486 p
.prefix
= path
->attr
->nexthop
;
487 p
.prefixlen
= IPV4_MAX_BITLEN
;
489 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
493 return (access_list_apply(alist
, &p
) == FILTER_DENY
500 /* Route map `ip next-hop' match statement. `arg' is
502 static void *route_match_ip_next_hop_compile(const char *arg
)
504 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
507 /* Free route map's compiled `ip address' value. */
508 static void route_match_ip_next_hop_free(void *rule
)
510 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
513 /* Route map commands for ip next-hop matching. */
514 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
515 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
516 route_match_ip_next_hop_free
};
518 /* `match ip route-source ACCESS-LIST' */
520 /* Match function return 1 if match is success else return zero. */
521 static route_map_result_t
route_match_ip_route_source(void *rule
,
522 const struct prefix
*pfx
,
523 route_map_object_t type
,
526 struct access_list
*alist
;
527 struct bgp_path_info
*path
;
529 struct prefix_ipv4 p
;
531 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
535 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
539 p
.prefix
= peer
->su
.sin
.sin_addr
;
540 p
.prefixlen
= IPV4_MAX_BITLEN
;
542 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
546 return (access_list_apply(alist
, &p
) == FILTER_DENY
553 /* Route map `ip route-source' match statement. `arg' is
555 static void *route_match_ip_route_source_compile(const char *arg
)
557 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
560 /* Free route map's compiled `ip address' value. */
561 static void route_match_ip_route_source_free(void *rule
)
563 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
566 /* Route map commands for ip route-source matching. */
567 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
568 "ip route-source", route_match_ip_route_source
,
569 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
571 /* `match ip address prefix-list PREFIX_LIST' */
573 static route_map_result_t
574 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
575 route_map_object_t type
, void *object
)
577 struct prefix_list
*plist
;
579 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
580 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
584 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
591 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
593 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
596 static void route_match_ip_address_prefix_list_free(void *rule
)
598 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
601 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
602 "ip address prefix-list", route_match_ip_address_prefix_list
,
603 route_match_ip_address_prefix_list_compile
,
604 route_match_ip_address_prefix_list_free
};
606 /* `match ip next-hop prefix-list PREFIX_LIST' */
608 static route_map_result_t
609 route_match_ip_next_hop_prefix_list(void *rule
, const struct prefix
*prefix
,
610 route_map_object_t type
, void *object
)
612 struct prefix_list
*plist
;
613 struct bgp_path_info
*path
;
614 struct prefix_ipv4 p
;
616 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
619 p
.prefix
= path
->attr
->nexthop
;
620 p
.prefixlen
= IPV4_MAX_BITLEN
;
622 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
626 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
633 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
635 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
638 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
640 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
643 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
644 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
645 route_match_ip_next_hop_prefix_list_compile
,
646 route_match_ip_next_hop_prefix_list_free
};
648 /* `match ip next-hop type <blackhole>' */
650 static route_map_result_t
651 route_match_ip_next_hop_type(void *rule
, const struct prefix
*prefix
,
652 route_map_object_t type
, void *object
)
654 struct bgp_path_info
*path
;
656 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
657 path
= (struct bgp_path_info
*)object
;
658 if (!path
|| !path
->attr
)
659 return RMAP_DENYMATCH
;
661 /* If nexthop interface's index can't be resolved and nexthop is
662 set to any address then mark it as type `blackhole`.
663 This logic works for matching kernel/static routes like:
664 `ip route add blackhole 10.0.0.1`. */
665 if (path
->attr
->nexthop
.s_addr
== INADDR_ANY
666 && !path
->attr
->nh_ifindex
)
672 static void *route_match_ip_next_hop_type_compile(const char *arg
)
674 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
677 static void route_match_ip_next_hop_type_free(void *rule
)
679 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
682 static struct route_map_rule_cmd route_match_ip_next_hop_type_cmd
= {
683 "ip next-hop type", route_match_ip_next_hop_type
,
684 route_match_ip_next_hop_type_compile
,
685 route_match_ip_next_hop_type_free
};
687 /* `match ip route-source prefix-list PREFIX_LIST' */
689 static route_map_result_t
690 route_match_ip_route_source_prefix_list(void *rule
,
691 const struct prefix
*prefix
,
692 route_map_object_t type
, void *object
)
694 struct prefix_list
*plist
;
695 struct bgp_path_info
*path
;
697 struct prefix_ipv4 p
;
699 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
703 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
707 p
.prefix
= peer
->su
.sin
.sin_addr
;
708 p
.prefixlen
= IPV4_MAX_BITLEN
;
710 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
714 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
721 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
723 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
726 static void route_match_ip_route_source_prefix_list_free(void *rule
)
728 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
731 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
732 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
733 route_match_ip_route_source_prefix_list_compile
,
734 route_match_ip_route_source_prefix_list_free
};
736 /* `match evpn default-route' */
738 /* Match function should return 1 if match is success else 0 */
739 static route_map_result_t
route_match_evpn_default_route(void *rule
,
740 const struct prefix
*p
,
744 if (type
== RMAP_BGP
&& is_evpn_prefix_default(p
))
750 /* Route map commands for default-route matching. */
751 struct route_map_rule_cmd route_match_evpn_default_route_cmd
= {
752 "evpn default-route", route_match_evpn_default_route
, NULL
, NULL
};
754 /* `match mac address MAC_ACCESS_LIST' */
756 /* Match function should return 1 if match is success else return
758 static route_map_result_t
route_match_mac_address(void *rule
,
759 const struct prefix
*prefix
,
760 route_map_object_t type
,
763 struct access_list
*alist
;
766 if (type
== RMAP_BGP
) {
767 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
771 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
774 p
.family
= AF_ETHERNET
;
775 p
.prefixlen
= ETH_ALEN
* 8;
776 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.macip_addr
.mac
;
778 return (access_list_apply(alist
, &p
) == FILTER_DENY
786 /* Route map `mac address' match statement. `arg' should be
788 static void *route_match_mac_address_compile(const char *arg
)
790 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
793 /* Free route map's compiled `ip address' value. */
794 static void route_match_mac_address_free(void *rule
)
796 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
799 /* Route map commands for mac address matching. */
800 struct route_map_rule_cmd route_match_mac_address_cmd
= {
801 "mac address", route_match_mac_address
, route_match_mac_address_compile
,
802 route_match_mac_address_free
};
806 /* Match function should return 1 if match is success else return
808 static route_map_result_t
route_match_vni(void *rule
,
809 const struct prefix
*prefix
,
810 route_map_object_t type
, void *object
)
813 struct bgp_path_info
*path
= NULL
;
815 if (type
== RMAP_BGP
) {
816 vni
= *((vni_t
*)rule
);
817 path
= (struct bgp_path_info
*)object
;
819 if (path
->extra
== NULL
)
822 if (vni
== label2vni(&path
->extra
->label
[0]))
829 /* Route map `vni' match statement. */
830 static void *route_match_vni_compile(const char *arg
)
835 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
839 *vni
= strtoul(arg
, &end
, 10);
841 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
848 /* Free route map's compiled `vni' value. */
849 static void route_match_vni_free(void *rule
)
851 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
854 /* Route map commands for vni matching. */
855 struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
856 "evpn vni", route_match_vni
, route_match_vni_compile
,
857 route_match_vni_free
};
859 /* `match evpn route-type' */
861 /* Match function should return 1 if match is success else return
863 static route_map_result_t
route_match_evpn_route_type(void *rule
,
864 const struct prefix
*pfx
,
865 route_map_object_t type
,
868 uint8_t route_type
= 0;
870 if (type
== RMAP_BGP
) {
871 route_type
= *((uint8_t *)rule
);
873 if (route_type
== pfx
->u
.prefix_evpn
.route_type
)
880 /* Route map `route-type' match statement. */
881 static void *route_match_evpn_route_type_compile(const char *arg
)
883 uint8_t *route_type
= NULL
;
885 route_type
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
887 if (strncmp(arg
, "ma", 2) == 0)
888 *route_type
= BGP_EVPN_MAC_IP_ROUTE
;
889 else if (strncmp(arg
, "mu", 2) == 0)
890 *route_type
= BGP_EVPN_IMET_ROUTE
;
892 *route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
897 /* Free route map's compiled `route-type' value. */
898 static void route_match_evpn_route_type_free(void *rule
)
900 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
903 /* Route map commands for evpn route-type matching. */
904 struct route_map_rule_cmd route_match_evpn_route_type_cmd
= {
905 "evpn route-type", route_match_evpn_route_type
,
906 route_match_evpn_route_type_compile
, route_match_evpn_route_type_free
};
908 /* `match local-preference LOCAL-PREF' */
910 /* Match function return 1 if match is success else return zero. */
911 static route_map_result_t
route_match_local_pref(void *rule
,
912 const struct prefix
*prefix
,
913 route_map_object_t type
,
916 uint32_t *local_pref
;
917 struct bgp_path_info
*path
;
919 if (type
== RMAP_BGP
) {
923 if (path
->attr
->local_pref
== *local_pref
)
931 /* Route map `match local-preference' match statement.
932 `arg' is local-pref value */
933 static void *route_match_local_pref_compile(const char *arg
)
935 uint32_t *local_pref
;
937 unsigned long tmpval
;
939 /* Locpref value shoud be integer. */
944 tmpval
= strtoul(arg
, &endptr
, 10);
945 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
948 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint32_t));
953 *local_pref
= tmpval
;
957 /* Free route map's compiled `match local-preference' value. */
958 static void route_match_local_pref_free(void *rule
)
960 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
963 /* Route map commands for metric matching. */
964 struct route_map_rule_cmd route_match_local_pref_cmd
= {
965 "local-preference", route_match_local_pref
,
966 route_match_local_pref_compile
, route_match_local_pref_free
};
968 /* `match metric METRIC' */
970 /* Match function return 1 if match is success else return zero. */
971 static route_map_result_t
route_match_metric(void *rule
,
972 const struct prefix
*prefix
,
973 route_map_object_t type
,
976 struct rmap_value
*rv
;
977 struct bgp_path_info
*path
;
979 if (type
== RMAP_BGP
) {
982 return route_value_match(rv
, path
->attr
->med
);
987 /* Route map commands for metric matching. */
988 struct route_map_rule_cmd route_match_metric_cmd
= {
989 "metric", route_match_metric
, route_value_compile
, route_value_free
,
992 /* `match as-path ASPATH' */
994 /* Match function for as-path match. I assume given object is */
995 static route_map_result_t
route_match_aspath(void *rule
,
996 const struct prefix
*prefix
,
997 route_map_object_t type
,
1001 struct as_list
*as_list
;
1002 struct bgp_path_info
*path
;
1004 if (type
== RMAP_BGP
) {
1005 as_list
= as_list_lookup((char *)rule
);
1006 if (as_list
== NULL
)
1007 return RMAP_NOMATCH
;
1011 /* Perform match. */
1012 return ((as_list_apply(as_list
, path
->attr
->aspath
)
1017 return RMAP_NOMATCH
;
1020 /* Compile function for as-path match. */
1021 static void *route_match_aspath_compile(const char *arg
)
1023 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1026 /* Compile function for as-path match. */
1027 static void route_match_aspath_free(void *rule
)
1029 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1032 /* Route map commands for aspath matching. */
1033 struct route_map_rule_cmd route_match_aspath_cmd
= {
1034 "as-path", route_match_aspath
, route_match_aspath_compile
,
1035 route_match_aspath_free
};
1037 /* `match community COMMUNIY' */
1038 struct rmap_community
{
1044 /* Match function for community match. */
1045 static route_map_result_t
route_match_community(void *rule
,
1046 const struct prefix
*prefix
,
1047 route_map_object_t type
,
1050 struct community_list
*list
;
1051 struct bgp_path_info
*path
;
1052 struct rmap_community
*rcom
= rule
;
1054 if (type
== RMAP_BGP
) {
1058 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1060 COMMUNITY_LIST_MASTER
);
1062 return RMAP_NOMATCH
;
1065 if (community_list_exact_match(path
->attr
->community
,
1069 if (community_list_match(path
->attr
->community
, list
))
1073 return RMAP_NOMATCH
;
1076 /* Compile function for community match. */
1077 static void *route_match_community_compile(const char *arg
)
1079 struct rmap_community
*rcom
;
1083 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1085 p
= strchr(arg
, ' ');
1088 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1089 memcpy(rcom
->name
, arg
, len
);
1092 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1096 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1100 /* Compile function for community match. */
1101 static void route_match_community_free(void *rule
)
1103 struct rmap_community
*rcom
= rule
;
1105 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1106 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1109 /* Route map commands for community matching. */
1110 struct route_map_rule_cmd route_match_community_cmd
= {
1111 "community", route_match_community
, route_match_community_compile
,
1112 route_match_community_free
};
1114 /* Match function for lcommunity match. */
1115 static route_map_result_t
route_match_lcommunity(void *rule
,
1116 const struct prefix
*prefix
,
1117 route_map_object_t type
,
1120 struct community_list
*list
;
1121 struct bgp_path_info
*path
;
1122 struct rmap_community
*rcom
= rule
;
1124 if (type
== RMAP_BGP
) {
1127 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1129 LARGE_COMMUNITY_LIST_MASTER
);
1131 return RMAP_NOMATCH
;
1133 if (lcommunity_list_match(path
->attr
->lcommunity
, list
))
1136 return RMAP_NOMATCH
;
1139 /* Compile function for community match. */
1140 static void *route_match_lcommunity_compile(const char *arg
)
1142 struct rmap_community
*rcom
;
1146 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1148 p
= strchr(arg
, ' ');
1151 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1152 memcpy(rcom
->name
, arg
, len
);
1154 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1158 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1162 /* Compile function for community match. */
1163 static void route_match_lcommunity_free(void *rule
)
1165 struct rmap_community
*rcom
= rule
;
1167 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1168 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1171 /* Route map commands for community matching. */
1172 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1173 "large-community", route_match_lcommunity
,
1174 route_match_lcommunity_compile
, route_match_lcommunity_free
};
1177 /* Match function for extcommunity match. */
1178 static route_map_result_t
route_match_ecommunity(void *rule
,
1179 const struct prefix
*prefix
,
1180 route_map_object_t type
,
1183 struct community_list
*list
;
1184 struct bgp_path_info
*path
;
1185 struct rmap_community
*rcom
= rule
;
1187 if (type
== RMAP_BGP
) {
1190 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1192 EXTCOMMUNITY_LIST_MASTER
);
1194 return RMAP_NOMATCH
;
1196 if (ecommunity_list_match(path
->attr
->ecommunity
, list
))
1199 return RMAP_NOMATCH
;
1202 /* Compile function for extcommunity match. */
1203 static void *route_match_ecommunity_compile(const char *arg
)
1205 struct rmap_community
*rcom
;
1207 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1208 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1209 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
1214 /* Compile function for extcommunity match. */
1215 static void route_match_ecommunity_free(void *rule
)
1217 struct rmap_community
*rcom
= rule
;
1219 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1220 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1223 /* Route map commands for community matching. */
1224 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1225 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1226 route_match_ecommunity_free
};
1228 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1229 and `address-family vpnv4'. */
1231 /* `match origin' */
1232 static route_map_result_t
route_match_origin(void *rule
,
1233 const struct prefix
*prefix
,
1234 route_map_object_t type
,
1238 struct bgp_path_info
*path
;
1240 if (type
== RMAP_BGP
) {
1244 if (path
->attr
->origin
== *origin
)
1248 return RMAP_NOMATCH
;
1251 static void *route_match_origin_compile(const char *arg
)
1255 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1257 if (strcmp(arg
, "igp") == 0)
1259 else if (strcmp(arg
, "egp") == 0)
1267 /* Free route map's compiled `ip address' value. */
1268 static void route_match_origin_free(void *rule
)
1270 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1273 /* Route map commands for origin matching. */
1274 struct route_map_rule_cmd route_match_origin_cmd
= {
1275 "origin", route_match_origin
, route_match_origin_compile
,
1276 route_match_origin_free
};
1278 /* match probability { */
1280 static route_map_result_t
route_match_probability(void *rule
,
1281 const struct prefix
*prefix
,
1282 route_map_object_t type
,
1287 switch (*(long *)rule
) {
1293 if (r
< *(long *)rule
) {
1298 return RMAP_NOMATCH
;
1301 static void *route_match_probability_compile(const char *arg
)
1307 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1317 *lobule
= RAND_MAX
/ 100 * perc
;
1323 static void route_match_probability_free(void *rule
)
1325 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1328 struct route_map_rule_cmd route_match_probability_cmd
= {
1329 "probability", route_match_probability
, route_match_probability_compile
,
1330 route_match_probability_free
};
1332 /* `match interface IFNAME' */
1333 /* Match function should return 1 if match is success else return
1335 static route_map_result_t
route_match_interface(void *rule
,
1336 const struct prefix
*prefix
,
1337 route_map_object_t type
,
1340 struct interface
*ifp
;
1341 struct bgp_path_info
*path
;
1343 if (type
== RMAP_BGP
) {
1346 if (!path
|| !path
->attr
)
1347 return RMAP_NOMATCH
;
1349 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1351 if (ifp
== NULL
|| ifp
->ifindex
!= path
->attr
->nh_ifindex
)
1352 return RMAP_NOMATCH
;
1356 return RMAP_NOMATCH
;
1359 /* Route map `interface' match statement. `arg' should be
1361 static void *route_match_interface_compile(const char *arg
)
1363 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1366 /* Free route map's compiled `interface' value. */
1367 static void route_match_interface_free(void *rule
)
1369 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1372 /* Route map commands for ip address matching. */
1373 struct route_map_rule_cmd route_match_interface_cmd
= {
1374 "interface", route_match_interface
, route_match_interface_compile
,
1375 route_match_interface_free
};
1379 /* `set ip next-hop IP_ADDRESS' */
1381 /* Match function return 1 if match is success else return zero. */
1382 static route_map_result_t
route_match_tag(void *rule
,
1383 const struct prefix
*prefix
,
1384 route_map_object_t type
, void *object
)
1387 struct bgp_path_info
*path
;
1389 if (type
== RMAP_BGP
) {
1393 return ((path
->attr
->tag
== *tag
) ? RMAP_MATCH
: RMAP_NOMATCH
);
1396 return RMAP_NOMATCH
;
1400 /* Route map commands for tag matching. */
1401 static struct route_map_rule_cmd route_match_tag_cmd
= {
1402 "tag", route_match_tag
, route_map_rule_tag_compile
,
1403 route_map_rule_tag_free
,
1407 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1408 struct rmap_ip_nexthop_set
{
1409 struct in_addr
*address
;
1414 static route_map_result_t
route_set_ip_nexthop(void *rule
,
1415 const struct prefix
*prefix
,
1416 route_map_object_t type
,
1419 struct rmap_ip_nexthop_set
*rins
= rule
;
1420 struct bgp_path_info
*path
;
1423 if (type
!= RMAP_BGP
)
1426 if (prefix
->family
== AF_INET6
)
1432 if (rins
->unchanged
) {
1433 SET_FLAG(path
->attr
->rmap_change_flags
,
1434 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1435 } else if (rins
->peer_address
) {
1436 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1437 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1439 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1440 path
->attr
->nexthop
.s_addr
=
1441 sockunion2ip(peer
->su_remote
);
1442 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1443 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
1444 /* The next hop value will be set as part of
1445 * packet rewrite. Set the flags here to indicate
1446 * that rewrite needs to be done.
1447 * Also, clear the value.
1449 SET_FLAG(path
->attr
->rmap_change_flags
,
1450 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1451 path
->attr
->nexthop
.s_addr
= 0;
1454 /* Set next hop value. */
1455 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1456 path
->attr
->nexthop
= *rins
->address
;
1457 SET_FLAG(path
->attr
->rmap_change_flags
,
1458 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1459 /* case for MP-BGP : MPLS VPN */
1460 path
->attr
->mp_nexthop_global_in
= *rins
->address
;
1461 path
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1467 /* Route map `ip nexthop' compile function. Given string is converted
1468 to struct in_addr structure. */
1469 static void *route_set_ip_nexthop_compile(const char *arg
)
1471 struct rmap_ip_nexthop_set
*rins
;
1472 struct in_addr
*address
= NULL
;
1473 int peer_address
= 0;
1477 if (strcmp(arg
, "peer-address") == 0)
1479 else if (strcmp(arg
, "unchanged") == 0)
1482 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1483 sizeof(struct in_addr
));
1484 ret
= inet_aton(arg
, address
);
1487 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1492 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1493 sizeof(struct rmap_ip_nexthop_set
));
1495 rins
->address
= address
;
1496 rins
->peer_address
= peer_address
;
1497 rins
->unchanged
= unchanged
;
1502 /* Free route map's compiled `ip nexthop' value. */
1503 static void route_set_ip_nexthop_free(void *rule
)
1505 struct rmap_ip_nexthop_set
*rins
= rule
;
1508 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1510 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1513 /* Route map commands for ip nexthop set. */
1514 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1515 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1516 route_set_ip_nexthop_free
};
1518 /* `set local-preference LOCAL_PREF' */
1520 /* Set local preference. */
1521 static route_map_result_t
route_set_local_pref(void *rule
,
1522 const struct prefix
*prefix
,
1523 route_map_object_t type
,
1526 struct rmap_value
*rv
;
1527 struct bgp_path_info
*path
;
1528 uint32_t locpref
= 0;
1530 if (type
== RMAP_BGP
) {
1531 /* Fetch routemap's rule information. */
1535 /* Set local preference value. */
1536 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1537 locpref
= path
->attr
->local_pref
;
1539 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1540 path
->attr
->local_pref
=
1541 route_value_adjust(rv
, locpref
, path
->peer
);
1547 /* Set local preference rule structure. */
1548 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1549 "local-preference", route_set_local_pref
, route_value_compile
,
1553 /* `set weight WEIGHT' */
1556 static route_map_result_t
route_set_weight(void *rule
,
1557 const struct prefix
*prefix
,
1558 route_map_object_t type
,
1561 struct rmap_value
*rv
;
1562 struct bgp_path_info
*path
;
1564 if (type
== RMAP_BGP
) {
1565 /* Fetch routemap's rule information. */
1569 /* Set weight value. */
1570 path
->attr
->weight
= route_value_adjust(rv
, 0, path
->peer
);
1576 /* Set local preference rule structure. */
1577 struct route_map_rule_cmd route_set_weight_cmd
= {
1578 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1581 /* `set metric METRIC' */
1583 /* Set metric to attribute. */
1584 static route_map_result_t
route_set_metric(void *rule
,
1585 const struct prefix
*prefix
,
1586 route_map_object_t type
,
1589 struct rmap_value
*rv
;
1590 struct bgp_path_info
*path
;
1593 if (type
== RMAP_BGP
) {
1594 /* Fetch routemap's rule information. */
1598 if (path
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1599 med
= path
->attr
->med
;
1601 path
->attr
->med
= route_value_adjust(rv
, med
, path
->peer
);
1602 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1607 /* Set metric rule structure. */
1608 struct route_map_rule_cmd route_set_metric_cmd
= {
1609 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1612 /* `set as-path prepend ASPATH' */
1614 /* For AS path prepend mechanism. */
1615 static route_map_result_t
route_set_aspath_prepend(void *rule
,
1616 const struct prefix
*prefix
,
1617 route_map_object_t type
,
1620 struct aspath
*aspath
;
1622 struct bgp_path_info
*path
;
1624 if (type
== RMAP_BGP
) {
1627 if (path
->attr
->aspath
->refcnt
)
1628 new = aspath_dup(path
->attr
->aspath
);
1630 new = path
->attr
->aspath
;
1632 if ((uintptr_t)rule
> 10) {
1634 aspath_prepend(aspath
, new);
1636 as_t as
= aspath_leftmost(new);
1638 as
= path
->peer
->as
;
1639 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1642 path
->attr
->aspath
= new;
1648 static void *route_set_aspath_prepend_compile(const char *arg
)
1652 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1653 return (void *)(uintptr_t)num
;
1655 return route_aspath_compile(arg
);
1658 static void route_set_aspath_prepend_free(void *rule
)
1660 if ((uintptr_t)rule
> 10)
1661 route_aspath_free(rule
);
1665 /* Set as-path prepend rule structure. */
1666 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1667 "as-path prepend", route_set_aspath_prepend
,
1668 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1671 /* `set as-path exclude ASn' */
1673 /* For ASN exclude mechanism.
1674 * Iterate over ASns requested and filter them from the given AS_PATH one by
1676 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1678 static route_map_result_t
route_set_aspath_exclude(void *rule
,
1679 const struct prefix
*dummy
,
1680 route_map_object_t type
,
1683 struct aspath
*new_path
, *exclude_path
;
1684 struct bgp_path_info
*path
;
1686 if (type
== RMAP_BGP
) {
1687 exclude_path
= rule
;
1689 if (path
->attr
->aspath
->refcnt
)
1690 new_path
= aspath_dup(path
->attr
->aspath
);
1692 new_path
= path
->attr
->aspath
;
1693 path
->attr
->aspath
=
1694 aspath_filter_exclude(new_path
, exclude_path
);
1699 /* Set ASn exlude rule structure. */
1700 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1701 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1705 /* `set community COMMUNITY' */
1706 struct rmap_com_set
{
1707 struct community
*com
;
1712 /* For community set mechanism. */
1713 static route_map_result_t
route_set_community(void *rule
,
1714 const struct prefix
*prefix
,
1715 route_map_object_t type
,
1718 struct rmap_com_set
*rcs
;
1719 struct bgp_path_info
*path
;
1721 struct community
*new = NULL
;
1722 struct community
*old
;
1723 struct community
*merge
;
1725 if (type
== RMAP_BGP
) {
1729 old
= attr
->community
;
1733 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1734 attr
->community
= NULL
;
1735 /* See the longer comment down below. */
1736 if (old
&& old
->refcnt
== 0)
1737 community_free(&old
);
1741 /* "additive" case. */
1742 if (rcs
->additive
&& old
) {
1743 merge
= community_merge(community_dup(old
), rcs
->com
);
1745 new = community_uniq_sort(merge
);
1746 community_free(&merge
);
1748 new = community_dup(rcs
->com
);
1750 /* HACK: if the old community is not intern'd,
1751 * we should free it here, or all reference to it may be
1753 * Really need to cleanup attribute caching sometime.
1755 if (old
&& old
->refcnt
== 0)
1756 community_free(&old
);
1758 /* will be interned by caller if required */
1759 attr
->community
= new;
1761 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1767 /* Compile function for set community. */
1768 static void *route_set_community_compile(const char *arg
)
1770 struct rmap_com_set
*rcs
;
1771 struct community
*com
= NULL
;
1776 if (strcmp(arg
, "none") == 0)
1779 sp
= strstr(arg
, "additive");
1781 if (sp
&& sp
> arg
) {
1782 /* "additive" keyword is included. */
1787 com
= community_str2com(arg
);
1796 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1798 rcs
->additive
= additive
;
1804 /* Free function for set community. */
1805 static void route_set_community_free(void *rule
)
1807 struct rmap_com_set
*rcs
= rule
;
1810 community_free(&rcs
->com
);
1811 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1814 /* Set community rule structure. */
1815 struct route_map_rule_cmd route_set_community_cmd
= {
1816 "community", route_set_community
, route_set_community_compile
,
1817 route_set_community_free
,
1820 /* `set community COMMUNITY' */
1821 struct rmap_lcom_set
{
1822 struct lcommunity
*lcom
;
1828 /* For lcommunity set mechanism. */
1829 static route_map_result_t
route_set_lcommunity(void *rule
,
1830 const struct prefix
*prefix
,
1831 route_map_object_t type
,
1834 struct rmap_lcom_set
*rcs
;
1835 struct bgp_path_info
*path
;
1837 struct lcommunity
*new = NULL
;
1838 struct lcommunity
*old
;
1839 struct lcommunity
*merge
;
1841 if (type
== RMAP_BGP
) {
1845 old
= attr
->lcommunity
;
1850 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
1851 attr
->lcommunity
= NULL
;
1853 /* See the longer comment down below. */
1854 if (old
&& old
->refcnt
== 0)
1855 lcommunity_free(&old
);
1859 if (rcs
->additive
&& old
) {
1860 merge
= lcommunity_merge(lcommunity_dup(old
),
1863 new = lcommunity_uniq_sort(merge
);
1864 lcommunity_free(&merge
);
1866 new = lcommunity_dup(rcs
->lcom
);
1868 /* HACK: if the old large-community is not intern'd,
1869 * we should free it here, or all reference to it may be
1871 * Really need to cleanup attribute caching sometime.
1873 if (old
&& old
->refcnt
== 0)
1874 lcommunity_free(&old
);
1876 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1877 attr
->lcommunity
= new;
1879 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
1885 /* Compile function for set community. */
1886 static void *route_set_lcommunity_compile(const char *arg
)
1888 struct rmap_lcom_set
*rcs
;
1889 struct lcommunity
*lcom
= NULL
;
1894 if (strcmp(arg
, "none") == 0)
1897 sp
= strstr(arg
, "additive");
1899 if (sp
&& sp
> arg
) {
1900 /* "additive" keyworkd is included. */
1905 lcom
= lcommunity_str2com(arg
);
1914 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1916 rcs
->additive
= additive
;
1922 /* Free function for set lcommunity. */
1923 static void route_set_lcommunity_free(void *rule
)
1925 struct rmap_lcom_set
*rcs
= rule
;
1928 lcommunity_free(&rcs
->lcom
);
1930 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1933 /* Set community rule structure. */
1934 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
1935 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
1936 route_set_lcommunity_free
,
1939 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
1941 /* For large community set mechanism. */
1942 static route_map_result_t
route_set_lcommunity_delete(void *rule
,
1943 const struct prefix
*pfx
,
1944 route_map_object_t type
,
1947 struct community_list
*list
;
1948 struct lcommunity
*merge
;
1949 struct lcommunity
*new;
1950 struct lcommunity
*old
;
1951 struct bgp_path_info
*path
;
1952 struct rmap_community
*rcom
= rule
;
1954 if (type
== RMAP_BGP
) {
1959 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1961 LARGE_COMMUNITY_LIST_MASTER
);
1962 old
= path
->attr
->lcommunity
;
1965 merge
= lcommunity_list_match_delete(
1966 lcommunity_dup(old
), list
);
1967 new = lcommunity_uniq_sort(merge
);
1968 lcommunity_free(&merge
);
1970 /* HACK: if the old community is not intern'd,
1971 * we should free it here, or all reference to it may be
1973 * Really need to cleanup attribute caching sometime.
1975 if (old
->refcnt
== 0)
1976 lcommunity_free(&old
);
1978 if (new->size
== 0) {
1979 path
->attr
->lcommunity
= NULL
;
1980 path
->attr
->flag
&= ~ATTR_FLAG_BIT(
1981 BGP_ATTR_LARGE_COMMUNITIES
);
1982 lcommunity_free(&new);
1984 path
->attr
->lcommunity
= new;
1985 path
->attr
->flag
|= ATTR_FLAG_BIT(
1986 BGP_ATTR_LARGE_COMMUNITIES
);
1994 /* Compile function for set lcommunity. */
1995 static void *route_set_lcommunity_delete_compile(const char *arg
)
1997 struct rmap_community
*rcom
;
2002 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2004 p
= strchr(arg
, ' ');
2007 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
2008 memcpy(str
, arg
, len
);
2013 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2017 /* Free function for set lcommunity. */
2018 static void route_set_lcommunity_delete_free(void *rule
)
2020 struct rmap_community
*rcom
= rule
;
2022 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2023 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2026 /* Set lcommunity rule structure. */
2027 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2028 "large-comm-list", route_set_lcommunity_delete
,
2029 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2033 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2035 /* For community set mechanism. */
2036 static route_map_result_t
route_set_community_delete(
2038 const struct prefix
*prefix
,
2039 route_map_object_t type
,
2042 struct community_list
*list
;
2043 struct community
*merge
;
2044 struct community
*new;
2045 struct community
*old
;
2046 struct bgp_path_info
*path
;
2047 struct rmap_community
*rcom
= rule
;
2049 if (type
== RMAP_BGP
) {
2054 list
= community_list_lookup(bgp_clist
, rcom
->name
,
2056 COMMUNITY_LIST_MASTER
);
2057 old
= path
->attr
->community
;
2060 merge
= community_list_match_delete(community_dup(old
),
2062 new = community_uniq_sort(merge
);
2063 community_free(&merge
);
2065 /* HACK: if the old community is not intern'd,
2066 * we should free it here, or all reference to it may be
2068 * Really need to cleanup attribute caching sometime.
2070 if (old
->refcnt
== 0)
2071 community_free(&old
);
2073 if (new->size
== 0) {
2074 path
->attr
->community
= NULL
;
2076 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2077 community_free(&new);
2079 path
->attr
->community
= new;
2081 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2089 /* Compile function for set community. */
2090 static void *route_set_community_delete_compile(const char *arg
)
2092 struct rmap_community
*rcom
;
2097 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
2099 p
= strchr(arg
, ' ');
2102 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
2103 memcpy(str
, arg
, len
);
2108 rcom
->name_hash
= bgp_clist_hash_key(rcom
->name
);
2112 /* Free function for set community. */
2113 static void route_set_community_delete_free(void *rule
)
2115 struct rmap_community
*rcom
= rule
;
2117 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
2118 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
2121 /* Set community rule structure. */
2122 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2123 "comm-list", route_set_community_delete
,
2124 route_set_community_delete_compile
, route_set_community_delete_free
,
2127 /* `set extcommunity rt COMMUNITY' */
2129 /* For community set mechanism. Used by _rt and _soo. */
2130 static route_map_result_t
route_set_ecommunity(void *rule
,
2131 const struct prefix
*prefix
,
2132 route_map_object_t type
,
2135 struct ecommunity
*ecom
;
2136 struct ecommunity
*new_ecom
;
2137 struct ecommunity
*old_ecom
;
2138 struct bgp_path_info
*path
;
2140 if (type
== RMAP_BGP
) {
2147 /* We assume additive for Extended Community. */
2148 old_ecom
= path
->attr
->ecommunity
;
2151 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2154 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2155 * bgp_update_receive()
2156 * ->refcnt = 0 => set by a previous route-map
2158 if (!old_ecom
->refcnt
)
2159 ecommunity_free(&old_ecom
);
2161 new_ecom
= ecommunity_dup(ecom
);
2163 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2164 path
->attr
->ecommunity
= new_ecom
;
2166 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2171 /* Compile function for set community. */
2172 static void *route_set_ecommunity_rt_compile(const char *arg
)
2174 struct ecommunity
*ecom
;
2176 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2179 return ecommunity_intern(ecom
);
2182 /* Free function for set community. Used by _rt and _soo */
2183 static void route_set_ecommunity_free(void *rule
)
2185 struct ecommunity
*ecom
= rule
;
2186 ecommunity_unintern(&ecom
);
2189 /* Set community rule structure. */
2190 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2191 "extcommunity rt", route_set_ecommunity
,
2192 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2195 /* `set extcommunity soo COMMUNITY' */
2197 /* Compile function for set community. */
2198 static void *route_set_ecommunity_soo_compile(const char *arg
)
2200 struct ecommunity
*ecom
;
2202 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2206 return ecommunity_intern(ecom
);
2209 /* Set community rule structure. */
2210 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2211 "extcommunity soo", route_set_ecommunity
,
2212 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2215 /* `set origin ORIGIN' */
2217 /* For origin set. */
2218 static route_map_result_t
route_set_origin(void *rule
,
2219 const struct prefix
*prefix
,
2220 route_map_object_t type
,
2224 struct bgp_path_info
*path
;
2226 if (type
== RMAP_BGP
) {
2230 path
->attr
->origin
= *origin
;
2236 /* Compile function for origin set. */
2237 static void *route_set_origin_compile(const char *arg
)
2241 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2243 if (strcmp(arg
, "igp") == 0)
2245 else if (strcmp(arg
, "egp") == 0)
2253 /* Compile function for origin set. */
2254 static void route_set_origin_free(void *rule
)
2256 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2259 /* Set origin rule structure. */
2260 struct route_map_rule_cmd route_set_origin_cmd
= {
2261 "origin", route_set_origin
, route_set_origin_compile
,
2262 route_set_origin_free
,
2265 /* `set atomic-aggregate' */
2267 /* For atomic aggregate set. */
2268 static route_map_result_t
route_set_atomic_aggregate(void *rule
,
2269 const struct prefix
*pfx
,
2270 route_map_object_t type
,
2273 struct bgp_path_info
*path
;
2275 if (type
== RMAP_BGP
) {
2277 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2283 /* Compile function for atomic aggregate. */
2284 static void *route_set_atomic_aggregate_compile(const char *arg
)
2289 /* Compile function for atomic aggregate. */
2290 static void route_set_atomic_aggregate_free(void *rule
)
2295 /* Set atomic aggregate rule structure. */
2296 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2297 "atomic-aggregate", route_set_atomic_aggregate
,
2298 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2301 /* `set aggregator as AS A.B.C.D' */
2304 struct in_addr address
;
2307 static route_map_result_t
route_set_aggregator_as(void *rule
,
2308 const struct prefix
*prefix
,
2309 route_map_object_t type
,
2312 struct bgp_path_info
*path
;
2313 struct aggregator
*aggregator
;
2315 if (type
== RMAP_BGP
) {
2319 path
->attr
->aggregator_as
= aggregator
->as
;
2320 path
->attr
->aggregator_addr
= aggregator
->address
;
2321 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2327 static void *route_set_aggregator_as_compile(const char *arg
)
2329 struct aggregator
*aggregator
;
2335 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2336 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2337 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2341 aggregator
->as
= strtoul(as
, NULL
, 10);
2342 ret
= inet_aton(address
, &aggregator
->address
);
2344 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2350 static void route_set_aggregator_as_free(void *rule
)
2352 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2355 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2356 "aggregator as", route_set_aggregator_as
,
2357 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2360 /* Set tag to object. object must be pointer to struct bgp_path_info */
2361 static route_map_result_t
route_set_tag(void *rule
,
2362 const struct prefix
*prefix
,
2363 route_map_object_t type
, void *object
)
2366 struct bgp_path_info
*path
;
2368 if (type
== RMAP_BGP
) {
2373 path
->attr
->tag
= *tag
;
2379 /* Route map commands for tag set. */
2380 static struct route_map_rule_cmd route_set_tag_cmd
= {
2381 "tag", route_set_tag
, route_map_rule_tag_compile
,
2382 route_map_rule_tag_free
,
2385 /* Set label-index to object. object must be pointer to struct bgp_path_info */
2386 static route_map_result_t
route_set_label_index(void *rule
,
2387 const struct prefix
*prefix
,
2388 route_map_object_t type
,
2391 struct rmap_value
*rv
;
2392 struct bgp_path_info
*path
;
2393 uint32_t label_index
;
2395 if (type
== RMAP_BGP
) {
2396 /* Fetch routemap's rule information. */
2400 /* Set label-index value. */
2401 label_index
= rv
->value
;
2403 path
->attr
->label_index
= label_index
;
2404 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2411 /* Route map commands for label-index set. */
2412 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2413 "label-index", route_set_label_index
, route_value_compile
,
2417 /* `match ipv6 address IP_ACCESS_LIST' */
2419 static route_map_result_t
route_match_ipv6_address(void *rule
,
2420 const struct prefix
*prefix
,
2421 route_map_object_t type
,
2424 struct access_list
*alist
;
2426 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2427 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2429 return RMAP_NOMATCH
;
2431 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2435 return RMAP_NOMATCH
;
2438 static void *route_match_ipv6_address_compile(const char *arg
)
2440 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2443 static void route_match_ipv6_address_free(void *rule
)
2445 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2448 /* Route map commands for ip address matching. */
2449 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2450 "ipv6 address", route_match_ipv6_address
,
2451 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2453 /* `match ipv6 next-hop IP_ADDRESS' */
2455 static route_map_result_t
route_match_ipv6_next_hop(void *rule
,
2456 const struct prefix
*prefix
,
2457 route_map_object_t type
,
2460 struct in6_addr
*addr
= rule
;
2461 struct bgp_path_info
*path
;
2463 if (type
== RMAP_BGP
) {
2466 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
))
2469 if (path
->attr
->mp_nexthop_len
2470 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2471 && IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_local
, rule
))
2474 return RMAP_NOMATCH
;
2477 return RMAP_NOMATCH
;
2480 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2482 struct in6_addr
*address
;
2485 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2487 ret
= inet_pton(AF_INET6
, arg
, address
);
2489 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2496 static void route_match_ipv6_next_hop_free(void *rule
)
2498 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2501 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2502 "ipv6 next-hop", route_match_ipv6_next_hop
,
2503 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2505 /* `match ipv6 address prefix-list PREFIX_LIST' */
2507 static route_map_result_t
2508 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2509 route_map_object_t type
, void *object
)
2511 struct prefix_list
*plist
;
2513 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2514 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
2516 return RMAP_NOMATCH
;
2518 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
2522 return RMAP_NOMATCH
;
2525 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2527 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2530 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2532 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2535 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2536 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2537 route_match_ipv6_address_prefix_list_compile
,
2538 route_match_ipv6_address_prefix_list_free
};
2540 /* `match ipv6 next-hop type <TYPE>' */
2542 static route_map_result_t
2543 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2544 route_map_object_t type
, void *object
)
2546 struct bgp_path_info
*path
;
2547 struct in6_addr
*addr
= rule
;
2549 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2550 path
= (struct bgp_path_info
*)object
;
2551 if (!path
|| !path
->attr
)
2552 return RMAP_DENYMATCH
;
2554 if (IPV6_ADDR_SAME(&path
->attr
->mp_nexthop_global
, addr
)
2555 && !path
->attr
->nh_ifindex
)
2558 return RMAP_NOMATCH
;
2561 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2563 struct in6_addr
*address
;
2566 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2568 ret
= inet_pton(AF_INET6
, "::0", address
);
2570 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2577 static void route_match_ipv6_next_hop_type_free(void *rule
)
2579 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2582 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2583 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2584 route_match_ipv6_next_hop_type_compile
,
2585 route_match_ipv6_next_hop_type_free
};
2587 /* `set ipv6 nexthop global IP_ADDRESS' */
2589 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2590 static route_map_result_t
route_set_ipv6_nexthop_global(void *rule
,
2591 const struct prefix
*p
,
2592 route_map_object_t type
,
2595 struct in6_addr
*address
;
2596 struct bgp_path_info
*path
;
2598 if (type
== RMAP_BGP
) {
2599 /* Fetch routemap's rule information. */
2603 /* Set next hop value. */
2604 path
->attr
->mp_nexthop_global
= *address
;
2606 /* Set nexthop length. */
2607 if (path
->attr
->mp_nexthop_len
== 0)
2608 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2610 SET_FLAG(path
->attr
->rmap_change_flags
,
2611 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2617 /* Route map `ip next-hop' compile function. Given string is converted
2618 to struct in_addr structure. */
2619 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2622 struct in6_addr
*address
;
2624 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2626 ret
= inet_pton(AF_INET6
, arg
, address
);
2629 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2636 /* Free route map's compiled `ip next-hop' value. */
2637 static void route_set_ipv6_nexthop_global_free(void *rule
)
2639 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2642 /* Route map commands for ip nexthop set. */
2643 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2644 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2645 route_set_ipv6_nexthop_global_compile
,
2646 route_set_ipv6_nexthop_global_free
};
2648 /* Set next-hop preference value. */
2649 static route_map_result_t
2650 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2651 route_map_object_t type
, void *object
)
2653 struct bgp_path_info
*path
;
2656 if (type
== RMAP_BGP
) {
2657 /* Fetch routemap's rule information. */
2661 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2662 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2664 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2665 /* Set next hop preference to global */
2666 path
->attr
->mp_nexthop_prefer_global
= TRUE
;
2667 SET_FLAG(path
->attr
->rmap_change_flags
,
2668 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2670 path
->attr
->mp_nexthop_prefer_global
= FALSE
;
2671 SET_FLAG(path
->attr
->rmap_change_flags
,
2672 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2678 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2682 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2688 /* Free route map's compiled `ip next-hop' value. */
2689 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2691 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2694 /* Route map commands for ip nexthop set preferred. */
2695 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2696 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2697 route_set_ipv6_nexthop_prefer_global_compile
,
2698 route_set_ipv6_nexthop_prefer_global_free
};
2700 /* `set ipv6 nexthop local IP_ADDRESS' */
2702 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2703 static route_map_result_t
route_set_ipv6_nexthop_local(void *rule
,
2704 const struct prefix
*p
,
2705 route_map_object_t type
,
2708 struct in6_addr
*address
;
2709 struct bgp_path_info
*path
;
2711 if (type
== RMAP_BGP
) {
2712 /* Fetch routemap's rule information. */
2716 /* Set next hop value. */
2717 path
->attr
->mp_nexthop_local
= *address
;
2719 /* Set nexthop length. */
2720 if (path
->attr
->mp_nexthop_len
2721 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2722 path
->attr
->mp_nexthop_len
=
2723 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2725 SET_FLAG(path
->attr
->rmap_change_flags
,
2726 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2732 /* Route map `ip nexthop' compile function. Given string is converted
2733 to struct in_addr structure. */
2734 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2737 struct in6_addr
*address
;
2739 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2741 ret
= inet_pton(AF_INET6
, arg
, address
);
2744 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2751 /* Free route map's compiled `ip nexthop' value. */
2752 static void route_set_ipv6_nexthop_local_free(void *rule
)
2754 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2757 /* Route map commands for ip nexthop set. */
2758 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2759 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2760 route_set_ipv6_nexthop_local_compile
,
2761 route_set_ipv6_nexthop_local_free
};
2763 /* `set ipv6 nexthop peer-address' */
2765 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2766 static route_map_result_t
route_set_ipv6_nexthop_peer(void *rule
,
2767 const struct prefix
*pfx
,
2768 route_map_object_t type
,
2771 struct in6_addr peer_address
;
2772 struct bgp_path_info
*path
;
2775 if (type
== RMAP_BGP
) {
2776 /* Fetch routemap's rule information. */
2780 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2781 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2783 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2784 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2785 /* Set next hop value and length in attribute. */
2786 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2787 path
->attr
->mp_nexthop_local
= peer_address
;
2788 if (path
->attr
->mp_nexthop_len
!= 32)
2789 path
->attr
->mp_nexthop_len
= 32;
2791 path
->attr
->mp_nexthop_global
= peer_address
;
2792 if (path
->attr
->mp_nexthop_len
== 0)
2793 path
->attr
->mp_nexthop_len
= 16;
2796 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2797 /* The next hop value will be set as part of packet
2799 * Set the flags here to indicate that rewrite needs to
2801 * Also, clear the value - we clear both global and
2803 * nexthops, whether we send one or both is determined
2806 SET_FLAG(path
->attr
->rmap_change_flags
,
2807 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2808 /* clear next hop value. */
2809 memset(&(path
->attr
->mp_nexthop_global
), 0,
2810 sizeof(struct in6_addr
));
2811 memset(&(path
->attr
->mp_nexthop_local
), 0,
2812 sizeof(struct in6_addr
));
2819 /* Route map `ip next-hop' compile function. Given string is converted
2820 to struct in_addr structure. */
2821 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2825 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2831 /* Free route map's compiled `ip next-hop' value. */
2832 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2834 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2837 /* Route map commands for ip nexthop set. */
2838 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2839 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2840 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2842 /* `set ipv4 vpn next-hop A.B.C.D' */
2844 static route_map_result_t
route_set_vpnv4_nexthop(void *rule
,
2845 const struct prefix
*prefix
,
2846 route_map_object_t type
,
2849 struct in_addr
*address
;
2850 struct bgp_path_info
*path
;
2852 if (type
== RMAP_BGP
) {
2853 /* Fetch routemap's rule information. */
2857 /* Set next hop value. */
2858 path
->attr
->mp_nexthop_global_in
= *address
;
2859 path
->attr
->mp_nexthop_len
= 4;
2865 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2868 struct in_addr
*address
;
2870 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2872 ret
= inet_aton(arg
, address
);
2875 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2882 /* `set ipv6 vpn next-hop A.B.C.D' */
2884 static route_map_result_t
route_set_vpnv6_nexthop(void *rule
,
2885 const struct prefix
*prefix
,
2886 route_map_object_t type
,
2889 struct in6_addr
*address
;
2890 struct bgp_path_info
*path
;
2892 if (type
== RMAP_BGP
) {
2893 /* Fetch routemap's rule information. */
2897 /* Set next hop value. */
2898 memcpy(&path
->attr
->mp_nexthop_global
, address
,
2899 sizeof(struct in6_addr
));
2900 path
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2906 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2909 struct in6_addr
*address
;
2911 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2912 ret
= inet_pton(AF_INET6
, arg
, address
);
2915 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2922 static void route_set_vpn_nexthop_free(void *rule
)
2924 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2927 /* Route map commands for ipv4 next-hop set. */
2928 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2929 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2930 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
2932 /* Route map commands for ipv6 next-hop set. */
2933 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
2934 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
2935 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
2937 /* `set originator-id' */
2939 /* For origin set. */
2940 static route_map_result_t
route_set_originator_id(void *rule
,
2941 const struct prefix
*prefix
,
2942 route_map_object_t type
,
2945 struct in_addr
*address
;
2946 struct bgp_path_info
*path
;
2948 if (type
== RMAP_BGP
) {
2952 path
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
2953 path
->attr
->originator_id
= *address
;
2959 /* Compile function for originator-id set. */
2960 static void *route_set_originator_id_compile(const char *arg
)
2963 struct in_addr
*address
;
2965 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2967 ret
= inet_aton(arg
, address
);
2970 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2977 /* Compile function for originator_id set. */
2978 static void route_set_originator_id_free(void *rule
)
2980 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2983 /* Set originator-id rule structure. */
2984 struct route_map_rule_cmd route_set_originator_id_cmd
= {
2985 "originator-id", route_set_originator_id
,
2986 route_set_originator_id_compile
, route_set_originator_id_free
,
2989 /* Add bgp route map rule. */
2990 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
2991 const char *arg
, route_map_event_t type
)
2993 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2994 int retval
= CMD_SUCCESS
;
2997 ret
= route_map_add_match(index
, command
, arg
);
2999 case RMAP_RULE_MISSING
:
3000 vty_out(vty
, "%% BGP Can't find rule.\n");
3001 retval
= CMD_WARNING_CONFIG_FAILED
;
3003 case RMAP_COMPILE_ERROR
:
3004 vty_out(vty
, "%% BGP Argument is malformed.\n");
3005 retval
= CMD_WARNING_CONFIG_FAILED
;
3007 case RMAP_COMPILE_SUCCESS
:
3008 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
3009 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
3017 /* Delete bgp route map rule. */
3018 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
3019 const char *arg
, route_map_event_t type
)
3021 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
3023 int retval
= CMD_SUCCESS
;
3024 char *dep_name
= NULL
;
3026 char *rmap_name
= NULL
;
3028 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3029 /* ignore the mundane, the types without any dependency */
3031 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3034 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3036 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3038 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3041 ret
= route_map_delete_match(index
, command
, dep_name
);
3043 case RMAP_RULE_MISSING
:
3044 vty_out(vty
, "%% BGP Can't find rule.\n");
3045 retval
= CMD_WARNING_CONFIG_FAILED
;
3047 case RMAP_COMPILE_ERROR
:
3048 vty_out(vty
, "%% BGP Argument is malformed.\n");
3049 retval
= CMD_WARNING_CONFIG_FAILED
;
3051 case RMAP_COMPILE_SUCCESS
:
3052 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
3053 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
3058 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3060 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3066 * This is the workhorse routine for processing in/out routemap
3069 static void bgp_route_map_process_peer(const char *rmap_name
,
3070 struct route_map
*map
, struct peer
*peer
,
3071 int afi
, int safi
, int route_update
)
3075 struct bgp_filter
*filter
;
3077 if (!peer
|| !rmap_name
)
3080 filter
= &peer
->filter
[afi
][safi
];
3082 * in is for non-route-server clients,
3083 * out is for all peers
3085 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
3086 if (filter
->map
[RMAP_IN
].name
3087 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3088 filter
->map
[RMAP_IN
].map
= map
;
3090 if (route_update
&& peer
->status
== Established
) {
3091 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3092 PEER_FLAG_SOFT_RECONFIG
)) {
3093 if (bgp_debug_update(peer
, NULL
, NULL
,
3096 "Processing route_map %s update on "
3097 "peer %s (inbound, soft-reconfig)",
3098 rmap_name
, peer
->host
);
3100 bgp_soft_reconfig_in(peer
, afi
, safi
);
3102 CHECK_FLAG(peer
->cap
,
3103 PEER_CAP_REFRESH_OLD_RCV
)
3106 PEER_CAP_REFRESH_NEW_RCV
)) {
3108 if (bgp_debug_update(peer
, NULL
, NULL
,
3111 "Processing route_map %s update on "
3112 "peer %s (inbound, route-refresh)",
3113 rmap_name
, peer
->host
);
3114 bgp_route_refresh_send(peer
, afi
, safi
,
3121 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
3124 if (update
&& route_update
&& peer
->status
== Established
) {
3125 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3126 PEER_FLAG_SOFT_RECONFIG
)) {
3127 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3129 "Processing route_map %s update on "
3130 "peer %s (import, soft-reconfig)",
3131 rmap_name
, peer
->host
);
3133 bgp_soft_reconfig_in(peer
, afi
, safi
);
3134 } else if (CHECK_FLAG(peer
->cap
,
3135 PEER_CAP_REFRESH_OLD_RCV
)
3136 || CHECK_FLAG(peer
->cap
,
3137 PEER_CAP_REFRESH_NEW_RCV
)) {
3138 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3140 "Processing route_map %s update on "
3141 "peer %s (import, route-refresh)",
3142 rmap_name
, peer
->host
);
3143 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3146 /* DD: Else, what else do we do ? Reset peer ? */
3151 * For outbound, unsuppress and default-originate map change (content or
3152 * map created), merely update the "config" here, the actual route
3153 * announcement happens at the group level.
3155 if (filter
->map
[RMAP_OUT
].name
3156 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3157 filter
->map
[RMAP_OUT
].map
= map
;
3159 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3160 filter
->usmap
.map
= map
;
3162 if (peer
->default_rmap
[afi
][safi
].name
3163 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3164 peer
->default_rmap
[afi
][safi
].map
= map
;
3167 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3168 struct route_map
*map
,
3171 struct peer_group
*group
;
3172 struct listnode
*node
, *nnode
;
3173 struct bgp_filter
*filter
;
3180 /* All the peers have been updated correctly already. This is
3181 * just updating the placeholder data. No real update required.
3183 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3184 FOREACH_AFI_SAFI (afi
, safi
) {
3185 filter
= &group
->conf
->filter
[afi
][safi
];
3187 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3188 if ((filter
->map
[direct
].name
)
3189 && (strcmp(rmap_name
,
3190 filter
->map
[direct
].name
)
3192 filter
->map
[direct
].map
= map
;
3195 if (filter
->usmap
.name
3196 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3197 filter
->usmap
.map
= map
;
3203 * Note that if an extreme number (tens of thousands) of route-maps are in use
3204 * and if bgp has an extreme number of peers, network statements, etc then this
3205 * function can consume a lot of cycles. This is due to this function being
3206 * called for each route-map and within this function we walk the list of peers,
3207 * network statements, etc looking to see if they use this route-map.
3209 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3216 struct bgp_node
*bn
;
3217 struct bgp_static
*bgp_static
;
3218 struct listnode
*node
, *nnode
;
3219 struct route_map
*map
;
3220 char buf
[INET6_ADDRSTRLEN
];
3222 map
= route_map_lookup_by_name(rmap_name
);
3224 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3226 /* Ignore dummy peer-group structure */
3227 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3230 FOREACH_AFI_SAFI (afi
, safi
) {
3231 /* process in/out/import/export/default-orig
3233 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3234 safi
, route_update
);
3238 /* for outbound/default-orig route-maps, process for groups */
3239 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3242 /* update peer-group config (template) */
3243 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3245 FOREACH_AFI_SAFI (afi
, safi
) {
3246 /* For table route-map updates. */
3247 if (!bgp_fibupd_safi(safi
))
3250 if (bgp
->table_map
[afi
][safi
].name
3251 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3253 bgp
->table_map
[afi
][safi
].map
= map
;
3255 if (BGP_DEBUG(zebra
, ZEBRA
))
3257 "Processing route_map %s update on "
3261 bgp_zebra_announce_table(bgp
, afi
, safi
);
3264 /* For network route-map updates. */
3265 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3266 bn
= bgp_route_next(bn
)) {
3267 bgp_static
= bgp_node_get_bgp_static_info(bn
);
3271 if (!bgp_static
->rmap
.name
3272 || (strcmp(rmap_name
, bgp_static
->rmap
.name
) != 0))
3275 bgp_static
->rmap
.map
= map
;
3277 if (route_update
&& !bgp_static
->backdoor
) {
3278 if (bgp_debug_zebra(&bn
->p
))
3280 "Processing route_map %s update on static route %s",
3282 inet_ntop(bn
->p
.family
,
3283 &bn
->p
.u
.prefix
, buf
,
3285 bgp_static_update(bgp
, &bn
->p
, bgp_static
, afi
,
3291 /* For redistribute route-map updates. */
3292 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3293 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3294 struct list
*red_list
;
3295 struct bgp_redist
*red
;
3297 red_list
= bgp
->redist
[afi
][i
];
3301 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3303 || (strcmp(rmap_name
, red
->rmap
.name
) != 0))
3306 red
->rmap
.map
= map
;
3311 if (BGP_DEBUG(zebra
, ZEBRA
))
3313 "Processing route_map %s update on redistributed routes",
3316 bgp_redistribute_resend(bgp
, afi
, i
,
3321 /* for type5 command route-maps */
3322 FOREACH_AFI_SAFI (afi
, safi
) {
3323 if (!bgp
->adv_cmd_rmap
[afi
][safi
].name
3324 || strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3328 if (BGP_DEBUG(zebra
, ZEBRA
))
3330 "Processing route_map %s update on advertise type5 route command",
3332 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3333 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3337 static void bgp_route_map_process_update_cb(char *rmap_name
)
3339 struct listnode
*node
, *nnode
;
3342 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3343 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3346 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3347 vnc_routemap_update(bgp
, __func__
);
3351 vpn_policy_routemap_event(rmap_name
);
3354 int bgp_route_map_update_timer(struct thread
*thread
)
3356 bm
->t_rmap_update
= NULL
;
3358 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3363 static void bgp_route_map_mark_update(const char *rmap_name
)
3365 if (bm
->t_rmap_update
== NULL
) {
3366 struct listnode
*node
, *nnode
;
3369 /* rmap_update_timer of 0 means don't do route updates */
3370 if (bm
->rmap_update_timer
) {
3371 bm
->t_rmap_update
= NULL
;
3372 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3373 NULL
, bm
->rmap_update_timer
,
3374 &bm
->t_rmap_update
);
3376 /* Signal the groups that a route-map update event has
3378 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3379 update_group_policy_update(bgp
,
3380 BGP_POLICY_ROUTE_MAP
,
3383 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3384 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3386 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3387 vnc_routemap_update(bgp
, __func__
);
3393 static void bgp_route_map_add(const char *rmap_name
)
3395 if (route_map_mark_updated(rmap_name
) == 0)
3396 bgp_route_map_mark_update(rmap_name
);
3398 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3401 static void bgp_route_map_delete(const char *rmap_name
)
3403 if (route_map_mark_updated(rmap_name
) == 0)
3404 bgp_route_map_mark_update(rmap_name
);
3406 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3409 static void bgp_route_map_event(route_map_event_t event
, const char *rmap_name
)
3411 if (route_map_mark_updated(rmap_name
) == 0)
3412 bgp_route_map_mark_update(rmap_name
);
3414 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3417 DEFUN (match_mac_address
,
3418 match_mac_address_cmd
,
3419 "match mac address WORD",
3422 "Match address of route\n"
3423 "MAC Access-list name\n")
3425 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3426 RMAP_EVENT_FILTER_ADDED
);
3429 DEFUN (no_match_mac_address
,
3430 no_match_mac_address_cmd
,
3431 "no match mac address WORD",
3435 "Match address of route\n"
3436 "MAC acess-list name\n")
3438 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3439 RMAP_EVENT_FILTER_DELETED
);
3442 DEFUN (match_evpn_route_type
,
3443 match_evpn_route_type_cmd
,
3444 "match evpn route-type <macip | multicast | prefix>",
3447 "Match route-type\n"
3452 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3453 RMAP_EVENT_MATCH_ADDED
);
3456 DEFUN (no_match_evpn_route_type
,
3457 no_match_evpn_route_type_cmd
,
3458 "no match evpn route-type <macip | multicast | prefix>",
3462 "Match route-type\n"
3467 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3468 RMAP_EVENT_MATCH_DELETED
);
3472 DEFUN (match_evpn_vni
,
3474 "match evpn vni " CMD_VNI_RANGE
,
3480 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3481 RMAP_EVENT_MATCH_ADDED
);
3484 DEFUN (no_match_evpn_vni
,
3485 no_match_evpn_vni_cmd
,
3486 "no match evpn vni " CMD_VNI_RANGE
,
3493 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3494 RMAP_EVENT_MATCH_DELETED
);
3497 DEFUN (match_evpn_default_route
,
3498 match_evpn_default_route_cmd
,
3499 "match evpn default-route",
3502 "default EVPN type-5 route\n")
3504 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3505 RMAP_EVENT_MATCH_ADDED
);
3508 DEFUN (no_match_evpn_default_route
,
3509 no_match_evpn_default_route_cmd
,
3510 "no match evpn default-route",
3514 "default EVPN type-5 route\n")
3516 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3517 RMAP_EVENT_MATCH_DELETED
);
3522 "match peer <A.B.C.D|X:X::X:X|WORD>",
3524 "Match peer address\n"
3525 "IP address of peer\n"
3526 "IPv6 address of peer\n"
3527 "Interface name of peer\n")
3530 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3531 RMAP_EVENT_MATCH_ADDED
);
3534 DEFUN (match_peer_local
,
3535 match_peer_local_cmd
,
3538 "Match peer address\n"
3539 "Static or Redistributed routes\n")
3541 return bgp_route_match_add(vty
, "peer", "local",
3542 RMAP_EVENT_MATCH_DELETED
);
3545 DEFUN (no_match_peer
,
3547 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3550 "Match peer address\n"
3551 "Static or Redistributed routes\n"
3552 "IP address of peer\n"
3553 "IPv6 address of peer\n"
3554 "Interface name of peer\n")
3558 if (argc
<= idx_peer
)
3559 return bgp_route_match_delete(vty
, "peer", NULL
,
3560 RMAP_EVENT_MATCH_DELETED
);
3561 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3562 RMAP_EVENT_MATCH_DELETED
);
3565 #if defined(HAVE_LUA)
3566 DEFUN (match_command
,
3568 "match command WORD",
3570 "Run a command to match\n"
3571 "The command to run\n")
3573 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3574 RMAP_EVENT_FILTER_ADDED
);
3577 DEFUN (no_match_command
,
3578 no_match_command_cmd
,
3579 "no match command WORD",
3582 "Run a command to match\n"
3583 "The command to run\n")
3585 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3586 RMAP_EVENT_FILTER_DELETED
);
3590 /* match probability */
3591 DEFUN (match_probability
,
3592 match_probability_cmd
,
3593 "match probability (0-100)",
3595 "Match portion of routes defined by percentage value\n"
3596 "Percentage of routes\n")
3599 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3600 RMAP_EVENT_MATCH_ADDED
);
3604 DEFUN (no_match_probability
,
3605 no_match_probability_cmd
,
3606 "no match probability [(1-99)]",
3609 "Match portion of routes defined by percentage value\n"
3610 "Percentage of routes\n")
3613 if (argc
<= idx_number
)
3614 return bgp_route_match_delete(vty
, "probability", NULL
,
3615 RMAP_EVENT_MATCH_DELETED
);
3616 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3617 RMAP_EVENT_MATCH_DELETED
);
3621 DEFUN (match_ip_route_source
,
3622 match_ip_route_source_cmd
,
3623 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3626 "Match advertising source address of route\n"
3627 "IP access-list number\n"
3628 "IP access-list number (expanded range)\n"
3629 "IP standard access-list name\n")
3632 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3633 RMAP_EVENT_FILTER_ADDED
);
3637 DEFUN (no_match_ip_route_source
,
3638 no_match_ip_route_source_cmd
,
3639 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3643 "Match advertising source address of route\n"
3644 "IP access-list number\n"
3645 "IP access-list number (expanded range)\n"
3646 "IP standard access-list name\n")
3649 if (argc
<= idx_number
)
3650 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3651 RMAP_EVENT_FILTER_DELETED
);
3652 return bgp_route_match_delete(vty
, "ip route-source",
3653 argv
[idx_number
]->arg
,
3654 RMAP_EVENT_FILTER_DELETED
);
3658 DEFUN (match_ip_route_source_prefix_list
,
3659 match_ip_route_source_prefix_list_cmd
,
3660 "match ip route-source prefix-list WORD",
3663 "Match advertising source address of route\n"
3664 "Match entries of prefix-lists\n"
3665 "IP prefix-list name\n")
3668 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3669 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3673 DEFUN (no_match_ip_route_source_prefix_list
,
3674 no_match_ip_route_source_prefix_list_cmd
,
3675 "no match ip route-source prefix-list [WORD]",
3679 "Match advertising source address of route\n"
3680 "Match entries of prefix-lists\n"
3681 "IP prefix-list name\n")
3684 if (argc
<= idx_word
)
3685 return bgp_route_match_delete(vty
,
3686 "ip route-source prefix-list",
3687 NULL
, RMAP_EVENT_PLIST_DELETED
);
3688 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3689 argv
[idx_word
]->arg
,
3690 RMAP_EVENT_PLIST_DELETED
);
3694 DEFUN (match_local_pref
,
3695 match_local_pref_cmd
,
3696 "match local-preference (0-4294967295)",
3698 "Match local-preference of route\n"
3702 return bgp_route_match_add(vty
, "local-preference",
3703 argv
[idx_number
]->arg
,
3704 RMAP_EVENT_MATCH_ADDED
);
3708 DEFUN (no_match_local_pref
,
3709 no_match_local_pref_cmd
,
3710 "no match local-preference [(0-4294967295)]",
3713 "Match local preference of route\n"
3714 "Local preference value\n")
3716 int idx_localpref
= 3;
3717 if (argc
<= idx_localpref
)
3718 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3719 RMAP_EVENT_MATCH_DELETED
);
3720 return bgp_route_match_delete(vty
, "local-preference",
3721 argv
[idx_localpref
]->arg
,
3722 RMAP_EVENT_MATCH_DELETED
);
3726 DEFUN (match_community
,
3727 match_community_cmd
,
3728 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3730 "Match BGP community list\n"
3731 "Community-list number (standard)\n"
3732 "Community-list number (expanded)\n"
3733 "Community-list name\n"
3734 "Do exact matching of communities\n")
3736 int idx_comm_list
= 2;
3741 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3742 strlen(argv
[idx_comm_list
]->arg
)
3743 + strlen("exact-match") + 2);
3745 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3747 argstr
= argv
[idx_comm_list
]->arg
;
3749 ret
= bgp_route_match_add(vty
, "community", argstr
,
3750 RMAP_EVENT_CLIST_ADDED
);
3752 if (argstr
!= argv
[idx_comm_list
]->arg
)
3753 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3758 DEFUN (no_match_community
,
3759 no_match_community_cmd
,
3760 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3763 "Match BGP community list\n"
3764 "Community-list number (standard)\n"
3765 "Community-list number (expanded)\n"
3766 "Community-list name\n"
3767 "Do exact matching of communities\n")
3769 return bgp_route_match_delete(vty
, "community", NULL
,
3770 RMAP_EVENT_CLIST_DELETED
);
3773 DEFUN (match_lcommunity
,
3774 match_lcommunity_cmd
,
3775 "match large-community <(1-99)|(100-500)|WORD>",
3777 "Match BGP large community list\n"
3778 "Large Community-list number (standard)\n"
3779 "Large Community-list number (expanded)\n"
3780 "Large Community-list name\n")
3782 return bgp_route_match_add(vty
, "large-community", argv
[2]->arg
,
3783 RMAP_EVENT_LLIST_ADDED
);
3786 DEFUN (no_match_lcommunity
,
3787 no_match_lcommunity_cmd
,
3788 "no match large-community [<(1-99)|(100-500)|WORD>]",
3791 "Match BGP large community list\n"
3792 "Large Community-list number (standard)\n"
3793 "Large Community-list number (expanded)\n"
3794 "Large Community-list name\n")
3796 return bgp_route_match_delete(vty
, "large-community", NULL
,
3797 RMAP_EVENT_LLIST_DELETED
);
3800 DEFUN (match_ecommunity
,
3801 match_ecommunity_cmd
,
3802 "match extcommunity <(1-99)|(100-500)|WORD>",
3804 "Match BGP/VPN extended community list\n"
3805 "Extended community-list number (standard)\n"
3806 "Extended community-list number (expanded)\n"
3807 "Extended community-list name\n")
3809 int idx_comm_list
= 2;
3810 return bgp_route_match_add(vty
, "extcommunity",
3811 argv
[idx_comm_list
]->arg
,
3812 RMAP_EVENT_ECLIST_ADDED
);
3816 DEFUN (no_match_ecommunity
,
3817 no_match_ecommunity_cmd
,
3818 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3821 "Match BGP/VPN extended community list\n"
3822 "Extended community-list number (standard)\n"
3823 "Extended community-list number (expanded)\n"
3824 "Extended community-list name\n")
3826 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3827 RMAP_EVENT_ECLIST_DELETED
);
3831 DEFUN (match_aspath
,
3833 "match as-path WORD",
3835 "Match BGP AS path list\n"
3836 "AS path access-list name\n")
3839 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3840 RMAP_EVENT_ASLIST_ADDED
);
3844 DEFUN (no_match_aspath
,
3845 no_match_aspath_cmd
,
3846 "no match as-path [WORD]",
3849 "Match BGP AS path list\n"
3850 "AS path access-list name\n")
3852 return bgp_route_match_delete(vty
, "as-path", NULL
,
3853 RMAP_EVENT_ASLIST_DELETED
);
3857 DEFUN (match_origin
,
3859 "match origin <egp|igp|incomplete>",
3864 "unknown heritage\n")
3867 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3868 return bgp_route_match_add(vty
, "origin", "igp",
3869 RMAP_EVENT_MATCH_ADDED
);
3870 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3871 return bgp_route_match_add(vty
, "origin", "egp",
3872 RMAP_EVENT_MATCH_ADDED
);
3873 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3874 return bgp_route_match_add(vty
, "origin", "incomplete",
3875 RMAP_EVENT_MATCH_ADDED
);
3877 vty_out(vty
, "%% Invalid match origin type\n");
3878 return CMD_WARNING_CONFIG_FAILED
;
3882 DEFUN (no_match_origin
,
3883 no_match_origin_cmd
,
3884 "no match origin [<egp|igp|incomplete>]",
3890 "unknown heritage\n")
3892 return bgp_route_match_delete(vty
, "origin", NULL
,
3893 RMAP_EVENT_MATCH_DELETED
);
3896 DEFUN (set_ip_nexthop_peer
,
3897 set_ip_nexthop_peer_cmd
,
3898 "[no] set ip next-hop peer-address",
3902 "Next hop address\n"
3903 "Use peer address (for BGP only)\n")
3905 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3906 const char *) = strmatch(argv
[0]->text
, "no")
3907 ? generic_set_delete
3910 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3914 DEFUN (set_ip_nexthop_unchanged
,
3915 set_ip_nexthop_unchanged_cmd
,
3916 "[no] set ip next-hop unchanged",
3920 "Next hop address\n"
3921 "Don't modify existing Next hop address\n")
3923 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3924 const char *) = strmatch(argv
[0]->text
, "no")
3925 ? generic_set_delete
3928 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3933 DEFUN (set_local_pref
,
3935 "set local-preference (0-4294967295)",
3937 "BGP local preference path attribute\n"
3938 "Preference value\n")
3941 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3942 "local-preference", argv
[idx_number
]->arg
);
3946 DEFUN (no_set_local_pref
,
3947 no_set_local_pref_cmd
,
3948 "no set local-preference [(0-4294967295)]",
3951 "BGP local preference path attribute\n"
3952 "Preference value\n")
3954 int idx_localpref
= 3;
3955 if (argc
<= idx_localpref
)
3956 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3957 "local-preference", NULL
);
3958 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3959 "local-preference", argv
[idx_localpref
]->arg
);
3965 "set weight (0-4294967295)",
3967 "BGP weight for routing table\n"
3971 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
3972 argv
[idx_number
]->arg
);
3976 DEFUN (no_set_weight
,
3978 "no set weight [(0-4294967295)]",
3981 "BGP weight for routing table\n"
3985 if (argc
<= idx_weight
)
3986 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3988 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3989 "weight", argv
[idx_weight
]->arg
);
3992 DEFUN (set_label_index
,
3993 set_label_index_cmd
,
3994 "set label-index (0-1048560)",
3996 "Label index to associate with the prefix\n"
3997 "Label index value\n")
4000 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4001 "label-index", argv
[idx_number
]->arg
);
4004 DEFUN (no_set_label_index
,
4005 no_set_label_index_cmd
,
4006 "no set label-index [(0-1048560)]",
4009 "Label index to associate with the prefix\n"
4010 "Label index value\n")
4012 int idx_label_index
= 3;
4013 if (argc
<= idx_label_index
)
4014 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4015 "label-index", NULL
);
4016 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4017 "label-index", argv
[idx_label_index
]->arg
);
4020 DEFUN (set_aspath_prepend_asn
,
4021 set_aspath_prepend_asn_cmd
,
4022 "set as-path prepend (1-4294967295)...",
4024 "Transform BGP AS_PATH attribute\n"
4025 "Prepend to the as-path\n"
4032 str
= argv_concat(argv
, argc
, idx_asn
);
4033 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4034 "as-path prepend", str
);
4035 XFREE(MTYPE_TMP
, str
);
4040 DEFUN (set_aspath_prepend_lastas
,
4041 set_aspath_prepend_lastas_cmd
,
4042 "set as-path prepend last-as (1-10)",
4044 "Transform BGP AS_PATH attribute\n"
4045 "Prepend to the as-path\n"
4046 "Use the peer's AS-number\n"
4047 "Number of times to insert\n")
4049 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4052 DEFUN (no_set_aspath_prepend
,
4053 no_set_aspath_prepend_cmd
,
4054 "no set as-path prepend [(1-4294967295)]",
4057 "Transform BGP AS_PATH attribute\n"
4058 "Prepend to the as-path\n"
4065 str
= argv_concat(argv
, argc
, idx_asn
);
4066 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4067 "as-path prepend", str
);
4068 XFREE(MTYPE_TMP
, str
);
4073 DEFUN (set_aspath_exclude
,
4074 set_aspath_exclude_cmd
,
4075 "set as-path exclude (1-4294967295)...",
4077 "Transform BGP AS-path attribute\n"
4078 "Exclude from 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 exclude", str
);
4088 XFREE(MTYPE_TMP
, str
);
4092 DEFUN (no_set_aspath_exclude
,
4093 no_set_aspath_exclude_cmd
,
4094 "no set as-path exclude (1-4294967295)...",
4097 "Transform BGP AS_PATH attribute\n"
4098 "Exclude from the as-path\n"
4105 str
= argv_concat(argv
, argc
, idx_asn
);
4106 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4107 "as-path exclude", str
);
4108 XFREE(MTYPE_TMP
, str
);
4112 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4113 "no set as-path exclude",
4115 "Transform BGP AS_PATH attribute\n"
4116 "Exclude from the as-path\n")
4118 DEFUN (set_community
,
4120 "set community AA:NN...",
4122 "BGP community attribute\n"
4130 struct community
*com
= NULL
;
4135 b
= buffer_new(1024);
4137 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4138 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4145 buffer_putc(b
, ' ');
4149 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4151 buffer_putstr(b
, "internet");
4154 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4156 buffer_putstr(b
, "local-AS");
4159 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4160 && strncmp(argv
[i
]->arg
, "no-advertise",
4161 strlen(argv
[i
]->arg
))
4163 buffer_putstr(b
, "no-advertise");
4166 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4167 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4169 buffer_putstr(b
, "no-export");
4172 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4173 strlen(argv
[i
]->arg
))
4175 buffer_putstr(b
, "graceful-shutdown");
4178 buffer_putstr(b
, argv
[i
]->arg
);
4180 buffer_putc(b
, '\0');
4182 /* Fetch result string then compile it to communities attribute. */
4183 str
= buffer_getstr(b
);
4187 com
= community_str2com(str
);
4188 XFREE(MTYPE_TMP
, str
);
4191 /* Can't compile user input into communities attribute. */
4193 vty_out(vty
, "%% Malformed communities attribute\n");
4194 return CMD_WARNING_CONFIG_FAILED
;
4197 /* Set communites attribute string. */
4198 str
= community_str(com
, false);
4201 argstr
= XCALLOC(MTYPE_TMP
,
4202 strlen(str
) + strlen(" additive") + 1);
4203 strcpy(argstr
, str
);
4204 strcpy(argstr
+ strlen(str
), " additive");
4205 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4206 "community", argstr
);
4207 XFREE(MTYPE_TMP
, argstr
);
4209 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4212 community_free(&com
);
4217 DEFUN (set_community_none
,
4218 set_community_none_cmd
,
4219 "set community none",
4221 "BGP community attribute\n"
4222 "No community attribute\n")
4224 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4225 "community", "none");
4228 DEFUN (no_set_community
,
4229 no_set_community_cmd
,
4230 "no set community AA:NN...",
4233 "BGP community attribute\n"
4236 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4240 ALIAS (no_set_community
,
4241 no_set_community_short_cmd
,
4245 "BGP community attribute\n")
4248 DEFUN (set_community_delete
,
4249 set_community_delete_cmd
,
4250 "set comm-list <(1-99)|(100-500)|WORD> delete",
4252 "set BGP community list (for deletion)\n"
4253 "Community-list number (standard)\n"
4254 "Community-list number (expanded)\n"
4255 "Community-list name\n"
4256 "Delete matching communities\n")
4258 int idx_comm_list
= 2;
4261 str
= XCALLOC(MTYPE_TMP
,
4262 strlen(argv
[idx_comm_list
]->arg
) + strlen(" delete") + 1);
4263 strcpy(str
, argv
[idx_comm_list
]->arg
);
4264 strcpy(str
+ strlen(argv
[idx_comm_list
]->arg
), " delete");
4266 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4269 XFREE(MTYPE_TMP
, str
);
4273 DEFUN (no_set_community_delete
,
4274 no_set_community_delete_cmd
,
4275 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4278 "set BGP community list (for deletion)\n"
4279 "Community-list number (standard)\n"
4280 "Community-list number (expanded)\n"
4281 "Community-list name\n"
4282 "Delete matching communities\n")
4284 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4288 DEFUN (set_lcommunity
,
4290 "set large-community AA:BB:CC...",
4292 "BGP large community attribute\n"
4293 "Large Community number in aa:bb:cc format or additive\n")
4298 str
= argv_concat(argv
, argc
, 2);
4299 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4300 "large-community", str
);
4301 XFREE(MTYPE_TMP
, str
);
4306 DEFUN (set_lcommunity_none
,
4307 set_lcommunity_none_cmd
,
4308 "set large-community none",
4310 "BGP large community attribute\n"
4311 "No large community attribute\n")
4313 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4314 "large-community", "none");
4317 DEFUN (no_set_lcommunity
,
4318 no_set_lcommunity_cmd
,
4319 "no set large-community none",
4322 "BGP large community attribute\n"
4323 "No community attribute\n")
4325 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4326 "large-community", NULL
);
4329 DEFUN (no_set_lcommunity1
,
4330 no_set_lcommunity1_cmd
,
4331 "no set large-community AA:BB:CC...",
4334 "BGP large community attribute\n"
4335 "Large community in AA:BB:CC... format or additive\n")
4337 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4338 "large-community", NULL
);
4341 ALIAS (no_set_lcommunity1
,
4342 no_set_lcommunity1_short_cmd
,
4343 "no set large-community",
4346 "BGP large community attribute\n")
4348 DEFUN (set_lcommunity_delete
,
4349 set_lcommunity_delete_cmd
,
4350 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4352 "set BGP large community list (for deletion)\n"
4353 "Large Community-list number (standard)\n"
4354 "Large Communitly-list number (expanded)\n"
4355 "Large Community-list name\n"
4356 "Delete matching large communities\n")
4360 str
= XCALLOC(MTYPE_TMP
, strlen(argv
[2]->arg
) + strlen(" delete") + 1);
4361 strcpy(str
, argv
[2]->arg
);
4362 strcpy(str
+ strlen(argv
[2]->arg
), " delete");
4364 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4365 "large-comm-list", str
);
4367 XFREE(MTYPE_TMP
, str
);
4371 DEFUN (no_set_lcommunity_delete
,
4372 no_set_lcommunity_delete_cmd
,
4373 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4376 "set BGP large community list (for deletion)\n"
4377 "Large Community-list number (standard)\n"
4378 "Large Communitly-list number (expanded)\n"
4379 "Large Community-list name\n"
4380 "Delete matching large communities\n")
4382 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4383 "large-comm-list", NULL
);
4386 ALIAS (no_set_lcommunity_delete
,
4387 no_set_lcommunity_delete_short_cmd
,
4388 "no set large-comm-list",
4391 "set BGP large community list (for deletion)\n")
4393 DEFUN (set_ecommunity_rt
,
4394 set_ecommunity_rt_cmd
,
4395 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4397 "BGP extended community attribute\n"
4398 "Route Target extended community\n"
4399 "VPN extended community\n")
4405 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4406 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4407 "extcommunity rt", str
);
4408 XFREE(MTYPE_TMP
, str
);
4413 DEFUN (no_set_ecommunity_rt
,
4414 no_set_ecommunity_rt_cmd
,
4415 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4418 "BGP extended community attribute\n"
4419 "Route Target extended community\n"
4420 "VPN extended community\n")
4422 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4423 "extcommunity rt", NULL
);
4426 ALIAS (no_set_ecommunity_rt
,
4427 no_set_ecommunity_rt_short_cmd
,
4428 "no set extcommunity rt",
4431 "BGP extended community attribute\n"
4432 "Route Target extended community\n")
4434 DEFUN (set_ecommunity_soo
,
4435 set_ecommunity_soo_cmd
,
4436 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4438 "BGP extended community attribute\n"
4439 "Site-of-Origin extended community\n"
4440 "VPN extended community\n")
4446 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4447 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4448 "extcommunity soo", str
);
4449 XFREE(MTYPE_TMP
, str
);
4454 DEFUN (no_set_ecommunity_soo
,
4455 no_set_ecommunity_soo_cmd
,
4456 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4459 "BGP extended community attribute\n"
4460 "Site-of-Origin extended community\n"
4461 "VPN extended community\n")
4463 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4464 "extcommunity soo", NULL
);
4467 ALIAS (no_set_ecommunity_soo
,
4468 no_set_ecommunity_soo_short_cmd
,
4469 "no set extcommunity soo",
4472 "GP extended community attribute\n"
4473 "Site-of-Origin extended community\n")
4477 "set origin <egp|igp|incomplete>",
4482 "unknown heritage\n")
4485 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4486 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4488 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4489 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4491 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4492 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4493 "origin", "incomplete");
4495 vty_out(vty
, "%% Invalid set origin type\n");
4496 return CMD_WARNING_CONFIG_FAILED
;
4500 DEFUN (no_set_origin
,
4502 "no set origin [<egp|igp|incomplete>]",
4508 "unknown heritage\n")
4510 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4515 DEFUN (set_atomic_aggregate
,
4516 set_atomic_aggregate_cmd
,
4517 "set atomic-aggregate",
4519 "BGP atomic aggregate attribute\n" )
4521 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4522 "atomic-aggregate", NULL
);
4525 DEFUN (no_set_atomic_aggregate
,
4526 no_set_atomic_aggregate_cmd
,
4527 "no set atomic-aggregate",
4530 "BGP atomic aggregate attribute\n" )
4532 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4533 "atomic-aggregate", NULL
);
4536 DEFUN (set_aggregator_as
,
4537 set_aggregator_as_cmd
,
4538 "set aggregator as (1-4294967295) A.B.C.D",
4540 "BGP aggregator attribute\n"
4541 "AS number of aggregator\n"
4543 "IP address of aggregator\n")
4548 struct in_addr address
;
4551 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4553 vty_out(vty
, "Aggregator IP address is invalid\n");
4554 return CMD_WARNING_CONFIG_FAILED
;
4557 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4558 strlen(argv
[idx_number
]->arg
)
4559 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4561 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4563 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4564 "aggregator as", argstr
);
4566 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4572 DEFUN (no_set_aggregator_as
,
4573 no_set_aggregator_as_cmd
,
4574 "no set aggregator as [(1-4294967295) A.B.C.D]",
4577 "BGP aggregator attribute\n"
4578 "AS number of aggregator\n"
4580 "IP address of aggregator\n")
4585 struct in_addr address
;
4588 if (argc
<= idx_asn
)
4589 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4590 "aggregator as", NULL
);
4592 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4594 vty_out(vty
, "Aggregator IP address is invalid\n");
4595 return CMD_WARNING_CONFIG_FAILED
;
4598 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4599 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4602 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4604 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4605 "aggregator as", argstr
);
4607 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4612 DEFUN (match_ipv6_next_hop
,
4613 match_ipv6_next_hop_cmd
,
4614 "match ipv6 next-hop X:X::X:X",
4617 "Match IPv6 next-hop address of route\n"
4618 "IPv6 address of next hop\n")
4621 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4622 RMAP_EVENT_MATCH_ADDED
);
4625 DEFUN (no_match_ipv6_next_hop
,
4626 no_match_ipv6_next_hop_cmd
,
4627 "no match ipv6 next-hop X:X::X:X",
4631 "Match IPv6 next-hop address of route\n"
4632 "IPv6 address of next hop\n")
4635 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4636 RMAP_EVENT_MATCH_DELETED
);
4640 DEFUN (set_ipv6_nexthop_peer
,
4641 set_ipv6_nexthop_peer_cmd
,
4642 "set ipv6 next-hop peer-address",
4645 "Next hop address\n"
4646 "Use peer address (for BGP only)\n")
4648 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4649 "ipv6 next-hop peer-address", NULL
);
4652 DEFUN (no_set_ipv6_nexthop_peer
,
4653 no_set_ipv6_nexthop_peer_cmd
,
4654 "no set ipv6 next-hop peer-address",
4658 "IPv6 next-hop address\n"
4659 "Use peer address (for BGP only)\n")
4661 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4662 "ipv6 next-hop peer-address", NULL
);
4665 DEFUN (set_ipv6_nexthop_prefer_global
,
4666 set_ipv6_nexthop_prefer_global_cmd
,
4667 "set ipv6 next-hop prefer-global",
4670 "IPv6 next-hop address\n"
4671 "Prefer global over link-local if both exist\n")
4673 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4674 "ipv6 next-hop prefer-global", NULL
);
4678 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4679 no_set_ipv6_nexthop_prefer_global_cmd
,
4680 "no set ipv6 next-hop prefer-global",
4684 "IPv6 next-hop address\n"
4685 "Prefer global over link-local if both exist\n")
4687 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4688 "ipv6 next-hop prefer-global", NULL
);
4691 DEFUN (set_ipv6_nexthop_global
,
4692 set_ipv6_nexthop_global_cmd
,
4693 "set ipv6 next-hop global X:X::X:X",
4696 "IPv6 next-hop address\n"
4697 "IPv6 global address\n"
4698 "IPv6 address of next hop\n")
4701 struct in6_addr addr
;
4704 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4706 vty_out(vty
, "%% Malformed nexthop address\n");
4707 return CMD_WARNING_CONFIG_FAILED
;
4709 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4710 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4711 vty_out(vty
, "%% Invalid global nexthop address\n");
4712 return CMD_WARNING_CONFIG_FAILED
;
4715 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4716 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4720 DEFUN (no_set_ipv6_nexthop_global
,
4721 no_set_ipv6_nexthop_global_cmd
,
4722 "no set ipv6 next-hop global X:X::X:X",
4726 "IPv6 next-hop address\n"
4727 "IPv6 global address\n"
4728 "IPv6 address of next hop\n")
4731 if (argc
<= idx_ipv6
)
4732 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4733 "ipv6 next-hop global", NULL
);
4734 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4735 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4738 #ifdef KEEP_OLD_VPN_COMMANDS
4739 DEFUN (set_vpn_nexthop
,
4740 set_vpn_nexthop_cmd
,
4741 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4743 "VPNv4 information\n"
4744 "VPN next-hop address\n"
4745 "IP address of next hop\n"
4746 "VPNv6 information\n"
4747 "VPN next-hop address\n"
4748 "IPv6 address of next hop\n")
4754 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4756 return generic_set_add(
4757 vty
, VTY_GET_CONTEXT(route_map_index
),
4758 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4760 return generic_set_add(
4761 vty
, VTY_GET_CONTEXT(route_map_index
),
4762 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4767 DEFUN (no_set_vpn_nexthop
,
4768 no_set_vpn_nexthop_cmd
,
4769 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4772 "VPNv4 information\n"
4773 "VPN next-hop address\n"
4774 "IP address of next hop\n"
4775 "VPNv6 information\n"
4776 "VPN next-hop address\n"
4777 "IPv6 address of next hop\n")
4787 arg
= argv
[idx_ip
]->arg
;
4788 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4790 return generic_set_delete(
4791 vty
, VTY_GET_CONTEXT(route_map_index
),
4792 "ipv4 vpn next-hop", arg
);
4794 return generic_set_delete(
4795 vty
, VTY_GET_CONTEXT(route_map_index
),
4796 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4800 #endif /* KEEP_OLD_VPN_COMMANDS */
4802 DEFUN (set_ipx_vpn_nexthop
,
4803 set_ipx_vpn_nexthop_cmd
,
4804 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4806 "IPv4 information\n"
4807 "IPv6 information\n"
4809 "VPN next-hop address\n"
4810 "IP address of next hop\n"
4811 "IPv6 address of next hop\n")
4817 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4819 return generic_set_add(
4820 vty
, VTY_GET_CONTEXT(route_map_index
),
4821 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4823 return generic_set_add(
4824 vty
, VTY_GET_CONTEXT(route_map_index
),
4825 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4830 DEFUN (no_set_ipx_vpn_nexthop
,
4831 no_set_ipx_vpn_nexthop_cmd
,
4832 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4835 "IPv4 information\n"
4836 "IPv6 information\n"
4838 "VPN next-hop address\n"
4839 "IP address of next hop\n"
4840 "IPv6 address of next hop\n")
4850 arg
= argv
[idx_ip
]->arg
;
4851 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4853 return generic_set_delete(
4854 vty
, VTY_GET_CONTEXT(route_map_index
),
4855 "ipv4 vpn next-hop", arg
);
4857 return generic_set_delete(
4858 vty
, VTY_GET_CONTEXT(route_map_index
),
4859 "ipv6 vpn next-hop", arg
);
4864 DEFUN (set_originator_id
,
4865 set_originator_id_cmd
,
4866 "set originator-id A.B.C.D",
4868 "BGP originator ID attribute\n"
4869 "IP address of originator\n")
4872 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4873 "originator-id", argv
[idx_ipv4
]->arg
);
4877 DEFUN (no_set_originator_id
,
4878 no_set_originator_id_cmd
,
4879 "no set originator-id [A.B.C.D]",
4882 "BGP originator ID attribute\n"
4883 "IP address of originator\n")
4887 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4889 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4890 "originator-id", arg
);
4894 /* Initialization of route map. */
4895 void bgp_route_map_init(void)
4899 route_map_add_hook(bgp_route_map_add
);
4900 route_map_delete_hook(bgp_route_map_delete
);
4901 route_map_event_hook(bgp_route_map_event
);
4903 route_map_match_interface_hook(generic_match_add
);
4904 route_map_no_match_interface_hook(generic_match_delete
);
4906 route_map_match_ip_address_hook(generic_match_add
);
4907 route_map_no_match_ip_address_hook(generic_match_delete
);
4909 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
4910 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
4912 route_map_match_ip_next_hop_hook(generic_match_add
);
4913 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
4915 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
4916 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
4918 route_map_match_ip_next_hop_type_hook(generic_match_add
);
4919 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
4921 route_map_match_ipv6_address_hook(generic_match_add
);
4922 route_map_no_match_ipv6_address_hook(generic_match_delete
);
4924 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
4925 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
4927 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
4928 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
4930 route_map_match_metric_hook(generic_match_add
);
4931 route_map_no_match_metric_hook(generic_match_delete
);
4933 route_map_match_tag_hook(generic_match_add
);
4934 route_map_no_match_tag_hook(generic_match_delete
);
4936 route_map_set_ip_nexthop_hook(generic_set_add
);
4937 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
4939 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
4940 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
4942 route_map_set_metric_hook(generic_set_add
);
4943 route_map_no_set_metric_hook(generic_set_delete
);
4945 route_map_set_tag_hook(generic_set_add
);
4946 route_map_no_set_tag_hook(generic_set_delete
);
4948 route_map_install_match(&route_match_peer_cmd
);
4949 route_map_install_match(&route_match_local_pref_cmd
);
4950 #if defined(HAVE_LUA)
4951 route_map_install_match(&route_match_command_cmd
);
4953 route_map_install_match(&route_match_ip_address_cmd
);
4954 route_map_install_match(&route_match_ip_next_hop_cmd
);
4955 route_map_install_match(&route_match_ip_route_source_cmd
);
4956 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
4957 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
4958 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
4959 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
4960 route_map_install_match(&route_match_aspath_cmd
);
4961 route_map_install_match(&route_match_community_cmd
);
4962 route_map_install_match(&route_match_lcommunity_cmd
);
4963 route_map_install_match(&route_match_ecommunity_cmd
);
4964 route_map_install_match(&route_match_local_pref_cmd
);
4965 route_map_install_match(&route_match_metric_cmd
);
4966 route_map_install_match(&route_match_origin_cmd
);
4967 route_map_install_match(&route_match_probability_cmd
);
4968 route_map_install_match(&route_match_interface_cmd
);
4969 route_map_install_match(&route_match_tag_cmd
);
4970 route_map_install_match(&route_match_mac_address_cmd
);
4971 route_map_install_match(&route_match_evpn_vni_cmd
);
4972 route_map_install_match(&route_match_evpn_route_type_cmd
);
4973 route_map_install_match(&route_match_evpn_default_route_cmd
);
4975 route_map_install_set(&route_set_ip_nexthop_cmd
);
4976 route_map_install_set(&route_set_local_pref_cmd
);
4977 route_map_install_set(&route_set_weight_cmd
);
4978 route_map_install_set(&route_set_label_index_cmd
);
4979 route_map_install_set(&route_set_metric_cmd
);
4980 route_map_install_set(&route_set_aspath_prepend_cmd
);
4981 route_map_install_set(&route_set_aspath_exclude_cmd
);
4982 route_map_install_set(&route_set_origin_cmd
);
4983 route_map_install_set(&route_set_atomic_aggregate_cmd
);
4984 route_map_install_set(&route_set_aggregator_as_cmd
);
4985 route_map_install_set(&route_set_community_cmd
);
4986 route_map_install_set(&route_set_community_delete_cmd
);
4987 route_map_install_set(&route_set_lcommunity_cmd
);
4988 route_map_install_set(&route_set_lcommunity_delete_cmd
);
4989 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
4990 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
4991 route_map_install_set(&route_set_originator_id_cmd
);
4992 route_map_install_set(&route_set_ecommunity_rt_cmd
);
4993 route_map_install_set(&route_set_ecommunity_soo_cmd
);
4994 route_map_install_set(&route_set_tag_cmd
);
4995 route_map_install_set(&route_set_label_index_cmd
);
4997 install_element(RMAP_NODE
, &match_peer_cmd
);
4998 install_element(RMAP_NODE
, &match_peer_local_cmd
);
4999 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5000 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5001 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5002 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5003 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5004 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5005 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5006 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5007 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5008 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5009 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5010 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5011 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5013 install_element(RMAP_NODE
, &match_aspath_cmd
);
5014 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5015 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5016 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5017 install_element(RMAP_NODE
, &match_community_cmd
);
5018 install_element(RMAP_NODE
, &no_match_community_cmd
);
5019 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5020 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5021 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5022 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5023 install_element(RMAP_NODE
, &match_origin_cmd
);
5024 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5025 install_element(RMAP_NODE
, &match_probability_cmd
);
5026 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5028 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5029 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5030 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5031 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5032 install_element(RMAP_NODE
, &set_weight_cmd
);
5033 install_element(RMAP_NODE
, &set_label_index_cmd
);
5034 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5035 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5036 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5037 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5038 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5039 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5040 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5041 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5042 install_element(RMAP_NODE
, &set_origin_cmd
);
5043 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5044 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5045 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5046 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5047 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5048 install_element(RMAP_NODE
, &set_community_cmd
);
5049 install_element(RMAP_NODE
, &set_community_none_cmd
);
5050 install_element(RMAP_NODE
, &no_set_community_cmd
);
5051 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5052 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5053 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5054 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5055 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5056 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5057 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5058 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5059 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5060 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5061 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5062 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5063 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5064 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5065 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5066 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5067 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5068 #ifdef KEEP_OLD_VPN_COMMANDS
5069 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5070 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5071 #endif /* KEEP_OLD_VPN_COMMANDS */
5072 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5073 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5074 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5075 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5077 route_map_install_match(&route_match_ipv6_address_cmd
);
5078 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5079 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5080 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5081 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5082 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5083 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5084 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5086 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5087 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5088 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5089 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5090 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5091 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5092 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5093 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5094 #if defined(HAVE_LUA)
5095 install_element(RMAP_NODE
, &match_command_cmd
);
5096 install_element(RMAP_NODE
, &no_match_command_cmd
);
5100 void bgp_route_map_terminate(void)
5102 /* ToDo: Cleanup all the used memory */