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
31 #ifdef HAVE_LIBPCREPOSIX
32 #include <pcreposix.h>
35 #endif /* HAVE_LIBPCREPOSIX */
37 #include "sockunion.h"
41 #include "bgpd/bgpd.h"
42 #include "bgpd/bgp_table.h"
43 #include "bgpd/bgp_attr.h"
44 #include "bgpd/bgp_aspath.h"
45 #include "bgpd/bgp_packet.h"
46 #include "bgpd/bgp_route.h"
47 #include "bgpd/bgp_zebra.h"
48 #include "bgpd/bgp_regex.h"
49 #include "bgpd/bgp_community.h"
50 #include "bgpd/bgp_clist.h"
51 #include "bgpd/bgp_filter.h"
52 #include "bgpd/bgp_mplsvpn.h"
53 #include "bgpd/bgp_ecommunity.h"
54 #include "bgpd/bgp_lcommunity.h"
55 #include "bgpd/bgp_vty.h"
56 #include "bgpd/bgp_debug.h"
57 #include "bgpd/bgp_evpn.h"
58 #include "bgpd/bgp_evpn_private.h"
59 #include "bgpd/bgp_evpn_vty.h"
62 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
65 /* Memo of route-map commands.
74 ip route-source : Done
78 ipv6 route-source: (This will not be implemented by bgpd)
79 ipv6 prefix-list : Done
80 length : (This will not be implemented by bgpd)
82 route-type : (This will not be implemented by bgpd)
84 local-preference : Done
86 set as-path prepend : Done
88 automatic-tag : (This will not be implemented by bgpd)
90 large-community : Done
91 large-comm-list : Done
94 default : (This will not be implemented by bgpd)
95 interface : (This will not be implemented by bgpd)
96 ip default : (This will not be implemented by bgpd)
98 ip precedence : (This will not be implemented by bgpd)
99 ip tos : (This will not be implemented by bgpd)
100 level : (This will not be implemented by bgpd)
101 local-preference : Done
103 metric-type : Not yet
110 set ipv6 next-hop global: Done
111 set ipv6 next-hop prefer-global: Done
112 set ipv6 next-hop local : Done
113 set as-path exclude : Done
117 /* generic value manipulation to be shared in multiple rules */
119 #define RMAP_VALUE_SET 0
120 #define RMAP_VALUE_ADD 1
121 #define RMAP_VALUE_SUB 2
129 static int route_value_match(struct rmap_value
*rv
, u_int32_t value
)
131 if (rv
->variable
== 0 && value
== rv
->value
)
137 static u_int32_t
route_value_adjust(struct rmap_value
*rv
, u_int32_t current
,
142 switch (rv
->variable
) {
151 switch (rv
->action
) {
153 if (current
> UINT32_MAX
- value
)
155 return current
+ value
;
157 if (current
<= value
)
159 return current
- value
;
165 static void *route_value_compile(const char *arg
)
167 u_int8_t action
= RMAP_VALUE_SET
, var
= 0;
168 unsigned long larg
= 0;
170 struct rmap_value
*rv
;
173 action
= RMAP_VALUE_ADD
;
175 } else if (arg
[0] == '-') {
176 action
= RMAP_VALUE_SUB
;
180 if (all_digit(arg
)) {
182 larg
= strtoul(arg
, &endptr
, 10);
183 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
186 if (strcmp(arg
, "rtt") == 0)
192 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
202 static void route_value_free(void *rule
)
204 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
207 /* generic as path object to be shared in multiple rules */
209 static void *route_aspath_compile(const char *arg
)
211 struct aspath
*aspath
;
213 aspath
= aspath_str2aspath(arg
);
219 static void route_aspath_free(void *rule
)
221 struct aspath
*aspath
= rule
;
225 /* 'match peer (A.B.C.D|X:X::X:X)' */
227 /* Compares the peer specified in the 'match peer' clause with the peer
228 received in bgp_info->peer. If it is the same, or if the peer structure
229 received is a peer_group containing it, returns RMAP_MATCH. */
230 static route_map_result_t
route_match_peer(void *rule
, struct prefix
*prefix
,
231 route_map_object_t type
,
235 union sockunion su_def
= {
236 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
237 struct peer_group
*group
;
239 struct listnode
*node
, *nnode
;
241 if (type
== RMAP_BGP
) {
243 peer
= ((struct bgp_info
*)object
)->peer
;
245 if (!CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)
246 && !CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_EXPORT
))
249 /* If su='0.0.0.0' (command 'match peer local'), and it's a
251 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH
253 if (sockunion_same(su
, &su_def
)) {
255 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
256 || CHECK_FLAG(peer
->rmap_type
,
257 PEER_RMAP_TYPE_REDISTRIBUTE
)
258 || CHECK_FLAG(peer
->rmap_type
,
259 PEER_RMAP_TYPE_DEFAULT
))
266 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
267 if (sockunion_same(su
, &peer
->su
))
273 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
275 if (sockunion_same(su
, &peer
->su
))
284 static void *route_match_peer_compile(const char *arg
)
289 su
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(union sockunion
));
291 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", su
);
293 XFREE(MTYPE_ROUTE_MAP_COMPILED
, su
);
300 /* Free route map's compiled `ip address' value. */
301 static void route_match_peer_free(void *rule
)
303 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
306 /* Route map commands for ip address matching. */
307 struct route_map_rule_cmd route_match_peer_cmd
= {"peer", route_match_peer
,
308 route_match_peer_compile
,
309 route_match_peer_free
};
311 /* `match ip address IP_ACCESS_LIST' */
313 /* Match function should return 1 if match is success else return
315 static route_map_result_t
route_match_ip_address(void *rule
,
316 struct prefix
*prefix
,
317 route_map_object_t type
,
320 struct access_list
*alist
;
321 /* struct prefix_ipv4 match; */
323 if (type
== RMAP_BGP
) {
324 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
328 return (access_list_apply(alist
, prefix
) == FILTER_DENY
335 /* Route map `ip address' match statement. `arg' should be
337 static void *route_match_ip_address_compile(const char *arg
)
339 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
342 /* Free route map's compiled `ip address' value. */
343 static void route_match_ip_address_free(void *rule
)
345 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
348 /* Route map commands for ip address matching. */
349 struct route_map_rule_cmd route_match_ip_address_cmd
= {
350 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
351 route_match_ip_address_free
};
353 /* `match ip next-hop IP_ADDRESS' */
355 /* Match function return 1 if match is success else return zero. */
356 static route_map_result_t
route_match_ip_next_hop(void *rule
,
357 struct prefix
*prefix
,
358 route_map_object_t type
,
361 struct access_list
*alist
;
362 struct bgp_info
*bgp_info
;
363 struct prefix_ipv4 p
;
365 if (type
== RMAP_BGP
) {
368 p
.prefix
= bgp_info
->attr
->nexthop
;
369 p
.prefixlen
= IPV4_MAX_BITLEN
;
371 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
375 return (access_list_apply(alist
, &p
) == FILTER_DENY
382 /* Route map `ip next-hop' match statement. `arg' is
384 static void *route_match_ip_next_hop_compile(const char *arg
)
386 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
389 /* Free route map's compiled `ip address' value. */
390 static void route_match_ip_next_hop_free(void *rule
)
392 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
395 /* Route map commands for ip next-hop matching. */
396 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
397 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
398 route_match_ip_next_hop_free
};
400 /* `match ip route-source ACCESS-LIST' */
402 /* Match function return 1 if match is success else return zero. */
403 static route_map_result_t
route_match_ip_route_source(void *rule
,
404 struct prefix
*prefix
,
405 route_map_object_t type
,
408 struct access_list
*alist
;
409 struct bgp_info
*bgp_info
;
411 struct prefix_ipv4 p
;
413 if (type
== RMAP_BGP
) {
415 peer
= bgp_info
->peer
;
417 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
421 p
.prefix
= peer
->su
.sin
.sin_addr
;
422 p
.prefixlen
= IPV4_MAX_BITLEN
;
424 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
428 return (access_list_apply(alist
, &p
) == FILTER_DENY
435 /* Route map `ip route-source' match statement. `arg' is
437 static void *route_match_ip_route_source_compile(const char *arg
)
439 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
442 /* Free route map's compiled `ip address' value. */
443 static void route_match_ip_route_source_free(void *rule
)
445 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
448 /* Route map commands for ip route-source matching. */
449 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
450 "ip route-source", route_match_ip_route_source
,
451 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
453 /* `match ip address prefix-list PREFIX_LIST' */
455 static route_map_result_t
456 route_match_ip_address_prefix_list(void *rule
, struct prefix
*prefix
,
457 route_map_object_t type
, void *object
)
459 struct prefix_list
*plist
;
461 if (type
== RMAP_BGP
) {
462 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
466 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
473 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
475 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
478 static void route_match_ip_address_prefix_list_free(void *rule
)
480 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
483 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
484 "ip address prefix-list", route_match_ip_address_prefix_list
,
485 route_match_ip_address_prefix_list_compile
,
486 route_match_ip_address_prefix_list_free
};
488 /* `match ip next-hop prefix-list PREFIX_LIST' */
490 static route_map_result_t
491 route_match_ip_next_hop_prefix_list(void *rule
, struct prefix
*prefix
,
492 route_map_object_t type
, void *object
)
494 struct prefix_list
*plist
;
495 struct bgp_info
*bgp_info
;
496 struct prefix_ipv4 p
;
498 if (type
== RMAP_BGP
) {
501 p
.prefix
= bgp_info
->attr
->nexthop
;
502 p
.prefixlen
= IPV4_MAX_BITLEN
;
504 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
508 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
515 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
517 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
520 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
522 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
525 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
526 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
527 route_match_ip_next_hop_prefix_list_compile
,
528 route_match_ip_next_hop_prefix_list_free
};
530 /* `match ip route-source prefix-list PREFIX_LIST' */
532 static route_map_result_t
533 route_match_ip_route_source_prefix_list(void *rule
, struct prefix
*prefix
,
534 route_map_object_t type
, void *object
)
536 struct prefix_list
*plist
;
537 struct bgp_info
*bgp_info
;
539 struct prefix_ipv4 p
;
541 if (type
== RMAP_BGP
) {
543 peer
= bgp_info
->peer
;
545 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
549 p
.prefix
= peer
->su
.sin
.sin_addr
;
550 p
.prefixlen
= IPV4_MAX_BITLEN
;
552 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
556 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
563 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
565 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
568 static void route_match_ip_route_source_prefix_list_free(void *rule
)
570 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
573 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
574 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
575 route_match_ip_route_source_prefix_list_compile
,
576 route_match_ip_route_source_prefix_list_free
};
578 /* `match mac address MAC_ACCESS_LIST' */
580 /* Match function should return 1 if match is success else return
582 static route_map_result_t
route_match_mac_address(void *rule
,
583 struct prefix
*prefix
,
584 route_map_object_t type
,
587 struct access_list
*alist
;
590 if (type
== RMAP_BGP
) {
591 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
595 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
598 p
.family
= AF_ETHERNET
;
599 p
.prefixlen
= ETH_ALEN
* 8;
600 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.mac
;
602 return (access_list_apply(alist
, &p
)
611 /* Route map `mac address' match statement. `arg' should be
613 static void *route_match_mac_address_compile(const char *arg
)
615 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
618 /* Free route map's compiled `ip address' value. */
619 static void route_match_mac_address_free(void *rule
)
621 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
624 /* Route map commands for mac address matching. */
625 struct route_map_rule_cmd route_match_mac_address_cmd
= {
626 "mac address", route_match_mac_address
, route_match_mac_address_compile
,
627 route_match_mac_address_free
};
631 /* Match function should return 1 if match is success else return
633 static route_map_result_t
route_match_vni(void *rule
, struct prefix
*prefix
,
634 route_map_object_t type
, void *object
)
637 struct bgp_info
*bgp_info
= NULL
;
639 if (type
== RMAP_BGP
) {
640 vni
= *((vni_t
*)rule
);
641 bgp_info
= (struct bgp_info
*)object
;
643 if (vni
== label2vni(&bgp_info
->extra
->label
))
650 /* Route map `vni' match statement. */
651 static void *route_match_vni_compile(const char *arg
)
656 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
660 *vni
= strtoul(arg
, &end
, 10);
667 /* Free route map's compiled `vni' value. */
668 static void route_match_vni_free(void *rule
)
670 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
673 /* Route map commands for vni matching. */
674 struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
675 "evpn vni", route_match_vni
, route_match_vni_compile
,
676 route_match_vni_free
};
678 /* `match local-preference LOCAL-PREF' */
680 /* Match function return 1 if match is success else return zero. */
681 static route_map_result_t
route_match_local_pref(void *rule
,
682 struct prefix
*prefix
,
683 route_map_object_t type
,
686 u_int32_t
*local_pref
;
687 struct bgp_info
*bgp_info
;
689 if (type
== RMAP_BGP
) {
693 if (bgp_info
->attr
->local_pref
== *local_pref
)
701 /* Route map `match local-preference' match statement.
702 `arg' is local-pref value */
703 static void *route_match_local_pref_compile(const char *arg
)
705 u_int32_t
*local_pref
;
707 unsigned long tmpval
;
709 /* Locpref value shoud be integer. */
714 tmpval
= strtoul(arg
, &endptr
, 10);
715 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
718 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(u_int32_t
));
723 *local_pref
= tmpval
;
727 /* Free route map's compiled `match local-preference' value. */
728 static void route_match_local_pref_free(void *rule
)
730 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
733 /* Route map commands for metric matching. */
734 struct route_map_rule_cmd route_match_local_pref_cmd
= {
735 "local-preference", route_match_local_pref
,
736 route_match_local_pref_compile
, route_match_local_pref_free
};
738 /* `match metric METRIC' */
740 /* Match function return 1 if match is success else return zero. */
741 static route_map_result_t
route_match_metric(void *rule
, struct prefix
*prefix
,
742 route_map_object_t type
,
745 struct rmap_value
*rv
;
746 struct bgp_info
*bgp_info
;
748 if (type
== RMAP_BGP
) {
751 return route_value_match(rv
, bgp_info
->attr
->med
);
756 /* Route map commands for metric matching. */
757 struct route_map_rule_cmd route_match_metric_cmd
= {
758 "metric", route_match_metric
, route_value_compile
, route_value_free
,
761 /* `match as-path ASPATH' */
763 /* Match function for as-path match. I assume given object is */
764 static route_map_result_t
route_match_aspath(void *rule
, struct prefix
*prefix
,
765 route_map_object_t type
,
769 struct as_list
*as_list
;
770 struct bgp_info
*bgp_info
;
772 if (type
== RMAP_BGP
) {
773 as_list
= as_list_lookup((char *)rule
);
780 return ((as_list_apply(as_list
, bgp_info
->attr
->aspath
)
788 /* Compile function for as-path match. */
789 static void *route_match_aspath_compile(const char *arg
)
791 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
794 /* Compile function for as-path match. */
795 static void route_match_aspath_free(void *rule
)
797 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
800 /* Route map commands for aspath matching. */
801 struct route_map_rule_cmd route_match_aspath_cmd
= {
802 "as-path", route_match_aspath
, route_match_aspath_compile
,
803 route_match_aspath_free
};
805 /* `match community COMMUNIY' */
806 struct rmap_community
{
811 /* Match function for community match. */
812 static route_map_result_t
route_match_community(void *rule
,
813 struct prefix
*prefix
,
814 route_map_object_t type
,
817 struct community_list
*list
;
818 struct bgp_info
*bgp_info
;
819 struct rmap_community
*rcom
;
821 if (type
== RMAP_BGP
) {
825 list
= community_list_lookup(bgp_clist
, rcom
->name
,
826 COMMUNITY_LIST_MASTER
);
831 if (community_list_exact_match(
832 bgp_info
->attr
->community
, list
))
835 if (community_list_match(bgp_info
->attr
->community
,
843 /* Compile function for community match. */
844 static void *route_match_community_compile(const char *arg
)
846 struct rmap_community
*rcom
;
850 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
852 p
= strchr(arg
, ' ');
855 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
856 memcpy(rcom
->name
, arg
, len
);
859 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
865 /* Compile function for community match. */
866 static void route_match_community_free(void *rule
)
868 struct rmap_community
*rcom
= rule
;
870 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
871 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
874 /* Route map commands for community matching. */
875 struct route_map_rule_cmd route_match_community_cmd
= {
876 "community", route_match_community
, route_match_community_compile
,
877 route_match_community_free
};
879 /* Match function for lcommunity match. */
880 static route_map_result_t
route_match_lcommunity(void *rule
,
881 struct prefix
*prefix
,
882 route_map_object_t type
,
885 struct community_list
*list
;
886 struct bgp_info
*bgp_info
;
887 struct rmap_community
*rcom
;
889 if (type
== RMAP_BGP
) {
893 list
= community_list_lookup(bgp_clist
, rcom
->name
,
894 LARGE_COMMUNITY_LIST_MASTER
);
898 if (lcommunity_list_match(bgp_info
->attr
->lcommunity
, list
))
904 /* Compile function for community match. */
905 static void *route_match_lcommunity_compile(const char *arg
)
907 struct rmap_community
*rcom
;
911 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
913 p
= strchr(arg
, ' ');
916 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
917 memcpy(rcom
->name
, arg
, len
);
919 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
925 /* Compile function for community match. */
926 static void route_match_lcommunity_free(void *rule
)
928 struct rmap_community
*rcom
= rule
;
930 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
931 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
934 /* Route map commands for community matching. */
935 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
936 "large-community", route_match_lcommunity
,
937 route_match_lcommunity_compile
, route_match_lcommunity_free
};
940 /* Match function for extcommunity match. */
941 static route_map_result_t
route_match_ecommunity(void *rule
,
942 struct prefix
*prefix
,
943 route_map_object_t type
,
946 struct community_list
*list
;
947 struct bgp_info
*bgp_info
;
949 if (type
== RMAP_BGP
) {
952 list
= community_list_lookup(bgp_clist
, (char *)rule
,
953 EXTCOMMUNITY_LIST_MASTER
);
957 if (ecommunity_list_match(bgp_info
->attr
->ecommunity
, list
))
963 /* Compile function for extcommunity match. */
964 static void *route_match_ecommunity_compile(const char *arg
)
966 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
969 /* Compile function for extcommunity match. */
970 static void route_match_ecommunity_free(void *rule
)
972 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
975 /* Route map commands for community matching. */
976 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
977 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
978 route_match_ecommunity_free
};
980 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
981 and `address-family vpnv4'. */
984 static route_map_result_t
route_match_origin(void *rule
, struct prefix
*prefix
,
985 route_map_object_t type
,
989 struct bgp_info
*bgp_info
;
991 if (type
== RMAP_BGP
) {
995 if (bgp_info
->attr
->origin
== *origin
)
1002 static void *route_match_origin_compile(const char *arg
)
1006 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(u_char
));
1008 if (strcmp(arg
, "igp") == 0)
1010 else if (strcmp(arg
, "egp") == 0)
1018 /* Free route map's compiled `ip address' value. */
1019 static void route_match_origin_free(void *rule
)
1021 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1024 /* Route map commands for origin matching. */
1025 struct route_map_rule_cmd route_match_origin_cmd
= {
1026 "origin", route_match_origin
, route_match_origin_compile
,
1027 route_match_origin_free
};
1029 /* match probability { */
1031 static route_map_result_t
route_match_probability(void *rule
,
1032 struct prefix
*prefix
,
1033 route_map_object_t type
,
1038 switch (*(long *)rule
) {
1044 if (r
< *(long *)rule
) {
1049 return RMAP_NOMATCH
;
1052 static void *route_match_probability_compile(const char *arg
)
1058 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1068 *lobule
= RAND_MAX
/ 100 * perc
;
1074 static void route_match_probability_free(void *rule
)
1076 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1079 struct route_map_rule_cmd route_match_probability_cmd
= {
1080 "probability", route_match_probability
, route_match_probability_compile
,
1081 route_match_probability_free
};
1083 /* `match interface IFNAME' */
1084 /* Match function should return 1 if match is success else return
1086 static route_map_result_t
route_match_interface(void *rule
,
1087 struct prefix
*prefix
,
1088 route_map_object_t type
,
1091 struct interface
*ifp
;
1092 struct bgp_info
*info
;
1094 if (type
== RMAP_BGP
) {
1097 if (!info
|| !info
->attr
)
1098 return RMAP_NOMATCH
;
1100 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1102 if (ifp
== NULL
|| ifp
->ifindex
!= info
->attr
->nh_ifindex
)
1103 return RMAP_NOMATCH
;
1107 return RMAP_NOMATCH
;
1110 /* Route map `interface' match statement. `arg' should be
1112 static void *route_match_interface_compile(const char *arg
)
1114 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1117 /* Free route map's compiled `interface' value. */
1118 static void route_match_interface_free(void *rule
)
1120 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1123 /* Route map commands for ip address matching. */
1124 struct route_map_rule_cmd route_match_interface_cmd
= {
1125 "interface", route_match_interface
, route_match_interface_compile
,
1126 route_match_interface_free
};
1130 /* `set ip next-hop IP_ADDRESS' */
1132 /* Match function return 1 if match is success else return zero. */
1133 static route_map_result_t
route_match_tag(void *rule
, struct prefix
*prefix
,
1134 route_map_object_t type
, void *object
)
1137 struct bgp_info
*bgp_info
;
1139 if (type
== RMAP_BGP
) {
1143 return ((bgp_info
->attr
->tag
== *tag
) ? RMAP_MATCH
1147 return RMAP_NOMATCH
;
1151 /* Route map commands for tag matching. */
1152 static struct route_map_rule_cmd route_match_tag_cmd
= {
1153 "tag", route_match_tag
, route_map_rule_tag_compile
,
1154 route_map_rule_tag_free
,
1158 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1159 struct rmap_ip_nexthop_set
{
1160 struct in_addr
*address
;
1165 static route_map_result_t
route_set_ip_nexthop(void *rule
,
1166 struct prefix
*prefix
,
1167 route_map_object_t type
,
1170 struct rmap_ip_nexthop_set
*rins
= rule
;
1171 struct bgp_info
*bgp_info
;
1174 if (type
== RMAP_BGP
) {
1176 peer
= bgp_info
->peer
;
1178 if (rins
->unchanged
) {
1179 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1180 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1181 } else if (rins
->peer_address
) {
1182 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1183 || CHECK_FLAG(peer
->rmap_type
,
1184 PEER_RMAP_TYPE_IMPORT
))
1186 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1187 bgp_info
->attr
->nexthop
.s_addr
=
1188 sockunion2ip(peer
->su_remote
);
1189 bgp_info
->attr
->flag
|=
1190 ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1191 } else if (CHECK_FLAG(peer
->rmap_type
,
1192 PEER_RMAP_TYPE_OUT
)) {
1193 /* The next hop value will be set as part of
1195 * Set the flags here to indicate that rewrite
1197 * Also, clear the value.
1199 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1200 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1201 bgp_info
->attr
->nexthop
.s_addr
= 0;
1204 /* Set next hop value. */
1205 bgp_info
->attr
->flag
|=
1206 ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1207 bgp_info
->attr
->nexthop
= *rins
->address
;
1208 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1209 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1216 /* Route map `ip nexthop' compile function. Given string is converted
1217 to struct in_addr structure. */
1218 static void *route_set_ip_nexthop_compile(const char *arg
)
1220 struct rmap_ip_nexthop_set
*rins
;
1221 struct in_addr
*address
= NULL
;
1222 int peer_address
= 0;
1226 if (strcmp(arg
, "peer-address") == 0)
1228 else if (strcmp(arg
, "unchanged") == 0)
1231 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1232 sizeof(struct in_addr
));
1233 ret
= inet_aton(arg
, address
);
1236 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1241 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1242 sizeof(struct rmap_ip_nexthop_set
));
1244 rins
->address
= address
;
1245 rins
->peer_address
= peer_address
;
1246 rins
->unchanged
= unchanged
;
1251 /* Free route map's compiled `ip nexthop' value. */
1252 static void route_set_ip_nexthop_free(void *rule
)
1254 struct rmap_ip_nexthop_set
*rins
= rule
;
1257 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1259 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1262 /* Route map commands for ip nexthop set. */
1263 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1264 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1265 route_set_ip_nexthop_free
};
1267 /* `set local-preference LOCAL_PREF' */
1269 /* Set local preference. */
1270 static route_map_result_t
route_set_local_pref(void *rule
,
1271 struct prefix
*prefix
,
1272 route_map_object_t type
,
1275 struct rmap_value
*rv
;
1276 struct bgp_info
*bgp_info
;
1277 u_int32_t locpref
= 0;
1279 if (type
== RMAP_BGP
) {
1280 /* Fetch routemap's rule information. */
1284 /* Set local preference value. */
1285 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1286 locpref
= bgp_info
->attr
->local_pref
;
1288 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1289 bgp_info
->attr
->local_pref
=
1290 route_value_adjust(rv
, locpref
, bgp_info
->peer
);
1296 /* Set local preference rule structure. */
1297 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1298 "local-preference", route_set_local_pref
, route_value_compile
,
1302 /* `set weight WEIGHT' */
1305 static route_map_result_t
route_set_weight(void *rule
, struct prefix
*prefix
,
1306 route_map_object_t type
,
1309 struct rmap_value
*rv
;
1310 struct bgp_info
*bgp_info
;
1312 if (type
== RMAP_BGP
) {
1313 /* Fetch routemap's rule information. */
1317 /* Set weight value. */
1318 bgp_info
->attr
->weight
=
1319 route_value_adjust(rv
, 0, bgp_info
->peer
);
1325 /* Set local preference rule structure. */
1326 struct route_map_rule_cmd route_set_weight_cmd
= {
1327 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1330 /* `set metric METRIC' */
1332 /* Set metric to attribute. */
1333 static route_map_result_t
route_set_metric(void *rule
, struct prefix
*prefix
,
1334 route_map_object_t type
,
1337 struct rmap_value
*rv
;
1338 struct bgp_info
*bgp_info
;
1341 if (type
== RMAP_BGP
) {
1342 /* Fetch routemap's rule information. */
1346 if (bgp_info
->attr
->flag
1347 & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1348 med
= bgp_info
->attr
->med
;
1350 bgp_info
->attr
->med
=
1351 route_value_adjust(rv
, med
, bgp_info
->peer
);
1352 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1357 /* Set metric rule structure. */
1358 struct route_map_rule_cmd route_set_metric_cmd
= {
1359 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1362 /* `set as-path prepend ASPATH' */
1364 /* For AS path prepend mechanism. */
1365 static route_map_result_t
route_set_aspath_prepend(void *rule
,
1366 struct prefix
*prefix
,
1367 route_map_object_t type
,
1370 struct aspath
*aspath
;
1372 struct bgp_info
*binfo
;
1374 if (type
== RMAP_BGP
) {
1377 if (binfo
->attr
->aspath
->refcnt
)
1378 new = aspath_dup(binfo
->attr
->aspath
);
1380 new = binfo
->attr
->aspath
;
1382 if ((uintptr_t)rule
> 10) {
1384 aspath_prepend(aspath
, new);
1386 as_t as
= aspath_leftmost(new);
1388 as
= binfo
->peer
->as
;
1389 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1392 binfo
->attr
->aspath
= new;
1398 static void *route_set_aspath_prepend_compile(const char *arg
)
1402 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1403 return (void *)(uintptr_t)num
;
1405 return route_aspath_compile(arg
);
1408 static void route_set_aspath_prepend_free(void *rule
)
1410 if ((uintptr_t)rule
> 10)
1411 route_aspath_free(rule
);
1415 /* Set as-path prepend rule structure. */
1416 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1417 "as-path prepend", route_set_aspath_prepend
,
1418 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1421 /* `set as-path exclude ASn' */
1423 /* For ASN exclude mechanism.
1424 * Iterate over ASns requested and filter them from the given AS_PATH one by
1426 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1428 static route_map_result_t
route_set_aspath_exclude(void *rule
,
1429 struct prefix
*dummy
,
1430 route_map_object_t type
,
1433 struct aspath
*new_path
, *exclude_path
;
1434 struct bgp_info
*binfo
;
1436 if (type
== RMAP_BGP
) {
1437 exclude_path
= rule
;
1439 if (binfo
->attr
->aspath
->refcnt
)
1440 new_path
= aspath_dup(binfo
->attr
->aspath
);
1442 new_path
= binfo
->attr
->aspath
;
1443 binfo
->attr
->aspath
=
1444 aspath_filter_exclude(new_path
, exclude_path
);
1449 /* Set ASn exlude rule structure. */
1450 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1451 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1455 /* `set community COMMUNITY' */
1456 struct rmap_com_set
{
1457 struct community
*com
;
1462 /* For community set mechanism. */
1463 static route_map_result_t
route_set_community(void *rule
, struct prefix
*prefix
,
1464 route_map_object_t type
,
1467 struct rmap_com_set
*rcs
;
1468 struct bgp_info
*binfo
;
1470 struct community
*new = NULL
;
1471 struct community
*old
;
1472 struct community
*merge
;
1474 if (type
== RMAP_BGP
) {
1478 old
= attr
->community
;
1482 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1483 attr
->community
= NULL
;
1484 /* See the longer comment down below. */
1485 if (old
&& old
->refcnt
== 0)
1486 community_free(old
);
1490 /* "additive" case. */
1491 if (rcs
->additive
&& old
) {
1492 merge
= community_merge(community_dup(old
), rcs
->com
);
1494 /* HACK: if the old community is not intern'd,
1495 * we should free it here, or all reference to it may be
1497 * Really need to cleanup attribute caching sometime.
1499 if (old
->refcnt
== 0)
1500 community_free(old
);
1501 new = community_uniq_sort(merge
);
1502 community_free(merge
);
1504 new = community_dup(rcs
->com
);
1506 /* will be interned by caller if required */
1507 attr
->community
= new;
1509 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1515 /* Compile function for set community. */
1516 static void *route_set_community_compile(const char *arg
)
1518 struct rmap_com_set
*rcs
;
1519 struct community
*com
= NULL
;
1524 if (strcmp(arg
, "none") == 0)
1527 sp
= strstr(arg
, "additive");
1529 if (sp
&& sp
> arg
) {
1530 /* "additive" keyworkd is included. */
1535 com
= community_str2com(arg
);
1544 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1546 rcs
->additive
= additive
;
1552 /* Free function for set community. */
1553 static void route_set_community_free(void *rule
)
1555 struct rmap_com_set
*rcs
= rule
;
1558 community_free(rcs
->com
);
1559 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1562 /* Set community rule structure. */
1563 struct route_map_rule_cmd route_set_community_cmd
= {
1564 "community", route_set_community
, route_set_community_compile
,
1565 route_set_community_free
,
1568 /* `set community COMMUNITY' */
1569 struct rmap_lcom_set
{
1570 struct lcommunity
*lcom
;
1576 /* For lcommunity set mechanism. */
1577 static route_map_result_t
route_set_lcommunity(void *rule
,
1578 struct prefix
*prefix
,
1579 route_map_object_t type
,
1582 struct rmap_lcom_set
*rcs
;
1583 struct bgp_info
*binfo
;
1585 struct lcommunity
*new = NULL
;
1586 struct lcommunity
*old
;
1587 struct lcommunity
*merge
;
1589 if (type
== RMAP_BGP
) {
1593 old
= attr
->lcommunity
;
1598 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
1599 attr
->lcommunity
= NULL
;
1601 /* See the longer comment down below. */
1602 if (old
&& old
->refcnt
== 0)
1603 lcommunity_free(&old
);
1607 if (rcs
->additive
&& old
) {
1608 merge
= lcommunity_merge(lcommunity_dup(old
),
1611 /* HACK: if the old large-community is not intern'd,
1612 * we should free it here, or all reference to it may be
1614 * Really need to cleanup attribute caching sometime.
1616 if (old
->refcnt
== 0)
1617 lcommunity_free(&old
);
1618 new = lcommunity_uniq_sort(merge
);
1619 lcommunity_free(&merge
);
1621 new = lcommunity_dup(rcs
->lcom
);
1623 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1624 attr
->lcommunity
= new;
1626 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
1632 /* Compile function for set community. */
1633 static void *route_set_lcommunity_compile(const char *arg
)
1635 struct rmap_lcom_set
*rcs
;
1636 struct lcommunity
*lcom
= NULL
;
1641 if (strcmp(arg
, "none") == 0)
1644 sp
= strstr(arg
, "additive");
1646 if (sp
&& sp
> arg
) {
1647 /* "additive" keyworkd is included. */
1652 lcom
= lcommunity_str2com(arg
);
1661 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1663 rcs
->additive
= additive
;
1669 /* Free function for set lcommunity. */
1670 static void route_set_lcommunity_free(void *rule
)
1672 struct rmap_lcom_set
*rcs
= rule
;
1675 lcommunity_free(&rcs
->lcom
);
1677 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1680 /* Set community rule structure. */
1681 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
1682 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
1683 route_set_lcommunity_free
,
1686 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
1688 /* For large community set mechanism. */
1689 static route_map_result_t
route_set_lcommunity_delete(void *rule
,
1690 struct prefix
*prefix
,
1691 route_map_object_t type
,
1694 struct community_list
*list
;
1695 struct lcommunity
*merge
;
1696 struct lcommunity
*new;
1697 struct lcommunity
*old
;
1698 struct bgp_info
*binfo
;
1700 if (type
== RMAP_BGP
) {
1705 list
= community_list_lookup(bgp_clist
, rule
,
1706 LARGE_COMMUNITY_LIST_MASTER
);
1707 old
= binfo
->attr
->lcommunity
;
1710 merge
= lcommunity_list_match_delete(
1711 lcommunity_dup(old
), list
);
1712 new = lcommunity_uniq_sort(merge
);
1713 lcommunity_free(&merge
);
1715 /* HACK: if the old community is not intern'd,
1716 * we should free it here, or all reference to it may be
1718 * Really need to cleanup attribute caching sometime.
1720 if (old
->refcnt
== 0)
1721 lcommunity_free(&old
);
1723 if (new->size
== 0) {
1724 binfo
->attr
->lcommunity
= NULL
;
1725 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT(
1726 BGP_ATTR_LARGE_COMMUNITIES
);
1727 lcommunity_free(&new);
1729 binfo
->attr
->lcommunity
= new;
1730 binfo
->attr
->flag
|= ATTR_FLAG_BIT(
1731 BGP_ATTR_LARGE_COMMUNITIES
);
1739 /* Compile function for set lcommunity. */
1740 static void *route_set_lcommunity_delete_compile(const char *arg
)
1746 p
= strchr(arg
, ' ');
1749 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1750 memcpy(str
, arg
, len
);
1757 /* Free function for set lcommunity. */
1758 static void route_set_lcommunity_delete_free(void *rule
)
1760 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1763 /* Set lcommunity rule structure. */
1764 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
1765 "large-comm-list", route_set_lcommunity_delete
,
1766 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
1770 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
1772 /* For community set mechanism. */
1773 static route_map_result_t
route_set_community_delete(void *rule
,
1774 struct prefix
*prefix
,
1775 route_map_object_t type
,
1778 struct community_list
*list
;
1779 struct community
*merge
;
1780 struct community
*new;
1781 struct community
*old
;
1782 struct bgp_info
*binfo
;
1784 if (type
== RMAP_BGP
) {
1789 list
= community_list_lookup(bgp_clist
, rule
,
1790 COMMUNITY_LIST_MASTER
);
1791 old
= binfo
->attr
->community
;
1794 merge
= community_list_match_delete(community_dup(old
),
1796 new = community_uniq_sort(merge
);
1797 community_free(merge
);
1799 /* HACK: if the old community is not intern'd,
1800 * we should free it here, or all reference to it may be
1802 * Really need to cleanup attribute caching sometime.
1804 if (old
->refcnt
== 0)
1805 community_free(old
);
1807 if (new->size
== 0) {
1808 binfo
->attr
->community
= NULL
;
1809 binfo
->attr
->flag
&=
1810 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1811 community_free(new);
1813 binfo
->attr
->community
= new;
1814 binfo
->attr
->flag
|=
1815 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1823 /* Compile function for set community. */
1824 static void *route_set_community_delete_compile(const char *arg
)
1830 p
= strchr(arg
, ' ');
1833 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1834 memcpy(str
, arg
, len
);
1841 /* Free function for set community. */
1842 static void route_set_community_delete_free(void *rule
)
1844 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1847 /* Set community rule structure. */
1848 struct route_map_rule_cmd route_set_community_delete_cmd
= {
1849 "comm-list", route_set_community_delete
,
1850 route_set_community_delete_compile
, route_set_community_delete_free
,
1853 /* `set extcommunity rt COMMUNITY' */
1855 /* For community set mechanism. Used by _rt and _soo. */
1856 static route_map_result_t
route_set_ecommunity(void *rule
,
1857 struct prefix
*prefix
,
1858 route_map_object_t type
,
1861 struct ecommunity
*ecom
;
1862 struct ecommunity
*new_ecom
;
1863 struct ecommunity
*old_ecom
;
1864 struct bgp_info
*bgp_info
;
1866 if (type
== RMAP_BGP
) {
1873 /* We assume additive for Extended Community. */
1874 old_ecom
= bgp_info
->attr
->ecommunity
;
1877 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
1880 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
1881 * bgp_update_receive()
1882 * ->refcnt = 0 => set by a previous route-map
1884 if (!old_ecom
->refcnt
)
1885 ecommunity_free(&old_ecom
);
1887 new_ecom
= ecommunity_dup(ecom
);
1889 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1890 bgp_info
->attr
->ecommunity
= new_ecom
;
1892 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
1897 /* Compile function for set community. */
1898 static void *route_set_ecommunity_rt_compile(const char *arg
)
1900 struct ecommunity
*ecom
;
1902 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
1905 return ecommunity_intern(ecom
);
1908 /* Free function for set community. Used by _rt and _soo */
1909 static void route_set_ecommunity_free(void *rule
)
1911 struct ecommunity
*ecom
= rule
;
1912 ecommunity_unintern(&ecom
);
1915 /* Set community rule structure. */
1916 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
1917 "extcommunity rt", route_set_ecommunity
,
1918 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
1921 /* `set extcommunity soo COMMUNITY' */
1923 /* Compile function for set community. */
1924 static void *route_set_ecommunity_soo_compile(const char *arg
)
1926 struct ecommunity
*ecom
;
1928 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
1932 return ecommunity_intern(ecom
);
1935 /* Set community rule structure. */
1936 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
1937 "extcommunity soo", route_set_ecommunity
,
1938 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
1941 /* `set origin ORIGIN' */
1943 /* For origin set. */
1944 static route_map_result_t
route_set_origin(void *rule
, struct prefix
*prefix
,
1945 route_map_object_t type
,
1949 struct bgp_info
*bgp_info
;
1951 if (type
== RMAP_BGP
) {
1955 bgp_info
->attr
->origin
= *origin
;
1961 /* Compile function for origin set. */
1962 static void *route_set_origin_compile(const char *arg
)
1966 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(u_char
));
1968 if (strcmp(arg
, "igp") == 0)
1970 else if (strcmp(arg
, "egp") == 0)
1978 /* Compile function for origin set. */
1979 static void route_set_origin_free(void *rule
)
1981 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1984 /* Set origin rule structure. */
1985 struct route_map_rule_cmd route_set_origin_cmd
= {
1986 "origin", route_set_origin
, route_set_origin_compile
,
1987 route_set_origin_free
,
1990 /* `set atomic-aggregate' */
1992 /* For atomic aggregate set. */
1993 static route_map_result_t
route_set_atomic_aggregate(void *rule
,
1994 struct prefix
*prefix
,
1995 route_map_object_t type
,
1998 struct bgp_info
*bgp_info
;
2000 if (type
== RMAP_BGP
) {
2002 bgp_info
->attr
->flag
|=
2003 ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2009 /* Compile function for atomic aggregate. */
2010 static void *route_set_atomic_aggregate_compile(const char *arg
)
2015 /* Compile function for atomic aggregate. */
2016 static void route_set_atomic_aggregate_free(void *rule
)
2021 /* Set atomic aggregate rule structure. */
2022 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2023 "atomic-aggregate", route_set_atomic_aggregate
,
2024 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2027 /* `set aggregator as AS A.B.C.D' */
2030 struct in_addr address
;
2033 static route_map_result_t
route_set_aggregator_as(void *rule
,
2034 struct prefix
*prefix
,
2035 route_map_object_t type
,
2038 struct bgp_info
*bgp_info
;
2039 struct aggregator
*aggregator
;
2041 if (type
== RMAP_BGP
) {
2045 bgp_info
->attr
->aggregator_as
= aggregator
->as
;
2046 bgp_info
->attr
->aggregator_addr
= aggregator
->address
;
2047 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2053 static void *route_set_aggregator_as_compile(const char *arg
)
2055 struct aggregator
*aggregator
;
2061 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2062 sscanf(arg
, "%s %s", as
, address
);
2064 aggregator
->as
= strtoul(as
, NULL
, 10);
2065 ret
= inet_aton(address
, &aggregator
->address
);
2067 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2073 static void route_set_aggregator_as_free(void *rule
)
2075 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2078 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2079 "aggregator as", route_set_aggregator_as
,
2080 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2083 /* Set tag to object. object must be pointer to struct bgp_info */
2084 static route_map_result_t
route_set_tag(void *rule
, struct prefix
*prefix
,
2085 route_map_object_t type
, void *object
)
2088 struct bgp_info
*bgp_info
;
2090 if (type
== RMAP_BGP
) {
2095 bgp_info
->attr
->tag
= *tag
;
2101 /* Route map commands for tag set. */
2102 static struct route_map_rule_cmd route_set_tag_cmd
= {
2103 "tag", route_set_tag
, route_map_rule_tag_compile
,
2104 route_map_rule_tag_free
,
2107 /* Set label-index to object. object must be pointer to struct bgp_info */
2108 static route_map_result_t
route_set_label_index(void *rule
,
2109 struct prefix
*prefix
,
2110 route_map_object_t type
,
2113 struct rmap_value
*rv
;
2114 struct bgp_info
*bgp_info
;
2115 u_int32_t label_index
;
2117 if (type
== RMAP_BGP
) {
2118 /* Fetch routemap's rule information. */
2122 /* Set label-index value. */
2123 label_index
= rv
->value
;
2125 bgp_info
->attr
->label_index
= label_index
;
2126 bgp_info
->attr
->flag
|=
2127 ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2134 /* Route map commands for label-index set. */
2135 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2136 "label-index", route_set_label_index
, route_value_compile
,
2140 /* `match ipv6 address IP_ACCESS_LIST' */
2142 static route_map_result_t
route_match_ipv6_address(void *rule
,
2143 struct prefix
*prefix
,
2144 route_map_object_t type
,
2147 struct access_list
*alist
;
2149 if (type
== RMAP_BGP
) {
2150 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2152 return RMAP_NOMATCH
;
2154 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2158 return RMAP_NOMATCH
;
2161 static void *route_match_ipv6_address_compile(const char *arg
)
2163 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2166 static void route_match_ipv6_address_free(void *rule
)
2168 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2171 /* Route map commands for ip address matching. */
2172 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2173 "ipv6 address", route_match_ipv6_address
,
2174 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2176 /* `match ipv6 next-hop IP_ADDRESS' */
2178 static route_map_result_t
route_match_ipv6_next_hop(void *rule
,
2179 struct prefix
*prefix
,
2180 route_map_object_t type
,
2183 struct in6_addr
*addr
= rule
;
2184 struct bgp_info
*bgp_info
;
2186 if (type
== RMAP_BGP
) {
2189 if (IPV6_ADDR_SAME(&bgp_info
->attr
->mp_nexthop_global
, addr
))
2192 if (bgp_info
->attr
->mp_nexthop_len
2193 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2194 && IPV6_ADDR_SAME(&bgp_info
->attr
->mp_nexthop_local
, rule
))
2197 return RMAP_NOMATCH
;
2200 return RMAP_NOMATCH
;
2203 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2205 struct in6_addr
*address
;
2208 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2210 ret
= inet_pton(AF_INET6
, arg
, address
);
2212 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2219 static void route_match_ipv6_next_hop_free(void *rule
)
2221 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2224 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2225 "ipv6 next-hop", route_match_ipv6_next_hop
,
2226 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2228 /* `match ipv6 address prefix-list PREFIX_LIST' */
2230 static route_map_result_t
2231 route_match_ipv6_address_prefix_list(void *rule
, struct prefix
*prefix
,
2232 route_map_object_t type
, void *object
)
2234 struct prefix_list
*plist
;
2236 if (type
== RMAP_BGP
) {
2237 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
2239 return RMAP_NOMATCH
;
2241 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
2245 return RMAP_NOMATCH
;
2248 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2250 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2253 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2255 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2258 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2259 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2260 route_match_ipv6_address_prefix_list_compile
,
2261 route_match_ipv6_address_prefix_list_free
};
2263 /* `set ipv6 nexthop global IP_ADDRESS' */
2265 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2266 static route_map_result_t
route_set_ipv6_nexthop_global(void *rule
,
2267 struct prefix
*prefix
,
2268 route_map_object_t type
,
2271 struct in6_addr
*address
;
2272 struct bgp_info
*bgp_info
;
2274 if (type
== RMAP_BGP
) {
2275 /* Fetch routemap's rule information. */
2279 /* Set next hop value. */
2280 bgp_info
->attr
->mp_nexthop_global
= *address
;
2282 /* Set nexthop length. */
2283 if (bgp_info
->attr
->mp_nexthop_len
== 0)
2284 bgp_info
->attr
->mp_nexthop_len
=
2285 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2287 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2288 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2294 /* Route map `ip next-hop' compile function. Given string is converted
2295 to struct in_addr structure. */
2296 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2299 struct in6_addr
*address
;
2301 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2303 ret
= inet_pton(AF_INET6
, arg
, address
);
2306 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2313 /* Free route map's compiled `ip next-hop' value. */
2314 static void route_set_ipv6_nexthop_global_free(void *rule
)
2316 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2319 /* Route map commands for ip nexthop set. */
2320 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2321 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2322 route_set_ipv6_nexthop_global_compile
,
2323 route_set_ipv6_nexthop_global_free
};
2325 /* Set next-hop preference value. */
2326 static route_map_result_t
2327 route_set_ipv6_nexthop_prefer_global(void *rule
, struct prefix
*prefix
,
2328 route_map_object_t type
, void *object
)
2330 struct bgp_info
*bgp_info
;
2333 if (type
== RMAP_BGP
) {
2334 /* Fetch routemap's rule information. */
2336 peer
= bgp_info
->peer
;
2338 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2339 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2341 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2342 /* Set next hop preference to global */
2343 bgp_info
->attr
->mp_nexthop_prefer_global
= TRUE
;
2344 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2345 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2347 bgp_info
->attr
->mp_nexthop_prefer_global
= FALSE
;
2348 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2349 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2355 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2359 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2365 /* Free route map's compiled `ip next-hop' value. */
2366 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2368 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2371 /* Route map commands for ip nexthop set preferred. */
2372 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2373 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2374 route_set_ipv6_nexthop_prefer_global_compile
,
2375 route_set_ipv6_nexthop_prefer_global_free
};
2377 /* `set ipv6 nexthop local IP_ADDRESS' */
2379 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2380 static route_map_result_t
route_set_ipv6_nexthop_local(void *rule
,
2381 struct prefix
*prefix
,
2382 route_map_object_t type
,
2385 struct in6_addr
*address
;
2386 struct bgp_info
*bgp_info
;
2388 if (type
== RMAP_BGP
) {
2389 /* Fetch routemap's rule information. */
2393 /* Set next hop value. */
2394 bgp_info
->attr
->mp_nexthop_local
= *address
;
2396 /* Set nexthop length. */
2397 if (bgp_info
->attr
->mp_nexthop_len
2398 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2399 bgp_info
->attr
->mp_nexthop_len
=
2400 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2402 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2403 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2409 /* Route map `ip nexthop' compile function. Given string is converted
2410 to struct in_addr structure. */
2411 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2414 struct in6_addr
*address
;
2416 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2418 ret
= inet_pton(AF_INET6
, arg
, address
);
2421 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2428 /* Free route map's compiled `ip nexthop' value. */
2429 static void route_set_ipv6_nexthop_local_free(void *rule
)
2431 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2434 /* Route map commands for ip nexthop set. */
2435 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2436 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2437 route_set_ipv6_nexthop_local_compile
,
2438 route_set_ipv6_nexthop_local_free
};
2440 /* `set ipv6 nexthop peer-address' */
2442 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2443 static route_map_result_t
route_set_ipv6_nexthop_peer(void *rule
,
2444 struct prefix
*prefix
,
2445 route_map_object_t type
,
2448 struct in6_addr peer_address
;
2449 struct bgp_info
*bgp_info
;
2452 if (type
== RMAP_BGP
) {
2453 /* Fetch routemap's rule information. */
2455 peer
= bgp_info
->peer
;
2457 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2458 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2460 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2461 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2462 /* Set next hop value and length in attribute. */
2463 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2464 bgp_info
->attr
->mp_nexthop_local
= peer_address
;
2465 if (bgp_info
->attr
->mp_nexthop_len
!= 32)
2466 bgp_info
->attr
->mp_nexthop_len
= 32;
2468 bgp_info
->attr
->mp_nexthop_global
=
2470 if (bgp_info
->attr
->mp_nexthop_len
== 0)
2471 bgp_info
->attr
->mp_nexthop_len
= 16;
2474 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2475 /* The next hop value will be set as part of packet
2477 * Set the flags here to indicate that rewrite needs to
2479 * Also, clear the value - we clear both global and
2481 * nexthops, whether we send one or both is determined
2484 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2485 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2486 /* clear next hop value. */
2487 memset(&(bgp_info
->attr
->mp_nexthop_global
), 0,
2488 sizeof(struct in6_addr
));
2489 memset(&(bgp_info
->attr
->mp_nexthop_local
), 0,
2490 sizeof(struct in6_addr
));
2497 /* Route map `ip next-hop' compile function. Given string is converted
2498 to struct in_addr structure. */
2499 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2503 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2509 /* Free route map's compiled `ip next-hop' value. */
2510 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2512 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2515 /* Route map commands for ip nexthop set. */
2516 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2517 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2518 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2520 /* `set ipv4 vpn next-hop A.B.C.D' */
2522 static route_map_result_t
route_set_vpnv4_nexthop(void *rule
,
2523 struct prefix
*prefix
,
2524 route_map_object_t type
,
2527 struct in_addr
*address
;
2528 struct bgp_info
*bgp_info
;
2530 if (type
== RMAP_BGP
) {
2531 /* Fetch routemap's rule information. */
2535 /* Set next hop value. */
2536 bgp_info
->attr
->mp_nexthop_global_in
= *address
;
2537 bgp_info
->attr
->mp_nexthop_len
= 4;
2543 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2546 struct in_addr
*address
;
2548 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2550 ret
= inet_aton(arg
, address
);
2553 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2560 /* `set ipv6 vpn next-hop A.B.C.D' */
2562 static route_map_result_t
route_set_vpnv6_nexthop(void *rule
,
2563 struct prefix
*prefix
,
2564 route_map_object_t type
,
2567 struct in6_addr
*address
;
2568 struct bgp_info
*bgp_info
;
2570 if (type
== RMAP_BGP
) {
2571 /* Fetch routemap's rule information. */
2575 /* Set next hop value. */
2576 memcpy(&bgp_info
->attr
->mp_nexthop_global
, address
,
2577 sizeof(struct in6_addr
));
2578 bgp_info
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2584 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2587 struct in6_addr
*address
;
2589 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2590 ret
= inet_pton(AF_INET6
, arg
, address
);
2593 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2600 static void route_set_vpn_nexthop_free(void *rule
)
2602 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2605 /* Route map commands for ipv4 next-hop set. */
2606 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2607 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2608 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
2610 /* Route map commands for ipv6 next-hop set. */
2611 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
2612 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
2613 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
2615 /* `set originator-id' */
2617 /* For origin set. */
2618 static route_map_result_t
route_set_originator_id(void *rule
,
2619 struct prefix
*prefix
,
2620 route_map_object_t type
,
2623 struct in_addr
*address
;
2624 struct bgp_info
*bgp_info
;
2626 if (type
== RMAP_BGP
) {
2630 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
2631 bgp_info
->attr
->originator_id
= *address
;
2637 /* Compile function for originator-id set. */
2638 static void *route_set_originator_id_compile(const char *arg
)
2641 struct in_addr
*address
;
2643 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2645 ret
= inet_aton(arg
, address
);
2648 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2655 /* Compile function for originator_id set. */
2656 static void route_set_originator_id_free(void *rule
)
2658 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2661 /* Set originator-id rule structure. */
2662 struct route_map_rule_cmd route_set_originator_id_cmd
= {
2663 "originator-id", route_set_originator_id
,
2664 route_set_originator_id_compile
, route_set_originator_id_free
,
2667 /* Add bgp route map rule. */
2668 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
2669 const char *arg
, route_map_event_t type
)
2671 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2674 ret
= route_map_add_match(index
, command
, arg
);
2677 case RMAP_RULE_MISSING
:
2678 vty_out(vty
, "%% BGP Can't find rule.\n");
2679 return CMD_WARNING_CONFIG_FAILED
;
2680 case RMAP_COMPILE_ERROR
:
2681 vty_out(vty
, "%% BGP Argument is malformed.\n");
2682 return CMD_WARNING_CONFIG_FAILED
;
2686 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
2687 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
2693 /* Delete bgp route map rule. */
2694 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
2695 const char *arg
, route_map_event_t type
)
2697 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2699 char *dep_name
= NULL
;
2701 char *rmap_name
= NULL
;
2703 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
2704 /* ignore the mundane, the types without any dependency */
2706 if ((tmpstr
= route_map_get_match_arg(index
, command
))
2709 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
2711 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
2713 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
2716 ret
= route_map_delete_match(index
, command
, dep_name
);
2719 case RMAP_RULE_MISSING
:
2720 vty_out(vty
, "%% BGP Can't find rule.\n");
2722 case RMAP_COMPILE_ERROR
:
2723 vty_out(vty
, "%% BGP Argument is malformed.\n");
2727 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2729 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2730 return CMD_WARNING_CONFIG_FAILED
;
2733 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
2734 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
2737 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2739 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2745 * This is the workhorse routine for processing in/out routemap
2748 static void bgp_route_map_process_peer(const char *rmap_name
,
2749 struct route_map
*map
, struct peer
*peer
,
2750 int afi
, int safi
, int route_update
)
2754 struct bgp_filter
*filter
;
2756 if (!peer
|| !rmap_name
)
2759 filter
= &peer
->filter
[afi
][safi
];
2761 * in is for non-route-server clients,
2762 * out is for all peers
2764 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
2765 if (filter
->map
[RMAP_IN
].name
2766 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
2767 filter
->map
[RMAP_IN
].map
= map
;
2769 if (route_update
&& peer
->status
== Established
) {
2770 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
2771 PEER_FLAG_SOFT_RECONFIG
)) {
2772 if (bgp_debug_update(peer
, NULL
, NULL
,
2775 "Processing route_map %s update on "
2776 "peer %s (inbound, soft-reconfig)",
2777 rmap_name
, peer
->host
);
2779 bgp_soft_reconfig_in(peer
, afi
, safi
);
2781 CHECK_FLAG(peer
->cap
,
2782 PEER_CAP_REFRESH_OLD_RCV
)
2785 PEER_CAP_REFRESH_NEW_RCV
)) {
2787 if (bgp_debug_update(peer
, NULL
, NULL
,
2790 "Processing route_map %s update on "
2791 "peer %s (inbound, route-refresh)",
2792 rmap_name
, peer
->host
);
2793 bgp_route_refresh_send(peer
, afi
, safi
,
2800 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
2803 if (update
&& route_update
&& peer
->status
== Established
) {
2804 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
2805 PEER_FLAG_SOFT_RECONFIG
)) {
2806 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2808 "Processing route_map %s update on "
2809 "peer %s (import, soft-reconfig)",
2810 rmap_name
, peer
->host
);
2812 bgp_soft_reconfig_in(peer
, afi
, safi
);
2813 } else if (CHECK_FLAG(peer
->cap
,
2814 PEER_CAP_REFRESH_OLD_RCV
)
2815 || CHECK_FLAG(peer
->cap
,
2816 PEER_CAP_REFRESH_NEW_RCV
)) {
2817 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2819 "Processing route_map %s update on "
2820 "peer %s (import, route-refresh)",
2821 rmap_name
, peer
->host
);
2822 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
2825 /* DD: Else, what else do we do ? Reset peer ? */
2830 * For outbound, unsuppress and default-originate map change (content or
2831 * map created), merely update the "config" here, the actual route
2832 * announcement happens at the group level.
2834 if (filter
->map
[RMAP_OUT
].name
2835 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
2836 filter
->map
[RMAP_OUT
].map
= map
;
2838 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
2839 filter
->usmap
.map
= map
;
2841 if (peer
->default_rmap
[afi
][safi
].name
2842 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
2843 peer
->default_rmap
[afi
][safi
].map
= map
;
2846 static void bgp_route_map_update_peer_group(const char *rmap_name
,
2847 struct route_map
*map
,
2850 struct peer_group
*group
;
2851 struct listnode
*node
, *nnode
;
2852 struct bgp_filter
*filter
;
2859 /* All the peers have been updated correctly already. This is
2860 * just updating the placeholder data. No real update required.
2862 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
))
2863 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2864 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
2865 filter
= &group
->conf
->filter
[afi
][safi
];
2867 for (direct
= RMAP_IN
; direct
< RMAP_MAX
;
2869 if ((filter
->map
[direct
].name
)
2870 && (strcmp(rmap_name
,
2871 filter
->map
[direct
].name
)
2873 filter
->map
[direct
].map
= map
;
2876 if (filter
->usmap
.name
2877 && (strcmp(rmap_name
, filter
->usmap
.name
)
2879 filter
->usmap
.map
= map
;
2884 * Note that if an extreme number (tens of thousands) of route-maps are in use
2885 * and if bgp has an extreme number of peers, network statements, etc then this
2886 * function can consume a lot of cycles. This is due to this function being
2887 * called for each route-map and within this function we walk the list of peers,
2888 * network statements, etc looking to see if they use this route-map.
2890 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
2897 struct bgp_node
*bn
;
2898 struct bgp_static
*bgp_static
;
2899 struct listnode
*node
, *nnode
;
2900 struct route_map
*map
;
2901 char buf
[INET6_ADDRSTRLEN
];
2903 map
= route_map_lookup_by_name(rmap_name
);
2905 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
2907 /* Ignore dummy peer-group structure */
2908 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
2911 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2912 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
2913 /* Ignore inactive AFI/SAFI */
2914 if (!peer
->afc
[afi
][safi
])
2917 /* process in/out/import/export/default-orig
2919 bgp_route_map_process_peer(rmap_name
, map
, peer
,
2925 /* for outbound/default-orig route-maps, process for groups */
2926 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
2929 /* update peer-group config (template) */
2930 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
2932 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2933 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
2934 /* For table route-map updates. */
2935 if (!bgp_fibupd_safi(safi
))
2938 if (bgp
->table_map
[afi
][safi
].name
2939 && (strcmp(rmap_name
,
2940 bgp
->table_map
[afi
][safi
].name
)
2942 bgp
->table_map
[afi
][safi
].map
= map
;
2944 if (BGP_DEBUG(zebra
, ZEBRA
))
2946 "Processing route_map %s update on "
2950 bgp_zebra_announce_table(bgp
, afi
,
2954 /* For network route-map updates. */
2955 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
2956 bn
= bgp_route_next(bn
))
2957 if ((bgp_static
= bn
->info
) != NULL
) {
2958 if (bgp_static
->rmap
.name
2959 && (strcmp(rmap_name
,
2960 bgp_static
->rmap
.name
)
2962 bgp_static
->rmap
.map
= map
;
2967 if (bgp_debug_zebra(
2970 "Processing route_map %s update on "
2989 /* For redistribute route-map updates. */
2990 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2991 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
2992 struct list
*red_list
;
2993 struct listnode
*node
;
2994 struct bgp_redist
*red
;
2996 red_list
= bgp
->redist
[afi
][i
];
3000 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3002 && (strcmp(rmap_name
, red
->rmap
.name
)
3004 red
->rmap
.map
= map
;
3007 if (BGP_DEBUG(zebra
, ZEBRA
))
3009 "Processing route_map %s update on "
3010 "redistributed routes",
3013 bgp_redistribute_resend(
3022 static int bgp_route_map_process_update_cb(char *rmap_name
)
3024 struct listnode
*node
, *nnode
;
3027 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3028 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3031 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3032 vnc_routemap_update(bgp
, __func__
);
3037 int bgp_route_map_update_timer(struct thread
*thread
)
3039 bm
->t_rmap_update
= NULL
;
3041 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3046 static void bgp_route_map_mark_update(const char *rmap_name
)
3048 if (bm
->t_rmap_update
== NULL
) {
3049 struct listnode
*node
, *nnode
;
3052 /* rmap_update_timer of 0 means don't do route updates */
3053 if (bm
->rmap_update_timer
) {
3054 bm
->t_rmap_update
= NULL
;
3055 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3056 NULL
, bm
->rmap_update_timer
,
3057 &bm
->t_rmap_update
);
3059 /* Signal the groups that a route-map update event has
3061 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3062 update_group_policy_update(bgp
,
3063 BGP_POLICY_ROUTE_MAP
,
3066 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3067 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3069 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3070 vnc_routemap_update(bgp
, __func__
);
3076 static void bgp_route_map_add(const char *rmap_name
)
3078 if (route_map_mark_updated(rmap_name
, 0) == 0)
3079 bgp_route_map_mark_update(rmap_name
);
3081 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3084 static void bgp_route_map_delete(const char *rmap_name
)
3086 if (route_map_mark_updated(rmap_name
, 1) == 0)
3087 bgp_route_map_mark_update(rmap_name
);
3089 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3092 static void bgp_route_map_event(route_map_event_t event
, const char *rmap_name
)
3094 if (route_map_mark_updated(rmap_name
, 0) == 0)
3095 bgp_route_map_mark_update(rmap_name
);
3097 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3100 DEFUN (match_mac_address
,
3101 match_mac_address_cmd
,
3102 "match mac address WORD",
3105 "Match address of route\n"
3106 "MAC Access-list name\n")
3108 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3109 RMAP_EVENT_FILTER_ADDED
);
3112 DEFUN (no_match_mac_address
,
3113 no_match_mac_address_cmd
,
3114 "no match mac address WORD",
3118 "Match address of route\n"
3119 "MAC acess-list name\n")
3121 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3122 RMAP_EVENT_FILTER_DELETED
);
3125 DEFUN (match_evpn_vni
,
3127 "match evpn vni (1-16777215)",
3133 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3134 RMAP_EVENT_MATCH_ADDED
);
3137 DEFUN (no_match_evpn_vni
,
3138 no_match_evpn_vni_cmd
,
3139 "no match evpn vni (1-16777215)",
3146 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3147 RMAP_EVENT_MATCH_DELETED
);
3152 "match peer <A.B.C.D|X:X::X:X>",
3154 "Match peer address\n"
3155 "IP address of peer\n"
3156 "IPv6 address of peer\n")
3159 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3160 RMAP_EVENT_MATCH_ADDED
);
3163 DEFUN (match_peer_local
,
3164 match_peer_local_cmd
,
3167 "Match peer address\n"
3168 "Static or Redistributed routes\n")
3170 return bgp_route_match_add(vty
, "peer", "local",
3171 RMAP_EVENT_MATCH_DELETED
);
3174 DEFUN (no_match_peer
,
3176 "no match peer [<local|A.B.C.D|X:X::X:X>]",
3179 "Match peer address\n"
3180 "Static or Redistributed routes\n"
3181 "IP address of peer\n"
3182 "IPv6 address of peer\n")
3186 if (argc
<= idx_peer
)
3187 return bgp_route_match_delete(vty
, "peer", NULL
,
3188 RMAP_EVENT_MATCH_DELETED
);
3189 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3190 RMAP_EVENT_MATCH_DELETED
);
3194 /* match probability */
3195 DEFUN (match_probability
,
3196 match_probability_cmd
,
3197 "match probability (0-100)",
3199 "Match portion of routes defined by percentage value\n"
3200 "Percentage of routes\n")
3203 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3204 RMAP_EVENT_MATCH_ADDED
);
3208 DEFUN (no_match_probability
,
3209 no_match_probability_cmd
,
3210 "no match probability [(1-99)]",
3213 "Match portion of routes defined by percentage value\n"
3214 "Percentage of routes\n")
3217 if (argc
<= idx_number
)
3218 return bgp_route_match_delete(vty
, "probability", NULL
,
3219 RMAP_EVENT_MATCH_DELETED
);
3220 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3221 RMAP_EVENT_MATCH_DELETED
);
3225 DEFUN (match_ip_route_source
,
3226 match_ip_route_source_cmd
,
3227 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3230 "Match advertising source address of route\n"
3231 "IP access-list number\n"
3232 "IP access-list number (expanded range)\n"
3233 "IP standard access-list name\n")
3236 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3237 RMAP_EVENT_FILTER_ADDED
);
3241 DEFUN (no_match_ip_route_source
,
3242 no_match_ip_route_source_cmd
,
3243 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3247 "Match advertising source address of route\n"
3248 "IP access-list number\n"
3249 "IP access-list number (expanded range)\n"
3250 "IP standard access-list name\n")
3253 if (argc
<= idx_number
)
3254 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3255 RMAP_EVENT_FILTER_DELETED
);
3256 return bgp_route_match_delete(vty
, "ip route-source",
3257 argv
[idx_number
]->arg
,
3258 RMAP_EVENT_FILTER_DELETED
);
3262 DEFUN (match_ip_route_source_prefix_list
,
3263 match_ip_route_source_prefix_list_cmd
,
3264 "match ip route-source prefix-list WORD",
3267 "Match advertising source address of route\n"
3268 "Match entries of prefix-lists\n"
3269 "IP prefix-list name\n")
3272 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3273 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3277 DEFUN (no_match_ip_route_source_prefix_list
,
3278 no_match_ip_route_source_prefix_list_cmd
,
3279 "no match ip route-source prefix-list [WORD]",
3283 "Match advertising source address of route\n"
3284 "Match entries of prefix-lists\n"
3285 "IP prefix-list name\n")
3288 if (argc
<= idx_word
)
3289 return bgp_route_match_delete(vty
,
3290 "ip route-source prefix-list",
3291 NULL
, RMAP_EVENT_PLIST_DELETED
);
3292 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3293 argv
[idx_word
]->arg
,
3294 RMAP_EVENT_PLIST_DELETED
);
3298 DEFUN (match_local_pref
,
3299 match_local_pref_cmd
,
3300 "match local-preference (0-4294967295)",
3302 "Match local-preference of route\n"
3306 return bgp_route_match_add(vty
, "local-preference",
3307 argv
[idx_number
]->arg
,
3308 RMAP_EVENT_MATCH_ADDED
);
3312 DEFUN (no_match_local_pref
,
3313 no_match_local_pref_cmd
,
3314 "no match local-preference [(0-4294967295)]",
3317 "Match local preference of route\n"
3318 "Local preference value\n")
3320 int idx_localpref
= 3;
3321 if (argc
<= idx_localpref
)
3322 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3323 RMAP_EVENT_MATCH_DELETED
);
3324 return bgp_route_match_delete(vty
, "local-preference",
3325 argv
[idx_localpref
]->arg
,
3326 RMAP_EVENT_MATCH_DELETED
);
3330 DEFUN (match_community
,
3331 match_community_cmd
,
3332 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3334 "Match BGP community list\n"
3335 "Community-list number (standard)\n"
3336 "Community-list number (expanded)\n"
3337 "Community-list name\n"
3338 "Do exact matching of communities\n")
3340 int idx_comm_list
= 2;
3345 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3346 strlen(argv
[idx_comm_list
]->arg
)
3347 + strlen("exact-match") + 2);
3349 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3351 argstr
= argv
[idx_comm_list
]->arg
;
3353 ret
= bgp_route_match_add(vty
, "community", argstr
,
3354 RMAP_EVENT_CLIST_ADDED
);
3356 if (argstr
!= argv
[idx_comm_list
]->arg
)
3357 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3362 DEFUN (no_match_community
,
3363 no_match_community_cmd
,
3364 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3367 "Match BGP community list\n"
3368 "Community-list number (standard)\n"
3369 "Community-list number (expanded)\n"
3370 "Community-list name\n"
3371 "Do exact matching of communities\n")
3373 return bgp_route_match_delete(vty
, "community", NULL
,
3374 RMAP_EVENT_CLIST_DELETED
);
3377 DEFUN (match_lcommunity
,
3378 match_lcommunity_cmd
,
3379 "match large-community <(1-99)|(100-500)|WORD>",
3381 "Match BGP large community list\n"
3382 "Large Community-list number (standard)\n"
3383 "Large Community-list number (expanded)\n"
3384 "Large Community-list name\n")
3386 return bgp_route_match_add(vty
, "large-community", argv
[2]->arg
,
3387 RMAP_EVENT_LLIST_ADDED
);
3390 DEFUN (no_match_lcommunity
,
3391 no_match_lcommunity_cmd
,
3392 "no match large-community [<(1-99)|(100-500)|WORD>]",
3395 "Match BGP large community list\n"
3396 "Large Community-list number (standard)\n"
3397 "Large Community-list number (expanded)\n"
3398 "Large Community-list name\n")
3400 return bgp_route_match_delete(vty
, "large-community", NULL
,
3401 RMAP_EVENT_LLIST_DELETED
);
3404 DEFUN (match_ecommunity
,
3405 match_ecommunity_cmd
,
3406 "match extcommunity <(1-99)|(100-500)|WORD>",
3408 "Match BGP/VPN extended community list\n"
3409 "Extended community-list number (standard)\n"
3410 "Extended community-list number (expanded)\n"
3411 "Extended community-list name\n")
3413 int idx_comm_list
= 2;
3414 return bgp_route_match_add(vty
, "extcommunity",
3415 argv
[idx_comm_list
]->arg
,
3416 RMAP_EVENT_ECLIST_ADDED
);
3420 DEFUN (no_match_ecommunity
,
3421 no_match_ecommunity_cmd
,
3422 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3425 "Match BGP/VPN extended community list\n"
3426 "Extended community-list number (standard)\n"
3427 "Extended community-list number (expanded)\n"
3428 "Extended community-list name\n")
3430 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3431 RMAP_EVENT_ECLIST_DELETED
);
3435 DEFUN (match_aspath
,
3437 "match as-path WORD",
3439 "Match BGP AS path list\n"
3440 "AS path access-list name\n")
3443 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3444 RMAP_EVENT_ASLIST_ADDED
);
3448 DEFUN (no_match_aspath
,
3449 no_match_aspath_cmd
,
3450 "no match as-path [WORD]",
3453 "Match BGP AS path list\n"
3454 "AS path access-list name\n")
3456 return bgp_route_match_delete(vty
, "as-path", NULL
,
3457 RMAP_EVENT_ASLIST_DELETED
);
3461 DEFUN (match_origin
,
3463 "match origin <egp|igp|incomplete>",
3468 "unknown heritage\n")
3471 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3472 return bgp_route_match_add(vty
, "origin", "igp",
3473 RMAP_EVENT_MATCH_ADDED
);
3474 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3475 return bgp_route_match_add(vty
, "origin", "egp",
3476 RMAP_EVENT_MATCH_ADDED
);
3477 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3478 return bgp_route_match_add(vty
, "origin", "incomplete",
3479 RMAP_EVENT_MATCH_ADDED
);
3481 vty_out(vty
, "%% Invalid match origin type\n");
3482 return CMD_WARNING_CONFIG_FAILED
;
3486 DEFUN (no_match_origin
,
3487 no_match_origin_cmd
,
3488 "no match origin [<egp|igp|incomplete>]",
3494 "unknown heritage\n")
3496 return bgp_route_match_delete(vty
, "origin", NULL
,
3497 RMAP_EVENT_MATCH_DELETED
);
3500 DEFUN (set_ip_nexthop_peer
,
3501 set_ip_nexthop_peer_cmd
,
3502 "[no] set ip next-hop peer-address",
3506 "Next hop address\n"
3507 "Use peer address (for BGP only)\n")
3509 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3510 const char *) = strmatch(argv
[0]->text
, "no")
3511 ? generic_set_delete
3514 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3518 DEFUN (set_ip_nexthop_unchanged
,
3519 set_ip_nexthop_unchanged_cmd
,
3520 "[no] set ip next-hop unchanged",
3524 "Next hop address\n"
3525 "Don't modify existing Next hop address\n")
3527 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3528 const char *) = strmatch(argv
[0]->text
, "no")
3529 ? generic_set_delete
3532 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3537 DEFUN (set_local_pref
,
3539 "set local-preference (0-4294967295)",
3541 "BGP local preference path attribute\n"
3542 "Preference value\n")
3545 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3546 "local-preference", argv
[idx_number
]->arg
);
3550 DEFUN (no_set_local_pref
,
3551 no_set_local_pref_cmd
,
3552 "no set local-preference [(0-4294967295)]",
3555 "BGP local preference path attribute\n"
3556 "Preference value\n")
3558 int idx_localpref
= 3;
3559 if (argc
<= idx_localpref
)
3560 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3561 "local-preference", NULL
);
3562 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3563 "local-preference", argv
[idx_localpref
]->arg
);
3569 "set weight (0-4294967295)",
3571 "BGP weight for routing table\n"
3575 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
3576 argv
[idx_number
]->arg
);
3580 DEFUN (no_set_weight
,
3582 "no set weight [(0-4294967295)]",
3585 "BGP weight for routing table\n"
3589 if (argc
<= idx_weight
)
3590 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3592 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3593 "weight", argv
[idx_weight
]->arg
);
3596 DEFUN (set_label_index
,
3597 set_label_index_cmd
,
3598 "set label-index (0-1048560)",
3600 "Label index to associate with the prefix\n"
3601 "Label index value\n")
3604 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3605 "label-index", argv
[idx_number
]->arg
);
3608 DEFUN (no_set_label_index
,
3609 no_set_label_index_cmd
,
3610 "no set label-index [(0-1048560)]",
3613 "Label index to associate with the prefix\n"
3614 "Label index value\n")
3616 int idx_label_index
= 3;
3617 if (argc
<= idx_label_index
)
3618 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3619 "label-index", NULL
);
3620 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3621 "label-index", argv
[idx_label_index
]->arg
);
3624 DEFUN (set_aspath_prepend_asn
,
3625 set_aspath_prepend_asn_cmd
,
3626 "set as-path prepend (1-4294967295)...",
3628 "Transform BGP AS_PATH attribute\n"
3629 "Prepend to the as-path\n"
3636 str
= argv_concat(argv
, argc
, idx_asn
);
3637 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3638 "as-path prepend", str
);
3639 XFREE(MTYPE_TMP
, str
);
3644 DEFUN (set_aspath_prepend_lastas
,
3645 set_aspath_prepend_lastas_cmd
,
3646 "set as-path prepend last-as (1-10)",
3648 "Transform BGP AS_PATH attribute\n"
3649 "Prepend to the as-path\n"
3650 "Use the peer's AS-number\n"
3651 "Number of times to insert\n")
3653 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
3656 DEFUN (no_set_aspath_prepend
,
3657 no_set_aspath_prepend_cmd
,
3658 "no set as-path prepend [(1-4294967295)]",
3661 "Transform BGP AS_PATH attribute\n"
3662 "Prepend to the as-path\n"
3669 str
= argv_concat(argv
, argc
, idx_asn
);
3670 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3671 "as-path prepend", str
);
3672 XFREE(MTYPE_TMP
, str
);
3677 DEFUN (set_aspath_exclude
,
3678 set_aspath_exclude_cmd
,
3679 "set as-path exclude (1-4294967295)...",
3681 "Transform BGP AS-path attribute\n"
3682 "Exclude from the as-path\n"
3689 str
= argv_concat(argv
, argc
, idx_asn
);
3690 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3691 "as-path exclude", str
);
3692 XFREE(MTYPE_TMP
, str
);
3696 DEFUN (no_set_aspath_exclude
,
3697 no_set_aspath_exclude_cmd
,
3698 "no set as-path exclude (1-4294967295)...",
3701 "Transform BGP AS_PATH attribute\n"
3702 "Exclude from the as-path\n"
3709 str
= argv_concat(argv
, argc
, idx_asn
);
3710 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3711 "as-path exclude", str
);
3712 XFREE(MTYPE_TMP
, str
);
3717 DEFUN (set_community
,
3719 "set community AA:NN...",
3721 "BGP community attribute\n"
3729 struct community
*com
= NULL
;
3734 b
= buffer_new(1024);
3736 for (i
= idx_aa_nn
; i
< argc
; i
++) {
3737 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
3744 buffer_putc(b
, ' ');
3748 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
3750 buffer_putstr(b
, "internet");
3753 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
3755 buffer_putstr(b
, "local-AS");
3758 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
3759 && strncmp(argv
[i
]->arg
, "no-advertise",
3760 strlen(argv
[i
]->arg
))
3762 buffer_putstr(b
, "no-advertise");
3765 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
3766 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
3768 buffer_putstr(b
, "no-export");
3771 buffer_putstr(b
, argv
[i
]->arg
);
3773 buffer_putc(b
, '\0');
3775 /* Fetch result string then compile it to communities attribute. */
3776 str
= buffer_getstr(b
);
3780 com
= community_str2com(str
);
3781 XFREE(MTYPE_TMP
, str
);
3784 /* Can't compile user input into communities attribute. */
3786 vty_out(vty
, "%% Malformed communities attribute\n");
3787 return CMD_WARNING_CONFIG_FAILED
;
3790 /* Set communites attribute string. */
3791 str
= community_str(com
);
3794 argstr
= XCALLOC(MTYPE_TMP
,
3795 strlen(str
) + strlen(" additive") + 1);
3796 strcpy(argstr
, str
);
3797 strcpy(argstr
+ strlen(str
), " additive");
3798 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3799 "community", argstr
);
3800 XFREE(MTYPE_TMP
, argstr
);
3802 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3805 community_free(com
);
3810 DEFUN (set_community_none
,
3811 set_community_none_cmd
,
3812 "set community none",
3814 "BGP community attribute\n"
3815 "No community attribute\n")
3817 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3818 "community", "none");
3821 DEFUN (no_set_community
,
3822 no_set_community_cmd
,
3823 "no set community AA:NN...",
3826 "BGP community attribute\n"
3829 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3834 DEFUN (set_community_delete
,
3835 set_community_delete_cmd
,
3836 "set comm-list <(1-99)|(100-500)|WORD> delete",
3838 "set BGP community list (for deletion)\n"
3839 "Community-list number (standard)\n"
3840 "Community-list number (expanded)\n"
3841 "Community-list name\n"
3842 "Delete matching communities\n")
3844 int idx_comm_list
= 2;
3847 str
= XCALLOC(MTYPE_TMP
,
3848 strlen(argv
[idx_comm_list
]->arg
) + strlen(" delete") + 1);
3849 strcpy(str
, argv
[idx_comm_list
]->arg
);
3850 strcpy(str
+ strlen(argv
[idx_comm_list
]->arg
), " delete");
3852 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
3855 XFREE(MTYPE_TMP
, str
);
3859 DEFUN (no_set_community_delete
,
3860 no_set_community_delete_cmd
,
3861 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
3864 "set BGP community list (for deletion)\n"
3865 "Community-list number (standard)\n"
3866 "Community-list number (expanded)\n"
3867 "Community-list name\n"
3868 "Delete matching communities\n")
3870 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3874 DEFUN (set_lcommunity
,
3876 "set large-community AA:BB:CC...",
3878 "BGP large community attribute\n"
3879 "Large Community number in aa:bb:cc format or additive\n")
3884 str
= argv_concat(argv
, argc
, 2);
3885 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3886 "large-community", str
);
3887 XFREE(MTYPE_TMP
, str
);
3892 DEFUN (set_lcommunity_none
,
3893 set_lcommunity_none_cmd
,
3894 "set large-community none",
3896 "BGP large community attribute\n"
3897 "No large community attribute\n")
3899 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3900 "large-community", "none");
3903 DEFUN (no_set_lcommunity
,
3904 no_set_lcommunity_cmd
,
3905 "no set large-community none",
3908 "BGP large community attribute\n"
3909 "No community attribute\n")
3911 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3912 "large-community", NULL
);
3915 DEFUN (no_set_lcommunity1
,
3916 no_set_lcommunity1_cmd
,
3917 "no set large-community AA:BB:CC...",
3920 "BGP large community attribute\n"
3921 "Large community in AA:BB:CC... format or additive\n")
3923 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3924 "large-community", NULL
);
3927 DEFUN (set_lcommunity_delete
,
3928 set_lcommunity_delete_cmd
,
3929 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
3931 "set BGP large community list (for deletion)\n"
3932 "Large Community-list number (standard)\n"
3933 "Large Communitly-list number (expanded)\n"
3934 "Large Community-list name\n"
3935 "Delete matching large communities\n")
3939 str
= XCALLOC(MTYPE_TMP
, strlen(argv
[2]->arg
) + strlen(" delete") + 1);
3940 strcpy(str
, argv
[2]->arg
);
3941 strcpy(str
+ strlen(argv
[2]->arg
), " delete");
3943 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3944 "large-comm-list", str
);
3946 XFREE(MTYPE_TMP
, str
);
3950 DEFUN (no_set_lcommunity_delete
,
3951 no_set_lcommunity_delete_cmd
,
3952 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
3955 "set BGP large community list (for deletion)\n"
3956 "Large Community-list number (standard)\n"
3957 "Large Communitly-list number (expanded)\n"
3958 "Large Community-list name\n"
3959 "Delete matching large communities\n")
3961 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3962 "large-comm-list", NULL
);
3965 DEFUN (set_ecommunity_rt
,
3966 set_ecommunity_rt_cmd
,
3967 "set extcommunity rt ASN:nn_or_IP-address:nn...",
3969 "BGP extended community attribute\n"
3970 "Route Target extended community\n"
3971 "VPN extended community\n")
3977 str
= argv_concat(argv
, argc
, idx_asn_nn
);
3978 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3979 "extcommunity rt", str
);
3980 XFREE(MTYPE_TMP
, str
);
3985 DEFUN (no_set_ecommunity_rt
,
3986 no_set_ecommunity_rt_cmd
,
3987 "no set extcommunity rt ASN:nn_or_IP-address:nn...",
3990 "BGP extended community attribute\n"
3991 "Route Target extended community\n"
3992 "VPN extended community\n")
3994 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3995 "extcommunity rt", NULL
);
3999 DEFUN (set_ecommunity_soo
,
4000 set_ecommunity_soo_cmd
,
4001 "set extcommunity soo ASN:nn_or_IP-address:nn...",
4003 "BGP extended community attribute\n"
4004 "Site-of-Origin extended community\n"
4005 "VPN extended community\n")
4011 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4012 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4013 "extcommunity soo", str
);
4014 XFREE(MTYPE_TMP
, str
);
4019 DEFUN (no_set_ecommunity_soo
,
4020 no_set_ecommunity_soo_cmd
,
4021 "no set extcommunity soo ASN:nn_or_IP-address:nn...",
4024 "BGP extended community attribute\n"
4025 "Site-of-Origin extended community\n"
4026 "VPN extended community\n")
4028 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4029 "extcommunity soo", NULL
);
4035 "set origin <egp|igp|incomplete>",
4040 "unknown heritage\n")
4043 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4044 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4046 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4047 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4049 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4050 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4051 "origin", "incomplete");
4053 vty_out(vty
, "%% Invalid set origin type\n");
4054 return CMD_WARNING_CONFIG_FAILED
;
4058 DEFUN (no_set_origin
,
4060 "no set origin [<egp|igp|incomplete>]",
4066 "unknown heritage\n")
4068 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4073 DEFUN (set_atomic_aggregate
,
4074 set_atomic_aggregate_cmd
,
4075 "set atomic-aggregate",
4077 "BGP atomic aggregate attribute\n" )
4079 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4080 "atomic-aggregate", NULL
);
4083 DEFUN (no_set_atomic_aggregate
,
4084 no_set_atomic_aggregate_cmd
,
4085 "no set atomic-aggregate",
4088 "BGP atomic aggregate attribute\n" )
4090 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4091 "atomic-aggregate", NULL
);
4094 DEFUN (set_aggregator_as
,
4095 set_aggregator_as_cmd
,
4096 "set aggregator as (1-4294967295) A.B.C.D",
4098 "BGP aggregator attribute\n"
4099 "AS number of aggregator\n"
4101 "IP address of aggregator\n")
4106 struct in_addr address
;
4109 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4111 vty_out(vty
, "Aggregator IP address is invalid\n");
4112 return CMD_WARNING_CONFIG_FAILED
;
4115 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4116 strlen(argv
[idx_number
]->arg
)
4117 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4119 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4121 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4122 "aggregator as", argstr
);
4124 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4130 DEFUN (no_set_aggregator_as
,
4131 no_set_aggregator_as_cmd
,
4132 "no set aggregator as [(1-4294967295) A.B.C.D]",
4135 "BGP aggregator attribute\n"
4136 "AS number of aggregator\n"
4138 "IP address of aggregator\n")
4143 struct in_addr address
;
4146 if (argc
<= idx_asn
)
4147 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4148 "aggregator as", NULL
);
4150 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4152 vty_out(vty
, "Aggregator IP address is invalid\n");
4153 return CMD_WARNING_CONFIG_FAILED
;
4156 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4157 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4160 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4162 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4163 "aggregator as", argstr
);
4165 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4170 DEFUN (match_ipv6_next_hop
,
4171 match_ipv6_next_hop_cmd
,
4172 "match ipv6 next-hop X:X::X:X",
4175 "Match IPv6 next-hop address of route\n"
4176 "IPv6 address of next hop\n")
4179 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4180 RMAP_EVENT_MATCH_ADDED
);
4183 DEFUN (no_match_ipv6_next_hop
,
4184 no_match_ipv6_next_hop_cmd
,
4185 "no match ipv6 next-hop X:X::X:X",
4189 "Match IPv6 next-hop address of route\n"
4190 "IPv6 address of next hop\n")
4193 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4194 RMAP_EVENT_MATCH_DELETED
);
4198 DEFUN (set_ipv6_nexthop_peer
,
4199 set_ipv6_nexthop_peer_cmd
,
4200 "set ipv6 next-hop peer-address",
4203 "Next hop address\n"
4204 "Use peer address (for BGP only)\n")
4206 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4207 "ipv6 next-hop peer-address", NULL
);
4210 DEFUN (no_set_ipv6_nexthop_peer
,
4211 no_set_ipv6_nexthop_peer_cmd
,
4212 "no set ipv6 next-hop peer-address",
4216 "IPv6 next-hop address\n"
4217 "Use peer address (for BGP only)\n")
4219 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4220 "ipv6 next-hop peer-address", NULL
);
4223 DEFUN (set_ipv6_nexthop_prefer_global
,
4224 set_ipv6_nexthop_prefer_global_cmd
,
4225 "set ipv6 next-hop prefer-global",
4228 "IPv6 next-hop address\n"
4229 "Prefer global over link-local if both exist\n")
4231 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4232 "ipv6 next-hop prefer-global", NULL
);
4236 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4237 no_set_ipv6_nexthop_prefer_global_cmd
,
4238 "no set ipv6 next-hop prefer-global",
4242 "IPv6 next-hop address\n"
4243 "Prefer global over link-local if both exist\n")
4245 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4246 "ipv6 next-hop prefer-global", NULL
);
4249 DEFUN (set_ipv6_nexthop_global
,
4250 set_ipv6_nexthop_global_cmd
,
4251 "set ipv6 next-hop global X:X::X:X",
4254 "IPv6 next-hop address\n"
4255 "IPv6 global address\n"
4256 "IPv6 address of next hop\n")
4259 struct in6_addr addr
;
4262 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4264 vty_out(vty
, "%% Malformed nexthop address\n");
4265 return CMD_WARNING_CONFIG_FAILED
;
4267 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4268 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4269 vty_out(vty
, "%% Invalid global nexthop address\n");
4270 return CMD_WARNING_CONFIG_FAILED
;
4273 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4274 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4278 DEFUN (no_set_ipv6_nexthop_global
,
4279 no_set_ipv6_nexthop_global_cmd
,
4280 "no set ipv6 next-hop global X:X::X:X",
4284 "IPv6 next-hop address\n"
4285 "IPv6 global address\n"
4286 "IPv6 address of next hop\n")
4289 if (argc
<= idx_ipv6
)
4290 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4291 "ipv6 next-hop global", NULL
);
4292 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4293 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4296 #ifdef KEEP_OLD_VPN_COMMANDS
4297 DEFUN (set_vpn_nexthop
,
4298 set_vpn_nexthop_cmd
,
4299 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4301 "VPNv4 information\n"
4302 "VPN next-hop address\n"
4303 "IP address of next hop\n"
4304 "VPNv6 information\n"
4305 "VPN next-hop address\n"
4306 "IPv6 address of next hop\n")
4312 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4314 return generic_set_add(
4315 vty
, VTY_GET_CONTEXT(route_map_index
),
4316 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4318 return generic_set_add(
4319 vty
, VTY_GET_CONTEXT(route_map_index
),
4320 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4325 DEFUN (no_set_vpn_nexthop
,
4326 no_set_vpn_nexthop_cmd
,
4327 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4330 "VPNv4 information\n"
4331 "VPN next-hop address\n"
4332 "IP address of next hop\n"
4333 "VPNv6 information\n"
4334 "VPN next-hop address\n"
4335 "IPv6 address of next hop\n")
4345 arg
= argv
[idx_ip
]->arg
;
4346 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4348 return generic_set_delete(
4349 vty
, VTY_GET_CONTEXT(route_map_index
),
4350 "ipv4 vpn next-hop", arg
);
4352 return generic_set_delete(
4353 vty
, VTY_GET_CONTEXT(route_map_index
),
4354 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4358 #endif /* KEEP_OLD_VPN_COMMANDS */
4360 DEFUN (set_ipx_vpn_nexthop
,
4361 set_ipx_vpn_nexthop_cmd
,
4362 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4364 "IPv4 information\n"
4365 "IPv6 information\n"
4367 "VPN next-hop address\n"
4368 "IP address of next hop\n"
4369 "IPv6 address of next hop\n")
4375 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4377 return generic_set_add(
4378 vty
, VTY_GET_CONTEXT(route_map_index
),
4379 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4381 return generic_set_add(
4382 vty
, VTY_GET_CONTEXT(route_map_index
),
4383 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4388 DEFUN (no_set_ipx_vpn_nexthop
,
4389 no_set_ipx_vpn_nexthop_cmd
,
4390 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4393 "IPv4 information\n"
4394 "IPv6 information\n"
4396 "VPN next-hop address\n"
4397 "IP address of next hop\n"
4398 "IPv6 address of next hop\n")
4408 arg
= argv
[idx_ip
]->arg
;
4409 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4411 return generic_set_delete(
4412 vty
, VTY_GET_CONTEXT(route_map_index
),
4413 "ipv4 vpn next-hop", arg
);
4415 return generic_set_delete(
4416 vty
, VTY_GET_CONTEXT(route_map_index
),
4417 "ipv6 vpn next-hop", arg
);
4422 DEFUN (set_originator_id
,
4423 set_originator_id_cmd
,
4424 "set originator-id A.B.C.D",
4426 "BGP originator ID attribute\n"
4427 "IP address of originator\n")
4430 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4431 "originator-id", argv
[idx_ipv4
]->arg
);
4435 DEFUN (no_set_originator_id
,
4436 no_set_originator_id_cmd
,
4437 "no set originator-id [A.B.C.D]",
4440 "BGP originator ID attribute\n"
4441 "IP address of originator\n")
4445 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4447 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4448 "originator-id", arg
);
4452 /* Initialization of route map. */
4453 void bgp_route_map_init(void)
4457 route_map_add_hook(bgp_route_map_add
);
4458 route_map_delete_hook(bgp_route_map_delete
);
4459 route_map_event_hook(bgp_route_map_event
);
4461 route_map_match_interface_hook(generic_match_add
);
4462 route_map_no_match_interface_hook(generic_match_delete
);
4464 route_map_match_ip_address_hook(generic_match_add
);
4465 route_map_no_match_ip_address_hook(generic_match_delete
);
4467 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
4468 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
4470 route_map_match_ip_next_hop_hook(generic_match_add
);
4471 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
4473 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
4474 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
4476 route_map_match_ipv6_address_hook(generic_match_add
);
4477 route_map_no_match_ipv6_address_hook(generic_match_delete
);
4479 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
4480 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
4482 route_map_match_metric_hook(generic_match_add
);
4483 route_map_no_match_metric_hook(generic_match_delete
);
4485 route_map_match_tag_hook(generic_match_add
);
4486 route_map_no_match_tag_hook(generic_match_delete
);
4488 route_map_set_ip_nexthop_hook(generic_set_add
);
4489 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
4491 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
4492 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
4494 route_map_set_metric_hook(generic_set_add
);
4495 route_map_no_set_metric_hook(generic_set_delete
);
4497 route_map_set_tag_hook(generic_set_add
);
4498 route_map_no_set_tag_hook(generic_set_delete
);
4500 route_map_install_match(&route_match_peer_cmd
);
4501 route_map_install_match(&route_match_local_pref_cmd
);
4502 route_map_install_match(&route_match_ip_address_cmd
);
4503 route_map_install_match(&route_match_ip_next_hop_cmd
);
4504 route_map_install_match(&route_match_ip_route_source_cmd
);
4505 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
4506 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
4507 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
4508 route_map_install_match(&route_match_aspath_cmd
);
4509 route_map_install_match(&route_match_community_cmd
);
4510 route_map_install_match(&route_match_lcommunity_cmd
);
4511 route_map_install_match(&route_match_ecommunity_cmd
);
4512 route_map_install_match(&route_match_local_pref_cmd
);
4513 route_map_install_match(&route_match_metric_cmd
);
4514 route_map_install_match(&route_match_origin_cmd
);
4515 route_map_install_match(&route_match_probability_cmd
);
4516 route_map_install_match(&route_match_interface_cmd
);
4517 route_map_install_match(&route_match_tag_cmd
);
4518 route_map_install_match(&route_match_mac_address_cmd
);
4519 route_map_install_match(&route_match_evpn_vni_cmd
);
4521 route_map_install_set(&route_set_ip_nexthop_cmd
);
4522 route_map_install_set(&route_set_local_pref_cmd
);
4523 route_map_install_set(&route_set_weight_cmd
);
4524 route_map_install_set(&route_set_label_index_cmd
);
4525 route_map_install_set(&route_set_metric_cmd
);
4526 route_map_install_set(&route_set_aspath_prepend_cmd
);
4527 route_map_install_set(&route_set_aspath_exclude_cmd
);
4528 route_map_install_set(&route_set_origin_cmd
);
4529 route_map_install_set(&route_set_atomic_aggregate_cmd
);
4530 route_map_install_set(&route_set_aggregator_as_cmd
);
4531 route_map_install_set(&route_set_community_cmd
);
4532 route_map_install_set(&route_set_community_delete_cmd
);
4533 route_map_install_set(&route_set_lcommunity_cmd
);
4534 route_map_install_set(&route_set_lcommunity_delete_cmd
);
4535 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
4536 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
4537 route_map_install_set(&route_set_originator_id_cmd
);
4538 route_map_install_set(&route_set_ecommunity_rt_cmd
);
4539 route_map_install_set(&route_set_ecommunity_soo_cmd
);
4540 route_map_install_set(&route_set_tag_cmd
);
4541 route_map_install_set(&route_set_label_index_cmd
);
4543 install_element(RMAP_NODE
, &match_peer_cmd
);
4544 install_element(RMAP_NODE
, &match_peer_local_cmd
);
4545 install_element(RMAP_NODE
, &no_match_peer_cmd
);
4546 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
4547 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
4548 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
4549 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
4550 install_element(RMAP_NODE
, &match_mac_address_cmd
);
4551 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
4552 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
4553 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
4555 install_element(RMAP_NODE
, &match_aspath_cmd
);
4556 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
4557 install_element(RMAP_NODE
, &match_local_pref_cmd
);
4558 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
4559 install_element(RMAP_NODE
, &match_community_cmd
);
4560 install_element(RMAP_NODE
, &no_match_community_cmd
);
4561 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
4562 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
4563 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
4564 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
4565 install_element(RMAP_NODE
, &match_origin_cmd
);
4566 install_element(RMAP_NODE
, &no_match_origin_cmd
);
4567 install_element(RMAP_NODE
, &match_probability_cmd
);
4568 install_element(RMAP_NODE
, &no_match_probability_cmd
);
4570 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
4571 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
4572 install_element(RMAP_NODE
, &set_local_pref_cmd
);
4573 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
4574 install_element(RMAP_NODE
, &set_weight_cmd
);
4575 install_element(RMAP_NODE
, &set_label_index_cmd
);
4576 install_element(RMAP_NODE
, &no_set_weight_cmd
);
4577 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
4578 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
4579 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
4580 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
4581 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
4582 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
4583 install_element(RMAP_NODE
, &set_origin_cmd
);
4584 install_element(RMAP_NODE
, &no_set_origin_cmd
);
4585 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
4586 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
4587 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
4588 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
4589 install_element(RMAP_NODE
, &set_community_cmd
);
4590 install_element(RMAP_NODE
, &set_community_none_cmd
);
4591 install_element(RMAP_NODE
, &no_set_community_cmd
);
4592 install_element(RMAP_NODE
, &set_community_delete_cmd
);
4593 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
4594 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
4595 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
4596 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
4597 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
4598 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
4599 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
4600 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
4601 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
4602 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
4603 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
4604 #ifdef KEEP_OLD_VPN_COMMANDS
4605 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
4606 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
4607 #endif /* KEEP_OLD_VPN_COMMANDS */
4608 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
4609 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
4610 install_element(RMAP_NODE
, &set_originator_id_cmd
);
4611 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
4613 route_map_install_match(&route_match_ipv6_address_cmd
);
4614 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
4615 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
4616 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
4617 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
4618 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
4619 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
4621 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
4622 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
4623 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
4624 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
4625 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
4626 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
4627 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
4628 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
4631 void bgp_route_map_terminate(void)
4633 /* ToDo: Cleanup all the used memory */
4635 route_map_add_hook(NULL
);
4636 route_map_delete_hook(NULL
);
4637 route_map_event_hook(NULL
);