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"
59 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
62 /* Memo of route-map commands.
71 ip route-source : Done
75 ipv6 route-source: (This will not be implemented by bgpd)
76 ipv6 prefix-list : Done
77 length : (This will not be implemented by bgpd)
79 route-type : (This will not be implemented by bgpd)
81 local-preference : Done
83 set as-path prepend : Done
85 automatic-tag : (This will not be implemented by bgpd)
87 large-community : Done
88 large-comm-list : Done
91 default : (This will not be implemented by bgpd)
92 interface : (This will not be implemented by bgpd)
93 ip default : (This will not be implemented by bgpd)
95 ip precedence : (This will not be implemented by bgpd)
96 ip tos : (This will not be implemented by bgpd)
97 level : (This will not be implemented by bgpd)
98 local-preference : Done
100 metric-type : Not yet
107 set ipv6 next-hop global: Done
108 set ipv6 next-hop prefer-global: Done
109 set ipv6 next-hop local : Done
110 set as-path exclude : Done
114 /* generic value manipulation to be shared in multiple rules */
116 #define RMAP_VALUE_SET 0
117 #define RMAP_VALUE_ADD 1
118 #define RMAP_VALUE_SUB 2
126 static int route_value_match(struct rmap_value
*rv
, u_int32_t value
)
128 if (rv
->variable
== 0 && value
== rv
->value
)
134 static u_int32_t
route_value_adjust(struct rmap_value
*rv
, u_int32_t current
,
139 switch (rv
->variable
) {
148 switch (rv
->action
) {
150 if (current
> UINT32_MAX
- value
)
152 return current
+ value
;
154 if (current
<= value
)
156 return current
- value
;
162 static void *route_value_compile(const char *arg
)
164 u_int8_t action
= RMAP_VALUE_SET
, var
= 0;
165 unsigned long larg
= 0;
167 struct rmap_value
*rv
;
170 action
= RMAP_VALUE_ADD
;
172 } else if (arg
[0] == '-') {
173 action
= RMAP_VALUE_SUB
;
177 if (all_digit(arg
)) {
179 larg
= strtoul(arg
, &endptr
, 10);
180 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
183 if (strcmp(arg
, "rtt") == 0)
189 rv
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
199 static void route_value_free(void *rule
)
201 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
204 /* generic as path object to be shared in multiple rules */
206 static void *route_aspath_compile(const char *arg
)
208 struct aspath
*aspath
;
210 aspath
= aspath_str2aspath(arg
);
216 static void route_aspath_free(void *rule
)
218 struct aspath
*aspath
= rule
;
222 /* 'match peer (A.B.C.D|X:X::X:X)' */
224 /* Compares the peer specified in the 'match peer' clause with the peer
225 received in bgp_info->peer. If it is the same, or if the peer structure
226 received is a peer_group containing it, returns RMAP_MATCH. */
227 static route_map_result_t
route_match_peer(void *rule
, struct prefix
*prefix
,
228 route_map_object_t type
,
232 union sockunion su_def
= {
233 .sin
= {.sin_family
= AF_INET
, .sin_addr
.s_addr
= INADDR_ANY
}};
234 struct peer_group
*group
;
236 struct listnode
*node
, *nnode
;
238 if (type
== RMAP_BGP
) {
240 peer
= ((struct bgp_info
*)object
)->peer
;
242 if (!CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
)
243 && !CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_EXPORT
))
246 /* If su='0.0.0.0' (command 'match peer local'), and it's a
248 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH
250 if (sockunion_same(su
, &su_def
)) {
252 if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
)
253 || CHECK_FLAG(peer
->rmap_type
,
254 PEER_RMAP_TYPE_REDISTRIBUTE
)
255 || CHECK_FLAG(peer
->rmap_type
,
256 PEER_RMAP_TYPE_DEFAULT
))
263 if (!CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
)) {
264 if (sockunion_same(su
, &peer
->su
))
270 for (ALL_LIST_ELEMENTS(group
->peer
, node
, nnode
,
272 if (sockunion_same(su
, &peer
->su
))
281 static void *route_match_peer_compile(const char *arg
)
286 su
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(union sockunion
));
288 ret
= str2sockunion(strcmp(arg
, "local") ? arg
: "0.0.0.0", su
);
290 XFREE(MTYPE_ROUTE_MAP_COMPILED
, su
);
297 /* Free route map's compiled `ip address' value. */
298 static void route_match_peer_free(void *rule
)
300 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
303 /* Route map commands for ip address matching. */
304 struct route_map_rule_cmd route_match_peer_cmd
= {"peer", route_match_peer
,
305 route_match_peer_compile
,
306 route_match_peer_free
};
308 /* `match ip address IP_ACCESS_LIST' */
310 /* Match function should return 1 if match is success else return
312 static route_map_result_t
route_match_ip_address(void *rule
,
313 struct prefix
*prefix
,
314 route_map_object_t type
,
317 struct access_list
*alist
;
318 /* struct prefix_ipv4 match; */
320 if (type
== RMAP_BGP
) {
321 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
325 return (access_list_apply(alist
, prefix
) == FILTER_DENY
332 /* Route map `ip address' match statement. `arg' should be
334 static void *route_match_ip_address_compile(const char *arg
)
336 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
339 /* Free route map's compiled `ip address' value. */
340 static void route_match_ip_address_free(void *rule
)
342 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
345 /* Route map commands for ip address matching. */
346 struct route_map_rule_cmd route_match_ip_address_cmd
= {
347 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
348 route_match_ip_address_free
};
350 /* `match ip next-hop IP_ADDRESS' */
352 /* Match function return 1 if match is success else return zero. */
353 static route_map_result_t
route_match_ip_next_hop(void *rule
,
354 struct prefix
*prefix
,
355 route_map_object_t type
,
358 struct access_list
*alist
;
359 struct bgp_info
*bgp_info
;
360 struct prefix_ipv4 p
;
362 if (type
== RMAP_BGP
) {
365 p
.prefix
= bgp_info
->attr
->nexthop
;
366 p
.prefixlen
= IPV4_MAX_BITLEN
;
368 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
372 return (access_list_apply(alist
, &p
) == FILTER_DENY
379 /* Route map `ip next-hop' match statement. `arg' is
381 static void *route_match_ip_next_hop_compile(const char *arg
)
383 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
386 /* Free route map's compiled `ip address' value. */
387 static void route_match_ip_next_hop_free(void *rule
)
389 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
392 /* Route map commands for ip next-hop matching. */
393 struct route_map_rule_cmd route_match_ip_next_hop_cmd
= {
394 "ip next-hop", route_match_ip_next_hop
, route_match_ip_next_hop_compile
,
395 route_match_ip_next_hop_free
};
397 /* `match ip route-source ACCESS-LIST' */
399 /* Match function return 1 if match is success else return zero. */
400 static route_map_result_t
route_match_ip_route_source(void *rule
,
401 struct prefix
*prefix
,
402 route_map_object_t type
,
405 struct access_list
*alist
;
406 struct bgp_info
*bgp_info
;
408 struct prefix_ipv4 p
;
410 if (type
== RMAP_BGP
) {
412 peer
= bgp_info
->peer
;
414 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
418 p
.prefix
= peer
->su
.sin
.sin_addr
;
419 p
.prefixlen
= IPV4_MAX_BITLEN
;
421 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
425 return (access_list_apply(alist
, &p
) == FILTER_DENY
432 /* Route map `ip route-source' match statement. `arg' is
434 static void *route_match_ip_route_source_compile(const char *arg
)
436 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
439 /* Free route map's compiled `ip address' value. */
440 static void route_match_ip_route_source_free(void *rule
)
442 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
445 /* Route map commands for ip route-source matching. */
446 struct route_map_rule_cmd route_match_ip_route_source_cmd
= {
447 "ip route-source", route_match_ip_route_source
,
448 route_match_ip_route_source_compile
, route_match_ip_route_source_free
};
450 /* `match ip address prefix-list PREFIX_LIST' */
452 static route_map_result_t
453 route_match_ip_address_prefix_list(void *rule
, struct prefix
*prefix
,
454 route_map_object_t type
, void *object
)
456 struct prefix_list
*plist
;
458 if (type
== RMAP_BGP
) {
459 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
463 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
470 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
472 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
475 static void route_match_ip_address_prefix_list_free(void *rule
)
477 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
480 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
481 "ip address prefix-list", route_match_ip_address_prefix_list
,
482 route_match_ip_address_prefix_list_compile
,
483 route_match_ip_address_prefix_list_free
};
485 /* `match ip next-hop prefix-list PREFIX_LIST' */
487 static route_map_result_t
488 route_match_ip_next_hop_prefix_list(void *rule
, struct prefix
*prefix
,
489 route_map_object_t type
, void *object
)
491 struct prefix_list
*plist
;
492 struct bgp_info
*bgp_info
;
493 struct prefix_ipv4 p
;
495 if (type
== RMAP_BGP
) {
498 p
.prefix
= bgp_info
->attr
->nexthop
;
499 p
.prefixlen
= IPV4_MAX_BITLEN
;
501 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
505 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
512 static void *route_match_ip_next_hop_prefix_list_compile(const char *arg
)
514 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
517 static void route_match_ip_next_hop_prefix_list_free(void *rule
)
519 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
522 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
= {
523 "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list
,
524 route_match_ip_next_hop_prefix_list_compile
,
525 route_match_ip_next_hop_prefix_list_free
};
527 /* `match ip route-source prefix-list PREFIX_LIST' */
529 static route_map_result_t
530 route_match_ip_route_source_prefix_list(void *rule
, struct prefix
*prefix
,
531 route_map_object_t type
, void *object
)
533 struct prefix_list
*plist
;
534 struct bgp_info
*bgp_info
;
536 struct prefix_ipv4 p
;
538 if (type
== RMAP_BGP
) {
540 peer
= bgp_info
->peer
;
542 if (!peer
|| sockunion_family(&peer
->su
) != AF_INET
)
546 p
.prefix
= peer
->su
.sin
.sin_addr
;
547 p
.prefixlen
= IPV4_MAX_BITLEN
;
549 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
553 return (prefix_list_apply(plist
, &p
) == PREFIX_DENY
560 static void *route_match_ip_route_source_prefix_list_compile(const char *arg
)
562 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
565 static void route_match_ip_route_source_prefix_list_free(void *rule
)
567 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
570 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
= {
571 "ip route-source prefix-list", route_match_ip_route_source_prefix_list
,
572 route_match_ip_route_source_prefix_list_compile
,
573 route_match_ip_route_source_prefix_list_free
};
575 /* `match local-preference LOCAL-PREF' */
577 /* Match function return 1 if match is success else return zero. */
578 static route_map_result_t
route_match_local_pref(void *rule
,
579 struct prefix
*prefix
,
580 route_map_object_t type
,
583 u_int32_t
*local_pref
;
584 struct bgp_info
*bgp_info
;
586 if (type
== RMAP_BGP
) {
590 if (bgp_info
->attr
->local_pref
== *local_pref
)
598 /* Route map `match local-preference' match statement.
599 `arg' is local-pref value */
600 static void *route_match_local_pref_compile(const char *arg
)
602 u_int32_t
*local_pref
;
604 unsigned long tmpval
;
606 /* Locpref value shoud be integer. */
611 tmpval
= strtoul(arg
, &endptr
, 10);
612 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
615 local_pref
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(u_int32_t
));
620 *local_pref
= tmpval
;
624 /* Free route map's compiled `match local-preference' value. */
625 static void route_match_local_pref_free(void *rule
)
627 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
630 /* Route map commands for metric matching. */
631 struct route_map_rule_cmd route_match_local_pref_cmd
= {
632 "local-preference", route_match_local_pref
,
633 route_match_local_pref_compile
, route_match_local_pref_free
};
635 /* `match metric METRIC' */
637 /* Match function return 1 if match is success else return zero. */
638 static route_map_result_t
route_match_metric(void *rule
, struct prefix
*prefix
,
639 route_map_object_t type
,
642 struct rmap_value
*rv
;
643 struct bgp_info
*bgp_info
;
645 if (type
== RMAP_BGP
) {
648 return route_value_match(rv
, bgp_info
->attr
->med
);
653 /* Route map commands for metric matching. */
654 struct route_map_rule_cmd route_match_metric_cmd
= {
655 "metric", route_match_metric
, route_value_compile
, route_value_free
,
658 /* `match as-path ASPATH' */
660 /* Match function for as-path match. I assume given object is */
661 static route_map_result_t
route_match_aspath(void *rule
, struct prefix
*prefix
,
662 route_map_object_t type
,
666 struct as_list
*as_list
;
667 struct bgp_info
*bgp_info
;
669 if (type
== RMAP_BGP
) {
670 as_list
= as_list_lookup((char *)rule
);
677 return ((as_list_apply(as_list
, bgp_info
->attr
->aspath
)
685 /* Compile function for as-path match. */
686 static void *route_match_aspath_compile(const char *arg
)
688 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
691 /* Compile function for as-path match. */
692 static void route_match_aspath_free(void *rule
)
694 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
697 /* Route map commands for aspath matching. */
698 struct route_map_rule_cmd route_match_aspath_cmd
= {
699 "as-path", route_match_aspath
, route_match_aspath_compile
,
700 route_match_aspath_free
};
702 /* `match community COMMUNIY' */
703 struct rmap_community
{
708 /* Match function for community match. */
709 static route_map_result_t
route_match_community(void *rule
,
710 struct prefix
*prefix
,
711 route_map_object_t type
,
714 struct community_list
*list
;
715 struct bgp_info
*bgp_info
;
716 struct rmap_community
*rcom
;
718 if (type
== RMAP_BGP
) {
722 list
= community_list_lookup(bgp_clist
, rcom
->name
,
723 COMMUNITY_LIST_MASTER
);
728 if (community_list_exact_match(
729 bgp_info
->attr
->community
, list
))
732 if (community_list_match(bgp_info
->attr
->community
,
740 /* Compile function for community match. */
741 static void *route_match_community_compile(const char *arg
)
743 struct rmap_community
*rcom
;
747 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
749 p
= strchr(arg
, ' ');
752 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
753 memcpy(rcom
->name
, arg
, len
);
756 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
762 /* Compile function for community match. */
763 static void route_match_community_free(void *rule
)
765 struct rmap_community
*rcom
= rule
;
767 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
768 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
771 /* Route map commands for community matching. */
772 struct route_map_rule_cmd route_match_community_cmd
= {
773 "community", route_match_community
, route_match_community_compile
,
774 route_match_community_free
};
776 /* Match function for lcommunity match. */
777 static route_map_result_t
route_match_lcommunity(void *rule
,
778 struct prefix
*prefix
,
779 route_map_object_t type
,
782 struct community_list
*list
;
783 struct bgp_info
*bgp_info
;
784 struct rmap_community
*rcom
;
786 if (type
== RMAP_BGP
) {
790 list
= community_list_lookup(bgp_clist
, rcom
->name
,
791 LARGE_COMMUNITY_LIST_MASTER
);
795 if (lcommunity_list_match(bgp_info
->attr
->lcommunity
, list
))
801 /* Compile function for community match. */
802 static void *route_match_lcommunity_compile(const char *arg
)
804 struct rmap_community
*rcom
;
808 rcom
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_community
));
810 p
= strchr(arg
, ' ');
813 rcom
->name
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
814 memcpy(rcom
->name
, arg
, len
);
816 rcom
->name
= XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
822 /* Compile function for community match. */
823 static void route_match_lcommunity_free(void *rule
)
825 struct rmap_community
*rcom
= rule
;
827 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
828 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcom
);
831 /* Route map commands for community matching. */
832 struct route_map_rule_cmd route_match_lcommunity_cmd
= {
833 "large-community", route_match_lcommunity
,
834 route_match_lcommunity_compile
, route_match_lcommunity_free
};
837 /* Match function for extcommunity match. */
838 static route_map_result_t
route_match_ecommunity(void *rule
,
839 struct prefix
*prefix
,
840 route_map_object_t type
,
843 struct community_list
*list
;
844 struct bgp_info
*bgp_info
;
846 if (type
== RMAP_BGP
) {
849 list
= community_list_lookup(bgp_clist
, (char *)rule
,
850 EXTCOMMUNITY_LIST_MASTER
);
854 if (ecommunity_list_match(bgp_info
->attr
->ecommunity
, list
))
860 /* Compile function for extcommunity match. */
861 static void *route_match_ecommunity_compile(const char *arg
)
863 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
866 /* Compile function for extcommunity match. */
867 static void route_match_ecommunity_free(void *rule
)
869 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
872 /* Route map commands for community matching. */
873 struct route_map_rule_cmd route_match_ecommunity_cmd
= {
874 "extcommunity", route_match_ecommunity
, route_match_ecommunity_compile
,
875 route_match_ecommunity_free
};
877 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
878 and `address-family vpnv4'. */
881 static route_map_result_t
route_match_origin(void *rule
, struct prefix
*prefix
,
882 route_map_object_t type
,
886 struct bgp_info
*bgp_info
;
888 if (type
== RMAP_BGP
) {
892 if (bgp_info
->attr
->origin
== *origin
)
899 static void *route_match_origin_compile(const char *arg
)
903 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(u_char
));
905 if (strcmp(arg
, "igp") == 0)
907 else if (strcmp(arg
, "egp") == 0)
915 /* Free route map's compiled `ip address' value. */
916 static void route_match_origin_free(void *rule
)
918 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
921 /* Route map commands for origin matching. */
922 struct route_map_rule_cmd route_match_origin_cmd
= {
923 "origin", route_match_origin
, route_match_origin_compile
,
924 route_match_origin_free
};
926 /* match probability { */
928 static route_map_result_t
route_match_probability(void *rule
,
929 struct prefix
*prefix
,
930 route_map_object_t type
,
935 switch (*(long *)rule
) {
941 if (r
< *(long *)rule
) {
949 static void *route_match_probability_compile(const char *arg
)
955 lobule
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(long));
965 *lobule
= RAND_MAX
/ 100 * perc
;
971 static void route_match_probability_free(void *rule
)
973 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
976 struct route_map_rule_cmd route_match_probability_cmd
= {
977 "probability", route_match_probability
, route_match_probability_compile
,
978 route_match_probability_free
};
980 /* `match interface IFNAME' */
981 /* Match function should return 1 if match is success else return
983 static route_map_result_t
route_match_interface(void *rule
,
984 struct prefix
*prefix
,
985 route_map_object_t type
,
988 struct interface
*ifp
;
989 struct bgp_info
*info
;
991 if (type
== RMAP_BGP
) {
994 if (!info
|| !info
->attr
)
997 ifp
= if_lookup_by_name_all_vrf((char *)rule
);
999 if (ifp
== NULL
|| ifp
->ifindex
!= info
->attr
->nh_ifindex
)
1000 return RMAP_NOMATCH
;
1004 return RMAP_NOMATCH
;
1007 /* Route map `interface' match statement. `arg' should be
1009 static void *route_match_interface_compile(const char *arg
)
1011 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
1014 /* Free route map's compiled `interface' value. */
1015 static void route_match_interface_free(void *rule
)
1017 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1020 /* Route map commands for ip address matching. */
1021 struct route_map_rule_cmd route_match_interface_cmd
= {
1022 "interface", route_match_interface
, route_match_interface_compile
,
1023 route_match_interface_free
};
1027 /* `set ip next-hop IP_ADDRESS' */
1029 /* Match function return 1 if match is success else return zero. */
1030 static route_map_result_t
route_match_tag(void *rule
, struct prefix
*prefix
,
1031 route_map_object_t type
, void *object
)
1034 struct bgp_info
*bgp_info
;
1036 if (type
== RMAP_BGP
) {
1040 return ((bgp_info
->attr
->tag
== *tag
) ? RMAP_MATCH
1044 return RMAP_NOMATCH
;
1048 /* Route map commands for tag matching. */
1049 static struct route_map_rule_cmd route_match_tag_cmd
= {
1050 "tag", route_match_tag
, route_map_rule_tag_compile
,
1051 route_map_rule_tag_free
,
1055 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1056 struct rmap_ip_nexthop_set
{
1057 struct in_addr
*address
;
1062 static route_map_result_t
route_set_ip_nexthop(void *rule
,
1063 struct prefix
*prefix
,
1064 route_map_object_t type
,
1067 struct rmap_ip_nexthop_set
*rins
= rule
;
1068 struct bgp_info
*bgp_info
;
1071 if (type
== RMAP_BGP
) {
1073 peer
= bgp_info
->peer
;
1075 if (rins
->unchanged
) {
1076 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1077 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1078 } else if (rins
->peer_address
) {
1079 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
1080 || CHECK_FLAG(peer
->rmap_type
,
1081 PEER_RMAP_TYPE_IMPORT
))
1083 && sockunion_family(peer
->su_remote
) == AF_INET
) {
1084 bgp_info
->attr
->nexthop
.s_addr
=
1085 sockunion2ip(peer
->su_remote
);
1086 bgp_info
->attr
->flag
|=
1087 ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1088 } else if (CHECK_FLAG(peer
->rmap_type
,
1089 PEER_RMAP_TYPE_OUT
)) {
1090 /* The next hop value will be set as part of
1092 * Set the flags here to indicate that rewrite
1094 * Also, clear the value.
1096 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1097 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1098 bgp_info
->attr
->nexthop
.s_addr
= 0;
1101 /* Set next hop value. */
1102 bgp_info
->attr
->flag
|=
1103 ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
1104 bgp_info
->attr
->nexthop
= *rins
->address
;
1105 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1106 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1113 /* Route map `ip nexthop' compile function. Given string is converted
1114 to struct in_addr structure. */
1115 static void *route_set_ip_nexthop_compile(const char *arg
)
1117 struct rmap_ip_nexthop_set
*rins
;
1118 struct in_addr
*address
= NULL
;
1119 int peer_address
= 0;
1123 if (strcmp(arg
, "peer-address") == 0)
1125 else if (strcmp(arg
, "unchanged") == 0)
1128 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1129 sizeof(struct in_addr
));
1130 ret
= inet_aton(arg
, address
);
1133 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
1138 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
,
1139 sizeof(struct rmap_ip_nexthop_set
));
1141 rins
->address
= address
;
1142 rins
->peer_address
= peer_address
;
1143 rins
->unchanged
= unchanged
;
1148 /* Free route map's compiled `ip nexthop' value. */
1149 static void route_set_ip_nexthop_free(void *rule
)
1151 struct rmap_ip_nexthop_set
*rins
= rule
;
1154 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1156 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rins
);
1159 /* Route map commands for ip nexthop set. */
1160 struct route_map_rule_cmd route_set_ip_nexthop_cmd
= {
1161 "ip next-hop", route_set_ip_nexthop
, route_set_ip_nexthop_compile
,
1162 route_set_ip_nexthop_free
};
1164 /* `set local-preference LOCAL_PREF' */
1166 /* Set local preference. */
1167 static route_map_result_t
route_set_local_pref(void *rule
,
1168 struct prefix
*prefix
,
1169 route_map_object_t type
,
1172 struct rmap_value
*rv
;
1173 struct bgp_info
*bgp_info
;
1174 u_int32_t locpref
= 0;
1176 if (type
== RMAP_BGP
) {
1177 /* Fetch routemap's rule information. */
1181 /* Set local preference value. */
1182 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
))
1183 locpref
= bgp_info
->attr
->local_pref
;
1185 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF
);
1186 bgp_info
->attr
->local_pref
=
1187 route_value_adjust(rv
, locpref
, bgp_info
->peer
);
1193 /* Set local preference rule structure. */
1194 struct route_map_rule_cmd route_set_local_pref_cmd
= {
1195 "local-preference", route_set_local_pref
, route_value_compile
,
1199 /* `set weight WEIGHT' */
1202 static route_map_result_t
route_set_weight(void *rule
, struct prefix
*prefix
,
1203 route_map_object_t type
,
1206 struct rmap_value
*rv
;
1207 struct bgp_info
*bgp_info
;
1209 if (type
== RMAP_BGP
) {
1210 /* Fetch routemap's rule information. */
1214 /* Set weight value. */
1215 bgp_info
->attr
->weight
=
1216 route_value_adjust(rv
, 0, bgp_info
->peer
);
1222 /* Set local preference rule structure. */
1223 struct route_map_rule_cmd route_set_weight_cmd
= {
1224 "weight", route_set_weight
, route_value_compile
, route_value_free
,
1227 /* `set metric METRIC' */
1229 /* Set metric to attribute. */
1230 static route_map_result_t
route_set_metric(void *rule
, struct prefix
*prefix
,
1231 route_map_object_t type
,
1234 struct rmap_value
*rv
;
1235 struct bgp_info
*bgp_info
;
1238 if (type
== RMAP_BGP
) {
1239 /* Fetch routemap's rule information. */
1243 if (bgp_info
->attr
->flag
1244 & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
))
1245 med
= bgp_info
->attr
->med
;
1247 bgp_info
->attr
->med
=
1248 route_value_adjust(rv
, med
, bgp_info
->peer
);
1249 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC
);
1254 /* Set metric rule structure. */
1255 struct route_map_rule_cmd route_set_metric_cmd
= {
1256 "metric", route_set_metric
, route_value_compile
, route_value_free
,
1259 /* `set as-path prepend ASPATH' */
1261 /* For AS path prepend mechanism. */
1262 static route_map_result_t
route_set_aspath_prepend(void *rule
,
1263 struct prefix
*prefix
,
1264 route_map_object_t type
,
1267 struct aspath
*aspath
;
1269 struct bgp_info
*binfo
;
1271 if (type
== RMAP_BGP
) {
1274 if (binfo
->attr
->aspath
->refcnt
)
1275 new = aspath_dup(binfo
->attr
->aspath
);
1277 new = binfo
->attr
->aspath
;
1279 if ((uintptr_t)rule
> 10) {
1281 aspath_prepend(aspath
, new);
1283 as_t as
= aspath_leftmost(new);
1285 as
= binfo
->peer
->as
;
1286 new = aspath_add_seq_n(new, as
, (uintptr_t)rule
);
1289 binfo
->attr
->aspath
= new;
1295 static void *route_set_aspath_prepend_compile(const char *arg
)
1299 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1300 return (void *)(uintptr_t)num
;
1302 return route_aspath_compile(arg
);
1305 static void route_set_aspath_prepend_free(void *rule
)
1307 if ((uintptr_t)rule
> 10)
1308 route_aspath_free(rule
);
1312 /* Set as-path prepend rule structure. */
1313 struct route_map_rule_cmd route_set_aspath_prepend_cmd
= {
1314 "as-path prepend", route_set_aspath_prepend
,
1315 route_set_aspath_prepend_compile
, route_set_aspath_prepend_free
,
1318 /* `set as-path exclude ASn' */
1320 /* For ASN exclude mechanism.
1321 * Iterate over ASns requested and filter them from the given AS_PATH one by
1323 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1325 static route_map_result_t
route_set_aspath_exclude(void *rule
,
1326 struct prefix
*dummy
,
1327 route_map_object_t type
,
1330 struct aspath
*new_path
, *exclude_path
;
1331 struct bgp_info
*binfo
;
1333 if (type
== RMAP_BGP
) {
1334 exclude_path
= rule
;
1336 if (binfo
->attr
->aspath
->refcnt
)
1337 new_path
= aspath_dup(binfo
->attr
->aspath
);
1339 new_path
= binfo
->attr
->aspath
;
1340 binfo
->attr
->aspath
=
1341 aspath_filter_exclude(new_path
, exclude_path
);
1346 /* Set ASn exlude rule structure. */
1347 struct route_map_rule_cmd route_set_aspath_exclude_cmd
= {
1348 "as-path exclude", route_set_aspath_exclude
, route_aspath_compile
,
1352 /* `set community COMMUNITY' */
1353 struct rmap_com_set
{
1354 struct community
*com
;
1359 /* For community set mechanism. */
1360 static route_map_result_t
route_set_community(void *rule
, struct prefix
*prefix
,
1361 route_map_object_t type
,
1364 struct rmap_com_set
*rcs
;
1365 struct bgp_info
*binfo
;
1367 struct community
*new = NULL
;
1368 struct community
*old
;
1369 struct community
*merge
;
1371 if (type
== RMAP_BGP
) {
1375 old
= attr
->community
;
1379 attr
->flag
&= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
));
1380 attr
->community
= NULL
;
1381 /* See the longer comment down below. */
1382 if (old
&& old
->refcnt
== 0)
1383 community_free(old
);
1387 /* "additive" case. */
1388 if (rcs
->additive
&& old
) {
1389 merge
= community_merge(community_dup(old
), rcs
->com
);
1391 /* HACK: if the old community is not intern'd,
1392 * we should free it here, or all reference to it may be
1394 * Really need to cleanup attribute caching sometime.
1396 if (old
->refcnt
== 0)
1397 community_free(old
);
1398 new = community_uniq_sort(merge
);
1399 community_free(merge
);
1401 new = community_dup(rcs
->com
);
1403 /* will be interned by caller if required */
1404 attr
->community
= new;
1406 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1412 /* Compile function for set community. */
1413 static void *route_set_community_compile(const char *arg
)
1415 struct rmap_com_set
*rcs
;
1416 struct community
*com
= NULL
;
1421 if (strcmp(arg
, "none") == 0)
1424 sp
= strstr(arg
, "additive");
1426 if (sp
&& sp
> arg
) {
1427 /* "additive" keyworkd is included. */
1432 com
= community_str2com(arg
);
1441 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1443 rcs
->additive
= additive
;
1449 /* Free function for set community. */
1450 static void route_set_community_free(void *rule
)
1452 struct rmap_com_set
*rcs
= rule
;
1455 community_free(rcs
->com
);
1456 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1459 /* Set community rule structure. */
1460 struct route_map_rule_cmd route_set_community_cmd
= {
1461 "community", route_set_community
, route_set_community_compile
,
1462 route_set_community_free
,
1465 /* `set community COMMUNITY' */
1466 struct rmap_lcom_set
{
1467 struct lcommunity
*lcom
;
1473 /* For lcommunity set mechanism. */
1474 static route_map_result_t
route_set_lcommunity(void *rule
,
1475 struct prefix
*prefix
,
1476 route_map_object_t type
,
1479 struct rmap_lcom_set
*rcs
;
1480 struct bgp_info
*binfo
;
1482 struct lcommunity
*new = NULL
;
1483 struct lcommunity
*old
;
1484 struct lcommunity
*merge
;
1486 if (type
== RMAP_BGP
) {
1490 old
= attr
->lcommunity
;
1495 ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
));
1496 attr
->lcommunity
= NULL
;
1498 /* See the longer comment down below. */
1499 if (old
&& old
->refcnt
== 0)
1500 lcommunity_free(&old
);
1504 if (rcs
->additive
&& old
) {
1505 merge
= lcommunity_merge(lcommunity_dup(old
),
1508 /* HACK: if the old large-community is not intern'd,
1509 * we should free it here, or all reference to it may be
1511 * Really need to cleanup attribute caching sometime.
1513 if (old
->refcnt
== 0)
1514 lcommunity_free(&old
);
1515 new = lcommunity_uniq_sort(merge
);
1516 lcommunity_free(&merge
);
1518 new = lcommunity_dup(rcs
->lcom
);
1520 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1521 attr
->lcommunity
= new;
1523 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES
);
1529 /* Compile function for set community. */
1530 static void *route_set_lcommunity_compile(const char *arg
)
1532 struct rmap_lcom_set
*rcs
;
1533 struct lcommunity
*lcom
= NULL
;
1538 if (strcmp(arg
, "none") == 0)
1541 sp
= strstr(arg
, "additive");
1543 if (sp
&& sp
> arg
) {
1544 /* "additive" keyworkd is included. */
1549 lcom
= lcommunity_str2com(arg
);
1558 rcs
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_com_set
));
1560 rcs
->additive
= additive
;
1566 /* Free function for set lcommunity. */
1567 static void route_set_lcommunity_free(void *rule
)
1569 struct rmap_lcom_set
*rcs
= rule
;
1572 lcommunity_free(&rcs
->lcom
);
1574 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1577 /* Set community rule structure. */
1578 struct route_map_rule_cmd route_set_lcommunity_cmd
= {
1579 "large-community", route_set_lcommunity
, route_set_lcommunity_compile
,
1580 route_set_lcommunity_free
,
1583 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
1585 /* For large community set mechanism. */
1586 static route_map_result_t
route_set_lcommunity_delete(void *rule
,
1587 struct prefix
*prefix
,
1588 route_map_object_t type
,
1591 struct community_list
*list
;
1592 struct lcommunity
*merge
;
1593 struct lcommunity
*new;
1594 struct lcommunity
*old
;
1595 struct bgp_info
*binfo
;
1597 if (type
== RMAP_BGP
) {
1602 list
= community_list_lookup(bgp_clist
, rule
,
1603 LARGE_COMMUNITY_LIST_MASTER
);
1604 old
= binfo
->attr
->lcommunity
;
1607 merge
= lcommunity_list_match_delete(
1608 lcommunity_dup(old
), list
);
1609 new = lcommunity_uniq_sort(merge
);
1610 lcommunity_free(&merge
);
1612 /* HACK: if the old community is not intern'd,
1613 * we should free it here, or all reference to it may be
1615 * Really need to cleanup attribute caching sometime.
1617 if (old
->refcnt
== 0)
1618 lcommunity_free(&old
);
1620 if (new->size
== 0) {
1621 binfo
->attr
->lcommunity
= NULL
;
1622 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT(
1623 BGP_ATTR_LARGE_COMMUNITIES
);
1624 lcommunity_free(&new);
1626 binfo
->attr
->lcommunity
= new;
1627 binfo
->attr
->flag
|= ATTR_FLAG_BIT(
1628 BGP_ATTR_LARGE_COMMUNITIES
);
1636 /* Compile function for set lcommunity. */
1637 static void *route_set_lcommunity_delete_compile(const char *arg
)
1643 p
= strchr(arg
, ' ');
1646 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1647 memcpy(str
, arg
, len
);
1654 /* Free function for set lcommunity. */
1655 static void route_set_lcommunity_delete_free(void *rule
)
1657 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1660 /* Set lcommunity rule structure. */
1661 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
= {
1662 "large-comm-list", route_set_lcommunity_delete
,
1663 route_set_lcommunity_delete_compile
, route_set_lcommunity_delete_free
,
1667 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
1669 /* For community set mechanism. */
1670 static route_map_result_t
route_set_community_delete(void *rule
,
1671 struct prefix
*prefix
,
1672 route_map_object_t type
,
1675 struct community_list
*list
;
1676 struct community
*merge
;
1677 struct community
*new;
1678 struct community
*old
;
1679 struct bgp_info
*binfo
;
1681 if (type
== RMAP_BGP
) {
1686 list
= community_list_lookup(bgp_clist
, rule
,
1687 COMMUNITY_LIST_MASTER
);
1688 old
= binfo
->attr
->community
;
1691 merge
= community_list_match_delete(community_dup(old
),
1693 new = community_uniq_sort(merge
);
1694 community_free(merge
);
1696 /* HACK: if the old community is not intern'd,
1697 * we should free it here, or all reference to it may be
1699 * Really need to cleanup attribute caching sometime.
1701 if (old
->refcnt
== 0)
1702 community_free(old
);
1704 if (new->size
== 0) {
1705 binfo
->attr
->community
= NULL
;
1706 binfo
->attr
->flag
&=
1707 ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1708 community_free(new);
1710 binfo
->attr
->community
= new;
1711 binfo
->attr
->flag
|=
1712 ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES
);
1720 /* Compile function for set community. */
1721 static void *route_set_community_delete_compile(const char *arg
)
1727 p
= strchr(arg
, ' ');
1730 str
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1731 memcpy(str
, arg
, len
);
1738 /* Free function for set community. */
1739 static void route_set_community_delete_free(void *rule
)
1741 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1744 /* Set community rule structure. */
1745 struct route_map_rule_cmd route_set_community_delete_cmd
= {
1746 "comm-list", route_set_community_delete
,
1747 route_set_community_delete_compile
, route_set_community_delete_free
,
1750 /* `set extcommunity rt COMMUNITY' */
1752 /* For community set mechanism. Used by _rt and _soo. */
1753 static route_map_result_t
route_set_ecommunity(void *rule
,
1754 struct prefix
*prefix
,
1755 route_map_object_t type
,
1758 struct ecommunity
*ecom
;
1759 struct ecommunity
*new_ecom
;
1760 struct ecommunity
*old_ecom
;
1761 struct bgp_info
*bgp_info
;
1763 if (type
== RMAP_BGP
) {
1770 /* We assume additive for Extended Community. */
1771 old_ecom
= bgp_info
->attr
->ecommunity
;
1774 new_ecom
= ecommunity_merge(ecommunity_dup(old_ecom
),
1777 /* old_ecom->refcnt = 1 => owned elsewhere, e.g.
1778 * bgp_update_receive()
1779 * ->refcnt = 0 => set by a previous route-map
1781 if (!old_ecom
->refcnt
)
1782 ecommunity_free(&old_ecom
);
1784 new_ecom
= ecommunity_dup(ecom
);
1786 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1787 bgp_info
->attr
->ecommunity
= new_ecom
;
1789 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
1794 /* Compile function for set community. */
1795 static void *route_set_ecommunity_rt_compile(const char *arg
)
1797 struct ecommunity
*ecom
;
1799 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
1802 return ecommunity_intern(ecom
);
1805 /* Free function for set community. Used by _rt and _soo */
1806 static void route_set_ecommunity_free(void *rule
)
1808 struct ecommunity
*ecom
= rule
;
1809 ecommunity_unintern(&ecom
);
1812 /* Set community rule structure. */
1813 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
= {
1814 "extcommunity rt", route_set_ecommunity
,
1815 route_set_ecommunity_rt_compile
, route_set_ecommunity_free
,
1818 /* `set extcommunity soo COMMUNITY' */
1820 /* Compile function for set community. */
1821 static void *route_set_ecommunity_soo_compile(const char *arg
)
1823 struct ecommunity
*ecom
;
1825 ecom
= ecommunity_str2com(arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
1829 return ecommunity_intern(ecom
);
1832 /* Set community rule structure. */
1833 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
= {
1834 "extcommunity soo", route_set_ecommunity
,
1835 route_set_ecommunity_soo_compile
, route_set_ecommunity_free
,
1838 /* `set origin ORIGIN' */
1840 /* For origin set. */
1841 static route_map_result_t
route_set_origin(void *rule
, struct prefix
*prefix
,
1842 route_map_object_t type
,
1846 struct bgp_info
*bgp_info
;
1848 if (type
== RMAP_BGP
) {
1852 bgp_info
->attr
->origin
= *origin
;
1858 /* Compile function for origin set. */
1859 static void *route_set_origin_compile(const char *arg
)
1863 origin
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(u_char
));
1865 if (strcmp(arg
, "igp") == 0)
1867 else if (strcmp(arg
, "egp") == 0)
1875 /* Compile function for origin set. */
1876 static void route_set_origin_free(void *rule
)
1878 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1881 /* Set origin rule structure. */
1882 struct route_map_rule_cmd route_set_origin_cmd
= {
1883 "origin", route_set_origin
, route_set_origin_compile
,
1884 route_set_origin_free
,
1887 /* `set atomic-aggregate' */
1889 /* For atomic aggregate set. */
1890 static route_map_result_t
route_set_atomic_aggregate(void *rule
,
1891 struct prefix
*prefix
,
1892 route_map_object_t type
,
1895 struct bgp_info
*bgp_info
;
1897 if (type
== RMAP_BGP
) {
1899 bgp_info
->attr
->flag
|=
1900 ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE
);
1906 /* Compile function for atomic aggregate. */
1907 static void *route_set_atomic_aggregate_compile(const char *arg
)
1912 /* Compile function for atomic aggregate. */
1913 static void route_set_atomic_aggregate_free(void *rule
)
1918 /* Set atomic aggregate rule structure. */
1919 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
= {
1920 "atomic-aggregate", route_set_atomic_aggregate
,
1921 route_set_atomic_aggregate_compile
, route_set_atomic_aggregate_free
,
1924 /* `set aggregator as AS A.B.C.D' */
1927 struct in_addr address
;
1930 static route_map_result_t
route_set_aggregator_as(void *rule
,
1931 struct prefix
*prefix
,
1932 route_map_object_t type
,
1935 struct bgp_info
*bgp_info
;
1936 struct aggregator
*aggregator
;
1938 if (type
== RMAP_BGP
) {
1942 bgp_info
->attr
->aggregator_as
= aggregator
->as
;
1943 bgp_info
->attr
->aggregator_addr
= aggregator
->address
;
1944 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR
);
1950 static void *route_set_aggregator_as_compile(const char *arg
)
1952 struct aggregator
*aggregator
;
1958 XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct aggregator
));
1959 sscanf(arg
, "%s %s", as
, address
);
1961 aggregator
->as
= strtoul(as
, NULL
, 10);
1962 ret
= inet_aton(address
, &aggregator
->address
);
1964 XFREE(MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
1970 static void route_set_aggregator_as_free(void *rule
)
1972 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
1975 struct route_map_rule_cmd route_set_aggregator_as_cmd
= {
1976 "aggregator as", route_set_aggregator_as
,
1977 route_set_aggregator_as_compile
, route_set_aggregator_as_free
,
1980 /* Set tag to object. object must be pointer to struct bgp_info */
1981 static route_map_result_t
route_set_tag(void *rule
, struct prefix
*prefix
,
1982 route_map_object_t type
, void *object
)
1985 struct bgp_info
*bgp_info
;
1987 if (type
== RMAP_BGP
) {
1992 bgp_info
->attr
->tag
= *tag
;
1998 /* Route map commands for tag set. */
1999 static struct route_map_rule_cmd route_set_tag_cmd
= {
2000 "tag", route_set_tag
, route_map_rule_tag_compile
,
2001 route_map_rule_tag_free
,
2004 /* Set label-index to object. object must be pointer to struct bgp_info */
2005 static route_map_result_t
route_set_label_index(void *rule
,
2006 struct prefix
*prefix
,
2007 route_map_object_t type
,
2010 struct rmap_value
*rv
;
2011 struct bgp_info
*bgp_info
;
2012 u_int32_t label_index
;
2014 if (type
== RMAP_BGP
) {
2015 /* Fetch routemap's rule information. */
2019 /* Set label-index value. */
2020 label_index
= rv
->value
;
2022 bgp_info
->attr
->label_index
= label_index
;
2023 bgp_info
->attr
->flag
|=
2024 ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID
);
2031 /* Route map commands for label-index set. */
2032 static struct route_map_rule_cmd route_set_label_index_cmd
= {
2033 "label-index", route_set_label_index
, route_value_compile
,
2037 /* `match ipv6 address IP_ACCESS_LIST' */
2039 static route_map_result_t
route_match_ipv6_address(void *rule
,
2040 struct prefix
*prefix
,
2041 route_map_object_t type
,
2044 struct access_list
*alist
;
2046 if (type
== RMAP_BGP
) {
2047 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
2049 return RMAP_NOMATCH
;
2051 return (access_list_apply(alist
, prefix
) == FILTER_DENY
2055 return RMAP_NOMATCH
;
2058 static void *route_match_ipv6_address_compile(const char *arg
)
2060 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2063 static void route_match_ipv6_address_free(void *rule
)
2065 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2068 /* Route map commands for ip address matching. */
2069 struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
2070 "ipv6 address", route_match_ipv6_address
,
2071 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
2073 /* `match ipv6 next-hop IP_ADDRESS' */
2075 static route_map_result_t
route_match_ipv6_next_hop(void *rule
,
2076 struct prefix
*prefix
,
2077 route_map_object_t type
,
2080 struct in6_addr
*addr
= rule
;
2081 struct bgp_info
*bgp_info
;
2083 if (type
== RMAP_BGP
) {
2086 if (IPV6_ADDR_SAME(&bgp_info
->attr
->mp_nexthop_global
, addr
))
2089 if (bgp_info
->attr
->mp_nexthop_len
2090 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
2091 && IPV6_ADDR_SAME(&bgp_info
->attr
->mp_nexthop_local
, rule
))
2094 return RMAP_NOMATCH
;
2097 return RMAP_NOMATCH
;
2100 static void *route_match_ipv6_next_hop_compile(const char *arg
)
2102 struct in6_addr
*address
;
2105 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2107 ret
= inet_pton(AF_INET6
, arg
, address
);
2109 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2116 static void route_match_ipv6_next_hop_free(void *rule
)
2118 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2121 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
= {
2122 "ipv6 next-hop", route_match_ipv6_next_hop
,
2123 route_match_ipv6_next_hop_compile
, route_match_ipv6_next_hop_free
};
2125 /* `match ipv6 address prefix-list PREFIX_LIST' */
2127 static route_map_result_t
2128 route_match_ipv6_address_prefix_list(void *rule
, struct prefix
*prefix
,
2129 route_map_object_t type
, void *object
)
2131 struct prefix_list
*plist
;
2133 if (type
== RMAP_BGP
) {
2134 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
2136 return RMAP_NOMATCH
;
2138 return (prefix_list_apply(plist
, prefix
) == PREFIX_DENY
2142 return RMAP_NOMATCH
;
2145 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
2147 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
2150 static void route_match_ipv6_address_prefix_list_free(void *rule
)
2152 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2155 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
2156 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
2157 route_match_ipv6_address_prefix_list_compile
,
2158 route_match_ipv6_address_prefix_list_free
};
2160 /* `set ipv6 nexthop global IP_ADDRESS' */
2162 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2163 static route_map_result_t
route_set_ipv6_nexthop_global(void *rule
,
2164 struct prefix
*prefix
,
2165 route_map_object_t type
,
2168 struct in6_addr
*address
;
2169 struct bgp_info
*bgp_info
;
2171 if (type
== RMAP_BGP
) {
2172 /* Fetch routemap's rule information. */
2176 /* Set next hop value. */
2177 bgp_info
->attr
->mp_nexthop_global
= *address
;
2179 /* Set nexthop length. */
2180 if (bgp_info
->attr
->mp_nexthop_len
== 0)
2181 bgp_info
->attr
->mp_nexthop_len
=
2182 BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2184 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2185 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2191 /* Route map `ip next-hop' compile function. Given string is converted
2192 to struct in_addr structure. */
2193 static void *route_set_ipv6_nexthop_global_compile(const char *arg
)
2196 struct in6_addr
*address
;
2198 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2200 ret
= inet_pton(AF_INET6
, arg
, address
);
2203 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2210 /* Free route map's compiled `ip next-hop' value. */
2211 static void route_set_ipv6_nexthop_global_free(void *rule
)
2213 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2216 /* Route map commands for ip nexthop set. */
2217 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
= {
2218 "ipv6 next-hop global", route_set_ipv6_nexthop_global
,
2219 route_set_ipv6_nexthop_global_compile
,
2220 route_set_ipv6_nexthop_global_free
};
2222 /* Set next-hop preference value. */
2223 static route_map_result_t
2224 route_set_ipv6_nexthop_prefer_global(void *rule
, struct prefix
*prefix
,
2225 route_map_object_t type
, void *object
)
2227 struct bgp_info
*bgp_info
;
2230 if (type
== RMAP_BGP
) {
2231 /* Fetch routemap's rule information. */
2233 peer
= bgp_info
->peer
;
2235 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2236 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2238 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2239 /* Set next hop preference to global */
2240 bgp_info
->attr
->mp_nexthop_prefer_global
= TRUE
;
2241 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2242 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2244 bgp_info
->attr
->mp_nexthop_prefer_global
= FALSE
;
2245 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2246 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2252 static void *route_set_ipv6_nexthop_prefer_global_compile(const char *arg
)
2256 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2262 /* Free route map's compiled `ip next-hop' value. */
2263 static void route_set_ipv6_nexthop_prefer_global_free(void *rule
)
2265 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2268 /* Route map commands for ip nexthop set preferred. */
2269 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
= {
2270 "ipv6 next-hop prefer-global", route_set_ipv6_nexthop_prefer_global
,
2271 route_set_ipv6_nexthop_prefer_global_compile
,
2272 route_set_ipv6_nexthop_prefer_global_free
};
2274 /* `set ipv6 nexthop local IP_ADDRESS' */
2276 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2277 static route_map_result_t
route_set_ipv6_nexthop_local(void *rule
,
2278 struct prefix
*prefix
,
2279 route_map_object_t type
,
2282 struct in6_addr
*address
;
2283 struct bgp_info
*bgp_info
;
2285 if (type
== RMAP_BGP
) {
2286 /* Fetch routemap's rule information. */
2290 /* Set next hop value. */
2291 bgp_info
->attr
->mp_nexthop_local
= *address
;
2293 /* Set nexthop length. */
2294 if (bgp_info
->attr
->mp_nexthop_len
2295 != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2296 bgp_info
->attr
->mp_nexthop_len
=
2297 BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2299 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2300 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2306 /* Route map `ip nexthop' compile function. Given string is converted
2307 to struct in_addr structure. */
2308 static void *route_set_ipv6_nexthop_local_compile(const char *arg
)
2311 struct in6_addr
*address
;
2313 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2315 ret
= inet_pton(AF_INET6
, arg
, address
);
2318 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2325 /* Free route map's compiled `ip nexthop' value. */
2326 static void route_set_ipv6_nexthop_local_free(void *rule
)
2328 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2331 /* Route map commands for ip nexthop set. */
2332 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
= {
2333 "ipv6 next-hop local", route_set_ipv6_nexthop_local
,
2334 route_set_ipv6_nexthop_local_compile
,
2335 route_set_ipv6_nexthop_local_free
};
2337 /* `set ipv6 nexthop peer-address' */
2339 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2340 static route_map_result_t
route_set_ipv6_nexthop_peer(void *rule
,
2341 struct prefix
*prefix
,
2342 route_map_object_t type
,
2345 struct in6_addr peer_address
;
2346 struct bgp_info
*bgp_info
;
2349 if (type
== RMAP_BGP
) {
2350 /* Fetch routemap's rule information. */
2352 peer
= bgp_info
->peer
;
2354 if ((CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IN
)
2355 || CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2357 && sockunion_family(peer
->su_remote
) == AF_INET6
) {
2358 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2359 /* Set next hop value and length in attribute. */
2360 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
)) {
2361 bgp_info
->attr
->mp_nexthop_local
= peer_address
;
2362 if (bgp_info
->attr
->mp_nexthop_len
!= 32)
2363 bgp_info
->attr
->mp_nexthop_len
= 32;
2365 bgp_info
->attr
->mp_nexthop_global
=
2367 if (bgp_info
->attr
->mp_nexthop_len
== 0)
2368 bgp_info
->attr
->mp_nexthop_len
= 16;
2371 } else if (CHECK_FLAG(peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)) {
2372 /* The next hop value will be set as part of packet
2374 * Set the flags here to indicate that rewrite needs to
2376 * Also, clear the value - we clear both global and
2378 * nexthops, whether we send one or both is determined
2381 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2382 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2383 /* clear next hop value. */
2384 memset(&(bgp_info
->attr
->mp_nexthop_global
), 0,
2385 sizeof(struct in6_addr
));
2386 memset(&(bgp_info
->attr
->mp_nexthop_local
), 0,
2387 sizeof(struct in6_addr
));
2394 /* Route map `ip next-hop' compile function. Given string is converted
2395 to struct in_addr structure. */
2396 static void *route_set_ipv6_nexthop_peer_compile(const char *arg
)
2400 rins
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(int));
2406 /* Free route map's compiled `ip next-hop' value. */
2407 static void route_set_ipv6_nexthop_peer_free(void *rule
)
2409 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2412 /* Route map commands for ip nexthop set. */
2413 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
= {
2414 "ipv6 next-hop peer-address", route_set_ipv6_nexthop_peer
,
2415 route_set_ipv6_nexthop_peer_compile
, route_set_ipv6_nexthop_peer_free
};
2417 /* `set ipv4 vpn next-hop A.B.C.D' */
2419 static route_map_result_t
route_set_vpnv4_nexthop(void *rule
,
2420 struct prefix
*prefix
,
2421 route_map_object_t type
,
2424 struct in_addr
*address
;
2425 struct bgp_info
*bgp_info
;
2427 if (type
== RMAP_BGP
) {
2428 /* Fetch routemap's rule information. */
2432 /* Set next hop value. */
2433 bgp_info
->attr
->mp_nexthop_global_in
= *address
;
2434 bgp_info
->attr
->mp_nexthop_len
= 4;
2440 static void *route_set_vpnv4_nexthop_compile(const char *arg
)
2443 struct in_addr
*address
;
2445 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2447 ret
= inet_aton(arg
, address
);
2450 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2457 /* `set ipv6 vpn next-hop A.B.C.D' */
2459 static route_map_result_t
route_set_vpnv6_nexthop(void *rule
,
2460 struct prefix
*prefix
,
2461 route_map_object_t type
,
2464 struct in6_addr
*address
;
2465 struct bgp_info
*bgp_info
;
2467 if (type
== RMAP_BGP
) {
2468 /* Fetch routemap's rule information. */
2472 /* Set next hop value. */
2473 memcpy(&bgp_info
->attr
->mp_nexthop_global
, address
,
2474 sizeof(struct in6_addr
));
2475 bgp_info
->attr
->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2481 static void *route_set_vpnv6_nexthop_compile(const char *arg
)
2484 struct in6_addr
*address
;
2486 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in6_addr
));
2487 ret
= inet_pton(AF_INET6
, arg
, address
);
2490 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2497 static void route_set_vpn_nexthop_free(void *rule
)
2499 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2502 /* Route map commands for ipv4 next-hop set. */
2503 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
= {
2504 "ipv4 vpn next-hop", route_set_vpnv4_nexthop
,
2505 route_set_vpnv4_nexthop_compile
, route_set_vpn_nexthop_free
};
2507 /* Route map commands for ipv6 next-hop set. */
2508 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
= {
2509 "ipv6 vpn next-hop", route_set_vpnv6_nexthop
,
2510 route_set_vpnv6_nexthop_compile
, route_set_vpn_nexthop_free
};
2512 /* `set originator-id' */
2514 /* For origin set. */
2515 static route_map_result_t
route_set_originator_id(void *rule
,
2516 struct prefix
*prefix
,
2517 route_map_object_t type
,
2520 struct in_addr
*address
;
2521 struct bgp_info
*bgp_info
;
2523 if (type
== RMAP_BGP
) {
2527 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID
);
2528 bgp_info
->attr
->originator_id
= *address
;
2534 /* Compile function for originator-id set. */
2535 static void *route_set_originator_id_compile(const char *arg
)
2538 struct in_addr
*address
;
2540 address
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct in_addr
));
2542 ret
= inet_aton(arg
, address
);
2545 XFREE(MTYPE_ROUTE_MAP_COMPILED
, address
);
2552 /* Compile function for originator_id set. */
2553 static void route_set_originator_id_free(void *rule
)
2555 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
2558 /* Set originator-id rule structure. */
2559 struct route_map_rule_cmd route_set_originator_id_cmd
= {
2560 "originator-id", route_set_originator_id
,
2561 route_set_originator_id_compile
, route_set_originator_id_free
,
2564 /* Add bgp route map rule. */
2565 static int bgp_route_match_add(struct vty
*vty
, const char *command
,
2566 const char *arg
, route_map_event_t type
)
2568 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2571 ret
= route_map_add_match(index
, command
, arg
);
2574 case RMAP_RULE_MISSING
:
2575 vty_out(vty
, "%% BGP Can't find rule.\n");
2576 return CMD_WARNING_CONFIG_FAILED
;
2577 case RMAP_COMPILE_ERROR
:
2578 vty_out(vty
, "%% BGP Argument is malformed.\n");
2579 return CMD_WARNING_CONFIG_FAILED
;
2583 if (type
!= RMAP_EVENT_MATCH_ADDED
) {
2584 route_map_upd8_dependency(type
, arg
, index
->map
->name
);
2590 /* Delete bgp route map rule. */
2591 static int bgp_route_match_delete(struct vty
*vty
, const char *command
,
2592 const char *arg
, route_map_event_t type
)
2594 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2596 char *dep_name
= NULL
;
2598 char *rmap_name
= NULL
;
2600 if (type
!= RMAP_EVENT_MATCH_DELETED
) {
2601 /* ignore the mundane, the types without any dependency */
2603 if ((tmpstr
= route_map_get_match_arg(index
, command
))
2606 XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
2608 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
2610 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
2613 ret
= route_map_delete_match(index
, command
, dep_name
);
2616 case RMAP_RULE_MISSING
:
2617 vty_out(vty
, "%% BGP Can't find rule.\n");
2619 case RMAP_COMPILE_ERROR
:
2620 vty_out(vty
, "%% BGP Argument is malformed.\n");
2624 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2626 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2627 return CMD_WARNING_CONFIG_FAILED
;
2630 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
2631 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
2634 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2636 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2642 * This is the workhorse routine for processing in/out routemap
2645 static void bgp_route_map_process_peer(const char *rmap_name
,
2646 struct route_map
*map
, struct peer
*peer
,
2647 int afi
, int safi
, int route_update
)
2651 struct bgp_filter
*filter
;
2653 if (!peer
|| !rmap_name
)
2656 filter
= &peer
->filter
[afi
][safi
];
2658 * in is for non-route-server clients,
2659 * out is for all peers
2661 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
2662 if (filter
->map
[RMAP_IN
].name
2663 && (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0)) {
2664 filter
->map
[RMAP_IN
].map
= map
;
2666 if (route_update
&& peer
->status
== Established
) {
2667 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
2668 PEER_FLAG_SOFT_RECONFIG
)) {
2669 if (bgp_debug_update(peer
, NULL
, NULL
,
2672 "Processing route_map %s update on "
2673 "peer %s (inbound, soft-reconfig)",
2674 rmap_name
, peer
->host
);
2676 bgp_soft_reconfig_in(peer
, afi
, safi
);
2678 CHECK_FLAG(peer
->cap
,
2679 PEER_CAP_REFRESH_OLD_RCV
)
2682 PEER_CAP_REFRESH_NEW_RCV
)) {
2684 if (bgp_debug_update(peer
, NULL
, NULL
,
2687 "Processing route_map %s update on "
2688 "peer %s (inbound, route-refresh)",
2689 rmap_name
, peer
->host
);
2690 bgp_route_refresh_send(peer
, afi
, safi
,
2697 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
)) {
2700 if (update
&& route_update
&& peer
->status
== Established
) {
2701 if (CHECK_FLAG(peer
->af_flags
[afi
][safi
],
2702 PEER_FLAG_SOFT_RECONFIG
)) {
2703 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2705 "Processing route_map %s update on "
2706 "peer %s (import, soft-reconfig)",
2707 rmap_name
, peer
->host
);
2709 bgp_soft_reconfig_in(peer
, afi
, safi
);
2710 } else if (CHECK_FLAG(peer
->cap
,
2711 PEER_CAP_REFRESH_OLD_RCV
)
2712 || CHECK_FLAG(peer
->cap
,
2713 PEER_CAP_REFRESH_NEW_RCV
)) {
2714 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2716 "Processing route_map %s update on "
2717 "peer %s (import, route-refresh)",
2718 rmap_name
, peer
->host
);
2719 bgp_route_refresh_send(peer
, afi
, safi
, 0, 0,
2722 /* DD: Else, what else do we do ? Reset peer ? */
2727 * For outbound, unsuppress and default-originate map change (content or
2728 * map created), merely update the "config" here, the actual route
2729 * announcement happens at the group level.
2731 if (filter
->map
[RMAP_OUT
].name
2732 && (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
2733 filter
->map
[RMAP_OUT
].map
= map
;
2735 if (filter
->usmap
.name
&& (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
2736 filter
->usmap
.map
= map
;
2738 if (peer
->default_rmap
[afi
][safi
].name
2739 && (strcmp(rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
2740 peer
->default_rmap
[afi
][safi
].map
= map
;
2743 static void bgp_route_map_update_peer_group(const char *rmap_name
,
2744 struct route_map
*map
,
2747 struct peer_group
*group
;
2748 struct listnode
*node
, *nnode
;
2749 struct bgp_filter
*filter
;
2756 /* All the peers have been updated correctly already. This is
2757 * just updating the placeholder data. No real update required.
2759 for (ALL_LIST_ELEMENTS(bgp
->group
, node
, nnode
, group
))
2760 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2761 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
2762 filter
= &group
->conf
->filter
[afi
][safi
];
2764 for (direct
= RMAP_IN
; direct
< RMAP_MAX
;
2766 if ((filter
->map
[direct
].name
)
2767 && (strcmp(rmap_name
,
2768 filter
->map
[direct
].name
)
2770 filter
->map
[direct
].map
= map
;
2773 if (filter
->usmap
.name
2774 && (strcmp(rmap_name
, filter
->usmap
.name
)
2776 filter
->usmap
.map
= map
;
2781 * Note that if an extreme number (tens of thousands) of route-maps are in use
2782 * and if bgp has an extreme number of peers, network statements, etc then this
2783 * function can consume a lot of cycles. This is due to this function being
2784 * called for each route-map and within this function we walk the list of peers,
2785 * network statements, etc looking to see if they use this route-map.
2787 static void bgp_route_map_process_update(struct bgp
*bgp
, const char *rmap_name
,
2794 struct bgp_node
*bn
;
2795 struct bgp_static
*bgp_static
;
2796 struct listnode
*node
, *nnode
;
2797 struct route_map
*map
;
2798 char buf
[INET6_ADDRSTRLEN
];
2800 map
= route_map_lookup_by_name(rmap_name
);
2802 for (ALL_LIST_ELEMENTS(bgp
->peer
, node
, nnode
, peer
)) {
2804 /* Ignore dummy peer-group structure */
2805 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
2808 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2809 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
2810 /* Ignore inactive AFI/SAFI */
2811 if (!peer
->afc
[afi
][safi
])
2814 /* process in/out/import/export/default-orig
2816 bgp_route_map_process_peer(rmap_name
, map
, peer
,
2822 /* for outbound/default-orig route-maps, process for groups */
2823 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
2826 /* update peer-group config (template) */
2827 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
2829 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2830 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++) {
2831 /* For table route-map updates. */
2832 if (!bgp_fibupd_safi(safi
))
2835 if (bgp
->table_map
[afi
][safi
].name
2836 && (strcmp(rmap_name
,
2837 bgp
->table_map
[afi
][safi
].name
)
2839 bgp
->table_map
[afi
][safi
].map
= map
;
2841 if (BGP_DEBUG(zebra
, ZEBRA
))
2843 "Processing route_map %s update on "
2847 bgp_zebra_announce_table(bgp
, afi
,
2851 /* For network route-map updates. */
2852 for (bn
= bgp_table_top(bgp
->route
[afi
][safi
]); bn
;
2853 bn
= bgp_route_next(bn
))
2854 if ((bgp_static
= bn
->info
) != NULL
) {
2855 if (bgp_static
->rmap
.name
2856 && (strcmp(rmap_name
,
2857 bgp_static
->rmap
.name
)
2859 bgp_static
->rmap
.map
= map
;
2864 if (bgp_debug_zebra(
2867 "Processing route_map %s update on "
2886 /* For redistribute route-map updates. */
2887 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2888 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++) {
2889 struct list
*red_list
;
2890 struct listnode
*node
;
2891 struct bgp_redist
*red
;
2893 red_list
= bgp
->redist
[afi
][i
];
2897 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
)) {
2899 && (strcmp(rmap_name
, red
->rmap
.name
)
2901 red
->rmap
.map
= map
;
2904 if (BGP_DEBUG(zebra
, ZEBRA
))
2906 "Processing route_map %s update on "
2907 "redistributed routes",
2910 bgp_redistribute_resend(
2919 static int bgp_route_map_process_update_cb(char *rmap_name
)
2921 struct listnode
*node
, *nnode
;
2924 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
2925 bgp_route_map_process_update(bgp
, rmap_name
, 1);
2928 zlog_debug("%s: calling vnc_routemap_update", __func__
);
2929 vnc_routemap_update(bgp
, __func__
);
2934 int bgp_route_map_update_timer(struct thread
*thread
)
2936 bm
->t_rmap_update
= NULL
;
2938 route_map_walk_update_list(bgp_route_map_process_update_cb
);
2943 static void bgp_route_map_mark_update(const char *rmap_name
)
2945 if (bm
->t_rmap_update
== NULL
) {
2946 struct listnode
*node
, *nnode
;
2949 /* rmap_update_timer of 0 means don't do route updates */
2950 if (bm
->rmap_update_timer
) {
2951 bm
->t_rmap_update
= NULL
;
2952 thread_add_timer(bm
->master
, bgp_route_map_update_timer
,
2953 NULL
, bm
->rmap_update_timer
,
2954 &bm
->t_rmap_update
);
2956 /* Signal the groups that a route-map update event has
2958 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
2959 update_group_policy_update(bgp
,
2960 BGP_POLICY_ROUTE_MAP
,
2963 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
))
2964 bgp_route_map_process_update(bgp
, rmap_name
, 0);
2966 zlog_debug("%s: calling vnc_routemap_update", __func__
);
2967 vnc_routemap_update(bgp
, __func__
);
2973 static void bgp_route_map_add(const char *rmap_name
)
2975 if (route_map_mark_updated(rmap_name
, 0) == 0)
2976 bgp_route_map_mark_update(rmap_name
);
2978 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
2981 static void bgp_route_map_delete(const char *rmap_name
)
2983 if (route_map_mark_updated(rmap_name
, 1) == 0)
2984 bgp_route_map_mark_update(rmap_name
);
2986 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
2989 static void bgp_route_map_event(route_map_event_t event
, const char *rmap_name
)
2991 if (route_map_mark_updated(rmap_name
, 0) == 0)
2992 bgp_route_map_mark_update(rmap_name
);
2994 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3000 "match peer <A.B.C.D|X:X::X:X>",
3002 "Match peer address\n"
3003 "IP address of peer\n"
3004 "IPv6 address of peer\n")
3007 return bgp_route_match_add(vty
, "peer", argv
[idx_ip
]->arg
,
3008 RMAP_EVENT_MATCH_ADDED
);
3011 DEFUN (match_peer_local
,
3012 match_peer_local_cmd
,
3015 "Match peer address\n"
3016 "Static or Redistributed routes\n")
3018 return bgp_route_match_add(vty
, "peer", "local",
3019 RMAP_EVENT_MATCH_DELETED
);
3022 DEFUN (no_match_peer
,
3024 "no match peer [<local|A.B.C.D|X:X::X:X>]",
3027 "Match peer address\n"
3028 "Static or Redistributed routes\n"
3029 "IP address of peer\n"
3030 "IPv6 address of peer\n")
3034 if (argc
<= idx_peer
)
3035 return bgp_route_match_delete(vty
, "peer", NULL
,
3036 RMAP_EVENT_MATCH_DELETED
);
3037 return bgp_route_match_delete(vty
, "peer", argv
[idx_peer
]->arg
,
3038 RMAP_EVENT_MATCH_DELETED
);
3042 /* match probability */
3043 DEFUN (match_probability
,
3044 match_probability_cmd
,
3045 "match probability (0-100)",
3047 "Match portion of routes defined by percentage value\n"
3048 "Percentage of routes\n")
3051 return bgp_route_match_add(vty
, "probability", argv
[idx_number
]->arg
,
3052 RMAP_EVENT_MATCH_ADDED
);
3056 DEFUN (no_match_probability
,
3057 no_match_probability_cmd
,
3058 "no match probability [(1-99)]",
3061 "Match portion of routes defined by percentage value\n"
3062 "Percentage of routes\n")
3065 if (argc
<= idx_number
)
3066 return bgp_route_match_delete(vty
, "probability", NULL
,
3067 RMAP_EVENT_MATCH_DELETED
);
3068 return bgp_route_match_delete(vty
, "probability", argv
[idx_number
]->arg
,
3069 RMAP_EVENT_MATCH_DELETED
);
3073 DEFUN (match_ip_route_source
,
3074 match_ip_route_source_cmd
,
3075 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3078 "Match advertising source address of route\n"
3079 "IP access-list number\n"
3080 "IP access-list number (expanded range)\n"
3081 "IP standard access-list name\n")
3084 return bgp_route_match_add(vty
, "ip route-source", argv
[idx_acl
]->arg
,
3085 RMAP_EVENT_FILTER_ADDED
);
3089 DEFUN (no_match_ip_route_source
,
3090 no_match_ip_route_source_cmd
,
3091 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3095 "Match advertising source address of route\n"
3096 "IP access-list number\n"
3097 "IP access-list number (expanded range)\n"
3098 "IP standard access-list name\n")
3101 if (argc
<= idx_number
)
3102 return bgp_route_match_delete(vty
, "ip route-source", NULL
,
3103 RMAP_EVENT_FILTER_DELETED
);
3104 return bgp_route_match_delete(vty
, "ip route-source",
3105 argv
[idx_number
]->arg
,
3106 RMAP_EVENT_FILTER_DELETED
);
3110 DEFUN (match_ip_route_source_prefix_list
,
3111 match_ip_route_source_prefix_list_cmd
,
3112 "match ip route-source prefix-list WORD",
3115 "Match advertising source address of route\n"
3116 "Match entries of prefix-lists\n"
3117 "IP prefix-list name\n")
3120 return bgp_route_match_add(vty
, "ip route-source prefix-list",
3121 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3125 DEFUN (no_match_ip_route_source_prefix_list
,
3126 no_match_ip_route_source_prefix_list_cmd
,
3127 "no match ip route-source prefix-list [WORD]",
3131 "Match advertising source address of route\n"
3132 "Match entries of prefix-lists\n"
3133 "IP prefix-list name\n")
3136 if (argc
<= idx_word
)
3137 return bgp_route_match_delete(vty
,
3138 "ip route-source prefix-list",
3139 NULL
, RMAP_EVENT_PLIST_DELETED
);
3140 return bgp_route_match_delete(vty
, "ip route-source prefix-list",
3141 argv
[idx_word
]->arg
,
3142 RMAP_EVENT_PLIST_DELETED
);
3146 DEFUN (match_local_pref
,
3147 match_local_pref_cmd
,
3148 "match local-preference (0-4294967295)",
3150 "Match local-preference of route\n"
3154 return bgp_route_match_add(vty
, "local-preference",
3155 argv
[idx_number
]->arg
,
3156 RMAP_EVENT_MATCH_ADDED
);
3160 DEFUN (no_match_local_pref
,
3161 no_match_local_pref_cmd
,
3162 "no match local-preference [(0-4294967295)]",
3165 "Match local preference of route\n"
3166 "Local preference value\n")
3168 int idx_localpref
= 3;
3169 if (argc
<= idx_localpref
)
3170 return bgp_route_match_delete(vty
, "local-preference", NULL
,
3171 RMAP_EVENT_MATCH_DELETED
);
3172 return bgp_route_match_delete(vty
, "local-preference",
3173 argv
[idx_localpref
]->arg
,
3174 RMAP_EVENT_MATCH_DELETED
);
3178 DEFUN (match_community
,
3179 match_community_cmd
,
3180 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3182 "Match BGP community list\n"
3183 "Community-list number (standard)\n"
3184 "Community-list number (expanded)\n"
3185 "Community-list name\n"
3186 "Do exact matching of communities\n")
3188 int idx_comm_list
= 2;
3193 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3194 strlen(argv
[idx_comm_list
]->arg
)
3195 + strlen("exact-match") + 2);
3197 sprintf(argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3199 argstr
= argv
[idx_comm_list
]->arg
;
3201 ret
= bgp_route_match_add(vty
, "community", argstr
,
3202 RMAP_EVENT_CLIST_ADDED
);
3204 if (argstr
!= argv
[idx_comm_list
]->arg
)
3205 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3210 DEFUN (no_match_community
,
3211 no_match_community_cmd
,
3212 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3215 "Match BGP community list\n"
3216 "Community-list number (standard)\n"
3217 "Community-list number (expanded)\n"
3218 "Community-list name\n"
3219 "Do exact matching of communities\n")
3221 return bgp_route_match_delete(vty
, "community", NULL
,
3222 RMAP_EVENT_CLIST_DELETED
);
3225 DEFUN (match_lcommunity
,
3226 match_lcommunity_cmd
,
3227 "match large-community <(1-99)|(100-500)|WORD>",
3229 "Match BGP large community list\n"
3230 "Large Community-list number (standard)\n"
3231 "Large Community-list number (expanded)\n"
3232 "Large Community-list name\n")
3234 return bgp_route_match_add(vty
, "large-community", argv
[2]->arg
,
3235 RMAP_EVENT_LLIST_ADDED
);
3238 DEFUN (no_match_lcommunity
,
3239 no_match_lcommunity_cmd
,
3240 "no match large-community [<(1-99)|(100-500)|WORD>]",
3243 "Match BGP large community list\n"
3244 "Large Community-list number (standard)\n"
3245 "Large Community-list number (expanded)\n"
3246 "Large Community-list name\n")
3248 return bgp_route_match_delete(vty
, "large-community", NULL
,
3249 RMAP_EVENT_LLIST_DELETED
);
3252 DEFUN (match_ecommunity
,
3253 match_ecommunity_cmd
,
3254 "match extcommunity <(1-99)|(100-500)|WORD>",
3256 "Match BGP/VPN extended community list\n"
3257 "Extended community-list number (standard)\n"
3258 "Extended community-list number (expanded)\n"
3259 "Extended community-list name\n")
3261 int idx_comm_list
= 2;
3262 return bgp_route_match_add(vty
, "extcommunity",
3263 argv
[idx_comm_list
]->arg
,
3264 RMAP_EVENT_ECLIST_ADDED
);
3268 DEFUN (no_match_ecommunity
,
3269 no_match_ecommunity_cmd
,
3270 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3273 "Match BGP/VPN extended community list\n"
3274 "Extended community-list number (standard)\n"
3275 "Extended community-list number (expanded)\n"
3276 "Extended community-list name\n")
3278 return bgp_route_match_delete(vty
, "extcommunity", NULL
,
3279 RMAP_EVENT_ECLIST_DELETED
);
3283 DEFUN (match_aspath
,
3285 "match as-path WORD",
3287 "Match BGP AS path list\n"
3288 "AS path access-list name\n")
3291 return bgp_route_match_add(vty
, "as-path", argv
[idx_word
]->arg
,
3292 RMAP_EVENT_ASLIST_ADDED
);
3296 DEFUN (no_match_aspath
,
3297 no_match_aspath_cmd
,
3298 "no match as-path [WORD]",
3301 "Match BGP AS path list\n"
3302 "AS path access-list name\n")
3304 return bgp_route_match_delete(vty
, "as-path", NULL
,
3305 RMAP_EVENT_ASLIST_DELETED
);
3309 DEFUN (match_origin
,
3311 "match origin <egp|igp|incomplete>",
3316 "unknown heritage\n")
3319 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3320 return bgp_route_match_add(vty
, "origin", "igp",
3321 RMAP_EVENT_MATCH_ADDED
);
3322 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3323 return bgp_route_match_add(vty
, "origin", "egp",
3324 RMAP_EVENT_MATCH_ADDED
);
3325 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3326 return bgp_route_match_add(vty
, "origin", "incomplete",
3327 RMAP_EVENT_MATCH_ADDED
);
3329 vty_out(vty
, "%% Invalid match origin type\n");
3330 return CMD_WARNING_CONFIG_FAILED
;
3334 DEFUN (no_match_origin
,
3335 no_match_origin_cmd
,
3336 "no match origin [<egp|igp|incomplete>]",
3342 "unknown heritage\n")
3344 return bgp_route_match_delete(vty
, "origin", NULL
,
3345 RMAP_EVENT_MATCH_DELETED
);
3348 DEFUN (set_ip_nexthop_peer
,
3349 set_ip_nexthop_peer_cmd
,
3350 "set ip next-hop peer-address",
3353 "Next hop address\n"
3354 "Use peer address (for BGP only)\n")
3356 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3357 "ip next-hop", "peer-address");
3360 DEFUN (set_ip_nexthop_unchanged
,
3361 set_ip_nexthop_unchanged_cmd
,
3362 "set ip next-hop unchanged",
3365 "Next hop address\n"
3366 "Don't modify existing Next hop address\n")
3368 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3369 "ip next-hop", "unchanged");
3373 DEFUN (set_local_pref
,
3375 "set local-preference (0-4294967295)",
3377 "BGP local preference path attribute\n"
3378 "Preference value\n")
3381 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3382 "local-preference", argv
[idx_number
]->arg
);
3386 DEFUN (no_set_local_pref
,
3387 no_set_local_pref_cmd
,
3388 "no set local-preference [(0-4294967295)]",
3391 "BGP local preference path attribute\n"
3392 "Preference value\n")
3394 int idx_localpref
= 3;
3395 if (argc
<= idx_localpref
)
3396 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3397 "local-preference", NULL
);
3398 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3399 "local-preference", argv
[idx_localpref
]->arg
);
3405 "set weight (0-4294967295)",
3407 "BGP weight for routing table\n"
3411 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
3412 argv
[idx_number
]->arg
);
3416 DEFUN (no_set_weight
,
3418 "no set weight [(0-4294967295)]",
3421 "BGP weight for routing table\n"
3425 if (argc
<= idx_weight
)
3426 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3428 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3429 "weight", argv
[idx_weight
]->arg
);
3432 DEFUN (set_label_index
,
3433 set_label_index_cmd
,
3434 "set label-index (0-1048560)",
3436 "Label index to associate with the prefix\n"
3437 "Label index value\n")
3440 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3441 "label-index", argv
[idx_number
]->arg
);
3444 DEFUN (no_set_label_index
,
3445 no_set_label_index_cmd
,
3446 "no set label-index [(0-1048560)]",
3449 "Label index to associate with the prefix\n"
3450 "Label index value\n")
3452 int idx_label_index
= 3;
3453 if (argc
<= idx_label_index
)
3454 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3455 "label-index", NULL
);
3456 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3457 "label-index", argv
[idx_label_index
]->arg
);
3460 DEFUN (set_aspath_prepend_asn
,
3461 set_aspath_prepend_asn_cmd
,
3462 "set as-path prepend (1-4294967295)...",
3464 "Transform BGP AS_PATH attribute\n"
3465 "Prepend to the as-path\n"
3472 str
= argv_concat(argv
, argc
, idx_asn
);
3473 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3474 "as-path prepend", str
);
3475 XFREE(MTYPE_TMP
, str
);
3480 DEFUN (set_aspath_prepend_lastas
,
3481 set_aspath_prepend_lastas_cmd
,
3482 "set as-path prepend last-as (1-10)",
3484 "Transform BGP AS_PATH attribute\n"
3485 "Prepend to the as-path\n"
3486 "Use the peer's AS-number\n"
3487 "Number of times to insert\n")
3489 return set_aspath_prepend_asn(self
, vty
, argc
, argv
);
3492 DEFUN (no_set_aspath_prepend
,
3493 no_set_aspath_prepend_cmd
,
3494 "no set as-path prepend [(1-4294967295)]",
3497 "Transform BGP AS_PATH attribute\n"
3498 "Prepend to the as-path\n"
3505 str
= argv_concat(argv
, argc
, idx_asn
);
3506 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3507 "as-path prepend", str
);
3508 XFREE(MTYPE_TMP
, str
);
3513 DEFUN (set_aspath_exclude
,
3514 set_aspath_exclude_cmd
,
3515 "set as-path exclude (1-4294967295)...",
3517 "Transform BGP AS-path attribute\n"
3518 "Exclude from the as-path\n"
3525 str
= argv_concat(argv
, argc
, idx_asn
);
3526 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3527 "as-path exclude", str
);
3528 XFREE(MTYPE_TMP
, str
);
3532 DEFUN (no_set_aspath_exclude
,
3533 no_set_aspath_exclude_cmd
,
3534 "no set as-path exclude (1-4294967295)...",
3537 "Transform BGP AS_PATH attribute\n"
3538 "Exclude from the as-path\n"
3545 str
= argv_concat(argv
, argc
, idx_asn
);
3546 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3547 "as-path exclude", str
);
3548 XFREE(MTYPE_TMP
, str
);
3553 DEFUN (set_community
,
3555 "set community AA:NN...",
3557 "BGP community attribute\n"
3565 struct community
*com
= NULL
;
3570 b
= buffer_new(1024);
3572 for (i
= idx_aa_nn
; i
< argc
; i
++) {
3573 if (strncmp(argv
[i
]->arg
, "additive", strlen(argv
[i
]->arg
))
3580 buffer_putc(b
, ' ');
3584 if (strncmp(argv
[i
]->arg
, "internet", strlen(argv
[i
]->arg
))
3586 buffer_putstr(b
, "internet");
3589 if (strncmp(argv
[i
]->arg
, "local-AS", strlen(argv
[i
]->arg
))
3591 buffer_putstr(b
, "local-AS");
3594 if (strncmp(argv
[i
]->arg
, "no-a", strlen("no-a")) == 0
3595 && strncmp(argv
[i
]->arg
, "no-advertise",
3596 strlen(argv
[i
]->arg
))
3598 buffer_putstr(b
, "no-advertise");
3601 if (strncmp(argv
[i
]->arg
, "no-e", strlen("no-e")) == 0
3602 && strncmp(argv
[i
]->arg
, "no-export", strlen(argv
[i
]->arg
))
3604 buffer_putstr(b
, "no-export");
3607 buffer_putstr(b
, argv
[i
]->arg
);
3609 buffer_putc(b
, '\0');
3611 /* Fetch result string then compile it to communities attribute. */
3612 str
= buffer_getstr(b
);
3616 com
= community_str2com(str
);
3617 XFREE(MTYPE_TMP
, str
);
3620 /* Can't compile user input into communities attribute. */
3622 vty_out(vty
, "%% Malformed communities attribute\n");
3623 return CMD_WARNING_CONFIG_FAILED
;
3626 /* Set communites attribute string. */
3627 str
= community_str(com
);
3630 argstr
= XCALLOC(MTYPE_TMP
,
3631 strlen(str
) + strlen(" additive") + 1);
3632 strcpy(argstr
, str
);
3633 strcpy(argstr
+ strlen(str
), " additive");
3634 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3635 "community", argstr
);
3636 XFREE(MTYPE_TMP
, argstr
);
3638 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3641 community_free(com
);
3646 DEFUN (set_community_none
,
3647 set_community_none_cmd
,
3648 "set community none",
3650 "BGP community attribute\n"
3651 "No community attribute\n")
3653 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3654 "community", "none");
3657 DEFUN (no_set_community
,
3658 no_set_community_cmd
,
3659 "no set community AA:NN...",
3662 "BGP community attribute\n"
3665 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3670 DEFUN (set_community_delete
,
3671 set_community_delete_cmd
,
3672 "set comm-list <(1-99)|(100-500)|WORD> delete",
3674 "set BGP community list (for deletion)\n"
3675 "Community-list number (standard)\n"
3676 "Community-list number (expanded)\n"
3677 "Community-list name\n"
3678 "Delete matching communities\n")
3680 int idx_comm_list
= 2;
3683 str
= XCALLOC(MTYPE_TMP
,
3684 strlen(argv
[idx_comm_list
]->arg
) + strlen(" delete") + 1);
3685 strcpy(str
, argv
[idx_comm_list
]->arg
);
3686 strcpy(str
+ strlen(argv
[idx_comm_list
]->arg
), " delete");
3688 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list",
3691 XFREE(MTYPE_TMP
, str
);
3695 DEFUN (no_set_community_delete
,
3696 no_set_community_delete_cmd
,
3697 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
3700 "set BGP community list (for deletion)\n"
3701 "Community-list number (standard)\n"
3702 "Community-list number (expanded)\n"
3703 "Community-list name\n"
3704 "Delete matching communities\n")
3706 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3710 DEFUN (set_lcommunity
,
3712 "set large-community AA:BB:CC...",
3714 "BGP large community attribute\n"
3715 "Large Community number in aa:bb:cc format or additive\n")
3720 str
= argv_concat(argv
, argc
, 2);
3721 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3722 "large-community", str
);
3723 XFREE(MTYPE_TMP
, str
);
3728 DEFUN (set_lcommunity_none
,
3729 set_lcommunity_none_cmd
,
3730 "set large-community none",
3732 "BGP large community attribute\n"
3733 "No large community attribute\n")
3735 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3736 "large-community", "none");
3739 DEFUN (no_set_lcommunity
,
3740 no_set_lcommunity_cmd
,
3741 "no set large-community none",
3744 "BGP large community attribute\n"
3745 "No community attribute\n")
3747 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3748 "large-community", NULL
);
3751 DEFUN (no_set_lcommunity1
,
3752 no_set_lcommunity1_cmd
,
3753 "no set large-community AA:BB:CC...",
3756 "BGP large community attribute\n"
3757 "Large community in AA:BB:CC... format or additive\n")
3759 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3760 "large-community", NULL
);
3763 DEFUN (set_lcommunity_delete
,
3764 set_lcommunity_delete_cmd
,
3765 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
3767 "set BGP large community list (for deletion)\n"
3768 "Large Community-list number (standard)\n"
3769 "Large Communitly-list number (expanded)\n"
3770 "Large Community-list name\n"
3771 "Delete matching large communities\n")
3775 str
= XCALLOC(MTYPE_TMP
, strlen(argv
[2]->arg
) + strlen(" delete") + 1);
3776 strcpy(str
, argv
[2]->arg
);
3777 strcpy(str
+ strlen(argv
[2]->arg
), " delete");
3779 generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3780 "large-comm-list", str
);
3782 XFREE(MTYPE_TMP
, str
);
3786 DEFUN (no_set_lcommunity_delete
,
3787 no_set_lcommunity_delete_cmd
,
3788 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
3791 "set BGP large community list (for deletion)\n"
3792 "Large Community-list number (standard)\n"
3793 "Large Communitly-list number (expanded)\n"
3794 "Large Community-list name\n"
3795 "Delete matching large communities\n")
3797 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3798 "large-comm-list", NULL
);
3801 DEFUN (set_ecommunity_rt
,
3802 set_ecommunity_rt_cmd
,
3803 "set extcommunity rt ASN:nn_or_IP-address:nn...",
3805 "BGP extended community attribute\n"
3806 "Route Target extended community\n"
3807 "VPN extended community\n")
3813 str
= argv_concat(argv
, argc
, idx_asn_nn
);
3814 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3815 "extcommunity rt", str
);
3816 XFREE(MTYPE_TMP
, str
);
3821 DEFUN (no_set_ecommunity_rt
,
3822 no_set_ecommunity_rt_cmd
,
3823 "no set extcommunity rt ASN:nn_or_IP-address:nn...",
3826 "BGP extended community attribute\n"
3827 "Route Target extended community\n"
3828 "VPN extended community\n")
3830 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3831 "extcommunity rt", NULL
);
3835 DEFUN (set_ecommunity_soo
,
3836 set_ecommunity_soo_cmd
,
3837 "set extcommunity soo ASN:nn_or_IP-address:nn...",
3839 "BGP extended community attribute\n"
3840 "Site-of-Origin extended community\n"
3841 "VPN extended community\n")
3847 str
= argv_concat(argv
, argc
, idx_asn_nn
);
3848 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3849 "extcommunity soo", str
);
3850 XFREE(MTYPE_TMP
, str
);
3855 DEFUN (no_set_ecommunity_soo
,
3856 no_set_ecommunity_soo_cmd
,
3857 "no set extcommunity soo ASN:nn_or_IP-address:nn...",
3860 "BGP extended community attribute\n"
3861 "Site-of-Origin extended community\n"
3862 "VPN extended community\n")
3864 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3865 "extcommunity soo", NULL
);
3871 "set origin <egp|igp|incomplete>",
3876 "unknown heritage\n")
3879 if (strncmp(argv
[idx_origin
]->arg
, "igp", 2) == 0)
3880 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3882 if (strncmp(argv
[idx_origin
]->arg
, "egp", 1) == 0)
3883 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3885 if (strncmp(argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3886 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3887 "origin", "incomplete");
3889 vty_out(vty
, "%% Invalid set origin type\n");
3890 return CMD_WARNING_CONFIG_FAILED
;
3894 DEFUN (no_set_origin
,
3896 "no set origin [<egp|igp|incomplete>]",
3902 "unknown heritage\n")
3904 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3909 DEFUN (set_atomic_aggregate
,
3910 set_atomic_aggregate_cmd
,
3911 "set atomic-aggregate",
3913 "BGP atomic aggregate attribute\n" )
3915 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3916 "atomic-aggregate", NULL
);
3919 DEFUN (no_set_atomic_aggregate
,
3920 no_set_atomic_aggregate_cmd
,
3921 "no set atomic-aggregate",
3924 "BGP atomic aggregate attribute\n" )
3926 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3927 "atomic-aggregate", NULL
);
3930 DEFUN (set_aggregator_as
,
3931 set_aggregator_as_cmd
,
3932 "set aggregator as (1-4294967295) A.B.C.D",
3934 "BGP aggregator attribute\n"
3935 "AS number of aggregator\n"
3937 "IP address of aggregator\n")
3942 struct in_addr address
;
3945 ret
= inet_aton(argv
[idx_ipv4
]->arg
, &address
);
3947 vty_out(vty
, "Aggregator IP address is invalid\n");
3948 return CMD_WARNING_CONFIG_FAILED
;
3951 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3952 strlen(argv
[idx_number
]->arg
)
3953 + strlen(argv
[idx_ipv4
]->arg
) + 2);
3955 sprintf(argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
3957 ret
= generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
3958 "aggregator as", argstr
);
3960 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3966 DEFUN (no_set_aggregator_as
,
3967 no_set_aggregator_as_cmd
,
3968 "no set aggregator as [(1-4294967295) A.B.C.D]",
3971 "BGP aggregator attribute\n"
3972 "AS number of aggregator\n"
3974 "IP address of aggregator\n")
3979 struct in_addr address
;
3982 if (argc
<= idx_asn
)
3983 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3984 "aggregator as", NULL
);
3986 ret
= inet_aton(argv
[idx_ip
]->arg
, &address
);
3988 vty_out(vty
, "Aggregator IP address is invalid\n");
3989 return CMD_WARNING_CONFIG_FAILED
;
3992 argstr
= XMALLOC(MTYPE_ROUTE_MAP_COMPILED
,
3993 strlen(argv
[idx_asn
]->arg
) + strlen(argv
[idx_ip
]->arg
)
3996 sprintf(argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
3998 ret
= generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
3999 "aggregator as", argstr
);
4001 XFREE(MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4006 DEFUN (match_ipv6_next_hop
,
4007 match_ipv6_next_hop_cmd
,
4008 "match ipv6 next-hop X:X::X:X",
4011 "Match IPv6 next-hop address of route\n"
4012 "IPv6 address of next hop\n")
4015 return bgp_route_match_add(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4016 RMAP_EVENT_MATCH_ADDED
);
4019 DEFUN (no_match_ipv6_next_hop
,
4020 no_match_ipv6_next_hop_cmd
,
4021 "no match ipv6 next-hop X:X::X:X",
4025 "Match IPv6 next-hop address of route\n"
4026 "IPv6 address of next hop\n")
4029 return bgp_route_match_delete(vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4030 RMAP_EVENT_MATCH_DELETED
);
4034 DEFUN (set_ipv6_nexthop_peer
,
4035 set_ipv6_nexthop_peer_cmd
,
4036 "set ipv6 next-hop peer-address",
4039 "Next hop address\n"
4040 "Use peer address (for BGP only)\n")
4042 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4043 "ipv6 next-hop peer-address", NULL
);
4046 DEFUN (no_set_ipv6_nexthop_peer
,
4047 no_set_ipv6_nexthop_peer_cmd
,
4048 "no set ipv6 next-hop peer-address",
4052 "IPv6 next-hop address\n"
4053 "Use peer address (for BGP only)\n")
4055 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4056 "ipv6 next-hop peer-address", NULL
);
4059 DEFUN (set_ipv6_nexthop_prefer_global
,
4060 set_ipv6_nexthop_prefer_global_cmd
,
4061 "set ipv6 next-hop prefer-global",
4064 "IPv6 next-hop address\n"
4065 "Prefer global over link-local if both exist\n")
4067 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4068 "ipv6 next-hop prefer-global", NULL
);
4072 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4073 no_set_ipv6_nexthop_prefer_global_cmd
,
4074 "no set ipv6 next-hop prefer-global",
4078 "IPv6 next-hop address\n"
4079 "Prefer global over link-local if both exist\n")
4081 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4082 "ipv6 next-hop prefer-global", NULL
);
4085 DEFUN (set_ipv6_nexthop_global
,
4086 set_ipv6_nexthop_global_cmd
,
4087 "set ipv6 next-hop global X:X::X:X",
4090 "IPv6 next-hop address\n"
4091 "IPv6 global address\n"
4092 "IPv6 address of next hop\n")
4095 struct in6_addr addr
;
4098 ret
= inet_pton(AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4100 vty_out(vty
, "%% Malformed nexthop address\n");
4101 return CMD_WARNING_CONFIG_FAILED
;
4103 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) || IN6_IS_ADDR_LOOPBACK(&addr
)
4104 || IN6_IS_ADDR_MULTICAST(&addr
) || IN6_IS_ADDR_LINKLOCAL(&addr
)) {
4105 vty_out(vty
, "%% Invalid global nexthop address\n");
4106 return CMD_WARNING_CONFIG_FAILED
;
4109 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4110 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4114 DEFUN (no_set_ipv6_nexthop_global
,
4115 no_set_ipv6_nexthop_global_cmd
,
4116 "no set ipv6 next-hop global X:X::X:X",
4120 "IPv6 next-hop address\n"
4121 "IPv6 global address\n"
4122 "IPv6 address of next hop\n")
4125 if (argc
<= idx_ipv6
)
4126 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4127 "ipv6 next-hop global", NULL
);
4128 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4129 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4132 #ifdef KEEP_OLD_VPN_COMMANDS
4133 DEFUN (set_vpn_nexthop
,
4134 set_vpn_nexthop_cmd
,
4135 "set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4137 "VPNv4 information\n"
4138 "VPN next-hop address\n"
4139 "IP address of next hop\n"
4140 "VPNv6 information\n"
4141 "VPN next-hop address\n"
4142 "IPv6 address of next hop\n")
4148 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4150 return generic_set_add(
4151 vty
, VTY_GET_CONTEXT(route_map_index
),
4152 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4154 return generic_set_add(
4155 vty
, VTY_GET_CONTEXT(route_map_index
),
4156 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4161 DEFUN (no_set_vpn_nexthop
,
4162 no_set_vpn_nexthop_cmd
,
4163 "no set <vpnv4 next-hop A.B.C.D|vpnv6 next-hop X:X::X:X>",
4166 "VPNv4 information\n"
4167 "VPN next-hop address\n"
4168 "IP address of next hop\n"
4169 "VPNv6 information\n"
4170 "VPN next-hop address\n"
4171 "IPv6 address of next hop\n")
4181 arg
= argv
[idx_ip
]->arg
;
4182 if (argv_find_and_parse_vpnvx(argv
, argc
, &idx
, &afi
)) {
4184 return generic_set_delete(
4185 vty
, VTY_GET_CONTEXT(route_map_index
),
4186 "ipv4 vpn next-hop", arg
);
4188 return generic_set_delete(
4189 vty
, VTY_GET_CONTEXT(route_map_index
),
4190 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4194 #endif /* KEEP_OLD_VPN_COMMANDS */
4196 DEFUN (set_ipx_vpn_nexthop
,
4197 set_ipx_vpn_nexthop_cmd
,
4198 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4200 "IPv4 information\n"
4201 "IPv6 information\n"
4203 "VPN next-hop address\n"
4204 "IP address of next hop\n"
4205 "IPv6 address of next hop\n")
4211 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4213 return generic_set_add(
4214 vty
, VTY_GET_CONTEXT(route_map_index
),
4215 "ipv4 vpn next-hop", argv
[idx_ip
]->arg
);
4217 return generic_set_add(
4218 vty
, VTY_GET_CONTEXT(route_map_index
),
4219 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4224 DEFUN (no_set_ipx_vpn_nexthop
,
4225 no_set_ipx_vpn_nexthop_cmd
,
4226 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4229 "IPv4 information\n"
4230 "IPv6 information\n"
4232 "VPN next-hop address\n"
4233 "IP address of next hop\n"
4234 "IPv6 address of next hop\n")
4244 arg
= argv
[idx_ip
]->arg
;
4245 if (argv_find_and_parse_afi(argv
, argc
, &idx
, &afi
)) {
4247 return generic_set_delete(
4248 vty
, VTY_GET_CONTEXT(route_map_index
),
4249 "ipv4 vpn next-hop", arg
);
4251 return generic_set_delete(
4252 vty
, VTY_GET_CONTEXT(route_map_index
),
4253 "ipv6 vpn next-hop", arg
);
4258 DEFUN (set_originator_id
,
4259 set_originator_id_cmd
,
4260 "set originator-id A.B.C.D",
4262 "BGP originator ID attribute\n"
4263 "IP address of originator\n")
4266 return generic_set_add(vty
, VTY_GET_CONTEXT(route_map_index
),
4267 "originator-id", argv
[idx_ipv4
]->arg
);
4271 DEFUN (no_set_originator_id
,
4272 no_set_originator_id_cmd
,
4273 "no set originator-id [A.B.C.D]",
4276 "BGP originator ID attribute\n"
4277 "IP address of originator\n")
4281 argv_find(argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4283 return generic_set_delete(vty
, VTY_GET_CONTEXT(route_map_index
),
4284 "originator-id", arg
);
4288 /* Initialization of route map. */
4289 void bgp_route_map_init(void)
4293 route_map_add_hook(bgp_route_map_add
);
4294 route_map_delete_hook(bgp_route_map_delete
);
4295 route_map_event_hook(bgp_route_map_event
);
4297 route_map_match_interface_hook(generic_match_add
);
4298 route_map_no_match_interface_hook(generic_match_delete
);
4300 route_map_match_ip_address_hook(generic_match_add
);
4301 route_map_no_match_ip_address_hook(generic_match_delete
);
4303 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
4304 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
4306 route_map_match_ip_next_hop_hook(generic_match_add
);
4307 route_map_no_match_ip_next_hop_hook(generic_match_delete
);
4309 route_map_match_ip_next_hop_prefix_list_hook(generic_match_add
);
4310 route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete
);
4312 route_map_match_ipv6_address_hook(generic_match_add
);
4313 route_map_no_match_ipv6_address_hook(generic_match_delete
);
4315 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
4316 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
4318 route_map_match_metric_hook(generic_match_add
);
4319 route_map_no_match_metric_hook(generic_match_delete
);
4321 route_map_match_tag_hook(generic_match_add
);
4322 route_map_no_match_tag_hook(generic_match_delete
);
4324 route_map_set_ip_nexthop_hook(generic_set_add
);
4325 route_map_no_set_ip_nexthop_hook(generic_set_delete
);
4327 route_map_set_ipv6_nexthop_local_hook(generic_set_add
);
4328 route_map_no_set_ipv6_nexthop_local_hook(generic_set_delete
);
4330 route_map_set_metric_hook(generic_set_add
);
4331 route_map_no_set_metric_hook(generic_set_delete
);
4333 route_map_set_tag_hook(generic_set_add
);
4334 route_map_no_set_tag_hook(generic_set_delete
);
4336 route_map_install_match(&route_match_peer_cmd
);
4337 route_map_install_match(&route_match_local_pref_cmd
);
4338 route_map_install_match(&route_match_ip_address_cmd
);
4339 route_map_install_match(&route_match_ip_next_hop_cmd
);
4340 route_map_install_match(&route_match_ip_route_source_cmd
);
4341 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
4342 route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd
);
4343 route_map_install_match(&route_match_ip_route_source_prefix_list_cmd
);
4344 route_map_install_match(&route_match_aspath_cmd
);
4345 route_map_install_match(&route_match_community_cmd
);
4346 route_map_install_match(&route_match_lcommunity_cmd
);
4347 route_map_install_match(&route_match_ecommunity_cmd
);
4348 route_map_install_match(&route_match_local_pref_cmd
);
4349 route_map_install_match(&route_match_metric_cmd
);
4350 route_map_install_match(&route_match_origin_cmd
);
4351 route_map_install_match(&route_match_probability_cmd
);
4352 route_map_install_match(&route_match_interface_cmd
);
4353 route_map_install_match(&route_match_tag_cmd
);
4355 route_map_install_set(&route_set_ip_nexthop_cmd
);
4356 route_map_install_set(&route_set_local_pref_cmd
);
4357 route_map_install_set(&route_set_weight_cmd
);
4358 route_map_install_set(&route_set_label_index_cmd
);
4359 route_map_install_set(&route_set_metric_cmd
);
4360 route_map_install_set(&route_set_aspath_prepend_cmd
);
4361 route_map_install_set(&route_set_aspath_exclude_cmd
);
4362 route_map_install_set(&route_set_origin_cmd
);
4363 route_map_install_set(&route_set_atomic_aggregate_cmd
);
4364 route_map_install_set(&route_set_aggregator_as_cmd
);
4365 route_map_install_set(&route_set_community_cmd
);
4366 route_map_install_set(&route_set_community_delete_cmd
);
4367 route_map_install_set(&route_set_lcommunity_cmd
);
4368 route_map_install_set(&route_set_lcommunity_delete_cmd
);
4369 route_map_install_set(&route_set_vpnv4_nexthop_cmd
);
4370 route_map_install_set(&route_set_vpnv6_nexthop_cmd
);
4371 route_map_install_set(&route_set_originator_id_cmd
);
4372 route_map_install_set(&route_set_ecommunity_rt_cmd
);
4373 route_map_install_set(&route_set_ecommunity_soo_cmd
);
4374 route_map_install_set(&route_set_tag_cmd
);
4375 route_map_install_set(&route_set_label_index_cmd
);
4377 install_element(RMAP_NODE
, &match_peer_cmd
);
4378 install_element(RMAP_NODE
, &match_peer_local_cmd
);
4379 install_element(RMAP_NODE
, &no_match_peer_cmd
);
4380 install_element(RMAP_NODE
, &match_ip_route_source_cmd
);
4381 install_element(RMAP_NODE
, &no_match_ip_route_source_cmd
);
4382 install_element(RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
4383 install_element(RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
4385 install_element(RMAP_NODE
, &match_aspath_cmd
);
4386 install_element(RMAP_NODE
, &no_match_aspath_cmd
);
4387 install_element(RMAP_NODE
, &match_local_pref_cmd
);
4388 install_element(RMAP_NODE
, &no_match_local_pref_cmd
);
4389 install_element(RMAP_NODE
, &match_community_cmd
);
4390 install_element(RMAP_NODE
, &no_match_community_cmd
);
4391 install_element(RMAP_NODE
, &match_lcommunity_cmd
);
4392 install_element(RMAP_NODE
, &no_match_lcommunity_cmd
);
4393 install_element(RMAP_NODE
, &match_ecommunity_cmd
);
4394 install_element(RMAP_NODE
, &no_match_ecommunity_cmd
);
4395 install_element(RMAP_NODE
, &match_origin_cmd
);
4396 install_element(RMAP_NODE
, &no_match_origin_cmd
);
4397 install_element(RMAP_NODE
, &match_probability_cmd
);
4398 install_element(RMAP_NODE
, &no_match_probability_cmd
);
4400 install_element(RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
4401 install_element(RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
4402 install_element(RMAP_NODE
, &set_local_pref_cmd
);
4403 install_element(RMAP_NODE
, &no_set_local_pref_cmd
);
4404 install_element(RMAP_NODE
, &set_weight_cmd
);
4405 install_element(RMAP_NODE
, &set_label_index_cmd
);
4406 install_element(RMAP_NODE
, &no_set_weight_cmd
);
4407 install_element(RMAP_NODE
, &no_set_label_index_cmd
);
4408 install_element(RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
4409 install_element(RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
4410 install_element(RMAP_NODE
, &set_aspath_exclude_cmd
);
4411 install_element(RMAP_NODE
, &no_set_aspath_prepend_cmd
);
4412 install_element(RMAP_NODE
, &no_set_aspath_exclude_cmd
);
4413 install_element(RMAP_NODE
, &set_origin_cmd
);
4414 install_element(RMAP_NODE
, &no_set_origin_cmd
);
4415 install_element(RMAP_NODE
, &set_atomic_aggregate_cmd
);
4416 install_element(RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
4417 install_element(RMAP_NODE
, &set_aggregator_as_cmd
);
4418 install_element(RMAP_NODE
, &no_set_aggregator_as_cmd
);
4419 install_element(RMAP_NODE
, &set_community_cmd
);
4420 install_element(RMAP_NODE
, &set_community_none_cmd
);
4421 install_element(RMAP_NODE
, &no_set_community_cmd
);
4422 install_element(RMAP_NODE
, &set_community_delete_cmd
);
4423 install_element(RMAP_NODE
, &no_set_community_delete_cmd
);
4424 install_element(RMAP_NODE
, &set_lcommunity_cmd
);
4425 install_element(RMAP_NODE
, &set_lcommunity_none_cmd
);
4426 install_element(RMAP_NODE
, &no_set_lcommunity_cmd
);
4427 install_element(RMAP_NODE
, &no_set_lcommunity1_cmd
);
4428 install_element(RMAP_NODE
, &set_lcommunity_delete_cmd
);
4429 install_element(RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
4430 install_element(RMAP_NODE
, &set_ecommunity_rt_cmd
);
4431 install_element(RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
4432 install_element(RMAP_NODE
, &set_ecommunity_soo_cmd
);
4433 install_element(RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
4434 #ifdef KEEP_OLD_VPN_COMMANDS
4435 install_element(RMAP_NODE
, &set_vpn_nexthop_cmd
);
4436 install_element(RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
4437 #endif /* KEEP_OLD_VPN_COMMANDS */
4438 install_element(RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
4439 install_element(RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
4440 install_element(RMAP_NODE
, &set_originator_id_cmd
);
4441 install_element(RMAP_NODE
, &no_set_originator_id_cmd
);
4443 route_map_install_match(&route_match_ipv6_address_cmd
);
4444 route_map_install_match(&route_match_ipv6_next_hop_cmd
);
4445 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
4446 route_map_install_set(&route_set_ipv6_nexthop_global_cmd
);
4447 route_map_install_set(&route_set_ipv6_nexthop_prefer_global_cmd
);
4448 route_map_install_set(&route_set_ipv6_nexthop_local_cmd
);
4449 route_map_install_set(&route_set_ipv6_nexthop_peer_cmd
);
4451 install_element(RMAP_NODE
, &match_ipv6_next_hop_cmd
);
4452 install_element(RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
4453 install_element(RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
4454 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
4455 install_element(RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
4456 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
4457 install_element(RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
4458 install_element(RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
4461 void bgp_route_map_terminate(void)
4463 /* ToDo: Cleanup all the used memory */
4465 route_map_add_hook(NULL
);
4466 route_map_delete_hook(NULL
);
4467 route_map_event_hook(NULL
);