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
= XCALLOC(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 if (sscanf(arg
, "%s %s", as
, address
) != 2) {
2086 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2090 aggregator
->as
= strtoul(as
, NULL
, 10);
2091 ret
= inet_aton(address
, &aggregator
->address
);
2093 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2099 static void route_set_aggregator_as_free(void *rule
)
2101 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2104 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
2105 "aggregator as", route_set_aggregator_as
,
2106 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
2109 /* Set tag to object. object must be pointer to struct bgp_info */
2110 static route_map_result_t
route_set_tag(void *rule
, struct prefix
*prefix
,
2111 route_map_object_t type
, void *object
)
2114 struct bgp_info
*bgp_info
;
2116 if (type
== RMAP_BGP
) {
2121 bgp_info
->attr
->tag
= *tag
;
2127 /* Route map commands for tag set. */
2128 static struct route_map_rule_cmd route_set_tag_cmd
= {
2129 "tag", route_set_tag
, route_map_rule_tag_compile
,
2130 route_map_rule_tag_free
,
2133 /* Set label-index to object. object must be pointer to struct bgp_info */
2134 static route_map_result_t
route_set_label_index(void *rule
,
2135 struct prefix
*prefix
,
2136 route_map_object_t type
,
2139 struct rmap_value
*rv
;
2140 struct bgp_info
*bgp_info
;
2141 u_int32_t label_index
;
2143 if (type
== RMAP_BGP
) {
2144 /* Fetch routemap's rule information. */
2148 /* Set label-index value. */
2149 label_index
= rv
->value
;
2151 bgp_info
->attr
->label_index
= label_index
;
2152 bgp_info
->attr
->flag
|=
2153 ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2160 /* Route map commands for label-index set. */
2161 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2162 "label-index", route_set_label_index
, route_value_compile
,
2166 /* `match ipv6 address IP_ACCESS_LIST' */
2168 static route_map_result_t
route_match_ipv6_address(void *rule
,
2169 struct prefix
*prefix
,
2170 route_map_object_t type
,
2173 struct access_list
*alist
;
2175 if (type
== RMAP_BGP
) {
2176 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2178 return RMAP_NOMATCH
;
2180 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2184 return RMAP_NOMATCH
;
2187 static void *route_match_ipv6_address_compile(const char *arg
)
2189 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2192 static void route_match_ipv6_address_free(void *rule
)
2194 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2197 /* Route map commands for ip address matching. */
2198 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2199 "ipv6 address", route_match_ipv6_address
,
2200 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2202 /* `match ipv6 next-hop IP_ADDRESS' */
2204 static route_map_result_t
route_match_ipv6_next_hop(void *rule
,
2205 struct prefix
*prefix
,
2206 route_map_object_t type
,
2209 struct in6_addr
*addr
= rule
;
2210 struct bgp_info
*bgp_info
;
2212 if (type
== RMAP_BGP
) {
2215 if (IPV6_ADDR_SAME(&bgp_info
->attr
->mp_nexthop_global
, addr
))
2218 if (bgp_info
->attr
->mp_nexthop_len
2219 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2220 && IPV6_ADDR_SAME(&bgp_info
->attr
->mp_nexthop_local
, rule
))
2223 return RMAP_NOMATCH
;
2226 return RMAP_NOMATCH
;
2229 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2231 struct in6_addr
*address
;
2234 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2236 ret
= inet_pton(AF_INET6
, arg
, address
);
2238 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2245 static void route_match_ipv6_next_hop_free(void *rule
)
2247 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2250 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2251 "ipv6 next-hop", route_match_ipv6_next_hop
,
2252 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2254 /* `match ipv6 address prefix-list PREFIX_LIST' */
2256 static route_map_result_t
2257 route_match_ipv6_address_prefix_list(void *rule
, struct prefix
*prefix
,
2258 route_map_object_t type
, void *object
)
2260 struct prefix_list
*plist
;
2262 if (type
== RMAP_BGP
) {
2263 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
2265 return RMAP_NOMATCH
;
2267 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
2271 return RMAP_NOMATCH
;
2274 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2276 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2279 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2281 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2284 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2285 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2286 route_match_ipv6_address_prefix_list_compile
,
2287 route_match_ipv6_address_prefix_list_free
};
2289 /* `set ipv6 nexthop global IP_ADDRESS' */
2291 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2292 static route_map_result_t
route_set_ipv6_nexthop_global(void *rule
,
2293 struct prefix
*prefix
,
2294 route_map_object_t type
,
2297 struct in6_addr
*address
;
2298 struct bgp_info
*bgp_info
;
2300 if (type
== RMAP_BGP
) {
2301 /* Fetch routemap's rule information. */
2305 /* Set next hop value. */
2306 bgp_info
->attr
->mp_nexthop_global
= *address
;
2308 /* Set nexthop length. */
2309 if (bgp_info
->attr
->mp_nexthop_len
== 0)
2310 bgp_info
->attr
->mp_nexthop_len
=
2311 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2313 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2314 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2320 /* Route map `ip next-hop' compile function. Given string is converted
2321 to struct in_addr structure. */
2322 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2325 struct in6_addr
*address
;
2327 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2329 ret
= inet_pton(AF_INET6
, arg
, address
);
2332 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2339 /* Free route map's compiled `ip next-hop' value. */
2340 static void route_set_ipv6_nexthop_global_free(void *rule
)
2342 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2345 /* Route map commands for ip nexthop set. */
2346 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2347 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2348 route_set_ipv6_nexthop_global_compile
,
2349 route_set_ipv6_nexthop_global_free
};
2351 /* Set next-hop preference value. */
2352 static route_map_result_t
2353 route_set_ipv6_nexthop_prefer_global(void *rule
, struct prefix
*prefix
,
2354 route_map_object_t type
, void *object
)
2356 struct bgp_info
*bgp_info
;
2359 if (type
== RMAP_BGP
) {
2360 /* Fetch routemap's rule information. */
2362 peer
= bgp_info
->peer
;
2364 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2365 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2367 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2368 /* Set next hop preference to global */
2369 bgp_info
->attr
->mp_nexthop_prefer_global
= TRUE
;
2370 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2371 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2373 bgp_info
->attr
->mp_nexthop_prefer_global
= FALSE
;
2374 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2375 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2381 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2385 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2391 /* Free route map's compiled `ip next-hop' value. */
2392 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2394 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2397 /* Route map commands for ip nexthop set preferred. */
2398 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2399 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2400 route_set_ipv6_nexthop_prefer_global_compile
,
2401 route_set_ipv6_nexthop_prefer_global_free
};
2403 /* `set ipv6 nexthop local IP_ADDRESS' */
2405 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2406 static route_map_result_t
route_set_ipv6_nexthop_local(void *rule
,
2407 struct prefix
*prefix
,
2408 route_map_object_t type
,
2411 struct in6_addr
*address
;
2412 struct bgp_info
*bgp_info
;
2414 if (type
== RMAP_BGP
) {
2415 /* Fetch routemap's rule information. */
2419 /* Set next hop value. */
2420 bgp_info
->attr
->mp_nexthop_local
= *address
;
2422 /* Set nexthop length. */
2423 if (bgp_info
->attr
->mp_nexthop_len
2424 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2425 bgp_info
->attr
->mp_nexthop_len
=
2426 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2428 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2429 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2435 /* Route map `ip nexthop' compile function. Given string is converted
2436 to struct in_addr structure. */
2437 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2440 struct in6_addr
*address
;
2442 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2444 ret
= inet_pton(AF_INET6
, arg
, address
);
2447 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2454 /* Free route map's compiled `ip nexthop' value. */
2455 static void route_set_ipv6_nexthop_local_free(void *rule
)
2457 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2460 /* Route map commands for ip nexthop set. */
2461 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2462 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2463 route_set_ipv6_nexthop_local_compile
,
2464 route_set_ipv6_nexthop_local_free
};
2466 /* `set ipv6 nexthop peer-address' */
2468 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2469 static route_map_result_t
route_set_ipv6_nexthop_peer(void *rule
,
2470 struct prefix
*prefix
,
2471 route_map_object_t type
,
2474 struct in6_addr peer_address
;
2475 struct bgp_info
*bgp_info
;
2478 if (type
== RMAP_BGP
) {
2479 /* Fetch routemap's rule information. */
2481 peer
= bgp_info
->peer
;
2483 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2484 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2486 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2487 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2488 /* Set next hop value and length in attribute. */
2489 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2490 bgp_info
->attr
->mp_nexthop_local
= peer_address
;
2491 if (bgp_info
->attr
->mp_nexthop_len
!= 32)
2492 bgp_info
->attr
->mp_nexthop_len
= 32;
2494 bgp_info
->attr
->mp_nexthop_global
=
2496 if (bgp_info
->attr
->mp_nexthop_len
== 0)
2497 bgp_info
->attr
->mp_nexthop_len
= 16;
2500 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2501 /* The next hop value will be set as part of packet
2503 * Set the flags here to indicate that rewrite needs to
2505 * Also, clear the value - we clear both global and
2507 * nexthops, whether we send one or both is determined
2510 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2511 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2512 /* clear next hop value. */
2513 memset(&(bgp_info
->attr
->mp_nexthop_global
), 0,
2514 sizeof(struct in6_addr
));
2515 memset(&(bgp_info
->attr
->mp_nexthop_local
), 0,
2516 sizeof(struct in6_addr
));
2523 /* Route map `ip next-hop' compile function. Given string is converted
2524 to struct in_addr structure. */
2525 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2529 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2535 /* Free route map's compiled `ip next-hop' value. */
2536 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2538 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2541 /* Route map commands for ip nexthop set. */
2542 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2543 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2544 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2546 /* `set ipv4 vpn next-hop A.B.C.D' */
2548 static route_map_result_t
route_set_vpnv4_nexthop(void *rule
,
2549 struct prefix
*prefix
,
2550 route_map_object_t type
,
2553 struct in_addr
*address
;
2554 struct bgp_info
*bgp_info
;
2556 if (type
== RMAP_BGP
) {
2557 /* Fetch routemap's rule information. */
2561 /* Set next hop value. */
2562 bgp_info
->attr
->mp_nexthop_global_in
= *address
;
2563 bgp_info
->attr
->mp_nexthop_len
= 4;
2569 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2572 struct in_addr
*address
;
2574 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2576 ret
= inet_aton(arg
, address
);
2579 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2586 /* `set ipv6 vpn next-hop A.B.C.D' */
2588 static route_map_result_t
route_set_vpnv6_nexthop(void *rule
,
2589 struct prefix
*prefix
,
2590 route_map_object_t type
,
2593 struct in6_addr
*address
;
2594 struct bgp_info
*bgp_info
;
2596 if (type
== RMAP_BGP
) {
2597 /* Fetch routemap's rule information. */
2601 /* Set next hop value. */
2602 memcpy(&bgp_info
->attr
->mp_nexthop_global
, address
,
2603 sizeof(struct in6_addr
));
2604 bgp_info
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2610 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2613 struct in6_addr
*address
;
2615 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2616 ret
= inet_pton(AF_INET6
, arg
, address
);
2619 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2626 static void route_set_vpn_nexthop_free(void *rule
)
2628 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2631 /* Route map commands for ipv4 next-hop set. */
2632 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2633 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2634 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
2636 /* Route map commands for ipv6 next-hop set. */
2637 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
2638 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
2639 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
2641 /* `set originator-id' */
2643 /* For origin set. */
2644 static route_map_result_t
route_set_originator_id(void *rule
,
2645 struct prefix
*prefix
,
2646 route_map_object_t type
,
2649 struct in_addr
*address
;
2650 struct bgp_info
*bgp_info
;
2652 if (type
== RMAP_BGP
) {
2656 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
2657 bgp_info
->attr
->originator_id
= *address
;
2663 /* Compile function for originator-id set. */
2664 static void *route_set_originator_id_compile(const char *arg
)
2667 struct in_addr
*address
;
2669 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2671 ret
= inet_aton(arg
, address
);
2674 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2681 /* Compile function for originator_id set. */
2682 static void route_set_originator_id_free(void *rule
)
2684 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2687 /* Set originator-id rule structure. */
2688 struct route_map_rule_cmd route_set_originator_id_cmd
= {
2689 "originator-id", route_set_originator_id
,
2690 route_set_originator_id_compile
, route_set_originator_id_free
,
2693 /* Add bgp route map rule. */
2694 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
2695 const char *arg
, route_map_event_t type
)
2697 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2698 int retval
= CMD_SUCCESS
;
2701 ret
= route_map_add_match(index
, command
, arg
);
2703 case RMAP_RULE_MISSING
:
2704 vty_out(vty
, "%% BGP Can't find rule.\n");
2705 retval
= CMD_WARNING_CONFIG_FAILED
;
2707 case RMAP_COMPILE_ERROR
:
2708 vty_out(vty
, "%% BGP Argument is malformed.\n");
2709 retval
= CMD_WARNING_CONFIG_FAILED
;
2711 case RMAP_COMPILE_SUCCESS
:
2712 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
2713 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
2721 /* Delete bgp route map rule. */
2722 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
2723 const char *arg
, route_map_event_t type
)
2725 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2727 int retval
= CMD_SUCCESS
;
2728 char *dep_name
= NULL
;
2730 char *rmap_name
= NULL
;
2732 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
2733 /* ignore the mundane, the types without any dependency */
2735 if ((tmpstr
= route_map_get_match_arg(index
, command
))
2738 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
2740 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
2742 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
2745 ret
= route_map_delete_match(index
, command
, dep_name
);
2747 case RMAP_RULE_MISSING
:
2748 vty_out(vty
, "%% BGP Can't find rule.\n");
2749 retval
= CMD_WARNING_CONFIG_FAILED
;
2751 case RMAP_COMPILE_ERROR
:
2752 vty_out(vty
, "%% BGP Argument is malformed.\n");
2753 retval
= CMD_WARNING_CONFIG_FAILED
;
2755 case RMAP_COMPILE_SUCCESS
:
2756 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
2757 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
2762 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2764 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2770 * This is the workhorse routine for processing in/out routemap
2773 static void bgp_route_map_process_peer(const char *rmap_name
,
2774 struct route_map
*map
, struct peer
*peer
,
2775 int afi
, int safi
, int route_update
)
2779 struct bgp_filter
*filter
;
2781 if (!peer
|| !rmap_name
)
2784 filter
= &peer
->filter
[afi
][safi
];
2786 * in is for non-route-server clients,
2787 * out is for all peers
2789 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
2790 if (filter
->map
[RMAP_IN
].name
2791 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
2792 filter
->map
[RMAP_IN
].map
= map
;
2794 if (route_update
&& peer
->status
== Established
) {
2795 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
2796 PEER_FLAG_SOFT_RECONFIG
)) {
2797 if (bgp_debug_update(peer
, NULL
, NULL
,
2800 "Processing route_map %s update on "
2801 "peer %s (inbound, soft-reconfig)",
2802 rmap_name
, peer
->host
);
2804 bgp_soft_reconfig_in(peer
, afi
, safi
);
2806 CHECK_FLAG(peer
->cap
,
2807 PEER_CAP_REFRESH_OLD_RCV
)
2810 PEER_CAP_REFRESH_NEW_RCV
)) {
2812 if (bgp_debug_update(peer
, NULL
, NULL
,
2815 "Processing route_map %s update on "
2816 "peer %s (inbound, route-refresh)",
2817 rmap_name
, peer
->host
);
2818 bgp_route_refresh_send(peer
, afi
, safi
,
2825 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
2828 if (update
&& route_update
&& peer
->status
== Established
) {
2829 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
2830 PEER_FLAG_SOFT_RECONFIG
)) {
2831 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2833 "Processing route_map %s update on "
2834 "peer %s (import, soft-reconfig)",
2835 rmap_name
, peer
->host
);
2837 bgp_soft_reconfig_in(peer
, afi
, safi
);
2838 } else if (CHECK_FLAG(peer
->cap
,
2839 PEER_CAP_REFRESH_OLD_RCV
)
2840 || CHECK_FLAG(peer
->cap
,
2841 PEER_CAP_REFRESH_NEW_RCV
)) {
2842 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2844 "Processing route_map %s update on "
2845 "peer %s (import, route-refresh)",
2846 rmap_name
, peer
->host
);
2847 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
2850 /* DD: Else, what else do we do ? Reset peer ? */
2855 * For outbound, unsuppress and default-originate map change (content or
2856 * map created), merely update the "config" here, the actual route
2857 * announcement happens at the group level.
2859 if (filter
->map
[RMAP_OUT
].name
2860 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
2861 filter
->map
[RMAP_OUT
].map
= map
;
2863 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
2864 filter
->usmap
.map
= map
;
2866 if (peer
->default_rmap
[afi
][safi
].name
2867 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
2868 peer
->default_rmap
[afi
][safi
].map
= map
;
2871 static void bgp_route_map_update_peer_group(const char *rmap_name
,
2872 struct route_map
*map
,
2875 struct peer_group
*group
;
2876 struct listnode
*node
, *nnode
;
2877 struct bgp_filter
*filter
;
2884 /* All the peers have been updated correctly already. This is
2885 * just updating the placeholder data. No real update required.
2887 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
)) {
2888 FOREACH_AFI_SAFI (afi
, safi
) {
2889 filter
= &group
->conf
->filter
[afi
][safi
];
2891 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++) {
2892 if ((filter
->map
[direct
].name
)
2893 && (strcmp(rmap_name
,
2894 filter
->map
[direct
].name
)
2896 filter
->map
[direct
].map
= map
;
2899 if (filter
->usmap
.name
2900 && (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
2901 filter
->usmap
.map
= map
;
2907 * Note that if an extreme number (tens of thousands) of route-maps are in use
2908 * and if bgp has an extreme number of peers, network statements, etc then this
2909 * function can consume a lot of cycles. This is due to this function being
2910 * called for each route-map and within this function we walk the list of peers,
2911 * network statements, etc looking to see if they use this route-map.
2913 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
2920 struct bgp_node
*bn
;
2921 struct bgp_static
*bgp_static
;
2922 struct listnode
*node
, *nnode
;
2923 struct route_map
*map
;
2924 char buf
[INET6_ADDRSTRLEN
];
2926 map
= route_map_lookup_by_name(rmap_name
);
2928 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
2930 /* Ignore dummy peer-group structure */
2931 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
2934 FOREACH_AFI_SAFI (afi
, safi
) {
2935 /* process in/out/import/export/default-orig
2937 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
,
2938 safi
, route_update
);
2942 /* for outbound/default-orig route-maps, process for groups */
2943 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
2946 /* update peer-group config (template) */
2947 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
2949 FOREACH_AFI_SAFI (afi
, safi
) {
2950 /* For table route-map updates. */
2951 if (!bgp_fibupd_safi(safi
))
2954 if (bgp
->table_map
[afi
][safi
].name
2955 && (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
)
2957 bgp
->table_map
[afi
][safi
].map
= map
;
2959 if (BGP_DEBUG(zebra
, ZEBRA
))
2961 "Processing route_map %s update on "
2965 bgp_zebra_announce_table(bgp
, afi
, safi
);
2968 /* For network route-map updates. */
2969 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
2970 bn
= bgp_route_next(bn
))
2971 if ((bgp_static
= bn
->info
) != NULL
) {
2972 if (bgp_static
->rmap
.name
2973 && (strcmp(rmap_name
, bgp_static
->rmap
.name
)
2975 bgp_static
->rmap
.map
= map
;
2978 if (!bgp_static
->backdoor
) {
2979 if (bgp_debug_zebra(
2982 "Processing route_map %s update on "
2999 /* For redistribute route-map updates. */
3000 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3001 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
3002 struct list
*red_list
;
3003 struct listnode
*node
;
3004 struct bgp_redist
*red
;
3006 red_list
= bgp
->redist
[afi
][i
];
3010 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
3012 && (strcmp(rmap_name
, red
->rmap
.name
)
3014 red
->rmap
.map
= map
;
3017 if (BGP_DEBUG(zebra
, ZEBRA
))
3019 "Processing route_map %s update on "
3020 "redistributed routes",
3023 bgp_redistribute_resend(
3032 static int bgp_route_map_process_update_cb(char *rmap_name
)
3034 struct listnode
*node
, *nnode
;
3037 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3038 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3041 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3042 vnc_routemap_update(bgp
, __func__
);
3047 int bgp_route_map_update_timer(struct thread
*thread
)
3049 bm
->t_rmap_update
= NULL
;
3051 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3056 static void bgp_route_map_mark_update(const char *rmap_name
)
3058 if (bm
->t_rmap_update
== NULL
) {
3059 struct listnode
*node
, *nnode
;
3062 /* rmap_update_timer of 0 means don't do route updates */
3063 if (bm
->rmap_update_timer
) {
3064 bm
->t_rmap_update
= NULL
;
3065 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
3066 NULL
, bm
->rmap_update_timer
,
3067 &bm
->t_rmap_update
);
3069 /* Signal the groups that a route-map update event has
3071 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3072 update_group_policy_update(bgp
,
3073 BGP_POLICY_ROUTE_MAP
,
3076 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
3077 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3079 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3080 vnc_routemap_update(bgp
, __func__
);
3086 static void bgp_route_map_add(const char *rmap_name
)
3088 if (route_map_mark_updated(rmap_name
, 0) == 0)
3089 bgp_route_map_mark_update(rmap_name
);
3091 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3094 static void bgp_route_map_delete(const char *rmap_name
)
3096 if (route_map_mark_updated(rmap_name
, 1) == 0)
3097 bgp_route_map_mark_update(rmap_name
);
3099 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3102 static void bgp_route_map_event(route_map_event_t event
, const char *rmap_name
)
3104 if (route_map_mark_updated(rmap_name
, 0) == 0)
3105 bgp_route_map_mark_update(rmap_name
);
3107 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3110 DEFUN (match_mac_address
,
3111 match_mac_address_cmd
,
3112 "match mac address WORD",
3115 "Match address of route\n"
3116 "MAC Access-list name\n")
3118 return bgp_route_match_add(vty
, "mac address", argv
[3]->arg
,
3119 RMAP_EVENT_FILTER_ADDED
);
3122 DEFUN (no_match_mac_address
,
3123 no_match_mac_address_cmd
,
3124 "no match mac address WORD",
3128 "Match address of route\n"
3129 "MAC acess-list name\n")
3131 return bgp_route_match_delete(vty
, "mac address", argv
[4]->arg
,
3132 RMAP_EVENT_FILTER_DELETED
);
3135 DEFUN (match_evpn_vni
,
3137 "match evpn vni (1-16777215)",
3143 return bgp_route_match_add(vty
, "evpn vni", argv
[3]->arg
,
3144 RMAP_EVENT_MATCH_ADDED
);
3147 DEFUN (no_match_evpn_vni
,
3148 no_match_evpn_vni_cmd
,
3149 "no match evpn vni (1-16777215)",
3156 return bgp_route_match_delete(vty
, "evpn vni", argv
[4]->arg
,
3157 RMAP_EVENT_MATCH_DELETED
);
3162 "match peer <A.B.C.D|X:X::X:X|WORD>",
3164 "Match peer address\n"
3165 "IP address of peer\n"
3166 "IPv6 address of peer\n"
3167 "Interface name of peer\n")
3170 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3171 RMAP_EVENT_MATCH_ADDED
);
3174 DEFUN (match_peer_local
,
3175 match_peer_local_cmd
,
3178 "Match peer address\n"
3179 "Static or Redistributed routes\n")
3181 return bgp_route_match_add(vty
, "peer", "local",
3182 RMAP_EVENT_MATCH_DELETED
);
3185 DEFUN (no_match_peer
,
3187 "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
3190 "Match peer address\n"
3191 "Static or Redistributed routes\n"
3192 "IP address of peer\n"
3193 "IPv6 address of peer\n"
3194 "Interface name of peer\n")
3198 if (argc
<= idx_peer
)
3199 return bgp_route_match_delete(vty
, "peer", NULL
,
3200 RMAP_EVENT_MATCH_DELETED
);
3201 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3202 RMAP_EVENT_MATCH_DELETED
);
3206 /* match probability */
3207 DEFUN (match_probability
,
3208 match_probability_cmd
,
3209 "match probability (0-100)",
3211 "Match portion of routes defined by percentage value\n"
3212 "Percentage of routes\n")
3215 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3216 RMAP_EVENT_MATCH_ADDED
);
3220 DEFUN (no_match_probability
,
3221 no_match_probability_cmd
,
3222 "no match probability [(1-99)]",
3225 "Match portion of routes defined by percentage value\n"
3226 "Percentage of routes\n")
3229 if (argc
<= idx_number
)
3230 return bgp_route_match_delete(vty
, "probability", NULL
,
3231 RMAP_EVENT_MATCH_DELETED
);
3232 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3233 RMAP_EVENT_MATCH_DELETED
);
3237 DEFUN (match_ip_route_source
,
3238 match_ip_route_source_cmd
,
3239 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3242 "Match advertising source address of route\n"
3243 "IP access-list number\n"
3244 "IP access-list number (expanded range)\n"
3245 "IP standard access-list name\n")
3248 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3249 RMAP_EVENT_FILTER_ADDED
);
3253 DEFUN (no_match_ip_route_source
,
3254 no_match_ip_route_source_cmd
,
3255 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3259 "Match advertising source address of route\n"
3260 "IP access-list number\n"
3261 "IP access-list number (expanded range)\n"
3262 "IP standard access-list name\n")
3265 if (argc
<= idx_number
)
3266 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3267 RMAP_EVENT_FILTER_DELETED
);
3268 return bgp_route_match_delete(vty
, "ip route-source",
3269 argv
[idx_number
]->arg
,
3270 RMAP_EVENT_FILTER_DELETED
);
3274 DEFUN (match_ip_route_source_prefix_list
,
3275 match_ip_route_source_prefix_list_cmd
,
3276 "match ip route-source prefix-list WORD",
3279 "Match advertising source address of route\n"
3280 "Match entries of prefix-lists\n"
3281 "IP prefix-list name\n")
3284 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3285 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3289 DEFUN (no_match_ip_route_source_prefix_list
,
3290 no_match_ip_route_source_prefix_list_cmd
,
3291 "no match ip route-source prefix-list [WORD]",
3295 "Match advertising source address of route\n"
3296 "Match entries of prefix-lists\n"
3297 "IP prefix-list name\n")
3300 if (argc
<= idx_word
)
3301 return bgp_route_match_delete(vty
,
3302 "ip route-source prefix-list",
3303 NULL
, RMAP_EVENT_PLIST_DELETED
);
3304 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3305 argv
[idx_word
]->arg
,
3306 RMAP_EVENT_PLIST_DELETED
);
3310 DEFUN (match_local_pref
,
3311 match_local_pref_cmd
,
3312 "match local-preference (0-4294967295)",
3314 "Match local-preference of route\n"
3318 return bgp_route_match_add(vty
, "local-preference",
3319 argv
[idx_number
]->arg
,
3320 RMAP_EVENT_MATCH_ADDED
);
3324 DEFUN (no_match_local_pref
,
3325 no_match_local_pref_cmd
,
3326 "no match local-preference [(0-4294967295)]",
3329 "Match local preference of route\n"
3330 "Local preference value\n")
3332 int idx_localpref
= 3;
3333 if (argc
<= idx_localpref
)
3334 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3335 RMAP_EVENT_MATCH_DELETED
);
3336 return bgp_route_match_delete(vty
, "local-preference",
3337 argv
[idx_localpref
]->arg
,
3338 RMAP_EVENT_MATCH_DELETED
);
3342 DEFUN (match_community
,
3343 match_community_cmd
,
3344 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3346 "Match BGP community list\n"
3347 "Community-list number (standard)\n"
3348 "Community-list number (expanded)\n"
3349 "Community-list name\n"
3350 "Do exact matching of communities\n")
3352 int idx_comm_list
= 2;
3357 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3358 strlen(argv
[idx_comm_list
]->arg
)
3359 + strlen("exact-match") + 2);
3361 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3363 argstr
= argv
[idx_comm_list
]->arg
;
3365 ret
= bgp_route_match_add(vty
, "community", argstr
,
3366 RMAP_EVENT_CLIST_ADDED
);
3368 if (argstr
!= argv
[idx_comm_list
]->arg
)
3369 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3374 DEFUN (no_match_community
,
3375 no_match_community_cmd
,
3376 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3379 "Match BGP community list\n"
3380 "Community-list number (standard)\n"
3381 "Community-list number (expanded)\n"
3382 "Community-list name\n"
3383 "Do exact matching of communities\n")
3385 return bgp_route_match_delete(vty
, "community", NULL
,
3386 RMAP_EVENT_CLIST_DELETED
);
3389 DEFUN (match_lcommunity
,
3390 match_lcommunity_cmd
,
3391 "match large-community <(1-99)|(100-500)|WORD>",
3393 "Match BGP large community list\n"
3394 "Large Community-list number (standard)\n"
3395 "Large Community-list number (expanded)\n"
3396 "Large Community-list name\n")
3398 return bgp_route_match_add(vty
, "large-community", argv
[2]->arg
,
3399 RMAP_EVENT_LLIST_ADDED
);
3402 DEFUN (no_match_lcommunity
,
3403 no_match_lcommunity_cmd
,
3404 "no match large-community [<(1-99)|(100-500)|WORD>]",
3407 "Match BGP large community list\n"
3408 "Large Community-list number (standard)\n"
3409 "Large Community-list number (expanded)\n"
3410 "Large Community-list name\n")
3412 return bgp_route_match_delete(vty
, "large-community", NULL
,
3413 RMAP_EVENT_LLIST_DELETED
);
3416 DEFUN (match_ecommunity
,
3417 match_ecommunity_cmd
,
3418 "match extcommunity <(1-99)|(100-500)|WORD>",
3420 "Match BGP/VPN extended community list\n"
3421 "Extended community-list number (standard)\n"
3422 "Extended community-list number (expanded)\n"
3423 "Extended community-list name\n")
3425 int idx_comm_list
= 2;
3426 return bgp_route_match_add(vty
, "extcommunity",
3427 argv
[idx_comm_list
]->arg
,
3428 RMAP_EVENT_ECLIST_ADDED
);
3432 DEFUN (no_match_ecommunity
,
3433 no_match_ecommunity_cmd
,
3434 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3437 "Match BGP/VPN extended community list\n"
3438 "Extended community-list number (standard)\n"
3439 "Extended community-list number (expanded)\n"
3440 "Extended community-list name\n")
3442 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3443 RMAP_EVENT_ECLIST_DELETED
);
3447 DEFUN (match_aspath
,
3449 "match as-path WORD",
3451 "Match BGP AS path list\n"
3452 "AS path access-list name\n")
3455 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3456 RMAP_EVENT_ASLIST_ADDED
);
3460 DEFUN (no_match_aspath
,
3461 no_match_aspath_cmd
,
3462 "no match as-path [WORD]",
3465 "Match BGP AS path list\n"
3466 "AS path access-list name\n")
3468 return bgp_route_match_delete(vty
, "as-path", NULL
,
3469 RMAP_EVENT_ASLIST_DELETED
);
3473 DEFUN (match_origin
,
3475 "match origin <egp|igp|incomplete>",
3480 "unknown heritage\n")
3483 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3484 return bgp_route_match_add(vty
, "origin", "igp",
3485 RMAP_EVENT_MATCH_ADDED
);
3486 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3487 return bgp_route_match_add(vty
, "origin", "egp",
3488 RMAP_EVENT_MATCH_ADDED
);
3489 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3490 return bgp_route_match_add(vty
, "origin", "incomplete",
3491 RMAP_EVENT_MATCH_ADDED
);
3493 vty_out(vty
, "%% Invalid match origin type\n");
3494 return CMD_WARNING_CONFIG_FAILED
;
3498 DEFUN (no_match_origin
,
3499 no_match_origin_cmd
,
3500 "no match origin [<egp|igp|incomplete>]",
3506 "unknown heritage\n")
3508 return bgp_route_match_delete(vty
, "origin", NULL
,
3509 RMAP_EVENT_MATCH_DELETED
);
3512 DEFUN (set_ip_nexthop_peer
,
3513 set_ip_nexthop_peer_cmd
,
3514 "[no] set ip next-hop peer-address",
3518 "Next hop address\n"
3519 "Use peer address (for BGP only)\n")
3521 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3522 const char *) = strmatch(argv
[0]->text
, "no")
3523 ? generic_set_delete
3526 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3530 DEFUN (set_ip_nexthop_unchanged
,
3531 set_ip_nexthop_unchanged_cmd
,
3532 "[no] set ip next-hop unchanged",
3536 "Next hop address\n"
3537 "Don't modify existing Next hop address\n")
3539 int (*func
)(struct vty
*, struct route_map_index
*, const char *,
3540 const char *) = strmatch(argv
[0]->text
, "no")
3541 ? generic_set_delete
3544 return func(vty
, VTY_GET_CONTEXT(route_map_index
), "ip next-hop",
3549 DEFUN (set_local_pref
,
3551 "set local-preference (0-4294967295)",
3553 "BGP local preference path attribute\n"
3554 "Preference value\n")
3557 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3558 "local-preference", argv
[idx_number
]->arg
);
3562 DEFUN (no_set_local_pref
,
3563 no_set_local_pref_cmd
,
3564 "no set local-preference [(0-4294967295)]",
3567 "BGP local preference path attribute\n"
3568 "Preference value\n")
3570 int idx_localpref
= 3;
3571 if (argc
<= idx_localpref
)
3572 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3573 "local-preference", NULL
);
3574 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3575 "local-preference", argv
[idx_localpref
]->arg
);
3581 "set weight (0-4294967295)",
3583 "BGP weight for routing table\n"
3587 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
3588 argv
[idx_number
]->arg
);
3592 DEFUN (no_set_weight
,
3594 "no set weight [(0-4294967295)]",
3597 "BGP weight for routing table\n"
3601 if (argc
<= idx_weight
)
3602 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3604 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3605 "weight", argv
[idx_weight
]->arg
);
3608 DEFUN (set_label_index
,
3609 set_label_index_cmd
,
3610 "set label-index (0-1048560)",
3612 "Label index to associate with the prefix\n"
3613 "Label index value\n")
3616 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3617 "label-index", argv
[idx_number
]->arg
);
3620 DEFUN (no_set_label_index
,
3621 no_set_label_index_cmd
,
3622 "no set label-index [(0-1048560)]",
3625 "Label index to associate with the prefix\n"
3626 "Label index value\n")
3628 int idx_label_index
= 3;
3629 if (argc
<= idx_label_index
)
3630 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3631 "label-index", NULL
);
3632 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3633 "label-index", argv
[idx_label_index
]->arg
);
3636 DEFUN (set_aspath_prepend_asn
,
3637 set_aspath_prepend_asn_cmd
,
3638 "set as-path prepend (1-4294967295)...",
3640 "Transform BGP AS_PATH attribute\n"
3641 "Prepend to the as-path\n"
3648 str
= argv_concat(argv
, argc
, idx_asn
);
3649 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3650 "as-path prepend", str
);
3651 XFREE(MTYPE_TMP
, str
);
3656 DEFUN (set_aspath_prepend_lastas
,
3657 set_aspath_prepend_lastas_cmd
,
3658 "set as-path prepend last-as (1-10)",
3660 "Transform BGP AS_PATH attribute\n"
3661 "Prepend to the as-path\n"
3662 "Use the peer's AS-number\n"
3663 "Number of times to insert\n")
3665 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
3668 DEFUN (no_set_aspath_prepend
,
3669 no_set_aspath_prepend_cmd
,
3670 "no set as-path prepend [(1-4294967295)]",
3673 "Transform BGP AS_PATH attribute\n"
3674 "Prepend to the as-path\n"
3681 str
= argv_concat(argv
, argc
, idx_asn
);
3682 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3683 "as-path prepend", str
);
3684 XFREE(MTYPE_TMP
, str
);
3689 DEFUN (set_aspath_exclude
,
3690 set_aspath_exclude_cmd
,
3691 "set as-path exclude (1-4294967295)...",
3693 "Transform BGP AS-path attribute\n"
3694 "Exclude from the as-path\n"
3701 str
= argv_concat(argv
, argc
, idx_asn
);
3702 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3703 "as-path exclude", str
);
3704 XFREE(MTYPE_TMP
, str
);
3708 DEFUN (no_set_aspath_exclude
,
3709 no_set_aspath_exclude_cmd
,
3710 "no set as-path exclude (1-4294967295)...",
3713 "Transform BGP AS_PATH attribute\n"
3714 "Exclude from the as-path\n"
3721 str
= argv_concat(argv
, argc
, idx_asn
);
3722 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3723 "as-path exclude", str
);
3724 XFREE(MTYPE_TMP
, str
);
3729 DEFUN (set_community
,
3731 "set community AA:NN...",
3733 "BGP community attribute\n"
3741 struct community
*com
= NULL
;
3746 b
= buffer_new(1024);
3748 for (i
= idx_aa_nn
; i
< argc
; i
++) {
3749 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
3756 buffer_putc(b
, ' ');
3760 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
3762 buffer_putstr(b
, "internet");
3765 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
3767 buffer_putstr(b
, "local-AS");
3770 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
3771 && strncmp(argv
[i
]->arg
, "no-advertise",
3772 strlen(argv
[i
]->arg
))
3774 buffer_putstr(b
, "no-advertise");
3777 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
3778 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
3780 buffer_putstr(b
, "no-export");
3783 if (strncmp(argv
[i
]->arg
, "graceful-shutdown", strlen(argv
[i
]->arg
))
3785 buffer_putstr(b
, "graceful-shutdown");
3788 buffer_putstr(b
, argv
[i
]->arg
);
3790 buffer_putc(b
, '\0');
3792 /* Fetch result string then compile it to communities attribute. */
3793 str
= buffer_getstr(b
);
3797 com
= community_str2com(str
);
3798 XFREE(MTYPE_TMP
, str
);
3801 /* Can't compile user input into communities attribute. */
3803 vty_out(vty
, "%% Malformed communities attribute\n");
3804 return CMD_WARNING_CONFIG_FAILED
;
3807 /* Set communites attribute string. */
3808 str
= community_str(com
, false);
3811 argstr
= XCALLOC(MTYPE_TMP
,
3812 strlen(str
) + strlen(" additive") + 1);
3813 strcpy(argstr
, str
);
3814 strcpy(argstr
+ strlen(str
), " additive");
3815 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3816 "community", argstr
);
3817 XFREE(MTYPE_TMP
, argstr
);
3819 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3822 community_free(com
);
3827 DEFUN (set_community_none
,
3828 set_community_none_cmd
,
3829 "set community none",
3831 "BGP community attribute\n"
3832 "No community attribute\n")
3834 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3835 "community", "none");
3838 DEFUN (no_set_community
,
3839 no_set_community_cmd
,
3840 "no set community AA:NN...",
3843 "BGP community attribute\n"
3846 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3851 DEFUN (set_community_delete
,
3852 set_community_delete_cmd
,
3853 "set comm-list <(1-99)|(100-500)|WORD> delete",
3855 "set BGP community list (for deletion)\n"
3856 "Community-list number (standard)\n"
3857 "Community-list number (expanded)\n"
3858 "Community-list name\n"
3859 "Delete matching communities\n")
3861 int idx_comm_list
= 2;
3864 str
= XCALLOC(MTYPE_TMP
,
3865 strlen(argv
[idx_comm_list
]->arg
) + strlen(" delete") + 1);
3866 strcpy(str
, argv
[idx_comm_list
]->arg
);
3867 strcpy(str
+ strlen(argv
[idx_comm_list
]->arg
), " delete");
3869 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
3872 XFREE(MTYPE_TMP
, str
);
3876 DEFUN (no_set_community_delete
,
3877 no_set_community_delete_cmd
,
3878 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
3881 "set BGP community list (for deletion)\n"
3882 "Community-list number (standard)\n"
3883 "Community-list number (expanded)\n"
3884 "Community-list name\n"
3885 "Delete matching communities\n")
3887 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3891 DEFUN (set_lcommunity
,
3893 "set large-community AA:BB:CC...",
3895 "BGP large community attribute\n"
3896 "Large Community number in aa:bb:cc format or additive\n")
3901 str
= argv_concat(argv
, argc
, 2);
3902 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3903 "large-community", str
);
3904 XFREE(MTYPE_TMP
, str
);
3909 DEFUN (set_lcommunity_none
,
3910 set_lcommunity_none_cmd
,
3911 "set large-community none",
3913 "BGP large community attribute\n"
3914 "No large community attribute\n")
3916 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3917 "large-community", "none");
3920 DEFUN (no_set_lcommunity
,
3921 no_set_lcommunity_cmd
,
3922 "no set large-community none",
3925 "BGP large community attribute\n"
3926 "No community attribute\n")
3928 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3929 "large-community", NULL
);
3932 DEFUN (no_set_lcommunity1
,
3933 no_set_lcommunity1_cmd
,
3934 "no set large-community AA:BB:CC...",
3937 "BGP large community attribute\n"
3938 "Large community in AA:BB:CC... format or additive\n")
3940 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3941 "large-community", NULL
);
3944 DEFUN (set_lcommunity_delete
,
3945 set_lcommunity_delete_cmd
,
3946 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
3948 "set BGP large community list (for deletion)\n"
3949 "Large Community-list number (standard)\n"
3950 "Large Communitly-list number (expanded)\n"
3951 "Large Community-list name\n"
3952 "Delete matching large communities\n")
3956 str
= XCALLOC(MTYPE_TMP
, strlen(argv
[2]->arg
) + strlen(" delete") + 1);
3957 strcpy(str
, argv
[2]->arg
);
3958 strcpy(str
+ strlen(argv
[2]->arg
), " delete");
3960 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3961 "large-comm-list", str
);
3963 XFREE(MTYPE_TMP
, str
);
3967 DEFUN (no_set_lcommunity_delete
,
3968 no_set_lcommunity_delete_cmd
,
3969 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
3972 "set BGP large community list (for deletion)\n"
3973 "Large Community-list number (standard)\n"
3974 "Large Communitly-list number (expanded)\n"
3975 "Large Community-list name\n"
3976 "Delete matching large communities\n")
3978 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3979 "large-comm-list", NULL
);
3982 DEFUN (set_ecommunity_rt
,
3983 set_ecommunity_rt_cmd
,
3984 "set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
3986 "BGP extended community attribute\n"
3987 "Route Target extended community\n"
3988 "VPN extended community\n")
3994 str
= argv_concat(argv
, argc
, idx_asn_nn
);
3995 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3996 "extcommunity rt", str
);
3997 XFREE(MTYPE_TMP
, str
);
4002 DEFUN (no_set_ecommunity_rt
,
4003 no_set_ecommunity_rt_cmd
,
4004 "no set extcommunity rt ASN:NN_OR_IP-ADDRESS:NN...",
4007 "BGP extended community attribute\n"
4008 "Route Target extended community\n"
4009 "VPN extended community\n")
4011 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4012 "extcommunity rt", NULL
);
4016 DEFUN (set_ecommunity_soo
,
4017 set_ecommunity_soo_cmd
,
4018 "set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4020 "BGP extended community attribute\n"
4021 "Site-of-Origin extended community\n"
4022 "VPN extended community\n")
4028 str
= argv_concat(argv
, argc
, idx_asn_nn
);
4029 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4030 "extcommunity soo", str
);
4031 XFREE(MTYPE_TMP
, str
);
4036 DEFUN (no_set_ecommunity_soo
,
4037 no_set_ecommunity_soo_cmd
,
4038 "no set extcommunity soo ASN:NN_OR_IP-ADDRESS:NN...",
4041 "BGP extended community attribute\n"
4042 "Site-of-Origin extended community\n"
4043 "VPN extended community\n")
4045 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4046 "extcommunity soo", NULL
);
4052 "set origin <egp|igp|incomplete>",
4057 "unknown heritage\n")
4060 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
4061 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4063 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
4064 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4066 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4067 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4068 "origin", "incomplete");
4070 vty_out(vty
, "%% Invalid set origin type\n");
4071 return CMD_WARNING_CONFIG_FAILED
;
4075 DEFUN (no_set_origin
,
4077 "no set origin [<egp|igp|incomplete>]",
4083 "unknown heritage\n")
4085 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4090 DEFUN (set_atomic_aggregate
,
4091 set_atomic_aggregate_cmd
,
4092 "set atomic-aggregate",
4094 "BGP atomic aggregate attribute\n" )
4096 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4097 "atomic-aggregate", NULL
);
4100 DEFUN (no_set_atomic_aggregate
,
4101 no_set_atomic_aggregate_cmd
,
4102 "no set atomic-aggregate",
4105 "BGP atomic aggregate attribute\n" )
4107 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4108 "atomic-aggregate", NULL
);
4111 DEFUN (set_aggregator_as
,
4112 set_aggregator_as_cmd
,
4113 "set aggregator as (1-4294967295) A.B.C.D",
4115 "BGP aggregator attribute\n"
4116 "AS number of aggregator\n"
4118 "IP address of aggregator\n")
4123 struct in_addr address
;
4126 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
4128 vty_out(vty
, "Aggregator IP address is invalid\n");
4129 return CMD_WARNING_CONFIG_FAILED
;
4132 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4133 strlen(argv
[idx_number
]->arg
)
4134 + strlen(argv
[idx_ipv4
]->arg
) + 2);
4136 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4138 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4139 "aggregator as", argstr
);
4141 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4147 DEFUN (no_set_aggregator_as
,
4148 no_set_aggregator_as_cmd
,
4149 "no set aggregator as [(1-4294967295) A.B.C.D]",
4152 "BGP aggregator attribute\n"
4153 "AS number of aggregator\n"
4155 "IP address of aggregator\n")
4160 struct in_addr address
;
4163 if (argc
<= idx_asn
)
4164 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4165 "aggregator as", NULL
);
4167 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
4169 vty_out(vty
, "Aggregator IP address is invalid\n");
4170 return CMD_WARNING_CONFIG_FAILED
;
4173 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
4174 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
4177 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4179 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4180 "aggregator as", argstr
);
4182 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4187 DEFUN (match_ipv6_next_hop
,
4188 match_ipv6_next_hop_cmd
,
4189 "match ipv6 next-hop X:X::X:X",
4192 "Match IPv6 next-hop address of route\n"
4193 "IPv6 address of next hop\n")
4196 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4197 RMAP_EVENT_MATCH_ADDED
);
4200 DEFUN (no_match_ipv6_next_hop
,
4201 no_match_ipv6_next_hop_cmd
,
4202 "no match ipv6 next-hop X:X::X:X",
4206 "Match IPv6 next-hop address of route\n"
4207 "IPv6 address of next hop\n")
4210 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4211 RMAP_EVENT_MATCH_DELETED
);
4215 DEFUN (set_ipv6_nexthop_peer
,
4216 set_ipv6_nexthop_peer_cmd
,
4217 "set ipv6 next-hop peer-address",
4220 "Next hop address\n"
4221 "Use peer address (for BGP only)\n")
4223 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4224 "ipv6 next-hop peer-address", NULL
);
4227 DEFUN (no_set_ipv6_nexthop_peer
,
4228 no_set_ipv6_nexthop_peer_cmd
,
4229 "no set ipv6 next-hop peer-address",
4233 "IPv6 next-hop address\n"
4234 "Use peer address (for BGP only)\n")
4236 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4237 "ipv6 next-hop peer-address", NULL
);
4240 DEFUN (set_ipv6_nexthop_prefer_global
,
4241 set_ipv6_nexthop_prefer_global_cmd
,
4242 "set ipv6 next-hop prefer-global",
4245 "IPv6 next-hop address\n"
4246 "Prefer global over link-local if both exist\n")
4248 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4249 "ipv6 next-hop prefer-global", NULL
);
4253 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4254 no_set_ipv6_nexthop_prefer_global_cmd
,
4255 "no set ipv6 next-hop prefer-global",
4259 "IPv6 next-hop address\n"
4260 "Prefer global over link-local if both exist\n")
4262 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4263 "ipv6 next-hop prefer-global", NULL
);
4266 DEFUN (set_ipv6_nexthop_global
,
4267 set_ipv6_nexthop_global_cmd
,
4268 "set ipv6 next-hop global X:X::X:X",
4271 "IPv6 next-hop address\n"
4272 "IPv6 global address\n"
4273 "IPv6 address of next hop\n")
4276 struct in6_addr addr
;
4279 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4281 vty_out(vty
, "%% Malformed nexthop address\n");
4282 return CMD_WARNING_CONFIG_FAILED
;
4284 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4285 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4286 vty_out(vty
, "%% Invalid global nexthop address\n");
4287 return CMD_WARNING_CONFIG_FAILED
;
4290 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4291 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4295 DEFUN (no_set_ipv6_nexthop_global
,
4296 no_set_ipv6_nexthop_global_cmd
,
4297 "no set ipv6 next-hop global X:X::X:X",
4301 "IPv6 next-hop address\n"
4302 "IPv6 global address\n"
4303 "IPv6 address of next hop\n")
4306 if (argc
<= idx_ipv6
)
4307 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4308 "ipv6 next-hop global", NULL
);
4309 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4310 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4313 #ifdef KEEP_OLD_VPN_COMMANDS
4314 DEFUN (set_vpn_nexthop
,
4315 set_vpn_nexthop_cmd
,
4316 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4318 "VPNv4 information\n"
4319 "VPN next-hop address\n"
4320 "IP address of next hop\n"
4321 "VPNv6 information\n"
4322 "VPN next-hop address\n"
4323 "IPv6 address of next hop\n")
4329 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4331 return generic_set_add(
4332 vty
, VTY_GET_CONTEXT(route_map_index
),
4333 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4335 return generic_set_add(
4336 vty
, VTY_GET_CONTEXT(route_map_index
),
4337 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4342 DEFUN (no_set_vpn_nexthop
,
4343 no_set_vpn_nexthop_cmd
,
4344 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4347 "VPNv4 information\n"
4348 "VPN next-hop address\n"
4349 "IP address of next hop\n"
4350 "VPNv6 information\n"
4351 "VPN next-hop address\n"
4352 "IPv6 address of next hop\n")
4362 arg
= argv
[idx_ip
]->arg
;
4363 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4365 return generic_set_delete(
4366 vty
, VTY_GET_CONTEXT(route_map_index
),
4367 "ipv4 vpn next-hop", arg
);
4369 return generic_set_delete(
4370 vty
, VTY_GET_CONTEXT(route_map_index
),
4371 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4375 #endif /* KEEP_OLD_VPN_COMMANDS */
4377 DEFUN (set_ipx_vpn_nexthop
,
4378 set_ipx_vpn_nexthop_cmd
,
4379 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4381 "IPv4 information\n"
4382 "IPv6 information\n"
4384 "VPN next-hop address\n"
4385 "IP address of next hop\n"
4386 "IPv6 address of next hop\n")
4392 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4394 return generic_set_add(
4395 vty
, VTY_GET_CONTEXT(route_map_index
),
4396 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4398 return generic_set_add(
4399 vty
, VTY_GET_CONTEXT(route_map_index
),
4400 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4405 DEFUN (no_set_ipx_vpn_nexthop
,
4406 no_set_ipx_vpn_nexthop_cmd
,
4407 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4410 "IPv4 information\n"
4411 "IPv6 information\n"
4413 "VPN next-hop address\n"
4414 "IP address of next hop\n"
4415 "IPv6 address of next hop\n")
4425 arg
= argv
[idx_ip
]->arg
;
4426 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4428 return generic_set_delete(
4429 vty
, VTY_GET_CONTEXT(route_map_index
),
4430 "ipv4 vpn next-hop", arg
);
4432 return generic_set_delete(
4433 vty
, VTY_GET_CONTEXT(route_map_index
),
4434 "ipv6 vpn next-hop", arg
);
4439 DEFUN (set_originator_id
,
4440 set_originator_id_cmd
,
4441 "set originator-id A.B.C.D",
4443 "BGP originator ID attribute\n"
4444 "IP address of originator\n")
4447 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4448 "originator-id", argv
[idx_ipv4
]->arg
);
4452 DEFUN (no_set_originator_id
,
4453 no_set_originator_id_cmd
,
4454 "no set originator-id [A.B.C.D]",
4457 "BGP originator ID attribute\n"
4458 "IP address of originator\n")
4462 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4464 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4465 "originator-id", arg
);
4469 /* Initialization of route map. */
4470 void bgp_route_map_init(void)
4474 route_map_add_hook(bgp_route_map_add
);
4475 route_map_delete_hook(bgp_route_map_delete
);
4476 route_map_event_hook(bgp_route_map_event
);
4478 route_map_match_interface_hook(generic_match_add
);
4479 route_map_no_match_interface_hook(generic_match_delete
);
4481 route_map_match_ip_address_hook(generic_match_add
);
4482 route_map_no_match_ip_address_hook(generic_match_delete
);
4484 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
4485 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
4487 route_map_match_ip_next_hop_hook(generic_match_add
);
4488 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
4490 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
4491 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
4493 route_map_match_ipv6_address_hook(generic_match_add
);
4494 route_map_no_match_ipv6_address_hook(generic_match_delete
);
4496 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
4497 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
4499 route_map_match_metric_hook(generic_match_add
);
4500 route_map_no_match_metric_hook(generic_match_delete
);
4502 route_map_match_tag_hook(generic_match_add
);
4503 route_map_no_match_tag_hook(generic_match_delete
);
4505 route_map_set_ip_nexthop_hook(generic_set_add
);
4506 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
4508 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
4509 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
4511 route_map_set_metric_hook(generic_set_add
);
4512 route_map_no_set_metric_hook(generic_set_delete
);
4514 route_map_set_tag_hook(generic_set_add
);
4515 route_map_no_set_tag_hook(generic_set_delete
);
4517 route_map_install_match(&route_match_peer_cmd
);
4518 route_map_install_match(&route_match_local_pref_cmd
);
4519 route_map_install_match(&route_match_ip_address_cmd
);
4520 route_map_install_match(&route_match_ip_next_hop_cmd
);
4521 route_map_install_match(&route_match_ip_route_source_cmd
);
4522 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
4523 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
4524 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
4525 route_map_install_match(&route_match_aspath_cmd
);
4526 route_map_install_match(&route_match_community_cmd
);
4527 route_map_install_match(&route_match_lcommunity_cmd
);
4528 route_map_install_match(&route_match_ecommunity_cmd
);
4529 route_map_install_match(&route_match_local_pref_cmd
);
4530 route_map_install_match(&route_match_metric_cmd
);
4531 route_map_install_match(&route_match_origin_cmd
);
4532 route_map_install_match(&route_match_probability_cmd
);
4533 route_map_install_match(&route_match_interface_cmd
);
4534 route_map_install_match(&route_match_tag_cmd
);
4535 route_map_install_match(&route_match_mac_address_cmd
);
4536 route_map_install_match(&route_match_evpn_vni_cmd
);
4538 route_map_install_set(&route_set_ip_nexthop_cmd
);
4539 route_map_install_set(&route_set_local_pref_cmd
);
4540 route_map_install_set(&route_set_weight_cmd
);
4541 route_map_install_set(&route_set_label_index_cmd
);
4542 route_map_install_set(&route_set_metric_cmd
);
4543 route_map_install_set(&route_set_aspath_prepend_cmd
);
4544 route_map_install_set(&route_set_aspath_exclude_cmd
);
4545 route_map_install_set(&route_set_origin_cmd
);
4546 route_map_install_set(&route_set_atomic_aggregate_cmd
);
4547 route_map_install_set(&route_set_aggregator_as_cmd
);
4548 route_map_install_set(&route_set_community_cmd
);
4549 route_map_install_set(&route_set_community_delete_cmd
);
4550 route_map_install_set(&route_set_lcommunity_cmd
);
4551 route_map_install_set(&route_set_lcommunity_delete_cmd
);
4552 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
4553 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
4554 route_map_install_set(&route_set_originator_id_cmd
);
4555 route_map_install_set(&route_set_ecommunity_rt_cmd
);
4556 route_map_install_set(&route_set_ecommunity_soo_cmd
);
4557 route_map_install_set(&route_set_tag_cmd
);
4558 route_map_install_set(&route_set_label_index_cmd
);
4560 install_element(RMAP_NODE
, &match_peer_cmd
);
4561 install_element(RMAP_NODE
, &match_peer_local_cmd
);
4562 install_element(RMAP_NODE
, &no_match_peer_cmd
);
4563 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
4564 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
4565 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
4566 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
4567 install_element(RMAP_NODE
, &match_mac_address_cmd
);
4568 install_element(RMAP_NODE
, &no_match_mac_address_cmd
);
4569 install_element(RMAP_NODE
, &match_evpn_vni_cmd
);
4570 install_element(RMAP_NODE
, &no_match_evpn_vni_cmd
);
4572 install_element(RMAP_NODE
, &match_aspath_cmd
);
4573 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
4574 install_element(RMAP_NODE
, &match_local_pref_cmd
);
4575 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
4576 install_element(RMAP_NODE
, &match_community_cmd
);
4577 install_element(RMAP_NODE
, &no_match_community_cmd
);
4578 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
4579 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
4580 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
4581 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
4582 install_element(RMAP_NODE
, &match_origin_cmd
);
4583 install_element(RMAP_NODE
, &no_match_origin_cmd
);
4584 install_element(RMAP_NODE
, &match_probability_cmd
);
4585 install_element(RMAP_NODE
, &no_match_probability_cmd
);
4587 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
4588 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
4589 install_element(RMAP_NODE
, &set_local_pref_cmd
);
4590 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
4591 install_element(RMAP_NODE
, &set_weight_cmd
);
4592 install_element(RMAP_NODE
, &set_label_index_cmd
);
4593 install_element(RMAP_NODE
, &no_set_weight_cmd
);
4594 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
4595 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
4596 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
4597 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
4598 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
4599 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
4600 install_element(RMAP_NODE
, &set_origin_cmd
);
4601 install_element(RMAP_NODE
, &no_set_origin_cmd
);
4602 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
4603 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
4604 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
4605 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
4606 install_element(RMAP_NODE
, &set_community_cmd
);
4607 install_element(RMAP_NODE
, &set_community_none_cmd
);
4608 install_element(RMAP_NODE
, &no_set_community_cmd
);
4609 install_element(RMAP_NODE
, &set_community_delete_cmd
);
4610 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
4611 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
4612 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
4613 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
4614 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
4615 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
4616 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
4617 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
4618 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
4619 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
4620 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
4621 #ifdef KEEP_OLD_VPN_COMMANDS
4622 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
4623 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
4624 #endif /* KEEP_OLD_VPN_COMMANDS */
4625 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
4626 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
4627 install_element(RMAP_NODE
, &set_originator_id_cmd
);
4628 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
4630 route_map_install_match(&route_match_ipv6_address_cmd
);
4631 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
4632 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
4633 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
4634 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
4635 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
4636 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
4638 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
4639 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
4640 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
4641 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
4642 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
4643 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
4644 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
4645 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
4648 void bgp_route_map_terminate(void)
4650 /* ToDo: Cleanup all the used memory */
4652 route_map_add_hook(NULL
);
4653 route_map_delete_hook(NULL
);
4654 route_map_event_hook(NULL
);