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 /* Make sure the route-map is populated here if not already done */
3329 bgp
->adv_cmd_rmap
[afi
][safi
].map
= map
;
3331 if (BGP_DEBUG(zebra
, ZEBRA
))
3333 "Processing route_map %s update on advertise type5 route command",
3337 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3338 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3343 static void bgp_route_map_process_update_cb(char *rmap_name
)
3345 struct listnode
*node
, *nnode
;
3348 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3349 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3352 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3353 vnc_routemap_update(bgp
, __func__
);
3357 vpn_policy_routemap_event(rmap_name
);
3360 int bgp_route_map_update_timer(struct thread
*thread
)
3362 bm
->t_rmap_update
= NULL
;
3364 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3369 static void bgp_route_map_mark_update(const char *rmap_name
)
3371 if (bm
->t_rmap_update
== NULL
) {
3372 struct listnode
*node
, *nnode
;
3375 /* rmap_update_timer of 0 means don't do route updates */
3376 if (bm
->rmap_update_timer
) {
3377 bm
->t_rmap_update
= NULL
;
3378 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3379 NULL
, bm
->rmap_update_timer
,
3380 &bm
->t_rmap_update
);
3382 /* Signal the groups that a route-map update event has
3384 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3385 update_group_policy_update(bgp
,
3386 BGP_POLICY_ROUTE_MAP
,
3389 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3390 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3392 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3393 vnc_routemap_update(bgp
, __func__
);
3399 static void bgp_route_map_add(const char *rmap_name
)
3401 if (route_map_mark_updated(rmap_name
) == 0)
3402 bgp_route_map_mark_update(rmap_name
);
3404 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3407 static void bgp_route_map_delete(const char *rmap_name
)
3409 if (route_map_mark_updated(rmap_name
) == 0)
3410 bgp_route_map_mark_update(rmap_name
);
3412 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3415 static void bgp_route_map_event(route_map_event_t event
, const char *rmap_name
)
3417 if (route_map_mark_updated(rmap_name
) == 0)
3418 bgp_route_map_mark_update(rmap_name
);
3420 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3423 DEFUN (match_mac_address
,
3424 match_mac_address_cmd
,
3425 "match mac address WORD",
3428 "Match address of route\n"
3429 "MAC Access-list name\n")
3431 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3432 RMAP_EVENT_FILTER_ADDED
);
3435 DEFUN (no_match_mac_address
,
3436 no_match_mac_address_cmd
,
3437 "no match mac address WORD",
3441 "Match address of route\n"
3442 "MAC acess-list name\n")
3444 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3445 RMAP_EVENT_FILTER_DELETED
);
3448 DEFUN (match_evpn_route_type
,
3449 match_evpn_route_type_cmd
,
3450 "match evpn route-type <macip | multicast | prefix>",
3453 "Match route-type\n"
3458 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3459 RMAP_EVENT_MATCH_ADDED
);
3462 DEFUN (no_match_evpn_route_type
,
3463 no_match_evpn_route_type_cmd
,
3464 "no match evpn route-type <macip | multicast | prefix>",
3468 "Match route-type\n"
3473 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3474 RMAP_EVENT_MATCH_DELETED
);
3478 DEFUN (match_evpn_vni
,
3480 "match evpn vni " CMD_VNI_RANGE
,
3486 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3487 RMAP_EVENT_MATCH_ADDED
);
3490 DEFUN (no_match_evpn_vni
,
3491 no_match_evpn_vni_cmd
,
3492 "no match evpn vni " CMD_VNI_RANGE
,
3499 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3500 RMAP_EVENT_MATCH_DELETED
);
3503 DEFUN (match_evpn_default_route
,
3504 match_evpn_default_route_cmd
,
3505 "match evpn default-route",
3508 "default EVPN type-5 route\n")
3510 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3511 RMAP_EVENT_MATCH_ADDED
);
3514 DEFUN (no_match_evpn_default_route
,
3515 no_match_evpn_default_route_cmd
,
3516 "no match evpn default-route",
3520 "default EVPN type-5 route\n")
3522 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3523 RMAP_EVENT_MATCH_DELETED
);
3528 "match peer <A.B.C.D|X:X::X:X|WORD>",
3530 "Match peer address\n"
3531 "IP address of peer\n"
3532 "IPv6 address of peer\n"
3533 "Interface name of peer\n")
3536 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3537 RMAP_EVENT_MATCH_ADDED
);
3540 DEFUN (match_peer_local
,
3541 match_peer_local_cmd
,
3544 "Match peer address\n"
3545 "Static or Redistributed routes\n")
3547 return bgp_route_match_add(vty
, "peer", "local",
3548 RMAP_EVENT_MATCH_DELETED
);
3551 DEFUN (no_match_peer
,
3553 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3556 "Match peer address\n"
3557 "Static or Redistributed routes\n"
3558 "IP address of peer\n"
3559 "IPv6 address of peer\n"
3560 "Interface name of peer\n")
3564 if (argc
<= idx_peer
)
3565 return bgp_route_match_delete(vty
, "peer", NULL
,
3566 RMAP_EVENT_MATCH_DELETED
);
3567 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3568 RMAP_EVENT_MATCH_DELETED
);
3571 #if defined(HAVE_LUA)
3572 DEFUN (match_command
,
3574 "match command WORD",
3576 "Run a command to match\n"
3577 "The command to run\n")
3579 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3580 RMAP_EVENT_FILTER_ADDED
);
3583 DEFUN (no_match_command
,
3584 no_match_command_cmd
,
3585 "no match command WORD",
3588 "Run a command to match\n"
3589 "The command to run\n")
3591 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3592 RMAP_EVENT_FILTER_DELETED
);
3596 /* match probability */
3597 DEFUN (match_probability
,
3598 match_probability_cmd
,
3599 "match probability (0-100)",
3601 "Match portion of routes defined by percentage value\n"
3602 "Percentage of routes\n")
3605 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3606 RMAP_EVENT_MATCH_ADDED
);
3610 DEFUN (no_match_probability
,
3611 no_match_probability_cmd
,
3612 "no match probability [(1-99)]",
3615 "Match portion of routes defined by percentage value\n"
3616 "Percentage of routes\n")
3619 if (argc
<= idx_number
)
3620 return bgp_route_match_delete(vty
, "probability", NULL
,
3621 RMAP_EVENT_MATCH_DELETED
);
3622 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3623 RMAP_EVENT_MATCH_DELETED
);
3627 DEFUN (match_ip_route_source
,
3628 match_ip_route_source_cmd
,
3629 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3632 "Match advertising source address of route\n"
3633 "IP access-list number\n"
3634 "IP access-list number (expanded range)\n"
3635 "IP standard access-list name\n")
3638 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3639 RMAP_EVENT_FILTER_ADDED
);
3643 DEFUN (no_match_ip_route_source
,
3644 no_match_ip_route_source_cmd
,
3645 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3649 "Match advertising source address of route\n"
3650 "IP access-list number\n"
3651 "IP access-list number (expanded range)\n"
3652 "IP standard access-list name\n")
3655 if (argc
<= idx_number
)
3656 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3657 RMAP_EVENT_FILTER_DELETED
);
3658 return bgp_route_match_delete(vty
, "ip route-source",
3659 argv
[idx_number
]->arg
,
3660 RMAP_EVENT_FILTER_DELETED
);
3664 DEFUN (match_ip_route_source_prefix_list
,
3665 match_ip_route_source_prefix_list_cmd
,
3666 "match ip route-source prefix-list WORD",
3669 "Match advertising source address of route\n"
3670 "Match entries of prefix-lists\n"
3671 "IP prefix-list name\n")
3674 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3675 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3679 DEFUN (no_match_ip_route_source_prefix_list
,
3680 no_match_ip_route_source_prefix_list_cmd
,
3681 "no match ip route-source prefix-list [WORD]",
3685 "Match advertising source address of route\n"
3686 "Match entries of prefix-lists\n"
3687 "IP prefix-list name\n")
3690 if (argc
<= idx_word
)
3691 return bgp_route_match_delete(vty
,
3692 "ip route-source prefix-list",
3693 NULL
, RMAP_EVENT_PLIST_DELETED
);
3694 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3695 argv
[idx_word
]->arg
,
3696 RMAP_EVENT_PLIST_DELETED
);
3700 DEFUN (match_local_pref
,
3701 match_local_pref_cmd
,
3702 "match local-preference (0-4294967295)",
3704 "Match local-preference of route\n"
3708 return bgp_route_match_add(vty
, "local-preference",
3709 argv
[idx_number
]->arg
,
3710 RMAP_EVENT_MATCH_ADDED
);
3714 DEFUN (no_match_local_pref
,
3715 no_match_local_pref_cmd
,
3716 "no match local-preference [(0-4294967295)]",
3719 "Match local preference of route\n"
3720 "Local preference value\n")
3722 int idx_localpref
= 3;
3723 if (argc
<= idx_localpref
)
3724 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3725 RMAP_EVENT_MATCH_DELETED
);
3726 return bgp_route_match_delete(vty
, "local-preference",
3727 argv
[idx_localpref
]->arg
,
3728 RMAP_EVENT_MATCH_DELETED
);
3732 DEFUN (match_community
,
3733 match_community_cmd
,
3734 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3736 "Match BGP community list\n"
3737 "Community-list number (standard)\n"
3738 "Community-list number (expanded)\n"
3739 "Community-list name\n"
3740 "Do exact matching of communities\n")
3742 int idx_comm_list
= 2;
3747 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3748 strlen(argv
[idx_comm_list
]->arg
)
3749 + strlen("exact-match") + 2);
3751 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3753 argstr
= argv
[idx_comm_list
]->arg
;
3755 ret
= bgp_route_match_add(vty
, "community", argstr
,
3756 RMAP_EVENT_CLIST_ADDED
);
3758 if (argstr
!= argv
[idx_comm_list
]->arg
)
3759 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3764 DEFUN (no_match_community
,
3765 no_match_community_cmd
,
3766 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3769 "Match BGP community list\n"
3770 "Community-list number (standard)\n"
3771 "Community-list number (expanded)\n"
3772 "Community-list name\n"
3773 "Do exact matching of communities\n")
3775 return bgp_route_match_delete(vty
, "community", NULL
,
3776 RMAP_EVENT_CLIST_DELETED
);
3779 DEFUN (match_lcommunity
,
3780 match_lcommunity_cmd
,
3781 "match large-community <(1-99)|(100-500)|WORD>",
3783 "Match BGP large community list\n"
3784 "Large Community-list number (standard)\n"
3785 "Large Community-list number (expanded)\n"
3786 "Large Community-list name\n")
3788 return bgp_route_match_add(vty
, "large-community", argv
[2]->arg
,
3789 RMAP_EVENT_LLIST_ADDED
);
3792 DEFUN (no_match_lcommunity
,
3793 no_match_lcommunity_cmd
,
3794 "no match large-community [<(1-99)|(100-500)|WORD>]",
3797 "Match BGP large community list\n"
3798 "Large Community-list number (standard)\n"
3799 "Large Community-list number (expanded)\n"
3800 "Large Community-list name\n")
3802 return bgp_route_match_delete(vty
, "large-community", NULL
,
3803 RMAP_EVENT_LLIST_DELETED
);
3806 DEFUN (match_ecommunity
,
3807 match_ecommunity_cmd
,
3808 "match extcommunity <(1-99)|(100-500)|WORD>",
3810 "Match BGP/VPN extended community list\n"
3811 "Extended community-list number (standard)\n"
3812 "Extended community-list number (expanded)\n"
3813 "Extended community-list name\n")
3815 int idx_comm_list
= 2;
3816 return bgp_route_match_add(vty
, "extcommunity",
3817 argv
[idx_comm_list
]->arg
,
3818 RMAP_EVENT_ECLIST_ADDED
);
3822 DEFUN (no_match_ecommunity
,
3823 no_match_ecommunity_cmd
,
3824 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3827 "Match BGP/VPN extended community list\n"
3828 "Extended community-list number (standard)\n"
3829 "Extended community-list number (expanded)\n"
3830 "Extended community-list name\n")
3832 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3833 RMAP_EVENT_ECLIST_DELETED
);
3837 DEFUN (match_aspath
,
3839 "match as-path WORD",
3841 "Match BGP AS path list\n"
3842 "AS path access-list name\n")
3845 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3846 RMAP_EVENT_ASLIST_ADDED
);
3850 DEFUN (no_match_aspath
,
3851 no_match_aspath_cmd
,
3852 "no match as-path [WORD]",
3855 "Match BGP AS path list\n"
3856 "AS path access-list name\n")
3858 return bgp_route_match_delete(vty
, "as-path", NULL
,
3859 RMAP_EVENT_ASLIST_DELETED
);
3863 DEFUN (match_origin
,
3865 "match origin <egp|igp|incomplete>",
3870 "unknown heritage\n")
3873 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3874 return bgp_route_match_add(vty
, "origin", "igp",
3875 RMAP_EVENT_MATCH_ADDED
);
3876 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3877 return bgp_route_match_add(vty
, "origin", "egp",
3878 RMAP_EVENT_MATCH_ADDED
);
3879 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3880 return bgp_route_match_add(vty
, "origin", "incomplete",
3881 RMAP_EVENT_MATCH_ADDED
);
3883 vty_out(vty
, "%% Invalid match origin type\n");
3884 return CMD_WARNING_CONFIG_FAILED
;
3888 DEFUN (no_match_origin
,
3889 no_match_origin_cmd
,
3890 "no match origin [<egp|igp|incomplete>]",
3896 "unknown heritage\n")
3898 return bgp_route_match_delete(vty
, "origin", NULL
,
3899 RMAP_EVENT_MATCH_DELETED
);
3902 DEFUN (set_ip_nexthop_peer
,
3903 set_ip_nexthop_peer_cmd
,
3904 "[no] set ip next-hop peer-address",
3908 "Next hop address\n"
3909 "Use peer address (for BGP only)\n")
3911 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3912 const char *) = strmatch(argv
[0]->text
, "no")
3913 ? generic_set_delete
3916 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3920 DEFUN (set_ip_nexthop_unchanged
,
3921 set_ip_nexthop_unchanged_cmd
,
3922 "[no] set ip next-hop unchanged",
3926 "Next hop address\n"
3927 "Don't modify existing Next hop address\n")
3929 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3930 const char *) = strmatch(argv
[0]->text
, "no")
3931 ? generic_set_delete
3934 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3939 DEFUN (set_local_pref
,
3941 "set local-preference (0-4294967295)",
3943 "BGP local preference path attribute\n"
3944 "Preference value\n")
3947 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3948 "local-preference", argv
[idx_number
]->arg
);
3952 DEFUN (no_set_local_pref
,
3953 no_set_local_pref_cmd
,
3954 "no set local-preference [(0-4294967295)]",
3957 "BGP local preference path attribute\n"
3958 "Preference value\n")
3960 int idx_localpref
= 3;
3961 if (argc
<= idx_localpref
)
3962 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3963 "local-preference", NULL
);
3964 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3965 "local-preference", argv
[idx_localpref
]->arg
);
3971 "set weight (0-4294967295)",
3973 "BGP weight for routing table\n"
3977 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
3978 argv
[idx_number
]->arg
);
3982 DEFUN (no_set_weight
,
3984 "no set weight [(0-4294967295)]",
3987 "BGP weight for routing table\n"
3991 if (argc
<= idx_weight
)
3992 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3994 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3995 "weight", argv
[idx_weight
]->arg
);
3998 DEFUN (set_label_index
,
3999 set_label_index_cmd
,
4000 "set label-index (0-1048560)",
4002 "Label index to associate with the prefix\n"
4003 "Label index value\n")
4006 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4007 "label-index", argv
[idx_number
]->arg
);
4010 DEFUN (no_set_label_index
,
4011 no_set_label_index_cmd
,
4012 "no set label-index [(0-1048560)]",
4015 "Label index to associate with the prefix\n"
4016 "Label index value\n")
4018 int idx_label_index
= 3;
4019 if (argc
<= idx_label_index
)
4020 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4021 "label-index", NULL
);
4022 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4023 "label-index", argv
[idx_label_index
]->arg
);
4026 DEFUN (set_aspath_prepend_asn
,
4027 set_aspath_prepend_asn_cmd
,
4028 "set as-path prepend (1-4294967295)...",
4030 "Transform BGP AS_PATH attribute\n"
4031 "Prepend to the as-path\n"
4038 str
= argv_concat(argv
, argc
, idx_asn
);
4039 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4040 "as-path prepend", str
);
4041 XFREE(MTYPE_TMP
, str
);
4046 DEFUN (set_aspath_prepend_lastas
,
4047 set_aspath_prepend_lastas_cmd
,
4048 "set as-path prepend last-as (1-10)",
4050 "Transform BGP AS_PATH attribute\n"
4051 "Prepend to the as-path\n"
4052 "Use the peer's AS-number\n"
4053 "Number of times to insert\n")
4055 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4058 DEFUN (no_set_aspath_prepend
,
4059 no_set_aspath_prepend_cmd
,
4060 "no set as-path prepend [(1-4294967295)]",
4063 "Transform BGP AS_PATH attribute\n"
4064 "Prepend to the as-path\n"
4071 str
= argv_concat(argv
, argc
, idx_asn
);
4072 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4073 "as-path prepend", str
);
4074 XFREE(MTYPE_TMP
, str
);
4079 DEFUN (set_aspath_exclude
,
4080 set_aspath_exclude_cmd
,
4081 "set as-path exclude (1-4294967295)...",
4083 "Transform BGP AS-path attribute\n"
4084 "Exclude from the as-path\n"
4091 str
= argv_concat(argv
, argc
, idx_asn
);
4092 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4093 "as-path exclude", str
);
4094 XFREE(MTYPE_TMP
, str
);
4098 DEFUN (no_set_aspath_exclude
,
4099 no_set_aspath_exclude_cmd
,
4100 "no set as-path exclude (1-4294967295)...",
4103 "Transform BGP AS_PATH attribute\n"
4104 "Exclude from the as-path\n"
4111 str
= argv_concat(argv
, argc
, idx_asn
);
4112 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4113 "as-path exclude", str
);
4114 XFREE(MTYPE_TMP
, str
);
4118 ALIAS(no_set_aspath_exclude
, no_set_aspath_exclude_all_cmd
,
4119 "no set as-path exclude",
4121 "Transform BGP AS_PATH attribute\n"
4122 "Exclude from the as-path\n")
4124 DEFUN (set_community
,
4126 "set community AA:NN...",
4128 "BGP community attribute\n"
4136 struct community
*com
= NULL
;
4141 b
= buffer_new(1024);
4143 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4144 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4151 buffer_putc(b
, ' ');
4155 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4157 buffer_putstr(b
, "internet");
4160 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4162 buffer_putstr(b
, "local-AS");
4165 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4166 && strncmp(argv
[i
]->arg
, "no-advertise",
4167 strlen(argv
[i
]->arg
))
4169 buffer_putstr(b
, "no-advertise");
4172 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4173 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4175 buffer_putstr(b
, "no-export");
4178 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4179 strlen(argv
[i
]->arg
))
4181 buffer_putstr(b
, "graceful-shutdown");
4184 buffer_putstr(b
, argv
[i
]->arg
);
4186 buffer_putc(b
, '\0');
4188 /* Fetch result string then compile it to communities attribute. */
4189 str
= buffer_getstr(b
);
4193 com
= community_str2com(str
);
4194 XFREE(MTYPE_TMP
, str
);
4197 /* Can't compile user input into communities attribute. */
4199 vty_out(vty
, "%% Malformed communities attribute\n");
4200 return CMD_WARNING_CONFIG_FAILED
;
4203 /* Set communites attribute string. */
4204 str
= community_str(com
, false);
4207 argstr
= XCALLOC(MTYPE_TMP
,
4208 strlen(str
) + strlen(" additive") + 1);
4209 strcpy(argstr
, str
);
4210 strcpy(argstr
+ strlen(str
), " additive");
4211 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4212 "community", argstr
);
4213 XFREE(MTYPE_TMP
, argstr
);
4215 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4218 community_free(&com
);
4223 DEFUN (set_community_none
,
4224 set_community_none_cmd
,
4225 "set community none",
4227 "BGP community attribute\n"
4228 "No community attribute\n")
4230 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4231 "community", "none");
4234 DEFUN (no_set_community
,
4235 no_set_community_cmd
,
4236 "no set community AA:NN...",
4239 "BGP community attribute\n"
4242 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4246 ALIAS (no_set_community
,
4247 no_set_community_short_cmd
,
4251 "BGP community attribute\n")
4254 DEFUN (set_community_delete
,
4255 set_community_delete_cmd
,
4256 "set comm-list <(1-99)|(100-500)|WORD> delete",
4258 "set BGP community list (for deletion)\n"
4259 "Community-list number (standard)\n"
4260 "Community-list number (expanded)\n"
4261 "Community-list name\n"
4262 "Delete matching communities\n")
4264 int idx_comm_list
= 2;
4267 str
= XCALLOC(MTYPE_TMP
,
4268 strlen(argv
[idx_comm_list
]->arg
) + strlen(" delete") + 1);
4269 strcpy(str
, argv
[idx_comm_list
]->arg
);
4270 strcpy(str
+ strlen(argv
[idx_comm_list
]->arg
), " delete");
4272 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4275 XFREE(MTYPE_TMP
, str
);
4279 DEFUN (no_set_community_delete
,
4280 no_set_community_delete_cmd
,
4281 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4284 "set BGP community list (for deletion)\n"
4285 "Community-list number (standard)\n"
4286 "Community-list number (expanded)\n"
4287 "Community-list name\n"
4288 "Delete matching communities\n")
4290 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4294 DEFUN (set_lcommunity
,
4296 "set large-community AA:BB:CC...",
4298 "BGP large community attribute\n"
4299 "Large Community number in aa:bb:cc format or additive\n")
4304 str
= argv_concat(argv
, argc
, 2);
4305 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4306 "large-community", str
);
4307 XFREE(MTYPE_TMP
, str
);
4312 DEFUN (set_lcommunity_none
,
4313 set_lcommunity_none_cmd
,
4314 "set large-community none",
4316 "BGP large community attribute\n"
4317 "No large community attribute\n")
4319 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4320 "large-community", "none");
4323 DEFUN (no_set_lcommunity
,
4324 no_set_lcommunity_cmd
,
4325 "no set large-community none",
4328 "BGP large community attribute\n"
4329 "No community attribute\n")
4331 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4332 "large-community", NULL
);
4335 DEFUN (no_set_lcommunity1
,
4336 no_set_lcommunity1_cmd
,
4337 "no set large-community AA:BB:CC...",
4340 "BGP large community attribute\n"
4341 "Large community in AA:BB:CC... format or additive\n")
4343 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4344 "large-community", NULL
);
4347 ALIAS (no_set_lcommunity1
,
4348 no_set_lcommunity1_short_cmd
,
4349 "no set large-community",
4352 "BGP large community attribute\n")
4354 DEFUN (set_lcommunity_delete
,
4355 set_lcommunity_delete_cmd
,
4356 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4358 "set BGP large community list (for deletion)\n"
4359 "Large Community-list number (standard)\n"
4360 "Large Communitly-list number (expanded)\n"
4361 "Large Community-list name\n"
4362 "Delete matching large communities\n")
4366 str
= XCALLOC(MTYPE_TMP
, strlen(argv
[2]->arg
) + strlen(" delete") + 1);
4367 strcpy(str
, argv
[2]->arg
);
4368 strcpy(str
+ strlen(argv
[2]->arg
), " delete");
4370 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4371 "large-comm-list", str
);
4373 XFREE(MTYPE_TMP
, str
);
4377 DEFUN (no_set_lcommunity_delete
,
4378 no_set_lcommunity_delete_cmd
,
4379 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4382 "set BGP large community list (for deletion)\n"
4383 "Large Community-list number (standard)\n"
4384 "Large Communitly-list number (expanded)\n"
4385 "Large Community-list name\n"
4386 "Delete matching large communities\n")
4388 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4389 "large-comm-list", NULL
);
4392 ALIAS (no_set_lcommunity_delete
,
4393 no_set_lcommunity_delete_short_cmd
,
4394 "no set large-comm-list",
4397 "set BGP large community list (for deletion)\n")
4399 DEFUN (set_ecommunity_rt
,
4400 set_ecommunity_rt_cmd
,
4401 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4403 "BGP extended community attribute\n"
4404 "Route Target extended community\n"
4405 "VPN extended community\n")
4411 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4412 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4413 "extcommunity rt", str
);
4414 XFREE(MTYPE_TMP
, str
);
4419 DEFUN (no_set_ecommunity_rt
,
4420 no_set_ecommunity_rt_cmd
,
4421 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4424 "BGP extended community attribute\n"
4425 "Route Target extended community\n"
4426 "VPN extended community\n")
4428 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4429 "extcommunity rt", NULL
);
4432 ALIAS (no_set_ecommunity_rt
,
4433 no_set_ecommunity_rt_short_cmd
,
4434 "no set extcommunity rt",
4437 "BGP extended community attribute\n"
4438 "Route Target extended community\n")
4440 DEFUN (set_ecommunity_soo
,
4441 set_ecommunity_soo_cmd
,
4442 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4444 "BGP extended community attribute\n"
4445 "Site-of-Origin extended community\n"
4446 "VPN extended community\n")
4452 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4453 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4454 "extcommunity soo", str
);
4455 XFREE(MTYPE_TMP
, str
);
4460 DEFUN (no_set_ecommunity_soo
,
4461 no_set_ecommunity_soo_cmd
,
4462 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4465 "BGP extended community attribute\n"
4466 "Site-of-Origin extended community\n"
4467 "VPN extended community\n")
4469 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4470 "extcommunity soo", NULL
);
4473 ALIAS (no_set_ecommunity_soo
,
4474 no_set_ecommunity_soo_short_cmd
,
4475 "no set extcommunity soo",
4478 "GP extended community attribute\n"
4479 "Site-of-Origin extended community\n")
4483 "set origin <egp|igp|incomplete>",
4488 "unknown heritage\n")
4491 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4492 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4494 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4495 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4497 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4498 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4499 "origin", "incomplete");
4501 vty_out(vty
, "%% Invalid set origin type\n");
4502 return CMD_WARNING_CONFIG_FAILED
;
4506 DEFUN (no_set_origin
,
4508 "no set origin [<egp|igp|incomplete>]",
4514 "unknown heritage\n")
4516 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4521 DEFUN (set_atomic_aggregate
,
4522 set_atomic_aggregate_cmd
,
4523 "set atomic-aggregate",
4525 "BGP atomic aggregate attribute\n" )
4527 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4528 "atomic-aggregate", NULL
);
4531 DEFUN (no_set_atomic_aggregate
,
4532 no_set_atomic_aggregate_cmd
,
4533 "no set atomic-aggregate",
4536 "BGP atomic aggregate attribute\n" )
4538 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4539 "atomic-aggregate", NULL
);
4542 DEFUN (set_aggregator_as
,
4543 set_aggregator_as_cmd
,
4544 "set aggregator as (1-4294967295) A.B.C.D",
4546 "BGP aggregator attribute\n"
4547 "AS number of aggregator\n"
4549 "IP address of aggregator\n")
4554 struct in_addr address
;
4557 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4559 vty_out(vty
, "Aggregator IP address is invalid\n");
4560 return CMD_WARNING_CONFIG_FAILED
;
4563 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4564 strlen(argv
[idx_number
]->arg
)
4565 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4567 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4569 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4570 "aggregator as", argstr
);
4572 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4578 DEFUN (no_set_aggregator_as
,
4579 no_set_aggregator_as_cmd
,
4580 "no set aggregator as [(1-4294967295) A.B.C.D]",
4583 "BGP aggregator attribute\n"
4584 "AS number of aggregator\n"
4586 "IP address of aggregator\n")
4591 struct in_addr address
;
4594 if (argc
<= idx_asn
)
4595 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4596 "aggregator as", NULL
);
4598 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4600 vty_out(vty
, "Aggregator IP address is invalid\n");
4601 return CMD_WARNING_CONFIG_FAILED
;
4604 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4605 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4608 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4610 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4611 "aggregator as", argstr
);
4613 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4618 DEFUN (match_ipv6_next_hop
,
4619 match_ipv6_next_hop_cmd
,
4620 "match ipv6 next-hop X:X::X:X",
4623 "Match IPv6 next-hop address of route\n"
4624 "IPv6 address of next hop\n")
4627 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4628 RMAP_EVENT_MATCH_ADDED
);
4631 DEFUN (no_match_ipv6_next_hop
,
4632 no_match_ipv6_next_hop_cmd
,
4633 "no match ipv6 next-hop X:X::X:X",
4637 "Match IPv6 next-hop address of route\n"
4638 "IPv6 address of next hop\n")
4641 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4642 RMAP_EVENT_MATCH_DELETED
);
4646 DEFUN (set_ipv6_nexthop_peer
,
4647 set_ipv6_nexthop_peer_cmd
,
4648 "set ipv6 next-hop peer-address",
4651 "Next hop address\n"
4652 "Use peer address (for BGP only)\n")
4654 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4655 "ipv6 next-hop peer-address", NULL
);
4658 DEFUN (no_set_ipv6_nexthop_peer
,
4659 no_set_ipv6_nexthop_peer_cmd
,
4660 "no set ipv6 next-hop peer-address",
4664 "IPv6 next-hop address\n"
4665 "Use peer address (for BGP only)\n")
4667 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4668 "ipv6 next-hop peer-address", NULL
);
4671 DEFUN (set_ipv6_nexthop_prefer_global
,
4672 set_ipv6_nexthop_prefer_global_cmd
,
4673 "set ipv6 next-hop prefer-global",
4676 "IPv6 next-hop address\n"
4677 "Prefer global over link-local if both exist\n")
4679 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4680 "ipv6 next-hop prefer-global", NULL
);
4684 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4685 no_set_ipv6_nexthop_prefer_global_cmd
,
4686 "no set ipv6 next-hop prefer-global",
4690 "IPv6 next-hop address\n"
4691 "Prefer global over link-local if both exist\n")
4693 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4694 "ipv6 next-hop prefer-global", NULL
);
4697 DEFUN (set_ipv6_nexthop_global
,
4698 set_ipv6_nexthop_global_cmd
,
4699 "set ipv6 next-hop global X:X::X:X",
4702 "IPv6 next-hop address\n"
4703 "IPv6 global address\n"
4704 "IPv6 address of next hop\n")
4707 struct in6_addr addr
;
4710 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4712 vty_out(vty
, "%% Malformed nexthop address\n");
4713 return CMD_WARNING_CONFIG_FAILED
;
4715 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4716 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4717 vty_out(vty
, "%% Invalid global nexthop address\n");
4718 return CMD_WARNING_CONFIG_FAILED
;
4721 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4722 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4726 DEFUN (no_set_ipv6_nexthop_global
,
4727 no_set_ipv6_nexthop_global_cmd
,
4728 "no set ipv6 next-hop global X:X::X:X",
4732 "IPv6 next-hop address\n"
4733 "IPv6 global address\n"
4734 "IPv6 address of next hop\n")
4737 if (argc
<= idx_ipv6
)
4738 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4739 "ipv6 next-hop global", NULL
);
4740 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4741 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4744 #ifdef KEEP_OLD_VPN_COMMANDS
4745 DEFUN (set_vpn_nexthop
,
4746 set_vpn_nexthop_cmd
,
4747 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4749 "VPNv4 information\n"
4750 "VPN next-hop address\n"
4751 "IP address of next hop\n"
4752 "VPNv6 information\n"
4753 "VPN next-hop address\n"
4754 "IPv6 address of next hop\n")
4760 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4762 return generic_set_add(
4763 vty
, VTY_GET_CONTEXT(route_map_index
),
4764 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4766 return generic_set_add(
4767 vty
, VTY_GET_CONTEXT(route_map_index
),
4768 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4773 DEFUN (no_set_vpn_nexthop
,
4774 no_set_vpn_nexthop_cmd
,
4775 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4778 "VPNv4 information\n"
4779 "VPN next-hop address\n"
4780 "IP address of next hop\n"
4781 "VPNv6 information\n"
4782 "VPN next-hop address\n"
4783 "IPv6 address of next hop\n")
4793 arg
= argv
[idx_ip
]->arg
;
4794 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4796 return generic_set_delete(
4797 vty
, VTY_GET_CONTEXT(route_map_index
),
4798 "ipv4 vpn next-hop", arg
);
4800 return generic_set_delete(
4801 vty
, VTY_GET_CONTEXT(route_map_index
),
4802 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4806 #endif /* KEEP_OLD_VPN_COMMANDS */
4808 DEFUN (set_ipx_vpn_nexthop
,
4809 set_ipx_vpn_nexthop_cmd
,
4810 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4812 "IPv4 information\n"
4813 "IPv6 information\n"
4815 "VPN next-hop address\n"
4816 "IP address of next hop\n"
4817 "IPv6 address of next hop\n")
4823 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4825 return generic_set_add(
4826 vty
, VTY_GET_CONTEXT(route_map_index
),
4827 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4829 return generic_set_add(
4830 vty
, VTY_GET_CONTEXT(route_map_index
),
4831 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4836 DEFUN (no_set_ipx_vpn_nexthop
,
4837 no_set_ipx_vpn_nexthop_cmd
,
4838 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4841 "IPv4 information\n"
4842 "IPv6 information\n"
4844 "VPN next-hop address\n"
4845 "IP address of next hop\n"
4846 "IPv6 address of next hop\n")
4856 arg
= argv
[idx_ip
]->arg
;
4857 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4859 return generic_set_delete(
4860 vty
, VTY_GET_CONTEXT(route_map_index
),
4861 "ipv4 vpn next-hop", arg
);
4863 return generic_set_delete(
4864 vty
, VTY_GET_CONTEXT(route_map_index
),
4865 "ipv6 vpn next-hop", arg
);
4870 DEFUN (set_originator_id
,
4871 set_originator_id_cmd
,
4872 "set originator-id A.B.C.D",
4874 "BGP originator ID attribute\n"
4875 "IP address of originator\n")
4878 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4879 "originator-id", argv
[idx_ipv4
]->arg
);
4883 DEFUN (no_set_originator_id
,
4884 no_set_originator_id_cmd
,
4885 "no set originator-id [A.B.C.D]",
4888 "BGP originator ID attribute\n"
4889 "IP address of originator\n")
4893 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4895 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4896 "originator-id", arg
);
4900 /* Initialization of route map. */
4901 void bgp_route_map_init(void)
4905 route_map_add_hook(bgp_route_map_add
);
4906 route_map_delete_hook(bgp_route_map_delete
);
4907 route_map_event_hook(bgp_route_map_event
);
4909 route_map_match_interface_hook(generic_match_add
);
4910 route_map_no_match_interface_hook(generic_match_delete
);
4912 route_map_match_ip_address_hook(generic_match_add
);
4913 route_map_no_match_ip_address_hook(generic_match_delete
);
4915 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
4916 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
4918 route_map_match_ip_next_hop_hook(generic_match_add
);
4919 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
4921 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
4922 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
4924 route_map_match_ip_next_hop_type_hook(generic_match_add
);
4925 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
4927 route_map_match_ipv6_address_hook(generic_match_add
);
4928 route_map_no_match_ipv6_address_hook(generic_match_delete
);
4930 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
4931 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
4933 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
4934 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
4936 route_map_match_metric_hook(generic_match_add
);
4937 route_map_no_match_metric_hook(generic_match_delete
);
4939 route_map_match_tag_hook(generic_match_add
);
4940 route_map_no_match_tag_hook(generic_match_delete
);
4942 route_map_set_ip_nexthop_hook(generic_set_add
);
4943 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
4945 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
4946 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
4948 route_map_set_metric_hook(generic_set_add
);
4949 route_map_no_set_metric_hook(generic_set_delete
);
4951 route_map_set_tag_hook(generic_set_add
);
4952 route_map_no_set_tag_hook(generic_set_delete
);
4954 route_map_install_match(&route_match_peer_cmd
);
4955 route_map_install_match(&route_match_local_pref_cmd
);
4956 #if defined(HAVE_LUA)
4957 route_map_install_match(&route_match_command_cmd
);
4959 route_map_install_match(&route_match_ip_address_cmd
);
4960 route_map_install_match(&route_match_ip_next_hop_cmd
);
4961 route_map_install_match(&route_match_ip_route_source_cmd
);
4962 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
4963 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
4964 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
4965 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
4966 route_map_install_match(&route_match_aspath_cmd
);
4967 route_map_install_match(&route_match_community_cmd
);
4968 route_map_install_match(&route_match_lcommunity_cmd
);
4969 route_map_install_match(&route_match_ecommunity_cmd
);
4970 route_map_install_match(&route_match_local_pref_cmd
);
4971 route_map_install_match(&route_match_metric_cmd
);
4972 route_map_install_match(&route_match_origin_cmd
);
4973 route_map_install_match(&route_match_probability_cmd
);
4974 route_map_install_match(&route_match_interface_cmd
);
4975 route_map_install_match(&route_match_tag_cmd
);
4976 route_map_install_match(&route_match_mac_address_cmd
);
4977 route_map_install_match(&route_match_evpn_vni_cmd
);
4978 route_map_install_match(&route_match_evpn_route_type_cmd
);
4979 route_map_install_match(&route_match_evpn_default_route_cmd
);
4981 route_map_install_set(&route_set_ip_nexthop_cmd
);
4982 route_map_install_set(&route_set_local_pref_cmd
);
4983 route_map_install_set(&route_set_weight_cmd
);
4984 route_map_install_set(&route_set_label_index_cmd
);
4985 route_map_install_set(&route_set_metric_cmd
);
4986 route_map_install_set(&route_set_aspath_prepend_cmd
);
4987 route_map_install_set(&route_set_aspath_exclude_cmd
);
4988 route_map_install_set(&route_set_origin_cmd
);
4989 route_map_install_set(&route_set_atomic_aggregate_cmd
);
4990 route_map_install_set(&route_set_aggregator_as_cmd
);
4991 route_map_install_set(&route_set_community_cmd
);
4992 route_map_install_set(&route_set_community_delete_cmd
);
4993 route_map_install_set(&route_set_lcommunity_cmd
);
4994 route_map_install_set(&route_set_lcommunity_delete_cmd
);
4995 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
4996 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
4997 route_map_install_set(&route_set_originator_id_cmd
);
4998 route_map_install_set(&route_set_ecommunity_rt_cmd
);
4999 route_map_install_set(&route_set_ecommunity_soo_cmd
);
5000 route_map_install_set(&route_set_tag_cmd
);
5001 route_map_install_set(&route_set_label_index_cmd
);
5003 install_element(RMAP_NODE
, &match_peer_cmd
);
5004 install_element(RMAP_NODE
, &match_peer_local_cmd
);
5005 install_element(RMAP_NODE
, &no_match_peer_cmd
);
5006 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
5007 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
5008 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
5009 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
5010 install_element(RMAP_NODE
, &match_mac_address_cmd
);
5011 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
5012 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
5013 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
5014 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
5015 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
5016 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
5017 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
5019 install_element(RMAP_NODE
, &match_aspath_cmd
);
5020 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
5021 install_element(RMAP_NODE
, &match_local_pref_cmd
);
5022 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
5023 install_element(RMAP_NODE
, &match_community_cmd
);
5024 install_element(RMAP_NODE
, &no_match_community_cmd
);
5025 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
5026 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
5027 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
5028 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
5029 install_element(RMAP_NODE
, &match_origin_cmd
);
5030 install_element(RMAP_NODE
, &no_match_origin_cmd
);
5031 install_element(RMAP_NODE
, &match_probability_cmd
);
5032 install_element(RMAP_NODE
, &no_match_probability_cmd
);
5034 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
5035 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
5036 install_element(RMAP_NODE
, &set_local_pref_cmd
);
5037 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
5038 install_element(RMAP_NODE
, &set_weight_cmd
);
5039 install_element(RMAP_NODE
, &set_label_index_cmd
);
5040 install_element(RMAP_NODE
, &no_set_weight_cmd
);
5041 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
5042 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
5043 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
5044 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
5045 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
5046 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
5047 install_element(RMAP_NODE
, &no_set_aspath_exclude_all_cmd
);
5048 install_element(RMAP_NODE
, &set_origin_cmd
);
5049 install_element(RMAP_NODE
, &no_set_origin_cmd
);
5050 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
5051 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
5052 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
5053 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
5054 install_element(RMAP_NODE
, &set_community_cmd
);
5055 install_element(RMAP_NODE
, &set_community_none_cmd
);
5056 install_element(RMAP_NODE
, &no_set_community_cmd
);
5057 install_element(RMAP_NODE
, &no_set_community_short_cmd
);
5058 install_element(RMAP_NODE
, &set_community_delete_cmd
);
5059 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
5060 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
5061 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
5062 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
5063 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
5064 install_element(RMAP_NODE
, &no_set_lcommunity1_short_cmd
);
5065 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
5066 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
5067 install_element(RMAP_NODE
, &no_set_lcommunity_delete_short_cmd
);
5068 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
5069 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
5070 install_element(RMAP_NODE
, &no_set_ecommunity_rt_short_cmd
);
5071 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
5072 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
5073 install_element(RMAP_NODE
, &no_set_ecommunity_soo_short_cmd
);
5074 #ifdef KEEP_OLD_VPN_COMMANDS
5075 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5076 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5077 #endif /* KEEP_OLD_VPN_COMMANDS */
5078 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5079 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5080 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5081 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5083 route_map_install_match(&route_match_ipv6_address_cmd
);
5084 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5085 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5086 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5087 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5088 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5089 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5090 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5092 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5093 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5094 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5095 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5096 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5097 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5098 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5099 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5100 #if defined(HAVE_LUA)
5101 install_element(RMAP_NODE
, &match_command_cmd
);
5102 install_element(RMAP_NODE
, &no_match_command_cmd
);
5106 void bgp_route_map_terminate(void)
5108 /* ToDo: Cleanup all the used memory */