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 struct bgp_match_peer_compiled
{
230 /* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
232 /* Compares the peer specified in the 'match peer' clause with the peer
233 received in bgp_info->peer. If it is the same, or if the peer structure
234 received is a peer_group containing it, returns RMAP_MATCH. */
235 static route_map_result_t
route_match_peer(void *rule
, struct prefix
*prefix
,
236 route_map_object_t type
,
239 struct bgp_match_peer_compiled
*pc
;
241 union sockunion su_def
= {
242 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
243 struct peer_group
*group
;
245 struct listnode
*node
, *nnode
;
247 if (type
== RMAP_BGP
) {
250 peer
= ((struct bgp_info
*)object
)->peer
;
256 if (strcmp(peer
->conf_if
, pc
->interface
) == 0)
262 /* If su='0.0.0.0' (command 'match peer local'), and it's a
264 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH
266 if (sockunion_same(su
, &su_def
)) {
268 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
269 || CHECK_FLAG(peer
->rmap_type
,
270 PEER_RMAP_TYPE_REDISTRIBUTE
)
271 || CHECK_FLAG(peer
->rmap_type
,
272 PEER_RMAP_TYPE_DEFAULT
))
279 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
280 if (sockunion_same(su
, &peer
->su
))
286 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
288 if (sockunion_same(su
, &peer
->su
))
297 static void *route_match_peer_compile(const char *arg
)
299 struct bgp_match_peer_compiled
*pc
;
302 pc
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
303 sizeof(struct bgp_match_peer_compiled
));
305 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", &pc
->su
);
307 pc
->interface
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
314 /* Free route map's compiled `ip address' value. */
315 static void route_match_peer_free(void *rule
)
317 struct bgp_match_peer_compiled
*pc
= rule
;
320 XFREE(MTYPE_ROUTE_MAP_COMPILED
, pc
->interface
);
322 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
325 /* Route map commands for ip address matching. */
326 struct route_map_rule_cmd route_match_peer_cmd
= {"peer", route_match_peer
,
327 route_match_peer_compile
,
328 route_match_peer_free
};
330 /* `match ip address IP_ACCESS_LIST' */
332 /* Match function should return 1 if match is success else return
334 static route_map_result_t
route_match_ip_address(void *rule
,
335 struct prefix
*prefix
,
336 route_map_object_t type
,
339 struct access_list
*alist
;
340 /* struct prefix_ipv4 match; */
342 if (type
== RMAP_BGP
) {
343 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
347 return (access_list_apply(alist
, prefix
) == FILTER_DENY
354 /* Route map `ip address' match statement. `arg' should be
356 static void *route_match_ip_address_compile(const char *arg
)
358 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
361 /* Free route map's compiled `ip address' value. */
362 static void route_match_ip_address_free(void *rule
)
364 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
367 /* Route map commands for ip address matching. */
368 struct route_map_rule_cmd route_match_ip_address_cmd
= {
369 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
370 route_match_ip_address_free
};
372 /* `match ip next-hop IP_ADDRESS' */
374 /* Match function return 1 if match is success else return zero. */
375 static route_map_result_t
route_match_ip_next_hop(void *rule
,
376 struct prefix
*prefix
,
377 route_map_object_t type
,
380 struct access_list
*alist
;
381 struct bgp_info
*bgp_info
;
382 struct prefix_ipv4 p
;
384 if (type
== RMAP_BGP
) {
387 p
.prefix
= bgp_info
->attr
->nexthop
;
388 p
.prefixlen
= IPV4_MAX_BITLEN
;
390 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
394 return (access_list_apply(alist
, &p
) == FILTER_DENY
401 /* Route map `ip next-hop' match statement. `arg' is
403 static void *route_match_ip_next_hop_compile(const char *arg
)
405 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
408 /* Free route map's compiled `ip address' value. */
409 static void route_match_ip_next_hop_free(void *rule
)
411 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
414 /* Route map commands for ip next-hop matching. */
415 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
416 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
417 route_match_ip_next_hop_free
};
419 /* `match ip route-source ACCESS-LIST' */
421 /* Match function return 1 if match is success else return zero. */
422 static route_map_result_t
route_match_ip_route_source(void *rule
,
423 struct prefix
*prefix
,
424 route_map_object_t type
,
427 struct access_list
*alist
;
428 struct bgp_info
*bgp_info
;
430 struct prefix_ipv4 p
;
432 if (type
== RMAP_BGP
) {
434 peer
= bgp_info
->peer
;
436 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
440 p
.prefix
= peer
->su
.sin
.sin_addr
;
441 p
.prefixlen
= IPV4_MAX_BITLEN
;
443 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
447 return (access_list_apply(alist
, &p
) == FILTER_DENY
454 /* Route map `ip route-source' match statement. `arg' is
456 static void *route_match_ip_route_source_compile(const char *arg
)
458 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
461 /* Free route map's compiled `ip address' value. */
462 static void route_match_ip_route_source_free(void *rule
)
464 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
467 /* Route map commands for ip route-source matching. */
468 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
469 "ip route-source", route_match_ip_route_source
,
470 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
472 /* `match ip address prefix-list PREFIX_LIST' */
474 static route_map_result_t
475 route_match_ip_address_prefix_list(void *rule
, struct prefix
*prefix
,
476 route_map_object_t type
, void *object
)
478 struct prefix_list
*plist
;
480 if (type
== RMAP_BGP
) {
481 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
485 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
492 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
494 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
497 static void route_match_ip_address_prefix_list_free(void *rule
)
499 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
502 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
503 "ip address prefix-list", route_match_ip_address_prefix_list
,
504 route_match_ip_address_prefix_list_compile
,
505 route_match_ip_address_prefix_list_free
};
507 /* `match ip next-hop prefix-list PREFIX_LIST' */
509 static route_map_result_t
510 route_match_ip_next_hop_prefix_list(void *rule
, struct prefix
*prefix
,
511 route_map_object_t type
, void *object
)
513 struct prefix_list
*plist
;
514 struct bgp_info
*bgp_info
;
515 struct prefix_ipv4 p
;
517 if (type
== RMAP_BGP
) {
520 p
.prefix
= bgp_info
->attr
->nexthop
;
521 p
.prefixlen
= IPV4_MAX_BITLEN
;
523 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
527 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
534 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
536 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
539 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
541 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
544 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
545 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
546 route_match_ip_next_hop_prefix_list_compile
,
547 route_match_ip_next_hop_prefix_list_free
};
549 /* `match ip route-source prefix-list PREFIX_LIST' */
551 static route_map_result_t
552 route_match_ip_route_source_prefix_list(void *rule
, struct prefix
*prefix
,
553 route_map_object_t type
, void *object
)
555 struct prefix_list
*plist
;
556 struct bgp_info
*bgp_info
;
558 struct prefix_ipv4 p
;
560 if (type
== RMAP_BGP
) {
562 peer
= bgp_info
->peer
;
564 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
568 p
.prefix
= peer
->su
.sin
.sin_addr
;
569 p
.prefixlen
= IPV4_MAX_BITLEN
;
571 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
575 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
582 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
584 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
587 static void route_match_ip_route_source_prefix_list_free(void *rule
)
589 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
592 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
593 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
594 route_match_ip_route_source_prefix_list_compile
,
595 route_match_ip_route_source_prefix_list_free
};
597 /* `match mac address MAC_ACCESS_LIST' */
599 /* Match function should return 1 if match is success else return
601 static route_map_result_t
route_match_mac_address(void *rule
,
602 struct prefix
*prefix
,
603 route_map_object_t type
,
606 struct access_list
*alist
;
609 if (type
== RMAP_BGP
) {
610 alist
= access_list_lookup(AFI_L2VPN
, (char *)rule
);
614 if (prefix
->u
.prefix_evpn
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
617 p
.family
= AF_ETHERNET
;
618 p
.prefixlen
= ETH_ALEN
* 8;
619 p
.u
.prefix_eth
= prefix
->u
.prefix_evpn
.mac
;
621 return (access_list_apply(alist
, &p
)
630 /* Route map `mac address' match statement. `arg' should be
632 static void *route_match_mac_address_compile(const char *arg
)
634 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
637 /* Free route map's compiled `ip address' value. */
638 static void route_match_mac_address_free(void *rule
)
640 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
643 /* Route map commands for mac address matching. */
644 struct route_map_rule_cmd route_match_mac_address_cmd
= {
645 "mac address", route_match_mac_address
, route_match_mac_address_compile
,
646 route_match_mac_address_free
};
650 /* Match function should return 1 if match is success else return
652 static route_map_result_t
route_match_vni(void *rule
, struct prefix
*prefix
,
653 route_map_object_t type
, void *object
)
656 struct bgp_info
*bgp_info
= NULL
;
658 if (type
== RMAP_BGP
) {
659 vni
= *((vni_t
*)rule
);
660 bgp_info
= (struct bgp_info
*)object
;
662 if (vni
== label2vni(&bgp_info
->extra
->label
))
669 /* Route map `vni' match statement. */
670 static void *route_match_vni_compile(const char *arg
)
675 vni
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(vni_t
));
679 *vni
= strtoul(arg
, &end
, 10);
681 XFREE(MTYPE_ROUTE_MAP_COMPILED
, vni
);
688 /* Free route map's compiled `vni' value. */
689 static void route_match_vni_free(void *rule
)
691 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
694 /* Route map commands for vni matching. */
695 struct route_map_rule_cmd route_match_evpn_vni_cmd
= {
696 "evpn vni", route_match_vni
, route_match_vni_compile
,
697 route_match_vni_free
};
699 /* `match local-preference LOCAL-PREF' */
701 /* Match function return 1 if match is success else return zero. */
702 static route_map_result_t
route_match_local_pref(void *rule
,
703 struct prefix
*prefix
,
704 route_map_object_t type
,
707 u_int32_t
*local_pref
;
708 struct bgp_info
*bgp_info
;
710 if (type
== RMAP_BGP
) {
714 if (bgp_info
->attr
->local_pref
== *local_pref
)
722 /* Route map `match local-preference' match statement.
723 `arg' is local-pref value */
724 static void *route_match_local_pref_compile(const char *arg
)
726 u_int32_t
*local_pref
;
728 unsigned long tmpval
;
730 /* Locpref value shoud be integer. */
735 tmpval
= strtoul(arg
, &endptr
, 10);
736 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
739 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(u_int32_t
));
744 *local_pref
= tmpval
;
748 /* Free route map's compiled `match local-preference' value. */
749 static void route_match_local_pref_free(void *rule
)
751 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
754 /* Route map commands for metric matching. */
755 struct route_map_rule_cmd route_match_local_pref_cmd
= {
756 "local-preference", route_match_local_pref
,
757 route_match_local_pref_compile
, route_match_local_pref_free
};
759 /* `match metric METRIC' */
761 /* Match function return 1 if match is success else return zero. */
762 static route_map_result_t
route_match_metric(void *rule
, struct prefix
*prefix
,
763 route_map_object_t type
,
766 struct rmap_value
*rv
;
767 struct bgp_info
*bgp_info
;
769 if (type
== RMAP_BGP
) {
772 return route_value_match(rv
, bgp_info
->attr
->med
);
777 /* Route map commands for metric matching. */
778 struct route_map_rule_cmd route_match_metric_cmd
= {
779 "metric", route_match_metric
, route_value_compile
, route_value_free
,
782 /* `match as-path ASPATH' */
784 /* Match function for as-path match. I assume given object is */
785 static route_map_result_t
route_match_aspath(void *rule
, struct prefix
*prefix
,
786 route_map_object_t type
,
790 struct as_list
*as_list
;
791 struct bgp_info
*bgp_info
;
793 if (type
== RMAP_BGP
) {
794 as_list
= as_list_lookup((char *)rule
);
801 return ((as_list_apply(as_list
, bgp_info
->attr
->aspath
)
809 /* Compile function for as-path match. */
810 static void *route_match_aspath_compile(const char *arg
)
812 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
815 /* Compile function for as-path match. */
816 static void route_match_aspath_free(void *rule
)
818 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
821 /* Route map commands for aspath matching. */
822 struct route_map_rule_cmd route_match_aspath_cmd
= {
823 "as-path", route_match_aspath
, route_match_aspath_compile
,
824 route_match_aspath_free
};
826 /* `match community COMMUNIY' */
827 struct rmap_community
{
832 /* Match function for community match. */
833 static route_map_result_t
route_match_community(void *rule
,
834 struct prefix
*prefix
,
835 route_map_object_t type
,
838 struct community_list
*list
;
839 struct bgp_info
*bgp_info
;
840 struct rmap_community
*rcom
;
842 if (type
== RMAP_BGP
) {
846 list
= community_list_lookup(bgp_clist
, rcom
->name
,
847 COMMUNITY_LIST_MASTER
);
852 if (community_list_exact_match(
853 bgp_info
->attr
->community
, list
))
856 if (community_list_match(bgp_info
->attr
->community
,
864 /* Compile function for community match. */
865 static void *route_match_community_compile(const char *arg
)
867 struct rmap_community
*rcom
;
871 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
873 p
= strchr(arg
, ' ');
876 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
877 memcpy(rcom
->name
, arg
, len
);
880 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
886 /* Compile function for community match. */
887 static void route_match_community_free(void *rule
)
889 struct rmap_community
*rcom
= rule
;
891 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
892 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
895 /* Route map commands for community matching. */
896 struct route_map_rule_cmd route_match_community_cmd
= {
897 "community", route_match_community
, route_match_community_compile
,
898 route_match_community_free
};
900 /* Match function for lcommunity match. */
901 static route_map_result_t
route_match_lcommunity(void *rule
,
902 struct prefix
*prefix
,
903 route_map_object_t type
,
906 struct community_list
*list
;
907 struct bgp_info
*bgp_info
;
908 struct rmap_community
*rcom
;
910 if (type
== RMAP_BGP
) {
914 list
= community_list_lookup(bgp_clist
, rcom
->name
,
915 LARGE_COMMUNITY_LIST_MASTER
);
919 if (lcommunity_list_match(bgp_info
->attr
->lcommunity
, list
))
925 /* Compile function for community match. */
926 static void *route_match_lcommunity_compile(const char *arg
)
928 struct rmap_community
*rcom
;
932 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
934 p
= strchr(arg
, ' ');
937 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
938 memcpy(rcom
->name
, arg
, len
);
940 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
946 /* Compile function for community match. */
947 static void route_match_lcommunity_free(void *rule
)
949 struct rmap_community
*rcom
= rule
;
951 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
952 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
955 /* Route map commands for community matching. */
956 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
957 "large-community", route_match_lcommunity
,
958 route_match_lcommunity_compile
, route_match_lcommunity_free
};
961 /* Match function for extcommunity match. */
962 static route_map_result_t
route_match_ecommunity(void *rule
,
963 struct prefix
*prefix
,
964 route_map_object_t type
,
967 struct community_list
*list
;
968 struct bgp_info
*bgp_info
;
970 if (type
== RMAP_BGP
) {
973 list
= community_list_lookup(bgp_clist
, (char *)rule
,
974 EXTCOMMUNITY_LIST_MASTER
);
978 if (ecommunity_list_match(bgp_info
->attr
->ecommunity
, list
))
984 /* Compile function for extcommunity match. */
985 static void *route_match_ecommunity_compile(const char *arg
)
987 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
990 /* Compile function for extcommunity match. */
991 static void route_match_ecommunity_free(void *rule
)
993 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
996 /* Route map commands for community matching. */
997 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
998 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
999 route_match_ecommunity_free
};
1001 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
1002 and `address-family vpnv4'. */
1004 /* `match origin' */
1005 static route_map_result_t
route_match_origin(void *rule
, struct prefix
*prefix
,
1006 route_map_object_t type
,
1010 struct bgp_info
*bgp_info
;
1012 if (type
== RMAP_BGP
) {
1016 if (bgp_info
->attr
->origin
== *origin
)
1020 return RMAP_NOMATCH
;
1023 static void *route_match_origin_compile(const char *arg
)
1027 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(u_char
));
1029 if (strcmp(arg
, "igp") == 0)
1031 else if (strcmp(arg
, "egp") == 0)
1039 /* Free route map's compiled `ip address' value. */
1040 static void route_match_origin_free(void *rule
)
1042 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1045 /* Route map commands for origin matching. */
1046 struct route_map_rule_cmd route_match_origin_cmd
= {
1047 "origin", route_match_origin
, route_match_origin_compile
,
1048 route_match_origin_free
};
1050 /* match probability { */
1052 static route_map_result_t
route_match_probability(void *rule
,
1053 struct prefix
*prefix
,
1054 route_map_object_t type
,
1059 switch (*(long *)rule
) {
1065 if (r
< *(long *)rule
) {
1070 return RMAP_NOMATCH
;
1073 static void *route_match_probability_compile(const char *arg
)
1079 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
1089 *lobule
= RAND_MAX
/ 100 * perc
;
1095 static void route_match_probability_free(void *rule
)
1097 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1100 struct route_map_rule_cmd route_match_probability_cmd
= {
1101 "probability", route_match_probability
, route_match_probability_compile
,
1102 route_match_probability_free
};
1104 /* `match interface IFNAME' */
1105 /* Match function should return 1 if match is success else return
1107 static route_map_result_t
route_match_interface(void *rule
,
1108 struct prefix
*prefix
,
1109 route_map_object_t type
,
1112 struct interface
*ifp
;
1113 struct bgp_info
*info
;
1115 if (type
== RMAP_BGP
) {
1118 if (!info
|| !info
->attr
)
1119 return RMAP_NOMATCH
;
1121 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
1123 if (ifp
== NULL
|| ifp
->ifindex
!= info
->attr
->nh_ifindex
)
1124 return RMAP_NOMATCH
;
1128 return RMAP_NOMATCH
;
1131 /* Route map `interface' match statement. `arg' should be
1133 static void *route_match_interface_compile(const char *arg
)
1135 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1138 /* Free route map's compiled `interface' value. */
1139 static void route_match_interface_free(void *rule
)
1141 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1144 /* Route map commands for ip address matching. */
1145 struct route_map_rule_cmd route_match_interface_cmd
= {
1146 "interface", route_match_interface
, route_match_interface_compile
,
1147 route_match_interface_free
};
1151 /* `set ip next-hop IP_ADDRESS' */
1153 /* Match function return 1 if match is success else return zero. */
1154 static route_map_result_t
route_match_tag(void *rule
, struct prefix
*prefix
,
1155 route_map_object_t type
, void *object
)
1158 struct bgp_info
*bgp_info
;
1160 if (type
== RMAP_BGP
) {
1164 return ((bgp_info
->attr
->tag
== *tag
) ? RMAP_MATCH
1168 return RMAP_NOMATCH
;
1172 /* Route map commands for tag matching. */
1173 static struct route_map_rule_cmd route_match_tag_cmd
= {
1174 "tag", route_match_tag
, route_map_rule_tag_compile
,
1175 route_map_rule_tag_free
,
1179 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1180 struct rmap_ip_nexthop_set
{
1181 struct in_addr
*address
;
1186 static route_map_result_t
route_set_ip_nexthop(void *rule
,
1187 struct prefix
*prefix
,
1188 route_map_object_t type
,
1191 struct rmap_ip_nexthop_set
*rins
= rule
;
1192 struct bgp_info
*bgp_info
;
1195 if (type
== RMAP_BGP
) {
1197 peer
= bgp_info
->peer
;
1199 if (rins
->unchanged
) {
1200 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1201 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1202 } else if (rins
->peer_address
) {
1203 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1204 || CHECK_FLAG(peer
->rmap_type
,
1205 PEER_RMAP_TYPE_IMPORT
))
1207 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1208 bgp_info
->attr
->nexthop
.s_addr
=
1209 sockunion2ip(peer
->su_remote
);
1210 bgp_info
->attr
->flag
|=
1211 ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1212 } else if (CHECK_FLAG(peer
->rmap_type
,
1213 PEER_RMAP_TYPE_OUT
)) {
1214 /* The next hop value will be set as part of
1216 * Set the flags here to indicate that rewrite
1218 * Also, clear the value.
1220 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1221 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1222 bgp_info
->attr
->nexthop
.s_addr
= 0;
1225 /* Set next hop value. */
1226 bgp_info
->attr
->flag
|=
1227 ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1228 bgp_info
->attr
->nexthop
= *rins
->address
;
1229 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1230 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1237 /* Route map `ip nexthop' compile function. Given string is converted
1238 to struct in_addr structure. */
1239 static void *route_set_ip_nexthop_compile(const char *arg
)
1241 struct rmap_ip_nexthop_set
*rins
;
1242 struct in_addr
*address
= NULL
;
1243 int peer_address
= 0;
1247 if (strcmp(arg
, "peer-address") == 0)
1249 else if (strcmp(arg
, "unchanged") == 0)
1252 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1253 sizeof(struct in_addr
));
1254 ret
= inet_aton(arg
, address
);
1257 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1262 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1263 sizeof(struct rmap_ip_nexthop_set
));
1265 rins
->address
= address
;
1266 rins
->peer_address
= peer_address
;
1267 rins
->unchanged
= unchanged
;
1272 /* Free route map's compiled `ip nexthop' value. */
1273 static void route_set_ip_nexthop_free(void *rule
)
1275 struct rmap_ip_nexthop_set
*rins
= rule
;
1278 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1280 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1283 /* Route map commands for ip nexthop set. */
1284 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1285 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1286 route_set_ip_nexthop_free
};
1288 /* `set local-preference LOCAL_PREF' */
1290 /* Set local preference. */
1291 static route_map_result_t
route_set_local_pref(void *rule
,
1292 struct prefix
*prefix
,
1293 route_map_object_t type
,
1296 struct rmap_value
*rv
;
1297 struct bgp_info
*bgp_info
;
1298 u_int32_t locpref
= 0;
1300 if (type
== RMAP_BGP
) {
1301 /* Fetch routemap's rule information. */
1305 /* Set local preference value. */
1306 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1307 locpref
= bgp_info
->attr
->local_pref
;
1309 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1310 bgp_info
->attr
->local_pref
=
1311 route_value_adjust(rv
, locpref
, bgp_info
->peer
);
1317 /* Set local preference rule structure. */
1318 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1319 "local-preference", route_set_local_pref
, route_value_compile
,
1323 /* `set weight WEIGHT' */
1326 static route_map_result_t
route_set_weight(void *rule
, struct prefix
*prefix
,
1327 route_map_object_t type
,
1330 struct rmap_value
*rv
;
1331 struct bgp_info
*bgp_info
;
1333 if (type
== RMAP_BGP
) {
1334 /* Fetch routemap's rule information. */
1338 /* Set weight value. */
1339 bgp_info
->attr
->weight
=
1340 route_value_adjust(rv
, 0, bgp_info
->peer
);
1346 /* Set local preference rule structure. */
1347 struct route_map_rule_cmd route_set_weight_cmd
= {
1348 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1351 /* `set metric METRIC' */
1353 /* Set metric to attribute. */
1354 static route_map_result_t
route_set_metric(void *rule
, struct prefix
*prefix
,
1355 route_map_object_t type
,
1358 struct rmap_value
*rv
;
1359 struct bgp_info
*bgp_info
;
1362 if (type
== RMAP_BGP
) {
1363 /* Fetch routemap's rule information. */
1367 if (bgp_info
->attr
->flag
1368 & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1369 med
= bgp_info
->attr
->med
;
1371 bgp_info
->attr
->med
=
1372 route_value_adjust(rv
, med
, bgp_info
->peer
);
1373 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1378 /* Set metric rule structure. */
1379 struct route_map_rule_cmd route_set_metric_cmd
= {
1380 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1383 /* `set as-path prepend ASPATH' */
1385 /* For AS path prepend mechanism. */
1386 static route_map_result_t
route_set_aspath_prepend(void *rule
,
1387 struct prefix
*prefix
,
1388 route_map_object_t type
,
1391 struct aspath
*aspath
;
1393 struct bgp_info
*binfo
;
1395 if (type
== RMAP_BGP
) {
1398 if (binfo
->attr
->aspath
->refcnt
)
1399 new = aspath_dup(binfo
->attr
->aspath
);
1401 new = binfo
->attr
->aspath
;
1403 if ((uintptr_t)rule
> 10) {
1405 aspath_prepend(aspath
, new);
1407 as_t as
= aspath_leftmost(new);
1409 as
= binfo
->peer
->as
;
1410 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1413 binfo
->attr
->aspath
= new;
1419 static void *route_set_aspath_prepend_compile(const char *arg
)
1423 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1424 return (void *)(uintptr_t)num
;
1426 return route_aspath_compile(arg
);
1429 static void route_set_aspath_prepend_free(void *rule
)
1431 if ((uintptr_t)rule
> 10)
1432 route_aspath_free(rule
);
1436 /* Set as-path prepend rule structure. */
1437 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1438 "as-path prepend", route_set_aspath_prepend
,
1439 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1442 /* `set as-path exclude ASn' */
1444 /* For ASN exclude mechanism.
1445 * Iterate over ASns requested and filter them from the given AS_PATH one by
1447 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1449 static route_map_result_t
route_set_aspath_exclude(void *rule
,
1450 struct prefix
*dummy
,
1451 route_map_object_t type
,
1454 struct aspath
*new_path
, *exclude_path
;
1455 struct bgp_info
*binfo
;
1457 if (type
== RMAP_BGP
) {
1458 exclude_path
= rule
;
1460 if (binfo
->attr
->aspath
->refcnt
)
1461 new_path
= aspath_dup(binfo
->attr
->aspath
);
1463 new_path
= binfo
->attr
->aspath
;
1464 binfo
->attr
->aspath
=
1465 aspath_filter_exclude(new_path
, exclude_path
);
1470 /* Set ASn exlude rule structure. */
1471 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1472 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1476 /* `set community COMMUNITY' */
1477 struct rmap_com_set
{
1478 struct community
*com
;
1483 /* For community set mechanism. */
1484 static route_map_result_t
route_set_community(void *rule
, struct prefix
*prefix
,
1485 route_map_object_t type
,
1488 struct rmap_com_set
*rcs
;
1489 struct bgp_info
*binfo
;
1491 struct community
*new = NULL
;
1492 struct community
*old
;
1493 struct community
*merge
;
1495 if (type
== RMAP_BGP
) {
1499 old
= attr
->community
;
1503 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1504 attr
->community
= NULL
;
1505 /* See the longer comment down below. */
1506 if (old
&& old
->refcnt
== 0)
1507 community_free(old
);
1511 /* "additive" case. */
1512 if (rcs
->additive
&& old
) {
1513 merge
= community_merge(community_dup(old
), rcs
->com
);
1515 new = community_uniq_sort(merge
);
1516 community_free(merge
);
1518 new = community_dup(rcs
->com
);
1520 /* HACK: if the old community is not intern'd,
1521 * we should free it here, or all reference to it may be
1523 * Really need to cleanup attribute caching sometime.
1525 if (old
&& old
->refcnt
== 0)
1526 community_free(old
);
1528 /* will be interned by caller if required */
1529 attr
->community
= new;
1531 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1537 /* Compile function for set community. */
1538 static void *route_set_community_compile(const char *arg
)
1540 struct rmap_com_set
*rcs
;
1541 struct community
*com
= NULL
;
1546 if (strcmp(arg
, "none") == 0)
1549 sp
= strstr(arg
, "additive");
1551 if (sp
&& sp
> arg
) {
1552 /* "additive" keyword is included. */
1557 com
= community_str2com(arg
);
1566 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1568 rcs
->additive
= additive
;
1574 /* Free function for set community. */
1575 static void route_set_community_free(void *rule
)
1577 struct rmap_com_set
*rcs
= rule
;
1580 community_free(rcs
->com
);
1581 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1584 /* Set community rule structure. */
1585 struct route_map_rule_cmd route_set_community_cmd
= {
1586 "community", route_set_community
, route_set_community_compile
,
1587 route_set_community_free
,
1590 /* `set community COMMUNITY' */
1591 struct rmap_lcom_set
{
1592 struct lcommunity
*lcom
;
1598 /* For lcommunity set mechanism. */
1599 static route_map_result_t
route_set_lcommunity(void *rule
,
1600 struct prefix
*prefix
,
1601 route_map_object_t type
,
1604 struct rmap_lcom_set
*rcs
;
1605 struct bgp_info
*binfo
;
1607 struct lcommunity
*new = NULL
;
1608 struct lcommunity
*old
;
1609 struct lcommunity
*merge
;
1611 if (type
== RMAP_BGP
) {
1615 old
= attr
->lcommunity
;
1620 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
1621 attr
->lcommunity
= NULL
;
1623 /* See the longer comment down below. */
1624 if (old
&& old
->refcnt
== 0)
1625 lcommunity_free(&old
);
1629 if (rcs
->additive
&& old
) {
1630 merge
= lcommunity_merge(lcommunity_dup(old
),
1633 new = lcommunity_uniq_sort(merge
);
1634 lcommunity_free(&merge
);
1636 new = lcommunity_dup(rcs
->lcom
);
1638 /* HACK: if the old large-community is not intern'd,
1639 * we should free it here, or all reference to it may be
1641 * Really need to cleanup attribute caching sometime.
1643 if (old
&& old
->refcnt
== 0)
1644 lcommunity_free(&old
);
1646 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1647 attr
->lcommunity
= new;
1649 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
1655 /* Compile function for set community. */
1656 static void *route_set_lcommunity_compile(const char *arg
)
1658 struct rmap_lcom_set
*rcs
;
1659 struct lcommunity
*lcom
= NULL
;
1664 if (strcmp(arg
, "none") == 0)
1667 sp
= strstr(arg
, "additive");
1669 if (sp
&& sp
> arg
) {
1670 /* "additive" keyworkd is included. */
1675 lcom
= lcommunity_str2com(arg
);
1684 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1686 rcs
->additive
= additive
;
1692 /* Free function for set lcommunity. */
1693 static void route_set_lcommunity_free(void *rule
)
1695 struct rmap_lcom_set
*rcs
= rule
;
1698 lcommunity_free(&rcs
->lcom
);
1700 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1703 /* Set community rule structure. */
1704 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
1705 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
1706 route_set_lcommunity_free
,
1709 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
1711 /* For large community set mechanism. */
1712 static route_map_result_t
route_set_lcommunity_delete(void *rule
,
1713 struct prefix
*prefix
,
1714 route_map_object_t type
,
1717 struct community_list
*list
;
1718 struct lcommunity
*merge
;
1719 struct lcommunity
*new;
1720 struct lcommunity
*old
;
1721 struct bgp_info
*binfo
;
1723 if (type
== RMAP_BGP
) {
1728 list
= community_list_lookup(bgp_clist
, rule
,
1729 LARGE_COMMUNITY_LIST_MASTER
);
1730 old
= binfo
->attr
->lcommunity
;
1733 merge
= lcommunity_list_match_delete(
1734 lcommunity_dup(old
), list
);
1735 new = lcommunity_uniq_sort(merge
);
1736 lcommunity_free(&merge
);
1738 /* HACK: if the old community is not intern'd,
1739 * we should free it here, or all reference to it may be
1741 * Really need to cleanup attribute caching sometime.
1743 if (old
->refcnt
== 0)
1744 lcommunity_free(&old
);
1746 if (new->size
== 0) {
1747 binfo
->attr
->lcommunity
= NULL
;
1748 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT(
1749 BGP_ATTR_LARGE_COMMUNITIES
);
1750 lcommunity_free(&new);
1752 binfo
->attr
->lcommunity
= new;
1753 binfo
->attr
->flag
|= ATTR_FLAG_BIT(
1754 BGP_ATTR_LARGE_COMMUNITIES
);
1762 /* Compile function for set lcommunity. */
1763 static void *route_set_lcommunity_delete_compile(const char *arg
)
1769 p
= strchr(arg
, ' ');
1772 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1773 memcpy(str
, arg
, len
);
1780 /* Free function for set lcommunity. */
1781 static void route_set_lcommunity_delete_free(void *rule
)
1783 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1786 /* Set lcommunity rule structure. */
1787 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
1788 "large-comm-list", route_set_lcommunity_delete
,
1789 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
1793 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
1795 /* For community set mechanism. */
1796 static route_map_result_t
route_set_community_delete(void *rule
,
1797 struct prefix
*prefix
,
1798 route_map_object_t type
,
1801 struct community_list
*list
;
1802 struct community
*merge
;
1803 struct community
*new;
1804 struct community
*old
;
1805 struct bgp_info
*binfo
;
1807 if (type
== RMAP_BGP
) {
1812 list
= community_list_lookup(bgp_clist
, rule
,
1813 COMMUNITY_LIST_MASTER
);
1814 old
= binfo
->attr
->community
;
1817 merge
= community_list_match_delete(community_dup(old
),
1819 new = community_uniq_sort(merge
);
1820 community_free(merge
);
1822 /* HACK: if the old community is not intern'd,
1823 * we should free it here, or all reference to it may be
1825 * Really need to cleanup attribute caching sometime.
1827 if (old
->refcnt
== 0)
1828 community_free(old
);
1830 if (new->size
== 0) {
1831 binfo
->attr
->community
= NULL
;
1832 binfo
->attr
->flag
&=
1833 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1834 community_free(new);
1836 binfo
->attr
->community
= new;
1837 binfo
->attr
->flag
|=
1838 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1846 /* Compile function for set community. */
1847 static void *route_set_community_delete_compile(const char *arg
)
1853 p
= strchr(arg
, ' ');
1856 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1857 memcpy(str
, arg
, len
);
1864 /* Free function for set community. */
1865 static void route_set_community_delete_free(void *rule
)
1867 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1870 /* Set community rule structure. */
1871 struct route_map_rule_cmd route_set_community_delete_cmd
= {
1872 "comm-list", route_set_community_delete
,
1873 route_set_community_delete_compile
, route_set_community_delete_free
,
1876 /* `set extcommunity rt COMMUNITY' */
1878 /* For community set mechanism. Used by _rt and _soo. */
1879 static route_map_result_t
route_set_ecommunity(void *rule
,
1880 struct prefix
*prefix
,
1881 route_map_object_t type
,
1884 struct ecommunity
*ecom
;
1885 struct ecommunity
*new_ecom
;
1886 struct ecommunity
*old_ecom
;
1887 struct bgp_info
*bgp_info
;
1889 if (type
== RMAP_BGP
) {
1896 /* We assume additive for Extended Community. */
1897 old_ecom
= bgp_info
->attr
->ecommunity
;
1900 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
1903 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
1904 * bgp_update_receive()
1905 * ->refcnt = 0 => set by a previous route-map
1907 if (!old_ecom
->refcnt
)
1908 ecommunity_free(&old_ecom
);
1910 new_ecom
= ecommunity_dup(ecom
);
1912 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1913 bgp_info
->attr
->ecommunity
= new_ecom
;
1915 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
1920 /* Compile function for set community. */
1921 static void *route_set_ecommunity_rt_compile(const char *arg
)
1923 struct ecommunity
*ecom
;
1925 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
1928 return ecommunity_intern(ecom
);
1931 /* Free function for set community. Used by _rt and _soo */
1932 static void route_set_ecommunity_free(void *rule
)
1934 struct ecommunity
*ecom
= rule
;
1935 ecommunity_unintern(&ecom
);
1938 /* Set community rule structure. */
1939 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
1940 "extcommunity rt", route_set_ecommunity
,
1941 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
1944 /* `set extcommunity soo COMMUNITY' */
1946 /* Compile function for set community. */
1947 static void *route_set_ecommunity_soo_compile(const char *arg
)
1949 struct ecommunity
*ecom
;
1951 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
1955 return ecommunity_intern(ecom
);
1958 /* Set community rule structure. */
1959 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
1960 "extcommunity soo", route_set_ecommunity
,
1961 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
1964 /* `set origin ORIGIN' */
1966 /* For origin set. */
1967 static route_map_result_t
route_set_origin(void *rule
, struct prefix
*prefix
,
1968 route_map_object_t type
,
1972 struct bgp_info
*bgp_info
;
1974 if (type
== RMAP_BGP
) {
1978 bgp_info
->attr
->origin
= *origin
;
1984 /* Compile function for origin set. */
1985 static void *route_set_origin_compile(const char *arg
)
1989 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(u_char
));
1991 if (strcmp(arg
, "igp") == 0)
1993 else if (strcmp(arg
, "egp") == 0)
2001 /* Compile function for origin set. */
2002 static void route_set_origin_free(void *rule
)
2004 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2007 /* Set origin rule structure. */
2008 struct route_map_rule_cmd route_set_origin_cmd
= {
2009 "origin", route_set_origin
, route_set_origin_compile
,
2010 route_set_origin_free
,
2013 /* `set atomic-aggregate' */
2015 /* For atomic aggregate set. */
2016 static route_map_result_t
route_set_atomic_aggregate(void *rule
,
2017 struct prefix
*prefix
,
2018 route_map_object_t type
,
2021 struct bgp_info
*bgp_info
;
2023 if (type
== RMAP_BGP
) {
2025 bgp_info
->attr
->flag
|=
2026 ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
2032 /* Compile function for atomic aggregate. */
2033 static void *route_set_atomic_aggregate_compile(const char *arg
)
2038 /* Compile function for atomic aggregate. */
2039 static void route_set_atomic_aggregate_free(void *rule
)
2044 /* Set atomic aggregate rule structure. */
2045 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
2046 "atomic-aggregate", route_set_atomic_aggregate
,
2047 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
2050 /* `set aggregator as AS A.B.C.D' */
2053 struct in_addr address
;
2056 static route_map_result_t
route_set_aggregator_as(void *rule
,
2057 struct prefix
*prefix
,
2058 route_map_object_t type
,
2061 struct bgp_info
*bgp_info
;
2062 struct aggregator
*aggregator
;
2064 if (type
== RMAP_BGP
) {
2068 bgp_info
->attr
->aggregator_as
= aggregator
->as
;
2069 bgp_info
->attr
->aggregator_addr
= aggregator
->address
;
2070 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
2076 static void *route_set_aggregator_as_compile(const char *arg
)
2078 struct aggregator
*aggregator
;
2084 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
2085 sscanf(arg
, "%s %s", as
, address
);
2087 aggregator
->as
= strtoul(as
, NULL
, 10);
2088 ret
= inet_aton(address
, &aggregator
->address
);
2090 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2096 static void route_set_aggregator_as_free(void *rule
)
2098 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2101 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2102 "aggregator as", route_set_aggregator_as
,
2103 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2106 /* Set tag to object. object must be pointer to struct bgp_info */
2107 static route_map_result_t
route_set_tag(void *rule
, struct prefix
*prefix
,
2108 route_map_object_t type
, void *object
)
2111 struct bgp_info
*bgp_info
;
2113 if (type
== RMAP_BGP
) {
2118 bgp_info
->attr
->tag
= *tag
;
2124 /* Route map commands for tag set. */
2125 static struct route_map_rule_cmd route_set_tag_cmd
= {
2126 "tag", route_set_tag
, route_map_rule_tag_compile
,
2127 route_map_rule_tag_free
,
2130 /* Set label-index to object. object must be pointer to struct bgp_info */
2131 static route_map_result_t
route_set_label_index(void *rule
,
2132 struct prefix
*prefix
,
2133 route_map_object_t type
,
2136 struct rmap_value
*rv
;
2137 struct bgp_info
*bgp_info
;
2138 u_int32_t label_index
;
2140 if (type
== RMAP_BGP
) {
2141 /* Fetch routemap's rule information. */
2145 /* Set label-index value. */
2146 label_index
= rv
->value
;
2148 bgp_info
->attr
->label_index
= label_index
;
2149 bgp_info
->attr
->flag
|=
2150 ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2157 /* Route map commands for label-index set. */
2158 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2159 "label-index", route_set_label_index
, route_value_compile
,
2163 /* `match ipv6 address IP_ACCESS_LIST' */
2165 static route_map_result_t
route_match_ipv6_address(void *rule
,
2166 struct prefix
*prefix
,
2167 route_map_object_t type
,
2170 struct access_list
*alist
;
2172 if (type
== RMAP_BGP
) {
2173 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2175 return RMAP_NOMATCH
;
2177 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2181 return RMAP_NOMATCH
;
2184 static void *route_match_ipv6_address_compile(const char *arg
)
2186 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2189 static void route_match_ipv6_address_free(void *rule
)
2191 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2194 /* Route map commands for ip address matching. */
2195 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2196 "ipv6 address", route_match_ipv6_address
,
2197 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2199 /* `match ipv6 next-hop IP_ADDRESS' */
2201 static route_map_result_t
route_match_ipv6_next_hop(void *rule
,
2202 struct prefix
*prefix
,
2203 route_map_object_t type
,
2206 struct in6_addr
*addr
= rule
;
2207 struct bgp_info
*bgp_info
;
2209 if (type
== RMAP_BGP
) {
2212 if (IPV6_ADDR_SAME(&bgp_info
->attr
->mp_nexthop_global
, addr
))
2215 if (bgp_info
->attr
->mp_nexthop_len
2216 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2217 && IPV6_ADDR_SAME(&bgp_info
->attr
->mp_nexthop_local
, rule
))
2220 return RMAP_NOMATCH
;
2223 return RMAP_NOMATCH
;
2226 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2228 struct in6_addr
*address
;
2231 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2233 ret
= inet_pton(AF_INET6
, arg
, address
);
2235 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2242 static void route_match_ipv6_next_hop_free(void *rule
)
2244 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2247 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2248 "ipv6 next-hop", route_match_ipv6_next_hop
,
2249 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2251 /* `match ipv6 address prefix-list PREFIX_LIST' */
2253 static route_map_result_t
2254 route_match_ipv6_address_prefix_list(void *rule
, struct prefix
*prefix
,
2255 route_map_object_t type
, void *object
)
2257 struct prefix_list
*plist
;
2259 if (type
== RMAP_BGP
) {
2260 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
2262 return RMAP_NOMATCH
;
2264 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
2268 return RMAP_NOMATCH
;
2271 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2273 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2276 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2278 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2281 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2282 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2283 route_match_ipv6_address_prefix_list_compile
,
2284 route_match_ipv6_address_prefix_list_free
};
2286 /* `set ipv6 nexthop global IP_ADDRESS' */
2288 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2289 static route_map_result_t
route_set_ipv6_nexthop_global(void *rule
,
2290 struct prefix
*prefix
,
2291 route_map_object_t type
,
2294 struct in6_addr
*address
;
2295 struct bgp_info
*bgp_info
;
2297 if (type
== RMAP_BGP
) {
2298 /* Fetch routemap's rule information. */
2302 /* Set next hop value. */
2303 bgp_info
->attr
->mp_nexthop_global
= *address
;
2305 /* Set nexthop length. */
2306 if (bgp_info
->attr
->mp_nexthop_len
== 0)
2307 bgp_info
->attr
->mp_nexthop_len
=
2308 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2310 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2311 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2317 /* Route map `ip next-hop' compile function. Given string is converted
2318 to struct in_addr structure. */
2319 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2322 struct in6_addr
*address
;
2324 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2326 ret
= inet_pton(AF_INET6
, arg
, address
);
2329 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2336 /* Free route map's compiled `ip next-hop' value. */
2337 static void route_set_ipv6_nexthop_global_free(void *rule
)
2339 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2342 /* Route map commands for ip nexthop set. */
2343 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2344 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2345 route_set_ipv6_nexthop_global_compile
,
2346 route_set_ipv6_nexthop_global_free
};
2348 /* Set next-hop preference value. */
2349 static route_map_result_t
2350 route_set_ipv6_nexthop_prefer_global(void *rule
, struct prefix
*prefix
,
2351 route_map_object_t type
, void *object
)
2353 struct bgp_info
*bgp_info
;
2356 if (type
== RMAP_BGP
) {
2357 /* Fetch routemap's rule information. */
2359 peer
= bgp_info
->peer
;
2361 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2362 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2364 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2365 /* Set next hop preference to global */
2366 bgp_info
->attr
->mp_nexthop_prefer_global
= TRUE
;
2367 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2368 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2370 bgp_info
->attr
->mp_nexthop_prefer_global
= FALSE
;
2371 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2372 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2378 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2382 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2388 /* Free route map's compiled `ip next-hop' value. */
2389 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2391 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2394 /* Route map commands for ip nexthop set preferred. */
2395 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2396 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2397 route_set_ipv6_nexthop_prefer_global_compile
,
2398 route_set_ipv6_nexthop_prefer_global_free
};
2400 /* `set ipv6 nexthop local IP_ADDRESS' */
2402 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2403 static route_map_result_t
route_set_ipv6_nexthop_local(void *rule
,
2404 struct prefix
*prefix
,
2405 route_map_object_t type
,
2408 struct in6_addr
*address
;
2409 struct bgp_info
*bgp_info
;
2411 if (type
== RMAP_BGP
) {
2412 /* Fetch routemap's rule information. */
2416 /* Set next hop value. */
2417 bgp_info
->attr
->mp_nexthop_local
= *address
;
2419 /* Set nexthop length. */
2420 if (bgp_info
->attr
->mp_nexthop_len
2421 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2422 bgp_info
->attr
->mp_nexthop_len
=
2423 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2425 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2426 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2432 /* Route map `ip nexthop' compile function. Given string is converted
2433 to struct in_addr structure. */
2434 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2437 struct in6_addr
*address
;
2439 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2441 ret
= inet_pton(AF_INET6
, arg
, address
);
2444 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2451 /* Free route map's compiled `ip nexthop' value. */
2452 static void route_set_ipv6_nexthop_local_free(void *rule
)
2454 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2457 /* Route map commands for ip nexthop set. */
2458 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2459 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2460 route_set_ipv6_nexthop_local_compile
,
2461 route_set_ipv6_nexthop_local_free
};
2463 /* `set ipv6 nexthop peer-address' */
2465 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2466 static route_map_result_t
route_set_ipv6_nexthop_peer(void *rule
,
2467 struct prefix
*prefix
,
2468 route_map_object_t type
,
2471 struct in6_addr peer_address
;
2472 struct bgp_info
*bgp_info
;
2475 if (type
== RMAP_BGP
) {
2476 /* Fetch routemap's rule information. */
2478 peer
= bgp_info
->peer
;
2480 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2481 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2483 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2484 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2485 /* Set next hop value and length in attribute. */
2486 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2487 bgp_info
->attr
->mp_nexthop_local
= peer_address
;
2488 if (bgp_info
->attr
->mp_nexthop_len
!= 32)
2489 bgp_info
->attr
->mp_nexthop_len
= 32;
2491 bgp_info
->attr
->mp_nexthop_global
=
2493 if (bgp_info
->attr
->mp_nexthop_len
== 0)
2494 bgp_info
->attr
->mp_nexthop_len
= 16;
2497 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2498 /* The next hop value will be set as part of packet
2500 * Set the flags here to indicate that rewrite needs to
2502 * Also, clear the value - we clear both global and
2504 * nexthops, whether we send one or both is determined
2507 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2508 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2509 /* clear next hop value. */
2510 memset(&(bgp_info
->attr
->mp_nexthop_global
), 0,
2511 sizeof(struct in6_addr
));
2512 memset(&(bgp_info
->attr
->mp_nexthop_local
), 0,
2513 sizeof(struct in6_addr
));
2520 /* Route map `ip next-hop' compile function. Given string is converted
2521 to struct in_addr structure. */
2522 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2526 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2532 /* Free route map's compiled `ip next-hop' value. */
2533 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2535 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2538 /* Route map commands for ip nexthop set. */
2539 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2540 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2541 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2543 /* `set ipv4 vpn next-hop A.B.C.D' */
2545 static route_map_result_t
route_set_vpnv4_nexthop(void *rule
,
2546 struct prefix
*prefix
,
2547 route_map_object_t type
,
2550 struct in_addr
*address
;
2551 struct bgp_info
*bgp_info
;
2553 if (type
== RMAP_BGP
) {
2554 /* Fetch routemap's rule information. */
2558 /* Set next hop value. */
2559 bgp_info
->attr
->mp_nexthop_global_in
= *address
;
2560 bgp_info
->attr
->mp_nexthop_len
= 4;
2566 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2569 struct in_addr
*address
;
2571 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2573 ret
= inet_aton(arg
, address
);
2576 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2583 /* `set ipv6 vpn next-hop A.B.C.D' */
2585 static route_map_result_t
route_set_vpnv6_nexthop(void *rule
,
2586 struct prefix
*prefix
,
2587 route_map_object_t type
,
2590 struct in6_addr
*address
;
2591 struct bgp_info
*bgp_info
;
2593 if (type
== RMAP_BGP
) {
2594 /* Fetch routemap's rule information. */
2598 /* Set next hop value. */
2599 memcpy(&bgp_info
->attr
->mp_nexthop_global
, address
,
2600 sizeof(struct in6_addr
));
2601 bgp_info
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2607 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2610 struct in6_addr
*address
;
2612 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2613 ret
= inet_pton(AF_INET6
, arg
, address
);
2616 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2623 static void route_set_vpn_nexthop_free(void *rule
)
2625 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2628 /* Route map commands for ipv4 next-hop set. */
2629 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2630 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2631 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
2633 /* Route map commands for ipv6 next-hop set. */
2634 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
2635 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
2636 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
2638 /* `set originator-id' */
2640 /* For origin set. */
2641 static route_map_result_t
route_set_originator_id(void *rule
,
2642 struct prefix
*prefix
,
2643 route_map_object_t type
,
2646 struct in_addr
*address
;
2647 struct bgp_info
*bgp_info
;
2649 if (type
== RMAP_BGP
) {
2653 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
2654 bgp_info
->attr
->originator_id
= *address
;
2660 /* Compile function for originator-id set. */
2661 static void *route_set_originator_id_compile(const char *arg
)
2664 struct in_addr
*address
;
2666 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2668 ret
= inet_aton(arg
, address
);
2671 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2678 /* Compile function for originator_id set. */
2679 static void route_set_originator_id_free(void *rule
)
2681 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2684 /* Set originator-id rule structure. */
2685 struct route_map_rule_cmd route_set_originator_id_cmd
= {
2686 "originator-id", route_set_originator_id
,
2687 route_set_originator_id_compile
, route_set_originator_id_free
,
2690 /* Add bgp route map rule. */
2691 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
2692 const char *arg
, route_map_event_t type
)
2694 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2695 int retval
= CMD_SUCCESS
;
2698 ret
= route_map_add_match(index
, command
, arg
);
2700 case RMAP_RULE_MISSING
:
2701 vty_out(vty
, "%% BGP Can't find rule.\n");
2702 retval
= CMD_WARNING_CONFIG_FAILED
;
2704 case RMAP_COMPILE_ERROR
:
2705 vty_out(vty
, "%% BGP Argument is malformed.\n");
2706 retval
= CMD_WARNING_CONFIG_FAILED
;
2708 case RMAP_COMPILE_SUCCESS
:
2709 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
2710 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
2718 /* Delete bgp route map rule. */
2719 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
2720 const char *arg
, route_map_event_t type
)
2722 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2724 int retval
= CMD_SUCCESS
;
2725 char *dep_name
= NULL
;
2727 char *rmap_name
= NULL
;
2729 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
2730 /* ignore the mundane, the types without any dependency */
2732 if ((tmpstr
= route_map_get_match_arg(index
, command
))
2735 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
2737 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
2739 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
2742 ret
= route_map_delete_match(index
, command
, dep_name
);
2744 case RMAP_RULE_MISSING
:
2745 vty_out(vty
, "%% BGP Can't find rule.\n");
2746 retval
= CMD_WARNING_CONFIG_FAILED
;
2748 case RMAP_COMPILE_ERROR
:
2749 vty_out(vty
, "%% BGP Argument is malformed.\n");
2750 retval
= CMD_WARNING_CONFIG_FAILED
;
2752 case RMAP_COMPILE_SUCCESS
:
2753 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
2754 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
2759 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2761 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2767 * This is the workhorse routine for processing in/out routemap
2770 static void bgp_route_map_process_peer(const char *rmap_name
,
2771 struct route_map
*map
, struct peer
*peer
,
2772 int afi
, int safi
, int route_update
)
2776 struct bgp_filter
*filter
;
2778 if (!peer
|| !rmap_name
)
2781 filter
= &peer
->filter
[afi
][safi
];
2783 * in is for non-route-server clients,
2784 * out is for all peers
2786 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
2787 if (filter
->map
[RMAP_IN
].name
2788 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
2789 filter
->map
[RMAP_IN
].map
= map
;
2791 if (route_update
&& peer
->status
== Established
) {
2792 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
2793 PEER_FLAG_SOFT_RECONFIG
)) {
2794 if (bgp_debug_update(peer
, NULL
, NULL
,
2797 "Processing route_map %s update on "
2798 "peer %s (inbound, soft-reconfig)",
2799 rmap_name
, peer
->host
);
2801 bgp_soft_reconfig_in(peer
, afi
, safi
);
2803 CHECK_FLAG(peer
->cap
,
2804 PEER_CAP_REFRESH_OLD_RCV
)
2807 PEER_CAP_REFRESH_NEW_RCV
)) {
2809 if (bgp_debug_update(peer
, NULL
, NULL
,
2812 "Processing route_map %s update on "
2813 "peer %s (inbound, route-refresh)",
2814 rmap_name
, peer
->host
);
2815 bgp_route_refresh_send(peer
, afi
, safi
,
2822 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
2825 if (update
&& route_update
&& peer
->status
== Established
) {
2826 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
2827 PEER_FLAG_SOFT_RECONFIG
)) {
2828 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2830 "Processing route_map %s update on "
2831 "peer %s (import, soft-reconfig)",
2832 rmap_name
, peer
->host
);
2834 bgp_soft_reconfig_in(peer
, afi
, safi
);
2835 } else if (CHECK_FLAG(peer
->cap
,
2836 PEER_CAP_REFRESH_OLD_RCV
)
2837 || CHECK_FLAG(peer
->cap
,
2838 PEER_CAP_REFRESH_NEW_RCV
)) {
2839 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2841 "Processing route_map %s update on "
2842 "peer %s (import, route-refresh)",
2843 rmap_name
, peer
->host
);
2844 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
2847 /* DD: Else, what else do we do ? Reset peer ? */
2852 * For outbound, unsuppress and default-originate map change (content or
2853 * map created), merely update the "config" here, the actual route
2854 * announcement happens at the group level.
2856 if (filter
->map
[RMAP_OUT
].name
2857 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
2858 filter
->map
[RMAP_OUT
].map
= map
;
2860 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
2861 filter
->usmap
.map
= map
;
2863 if (peer
->default_rmap
[afi
][safi
].name
2864 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
2865 peer
->default_rmap
[afi
][safi
].map
= map
;
2868 static void bgp_route_map_update_peer_group(const char *rmap_name
,
2869 struct route_map
*map
,
2872 struct peer_group
*group
;
2873 struct listnode
*node
, *nnode
;
2874 struct bgp_filter
*filter
;
2881 /* All the peers have been updated correctly already. This is
2882 * just updating the placeholder data. No real update required.
2884 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
))
2885 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2886 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
2887 filter
= &group
->conf
->filter
[afi
][safi
];
2889 for (direct
= RMAP_IN
; direct
< RMAP_MAX
;
2891 if ((filter
->map
[direct
].name
)
2892 && (strcmp(rmap_name
,
2893 filter
->map
[direct
].name
)
2895 filter
->map
[direct
].map
= map
;
2898 if (filter
->usmap
.name
2899 && (strcmp(rmap_name
, filter
->usmap
.name
)
2901 filter
->usmap
.map
= map
;
2906 * Note that if an extreme number (tens of thousands) of route-maps are in use
2907 * and if bgp has an extreme number of peers, network statements, etc then this
2908 * function can consume a lot of cycles. This is due to this function being
2909 * called for each route-map and within this function we walk the list of peers,
2910 * network statements, etc looking to see if they use this route-map.
2912 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
2919 struct bgp_node
*bn
;
2920 struct bgp_static
*bgp_static
;
2921 struct listnode
*node
, *nnode
;
2922 struct route_map
*map
;
2923 char buf
[INET6_ADDRSTRLEN
];
2925 map
= route_map_lookup_by_name(rmap_name
);
2927 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
2929 /* Ignore dummy peer-group structure */
2930 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
2933 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2934 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
2935 /* process in/out/import/export/default-orig
2937 bgp_route_map_process_peer(rmap_name
, map
, peer
,
2943 /* for outbound/default-orig route-maps, process for groups */
2944 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
2947 /* update peer-group config (template) */
2948 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
2950 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2951 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
2952 /* For table route-map updates. */
2953 if (!bgp_fibupd_safi(safi
))
2956 if (bgp
->table_map
[afi
][safi
].name
2957 && (strcmp(rmap_name
,
2958 bgp
->table_map
[afi
][safi
].name
)
2960 bgp
->table_map
[afi
][safi
].map
= map
;
2962 if (BGP_DEBUG(zebra
, ZEBRA
))
2964 "Processing route_map %s update on "
2968 bgp_zebra_announce_table(bgp
, afi
,
2972 /* For network route-map updates. */
2973 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
2974 bn
= bgp_route_next(bn
))
2975 if ((bgp_static
= bn
->info
) != NULL
) {
2976 if (bgp_static
->rmap
.name
2977 && (strcmp(rmap_name
,
2978 bgp_static
->rmap
.name
)
2980 bgp_static
->rmap
.map
= map
;
2985 if (bgp_debug_zebra(
2988 "Processing route_map %s update on "
3007 /* For redistribute route-map updates. */
3008 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3009 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3010 struct list
*red_list
;
3011 struct listnode
*node
;
3012 struct bgp_redist
*red
;
3014 red_list
= bgp
->redist
[afi
][i
];
3018 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3020 && (strcmp(rmap_name
, red
->rmap
.name
)
3022 red
->rmap
.map
= map
;
3025 if (BGP_DEBUG(zebra
, ZEBRA
))
3027 "Processing route_map %s update on "
3028 "redistributed routes",
3031 bgp_redistribute_resend(
3040 static int bgp_route_map_process_update_cb(char *rmap_name
)
3042 struct listnode
*node
, *nnode
;
3045 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3046 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3049 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3050 vnc_routemap_update(bgp
, __func__
);
3055 int bgp_route_map_update_timer(struct thread
*thread
)
3057 bm
->t_rmap_update
= NULL
;
3059 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3064 static void bgp_route_map_mark_update(const char *rmap_name
)
3066 if (bm
->t_rmap_update
== NULL
) {
3067 struct listnode
*node
, *nnode
;
3070 /* rmap_update_timer of 0 means don't do route updates */
3071 if (bm
->rmap_update_timer
) {
3072 bm
->t_rmap_update
= NULL
;
3073 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3074 NULL
, bm
->rmap_update_timer
,
3075 &bm
->t_rmap_update
);
3077 /* Signal the groups that a route-map update event has
3079 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3080 update_group_policy_update(bgp
,
3081 BGP_POLICY_ROUTE_MAP
,
3084 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3085 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3087 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3088 vnc_routemap_update(bgp
, __func__
);
3094 static void bgp_route_map_add(const char *rmap_name
)
3096 if (route_map_mark_updated(rmap_name
, 0) == 0)
3097 bgp_route_map_mark_update(rmap_name
);
3099 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3102 static void bgp_route_map_delete(const char *rmap_name
)
3104 if (route_map_mark_updated(rmap_name
, 1) == 0)
3105 bgp_route_map_mark_update(rmap_name
);
3107 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3110 static void bgp_route_map_event(route_map_event_t event
, const char *rmap_name
)
3112 if (route_map_mark_updated(rmap_name
, 0) == 0)
3113 bgp_route_map_mark_update(rmap_name
);
3115 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3118 DEFUN (match_mac_address
,
3119 match_mac_address_cmd
,
3120 "match mac address WORD",
3123 "Match address of route\n"
3124 "MAC Access-list name\n")
3126 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3127 RMAP_EVENT_FILTER_ADDED
);
3130 DEFUN (no_match_mac_address
,
3131 no_match_mac_address_cmd
,
3132 "no match mac address WORD",
3136 "Match address of route\n"
3137 "MAC acess-list name\n")
3139 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3140 RMAP_EVENT_FILTER_DELETED
);
3143 DEFUN (match_evpn_vni
,
3145 "match evpn vni (1-16777215)",
3151 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3152 RMAP_EVENT_MATCH_ADDED
);
3155 DEFUN (no_match_evpn_vni
,
3156 no_match_evpn_vni_cmd
,
3157 "no match evpn vni (1-16777215)",
3164 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3165 RMAP_EVENT_MATCH_DELETED
);
3170 "match peer <A.B.C.D|X:X::X:X|WORD>",
3172 "Match peer address\n"
3173 "IP address of peer\n"
3174 "IPv6 address of peer\n"
3175 "Interface name of peer\n")
3178 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3179 RMAP_EVENT_MATCH_ADDED
);
3182 DEFUN (match_peer_local
,
3183 match_peer_local_cmd
,
3186 "Match peer address\n"
3187 "Static or Redistributed routes\n")
3189 return bgp_route_match_add(vty
, "peer", "local",
3190 RMAP_EVENT_MATCH_DELETED
);
3193 DEFUN (no_match_peer
,
3195 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3198 "Match peer address\n"
3199 "Static or Redistributed routes\n"
3200 "IP address of peer\n"
3201 "IPv6 address of peer\n"
3202 "Interface name of peer\n")
3206 if (argc
<= idx_peer
)
3207 return bgp_route_match_delete(vty
, "peer", NULL
,
3208 RMAP_EVENT_MATCH_DELETED
);
3209 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3210 RMAP_EVENT_MATCH_DELETED
);
3214 /* match probability */
3215 DEFUN (match_probability
,
3216 match_probability_cmd
,
3217 "match probability (0-100)",
3219 "Match portion of routes defined by percentage value\n"
3220 "Percentage of routes\n")
3223 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3224 RMAP_EVENT_MATCH_ADDED
);
3228 DEFUN (no_match_probability
,
3229 no_match_probability_cmd
,
3230 "no match probability [(1-99)]",
3233 "Match portion of routes defined by percentage value\n"
3234 "Percentage of routes\n")
3237 if (argc
<= idx_number
)
3238 return bgp_route_match_delete(vty
, "probability", NULL
,
3239 RMAP_EVENT_MATCH_DELETED
);
3240 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3241 RMAP_EVENT_MATCH_DELETED
);
3245 DEFUN (match_ip_route_source
,
3246 match_ip_route_source_cmd
,
3247 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3250 "Match advertising source address of route\n"
3251 "IP access-list number\n"
3252 "IP access-list number (expanded range)\n"
3253 "IP standard access-list name\n")
3256 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3257 RMAP_EVENT_FILTER_ADDED
);
3261 DEFUN (no_match_ip_route_source
,
3262 no_match_ip_route_source_cmd
,
3263 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3267 "Match advertising source address of route\n"
3268 "IP access-list number\n"
3269 "IP access-list number (expanded range)\n"
3270 "IP standard access-list name\n")
3273 if (argc
<= idx_number
)
3274 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3275 RMAP_EVENT_FILTER_DELETED
);
3276 return bgp_route_match_delete(vty
, "ip route-source",
3277 argv
[idx_number
]->arg
,
3278 RMAP_EVENT_FILTER_DELETED
);
3282 DEFUN (match_ip_route_source_prefix_list
,
3283 match_ip_route_source_prefix_list_cmd
,
3284 "match ip route-source prefix-list WORD",
3287 "Match advertising source address of route\n"
3288 "Match entries of prefix-lists\n"
3289 "IP prefix-list name\n")
3292 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3293 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3297 DEFUN (no_match_ip_route_source_prefix_list
,
3298 no_match_ip_route_source_prefix_list_cmd
,
3299 "no match ip route-source prefix-list [WORD]",
3303 "Match advertising source address of route\n"
3304 "Match entries of prefix-lists\n"
3305 "IP prefix-list name\n")
3308 if (argc
<= idx_word
)
3309 return bgp_route_match_delete(vty
,
3310 "ip route-source prefix-list",
3311 NULL
, RMAP_EVENT_PLIST_DELETED
);
3312 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3313 argv
[idx_word
]->arg
,
3314 RMAP_EVENT_PLIST_DELETED
);
3318 DEFUN (match_local_pref
,
3319 match_local_pref_cmd
,
3320 "match local-preference (0-4294967295)",
3322 "Match local-preference of route\n"
3326 return bgp_route_match_add(vty
, "local-preference",
3327 argv
[idx_number
]->arg
,
3328 RMAP_EVENT_MATCH_ADDED
);
3332 DEFUN (no_match_local_pref
,
3333 no_match_local_pref_cmd
,
3334 "no match local-preference [(0-4294967295)]",
3337 "Match local preference of route\n"
3338 "Local preference value\n")
3340 int idx_localpref
= 3;
3341 if (argc
<= idx_localpref
)
3342 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3343 RMAP_EVENT_MATCH_DELETED
);
3344 return bgp_route_match_delete(vty
, "local-preference",
3345 argv
[idx_localpref
]->arg
,
3346 RMAP_EVENT_MATCH_DELETED
);
3350 DEFUN (match_community
,
3351 match_community_cmd
,
3352 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3354 "Match BGP community list\n"
3355 "Community-list number (standard)\n"
3356 "Community-list number (expanded)\n"
3357 "Community-list name\n"
3358 "Do exact matching of communities\n")
3360 int idx_comm_list
= 2;
3365 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3366 strlen(argv
[idx_comm_list
]->arg
)
3367 + strlen("exact-match") + 2);
3369 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3371 argstr
= argv
[idx_comm_list
]->arg
;
3373 ret
= bgp_route_match_add(vty
, "community", argstr
,
3374 RMAP_EVENT_CLIST_ADDED
);
3376 if (argstr
!= argv
[idx_comm_list
]->arg
)
3377 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3382 DEFUN (no_match_community
,
3383 no_match_community_cmd
,
3384 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3387 "Match BGP community list\n"
3388 "Community-list number (standard)\n"
3389 "Community-list number (expanded)\n"
3390 "Community-list name\n"
3391 "Do exact matching of communities\n")
3393 return bgp_route_match_delete(vty
, "community", NULL
,
3394 RMAP_EVENT_CLIST_DELETED
);
3397 DEFUN (match_lcommunity
,
3398 match_lcommunity_cmd
,
3399 "match large-community <(1-99)|(100-500)|WORD>",
3401 "Match BGP large community list\n"
3402 "Large Community-list number (standard)\n"
3403 "Large Community-list number (expanded)\n"
3404 "Large Community-list name\n")
3406 return bgp_route_match_add(vty
, "large-community", argv
[2]->arg
,
3407 RMAP_EVENT_LLIST_ADDED
);
3410 DEFUN (no_match_lcommunity
,
3411 no_match_lcommunity_cmd
,
3412 "no match large-community [<(1-99)|(100-500)|WORD>]",
3415 "Match BGP large community list\n"
3416 "Large Community-list number (standard)\n"
3417 "Large Community-list number (expanded)\n"
3418 "Large Community-list name\n")
3420 return bgp_route_match_delete(vty
, "large-community", NULL
,
3421 RMAP_EVENT_LLIST_DELETED
);
3424 DEFUN (match_ecommunity
,
3425 match_ecommunity_cmd
,
3426 "match extcommunity <(1-99)|(100-500)|WORD>",
3428 "Match BGP/VPN extended community list\n"
3429 "Extended community-list number (standard)\n"
3430 "Extended community-list number (expanded)\n"
3431 "Extended community-list name\n")
3433 int idx_comm_list
= 2;
3434 return bgp_route_match_add(vty
, "extcommunity",
3435 argv
[idx_comm_list
]->arg
,
3436 RMAP_EVENT_ECLIST_ADDED
);
3440 DEFUN (no_match_ecommunity
,
3441 no_match_ecommunity_cmd
,
3442 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3445 "Match BGP/VPN extended community list\n"
3446 "Extended community-list number (standard)\n"
3447 "Extended community-list number (expanded)\n"
3448 "Extended community-list name\n")
3450 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3451 RMAP_EVENT_ECLIST_DELETED
);
3455 DEFUN (match_aspath
,
3457 "match as-path WORD",
3459 "Match BGP AS path list\n"
3460 "AS path access-list name\n")
3463 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3464 RMAP_EVENT_ASLIST_ADDED
);
3468 DEFUN (no_match_aspath
,
3469 no_match_aspath_cmd
,
3470 "no match as-path [WORD]",
3473 "Match BGP AS path list\n"
3474 "AS path access-list name\n")
3476 return bgp_route_match_delete(vty
, "as-path", NULL
,
3477 RMAP_EVENT_ASLIST_DELETED
);
3481 DEFUN (match_origin
,
3483 "match origin <egp|igp|incomplete>",
3488 "unknown heritage\n")
3491 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3492 return bgp_route_match_add(vty
, "origin", "igp",
3493 RMAP_EVENT_MATCH_ADDED
);
3494 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3495 return bgp_route_match_add(vty
, "origin", "egp",
3496 RMAP_EVENT_MATCH_ADDED
);
3497 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3498 return bgp_route_match_add(vty
, "origin", "incomplete",
3499 RMAP_EVENT_MATCH_ADDED
);
3501 vty_out(vty
, "%% Invalid match origin type\n");
3502 return CMD_WARNING_CONFIG_FAILED
;
3506 DEFUN (no_match_origin
,
3507 no_match_origin_cmd
,
3508 "no match origin [<egp|igp|incomplete>]",
3514 "unknown heritage\n")
3516 return bgp_route_match_delete(vty
, "origin", NULL
,
3517 RMAP_EVENT_MATCH_DELETED
);
3520 DEFUN (set_ip_nexthop_peer
,
3521 set_ip_nexthop_peer_cmd
,
3522 "[no] set ip next-hop peer-address",
3526 "Next hop address\n"
3527 "Use peer address (for BGP only)\n")
3529 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3530 const char *) = strmatch(argv
[0]->text
, "no")
3531 ? generic_set_delete
3534 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3538 DEFUN (set_ip_nexthop_unchanged
,
3539 set_ip_nexthop_unchanged_cmd
,
3540 "[no] set ip next-hop unchanged",
3544 "Next hop address\n"
3545 "Don't modify existing Next hop address\n")
3547 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3548 const char *) = strmatch(argv
[0]->text
, "no")
3549 ? generic_set_delete
3552 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3557 DEFUN (set_local_pref
,
3559 "set local-preference (0-4294967295)",
3561 "BGP local preference path attribute\n"
3562 "Preference value\n")
3565 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3566 "local-preference", argv
[idx_number
]->arg
);
3570 DEFUN (no_set_local_pref
,
3571 no_set_local_pref_cmd
,
3572 "no set local-preference [(0-4294967295)]",
3575 "BGP local preference path attribute\n"
3576 "Preference value\n")
3578 int idx_localpref
= 3;
3579 if (argc
<= idx_localpref
)
3580 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3581 "local-preference", NULL
);
3582 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3583 "local-preference", argv
[idx_localpref
]->arg
);
3589 "set weight (0-4294967295)",
3591 "BGP weight for routing table\n"
3595 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
3596 argv
[idx_number
]->arg
);
3600 DEFUN (no_set_weight
,
3602 "no set weight [(0-4294967295)]",
3605 "BGP weight for routing table\n"
3609 if (argc
<= idx_weight
)
3610 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3612 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3613 "weight", argv
[idx_weight
]->arg
);
3616 DEFUN (set_label_index
,
3617 set_label_index_cmd
,
3618 "set label-index (0-1048560)",
3620 "Label index to associate with the prefix\n"
3621 "Label index value\n")
3624 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3625 "label-index", argv
[idx_number
]->arg
);
3628 DEFUN (no_set_label_index
,
3629 no_set_label_index_cmd
,
3630 "no set label-index [(0-1048560)]",
3633 "Label index to associate with the prefix\n"
3634 "Label index value\n")
3636 int idx_label_index
= 3;
3637 if (argc
<= idx_label_index
)
3638 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3639 "label-index", NULL
);
3640 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3641 "label-index", argv
[idx_label_index
]->arg
);
3644 DEFUN (set_aspath_prepend_asn
,
3645 set_aspath_prepend_asn_cmd
,
3646 "set as-path prepend (1-4294967295)...",
3648 "Transform BGP AS_PATH attribute\n"
3649 "Prepend to the as-path\n"
3656 str
= argv_concat(argv
, argc
, idx_asn
);
3657 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3658 "as-path prepend", str
);
3659 XFREE(MTYPE_TMP
, str
);
3664 DEFUN (set_aspath_prepend_lastas
,
3665 set_aspath_prepend_lastas_cmd
,
3666 "set as-path prepend last-as (1-10)",
3668 "Transform BGP AS_PATH attribute\n"
3669 "Prepend to the as-path\n"
3670 "Use the peer's AS-number\n"
3671 "Number of times to insert\n")
3673 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
3676 DEFUN (no_set_aspath_prepend
,
3677 no_set_aspath_prepend_cmd
,
3678 "no set as-path prepend [(1-4294967295)]",
3681 "Transform BGP AS_PATH attribute\n"
3682 "Prepend to the as-path\n"
3689 str
= argv_concat(argv
, argc
, idx_asn
);
3690 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3691 "as-path prepend", str
);
3692 XFREE(MTYPE_TMP
, str
);
3697 DEFUN (set_aspath_exclude
,
3698 set_aspath_exclude_cmd
,
3699 "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_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3711 "as-path exclude", str
);
3712 XFREE(MTYPE_TMP
, str
);
3716 DEFUN (no_set_aspath_exclude
,
3717 no_set_aspath_exclude_cmd
,
3718 "no set as-path exclude (1-4294967295)...",
3721 "Transform BGP AS_PATH attribute\n"
3722 "Exclude from the as-path\n"
3729 str
= argv_concat(argv
, argc
, idx_asn
);
3730 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3731 "as-path exclude", str
);
3732 XFREE(MTYPE_TMP
, str
);
3737 DEFUN (set_community
,
3739 "set community AA:NN...",
3741 "BGP community attribute\n"
3749 struct community
*com
= NULL
;
3754 b
= buffer_new(1024);
3756 for (i
= idx_aa_nn
; i
< argc
; i
++) {
3757 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
3764 buffer_putc(b
, ' ');
3768 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
3770 buffer_putstr(b
, "internet");
3773 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
3775 buffer_putstr(b
, "local-AS");
3778 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
3779 && strncmp(argv
[i
]->arg
, "no-advertise",
3780 strlen(argv
[i
]->arg
))
3782 buffer_putstr(b
, "no-advertise");
3785 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
3786 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
3788 buffer_putstr(b
, "no-export");
3791 if (strncmp(argv
[i
]->arg
, "graceful-shutdown", strlen(argv
[i
]->arg
))
3793 buffer_putstr(b
, "graceful-shutdown");
3796 buffer_putstr(b
, argv
[i
]->arg
);
3798 buffer_putc(b
, '\0');
3800 /* Fetch result string then compile it to communities attribute. */
3801 str
= buffer_getstr(b
);
3805 com
= community_str2com(str
);
3806 XFREE(MTYPE_TMP
, str
);
3809 /* Can't compile user input into communities attribute. */
3811 vty_out(vty
, "%% Malformed communities attribute\n");
3812 return CMD_WARNING_CONFIG_FAILED
;
3815 /* Set communites attribute string. */
3816 str
= community_str(com
);
3819 argstr
= XCALLOC(MTYPE_TMP
,
3820 strlen(str
) + strlen(" additive") + 1);
3821 strcpy(argstr
, str
);
3822 strcpy(argstr
+ strlen(str
), " additive");
3823 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3824 "community", argstr
);
3825 XFREE(MTYPE_TMP
, argstr
);
3827 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3830 community_free(com
);
3835 DEFUN (set_community_none
,
3836 set_community_none_cmd
,
3837 "set community none",
3839 "BGP community attribute\n"
3840 "No community attribute\n")
3842 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3843 "community", "none");
3846 DEFUN (no_set_community
,
3847 no_set_community_cmd
,
3848 "no set community AA:NN...",
3851 "BGP community attribute\n"
3854 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3859 DEFUN (set_community_delete
,
3860 set_community_delete_cmd
,
3861 "set comm-list <(1-99)|(100-500)|WORD> delete",
3863 "set BGP community list (for deletion)\n"
3864 "Community-list number (standard)\n"
3865 "Community-list number (expanded)\n"
3866 "Community-list name\n"
3867 "Delete matching communities\n")
3869 int idx_comm_list
= 2;
3872 str
= XCALLOC(MTYPE_TMP
,
3873 strlen(argv
[idx_comm_list
]->arg
) + strlen(" delete") + 1);
3874 strcpy(str
, argv
[idx_comm_list
]->arg
);
3875 strcpy(str
+ strlen(argv
[idx_comm_list
]->arg
), " delete");
3877 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
3880 XFREE(MTYPE_TMP
, str
);
3884 DEFUN (no_set_community_delete
,
3885 no_set_community_delete_cmd
,
3886 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
3889 "set BGP community list (for deletion)\n"
3890 "Community-list number (standard)\n"
3891 "Community-list number (expanded)\n"
3892 "Community-list name\n"
3893 "Delete matching communities\n")
3895 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3899 DEFUN (set_lcommunity
,
3901 "set large-community AA:BB:CC...",
3903 "BGP large community attribute\n"
3904 "Large Community number in aa:bb:cc format or additive\n")
3909 str
= argv_concat(argv
, argc
, 2);
3910 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3911 "large-community", str
);
3912 XFREE(MTYPE_TMP
, str
);
3917 DEFUN (set_lcommunity_none
,
3918 set_lcommunity_none_cmd
,
3919 "set large-community none",
3921 "BGP large community attribute\n"
3922 "No large community attribute\n")
3924 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3925 "large-community", "none");
3928 DEFUN (no_set_lcommunity
,
3929 no_set_lcommunity_cmd
,
3930 "no set large-community none",
3933 "BGP large community attribute\n"
3934 "No community attribute\n")
3936 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3937 "large-community", NULL
);
3940 DEFUN (no_set_lcommunity1
,
3941 no_set_lcommunity1_cmd
,
3942 "no set large-community AA:BB:CC...",
3945 "BGP large community attribute\n"
3946 "Large community in AA:BB:CC... format or additive\n")
3948 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3949 "large-community", NULL
);
3952 DEFUN (set_lcommunity_delete
,
3953 set_lcommunity_delete_cmd
,
3954 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
3956 "set BGP large community list (for deletion)\n"
3957 "Large Community-list number (standard)\n"
3958 "Large Communitly-list number (expanded)\n"
3959 "Large Community-list name\n"
3960 "Delete matching large communities\n")
3964 str
= XCALLOC(MTYPE_TMP
, strlen(argv
[2]->arg
) + strlen(" delete") + 1);
3965 strcpy(str
, argv
[2]->arg
);
3966 strcpy(str
+ strlen(argv
[2]->arg
), " delete");
3968 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3969 "large-comm-list", str
);
3971 XFREE(MTYPE_TMP
, str
);
3975 DEFUN (no_set_lcommunity_delete
,
3976 no_set_lcommunity_delete_cmd
,
3977 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
3980 "set BGP large community list (for deletion)\n"
3981 "Large Community-list number (standard)\n"
3982 "Large Communitly-list number (expanded)\n"
3983 "Large Community-list name\n"
3984 "Delete matching large communities\n")
3986 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3987 "large-comm-list", NULL
);
3990 DEFUN (set_ecommunity_rt
,
3991 set_ecommunity_rt_cmd
,
3992 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
3994 "BGP extended community attribute\n"
3995 "Route Target extended community\n"
3996 "VPN extended community\n")
4002 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4003 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4004 "extcommunity rt", str
);
4005 XFREE(MTYPE_TMP
, str
);
4010 DEFUN (no_set_ecommunity_rt
,
4011 no_set_ecommunity_rt_cmd
,
4012 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4015 "BGP extended community attribute\n"
4016 "Route Target extended community\n"
4017 "VPN extended community\n")
4019 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4020 "extcommunity rt", NULL
);
4024 DEFUN (set_ecommunity_soo
,
4025 set_ecommunity_soo_cmd
,
4026 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4028 "BGP extended community attribute\n"
4029 "Site-of-Origin extended community\n"
4030 "VPN extended community\n")
4036 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4037 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4038 "extcommunity soo", str
);
4039 XFREE(MTYPE_TMP
, str
);
4044 DEFUN (no_set_ecommunity_soo
,
4045 no_set_ecommunity_soo_cmd
,
4046 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4049 "BGP extended community attribute\n"
4050 "Site-of-Origin extended community\n"
4051 "VPN extended community\n")
4053 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4054 "extcommunity soo", NULL
);
4060 "set origin <egp|igp|incomplete>",
4065 "unknown heritage\n")
4068 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4069 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4071 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4072 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4074 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4075 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4076 "origin", "incomplete");
4078 vty_out(vty
, "%% Invalid set origin type\n");
4079 return CMD_WARNING_CONFIG_FAILED
;
4083 DEFUN (no_set_origin
,
4085 "no set origin [<egp|igp|incomplete>]",
4091 "unknown heritage\n")
4093 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4098 DEFUN (set_atomic_aggregate
,
4099 set_atomic_aggregate_cmd
,
4100 "set atomic-aggregate",
4102 "BGP atomic aggregate attribute\n" )
4104 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4105 "atomic-aggregate", NULL
);
4108 DEFUN (no_set_atomic_aggregate
,
4109 no_set_atomic_aggregate_cmd
,
4110 "no set atomic-aggregate",
4113 "BGP atomic aggregate attribute\n" )
4115 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4116 "atomic-aggregate", NULL
);
4119 DEFUN (set_aggregator_as
,
4120 set_aggregator_as_cmd
,
4121 "set aggregator as (1-4294967295) A.B.C.D",
4123 "BGP aggregator attribute\n"
4124 "AS number of aggregator\n"
4126 "IP address of aggregator\n")
4131 struct in_addr address
;
4134 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4136 vty_out(vty
, "Aggregator IP address is invalid\n");
4137 return CMD_WARNING_CONFIG_FAILED
;
4140 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4141 strlen(argv
[idx_number
]->arg
)
4142 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4144 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4146 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4147 "aggregator as", argstr
);
4149 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4155 DEFUN (no_set_aggregator_as
,
4156 no_set_aggregator_as_cmd
,
4157 "no set aggregator as [(1-4294967295) A.B.C.D]",
4160 "BGP aggregator attribute\n"
4161 "AS number of aggregator\n"
4163 "IP address of aggregator\n")
4168 struct in_addr address
;
4171 if (argc
<= idx_asn
)
4172 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4173 "aggregator as", NULL
);
4175 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4177 vty_out(vty
, "Aggregator IP address is invalid\n");
4178 return CMD_WARNING_CONFIG_FAILED
;
4181 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4182 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4185 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4187 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4188 "aggregator as", argstr
);
4190 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4195 DEFUN (match_ipv6_next_hop
,
4196 match_ipv6_next_hop_cmd
,
4197 "match ipv6 next-hop X:X::X:X",
4200 "Match IPv6 next-hop address of route\n"
4201 "IPv6 address of next hop\n")
4204 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4205 RMAP_EVENT_MATCH_ADDED
);
4208 DEFUN (no_match_ipv6_next_hop
,
4209 no_match_ipv6_next_hop_cmd
,
4210 "no match ipv6 next-hop X:X::X:X",
4214 "Match IPv6 next-hop address of route\n"
4215 "IPv6 address of next hop\n")
4218 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4219 RMAP_EVENT_MATCH_DELETED
);
4223 DEFUN (set_ipv6_nexthop_peer
,
4224 set_ipv6_nexthop_peer_cmd
,
4225 "set ipv6 next-hop peer-address",
4228 "Next hop address\n"
4229 "Use peer address (for BGP only)\n")
4231 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4232 "ipv6 next-hop peer-address", NULL
);
4235 DEFUN (no_set_ipv6_nexthop_peer
,
4236 no_set_ipv6_nexthop_peer_cmd
,
4237 "no set ipv6 next-hop peer-address",
4241 "IPv6 next-hop address\n"
4242 "Use peer address (for BGP only)\n")
4244 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4245 "ipv6 next-hop peer-address", NULL
);
4248 DEFUN (set_ipv6_nexthop_prefer_global
,
4249 set_ipv6_nexthop_prefer_global_cmd
,
4250 "set ipv6 next-hop prefer-global",
4253 "IPv6 next-hop address\n"
4254 "Prefer global over link-local if both exist\n")
4256 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4257 "ipv6 next-hop prefer-global", NULL
);
4261 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4262 no_set_ipv6_nexthop_prefer_global_cmd
,
4263 "no set ipv6 next-hop prefer-global",
4267 "IPv6 next-hop address\n"
4268 "Prefer global over link-local if both exist\n")
4270 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4271 "ipv6 next-hop prefer-global", NULL
);
4274 DEFUN (set_ipv6_nexthop_global
,
4275 set_ipv6_nexthop_global_cmd
,
4276 "set ipv6 next-hop global X:X::X:X",
4279 "IPv6 next-hop address\n"
4280 "IPv6 global address\n"
4281 "IPv6 address of next hop\n")
4284 struct in6_addr addr
;
4287 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4289 vty_out(vty
, "%% Malformed nexthop address\n");
4290 return CMD_WARNING_CONFIG_FAILED
;
4292 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4293 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4294 vty_out(vty
, "%% Invalid global nexthop address\n");
4295 return CMD_WARNING_CONFIG_FAILED
;
4298 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4299 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4303 DEFUN (no_set_ipv6_nexthop_global
,
4304 no_set_ipv6_nexthop_global_cmd
,
4305 "no set ipv6 next-hop global X:X::X:X",
4309 "IPv6 next-hop address\n"
4310 "IPv6 global address\n"
4311 "IPv6 address of next hop\n")
4314 if (argc
<= idx_ipv6
)
4315 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4316 "ipv6 next-hop global", NULL
);
4317 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4318 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4321 #ifdef KEEP_OLD_VPN_COMMANDS
4322 DEFUN (set_vpn_nexthop
,
4323 set_vpn_nexthop_cmd
,
4324 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4326 "VPNv4 information\n"
4327 "VPN next-hop address\n"
4328 "IP address of next hop\n"
4329 "VPNv6 information\n"
4330 "VPN next-hop address\n"
4331 "IPv6 address of next hop\n")
4337 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4339 return generic_set_add(
4340 vty
, VTY_GET_CONTEXT(route_map_index
),
4341 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4343 return generic_set_add(
4344 vty
, VTY_GET_CONTEXT(route_map_index
),
4345 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4350 DEFUN (no_set_vpn_nexthop
,
4351 no_set_vpn_nexthop_cmd
,
4352 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4355 "VPNv4 information\n"
4356 "VPN next-hop address\n"
4357 "IP address of next hop\n"
4358 "VPNv6 information\n"
4359 "VPN next-hop address\n"
4360 "IPv6 address of next hop\n")
4370 arg
= argv
[idx_ip
]->arg
;
4371 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4373 return generic_set_delete(
4374 vty
, VTY_GET_CONTEXT(route_map_index
),
4375 "ipv4 vpn next-hop", arg
);
4377 return generic_set_delete(
4378 vty
, VTY_GET_CONTEXT(route_map_index
),
4379 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4383 #endif /* KEEP_OLD_VPN_COMMANDS */
4385 DEFUN (set_ipx_vpn_nexthop
,
4386 set_ipx_vpn_nexthop_cmd
,
4387 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4389 "IPv4 information\n"
4390 "IPv6 information\n"
4392 "VPN next-hop address\n"
4393 "IP address of next hop\n"
4394 "IPv6 address of next hop\n")
4400 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4402 return generic_set_add(
4403 vty
, VTY_GET_CONTEXT(route_map_index
),
4404 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4406 return generic_set_add(
4407 vty
, VTY_GET_CONTEXT(route_map_index
),
4408 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4413 DEFUN (no_set_ipx_vpn_nexthop
,
4414 no_set_ipx_vpn_nexthop_cmd
,
4415 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4418 "IPv4 information\n"
4419 "IPv6 information\n"
4421 "VPN next-hop address\n"
4422 "IP address of next hop\n"
4423 "IPv6 address of next hop\n")
4433 arg
= argv
[idx_ip
]->arg
;
4434 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4436 return generic_set_delete(
4437 vty
, VTY_GET_CONTEXT(route_map_index
),
4438 "ipv4 vpn next-hop", arg
);
4440 return generic_set_delete(
4441 vty
, VTY_GET_CONTEXT(route_map_index
),
4442 "ipv6 vpn next-hop", arg
);
4447 DEFUN (set_originator_id
,
4448 set_originator_id_cmd
,
4449 "set originator-id A.B.C.D",
4451 "BGP originator ID attribute\n"
4452 "IP address of originator\n")
4455 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4456 "originator-id", argv
[idx_ipv4
]->arg
);
4460 DEFUN (no_set_originator_id
,
4461 no_set_originator_id_cmd
,
4462 "no set originator-id [A.B.C.D]",
4465 "BGP originator ID attribute\n"
4466 "IP address of originator\n")
4470 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4472 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4473 "originator-id", arg
);
4477 /* Initialization of route map. */
4478 void bgp_route_map_init(void)
4482 route_map_add_hook(bgp_route_map_add
);
4483 route_map_delete_hook(bgp_route_map_delete
);
4484 route_map_event_hook(bgp_route_map_event
);
4486 route_map_match_interface_hook(generic_match_add
);
4487 route_map_no_match_interface_hook(generic_match_delete
);
4489 route_map_match_ip_address_hook(generic_match_add
);
4490 route_map_no_match_ip_address_hook(generic_match_delete
);
4492 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
4493 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
4495 route_map_match_ip_next_hop_hook(generic_match_add
);
4496 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
4498 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
4499 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
4501 route_map_match_ipv6_address_hook(generic_match_add
);
4502 route_map_no_match_ipv6_address_hook(generic_match_delete
);
4504 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
4505 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
4507 route_map_match_metric_hook(generic_match_add
);
4508 route_map_no_match_metric_hook(generic_match_delete
);
4510 route_map_match_tag_hook(generic_match_add
);
4511 route_map_no_match_tag_hook(generic_match_delete
);
4513 route_map_set_ip_nexthop_hook(generic_set_add
);
4514 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
4516 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
4517 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
4519 route_map_set_metric_hook(generic_set_add
);
4520 route_map_no_set_metric_hook(generic_set_delete
);
4522 route_map_set_tag_hook(generic_set_add
);
4523 route_map_no_set_tag_hook(generic_set_delete
);
4525 route_map_install_match(&route_match_peer_cmd
);
4526 route_map_install_match(&route_match_local_pref_cmd
);
4527 route_map_install_match(&route_match_ip_address_cmd
);
4528 route_map_install_match(&route_match_ip_next_hop_cmd
);
4529 route_map_install_match(&route_match_ip_route_source_cmd
);
4530 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
4531 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
4532 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
4533 route_map_install_match(&route_match_aspath_cmd
);
4534 route_map_install_match(&route_match_community_cmd
);
4535 route_map_install_match(&route_match_lcommunity_cmd
);
4536 route_map_install_match(&route_match_ecommunity_cmd
);
4537 route_map_install_match(&route_match_local_pref_cmd
);
4538 route_map_install_match(&route_match_metric_cmd
);
4539 route_map_install_match(&route_match_origin_cmd
);
4540 route_map_install_match(&route_match_probability_cmd
);
4541 route_map_install_match(&route_match_interface_cmd
);
4542 route_map_install_match(&route_match_tag_cmd
);
4543 route_map_install_match(&route_match_mac_address_cmd
);
4544 route_map_install_match(&route_match_evpn_vni_cmd
);
4546 route_map_install_set(&route_set_ip_nexthop_cmd
);
4547 route_map_install_set(&route_set_local_pref_cmd
);
4548 route_map_install_set(&route_set_weight_cmd
);
4549 route_map_install_set(&route_set_label_index_cmd
);
4550 route_map_install_set(&route_set_metric_cmd
);
4551 route_map_install_set(&route_set_aspath_prepend_cmd
);
4552 route_map_install_set(&route_set_aspath_exclude_cmd
);
4553 route_map_install_set(&route_set_origin_cmd
);
4554 route_map_install_set(&route_set_atomic_aggregate_cmd
);
4555 route_map_install_set(&route_set_aggregator_as_cmd
);
4556 route_map_install_set(&route_set_community_cmd
);
4557 route_map_install_set(&route_set_community_delete_cmd
);
4558 route_map_install_set(&route_set_lcommunity_cmd
);
4559 route_map_install_set(&route_set_lcommunity_delete_cmd
);
4560 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
4561 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
4562 route_map_install_set(&route_set_originator_id_cmd
);
4563 route_map_install_set(&route_set_ecommunity_rt_cmd
);
4564 route_map_install_set(&route_set_ecommunity_soo_cmd
);
4565 route_map_install_set(&route_set_tag_cmd
);
4566 route_map_install_set(&route_set_label_index_cmd
);
4568 install_element(RMAP_NODE
, &match_peer_cmd
);
4569 install_element(RMAP_NODE
, &match_peer_local_cmd
);
4570 install_element(RMAP_NODE
, &no_match_peer_cmd
);
4571 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
4572 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
4573 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
4574 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
4575 install_element(RMAP_NODE
, &match_mac_address_cmd
);
4576 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
4577 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
4578 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
4580 install_element(RMAP_NODE
, &match_aspath_cmd
);
4581 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
4582 install_element(RMAP_NODE
, &match_local_pref_cmd
);
4583 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
4584 install_element(RMAP_NODE
, &match_community_cmd
);
4585 install_element(RMAP_NODE
, &no_match_community_cmd
);
4586 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
4587 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
4588 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
4589 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
4590 install_element(RMAP_NODE
, &match_origin_cmd
);
4591 install_element(RMAP_NODE
, &no_match_origin_cmd
);
4592 install_element(RMAP_NODE
, &match_probability_cmd
);
4593 install_element(RMAP_NODE
, &no_match_probability_cmd
);
4595 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
4596 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
4597 install_element(RMAP_NODE
, &set_local_pref_cmd
);
4598 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
4599 install_element(RMAP_NODE
, &set_weight_cmd
);
4600 install_element(RMAP_NODE
, &set_label_index_cmd
);
4601 install_element(RMAP_NODE
, &no_set_weight_cmd
);
4602 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
4603 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
4604 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
4605 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
4606 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
4607 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
4608 install_element(RMAP_NODE
, &set_origin_cmd
);
4609 install_element(RMAP_NODE
, &no_set_origin_cmd
);
4610 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
4611 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
4612 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
4613 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
4614 install_element(RMAP_NODE
, &set_community_cmd
);
4615 install_element(RMAP_NODE
, &set_community_none_cmd
);
4616 install_element(RMAP_NODE
, &no_set_community_cmd
);
4617 install_element(RMAP_NODE
, &set_community_delete_cmd
);
4618 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
4619 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
4620 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
4621 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
4622 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
4623 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
4624 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
4625 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
4626 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
4627 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
4628 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
4629 #ifdef KEEP_OLD_VPN_COMMANDS
4630 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
4631 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
4632 #endif /* KEEP_OLD_VPN_COMMANDS */
4633 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
4634 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
4635 install_element(RMAP_NODE
, &set_originator_id_cmd
);
4636 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
4638 route_map_install_match(&route_match_ipv6_address_cmd
);
4639 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
4640 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
4641 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
4642 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
4643 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
4644 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
4646 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
4647 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
4648 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
4649 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
4650 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
4651 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
4652 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
4653 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
4656 void bgp_route_map_terminate(void)
4658 /* ToDo: Cleanup all the used memory */
4660 route_map_add_hook(NULL
);
4661 route_map_delete_hook(NULL
);
4662 route_map_event_hook(NULL
);