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_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_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_info
*info
= (struct bgp_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_info information
360 lua_pushinteger(L
, info
->attr
->med
);
361 lua_setfield(L
, -2, "metric");
362 lua_pushinteger(L
, info
->attr
->nh_ifindex
);
363 lua_setfield(L
, -2, "ifindex");
364 lua_pushstring(L
, info
->attr
->aspath
->str
);
365 lua_setfield(L
, -2, "aspath");
366 lua_pushinteger(L
, info
->attr
->local_pref
);
367 lua_setfield(L
, -2, "localpref");
368 zlog_debug("%s %d", info
->attr
->aspath
->str
, info
->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 info
->attr
->med
= get_integer(L
, "metric");
388 * This needs to be abstraced with the set function
390 if (info
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
391 locpref
= info
->attr
->local_pref
;
392 newlocpref
= get_integer(L
, "localpref");
393 if (newlocpref
!= locpref
) {
394 info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
395 info
->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_info
*bgp_info
;
481 struct prefix_ipv4 p
;
483 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
486 p
.prefix
= bgp_info
->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_info
*bgp_info
;
529 struct prefix_ipv4 p
;
531 if (type
== RMAP_BGP
&& pfx
->family
== AF_INET
) {
533 peer
= bgp_info
->peer
;
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_info
*bgp_info
;
614 struct prefix_ipv4 p
;
616 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
619 p
.prefix
= bgp_info
->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_info
*bgp_info
;
656 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
657 bgp_info
= (struct bgp_info
*)object
;
658 if (!bgp_info
|| !bgp_info
->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 (bgp_info
->attr
->nexthop
.s_addr
== INADDR_ANY
666 && !bgp_info
->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_info
*bgp_info
;
697 struct prefix_ipv4 p
;
699 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET
) {
701 peer
= bgp_info
->peer
;
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_info
*bgp_info
= NULL
;
815 if (type
== RMAP_BGP
) {
816 vni
= *((vni_t
*)rule
);
817 bgp_info
= (struct bgp_info
*)object
;
819 if (bgp_info
->extra
== NULL
)
822 if (vni
== label2vni(&bgp_info
->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_info
*bgp_info
;
919 if (type
== RMAP_BGP
) {
923 if (bgp_info
->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_info
*bgp_info
;
979 if (type
== RMAP_BGP
) {
982 return route_value_match(rv
, bgp_info
->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_info
*bgp_info
;
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
, bgp_info
->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
{
1043 /* Match function for community match. */
1044 static route_map_result_t
route_match_community(void *rule
,
1045 const struct prefix
*prefix
,
1046 route_map_object_t type
,
1049 struct community_list
*list
;
1050 struct bgp_info
*bgp_info
;
1051 struct rmap_community
*rcom
;
1053 if (type
== RMAP_BGP
) {
1057 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1058 COMMUNITY_LIST_MASTER
);
1060 return RMAP_NOMATCH
;
1063 if (community_list_exact_match(
1064 bgp_info
->attr
->community
, list
))
1067 if (community_list_match(bgp_info
->attr
->community
,
1072 return RMAP_NOMATCH
;
1075 /* Compile function for community match. */
1076 static void *route_match_community_compile(const char *arg
)
1078 struct rmap_community
*rcom
;
1082 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1084 p
= strchr(arg
, ' ');
1087 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1088 memcpy(rcom
->name
, arg
, len
);
1091 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1097 /* Compile function for community match. */
1098 static void route_match_community_free(void *rule
)
1100 struct rmap_community
*rcom
= rule
;
1102 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1103 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1106 /* Route map commands for community matching. */
1107 struct route_map_rule_cmd route_match_community_cmd
= {
1108 "community", route_match_community
, route_match_community_compile
,
1109 route_match_community_free
};
1111 /* Match function for lcommunity match. */
1112 static route_map_result_t
route_match_lcommunity(void *rule
,
1113 const struct prefix
*prefix
,
1114 route_map_object_t type
,
1117 struct community_list
*list
;
1118 struct bgp_info
*bgp_info
;
1119 struct rmap_community
*rcom
;
1121 if (type
== RMAP_BGP
) {
1125 list
= community_list_lookup(bgp_clist
, rcom
->name
,
1126 LARGE_COMMUNITY_LIST_MASTER
);
1128 return RMAP_NOMATCH
;
1130 if (lcommunity_list_match(bgp_info
->attr
->lcommunity
, list
))
1133 return RMAP_NOMATCH
;
1136 /* Compile function for community match. */
1137 static void *route_match_lcommunity_compile(const char *arg
)
1139 struct rmap_community
*rcom
;
1143 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
1145 p
= strchr(arg
, ' ');
1148 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1149 memcpy(rcom
->name
, arg
, len
);
1151 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1157 /* Compile function for community match. */
1158 static void route_match_lcommunity_free(void *rule
)
1160 struct rmap_community
*rcom
= rule
;
1162 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
1163 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
1166 /* Route map commands for community matching. */
1167 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
1168 "large-community", route_match_lcommunity
,
1169 route_match_lcommunity_compile
, route_match_lcommunity_free
};
1172 /* Match function for extcommunity match. */
1173 static route_map_result_t
route_match_ecommunity(void *rule
,
1174 const struct prefix
*prefix
,
1175 route_map_object_t type
,
1178 struct community_list
*list
;
1179 struct bgp_info
*bgp_info
;
1181 if (type
== RMAP_BGP
) {
1184 list
= community_list_lookup(bgp_clist
, (char *)rule
,
1185 EXTCOMMUNITY_LIST_MASTER
);
1187 return RMAP_NOMATCH
;
1189 if (ecommunity_list_match(bgp_info
->attr
->ecommunity
, list
))
1192 return RMAP_NOMATCH
;
1195 /* Compile function for extcommunity match. */
1196 static void *route_match_ecommunity_compile(const char *arg
)
1198 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1201 /* Compile function for extcommunity match. */
1202 static void route_match_ecommunity_free(void *rule
)
1204 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1207 /* Route map commands for community matching. */
1208 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
1209 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
1210 route_match_ecommunity_free
};
1212 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1213 and `address-family vpnv4'. */
1215 /* `match origin' */
1216 static route_map_result_t
route_match_origin(void *rule
,
1217 const struct prefix
*prefix
,
1218 route_map_object_t type
,
1222 struct bgp_info
*bgp_info
;
1224 if (type
== RMAP_BGP
) {
1228 if (bgp_info
->attr
->origin
== *origin
)
1232 return RMAP_NOMATCH
;
1235 static void *route_match_origin_compile(const char *arg
)
1239 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
1241 if (strcmp(arg
, "igp") == 0)
1243 else if (strcmp(arg
, "egp") == 0)
1251 /* Free route map's compiled `ip address' value. */
1252 static void route_match_origin_free(void *rule
)
1254 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1257 /* Route map commands for origin matching. */
1258 struct route_map_rule_cmd route_match_origin_cmd
= {
1259 "origin", route_match_origin
, route_match_origin_compile
,
1260 route_match_origin_free
};
1262 /* match probability { */
1264 static route_map_result_t
route_match_probability(void *rule
,
1265 const struct prefix
*prefix
,
1266 route_map_object_t type
,
1271 switch (*(long *)rule
) {
1277 if (r
< *(long *)rule
) {
1282 return RMAP_NOMATCH
;
1285 static void *route_match_probability_compile(const char *arg
)
1291 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1301 *lobule
= RAND_MAX
/ 100 * perc
;
1307 static void route_match_probability_free(void *rule
)
1309 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1312 struct route_map_rule_cmd route_match_probability_cmd
= {
1313 "probability", route_match_probability
, route_match_probability_compile
,
1314 route_match_probability_free
};
1316 /* `match interface IFNAME' */
1317 /* Match function should return 1 if match is success else return
1319 static route_map_result_t
route_match_interface(void *rule
,
1320 const struct prefix
*prefix
,
1321 route_map_object_t type
,
1324 struct interface
*ifp
;
1325 struct bgp_info
*info
;
1327 if (type
== RMAP_BGP
) {
1330 if (!info
|| !info
->attr
)
1331 return RMAP_NOMATCH
;
1333 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1335 if (ifp
== NULL
|| ifp
->ifindex
!= info
->attr
->nh_ifindex
)
1336 return RMAP_NOMATCH
;
1340 return RMAP_NOMATCH
;
1343 /* Route map `interface' match statement. `arg' should be
1345 static void *route_match_interface_compile(const char *arg
)
1347 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1350 /* Free route map's compiled `interface' value. */
1351 static void route_match_interface_free(void *rule
)
1353 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1356 /* Route map commands for ip address matching. */
1357 struct route_map_rule_cmd route_match_interface_cmd
= {
1358 "interface", route_match_interface
, route_match_interface_compile
,
1359 route_match_interface_free
};
1363 /* `set ip next-hop IP_ADDRESS' */
1365 /* Match function return 1 if match is success else return zero. */
1366 static route_map_result_t
route_match_tag(void *rule
,
1367 const struct prefix
*prefix
,
1368 route_map_object_t type
, void *object
)
1371 struct bgp_info
*bgp_info
;
1373 if (type
== RMAP_BGP
) {
1377 return ((bgp_info
->attr
->tag
== *tag
) ? RMAP_MATCH
1381 return RMAP_NOMATCH
;
1385 /* Route map commands for tag matching. */
1386 static struct route_map_rule_cmd route_match_tag_cmd
= {
1387 "tag", route_match_tag
, route_map_rule_tag_compile
,
1388 route_map_rule_tag_free
,
1392 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1393 struct rmap_ip_nexthop_set
{
1394 struct in_addr
*address
;
1399 static route_map_result_t
route_set_ip_nexthop(void *rule
,
1400 const struct prefix
*prefix
,
1401 route_map_object_t type
,
1404 struct rmap_ip_nexthop_set
*rins
= rule
;
1405 struct bgp_info
*bgp_info
;
1408 if (type
== RMAP_BGP
) {
1410 peer
= bgp_info
->peer
;
1412 if (rins
->unchanged
) {
1413 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1414 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1415 } else if (rins
->peer_address
) {
1416 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1417 || CHECK_FLAG(peer
->rmap_type
,
1418 PEER_RMAP_TYPE_IMPORT
))
1420 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1421 bgp_info
->attr
->nexthop
.s_addr
=
1422 sockunion2ip(peer
->su_remote
);
1423 bgp_info
->attr
->flag
|=
1424 ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1425 } else if (CHECK_FLAG(peer
->rmap_type
,
1426 PEER_RMAP_TYPE_OUT
)) {
1427 /* The next hop value will be set as part of
1429 * Set the flags here to indicate that rewrite
1431 * Also, clear the value.
1433 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1434 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1435 bgp_info
->attr
->nexthop
.s_addr
= 0;
1438 /* Set next hop value. */
1439 bgp_info
->attr
->flag
|=
1440 ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1441 bgp_info
->attr
->nexthop
= *rins
->address
;
1442 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1443 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1444 /* case for MP-BGP : MPLS VPN */
1445 bgp_info
->attr
->mp_nexthop_global_in
= *rins
->address
;
1446 bgp_info
->attr
->mp_nexthop_len
= sizeof(*rins
->address
);
1453 /* Route map `ip nexthop' compile function. Given string is converted
1454 to struct in_addr structure. */
1455 static void *route_set_ip_nexthop_compile(const char *arg
)
1457 struct rmap_ip_nexthop_set
*rins
;
1458 struct in_addr
*address
= NULL
;
1459 int peer_address
= 0;
1463 if (strcmp(arg
, "peer-address") == 0)
1465 else if (strcmp(arg
, "unchanged") == 0)
1468 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1469 sizeof(struct in_addr
));
1470 ret
= inet_aton(arg
, address
);
1473 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1478 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1479 sizeof(struct rmap_ip_nexthop_set
));
1481 rins
->address
= address
;
1482 rins
->peer_address
= peer_address
;
1483 rins
->unchanged
= unchanged
;
1488 /* Free route map's compiled `ip nexthop' value. */
1489 static void route_set_ip_nexthop_free(void *rule
)
1491 struct rmap_ip_nexthop_set
*rins
= rule
;
1494 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1496 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1499 /* Route map commands for ip nexthop set. */
1500 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1501 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1502 route_set_ip_nexthop_free
};
1504 /* `set local-preference LOCAL_PREF' */
1506 /* Set local preference. */
1507 static route_map_result_t
route_set_local_pref(void *rule
,
1508 const struct prefix
*prefix
,
1509 route_map_object_t type
,
1512 struct rmap_value
*rv
;
1513 struct bgp_info
*bgp_info
;
1514 uint32_t locpref
= 0;
1516 if (type
== RMAP_BGP
) {
1517 /* Fetch routemap's rule information. */
1521 /* Set local preference value. */
1522 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1523 locpref
= bgp_info
->attr
->local_pref
;
1525 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1526 bgp_info
->attr
->local_pref
=
1527 route_value_adjust(rv
, locpref
, bgp_info
->peer
);
1533 /* Set local preference rule structure. */
1534 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1535 "local-preference", route_set_local_pref
, route_value_compile
,
1539 /* `set weight WEIGHT' */
1542 static route_map_result_t
route_set_weight(void *rule
,
1543 const struct prefix
*prefix
,
1544 route_map_object_t type
,
1547 struct rmap_value
*rv
;
1548 struct bgp_info
*bgp_info
;
1550 if (type
== RMAP_BGP
) {
1551 /* Fetch routemap's rule information. */
1555 /* Set weight value. */
1556 bgp_info
->attr
->weight
=
1557 route_value_adjust(rv
, 0, bgp_info
->peer
);
1563 /* Set local preference rule structure. */
1564 struct route_map_rule_cmd route_set_weight_cmd
= {
1565 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1568 /* `set metric METRIC' */
1570 /* Set metric to attribute. */
1571 static route_map_result_t
route_set_metric(void *rule
,
1572 const struct prefix
*prefix
,
1573 route_map_object_t type
,
1576 struct rmap_value
*rv
;
1577 struct bgp_info
*bgp_info
;
1580 if (type
== RMAP_BGP
) {
1581 /* Fetch routemap's rule information. */
1585 if (bgp_info
->attr
->flag
1586 & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1587 med
= bgp_info
->attr
->med
;
1589 bgp_info
->attr
->med
=
1590 route_value_adjust(rv
, med
, bgp_info
->peer
);
1591 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1596 /* Set metric rule structure. */
1597 struct route_map_rule_cmd route_set_metric_cmd
= {
1598 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1601 /* `set as-path prepend ASPATH' */
1603 /* For AS path prepend mechanism. */
1604 static route_map_result_t
route_set_aspath_prepend(void *rule
,
1605 const struct prefix
*prefix
,
1606 route_map_object_t type
,
1609 struct aspath
*aspath
;
1611 struct bgp_info
*binfo
;
1613 if (type
== RMAP_BGP
) {
1616 if (binfo
->attr
->aspath
->refcnt
)
1617 new = aspath_dup(binfo
->attr
->aspath
);
1619 new = binfo
->attr
->aspath
;
1621 if ((uintptr_t)rule
> 10) {
1623 aspath_prepend(aspath
, new);
1625 as_t as
= aspath_leftmost(new);
1627 as
= binfo
->peer
->as
;
1628 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1631 binfo
->attr
->aspath
= new;
1637 static void *route_set_aspath_prepend_compile(const char *arg
)
1641 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1642 return (void *)(uintptr_t)num
;
1644 return route_aspath_compile(arg
);
1647 static void route_set_aspath_prepend_free(void *rule
)
1649 if ((uintptr_t)rule
> 10)
1650 route_aspath_free(rule
);
1654 /* Set as-path prepend rule structure. */
1655 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1656 "as-path prepend", route_set_aspath_prepend
,
1657 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1660 /* `set as-path exclude ASn' */
1662 /* For ASN exclude mechanism.
1663 * Iterate over ASns requested and filter them from the given AS_PATH one by
1665 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1667 static route_map_result_t
route_set_aspath_exclude(void *rule
,
1668 const struct prefix
*dummy
,
1669 route_map_object_t type
,
1672 struct aspath
*new_path
, *exclude_path
;
1673 struct bgp_info
*binfo
;
1675 if (type
== RMAP_BGP
) {
1676 exclude_path
= rule
;
1678 if (binfo
->attr
->aspath
->refcnt
)
1679 new_path
= aspath_dup(binfo
->attr
->aspath
);
1681 new_path
= binfo
->attr
->aspath
;
1682 binfo
->attr
->aspath
=
1683 aspath_filter_exclude(new_path
, exclude_path
);
1688 /* Set ASn exlude rule structure. */
1689 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1690 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1694 /* `set community COMMUNITY' */
1695 struct rmap_com_set
{
1696 struct community
*com
;
1701 /* For community set mechanism. */
1702 static route_map_result_t
route_set_community(void *rule
,
1703 const struct prefix
*prefix
,
1704 route_map_object_t type
,
1707 struct rmap_com_set
*rcs
;
1708 struct bgp_info
*binfo
;
1710 struct community
*new = NULL
;
1711 struct community
*old
;
1712 struct community
*merge
;
1714 if (type
== RMAP_BGP
) {
1718 old
= attr
->community
;
1722 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1723 attr
->community
= NULL
;
1724 /* See the longer comment down below. */
1725 if (old
&& old
->refcnt
== 0)
1726 community_free(old
);
1730 /* "additive" case. */
1731 if (rcs
->additive
&& old
) {
1732 merge
= community_merge(community_dup(old
), rcs
->com
);
1734 new = community_uniq_sort(merge
);
1735 community_free(merge
);
1737 new = community_dup(rcs
->com
);
1739 /* HACK: if the old community is not intern'd,
1740 * we should free it here, or all reference to it may be
1742 * Really need to cleanup attribute caching sometime.
1744 if (old
&& old
->refcnt
== 0)
1745 community_free(old
);
1747 /* will be interned by caller if required */
1748 attr
->community
= new;
1750 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1756 /* Compile function for set community. */
1757 static void *route_set_community_compile(const char *arg
)
1759 struct rmap_com_set
*rcs
;
1760 struct community
*com
= NULL
;
1765 if (strcmp(arg
, "none") == 0)
1768 sp
= strstr(arg
, "additive");
1770 if (sp
&& sp
> arg
) {
1771 /* "additive" keyword is included. */
1776 com
= community_str2com(arg
);
1785 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1787 rcs
->additive
= additive
;
1793 /* Free function for set community. */
1794 static void route_set_community_free(void *rule
)
1796 struct rmap_com_set
*rcs
= rule
;
1799 community_free(rcs
->com
);
1800 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1803 /* Set community rule structure. */
1804 struct route_map_rule_cmd route_set_community_cmd
= {
1805 "community", route_set_community
, route_set_community_compile
,
1806 route_set_community_free
,
1809 /* `set community COMMUNITY' */
1810 struct rmap_lcom_set
{
1811 struct lcommunity
*lcom
;
1817 /* For lcommunity set mechanism. */
1818 static route_map_result_t
route_set_lcommunity(void *rule
,
1819 const struct prefix
*prefix
,
1820 route_map_object_t type
,
1823 struct rmap_lcom_set
*rcs
;
1824 struct bgp_info
*binfo
;
1826 struct lcommunity
*new = NULL
;
1827 struct lcommunity
*old
;
1828 struct lcommunity
*merge
;
1830 if (type
== RMAP_BGP
) {
1834 old
= attr
->lcommunity
;
1839 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
1840 attr
->lcommunity
= NULL
;
1842 /* See the longer comment down below. */
1843 if (old
&& old
->refcnt
== 0)
1844 lcommunity_free(&old
);
1848 if (rcs
->additive
&& old
) {
1849 merge
= lcommunity_merge(lcommunity_dup(old
),
1852 new = lcommunity_uniq_sort(merge
);
1853 lcommunity_free(&merge
);
1855 new = lcommunity_dup(rcs
->lcom
);
1857 /* HACK: if the old large-community is not intern'd,
1858 * we should free it here, or all reference to it may be
1860 * Really need to cleanup attribute caching sometime.
1862 if (old
&& old
->refcnt
== 0)
1863 lcommunity_free(&old
);
1865 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1866 attr
->lcommunity
= new;
1868 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
1874 /* Compile function for set community. */
1875 static void *route_set_lcommunity_compile(const char *arg
)
1877 struct rmap_lcom_set
*rcs
;
1878 struct lcommunity
*lcom
= NULL
;
1883 if (strcmp(arg
, "none") == 0)
1886 sp
= strstr(arg
, "additive");
1888 if (sp
&& sp
> arg
) {
1889 /* "additive" keyworkd is included. */
1894 lcom
= lcommunity_str2com(arg
);
1903 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1905 rcs
->additive
= additive
;
1911 /* Free function for set lcommunity. */
1912 static void route_set_lcommunity_free(void *rule
)
1914 struct rmap_lcom_set
*rcs
= rule
;
1917 lcommunity_free(&rcs
->lcom
);
1919 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1922 /* Set community rule structure. */
1923 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
1924 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
1925 route_set_lcommunity_free
,
1928 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
1930 /* For large community set mechanism. */
1931 static route_map_result_t
route_set_lcommunity_delete(void *rule
,
1932 const struct prefix
*pfx
,
1933 route_map_object_t type
,
1936 struct community_list
*list
;
1937 struct lcommunity
*merge
;
1938 struct lcommunity
*new;
1939 struct lcommunity
*old
;
1940 struct bgp_info
*binfo
;
1942 if (type
== RMAP_BGP
) {
1947 list
= community_list_lookup(bgp_clist
, rule
,
1948 LARGE_COMMUNITY_LIST_MASTER
);
1949 old
= binfo
->attr
->lcommunity
;
1952 merge
= lcommunity_list_match_delete(
1953 lcommunity_dup(old
), list
);
1954 new = lcommunity_uniq_sort(merge
);
1955 lcommunity_free(&merge
);
1957 /* HACK: if the old community is not intern'd,
1958 * we should free it here, or all reference to it may be
1960 * Really need to cleanup attribute caching sometime.
1962 if (old
->refcnt
== 0)
1963 lcommunity_free(&old
);
1965 if (new->size
== 0) {
1966 binfo
->attr
->lcommunity
= NULL
;
1967 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT(
1968 BGP_ATTR_LARGE_COMMUNITIES
);
1969 lcommunity_free(&new);
1971 binfo
->attr
->lcommunity
= new;
1972 binfo
->attr
->flag
|= ATTR_FLAG_BIT(
1973 BGP_ATTR_LARGE_COMMUNITIES
);
1981 /* Compile function for set lcommunity. */
1982 static void *route_set_lcommunity_delete_compile(const char *arg
)
1988 p
= strchr(arg
, ' ');
1991 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1992 memcpy(str
, arg
, len
);
1999 /* Free function for set lcommunity. */
2000 static void route_set_lcommunity_delete_free(void *rule
)
2002 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2005 /* Set lcommunity rule structure. */
2006 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
2007 "large-comm-list", route_set_lcommunity_delete
,
2008 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
2012 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
2014 /* For community set mechanism. */
2015 static route_map_result_t
route_set_community_delete(
2017 const struct prefix
*prefix
,
2018 route_map_object_t type
,
2021 struct community_list
*list
;
2022 struct community
*merge
;
2023 struct community
*new;
2024 struct community
*old
;
2025 struct bgp_info
*binfo
;
2027 if (type
== RMAP_BGP
) {
2032 list
= community_list_lookup(bgp_clist
, rule
,
2033 COMMUNITY_LIST_MASTER
);
2034 old
= binfo
->attr
->community
;
2037 merge
= community_list_match_delete(community_dup(old
),
2039 new = community_uniq_sort(merge
);
2040 community_free(merge
);
2042 /* HACK: if the old community is not intern'd,
2043 * we should free it here, or all reference to it may be
2045 * Really need to cleanup attribute caching sometime.
2047 if (old
->refcnt
== 0)
2048 community_free(old
);
2050 if (new->size
== 0) {
2051 binfo
->attr
->community
= NULL
;
2052 binfo
->attr
->flag
&=
2053 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2054 community_free(new);
2056 binfo
->attr
->community
= new;
2057 binfo
->attr
->flag
|=
2058 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
2066 /* Compile function for set community. */
2067 static void *route_set_community_delete_compile(const char *arg
)
2073 p
= strchr(arg
, ' ');
2076 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
2077 memcpy(str
, arg
, len
);
2084 /* Free function for set community. */
2085 static void route_set_community_delete_free(void *rule
)
2087 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2090 /* Set community rule structure. */
2091 struct route_map_rule_cmd route_set_community_delete_cmd
= {
2092 "comm-list", route_set_community_delete
,
2093 route_set_community_delete_compile
, route_set_community_delete_free
,
2096 /* `set extcommunity rt COMMUNITY' */
2098 /* For community set mechanism. Used by _rt and _soo. */
2099 static route_map_result_t
route_set_ecommunity(void *rule
,
2100 const struct prefix
*prefix
,
2101 route_map_object_t type
,
2104 struct ecommunity
*ecom
;
2105 struct ecommunity
*new_ecom
;
2106 struct ecommunity
*old_ecom
;
2107 struct bgp_info
*bgp_info
;
2109 if (type
== RMAP_BGP
) {
2116 /* We assume additive for Extended Community. */
2117 old_ecom
= bgp_info
->attr
->ecommunity
;
2120 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
2123 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
2124 * bgp_update_receive()
2125 * ->refcnt = 0 => set by a previous route-map
2127 if (!old_ecom
->refcnt
)
2128 ecommunity_free(&old_ecom
);
2130 new_ecom
= ecommunity_dup(ecom
);
2132 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
2133 bgp_info
->attr
->ecommunity
= new_ecom
;
2135 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
2140 /* Compile function for set community. */
2141 static void *route_set_ecommunity_rt_compile(const char *arg
)
2143 struct ecommunity
*ecom
;
2145 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
2148 return ecommunity_intern(ecom
);
2151 /* Free function for set community. Used by _rt and _soo */
2152 static void route_set_ecommunity_free(void *rule
)
2154 struct ecommunity
*ecom
= rule
;
2155 ecommunity_unintern(&ecom
);
2158 /* Set community rule structure. */
2159 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
2160 "extcommunity rt", route_set_ecommunity
,
2161 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
2164 /* `set extcommunity soo COMMUNITY' */
2166 /* Compile function for set community. */
2167 static void *route_set_ecommunity_soo_compile(const char *arg
)
2169 struct ecommunity
*ecom
;
2171 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2175 return ecommunity_intern(ecom
);
2178 /* Set community rule structure. */
2179 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
2180 "extcommunity soo", route_set_ecommunity
,
2181 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
2184 /* `set origin ORIGIN' */
2186 /* For origin set. */
2187 static route_map_result_t
route_set_origin(void *rule
,
2188 const struct prefix
*prefix
,
2189 route_map_object_t type
,
2193 struct bgp_info
*bgp_info
;
2195 if (type
== RMAP_BGP
) {
2199 bgp_info
->attr
->origin
= *origin
;
2205 /* Compile function for origin set. */
2206 static void *route_set_origin_compile(const char *arg
)
2210 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(uint8_t));
2212 if (strcmp(arg
, "igp") == 0)
2214 else if (strcmp(arg
, "egp") == 0)
2222 /* Compile function for origin set. */
2223 static void route_set_origin_free(void *rule
)
2225 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2228 /* Set origin rule structure. */
2229 struct route_map_rule_cmd route_set_origin_cmd
= {
2230 "origin", route_set_origin
, route_set_origin_compile
,
2231 route_set_origin_free
,
2234 /* `set atomic-aggregate' */
2236 /* For atomic aggregate set. */
2237 static route_map_result_t
route_set_atomic_aggregate(void *rule
,
2238 const struct prefix
*pfx
,
2239 route_map_object_t type
,
2242 struct bgp_info
*bgp_info
;
2244 if (type
== RMAP_BGP
) {
2246 bgp_info
->attr
->flag
|=
2247 ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2253 /* Compile function for atomic aggregate. */
2254 static void *route_set_atomic_aggregate_compile(const char *arg
)
2259 /* Compile function for atomic aggregate. */
2260 static void route_set_atomic_aggregate_free(void *rule
)
2265 /* Set atomic aggregate rule structure. */
2266 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2267 "atomic-aggregate", route_set_atomic_aggregate
,
2268 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2271 /* `set aggregator as AS A.B.C.D' */
2274 struct in_addr address
;
2277 static route_map_result_t
route_set_aggregator_as(void *rule
,
2278 const struct prefix
*prefix
,
2279 route_map_object_t type
,
2282 struct bgp_info
*bgp_info
;
2283 struct aggregator
*aggregator
;
2285 if (type
== RMAP_BGP
) {
2289 bgp_info
->attr
->aggregator_as
= aggregator
->as
;
2290 bgp_info
->attr
->aggregator_addr
= aggregator
->address
;
2291 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2297 static void *route_set_aggregator_as_compile(const char *arg
)
2299 struct aggregator
*aggregator
;
2305 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2306 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2307 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2311 aggregator
->as
= strtoul(as
, NULL
, 10);
2312 ret
= inet_aton(address
, &aggregator
->address
);
2314 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2320 static void route_set_aggregator_as_free(void *rule
)
2322 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2325 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2326 "aggregator as", route_set_aggregator_as
,
2327 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2330 /* Set tag to object. object must be pointer to struct bgp_info */
2331 static route_map_result_t
route_set_tag(void *rule
,
2332 const struct prefix
*prefix
,
2333 route_map_object_t type
, void *object
)
2336 struct bgp_info
*bgp_info
;
2338 if (type
== RMAP_BGP
) {
2343 bgp_info
->attr
->tag
= *tag
;
2349 /* Route map commands for tag set. */
2350 static struct route_map_rule_cmd route_set_tag_cmd
= {
2351 "tag", route_set_tag
, route_map_rule_tag_compile
,
2352 route_map_rule_tag_free
,
2355 /* Set label-index to object. object must be pointer to struct bgp_info */
2356 static route_map_result_t
route_set_label_index(void *rule
,
2357 const struct prefix
*prefix
,
2358 route_map_object_t type
,
2361 struct rmap_value
*rv
;
2362 struct bgp_info
*bgp_info
;
2363 uint32_t label_index
;
2365 if (type
== RMAP_BGP
) {
2366 /* Fetch routemap's rule information. */
2370 /* Set label-index value. */
2371 label_index
= rv
->value
;
2373 bgp_info
->attr
->label_index
= label_index
;
2374 bgp_info
->attr
->flag
|=
2375 ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2382 /* Route map commands for label-index set. */
2383 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2384 "label-index", route_set_label_index
, route_value_compile
,
2388 /* `match ipv6 address IP_ACCESS_LIST' */
2390 static route_map_result_t
route_match_ipv6_address(void *rule
,
2391 const struct prefix
*prefix
,
2392 route_map_object_t type
,
2395 struct access_list
*alist
;
2397 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2398 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2400 return RMAP_NOMATCH
;
2402 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2406 return RMAP_NOMATCH
;
2409 static void *route_match_ipv6_address_compile(const char *arg
)
2411 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2414 static void route_match_ipv6_address_free(void *rule
)
2416 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2419 /* Route map commands for ip address matching. */
2420 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2421 "ipv6 address", route_match_ipv6_address
,
2422 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2424 /* `match ipv6 next-hop IP_ADDRESS' */
2426 static route_map_result_t
route_match_ipv6_next_hop(void *rule
,
2427 const struct prefix
*prefix
,
2428 route_map_object_t type
,
2431 struct in6_addr
*addr
= rule
;
2432 struct bgp_info
*bgp_info
;
2434 if (type
== RMAP_BGP
) {
2437 if (IPV6_ADDR_SAME(&bgp_info
->attr
->mp_nexthop_global
, addr
))
2440 if (bgp_info
->attr
->mp_nexthop_len
2441 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2442 && IPV6_ADDR_SAME(&bgp_info
->attr
->mp_nexthop_local
, rule
))
2445 return RMAP_NOMATCH
;
2448 return RMAP_NOMATCH
;
2451 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2453 struct in6_addr
*address
;
2456 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2458 ret
= inet_pton(AF_INET6
, arg
, address
);
2460 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2467 static void route_match_ipv6_next_hop_free(void *rule
)
2469 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2472 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2473 "ipv6 next-hop", route_match_ipv6_next_hop
,
2474 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2476 /* `match ipv6 address prefix-list PREFIX_LIST' */
2478 static route_map_result_t
2479 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
2480 route_map_object_t type
, void *object
)
2482 struct prefix_list
*plist
;
2484 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2485 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
2487 return RMAP_NOMATCH
;
2489 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
2493 return RMAP_NOMATCH
;
2496 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2498 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2501 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2503 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2506 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2507 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2508 route_match_ipv6_address_prefix_list_compile
,
2509 route_match_ipv6_address_prefix_list_free
};
2511 /* `match ipv6 next-hop type <TYPE>' */
2513 static route_map_result_t
2514 route_match_ipv6_next_hop_type(void *rule
, const struct prefix
*prefix
,
2515 route_map_object_t type
, void *object
)
2517 struct bgp_info
*bgp_info
;
2518 struct in6_addr
*addr
= rule
;
2520 if (type
== RMAP_BGP
&& prefix
->family
== AF_INET6
) {
2521 bgp_info
= (struct bgp_info
*)object
;
2522 if (!bgp_info
|| !bgp_info
->attr
)
2523 return RMAP_DENYMATCH
;
2525 if (IPV6_ADDR_SAME(&bgp_info
->attr
->mp_nexthop_global
, addr
)
2526 && !bgp_info
->attr
->nh_ifindex
)
2529 return RMAP_NOMATCH
;
2532 static void *route_match_ipv6_next_hop_type_compile(const char *arg
)
2534 struct in6_addr
*address
;
2537 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2539 ret
= inet_pton(AF_INET6
, "::0", address
);
2541 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2548 static void route_match_ipv6_next_hop_type_free(void *rule
)
2550 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2553 struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd
= {
2554 "ipv6 next-hop type", route_match_ipv6_next_hop_type
,
2555 route_match_ipv6_next_hop_type_compile
,
2556 route_match_ipv6_next_hop_type_free
};
2558 /* `set ipv6 nexthop global IP_ADDRESS' */
2560 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2561 static route_map_result_t
route_set_ipv6_nexthop_global(void *rule
,
2562 const struct prefix
*p
,
2563 route_map_object_t type
,
2566 struct in6_addr
*address
;
2567 struct bgp_info
*bgp_info
;
2569 if (type
== RMAP_BGP
) {
2570 /* Fetch routemap's rule information. */
2574 /* Set next hop value. */
2575 bgp_info
->attr
->mp_nexthop_global
= *address
;
2577 /* Set nexthop length. */
2578 if (bgp_info
->attr
->mp_nexthop_len
== 0)
2579 bgp_info
->attr
->mp_nexthop_len
=
2580 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2582 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2583 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2589 /* Route map `ip next-hop' compile function. Given string is converted
2590 to struct in_addr structure. */
2591 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2594 struct in6_addr
*address
;
2596 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2598 ret
= inet_pton(AF_INET6
, arg
, address
);
2601 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2608 /* Free route map's compiled `ip next-hop' value. */
2609 static void route_set_ipv6_nexthop_global_free(void *rule
)
2611 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2614 /* Route map commands for ip nexthop set. */
2615 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2616 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2617 route_set_ipv6_nexthop_global_compile
,
2618 route_set_ipv6_nexthop_global_free
};
2620 /* Set next-hop preference value. */
2621 static route_map_result_t
2622 route_set_ipv6_nexthop_prefer_global(void *rule
, const struct prefix
*prefix
,
2623 route_map_object_t type
, void *object
)
2625 struct bgp_info
*bgp_info
;
2628 if (type
== RMAP_BGP
) {
2629 /* Fetch routemap's rule information. */
2631 peer
= bgp_info
->peer
;
2633 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2634 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2636 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2637 /* Set next hop preference to global */
2638 bgp_info
->attr
->mp_nexthop_prefer_global
= TRUE
;
2639 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2640 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2642 bgp_info
->attr
->mp_nexthop_prefer_global
= FALSE
;
2643 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2644 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2650 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2654 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2660 /* Free route map's compiled `ip next-hop' value. */
2661 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2663 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2666 /* Route map commands for ip nexthop set preferred. */
2667 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2668 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2669 route_set_ipv6_nexthop_prefer_global_compile
,
2670 route_set_ipv6_nexthop_prefer_global_free
};
2672 /* `set ipv6 nexthop local IP_ADDRESS' */
2674 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2675 static route_map_result_t
route_set_ipv6_nexthop_local(void *rule
,
2676 const struct prefix
*p
,
2677 route_map_object_t type
,
2680 struct in6_addr
*address
;
2681 struct bgp_info
*bgp_info
;
2683 if (type
== RMAP_BGP
) {
2684 /* Fetch routemap's rule information. */
2688 /* Set next hop value. */
2689 bgp_info
->attr
->mp_nexthop_local
= *address
;
2691 /* Set nexthop length. */
2692 if (bgp_info
->attr
->mp_nexthop_len
2693 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2694 bgp_info
->attr
->mp_nexthop_len
=
2695 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2697 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2698 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2704 /* Route map `ip nexthop' compile function. Given string is converted
2705 to struct in_addr structure. */
2706 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2709 struct in6_addr
*address
;
2711 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2713 ret
= inet_pton(AF_INET6
, arg
, address
);
2716 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2723 /* Free route map's compiled `ip nexthop' value. */
2724 static void route_set_ipv6_nexthop_local_free(void *rule
)
2726 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2729 /* Route map commands for ip nexthop set. */
2730 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2731 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2732 route_set_ipv6_nexthop_local_compile
,
2733 route_set_ipv6_nexthop_local_free
};
2735 /* `set ipv6 nexthop peer-address' */
2737 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2738 static route_map_result_t
route_set_ipv6_nexthop_peer(void *rule
,
2739 const struct prefix
*pfx
,
2740 route_map_object_t type
,
2743 struct in6_addr peer_address
;
2744 struct bgp_info
*bgp_info
;
2747 if (type
== RMAP_BGP
) {
2748 /* Fetch routemap's rule information. */
2750 peer
= bgp_info
->peer
;
2752 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2753 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2755 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2756 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2757 /* Set next hop value and length in attribute. */
2758 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2759 bgp_info
->attr
->mp_nexthop_local
= peer_address
;
2760 if (bgp_info
->attr
->mp_nexthop_len
!= 32)
2761 bgp_info
->attr
->mp_nexthop_len
= 32;
2763 bgp_info
->attr
->mp_nexthop_global
=
2765 if (bgp_info
->attr
->mp_nexthop_len
== 0)
2766 bgp_info
->attr
->mp_nexthop_len
= 16;
2769 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2770 /* The next hop value will be set as part of packet
2772 * Set the flags here to indicate that rewrite needs to
2774 * Also, clear the value - we clear both global and
2776 * nexthops, whether we send one or both is determined
2779 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2780 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2781 /* clear next hop value. */
2782 memset(&(bgp_info
->attr
->mp_nexthop_global
), 0,
2783 sizeof(struct in6_addr
));
2784 memset(&(bgp_info
->attr
->mp_nexthop_local
), 0,
2785 sizeof(struct in6_addr
));
2792 /* Route map `ip next-hop' compile function. Given string is converted
2793 to struct in_addr structure. */
2794 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2798 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2804 /* Free route map's compiled `ip next-hop' value. */
2805 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2807 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2810 /* Route map commands for ip nexthop set. */
2811 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2812 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2813 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2815 /* `set ipv4 vpn next-hop A.B.C.D' */
2817 static route_map_result_t
route_set_vpnv4_nexthop(void *rule
,
2818 const struct prefix
*prefix
,
2819 route_map_object_t type
,
2822 struct in_addr
*address
;
2823 struct bgp_info
*bgp_info
;
2825 if (type
== RMAP_BGP
) {
2826 /* Fetch routemap's rule information. */
2830 /* Set next hop value. */
2831 bgp_info
->attr
->mp_nexthop_global_in
= *address
;
2832 bgp_info
->attr
->mp_nexthop_len
= 4;
2838 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2841 struct in_addr
*address
;
2843 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2845 ret
= inet_aton(arg
, address
);
2848 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2855 /* `set ipv6 vpn next-hop A.B.C.D' */
2857 static route_map_result_t
route_set_vpnv6_nexthop(void *rule
,
2858 const struct prefix
*prefix
,
2859 route_map_object_t type
,
2862 struct in6_addr
*address
;
2863 struct bgp_info
*bgp_info
;
2865 if (type
== RMAP_BGP
) {
2866 /* Fetch routemap's rule information. */
2870 /* Set next hop value. */
2871 memcpy(&bgp_info
->attr
->mp_nexthop_global
, address
,
2872 sizeof(struct in6_addr
));
2873 bgp_info
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2879 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2882 struct in6_addr
*address
;
2884 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2885 ret
= inet_pton(AF_INET6
, arg
, address
);
2888 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2895 static void route_set_vpn_nexthop_free(void *rule
)
2897 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2900 /* Route map commands for ipv4 next-hop set. */
2901 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2902 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2903 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
2905 /* Route map commands for ipv6 next-hop set. */
2906 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
2907 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
2908 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
2910 /* `set originator-id' */
2912 /* For origin set. */
2913 static route_map_result_t
route_set_originator_id(void *rule
,
2914 const struct prefix
*prefix
,
2915 route_map_object_t type
,
2918 struct in_addr
*address
;
2919 struct bgp_info
*bgp_info
;
2921 if (type
== RMAP_BGP
) {
2925 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
2926 bgp_info
->attr
->originator_id
= *address
;
2932 /* Compile function for originator-id set. */
2933 static void *route_set_originator_id_compile(const char *arg
)
2936 struct in_addr
*address
;
2938 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2940 ret
= inet_aton(arg
, address
);
2943 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2950 /* Compile function for originator_id set. */
2951 static void route_set_originator_id_free(void *rule
)
2953 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2956 /* Set originator-id rule structure. */
2957 struct route_map_rule_cmd route_set_originator_id_cmd
= {
2958 "originator-id", route_set_originator_id
,
2959 route_set_originator_id_compile
, route_set_originator_id_free
,
2962 /* Add bgp route map rule. */
2963 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
2964 const char *arg
, route_map_event_t type
)
2966 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2967 int retval
= CMD_SUCCESS
;
2970 ret
= route_map_add_match(index
, command
, arg
);
2972 case RMAP_RULE_MISSING
:
2973 vty_out(vty
, "%% BGP Can't find rule.\n");
2974 retval
= CMD_WARNING_CONFIG_FAILED
;
2976 case RMAP_COMPILE_ERROR
:
2977 vty_out(vty
, "%% BGP Argument is malformed.\n");
2978 retval
= CMD_WARNING_CONFIG_FAILED
;
2980 case RMAP_COMPILE_SUCCESS
:
2981 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
2982 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
2990 /* Delete bgp route map rule. */
2991 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
2992 const char *arg
, route_map_event_t type
)
2994 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2996 int retval
= CMD_SUCCESS
;
2997 char *dep_name
= NULL
;
2999 char *rmap_name
= NULL
;
3001 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
3002 /* ignore the mundane, the types without any dependency */
3004 if ((tmpstr
= route_map_get_match_arg(index
, command
))
3007 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
3009 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
3011 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
3014 ret
= route_map_delete_match(index
, command
, dep_name
);
3016 case RMAP_RULE_MISSING
:
3017 vty_out(vty
, "%% BGP Can't find rule.\n");
3018 retval
= CMD_WARNING_CONFIG_FAILED
;
3020 case RMAP_COMPILE_ERROR
:
3021 vty_out(vty
, "%% BGP Argument is malformed.\n");
3022 retval
= CMD_WARNING_CONFIG_FAILED
;
3024 case RMAP_COMPILE_SUCCESS
:
3025 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
3026 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
3031 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
3033 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
3039 * This is the workhorse routine for processing in/out routemap
3042 static void bgp_route_map_process_peer(const char *rmap_name
,
3043 struct route_map
*map
, struct peer
*peer
,
3044 int afi
, int safi
, int route_update
)
3048 struct bgp_filter
*filter
;
3050 if (!peer
|| !rmap_name
)
3053 filter
= &peer
->filter
[afi
][safi
];
3055 * in is for non-route-server clients,
3056 * out is for all peers
3058 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
3059 if (filter
->map
[RMAP_IN
].name
3060 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
3061 filter
->map
[RMAP_IN
].map
= map
;
3063 if (route_update
&& peer
->status
== Established
) {
3064 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3065 PEER_FLAG_SOFT_RECONFIG
)) {
3066 if (bgp_debug_update(peer
, NULL
, NULL
,
3069 "Processing route_map %s update on "
3070 "peer %s (inbound, soft-reconfig)",
3071 rmap_name
, peer
->host
);
3073 bgp_soft_reconfig_in(peer
, afi
, safi
);
3075 CHECK_FLAG(peer
->cap
,
3076 PEER_CAP_REFRESH_OLD_RCV
)
3079 PEER_CAP_REFRESH_NEW_RCV
)) {
3081 if (bgp_debug_update(peer
, NULL
, NULL
,
3084 "Processing route_map %s update on "
3085 "peer %s (inbound, route-refresh)",
3086 rmap_name
, peer
->host
);
3087 bgp_route_refresh_send(peer
, afi
, safi
,
3094 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
3097 if (update
&& route_update
&& peer
->status
== Established
) {
3098 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
3099 PEER_FLAG_SOFT_RECONFIG
)) {
3100 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3102 "Processing route_map %s update on "
3103 "peer %s (import, soft-reconfig)",
3104 rmap_name
, peer
->host
);
3106 bgp_soft_reconfig_in(peer
, afi
, safi
);
3107 } else if (CHECK_FLAG(peer
->cap
,
3108 PEER_CAP_REFRESH_OLD_RCV
)
3109 || CHECK_FLAG(peer
->cap
,
3110 PEER_CAP_REFRESH_NEW_RCV
)) {
3111 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3113 "Processing route_map %s update on "
3114 "peer %s (import, route-refresh)",
3115 rmap_name
, peer
->host
);
3116 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
3119 /* DD: Else, what else do we do ? Reset peer ? */
3124 * For outbound, unsuppress and default-originate map change (content or
3125 * map created), merely update the "config" here, the actual route
3126 * announcement happens at the group level.
3128 if (filter
->map
[RMAP_OUT
].name
3129 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3130 filter
->map
[RMAP_OUT
].map
= map
;
3132 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3133 filter
->usmap
.map
= map
;
3135 if (peer
->default_rmap
[afi
][safi
].name
3136 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3137 peer
->default_rmap
[afi
][safi
].map
= map
;
3140 static void bgp_route_map_update_peer_group(const char *rmap_name
,
3141 struct route_map
*map
,
3144 struct peer_group
*group
;
3145 struct listnode
*node
, *nnode
;
3146 struct bgp_filter
*filter
;
3153 /* All the peers have been updated correctly already. This is
3154 * just updating the placeholder data. No real update required.
3156 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
3157 FOREACH_AFI_SAFI (afi
, safi
) {
3158 filter
= &group
->conf
->filter
[afi
][safi
];
3160 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
3161 if ((filter
->map
[direct
].name
)
3162 && (strcmp(rmap_name
,
3163 filter
->map
[direct
].name
)
3165 filter
->map
[direct
].map
= map
;
3168 if (filter
->usmap
.name
3169 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3170 filter
->usmap
.map
= map
;
3176 * Note that if an extreme number (tens of thousands) of route-maps are in use
3177 * and if bgp has an extreme number of peers, network statements, etc then this
3178 * function can consume a lot of cycles. This is due to this function being
3179 * called for each route-map and within this function we walk the list of peers,
3180 * network statements, etc looking to see if they use this route-map.
3182 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
3189 struct bgp_node
*bn
;
3190 struct bgp_static
*bgp_static
;
3191 struct listnode
*node
, *nnode
;
3192 struct route_map
*map
;
3193 char buf
[INET6_ADDRSTRLEN
];
3195 map
= route_map_lookup_by_name(rmap_name
);
3197 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
3199 /* Ignore dummy peer-group structure */
3200 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3203 FOREACH_AFI_SAFI (afi
, safi
) {
3204 /* process in/out/import/export/default-orig
3206 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
3207 safi
, route_update
);
3211 /* for outbound/default-orig route-maps, process for groups */
3212 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3215 /* update peer-group config (template) */
3216 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3218 FOREACH_AFI_SAFI (afi
, safi
) {
3219 /* For table route-map updates. */
3220 if (!bgp_fibupd_safi(safi
))
3223 if (bgp
->table_map
[afi
][safi
].name
3224 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
3226 bgp
->table_map
[afi
][safi
].map
= map
;
3228 if (BGP_DEBUG(zebra
, ZEBRA
))
3230 "Processing route_map %s update on "
3234 bgp_zebra_announce_table(bgp
, afi
, safi
);
3237 /* For network route-map updates. */
3238 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
3239 bn
= bgp_route_next(bn
))
3240 if ((bgp_static
= bn
->info
) != NULL
) {
3241 if (bgp_static
->rmap
.name
3242 && (strcmp(rmap_name
, bgp_static
->rmap
.name
)
3244 bgp_static
->rmap
.map
= map
;
3247 if (!bgp_static
->backdoor
) {
3248 if (bgp_debug_zebra(
3251 "Processing route_map %s update on "
3268 /* For redistribute route-map updates. */
3269 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3270 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3271 struct list
*red_list
;
3272 struct bgp_redist
*red
;
3274 red_list
= bgp
->redist
[afi
][i
];
3278 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3280 && (strcmp(rmap_name
, red
->rmap
.name
)
3282 red
->rmap
.map
= map
;
3285 if (BGP_DEBUG(zebra
, ZEBRA
))
3287 "Processing route_map %s update on "
3288 "redistributed routes",
3291 bgp_redistribute_resend(
3299 /* for type5 command route-maps */
3300 FOREACH_AFI_SAFI (afi
, safi
) {
3301 if (bgp
->adv_cmd_rmap
[afi
][safi
].name
3302 && strcmp(rmap_name
, bgp
->adv_cmd_rmap
[afi
][safi
].name
)
3304 if (BGP_DEBUG(zebra
, ZEBRA
))
3306 "Processing route_map %s update on advertise type5 route command",
3308 bgp_evpn_withdraw_type5_routes(bgp
, afi
, safi
);
3309 bgp_evpn_advertise_type5_routes(bgp
, afi
, safi
);
3314 static void bgp_route_map_process_update_cb(char *rmap_name
)
3316 struct listnode
*node
, *nnode
;
3319 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
3320 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3323 /* zlog_debug("%s: calling vnc_routemap_update", __func__); */
3324 vnc_routemap_update(bgp
, __func__
);
3328 vpn_policy_routemap_event(rmap_name
);
3331 int bgp_route_map_update_timer(struct thread
*thread
)
3333 bm
->t_rmap_update
= NULL
;
3335 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3340 static void bgp_route_map_mark_update(const char *rmap_name
)
3342 if (bm
->t_rmap_update
== NULL
) {
3343 struct listnode
*node
, *nnode
;
3346 /* rmap_update_timer of 0 means don't do route updates */
3347 if (bm
->rmap_update_timer
) {
3348 bm
->t_rmap_update
= NULL
;
3349 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3350 NULL
, bm
->rmap_update_timer
,
3351 &bm
->t_rmap_update
);
3353 /* Signal the groups that a route-map update event has
3355 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3356 update_group_policy_update(bgp
,
3357 BGP_POLICY_ROUTE_MAP
,
3360 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3361 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3363 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3364 vnc_routemap_update(bgp
, __func__
);
3370 static void bgp_route_map_add(const char *rmap_name
)
3372 if (route_map_mark_updated(rmap_name
) == 0)
3373 bgp_route_map_mark_update(rmap_name
);
3375 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3378 static void bgp_route_map_delete(const char *rmap_name
)
3380 if (route_map_mark_updated(rmap_name
) == 0)
3381 bgp_route_map_mark_update(rmap_name
);
3383 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3386 static void bgp_route_map_event(route_map_event_t event
, const char *rmap_name
)
3388 if (route_map_mark_updated(rmap_name
) == 0)
3389 bgp_route_map_mark_update(rmap_name
);
3391 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3394 DEFUN (match_mac_address
,
3395 match_mac_address_cmd
,
3396 "match mac address WORD",
3399 "Match address of route\n"
3400 "MAC Access-list name\n")
3402 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3403 RMAP_EVENT_FILTER_ADDED
);
3406 DEFUN (no_match_mac_address
,
3407 no_match_mac_address_cmd
,
3408 "no match mac address WORD",
3412 "Match address of route\n"
3413 "MAC acess-list name\n")
3415 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3416 RMAP_EVENT_FILTER_DELETED
);
3419 DEFUN (match_evpn_route_type
,
3420 match_evpn_route_type_cmd
,
3421 "match evpn route-type <macip | multicast | prefix>",
3424 "Match route-type\n"
3429 return bgp_route_match_add(vty
, "evpn route-type", argv
[3]->arg
,
3430 RMAP_EVENT_MATCH_ADDED
);
3433 DEFUN (no_match_evpn_route_type
,
3434 no_match_evpn_route_type_cmd
,
3435 "no match evpn route-type <macip | multicast | prefix>",
3439 "Match route-type\n"
3444 return bgp_route_match_delete(vty
, "evpn route-type", argv
[4]->arg
,
3445 RMAP_EVENT_MATCH_DELETED
);
3449 DEFUN (match_evpn_vni
,
3451 "match evpn vni (1-16777215)",
3457 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3458 RMAP_EVENT_MATCH_ADDED
);
3461 DEFUN (no_match_evpn_vni
,
3462 no_match_evpn_vni_cmd
,
3463 "no match evpn vni (1-16777215)",
3470 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3471 RMAP_EVENT_MATCH_DELETED
);
3474 DEFUN (match_evpn_default_route
,
3475 match_evpn_default_route_cmd
,
3476 "match evpn default-route",
3479 "default EVPN type-5 route\n")
3481 return bgp_route_match_add(vty
, "evpn default-route", NULL
,
3482 RMAP_EVENT_MATCH_ADDED
);
3485 DEFUN (no_match_evpn_default_route
,
3486 no_match_evpn_default_route_cmd
,
3487 "no match evpn default-route",
3491 "default EVPN type-5 route\n")
3493 return bgp_route_match_delete(vty
, "evpn default-route", NULL
,
3494 RMAP_EVENT_MATCH_DELETED
);
3499 "match peer <A.B.C.D|X:X::X:X|WORD>",
3501 "Match peer address\n"
3502 "IP address of peer\n"
3503 "IPv6 address of peer\n"
3504 "Interface name of peer\n")
3507 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3508 RMAP_EVENT_MATCH_ADDED
);
3511 DEFUN (match_peer_local
,
3512 match_peer_local_cmd
,
3515 "Match peer address\n"
3516 "Static or Redistributed routes\n")
3518 return bgp_route_match_add(vty
, "peer", "local",
3519 RMAP_EVENT_MATCH_DELETED
);
3522 DEFUN (no_match_peer
,
3524 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3527 "Match peer address\n"
3528 "Static or Redistributed routes\n"
3529 "IP address of peer\n"
3530 "IPv6 address of peer\n"
3531 "Interface name of peer\n")
3535 if (argc
<= idx_peer
)
3536 return bgp_route_match_delete(vty
, "peer", NULL
,
3537 RMAP_EVENT_MATCH_DELETED
);
3538 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3539 RMAP_EVENT_MATCH_DELETED
);
3542 #if defined(HAVE_LUA)
3543 DEFUN (match_command
,
3545 "match command WORD",
3547 "Run a command to match\n"
3548 "The command to run\n")
3550 return bgp_route_match_add(vty
, "command", argv
[2]->arg
,
3551 RMAP_EVENT_FILTER_ADDED
);
3554 DEFUN (no_match_command
,
3555 no_match_command_cmd
,
3556 "no match command WORD",
3559 "Run a command to match\n"
3560 "The command to run\n")
3562 return bgp_route_match_delete(vty
, "command", argv
[3]->arg
,
3563 RMAP_EVENT_FILTER_DELETED
);
3567 /* match probability */
3568 DEFUN (match_probability
,
3569 match_probability_cmd
,
3570 "match probability (0-100)",
3572 "Match portion of routes defined by percentage value\n"
3573 "Percentage of routes\n")
3576 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3577 RMAP_EVENT_MATCH_ADDED
);
3581 DEFUN (no_match_probability
,
3582 no_match_probability_cmd
,
3583 "no match probability [(1-99)]",
3586 "Match portion of routes defined by percentage value\n"
3587 "Percentage of routes\n")
3590 if (argc
<= idx_number
)
3591 return bgp_route_match_delete(vty
, "probability", NULL
,
3592 RMAP_EVENT_MATCH_DELETED
);
3593 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3594 RMAP_EVENT_MATCH_DELETED
);
3598 DEFUN (match_ip_route_source
,
3599 match_ip_route_source_cmd
,
3600 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3603 "Match advertising source address of route\n"
3604 "IP access-list number\n"
3605 "IP access-list number (expanded range)\n"
3606 "IP standard access-list name\n")
3609 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3610 RMAP_EVENT_FILTER_ADDED
);
3614 DEFUN (no_match_ip_route_source
,
3615 no_match_ip_route_source_cmd
,
3616 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3620 "Match advertising source address of route\n"
3621 "IP access-list number\n"
3622 "IP access-list number (expanded range)\n"
3623 "IP standard access-list name\n")
3626 if (argc
<= idx_number
)
3627 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3628 RMAP_EVENT_FILTER_DELETED
);
3629 return bgp_route_match_delete(vty
, "ip route-source",
3630 argv
[idx_number
]->arg
,
3631 RMAP_EVENT_FILTER_DELETED
);
3635 DEFUN (match_ip_route_source_prefix_list
,
3636 match_ip_route_source_prefix_list_cmd
,
3637 "match ip route-source prefix-list WORD",
3640 "Match advertising source address of route\n"
3641 "Match entries of prefix-lists\n"
3642 "IP prefix-list name\n")
3645 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3646 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3650 DEFUN (no_match_ip_route_source_prefix_list
,
3651 no_match_ip_route_source_prefix_list_cmd
,
3652 "no match ip route-source prefix-list [WORD]",
3656 "Match advertising source address of route\n"
3657 "Match entries of prefix-lists\n"
3658 "IP prefix-list name\n")
3661 if (argc
<= idx_word
)
3662 return bgp_route_match_delete(vty
,
3663 "ip route-source prefix-list",
3664 NULL
, RMAP_EVENT_PLIST_DELETED
);
3665 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3666 argv
[idx_word
]->arg
,
3667 RMAP_EVENT_PLIST_DELETED
);
3671 DEFUN (match_local_pref
,
3672 match_local_pref_cmd
,
3673 "match local-preference (0-4294967295)",
3675 "Match local-preference of route\n"
3679 return bgp_route_match_add(vty
, "local-preference",
3680 argv
[idx_number
]->arg
,
3681 RMAP_EVENT_MATCH_ADDED
);
3685 DEFUN (no_match_local_pref
,
3686 no_match_local_pref_cmd
,
3687 "no match local-preference [(0-4294967295)]",
3690 "Match local preference of route\n"
3691 "Local preference value\n")
3693 int idx_localpref
= 3;
3694 if (argc
<= idx_localpref
)
3695 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3696 RMAP_EVENT_MATCH_DELETED
);
3697 return bgp_route_match_delete(vty
, "local-preference",
3698 argv
[idx_localpref
]->arg
,
3699 RMAP_EVENT_MATCH_DELETED
);
3703 DEFUN (match_community
,
3704 match_community_cmd
,
3705 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3707 "Match BGP community list\n"
3708 "Community-list number (standard)\n"
3709 "Community-list number (expanded)\n"
3710 "Community-list name\n"
3711 "Do exact matching of communities\n")
3713 int idx_comm_list
= 2;
3718 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3719 strlen(argv
[idx_comm_list
]->arg
)
3720 + strlen("exact-match") + 2);
3722 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3724 argstr
= argv
[idx_comm_list
]->arg
;
3726 ret
= bgp_route_match_add(vty
, "community", argstr
,
3727 RMAP_EVENT_CLIST_ADDED
);
3729 if (argstr
!= argv
[idx_comm_list
]->arg
)
3730 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3735 DEFUN (no_match_community
,
3736 no_match_community_cmd
,
3737 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3740 "Match BGP community list\n"
3741 "Community-list number (standard)\n"
3742 "Community-list number (expanded)\n"
3743 "Community-list name\n"
3744 "Do exact matching of communities\n")
3746 return bgp_route_match_delete(vty
, "community", NULL
,
3747 RMAP_EVENT_CLIST_DELETED
);
3750 DEFUN (match_lcommunity
,
3751 match_lcommunity_cmd
,
3752 "match large-community <(1-99)|(100-500)|WORD>",
3754 "Match BGP large community list\n"
3755 "Large Community-list number (standard)\n"
3756 "Large Community-list number (expanded)\n"
3757 "Large Community-list name\n")
3759 return bgp_route_match_add(vty
, "large-community", argv
[2]->arg
,
3760 RMAP_EVENT_LLIST_ADDED
);
3763 DEFUN (no_match_lcommunity
,
3764 no_match_lcommunity_cmd
,
3765 "no match large-community [<(1-99)|(100-500)|WORD>]",
3768 "Match BGP large community list\n"
3769 "Large Community-list number (standard)\n"
3770 "Large Community-list number (expanded)\n"
3771 "Large Community-list name\n")
3773 return bgp_route_match_delete(vty
, "large-community", NULL
,
3774 RMAP_EVENT_LLIST_DELETED
);
3777 DEFUN (match_ecommunity
,
3778 match_ecommunity_cmd
,
3779 "match extcommunity <(1-99)|(100-500)|WORD>",
3781 "Match BGP/VPN extended community list\n"
3782 "Extended community-list number (standard)\n"
3783 "Extended community-list number (expanded)\n"
3784 "Extended community-list name\n")
3786 int idx_comm_list
= 2;
3787 return bgp_route_match_add(vty
, "extcommunity",
3788 argv
[idx_comm_list
]->arg
,
3789 RMAP_EVENT_ECLIST_ADDED
);
3793 DEFUN (no_match_ecommunity
,
3794 no_match_ecommunity_cmd
,
3795 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3798 "Match BGP/VPN extended community list\n"
3799 "Extended community-list number (standard)\n"
3800 "Extended community-list number (expanded)\n"
3801 "Extended community-list name\n")
3803 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3804 RMAP_EVENT_ECLIST_DELETED
);
3808 DEFUN (match_aspath
,
3810 "match as-path WORD",
3812 "Match BGP AS path list\n"
3813 "AS path access-list name\n")
3816 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3817 RMAP_EVENT_ASLIST_ADDED
);
3821 DEFUN (no_match_aspath
,
3822 no_match_aspath_cmd
,
3823 "no match as-path [WORD]",
3826 "Match BGP AS path list\n"
3827 "AS path access-list name\n")
3829 return bgp_route_match_delete(vty
, "as-path", NULL
,
3830 RMAP_EVENT_ASLIST_DELETED
);
3834 DEFUN (match_origin
,
3836 "match origin <egp|igp|incomplete>",
3841 "unknown heritage\n")
3844 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3845 return bgp_route_match_add(vty
, "origin", "igp",
3846 RMAP_EVENT_MATCH_ADDED
);
3847 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3848 return bgp_route_match_add(vty
, "origin", "egp",
3849 RMAP_EVENT_MATCH_ADDED
);
3850 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3851 return bgp_route_match_add(vty
, "origin", "incomplete",
3852 RMAP_EVENT_MATCH_ADDED
);
3854 vty_out(vty
, "%% Invalid match origin type\n");
3855 return CMD_WARNING_CONFIG_FAILED
;
3859 DEFUN (no_match_origin
,
3860 no_match_origin_cmd
,
3861 "no match origin [<egp|igp|incomplete>]",
3867 "unknown heritage\n")
3869 return bgp_route_match_delete(vty
, "origin", NULL
,
3870 RMAP_EVENT_MATCH_DELETED
);
3873 DEFUN (set_ip_nexthop_peer
,
3874 set_ip_nexthop_peer_cmd
,
3875 "[no] set ip next-hop peer-address",
3879 "Next hop address\n"
3880 "Use peer address (for BGP only)\n")
3882 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3883 const char *) = strmatch(argv
[0]->text
, "no")
3884 ? generic_set_delete
3887 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3891 DEFUN (set_ip_nexthop_unchanged
,
3892 set_ip_nexthop_unchanged_cmd
,
3893 "[no] set ip next-hop unchanged",
3897 "Next hop address\n"
3898 "Don't modify existing Next hop address\n")
3900 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3901 const char *) = strmatch(argv
[0]->text
, "no")
3902 ? generic_set_delete
3905 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3910 DEFUN (set_local_pref
,
3912 "set local-preference (0-4294967295)",
3914 "BGP local preference path attribute\n"
3915 "Preference value\n")
3918 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3919 "local-preference", argv
[idx_number
]->arg
);
3923 DEFUN (no_set_local_pref
,
3924 no_set_local_pref_cmd
,
3925 "no set local-preference [(0-4294967295)]",
3928 "BGP local preference path attribute\n"
3929 "Preference value\n")
3931 int idx_localpref
= 3;
3932 if (argc
<= idx_localpref
)
3933 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3934 "local-preference", NULL
);
3935 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3936 "local-preference", argv
[idx_localpref
]->arg
);
3942 "set weight (0-4294967295)",
3944 "BGP weight for routing table\n"
3948 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
3949 argv
[idx_number
]->arg
);
3953 DEFUN (no_set_weight
,
3955 "no set weight [(0-4294967295)]",
3958 "BGP weight for routing table\n"
3962 if (argc
<= idx_weight
)
3963 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3965 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3966 "weight", argv
[idx_weight
]->arg
);
3969 DEFUN (set_label_index
,
3970 set_label_index_cmd
,
3971 "set label-index (0-1048560)",
3973 "Label index to associate with the prefix\n"
3974 "Label index value\n")
3977 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3978 "label-index", argv
[idx_number
]->arg
);
3981 DEFUN (no_set_label_index
,
3982 no_set_label_index_cmd
,
3983 "no set label-index [(0-1048560)]",
3986 "Label index to associate with the prefix\n"
3987 "Label index value\n")
3989 int idx_label_index
= 3;
3990 if (argc
<= idx_label_index
)
3991 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3992 "label-index", NULL
);
3993 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3994 "label-index", argv
[idx_label_index
]->arg
);
3997 DEFUN (set_aspath_prepend_asn
,
3998 set_aspath_prepend_asn_cmd
,
3999 "set as-path prepend (1-4294967295)...",
4001 "Transform BGP AS_PATH attribute\n"
4002 "Prepend to the as-path\n"
4009 str
= argv_concat(argv
, argc
, idx_asn
);
4010 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4011 "as-path prepend", str
);
4012 XFREE(MTYPE_TMP
, str
);
4017 DEFUN (set_aspath_prepend_lastas
,
4018 set_aspath_prepend_lastas_cmd
,
4019 "set as-path prepend last-as (1-10)",
4021 "Transform BGP AS_PATH attribute\n"
4022 "Prepend to the as-path\n"
4023 "Use the peer's AS-number\n"
4024 "Number of times to insert\n")
4026 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
4029 DEFUN (no_set_aspath_prepend
,
4030 no_set_aspath_prepend_cmd
,
4031 "no set as-path prepend [(1-4294967295)]",
4034 "Transform BGP AS_PATH attribute\n"
4035 "Prepend to the as-path\n"
4042 str
= argv_concat(argv
, argc
, idx_asn
);
4043 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4044 "as-path prepend", str
);
4045 XFREE(MTYPE_TMP
, str
);
4050 DEFUN (set_aspath_exclude
,
4051 set_aspath_exclude_cmd
,
4052 "set as-path exclude (1-4294967295)...",
4054 "Transform BGP AS-path attribute\n"
4055 "Exclude from the as-path\n"
4062 str
= argv_concat(argv
, argc
, idx_asn
);
4063 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4064 "as-path exclude", str
);
4065 XFREE(MTYPE_TMP
, str
);
4069 DEFUN (no_set_aspath_exclude
,
4070 no_set_aspath_exclude_cmd
,
4071 "no set as-path exclude (1-4294967295)...",
4074 "Transform BGP AS_PATH attribute\n"
4075 "Exclude from the as-path\n"
4082 str
= argv_concat(argv
, argc
, idx_asn
);
4083 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4084 "as-path exclude", str
);
4085 XFREE(MTYPE_TMP
, str
);
4090 DEFUN (set_community
,
4092 "set community AA:NN...",
4094 "BGP community attribute\n"
4102 struct community
*com
= NULL
;
4107 b
= buffer_new(1024);
4109 for (i
= idx_aa_nn
; i
< argc
; i
++) {
4110 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
4117 buffer_putc(b
, ' ');
4121 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
4123 buffer_putstr(b
, "internet");
4126 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
4128 buffer_putstr(b
, "local-AS");
4131 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
4132 && strncmp(argv
[i
]->arg
, "no-advertise",
4133 strlen(argv
[i
]->arg
))
4135 buffer_putstr(b
, "no-advertise");
4138 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
4139 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
4141 buffer_putstr(b
, "no-export");
4144 if (strncmp(argv
[i
]->arg
, "graceful-shutdown",
4145 strlen(argv
[i
]->arg
))
4147 buffer_putstr(b
, "graceful-shutdown");
4150 buffer_putstr(b
, argv
[i
]->arg
);
4152 buffer_putc(b
, '\0');
4154 /* Fetch result string then compile it to communities attribute. */
4155 str
= buffer_getstr(b
);
4159 com
= community_str2com(str
);
4160 XFREE(MTYPE_TMP
, str
);
4163 /* Can't compile user input into communities attribute. */
4165 vty_out(vty
, "%% Malformed communities attribute\n");
4166 return CMD_WARNING_CONFIG_FAILED
;
4169 /* Set communites attribute string. */
4170 str
= community_str(com
, false);
4173 argstr
= XCALLOC(MTYPE_TMP
,
4174 strlen(str
) + strlen(" additive") + 1);
4175 strcpy(argstr
, str
);
4176 strcpy(argstr
+ strlen(str
), " additive");
4177 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4178 "community", argstr
);
4179 XFREE(MTYPE_TMP
, argstr
);
4181 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4184 community_free(com
);
4189 DEFUN (set_community_none
,
4190 set_community_none_cmd
,
4191 "set community none",
4193 "BGP community attribute\n"
4194 "No community attribute\n")
4196 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4197 "community", "none");
4200 DEFUN (no_set_community
,
4201 no_set_community_cmd
,
4202 "no set community AA:NN...",
4205 "BGP community attribute\n"
4208 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4213 DEFUN (set_community_delete
,
4214 set_community_delete_cmd
,
4215 "set comm-list <(1-99)|(100-500)|WORD> delete",
4217 "set BGP community list (for deletion)\n"
4218 "Community-list number (standard)\n"
4219 "Community-list number (expanded)\n"
4220 "Community-list name\n"
4221 "Delete matching communities\n")
4223 int idx_comm_list
= 2;
4226 str
= XCALLOC(MTYPE_TMP
,
4227 strlen(argv
[idx_comm_list
]->arg
) + strlen(" delete") + 1);
4228 strcpy(str
, argv
[idx_comm_list
]->arg
);
4229 strcpy(str
+ strlen(argv
[idx_comm_list
]->arg
), " delete");
4231 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
4234 XFREE(MTYPE_TMP
, str
);
4238 DEFUN (no_set_community_delete
,
4239 no_set_community_delete_cmd
,
4240 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
4243 "set BGP community list (for deletion)\n"
4244 "Community-list number (standard)\n"
4245 "Community-list number (expanded)\n"
4246 "Community-list name\n"
4247 "Delete matching communities\n")
4249 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4253 DEFUN (set_lcommunity
,
4255 "set large-community AA:BB:CC...",
4257 "BGP large community attribute\n"
4258 "Large Community number in aa:bb:cc format or additive\n")
4263 str
= argv_concat(argv
, argc
, 2);
4264 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4265 "large-community", str
);
4266 XFREE(MTYPE_TMP
, str
);
4271 DEFUN (set_lcommunity_none
,
4272 set_lcommunity_none_cmd
,
4273 "set large-community none",
4275 "BGP large community attribute\n"
4276 "No large community attribute\n")
4278 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4279 "large-community", "none");
4282 DEFUN (no_set_lcommunity
,
4283 no_set_lcommunity_cmd
,
4284 "no set large-community none",
4287 "BGP large community attribute\n"
4288 "No community attribute\n")
4290 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4291 "large-community", NULL
);
4294 DEFUN (no_set_lcommunity1
,
4295 no_set_lcommunity1_cmd
,
4296 "no set large-community AA:BB:CC...",
4299 "BGP large community attribute\n"
4300 "Large community in AA:BB:CC... format or additive\n")
4302 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4303 "large-community", NULL
);
4306 DEFUN (set_lcommunity_delete
,
4307 set_lcommunity_delete_cmd
,
4308 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4310 "set BGP large community list (for deletion)\n"
4311 "Large Community-list number (standard)\n"
4312 "Large Communitly-list number (expanded)\n"
4313 "Large Community-list name\n"
4314 "Delete matching large communities\n")
4318 str
= XCALLOC(MTYPE_TMP
, strlen(argv
[2]->arg
) + strlen(" delete") + 1);
4319 strcpy(str
, argv
[2]->arg
);
4320 strcpy(str
+ strlen(argv
[2]->arg
), " delete");
4322 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4323 "large-comm-list", str
);
4325 XFREE(MTYPE_TMP
, str
);
4329 DEFUN (no_set_lcommunity_delete
,
4330 no_set_lcommunity_delete_cmd
,
4331 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4334 "set BGP large community list (for deletion)\n"
4335 "Large Community-list number (standard)\n"
4336 "Large Communitly-list number (expanded)\n"
4337 "Large Community-list name\n"
4338 "Delete matching large communities\n")
4340 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4341 "large-comm-list", NULL
);
4344 DEFUN (set_ecommunity_rt
,
4345 set_ecommunity_rt_cmd
,
4346 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4348 "BGP extended community attribute\n"
4349 "Route Target extended community\n"
4350 "VPN extended community\n")
4356 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4357 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4358 "extcommunity rt", str
);
4359 XFREE(MTYPE_TMP
, str
);
4364 DEFUN (no_set_ecommunity_rt
,
4365 no_set_ecommunity_rt_cmd
,
4366 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4369 "BGP extended community attribute\n"
4370 "Route Target extended community\n"
4371 "VPN extended community\n")
4373 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4374 "extcommunity rt", NULL
);
4378 DEFUN (set_ecommunity_soo
,
4379 set_ecommunity_soo_cmd
,
4380 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4382 "BGP extended community attribute\n"
4383 "Site-of-Origin extended community\n"
4384 "VPN extended community\n")
4390 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4391 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4392 "extcommunity soo", str
);
4393 XFREE(MTYPE_TMP
, str
);
4398 DEFUN (no_set_ecommunity_soo
,
4399 no_set_ecommunity_soo_cmd
,
4400 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4403 "BGP extended community attribute\n"
4404 "Site-of-Origin extended community\n"
4405 "VPN extended community\n")
4407 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4408 "extcommunity soo", NULL
);
4414 "set origin <egp|igp|incomplete>",
4419 "unknown heritage\n")
4422 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4423 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4425 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4426 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4428 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4429 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4430 "origin", "incomplete");
4432 vty_out(vty
, "%% Invalid set origin type\n");
4433 return CMD_WARNING_CONFIG_FAILED
;
4437 DEFUN (no_set_origin
,
4439 "no set origin [<egp|igp|incomplete>]",
4445 "unknown heritage\n")
4447 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4452 DEFUN (set_atomic_aggregate
,
4453 set_atomic_aggregate_cmd
,
4454 "set atomic-aggregate",
4456 "BGP atomic aggregate attribute\n" )
4458 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4459 "atomic-aggregate", NULL
);
4462 DEFUN (no_set_atomic_aggregate
,
4463 no_set_atomic_aggregate_cmd
,
4464 "no set atomic-aggregate",
4467 "BGP atomic aggregate attribute\n" )
4469 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4470 "atomic-aggregate", NULL
);
4473 DEFUN (set_aggregator_as
,
4474 set_aggregator_as_cmd
,
4475 "set aggregator as (1-4294967295) A.B.C.D",
4477 "BGP aggregator attribute\n"
4478 "AS number of aggregator\n"
4480 "IP address of aggregator\n")
4485 struct in_addr address
;
4488 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4490 vty_out(vty
, "Aggregator IP address is invalid\n");
4491 return CMD_WARNING_CONFIG_FAILED
;
4494 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4495 strlen(argv
[idx_number
]->arg
)
4496 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4498 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4500 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4501 "aggregator as", argstr
);
4503 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4509 DEFUN (no_set_aggregator_as
,
4510 no_set_aggregator_as_cmd
,
4511 "no set aggregator as [(1-4294967295) A.B.C.D]",
4514 "BGP aggregator attribute\n"
4515 "AS number of aggregator\n"
4517 "IP address of aggregator\n")
4522 struct in_addr address
;
4525 if (argc
<= idx_asn
)
4526 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4527 "aggregator as", NULL
);
4529 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4531 vty_out(vty
, "Aggregator IP address is invalid\n");
4532 return CMD_WARNING_CONFIG_FAILED
;
4535 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4536 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4539 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4541 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4542 "aggregator as", argstr
);
4544 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4549 DEFUN (match_ipv6_next_hop
,
4550 match_ipv6_next_hop_cmd
,
4551 "match ipv6 next-hop X:X::X:X",
4554 "Match IPv6 next-hop address of route\n"
4555 "IPv6 address of next hop\n")
4558 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4559 RMAP_EVENT_MATCH_ADDED
);
4562 DEFUN (no_match_ipv6_next_hop
,
4563 no_match_ipv6_next_hop_cmd
,
4564 "no match ipv6 next-hop X:X::X:X",
4568 "Match IPv6 next-hop address of route\n"
4569 "IPv6 address of next hop\n")
4572 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4573 RMAP_EVENT_MATCH_DELETED
);
4577 DEFUN (set_ipv6_nexthop_peer
,
4578 set_ipv6_nexthop_peer_cmd
,
4579 "set ipv6 next-hop peer-address",
4582 "Next hop address\n"
4583 "Use peer address (for BGP only)\n")
4585 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4586 "ipv6 next-hop peer-address", NULL
);
4589 DEFUN (no_set_ipv6_nexthop_peer
,
4590 no_set_ipv6_nexthop_peer_cmd
,
4591 "no set ipv6 next-hop peer-address",
4595 "IPv6 next-hop address\n"
4596 "Use peer address (for BGP only)\n")
4598 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4599 "ipv6 next-hop peer-address", NULL
);
4602 DEFUN (set_ipv6_nexthop_prefer_global
,
4603 set_ipv6_nexthop_prefer_global_cmd
,
4604 "set ipv6 next-hop prefer-global",
4607 "IPv6 next-hop address\n"
4608 "Prefer global over link-local if both exist\n")
4610 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4611 "ipv6 next-hop prefer-global", NULL
);
4615 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4616 no_set_ipv6_nexthop_prefer_global_cmd
,
4617 "no set ipv6 next-hop prefer-global",
4621 "IPv6 next-hop address\n"
4622 "Prefer global over link-local if both exist\n")
4624 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4625 "ipv6 next-hop prefer-global", NULL
);
4628 DEFUN (set_ipv6_nexthop_global
,
4629 set_ipv6_nexthop_global_cmd
,
4630 "set ipv6 next-hop global X:X::X:X",
4633 "IPv6 next-hop address\n"
4634 "IPv6 global address\n"
4635 "IPv6 address of next hop\n")
4638 struct in6_addr addr
;
4641 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4643 vty_out(vty
, "%% Malformed nexthop address\n");
4644 return CMD_WARNING_CONFIG_FAILED
;
4646 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4647 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4648 vty_out(vty
, "%% Invalid global nexthop address\n");
4649 return CMD_WARNING_CONFIG_FAILED
;
4652 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4653 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4657 DEFUN (no_set_ipv6_nexthop_global
,
4658 no_set_ipv6_nexthop_global_cmd
,
4659 "no set ipv6 next-hop global X:X::X:X",
4663 "IPv6 next-hop address\n"
4664 "IPv6 global address\n"
4665 "IPv6 address of next hop\n")
4668 if (argc
<= idx_ipv6
)
4669 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4670 "ipv6 next-hop global", NULL
);
4671 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4672 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4675 #ifdef KEEP_OLD_VPN_COMMANDS
4676 DEFUN (set_vpn_nexthop
,
4677 set_vpn_nexthop_cmd
,
4678 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4680 "VPNv4 information\n"
4681 "VPN next-hop address\n"
4682 "IP address of next hop\n"
4683 "VPNv6 information\n"
4684 "VPN next-hop address\n"
4685 "IPv6 address of next hop\n")
4691 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4693 return generic_set_add(
4694 vty
, VTY_GET_CONTEXT(route_map_index
),
4695 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4697 return generic_set_add(
4698 vty
, VTY_GET_CONTEXT(route_map_index
),
4699 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4704 DEFUN (no_set_vpn_nexthop
,
4705 no_set_vpn_nexthop_cmd
,
4706 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4709 "VPNv4 information\n"
4710 "VPN next-hop address\n"
4711 "IP address of next hop\n"
4712 "VPNv6 information\n"
4713 "VPN next-hop address\n"
4714 "IPv6 address of next hop\n")
4724 arg
= argv
[idx_ip
]->arg
;
4725 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4727 return generic_set_delete(
4728 vty
, VTY_GET_CONTEXT(route_map_index
),
4729 "ipv4 vpn next-hop", arg
);
4731 return generic_set_delete(
4732 vty
, VTY_GET_CONTEXT(route_map_index
),
4733 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4737 #endif /* KEEP_OLD_VPN_COMMANDS */
4739 DEFUN (set_ipx_vpn_nexthop
,
4740 set_ipx_vpn_nexthop_cmd
,
4741 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4743 "IPv4 information\n"
4744 "IPv6 information\n"
4746 "VPN next-hop address\n"
4747 "IP address of next hop\n"
4748 "IPv6 address of next hop\n")
4754 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4756 return generic_set_add(
4757 vty
, VTY_GET_CONTEXT(route_map_index
),
4758 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4760 return generic_set_add(
4761 vty
, VTY_GET_CONTEXT(route_map_index
),
4762 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4767 DEFUN (no_set_ipx_vpn_nexthop
,
4768 no_set_ipx_vpn_nexthop_cmd
,
4769 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4772 "IPv4 information\n"
4773 "IPv6 information\n"
4775 "VPN next-hop address\n"
4776 "IP address of next hop\n"
4777 "IPv6 address of next hop\n")
4787 arg
= argv
[idx_ip
]->arg
;
4788 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4790 return generic_set_delete(
4791 vty
, VTY_GET_CONTEXT(route_map_index
),
4792 "ipv4 vpn next-hop", arg
);
4794 return generic_set_delete(
4795 vty
, VTY_GET_CONTEXT(route_map_index
),
4796 "ipv6 vpn next-hop", arg
);
4801 DEFUN (set_originator_id
,
4802 set_originator_id_cmd
,
4803 "set originator-id A.B.C.D",
4805 "BGP originator ID attribute\n"
4806 "IP address of originator\n")
4809 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4810 "originator-id", argv
[idx_ipv4
]->arg
);
4814 DEFUN (no_set_originator_id
,
4815 no_set_originator_id_cmd
,
4816 "no set originator-id [A.B.C.D]",
4819 "BGP originator ID attribute\n"
4820 "IP address of originator\n")
4824 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4826 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4827 "originator-id", arg
);
4831 /* Initialization of route map. */
4832 void bgp_route_map_init(void)
4836 route_map_add_hook(bgp_route_map_add
);
4837 route_map_delete_hook(bgp_route_map_delete
);
4838 route_map_event_hook(bgp_route_map_event
);
4840 route_map_match_interface_hook(generic_match_add
);
4841 route_map_no_match_interface_hook(generic_match_delete
);
4843 route_map_match_ip_address_hook(generic_match_add
);
4844 route_map_no_match_ip_address_hook(generic_match_delete
);
4846 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
4847 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
4849 route_map_match_ip_next_hop_hook(generic_match_add
);
4850 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
4852 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
4853 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
4855 route_map_match_ip_next_hop_type_hook(generic_match_add
);
4856 route_map_no_match_ip_next_hop_type_hook(generic_match_delete
);
4858 route_map_match_ipv6_address_hook(generic_match_add
);
4859 route_map_no_match_ipv6_address_hook(generic_match_delete
);
4861 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
4862 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
4864 route_map_match_ipv6_next_hop_type_hook(generic_match_add
);
4865 route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete
);
4867 route_map_match_metric_hook(generic_match_add
);
4868 route_map_no_match_metric_hook(generic_match_delete
);
4870 route_map_match_tag_hook(generic_match_add
);
4871 route_map_no_match_tag_hook(generic_match_delete
);
4873 route_map_set_ip_nexthop_hook(generic_set_add
);
4874 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
4876 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
4877 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
4879 route_map_set_metric_hook(generic_set_add
);
4880 route_map_no_set_metric_hook(generic_set_delete
);
4882 route_map_set_tag_hook(generic_set_add
);
4883 route_map_no_set_tag_hook(generic_set_delete
);
4885 route_map_install_match(&route_match_peer_cmd
);
4886 route_map_install_match(&route_match_local_pref_cmd
);
4887 #if defined(HAVE_LUA)
4888 route_map_install_match(&route_match_command_cmd
);
4890 route_map_install_match(&route_match_ip_address_cmd
);
4891 route_map_install_match(&route_match_ip_next_hop_cmd
);
4892 route_map_install_match(&route_match_ip_route_source_cmd
);
4893 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
4894 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
4895 route_map_install_match(&route_match_ip_next_hop_type_cmd
);
4896 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
4897 route_map_install_match(&route_match_aspath_cmd
);
4898 route_map_install_match(&route_match_community_cmd
);
4899 route_map_install_match(&route_match_lcommunity_cmd
);
4900 route_map_install_match(&route_match_ecommunity_cmd
);
4901 route_map_install_match(&route_match_local_pref_cmd
);
4902 route_map_install_match(&route_match_metric_cmd
);
4903 route_map_install_match(&route_match_origin_cmd
);
4904 route_map_install_match(&route_match_probability_cmd
);
4905 route_map_install_match(&route_match_interface_cmd
);
4906 route_map_install_match(&route_match_tag_cmd
);
4907 route_map_install_match(&route_match_mac_address_cmd
);
4908 route_map_install_match(&route_match_evpn_vni_cmd
);
4909 route_map_install_match(&route_match_evpn_route_type_cmd
);
4910 route_map_install_match(&route_match_evpn_default_route_cmd
);
4912 route_map_install_set(&route_set_ip_nexthop_cmd
);
4913 route_map_install_set(&route_set_local_pref_cmd
);
4914 route_map_install_set(&route_set_weight_cmd
);
4915 route_map_install_set(&route_set_label_index_cmd
);
4916 route_map_install_set(&route_set_metric_cmd
);
4917 route_map_install_set(&route_set_aspath_prepend_cmd
);
4918 route_map_install_set(&route_set_aspath_exclude_cmd
);
4919 route_map_install_set(&route_set_origin_cmd
);
4920 route_map_install_set(&route_set_atomic_aggregate_cmd
);
4921 route_map_install_set(&route_set_aggregator_as_cmd
);
4922 route_map_install_set(&route_set_community_cmd
);
4923 route_map_install_set(&route_set_community_delete_cmd
);
4924 route_map_install_set(&route_set_lcommunity_cmd
);
4925 route_map_install_set(&route_set_lcommunity_delete_cmd
);
4926 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
4927 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
4928 route_map_install_set(&route_set_originator_id_cmd
);
4929 route_map_install_set(&route_set_ecommunity_rt_cmd
);
4930 route_map_install_set(&route_set_ecommunity_soo_cmd
);
4931 route_map_install_set(&route_set_tag_cmd
);
4932 route_map_install_set(&route_set_label_index_cmd
);
4934 install_element(RMAP_NODE
, &match_peer_cmd
);
4935 install_element(RMAP_NODE
, &match_peer_local_cmd
);
4936 install_element(RMAP_NODE
, &no_match_peer_cmd
);
4937 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
4938 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
4939 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
4940 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
4941 install_element(RMAP_NODE
, &match_mac_address_cmd
);
4942 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
4943 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
4944 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
4945 install_element(RMAP_NODE
, &match_evpn_route_type_cmd
);
4946 install_element(RMAP_NODE
, &no_match_evpn_route_type_cmd
);
4947 install_element(RMAP_NODE
, &match_evpn_default_route_cmd
);
4948 install_element(RMAP_NODE
, &no_match_evpn_default_route_cmd
);
4950 install_element(RMAP_NODE
, &match_aspath_cmd
);
4951 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
4952 install_element(RMAP_NODE
, &match_local_pref_cmd
);
4953 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
4954 install_element(RMAP_NODE
, &match_community_cmd
);
4955 install_element(RMAP_NODE
, &no_match_community_cmd
);
4956 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
4957 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
4958 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
4959 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
4960 install_element(RMAP_NODE
, &match_origin_cmd
);
4961 install_element(RMAP_NODE
, &no_match_origin_cmd
);
4962 install_element(RMAP_NODE
, &match_probability_cmd
);
4963 install_element(RMAP_NODE
, &no_match_probability_cmd
);
4965 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
4966 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
4967 install_element(RMAP_NODE
, &set_local_pref_cmd
);
4968 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
4969 install_element(RMAP_NODE
, &set_weight_cmd
);
4970 install_element(RMAP_NODE
, &set_label_index_cmd
);
4971 install_element(RMAP_NODE
, &no_set_weight_cmd
);
4972 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
4973 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
4974 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
4975 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
4976 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
4977 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
4978 install_element(RMAP_NODE
, &set_origin_cmd
);
4979 install_element(RMAP_NODE
, &no_set_origin_cmd
);
4980 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
4981 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
4982 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
4983 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
4984 install_element(RMAP_NODE
, &set_community_cmd
);
4985 install_element(RMAP_NODE
, &set_community_none_cmd
);
4986 install_element(RMAP_NODE
, &no_set_community_cmd
);
4987 install_element(RMAP_NODE
, &set_community_delete_cmd
);
4988 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
4989 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
4990 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
4991 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
4992 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
4993 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
4994 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
4995 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
4996 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
4997 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
4998 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
4999 #ifdef KEEP_OLD_VPN_COMMANDS
5000 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
5001 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
5002 #endif /* KEEP_OLD_VPN_COMMANDS */
5003 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
5004 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
5005 install_element(RMAP_NODE
, &set_originator_id_cmd
);
5006 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
5008 route_map_install_match(&route_match_ipv6_address_cmd
);
5009 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
5010 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
5011 route_map_install_match(&route_match_ipv6_next_hop_type_cmd
);
5012 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
5013 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
5014 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
5015 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
5017 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
5018 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
5019 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
5020 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
5021 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
5022 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
5023 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
5024 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
5025 #if defined(HAVE_LUA)
5026 install_element(RMAP_NODE
, &match_command_cmd
);
5027 install_element(RMAP_NODE
, &no_match_command_cmd
);
5031 void bgp_route_map_terminate(void)
5033 /* ToDo: Cleanup all the used memory */