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
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
32 #ifdef HAVE_LIBPCREPOSIX
33 # include <pcreposix.h>
36 #endif /* HAVE_LIBPCREPOSIX */
38 #include "sockunion.h"
42 #include "bgpd/bgpd.h"
43 #include "bgpd/bgp_table.h"
44 #include "bgpd/bgp_attr.h"
45 #include "bgpd/bgp_aspath.h"
46 #include "bgpd/bgp_packet.h"
47 #include "bgpd/bgp_route.h"
48 #include "bgpd/bgp_zebra.h"
49 #include "bgpd/bgp_regex.h"
50 #include "bgpd/bgp_community.h"
51 #include "bgpd/bgp_clist.h"
52 #include "bgpd/bgp_filter.h"
53 #include "bgpd/bgp_mplsvpn.h"
54 #include "bgpd/bgp_ecommunity.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)
89 default : (This will not be implemented by bgpd)
90 interface : (This will not be implemented by bgpd)
91 ip default : (This will not be implemented by bgpd)
93 ip precedence : (This will not be implemented by bgpd)
94 ip tos : (This will not be implemented by bgpd)
95 level : (This will not be implemented by bgpd)
96 local-preference : Done
105 set ipv6 next-hop global: Done
106 set ipv6 next-hop prefer-global: Done
107 set ipv6 next-hop local : Done
108 set as-path exclude : Done
112 /* generic value manipulation to be shared in multiple rules */
114 #define RMAP_VALUE_SET 0
115 #define RMAP_VALUE_ADD 1
116 #define RMAP_VALUE_SUB 2
126 route_value_match (struct rmap_value
*rv
, u_int32_t value
)
128 if (rv
->variable
== 0 && value
== rv
->value
)
135 route_value_adjust (struct rmap_value
*rv
, u_int32_t current
, struct peer
*peer
)
139 switch (rv
->variable
)
152 if (current
> UINT32_MAX
-value
)
154 return current
+ value
;
156 if (current
<= value
)
158 return current
- value
;
165 route_value_compile (const char *arg
)
167 u_int8_t action
= RMAP_VALUE_SET
, var
= 0;
168 unsigned long larg
= 0;
170 struct rmap_value
*rv
;
174 action
= RMAP_VALUE_ADD
;
177 else if (arg
[0] == '-')
179 action
= RMAP_VALUE_SUB
;
186 larg
= strtoul (arg
, &endptr
, 10);
187 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
192 if (strcmp(arg
, "rtt") == 0)
198 rv
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
209 route_value_free (void *rule
)
211 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
214 /* generic as path object to be shared in multiple rules */
217 route_aspath_compile (const char *arg
)
219 struct aspath
*aspath
;
221 aspath
= aspath_str2aspath (arg
);
228 route_aspath_free (void *rule
)
230 struct aspath
*aspath
= rule
;
231 aspath_free (aspath
);
234 /* 'match peer (A.B.C.D|X:X::X:X)' */
236 /* Compares the peer specified in the 'match peer' clause with the peer
237 received in bgp_info->peer. If it is the same, or if the peer structure
238 received is a peer_group containing it, returns RMAP_MATCH. */
239 static route_map_result_t
240 route_match_peer (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
244 union sockunion su_def
= { .sin
= { .sin_family
= AF_INET
,
245 .sin_addr
.s_addr
= INADDR_ANY
} };
246 struct peer_group
*group
;
248 struct listnode
*node
, *nnode
;
250 if (type
== RMAP_BGP
)
253 peer
= ((struct bgp_info
*) object
)->peer
;
255 if ( ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
) &&
256 ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_EXPORT
) )
259 /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
260 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
261 if (sockunion_same (su
, &su_def
))
264 if ( CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
) ||
265 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
) ||
266 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
273 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
275 if (sockunion_same (su
, &peer
->su
))
283 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
285 if (sockunion_same (su
, &peer
->su
))
295 route_match_peer_compile (const char *arg
)
300 su
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (union sockunion
));
302 ret
= str2sockunion (strcmp(arg
, "local") ? arg
: "0.0.0.0", su
);
304 XFREE (MTYPE_ROUTE_MAP_COMPILED
, su
);
311 /* Free route map's compiled `ip address' value. */
313 route_match_peer_free (void *rule
)
315 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
318 /* Route map commands for ip address matching. */
319 struct route_map_rule_cmd route_match_peer_cmd
=
323 route_match_peer_compile
,
324 route_match_peer_free
327 /* `match ip address IP_ACCESS_LIST' */
329 /* Match function should return 1 if match is success else return
331 static route_map_result_t
332 route_match_ip_address (void *rule
, struct prefix
*prefix
,
333 route_map_object_t type
, void *object
)
335 struct access_list
*alist
;
336 /* struct prefix_ipv4 match; */
338 if (type
== RMAP_BGP
)
340 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
344 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
345 RMAP_NOMATCH
: RMAP_MATCH
);
350 /* Route map `ip address' match statement. `arg' should be
353 route_match_ip_address_compile (const char *arg
)
355 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
358 /* Free route map's compiled `ip address' value. */
360 route_match_ip_address_free (void *rule
)
362 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
365 /* Route map commands for ip address matching. */
366 struct route_map_rule_cmd route_match_ip_address_cmd
=
369 route_match_ip_address
,
370 route_match_ip_address_compile
,
371 route_match_ip_address_free
374 /* `match ip next-hop IP_ADDRESS' */
376 /* Match function return 1 if match is success else return zero. */
377 static route_map_result_t
378 route_match_ip_next_hop (void *rule
, struct prefix
*prefix
,
379 route_map_object_t type
, void *object
)
381 struct access_list
*alist
;
382 struct bgp_info
*bgp_info
;
383 struct prefix_ipv4 p
;
385 if (type
== RMAP_BGP
)
389 p
.prefix
= bgp_info
->attr
->nexthop
;
390 p
.prefixlen
= IPV4_MAX_BITLEN
;
392 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
396 return (access_list_apply (alist
, &p
) == FILTER_DENY
?
397 RMAP_NOMATCH
: RMAP_MATCH
);
402 /* Route map `ip next-hop' match statement. `arg' is
405 route_match_ip_next_hop_compile (const char *arg
)
407 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
410 /* Free route map's compiled `ip address' value. */
412 route_match_ip_next_hop_free (void *rule
)
414 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
417 /* Route map commands for ip next-hop matching. */
418 struct route_map_rule_cmd route_match_ip_next_hop_cmd
=
421 route_match_ip_next_hop
,
422 route_match_ip_next_hop_compile
,
423 route_match_ip_next_hop_free
426 /* `match ip route-source ACCESS-LIST' */
428 /* Match function return 1 if match is success else return zero. */
429 static route_map_result_t
430 route_match_ip_route_source (void *rule
, struct prefix
*prefix
,
431 route_map_object_t type
, void *object
)
433 struct access_list
*alist
;
434 struct bgp_info
*bgp_info
;
436 struct prefix_ipv4 p
;
438 if (type
== RMAP_BGP
)
441 peer
= bgp_info
->peer
;
443 if (! peer
|| sockunion_family (&peer
->su
) != AF_INET
)
447 p
.prefix
= peer
->su
.sin
.sin_addr
;
448 p
.prefixlen
= IPV4_MAX_BITLEN
;
450 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
454 return (access_list_apply (alist
, &p
) == FILTER_DENY
?
455 RMAP_NOMATCH
: RMAP_MATCH
);
460 /* Route map `ip route-source' match statement. `arg' is
463 route_match_ip_route_source_compile (const char *arg
)
465 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
468 /* Free route map's compiled `ip address' value. */
470 route_match_ip_route_source_free (void *rule
)
472 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
475 /* Route map commands for ip route-source matching. */
476 struct route_map_rule_cmd route_match_ip_route_source_cmd
=
479 route_match_ip_route_source
,
480 route_match_ip_route_source_compile
,
481 route_match_ip_route_source_free
484 /* `match ip address prefix-list PREFIX_LIST' */
486 static route_map_result_t
487 route_match_ip_address_prefix_list (void *rule
, struct prefix
*prefix
,
488 route_map_object_t type
, void *object
)
490 struct prefix_list
*plist
;
492 if (type
== RMAP_BGP
)
494 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
498 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
499 RMAP_NOMATCH
: RMAP_MATCH
);
505 route_match_ip_address_prefix_list_compile (const char *arg
)
507 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
511 route_match_ip_address_prefix_list_free (void *rule
)
513 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
516 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
=
518 "ip address prefix-list",
519 route_match_ip_address_prefix_list
,
520 route_match_ip_address_prefix_list_compile
,
521 route_match_ip_address_prefix_list_free
524 /* `match ip next-hop prefix-list PREFIX_LIST' */
526 static route_map_result_t
527 route_match_ip_next_hop_prefix_list (void *rule
, struct prefix
*prefix
,
528 route_map_object_t type
, void *object
)
530 struct prefix_list
*plist
;
531 struct bgp_info
*bgp_info
;
532 struct prefix_ipv4 p
;
534 if (type
== RMAP_BGP
)
538 p
.prefix
= bgp_info
->attr
->nexthop
;
539 p
.prefixlen
= IPV4_MAX_BITLEN
;
541 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
545 return (prefix_list_apply (plist
, &p
) == PREFIX_DENY
?
546 RMAP_NOMATCH
: RMAP_MATCH
);
552 route_match_ip_next_hop_prefix_list_compile (const char *arg
)
554 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
558 route_match_ip_next_hop_prefix_list_free (void *rule
)
560 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
563 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
=
565 "ip next-hop prefix-list",
566 route_match_ip_next_hop_prefix_list
,
567 route_match_ip_next_hop_prefix_list_compile
,
568 route_match_ip_next_hop_prefix_list_free
571 /* `match ip route-source prefix-list PREFIX_LIST' */
573 static route_map_result_t
574 route_match_ip_route_source_prefix_list (void *rule
, struct prefix
*prefix
,
575 route_map_object_t type
, void *object
)
577 struct prefix_list
*plist
;
578 struct bgp_info
*bgp_info
;
580 struct prefix_ipv4 p
;
582 if (type
== RMAP_BGP
)
585 peer
= bgp_info
->peer
;
587 if (! peer
|| sockunion_family (&peer
->su
) != AF_INET
)
591 p
.prefix
= peer
->su
.sin
.sin_addr
;
592 p
.prefixlen
= IPV4_MAX_BITLEN
;
594 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
598 return (prefix_list_apply (plist
, &p
) == PREFIX_DENY
?
599 RMAP_NOMATCH
: RMAP_MATCH
);
605 route_match_ip_route_source_prefix_list_compile (const char *arg
)
607 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
611 route_match_ip_route_source_prefix_list_free (void *rule
)
613 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
616 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
=
618 "ip route-source prefix-list",
619 route_match_ip_route_source_prefix_list
,
620 route_match_ip_route_source_prefix_list_compile
,
621 route_match_ip_route_source_prefix_list_free
624 /* `match local-preference LOCAL-PREF' */
626 /* Match function return 1 if match is success else return zero. */
627 static route_map_result_t
628 route_match_local_pref (void *rule
, struct prefix
*prefix
,
629 route_map_object_t type
, void *object
)
631 u_int32_t
*local_pref
;
632 struct bgp_info
*bgp_info
;
634 if (type
== RMAP_BGP
)
639 if (bgp_info
->attr
->local_pref
== *local_pref
)
647 /* Route map `match local-preference' match statement.
648 `arg' is local-pref value */
650 route_match_local_pref_compile (const char *arg
)
652 u_int32_t
*local_pref
;
654 unsigned long tmpval
;
656 /* Locpref value shoud be integer. */
657 if (! all_digit (arg
))
661 tmpval
= strtoul (arg
, &endptr
, 10);
662 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
665 local_pref
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
670 *local_pref
= tmpval
;
674 /* Free route map's compiled `match local-preference' value. */
676 route_match_local_pref_free (void *rule
)
678 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
681 /* Route map commands for metric matching. */
682 struct route_map_rule_cmd route_match_local_pref_cmd
=
685 route_match_local_pref
,
686 route_match_local_pref_compile
,
687 route_match_local_pref_free
690 /* `match metric METRIC' */
692 /* Match function return 1 if match is success else return zero. */
693 static route_map_result_t
694 route_match_metric (void *rule
, struct prefix
*prefix
,
695 route_map_object_t type
, void *object
)
697 struct rmap_value
*rv
;
698 struct bgp_info
*bgp_info
;
700 if (type
== RMAP_BGP
)
704 return route_value_match(rv
, bgp_info
->attr
->med
);
709 /* Route map commands for metric matching. */
710 struct route_map_rule_cmd route_match_metric_cmd
=
718 /* `match as-path ASPATH' */
720 /* Match function for as-path match. I assume given object is */
721 static route_map_result_t
722 route_match_aspath (void *rule
, struct prefix
*prefix
,
723 route_map_object_t type
, void *object
)
726 struct as_list
*as_list
;
727 struct bgp_info
*bgp_info
;
729 if (type
== RMAP_BGP
)
731 as_list
= as_list_lookup ((char *) rule
);
738 return ((as_list_apply (as_list
, bgp_info
->attr
->aspath
) == AS_FILTER_DENY
) ? RMAP_NOMATCH
: RMAP_MATCH
);
743 /* Compile function for as-path match. */
745 route_match_aspath_compile (const char *arg
)
747 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
750 /* Compile function for as-path match. */
752 route_match_aspath_free (void *rule
)
754 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
757 /* Route map commands for aspath matching. */
758 struct route_map_rule_cmd route_match_aspath_cmd
=
762 route_match_aspath_compile
,
763 route_match_aspath_free
766 /* `match community COMMUNIY' */
767 struct rmap_community
773 /* Match function for community match. */
774 static route_map_result_t
775 route_match_community (void *rule
, struct prefix
*prefix
,
776 route_map_object_t type
, void *object
)
778 struct community_list
*list
;
779 struct bgp_info
*bgp_info
;
780 struct rmap_community
*rcom
;
782 if (type
== RMAP_BGP
)
787 list
= community_list_lookup (bgp_clist
, rcom
->name
, COMMUNITY_LIST_MASTER
);
793 if (community_list_exact_match (bgp_info
->attr
->community
, list
))
798 if (community_list_match (bgp_info
->attr
->community
, list
))
805 /* Compile function for community match. */
807 route_match_community_compile (const char *arg
)
809 struct rmap_community
*rcom
;
813 rcom
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_community
));
815 p
= strchr (arg
, ' ');
819 rcom
->name
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
820 memcpy (rcom
->name
, arg
, len
);
825 rcom
->name
= XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
831 /* Compile function for community match. */
833 route_match_community_free (void *rule
)
835 struct rmap_community
*rcom
= rule
;
837 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
838 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
);
841 /* Route map commands for community matching. */
842 struct route_map_rule_cmd route_match_community_cmd
=
845 route_match_community
,
846 route_match_community_compile
,
847 route_match_community_free
850 /* Match function for extcommunity match. */
851 static route_map_result_t
852 route_match_ecommunity (void *rule
, struct prefix
*prefix
,
853 route_map_object_t type
, void *object
)
855 struct community_list
*list
;
856 struct bgp_info
*bgp_info
;
858 if (type
== RMAP_BGP
)
862 if (!bgp_info
->attr
->extra
)
865 list
= community_list_lookup (bgp_clist
, (char *) rule
,
866 EXTCOMMUNITY_LIST_MASTER
);
870 if (ecommunity_list_match (bgp_info
->attr
->extra
->ecommunity
, list
))
876 /* Compile function for extcommunity match. */
878 route_match_ecommunity_compile (const char *arg
)
880 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
883 /* Compile function for extcommunity match. */
885 route_match_ecommunity_free (void *rule
)
887 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
890 /* Route map commands for community matching. */
891 struct route_map_rule_cmd route_match_ecommunity_cmd
=
894 route_match_ecommunity
,
895 route_match_ecommunity_compile
,
896 route_match_ecommunity_free
899 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
900 and `address-family vpnv4'. */
903 static route_map_result_t
904 route_match_origin (void *rule
, struct prefix
*prefix
,
905 route_map_object_t type
, void *object
)
908 struct bgp_info
*bgp_info
;
910 if (type
== RMAP_BGP
)
915 if (bgp_info
->attr
->origin
== *origin
)
923 route_match_origin_compile (const char *arg
)
927 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
929 if (strcmp (arg
, "igp") == 0)
931 else if (strcmp (arg
, "egp") == 0)
939 /* Free route map's compiled `ip address' value. */
941 route_match_origin_free (void *rule
)
943 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
946 /* Route map commands for origin matching. */
947 struct route_map_rule_cmd route_match_origin_cmd
=
951 route_match_origin_compile
,
952 route_match_origin_free
955 /* match probability { */
957 static route_map_result_t
958 route_match_probability (void *rule
, struct prefix
*prefix
,
959 route_map_object_t type
, void *object
)
963 switch (*(long *) rule
)
966 case RAND_MAX
: return RMAP_MATCH
;
968 if (r
< *(long *) rule
)
978 route_match_probability_compile (const char *arg
)
984 lobule
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (long));
988 case 0: *lobule
= 0; break;
989 case 100: *lobule
= RAND_MAX
; break;
990 default: *lobule
= RAND_MAX
/ 100 * perc
;
997 route_match_probability_free (void *rule
)
999 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1002 struct route_map_rule_cmd route_match_probability_cmd
=
1005 route_match_probability
,
1006 route_match_probability_compile
,
1007 route_match_probability_free
1010 /* `match interface IFNAME' */
1011 /* Match function should return 1 if match is success else return
1013 static route_map_result_t
1014 route_match_interface (void *rule
, struct prefix
*prefix
,
1015 route_map_object_t type
, void *object
)
1017 struct interface
*ifp
;
1018 struct bgp_info
*info
;
1020 if (type
== RMAP_BGP
)
1024 if (!info
|| !info
->attr
)
1025 return RMAP_NOMATCH
;
1027 ifp
= if_lookup_by_name_all_vrf ((char *)rule
);
1029 if (ifp
== NULL
|| ifp
->ifindex
!= info
->attr
->nh_ifindex
)
1030 return RMAP_NOMATCH
;
1034 return RMAP_NOMATCH
;
1037 /* Route map `interface' match statement. `arg' should be
1040 route_match_interface_compile (const char *arg
)
1042 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1045 /* Free route map's compiled `interface' value. */
1047 route_match_interface_free (void *rule
)
1049 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1052 /* Route map commands for ip address matching. */
1053 struct route_map_rule_cmd route_match_interface_cmd
=
1056 route_match_interface
,
1057 route_match_interface_compile
,
1058 route_match_interface_free
1063 /* `set ip next-hop IP_ADDRESS' */
1065 /* Match function return 1 if match is success else return zero. */
1066 static route_map_result_t
1067 route_match_tag (void *rule
, struct prefix
*prefix
,
1068 route_map_object_t type
, void *object
)
1071 struct bgp_info
*bgp_info
;
1073 if (type
== RMAP_BGP
)
1078 if (!bgp_info
->attr
->extra
)
1079 return RMAP_NOMATCH
;
1081 return ((bgp_info
->attr
->extra
->tag
== *tag
)? RMAP_MATCH
: RMAP_NOMATCH
);
1084 return RMAP_NOMATCH
;
1088 /* Route map commands for tag matching. */
1089 static struct route_map_rule_cmd route_match_tag_cmd
=
1093 route_map_rule_tag_compile
,
1094 route_map_rule_tag_free
,
1098 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1099 struct rmap_ip_nexthop_set
1101 struct in_addr
*address
;
1106 static route_map_result_t
1107 route_set_ip_nexthop (void *rule
, struct prefix
*prefix
,
1108 route_map_object_t type
, void *object
)
1110 struct rmap_ip_nexthop_set
*rins
= rule
;
1111 struct bgp_info
*bgp_info
;
1114 if (type
== RMAP_BGP
)
1117 peer
= bgp_info
->peer
;
1119 if (rins
->unchanged
)
1121 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1122 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1124 else if (rins
->peer_address
)
1126 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
1127 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1129 && sockunion_family (peer
->su_remote
) == AF_INET
)
1131 bgp_info
->attr
->nexthop
.s_addr
= sockunion2ip (peer
->su_remote
);
1132 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
1134 else if (CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
))
1136 /* The next hop value will be set as part of packet rewrite.
1137 * Set the flags here to indicate that rewrite needs to be done.
1138 * Also, clear the value.
1140 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1141 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1142 bgp_info
->attr
->nexthop
.s_addr
= 0;
1147 /* Set next hop value. */
1148 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
1149 bgp_info
->attr
->nexthop
= *rins
->address
;
1150 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1151 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1158 /* Route map `ip nexthop' compile function. Given string is converted
1159 to struct in_addr structure. */
1161 route_set_ip_nexthop_compile (const char *arg
)
1163 struct rmap_ip_nexthop_set
*rins
;
1164 struct in_addr
*address
= NULL
;
1165 int peer_address
= 0;
1169 if (strcmp (arg
, "peer-address") == 0)
1171 else if (strcmp (arg
, "unchanged") == 0)
1175 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
1176 ret
= inet_aton (arg
, address
);
1180 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1185 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_ip_nexthop_set
));
1187 rins
->address
= address
;
1188 rins
->peer_address
= peer_address
;
1189 rins
->unchanged
= unchanged
;
1194 /* Free route map's compiled `ip nexthop' value. */
1196 route_set_ip_nexthop_free (void *rule
)
1198 struct rmap_ip_nexthop_set
*rins
= rule
;
1201 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1203 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
);
1206 /* Route map commands for ip nexthop set. */
1207 struct route_map_rule_cmd route_set_ip_nexthop_cmd
=
1210 route_set_ip_nexthop
,
1211 route_set_ip_nexthop_compile
,
1212 route_set_ip_nexthop_free
1215 /* `set local-preference LOCAL_PREF' */
1217 /* Set local preference. */
1218 static route_map_result_t
1219 route_set_local_pref (void *rule
, struct prefix
*prefix
,
1220 route_map_object_t type
, void *object
)
1222 struct rmap_value
*rv
;
1223 struct bgp_info
*bgp_info
;
1224 u_int32_t locpref
= 0;
1226 if (type
== RMAP_BGP
)
1228 /* Fetch routemap's rule information. */
1232 /* Set local preference value. */
1233 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
1234 locpref
= bgp_info
->attr
->local_pref
;
1236 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
);
1237 bgp_info
->attr
->local_pref
= route_value_adjust(rv
, locpref
, bgp_info
->peer
);
1243 /* Set local preference rule structure. */
1244 struct route_map_rule_cmd route_set_local_pref_cmd
=
1247 route_set_local_pref
,
1248 route_value_compile
,
1252 /* `set weight WEIGHT' */
1255 static route_map_result_t
1256 route_set_weight (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
1259 struct rmap_value
*rv
;
1260 struct bgp_info
*bgp_info
;
1263 if (type
== RMAP_BGP
)
1265 /* Fetch routemap's rule information. */
1269 /* Set weight value. */
1270 weight
= route_value_adjust(rv
, 0, bgp_info
->peer
);
1272 (bgp_attr_extra_get (bgp_info
->attr
))->weight
= weight
;
1273 else if (bgp_info
->attr
->extra
)
1274 bgp_info
->attr
->extra
->weight
= 0;
1280 /* Set local preference rule structure. */
1281 struct route_map_rule_cmd route_set_weight_cmd
=
1285 route_value_compile
,
1289 /* `set metric METRIC' */
1291 /* Set metric to attribute. */
1292 static route_map_result_t
1293 route_set_metric (void *rule
, struct prefix
*prefix
,
1294 route_map_object_t type
, void *object
)
1296 struct rmap_value
*rv
;
1297 struct bgp_info
*bgp_info
;
1300 if (type
== RMAP_BGP
)
1302 /* Fetch routemap's rule information. */
1306 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
))
1307 med
= bgp_info
->attr
->med
;
1309 bgp_info
->attr
->med
= route_value_adjust(rv
, med
, bgp_info
->peer
);
1310 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
);
1315 /* Set metric rule structure. */
1316 struct route_map_rule_cmd route_set_metric_cmd
=
1320 route_value_compile
,
1324 /* `set as-path prepend ASPATH' */
1326 /* For AS path prepend mechanism. */
1327 static route_map_result_t
1328 route_set_aspath_prepend (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1330 struct aspath
*aspath
;
1332 struct bgp_info
*binfo
;
1334 if (type
== RMAP_BGP
)
1338 if (binfo
->attr
->aspath
->refcnt
)
1339 new = aspath_dup (binfo
->attr
->aspath
);
1341 new = binfo
->attr
->aspath
;
1343 if ((uintptr_t)rule
> 10)
1346 aspath_prepend (aspath
, new);
1350 as_t as
= aspath_leftmost(new);
1351 if (!as
) as
= binfo
->peer
->as
;
1352 new = aspath_add_seq_n (new, as
, (uintptr_t) rule
);
1355 binfo
->attr
->aspath
= new;
1362 route_set_aspath_prepend_compile (const char *arg
)
1366 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
< 10)
1367 return (void*)(uintptr_t)num
;
1369 return route_aspath_compile(arg
);
1373 route_set_aspath_prepend_free (void *rule
)
1375 if ((uintptr_t)rule
> 10)
1376 route_aspath_free(rule
);
1380 /* Set as-path prepend rule structure. */
1381 struct route_map_rule_cmd route_set_aspath_prepend_cmd
=
1384 route_set_aspath_prepend
,
1385 route_set_aspath_prepend_compile
,
1386 route_set_aspath_prepend_free
,
1389 /* `set as-path exclude ASn' */
1391 /* For ASN exclude mechanism.
1392 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1393 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1395 static route_map_result_t
1396 route_set_aspath_exclude (void *rule
, struct prefix
*dummy
, route_map_object_t type
, void *object
)
1398 struct aspath
* new_path
, * exclude_path
;
1399 struct bgp_info
*binfo
;
1401 if (type
== RMAP_BGP
)
1403 exclude_path
= rule
;
1405 if (binfo
->attr
->aspath
->refcnt
)
1406 new_path
= aspath_dup (binfo
->attr
->aspath
);
1408 new_path
= binfo
->attr
->aspath
;
1409 binfo
->attr
->aspath
= aspath_filter_exclude (new_path
, exclude_path
);
1414 /* Set ASn exlude rule structure. */
1415 struct route_map_rule_cmd route_set_aspath_exclude_cmd
=
1418 route_set_aspath_exclude
,
1419 route_aspath_compile
,
1423 /* `set community COMMUNITY' */
1426 struct community
*com
;
1431 /* For community set mechanism. */
1432 static route_map_result_t
1433 route_set_community (void *rule
, struct prefix
*prefix
,
1434 route_map_object_t type
, void *object
)
1436 struct rmap_com_set
*rcs
;
1437 struct bgp_info
*binfo
;
1439 struct community
*new = NULL
;
1440 struct community
*old
;
1441 struct community
*merge
;
1443 if (type
== RMAP_BGP
)
1448 old
= attr
->community
;
1453 attr
->flag
&= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
));
1454 attr
->community
= NULL
;
1455 /* See the longer comment down below. */
1456 if (old
&& old
->refcnt
== 0)
1457 community_free(old
);
1461 /* "additive" case. */
1462 if (rcs
->additive
&& old
)
1464 merge
= community_merge (community_dup (old
), rcs
->com
);
1466 /* HACK: if the old community is not intern'd,
1467 * we should free it here, or all reference to it may be lost.
1468 * Really need to cleanup attribute caching sometime.
1470 if (old
->refcnt
== 0)
1471 community_free (old
);
1472 new = community_uniq_sort (merge
);
1473 community_free (merge
);
1476 new = community_dup (rcs
->com
);
1478 /* will be interned by caller if required */
1479 attr
->community
= new;
1481 attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1487 /* Compile function for set community. */
1489 route_set_community_compile (const char *arg
)
1491 struct rmap_com_set
*rcs
;
1492 struct community
*com
= NULL
;
1497 if (strcmp (arg
, "none") == 0)
1501 sp
= strstr (arg
, "additive");
1505 /* "additive" keyworkd is included. */
1510 com
= community_str2com (arg
);
1519 rcs
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_com_set
));
1521 rcs
->additive
= additive
;
1527 /* Free function for set community. */
1529 route_set_community_free (void *rule
)
1531 struct rmap_com_set
*rcs
= rule
;
1534 community_free (rcs
->com
);
1535 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1538 /* Set community rule structure. */
1539 struct route_map_rule_cmd route_set_community_cmd
=
1542 route_set_community
,
1543 route_set_community_compile
,
1544 route_set_community_free
,
1547 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
1549 /* For community set mechanism. */
1550 static route_map_result_t
1551 route_set_community_delete (void *rule
, struct prefix
*prefix
,
1552 route_map_object_t type
, void *object
)
1554 struct community_list
*list
;
1555 struct community
*merge
;
1556 struct community
*new;
1557 struct community
*old
;
1558 struct bgp_info
*binfo
;
1560 if (type
== RMAP_BGP
)
1566 list
= community_list_lookup (bgp_clist
, rule
, COMMUNITY_LIST_MASTER
);
1567 old
= binfo
->attr
->community
;
1571 merge
= community_list_match_delete (community_dup (old
), list
);
1572 new = community_uniq_sort (merge
);
1573 community_free (merge
);
1575 /* HACK: if the old community is not intern'd,
1576 * we should free it here, or all reference to it may be lost.
1577 * Really need to cleanup attribute caching sometime.
1579 if (old
->refcnt
== 0)
1580 community_free (old
);
1584 binfo
->attr
->community
= NULL
;
1585 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1586 community_free (new);
1590 binfo
->attr
->community
= new;
1591 binfo
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1599 /* Compile function for set community. */
1601 route_set_community_delete_compile (const char *arg
)
1607 p
= strchr (arg
, ' ');
1611 str
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1612 memcpy (str
, arg
, len
);
1620 /* Free function for set community. */
1622 route_set_community_delete_free (void *rule
)
1624 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1627 /* Set community rule structure. */
1628 struct route_map_rule_cmd route_set_community_delete_cmd
=
1631 route_set_community_delete
,
1632 route_set_community_delete_compile
,
1633 route_set_community_delete_free
,
1636 /* `set extcommunity rt COMMUNITY' */
1638 /* For community set mechanism. Used by _rt and _soo. */
1639 static route_map_result_t
1640 route_set_ecommunity (void *rule
, struct prefix
*prefix
,
1641 route_map_object_t type
, void *object
)
1643 struct ecommunity
*ecom
;
1644 struct ecommunity
*new_ecom
;
1645 struct ecommunity
*old_ecom
;
1646 struct bgp_info
*bgp_info
;
1648 if (type
== RMAP_BGP
)
1656 /* We assume additive for Extended Community. */
1657 old_ecom
= (bgp_attr_extra_get (bgp_info
->attr
))->ecommunity
;
1661 new_ecom
= ecommunity_merge (ecommunity_dup (old_ecom
), ecom
);
1663 /* old_ecom->refcnt = 1 => owned elsewhere, e.g. bgp_update_receive()
1664 * ->refcnt = 0 => set by a previous route-map statement */
1665 if (!old_ecom
->refcnt
)
1666 ecommunity_free (&old_ecom
);
1669 new_ecom
= ecommunity_dup (ecom
);
1671 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1672 bgp_info
->attr
->extra
->ecommunity
= new_ecom
;
1674 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES
);
1679 /* Compile function for set community. */
1681 route_set_ecommunity_rt_compile (const char *arg
)
1683 struct ecommunity
*ecom
;
1685 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
1688 return ecommunity_intern (ecom
);
1691 /* Free function for set community. Used by _rt and _soo */
1693 route_set_ecommunity_free (void *rule
)
1695 struct ecommunity
*ecom
= rule
;
1696 ecommunity_unintern (&ecom
);
1699 /* Set community rule structure. */
1700 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
=
1703 route_set_ecommunity
,
1704 route_set_ecommunity_rt_compile
,
1705 route_set_ecommunity_free
,
1708 /* `set extcommunity soo COMMUNITY' */
1710 /* Compile function for set community. */
1712 route_set_ecommunity_soo_compile (const char *arg
)
1714 struct ecommunity
*ecom
;
1716 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
1720 return ecommunity_intern (ecom
);
1723 /* Set community rule structure. */
1724 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
=
1727 route_set_ecommunity
,
1728 route_set_ecommunity_soo_compile
,
1729 route_set_ecommunity_free
,
1732 /* `set origin ORIGIN' */
1734 /* For origin set. */
1735 static route_map_result_t
1736 route_set_origin (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1739 struct bgp_info
*bgp_info
;
1741 if (type
== RMAP_BGP
)
1746 bgp_info
->attr
->origin
= *origin
;
1752 /* Compile function for origin set. */
1754 route_set_origin_compile (const char *arg
)
1758 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
1760 if (strcmp (arg
, "igp") == 0)
1762 else if (strcmp (arg
, "egp") == 0)
1770 /* Compile function for origin set. */
1772 route_set_origin_free (void *rule
)
1774 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1777 /* Set origin rule structure. */
1778 struct route_map_rule_cmd route_set_origin_cmd
=
1782 route_set_origin_compile
,
1783 route_set_origin_free
,
1786 /* `set atomic-aggregate' */
1788 /* For atomic aggregate set. */
1789 static route_map_result_t
1790 route_set_atomic_aggregate (void *rule
, struct prefix
*prefix
,
1791 route_map_object_t type
, void *object
)
1793 struct bgp_info
*bgp_info
;
1795 if (type
== RMAP_BGP
)
1798 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
);
1804 /* Compile function for atomic aggregate. */
1806 route_set_atomic_aggregate_compile (const char *arg
)
1811 /* Compile function for atomic aggregate. */
1813 route_set_atomic_aggregate_free (void *rule
)
1818 /* Set atomic aggregate rule structure. */
1819 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
=
1822 route_set_atomic_aggregate
,
1823 route_set_atomic_aggregate_compile
,
1824 route_set_atomic_aggregate_free
,
1827 /* `set aggregator as AS A.B.C.D' */
1831 struct in_addr address
;
1834 static route_map_result_t
1835 route_set_aggregator_as (void *rule
, struct prefix
*prefix
,
1836 route_map_object_t type
, void *object
)
1838 struct bgp_info
*bgp_info
;
1839 struct aggregator
*aggregator
;
1840 struct attr_extra
*ae
;
1842 if (type
== RMAP_BGP
)
1846 ae
= bgp_attr_extra_get (bgp_info
->attr
);
1848 ae
->aggregator_as
= aggregator
->as
;
1849 ae
->aggregator_addr
= aggregator
->address
;
1850 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR
);
1857 route_set_aggregator_as_compile (const char *arg
)
1859 struct aggregator
*aggregator
;
1863 aggregator
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct aggregator
));
1864 sscanf (arg
, "%s %s", as
, address
);
1866 aggregator
->as
= strtoul (as
, NULL
, 10);
1867 inet_aton (address
, &aggregator
->address
);
1873 route_set_aggregator_as_free (void *rule
)
1875 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1878 struct route_map_rule_cmd route_set_aggregator_as_cmd
=
1881 route_set_aggregator_as
,
1882 route_set_aggregator_as_compile
,
1883 route_set_aggregator_as_free
,
1886 /* Set tag to object. object must be pointer to struct bgp_info */
1887 static route_map_result_t
1888 route_set_tag (void *rule
, struct prefix
*prefix
,
1889 route_map_object_t type
, void *object
)
1892 struct bgp_info
*bgp_info
;
1893 struct attr_extra
*ae
;
1895 if (type
== RMAP_BGP
)
1899 ae
= bgp_attr_extra_get (bgp_info
->attr
);
1909 /* Route map commands for tag set. */
1910 static struct route_map_rule_cmd route_set_tag_cmd
=
1914 route_map_rule_tag_compile
,
1915 route_map_rule_tag_free
,
1920 /* `match ipv6 address IP_ACCESS_LIST' */
1922 static route_map_result_t
1923 route_match_ipv6_address (void *rule
, struct prefix
*prefix
,
1924 route_map_object_t type
, void *object
)
1926 struct access_list
*alist
;
1928 if (type
== RMAP_BGP
)
1930 alist
= access_list_lookup (AFI_IP6
, (char *) rule
);
1932 return RMAP_NOMATCH
;
1934 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
1935 RMAP_NOMATCH
: RMAP_MATCH
);
1937 return RMAP_NOMATCH
;
1941 route_match_ipv6_address_compile (const char *arg
)
1943 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1947 route_match_ipv6_address_free (void *rule
)
1949 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1952 /* Route map commands for ip address matching. */
1953 struct route_map_rule_cmd route_match_ipv6_address_cmd
=
1956 route_match_ipv6_address
,
1957 route_match_ipv6_address_compile
,
1958 route_match_ipv6_address_free
1961 /* `match ipv6 next-hop IP_ADDRESS' */
1963 static route_map_result_t
1964 route_match_ipv6_next_hop (void *rule
, struct prefix
*prefix
,
1965 route_map_object_t type
, void *object
)
1967 struct in6_addr
*addr
= rule
;
1968 struct bgp_info
*bgp_info
;
1970 if (type
== RMAP_BGP
)
1974 if (!bgp_info
->attr
->extra
)
1975 return RMAP_NOMATCH
;
1977 if (IPV6_ADDR_SAME (&bgp_info
->attr
->extra
->mp_nexthop_global
, addr
))
1980 if (bgp_info
->attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
&&
1981 IPV6_ADDR_SAME (&bgp_info
->attr
->extra
->mp_nexthop_local
, rule
))
1984 return RMAP_NOMATCH
;
1987 return RMAP_NOMATCH
;
1991 route_match_ipv6_next_hop_compile (const char *arg
)
1993 struct in6_addr
*address
;
1996 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
1998 ret
= inet_pton (AF_INET6
, arg
, address
);
2001 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2009 route_match_ipv6_next_hop_free (void *rule
)
2011 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2014 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
=
2017 route_match_ipv6_next_hop
,
2018 route_match_ipv6_next_hop_compile
,
2019 route_match_ipv6_next_hop_free
2022 /* `match ipv6 address prefix-list PREFIX_LIST' */
2024 static route_map_result_t
2025 route_match_ipv6_address_prefix_list (void *rule
, struct prefix
*prefix
,
2026 route_map_object_t type
, void *object
)
2028 struct prefix_list
*plist
;
2030 if (type
== RMAP_BGP
)
2032 plist
= prefix_list_lookup (AFI_IP6
, (char *) rule
);
2034 return RMAP_NOMATCH
;
2036 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
2037 RMAP_NOMATCH
: RMAP_MATCH
);
2039 return RMAP_NOMATCH
;
2043 route_match_ipv6_address_prefix_list_compile (const char *arg
)
2045 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
2049 route_match_ipv6_address_prefix_list_free (void *rule
)
2051 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2054 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
=
2056 "ipv6 address prefix-list",
2057 route_match_ipv6_address_prefix_list
,
2058 route_match_ipv6_address_prefix_list_compile
,
2059 route_match_ipv6_address_prefix_list_free
2062 /* `set ipv6 nexthop global IP_ADDRESS' */
2064 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2065 static route_map_result_t
2066 route_set_ipv6_nexthop_global (void *rule
, struct prefix
*prefix
,
2067 route_map_object_t type
, void *object
)
2069 struct in6_addr
*address
;
2070 struct bgp_info
*bgp_info
;
2072 if (type
== RMAP_BGP
)
2074 /* Fetch routemap's rule information. */
2078 /* Set next hop value. */
2079 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
= *address
;
2081 /* Set nexthop length. */
2082 if (bgp_info
->attr
->extra
->mp_nexthop_len
== 0)
2083 bgp_info
->attr
->extra
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2085 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2086 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2092 /* Route map `ip next-hop' compile function. Given string is converted
2093 to struct in_addr structure. */
2095 route_set_ipv6_nexthop_global_compile (const char *arg
)
2098 struct in6_addr
*address
;
2100 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2102 ret
= inet_pton (AF_INET6
, arg
, address
);
2106 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2113 /* Free route map's compiled `ip next-hop' value. */
2115 route_set_ipv6_nexthop_global_free (void *rule
)
2117 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2120 /* Route map commands for ip nexthop set. */
2121 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
=
2123 "ipv6 next-hop global",
2124 route_set_ipv6_nexthop_global
,
2125 route_set_ipv6_nexthop_global_compile
,
2126 route_set_ipv6_nexthop_global_free
2129 /* Set next-hop preference value. */
2130 static route_map_result_t
2131 route_set_ipv6_nexthop_prefer_global (void *rule
, struct prefix
*prefix
,
2132 route_map_object_t type
, void *object
)
2134 struct bgp_info
*bgp_info
;
2137 if (type
== RMAP_BGP
)
2139 /* Fetch routemap's rule information. */
2141 peer
= bgp_info
->peer
;
2143 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
2144 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2146 && sockunion_family (peer
->su_remote
) == AF_INET6
)
2148 /* Set next hop preference to global */
2149 bgp_info
->attr
->extra
->mp_nexthop_prefer_global
= TRUE
;
2150 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2151 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2155 bgp_info
->attr
->extra
->mp_nexthop_prefer_global
= FALSE
;
2156 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2157 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2164 route_set_ipv6_nexthop_prefer_global_compile (const char *arg
)
2168 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (int));
2174 /* Free route map's compiled `ip next-hop' value. */
2176 route_set_ipv6_nexthop_prefer_global_free (void *rule
)
2178 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2181 /* Route map commands for ip nexthop set preferred. */
2182 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
=
2184 "ipv6 next-hop prefer-global",
2185 route_set_ipv6_nexthop_prefer_global
,
2186 route_set_ipv6_nexthop_prefer_global_compile
,
2187 route_set_ipv6_nexthop_prefer_global_free
2190 /* `set ipv6 nexthop local IP_ADDRESS' */
2192 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2193 static route_map_result_t
2194 route_set_ipv6_nexthop_local (void *rule
, struct prefix
*prefix
,
2195 route_map_object_t type
, void *object
)
2197 struct in6_addr
*address
;
2198 struct bgp_info
*bgp_info
;
2200 if (type
== RMAP_BGP
)
2202 /* Fetch routemap's rule information. */
2206 /* Set next hop value. */
2207 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
= *address
;
2209 /* Set nexthop length. */
2210 if (bgp_info
->attr
->extra
->mp_nexthop_len
!= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2211 bgp_info
->attr
->extra
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2213 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2214 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2220 /* Route map `ip nexthop' compile function. Given string is converted
2221 to struct in_addr structure. */
2223 route_set_ipv6_nexthop_local_compile (const char *arg
)
2226 struct in6_addr
*address
;
2228 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2230 ret
= inet_pton (AF_INET6
, arg
, address
);
2234 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2241 /* Free route map's compiled `ip nexthop' value. */
2243 route_set_ipv6_nexthop_local_free (void *rule
)
2245 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2248 /* Route map commands for ip nexthop set. */
2249 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
=
2251 "ipv6 next-hop local",
2252 route_set_ipv6_nexthop_local
,
2253 route_set_ipv6_nexthop_local_compile
,
2254 route_set_ipv6_nexthop_local_free
2257 /* `set ipv6 nexthop peer-address' */
2259 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2260 static route_map_result_t
2261 route_set_ipv6_nexthop_peer (void *rule
, struct prefix
*prefix
,
2262 route_map_object_t type
, void *object
)
2264 struct in6_addr peer_address
;
2265 struct bgp_info
*bgp_info
;
2268 if (type
== RMAP_BGP
)
2270 /* Fetch routemap's rule information. */
2272 peer
= bgp_info
->peer
;
2274 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
2275 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2277 && sockunion_family (peer
->su_remote
) == AF_INET6
)
2279 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2280 /* Set next hop value and length in attribute. */
2281 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
))
2283 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
= peer_address
;
2284 if (bgp_info
->attr
->extra
->mp_nexthop_len
!= 32)
2285 bgp_info
->attr
->extra
->mp_nexthop_len
= 32;
2289 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
= peer_address
;
2290 if (bgp_info
->attr
->extra
->mp_nexthop_len
== 0)
2291 bgp_info
->attr
->extra
->mp_nexthop_len
= 16;
2295 else if (CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
))
2297 /* The next hop value will be set as part of packet rewrite.
2298 * Set the flags here to indicate that rewrite needs to be done.
2299 * Also, clear the value - we clear both global and link-local
2300 * nexthops, whether we send one or both is determined elsewhere.
2302 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2303 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2304 /* clear next hop value. */
2305 memset (&((bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
),
2306 0, sizeof (struct in6_addr
));
2307 memset (&((bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
),
2308 0, sizeof (struct in6_addr
));
2315 /* Route map `ip next-hop' compile function. Given string is converted
2316 to struct in_addr structure. */
2318 route_set_ipv6_nexthop_peer_compile (const char *arg
)
2322 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (int));
2328 /* Free route map's compiled `ip next-hop' value. */
2330 route_set_ipv6_nexthop_peer_free (void *rule
)
2332 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2335 /* Route map commands for ip nexthop set. */
2336 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
=
2338 "ipv6 next-hop peer-address",
2339 route_set_ipv6_nexthop_peer
,
2340 route_set_ipv6_nexthop_peer_compile
,
2341 route_set_ipv6_nexthop_peer_free
2344 #endif /* HAVE_IPV6 */
2346 /* `set vpnv4 nexthop A.B.C.D' */
2348 static route_map_result_t
2349 route_set_vpnv4_nexthop (void *rule
, struct prefix
*prefix
,
2350 route_map_object_t type
, void *object
)
2352 struct in_addr
*address
;
2353 struct bgp_info
*bgp_info
;
2355 if (type
== RMAP_BGP
)
2357 /* Fetch routemap's rule information. */
2361 /* Set next hop value. */
2362 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global_in
= *address
;
2363 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_len
= 4;
2370 route_set_vpnv4_nexthop_compile (const char *arg
)
2373 struct in_addr
*address
;
2375 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
2377 ret
= inet_aton (arg
, address
);
2381 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2389 route_set_vpnv4_nexthop_free (void *rule
)
2391 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2394 /* Route map commands for ip nexthop set. */
2395 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
=
2398 route_set_vpnv4_nexthop
,
2399 route_set_vpnv4_nexthop_compile
,
2400 route_set_vpnv4_nexthop_free
2403 /* `set originator-id' */
2405 /* For origin set. */
2406 static route_map_result_t
2407 route_set_originator_id (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
2409 struct in_addr
*address
;
2410 struct bgp_info
*bgp_info
;
2412 if (type
== RMAP_BGP
)
2417 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
);
2418 (bgp_attr_extra_get (bgp_info
->attr
))->originator_id
= *address
;
2424 /* Compile function for originator-id set. */
2426 route_set_originator_id_compile (const char *arg
)
2429 struct in_addr
*address
;
2431 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
2433 ret
= inet_aton (arg
, address
);
2437 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2444 /* Compile function for originator_id set. */
2446 route_set_originator_id_free (void *rule
)
2448 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2451 /* Set originator-id rule structure. */
2452 struct route_map_rule_cmd route_set_originator_id_cmd
=
2455 route_set_originator_id
,
2456 route_set_originator_id_compile
,
2457 route_set_originator_id_free
,
2460 /* Add bgp route map rule. */
2462 bgp_route_match_add (struct vty
*vty
, struct route_map_index
*index
,
2463 const char *command
, const char *arg
,
2464 route_map_event_t type
)
2468 ret
= route_map_add_match (index
, command
, arg
);
2473 case RMAP_RULE_MISSING
:
2474 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2476 case RMAP_COMPILE_ERROR
:
2477 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2482 if (type
!= RMAP_EVENT_MATCH_ADDED
)
2484 route_map_upd8_dependency (type
, arg
, index
->map
->name
);
2490 /* Delete bgp route map rule. */
2492 bgp_route_match_delete (struct vty
*vty
, struct route_map_index
*index
,
2493 const char *command
, const char *arg
,
2494 route_map_event_t type
)
2497 char *dep_name
= NULL
;
2499 char *rmap_name
= NULL
;
2501 if (type
!= RMAP_EVENT_MATCH_DELETED
)
2503 /* ignore the mundane, the types without any dependency */
2506 if ((tmpstr
= route_map_get_match_arg(index
, command
)) != NULL
)
2507 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
2511 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
2513 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
2516 ret
= route_map_delete_match (index
, command
, dep_name
);
2521 case RMAP_RULE_MISSING
:
2522 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2524 case RMAP_COMPILE_ERROR
:
2525 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2529 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2531 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2535 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
2536 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
2539 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2541 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2547 * This is the workhorse routine for processing in/out routemap
2551 bgp_route_map_process_peer (const char *rmap_name
, struct route_map
*map
,
2552 struct peer
*peer
, int afi
, int safi
,
2557 struct bgp_filter
*filter
;
2559 if (!peer
|| !rmap_name
)
2562 filter
= &peer
->filter
[afi
][safi
];
2564 * in is for non-route-server clients,
2565 * out is for all peers
2567 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
))
2569 if (filter
->map
[RMAP_IN
].name
&&
2570 (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0))
2572 filter
->map
[RMAP_IN
].map
= map
;
2574 if (route_update
&& peer
->status
== Established
)
2576 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
],
2577 PEER_FLAG_SOFT_RECONFIG
))
2579 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2580 zlog_debug("Processing route_map %s update on "
2581 "peer %s (inbound, soft-reconfig)",
2582 rmap_name
, peer
->host
);
2584 bgp_soft_reconfig_in (peer
, afi
, safi
);
2586 else if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
2587 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
2590 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2591 zlog_debug("Processing route_map %s update on "
2592 "peer %s (inbound, route-refresh)",
2593 rmap_name
, peer
->host
);
2594 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
2600 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
))
2604 if (update
&& route_update
&& peer
->status
== Established
)
2606 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
],
2607 PEER_FLAG_SOFT_RECONFIG
))
2609 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2610 zlog_debug("Processing route_map %s update on "
2611 "peer %s (import, soft-reconfig)",
2612 rmap_name
, peer
->host
);
2614 bgp_soft_reconfig_in (peer
, afi
, safi
);
2616 else if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
2617 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
2619 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2620 zlog_debug("Processing route_map %s update on "
2621 "peer %s (import, route-refresh)",
2622 rmap_name
, peer
->host
);
2623 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
2625 /* DD: Else, what else do we do ? Reset peer ? */
2630 * For outbound, unsuppress and default-originate map change (content or
2631 * map created), merely update the "config" here, the actual route
2632 * announcement happens at the group level.
2634 if (filter
->map
[RMAP_OUT
].name
&&
2635 (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
2636 filter
->map
[RMAP_OUT
].map
= map
;
2638 if (filter
->usmap
.name
&&
2639 (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
2640 filter
->usmap
.map
= map
;
2642 if (peer
->default_rmap
[afi
][safi
].name
&&
2643 (strcmp (rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
2644 peer
->default_rmap
[afi
][safi
].map
= map
;
2648 bgp_route_map_update_peer_group(const char *rmap_name
, struct route_map
*map
,
2651 struct peer_group
*group
;
2652 struct listnode
*node
, *nnode
;
2653 struct bgp_filter
*filter
;
2660 /* All the peers have been updated correctly already. This is
2661 * just updating the placeholder data. No real update required.
2663 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
2664 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2665 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2667 filter
= &group
->conf
->filter
[afi
][safi
];
2669 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++)
2671 if ((filter
->map
[direct
].name
) &&
2672 (strcmp(rmap_name
, filter
->map
[direct
].name
) == 0))
2673 filter
->map
[direct
].map
= map
;
2676 if (filter
->usmap
.name
&&
2677 (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
2678 filter
->usmap
.map
= map
;
2683 * Note that if an extreme number (tens of thousands) of route-maps are in use
2684 * and if bgp has an extreme number of peers, network statements, etc then this
2685 * function can consume a lot of cycles. This is due to this function being
2686 * called for each route-map and within this function we walk the list of peers,
2687 * network statements, etc looking to see if they use this route-map.
2690 bgp_route_map_process_update (struct bgp
*bgp
, const char *rmap_name
, int route_update
)
2696 struct bgp_node
*bn
;
2697 struct bgp_static
*bgp_static
;
2698 struct listnode
*node
, *nnode
;
2699 struct route_map
*map
;
2700 char buf
[INET6_ADDRSTRLEN
];
2702 map
= route_map_lookup_by_name (rmap_name
);
2704 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
2707 /* Ignore dummy peer-group structure */
2708 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
2711 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2712 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2714 /* Ignore inactive AFI/SAFI */
2715 if (! peer
->afc
[afi
][safi
])
2718 /* process in/out/import/export/default-orig route-maps */
2719 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
, safi
, route_update
);
2723 /* for outbound/default-orig route-maps, process for groups */
2724 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
2727 /* update peer-group config (template) */
2728 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
2730 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2731 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2733 /* For table route-map updates. */
2734 if (bgp
->table_map
[afi
][safi
].name
&&
2735 (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
) == 0))
2737 bgp
->table_map
[afi
][safi
].map
= map
;
2739 if (BGP_DEBUG (zebra
, ZEBRA
))
2740 zlog_debug("Processing route_map %s update on "
2741 "table map", rmap_name
);
2743 bgp_zebra_announce_table(bgp
, afi
, safi
);
2746 /* For network route-map updates. */
2747 for (bn
= bgp_table_top (bgp
->route
[afi
][safi
]); bn
; bn
= bgp_route_next (bn
))
2748 if ((bgp_static
= bn
->info
) != NULL
)
2750 if (bgp_static
->rmap
.name
&&
2751 (strcmp(rmap_name
, bgp_static
->rmap
.name
) == 0))
2753 bgp_static
->rmap
.map
= map
;
2756 if (!bgp_static
->backdoor
)
2758 if (bgp_debug_zebra(&bn
->p
))
2759 zlog_debug("Processing route_map %s update on "
2760 "static route %s", rmap_name
,
2761 inet_ntop (bn
->p
.family
, &bn
->p
.u
.prefix
,
2762 buf
, INET6_ADDRSTRLEN
));
2763 bgp_static_update (bgp
, &bn
->p
, bgp_static
, afi
, safi
);
2769 /* For redistribute route-map updates. */
2770 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2771 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2773 struct list
*red_list
;
2774 struct listnode
*node
;
2775 struct bgp_redist
*red
;
2777 red_list
= bgp
->redist
[afi
][i
];
2781 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
))
2783 if (red
->rmap
.name
&&
2784 (strcmp(rmap_name
, red
->rmap
.name
) == 0))
2786 red
->rmap
.map
= map
;
2790 if (BGP_DEBUG (zebra
, ZEBRA
))
2791 zlog_debug("Processing route_map %s update on "
2792 "redistributed routes", rmap_name
);
2794 bgp_redistribute_resend (bgp
, afi
, i
, red
->instance
);
2802 bgp_route_map_process_update_cb (char *rmap_name
)
2804 struct listnode
*node
, *nnode
;
2807 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
2808 bgp_route_map_process_update(bgp
, rmap_name
, 1);
2811 zlog_debug("%s: calling vnc_routemap_update", __func__
);
2812 vnc_routemap_update(bgp
, __func__
);
2818 bgp_route_map_update_timer(struct thread
*thread
)
2820 bm
->t_rmap_update
= NULL
;
2822 route_map_walk_update_list(bgp_route_map_process_update_cb
);
2828 bgp_route_map_mark_update (const char *rmap_name
)
2830 if (bm
->t_rmap_update
== NULL
)
2832 struct listnode
*node
, *nnode
;
2835 /* rmap_update_timer of 0 means don't do route updates */
2836 if (bm
->rmap_update_timer
)
2839 thread_add_timer(bm
->master
, bgp_route_map_update_timer
, NULL
,
2840 bm
->rmap_update_timer
);
2842 /* Signal the groups that a route-map update event has started */
2843 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
2844 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
, 1, 1);
2848 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
2849 bgp_route_map_process_update(bgp
, rmap_name
, 0);
2851 zlog_debug("%s: calling vnc_routemap_update", __func__
);
2852 vnc_routemap_update(bgp
, __func__
);
2859 bgp_route_map_add (const char *rmap_name
)
2861 if (route_map_mark_updated(rmap_name
, 0) == 0)
2862 bgp_route_map_mark_update(rmap_name
);
2864 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
2868 bgp_route_map_delete (const char *rmap_name
)
2870 if (route_map_mark_updated(rmap_name
, 1) == 0)
2871 bgp_route_map_mark_update(rmap_name
);
2873 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
2877 bgp_route_map_event (route_map_event_t event
, const char *rmap_name
)
2879 if (route_map_mark_updated(rmap_name
, 0) == 0)
2880 bgp_route_map_mark_update(rmap_name
);
2882 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
2888 "match peer <A.B.C.D|X:X::X:X>",
2890 "Match peer address\n"
2891 "IP address of peer\n"
2892 "IPv6 address of peer\n")
2895 return bgp_route_match_add (vty
, vty
->index
, "peer", argv
[idx_ip
]->arg
,
2896 RMAP_EVENT_MATCH_ADDED
);
2899 DEFUN (match_peer_local
,
2900 match_peer_local_cmd
,
2903 "Match peer address\n"
2904 "Static or Redistributed routes\n")
2906 return bgp_route_match_add (vty
, vty
->index
, "peer", "local",
2907 RMAP_EVENT_MATCH_DELETED
);
2910 DEFUN (no_match_peer
,
2912 "no match peer [<local|A.B.C.D|X:X::X:X>]",
2915 "Match peer address\n"
2916 "Static or Redistributed routes\n"
2917 "IP address of peer\n"
2918 "IPv6 address of peer\n")
2922 if (argc
<= idx_peer
)
2923 return bgp_route_match_delete (vty
, vty
->index
, "peer", NULL
,
2924 RMAP_EVENT_MATCH_DELETED
);
2925 return bgp_route_match_delete (vty
, vty
->index
, "peer", argv
[idx_peer
]->arg
,
2926 RMAP_EVENT_MATCH_DELETED
);
2930 /* match probability */
2931 DEFUN (match_probability
,
2932 match_probability_cmd
,
2933 "match probability (0-100)",
2935 "Match portion of routes defined by percentage value\n"
2936 "Percentage of routes\n")
2939 return bgp_route_match_add (vty
, vty
->index
, "probability", argv
[idx_number
]->arg
,
2940 RMAP_EVENT_MATCH_ADDED
);
2944 DEFUN (no_match_probability
,
2945 no_match_probability_cmd
,
2946 "no match probability [(1-99)]",
2949 "Match portion of routes defined by percentage value\n"
2950 "Percentage of routes\n")
2953 if (argc
<= idx_number
)
2954 return bgp_route_match_delete (vty
, vty
->index
, "probability", NULL
,
2955 RMAP_EVENT_MATCH_DELETED
);
2956 return bgp_route_match_delete (vty
, vty
->index
, "probability", argv
[idx_number
]->arg
,
2957 RMAP_EVENT_MATCH_DELETED
);
2961 DEFUN (match_ip_route_source
,
2962 match_ip_route_source_cmd
,
2963 "match ip route-source <(1-199)|(1300-2699)|WORD>",
2966 "Match advertising source address of route\n"
2967 "IP access-list number\n"
2968 "IP access-list number (expanded range)\n"
2969 "IP standard access-list name\n")
2972 return bgp_route_match_add (vty
, vty
->index
, "ip route-source", argv
[idx_acl
]->arg
,
2973 RMAP_EVENT_FILTER_ADDED
);
2977 DEFUN (no_match_ip_route_source
,
2978 no_match_ip_route_source_cmd
,
2979 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
2983 "Match advertising source address of route\n"
2984 "IP access-list number\n"
2985 "IP access-list number (expanded range)\n"
2986 "IP standard access-list name\n")
2989 if (argc
<= idx_number
)
2990 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source",
2991 NULL
, RMAP_EVENT_FILTER_DELETED
);
2992 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source",
2993 argv
[idx_number
]->arg
, RMAP_EVENT_FILTER_DELETED
);
2997 DEFUN (match_ip_route_source_prefix_list
,
2998 match_ip_route_source_prefix_list_cmd
,
2999 "match ip route-source prefix-list WORD",
3002 "Match advertising source address of route\n"
3003 "Match entries of prefix-lists\n"
3004 "IP prefix-list name\n")
3007 return bgp_route_match_add (vty
, vty
->index
, "ip route-source prefix-list",
3008 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3012 DEFUN (no_match_ip_route_source_prefix_list
,
3013 no_match_ip_route_source_prefix_list_cmd
,
3014 "no match ip route-source prefix-list [WORD]",
3018 "Match advertising source address of route\n"
3019 "Match entries of prefix-lists\n"
3020 "IP prefix-list name\n")
3023 if (argc
<= idx_word
)
3024 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source prefix-list",
3025 NULL
, RMAP_EVENT_PLIST_DELETED
);
3026 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source prefix-list",
3027 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_DELETED
);
3031 DEFUN (match_local_pref
,
3032 match_local_pref_cmd
,
3033 "match local-preference (0-4294967295)",
3035 "Match local-preference of route\n"
3039 return bgp_route_match_add (vty
, vty
->index
, "local-preference", argv
[idx_number
]->arg
,
3040 RMAP_EVENT_MATCH_ADDED
);
3044 DEFUN (no_match_local_pref
,
3045 no_match_local_pref_cmd
,
3046 "no match local-preference [(0-4294967295)]",
3049 "Match local preference of route\n"
3050 "Local preference value\n")
3052 int idx_localpref
= 3;
3053 if (argc
<= idx_localpref
)
3054 return bgp_route_match_delete (vty
, vty
->index
, "local-preference",
3055 NULL
, RMAP_EVENT_MATCH_DELETED
);
3056 return bgp_route_match_delete (vty
, vty
->index
, "local-preference",
3057 argv
[idx_localpref
]->arg
,
3058 RMAP_EVENT_MATCH_DELETED
);
3062 DEFUN (match_community
,
3063 match_community_cmd
,
3064 "match community <(1-99)|(100-500)|WORD>",
3066 "Match BGP community list\n"
3067 "Community-list number (standard)\n"
3068 "Community-list number (expanded)\n"
3069 "Community-list name\n")
3071 int idx_comm_list
= 2;
3072 return bgp_route_match_add (vty
, vty
->index
, "community", argv
[idx_comm_list
]->arg
,
3073 RMAP_EVENT_CLIST_ADDED
);
3076 DEFUN (match_community_exact
,
3077 match_community_exact_cmd
,
3078 "match community <(1-99)|(100-500)|WORD> exact-match",
3080 "Match BGP community list\n"
3081 "Community-list number (standard)\n"
3082 "Community-list number (expanded)\n"
3083 "Community-list name\n"
3084 "Do exact matching of communities\n")
3086 int idx_comm_list
= 2;
3090 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3091 strlen (argv
[idx_comm_list
]->arg
) + strlen ("exact-match") + 2);
3093 sprintf (argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3095 ret
= bgp_route_match_add (vty
, vty
->index
, "community", argstr
,
3096 RMAP_EVENT_CLIST_ADDED
);
3098 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3103 DEFUN (no_match_community
,
3104 no_match_community_cmd
,
3105 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3108 "Match BGP community list\n"
3109 "Community-list number (standard)\n"
3110 "Community-list number (expanded)\n"
3111 "Community-list name\n"
3112 "Do exact matching of communities\n")
3114 return bgp_route_match_delete (vty
, vty
->index
, "community", NULL
,
3115 RMAP_EVENT_CLIST_DELETED
);
3120 DEFUN (match_ecommunity
,
3121 match_ecommunity_cmd
,
3122 "match extcommunity <(1-99)|(100-500)|WORD>",
3124 "Match BGP/VPN extended community list\n"
3125 "Extended community-list number (standard)\n"
3126 "Extended community-list number (expanded)\n"
3127 "Extended community-list name\n")
3129 int idx_comm_list
= 2;
3130 return bgp_route_match_add (vty
, vty
->index
, "extcommunity", argv
[idx_comm_list
]->arg
,
3131 RMAP_EVENT_ECLIST_ADDED
);
3135 DEFUN (no_match_ecommunity
,
3136 no_match_ecommunity_cmd
,
3137 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3140 "Match BGP/VPN extended community list\n"
3141 "Extended community-list number (standard)\n"
3142 "Extended community-list number (expanded)\n"
3143 "Extended community-list name\n")
3145 return bgp_route_match_delete (vty
, vty
->index
, "extcommunity", NULL
,
3146 RMAP_EVENT_ECLIST_DELETED
);
3150 DEFUN (match_aspath
,
3152 "match as-path WORD",
3154 "Match BGP AS path list\n"
3155 "AS path access-list name\n")
3158 return bgp_route_match_add (vty
, vty
->index
, "as-path", argv
[idx_word
]->arg
,
3159 RMAP_EVENT_ASLIST_ADDED
);
3163 DEFUN (no_match_aspath
,
3164 no_match_aspath_cmd
,
3165 "no match as-path [WORD]",
3168 "Match BGP AS path list\n"
3169 "AS path access-list name\n")
3171 return bgp_route_match_delete (vty
, vty
->index
, "as-path", NULL
,
3172 RMAP_EVENT_ASLIST_DELETED
);
3176 DEFUN (match_origin
,
3178 "match origin <egp|igp|incomplete>",
3183 "unknown heritage\n")
3186 if (strncmp (argv
[idx_origin
]->arg
, "igp", 2) == 0)
3187 return bgp_route_match_add (vty
, vty
->index
, "origin", "igp",
3188 RMAP_EVENT_MATCH_ADDED
);
3189 if (strncmp (argv
[idx_origin
]->arg
, "egp", 1) == 0)
3190 return bgp_route_match_add (vty
, vty
->index
, "origin", "egp",
3191 RMAP_EVENT_MATCH_ADDED
);
3192 if (strncmp (argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3193 return bgp_route_match_add (vty
, vty
->index
, "origin", "incomplete",
3194 RMAP_EVENT_MATCH_ADDED
);
3200 DEFUN (no_match_origin
,
3201 no_match_origin_cmd
,
3202 "no match origin [<egp|igp|incomplete>]",
3208 "unknown heritage\n")
3210 return bgp_route_match_delete (vty
, vty
->index
, "origin", NULL
,
3211 RMAP_EVENT_MATCH_DELETED
);
3214 DEFUN (set_ip_nexthop_peer
,
3215 set_ip_nexthop_peer_cmd
,
3216 "set ip next-hop peer-address",
3219 "Next hop address\n"
3220 "Use peer address (for BGP only)\n")
3222 return generic_set_add (vty
, vty
->index
, "ip next-hop", "peer-address");
3225 DEFUN (set_ip_nexthop_unchanged
,
3226 set_ip_nexthop_unchanged_cmd
,
3227 "set ip next-hop unchanged",
3230 "Next hop address\n"
3231 "Don't modify existing Next hop address\n")
3233 return generic_set_add (vty
, vty
->index
, "ip next-hop", "unchanged");
3237 DEFUN (set_local_pref
,
3239 "set local-preference (0-4294967295)",
3241 "BGP local preference path attribute\n"
3242 "Preference value\n")
3245 return generic_set_add (vty
, vty
->index
, "local-preference", argv
[idx_number
]->arg
);
3249 DEFUN (no_set_local_pref
,
3250 no_set_local_pref_cmd
,
3251 "no set local-preference [(0-4294967295)]",
3254 "BGP local preference path attribute\n"
3255 "Preference value\n")
3257 int idx_localpref
= 3;
3258 if (argc
<= idx_localpref
)
3259 return generic_set_delete (vty
, vty
->index
, "local-preference", NULL
);
3260 return generic_set_delete (vty
, vty
->index
, "local-preference", argv
[idx_localpref
]->arg
);
3266 "set weight (0-4294967295)",
3268 "BGP weight for routing table\n"
3272 return generic_set_add (vty
, vty
->index
, "weight", argv
[idx_number
]->arg
);
3276 DEFUN (no_set_weight
,
3278 "no set weight [(0-4294967295)]",
3281 "BGP weight for routing table\n"
3285 if (argc
<= idx_weight
)
3286 return generic_set_delete (vty
, vty
->index
, "weight", NULL
);
3287 return generic_set_delete (vty
, vty
->index
, "weight", argv
[idx_weight
]->arg
);
3291 DEFUN (set_aspath_prepend_asn
,
3292 set_aspath_prepend_asn_cmd
,
3293 "set as-path prepend (1-4294967295)...",
3295 "Transform BGP AS_PATH attribute\n"
3296 "Prepend to the as-path\n"
3303 str
= argv_concat (argv
, argc
, idx_asn
);
3304 ret
= generic_set_add (vty
, vty
->index
, "as-path prepend", str
);
3305 XFREE (MTYPE_TMP
, str
);
3310 DEFUN (set_aspath_prepend_lastas
,
3311 set_aspath_prepend_lastas_cmd
,
3312 "set as-path prepend last-as (1-10)",
3314 "Transform BGP AS_PATH attribute\n"
3315 "Prepend to the as-path\n"
3316 "Use the peer's AS-number\n"
3317 "Number of times to insert")
3319 return set_aspath_prepend_asn (self
, vty
, argc
, argv
);
3322 DEFUN (no_set_aspath_prepend
,
3323 no_set_aspath_prepend_cmd
,
3324 "no set as-path prepend [(1-4294967295)]",
3327 "Transform BGP AS_PATH attribute\n"
3328 "Prepend to the as-path\n"
3335 str
= argv_concat (argv
, argc
, idx_asn
);
3336 ret
= generic_set_delete (vty
, vty
->index
, "as-path prepend", str
);
3337 XFREE (MTYPE_TMP
, str
);
3342 DEFUN (set_aspath_exclude
,
3343 set_aspath_exclude_cmd
,
3344 "set as-path exclude (1-4294967295)...",
3346 "Transform BGP AS-path attribute\n"
3347 "Exclude from the as-path\n"
3354 str
= argv_concat (argv
, argc
, idx_asn
);
3355 ret
= generic_set_add (vty
, vty
->index
, "as-path exclude", str
);
3356 XFREE (MTYPE_TMP
, str
);
3360 DEFUN (no_set_aspath_exclude
,
3361 no_set_aspath_exclude_cmd
,
3362 "no set as-path exclude (1-4294967295)...",
3365 "Transform BGP AS_PATH attribute\n"
3366 "Exclude from the as-path\n"
3373 str
= argv_concat (argv
, argc
, idx_asn
);
3374 ret
= generic_set_delete (vty
, vty
->index
, "as-path exclude", str
);
3375 XFREE (MTYPE_TMP
, str
);
3380 DEFUN (set_community
,
3382 "set community AA:NN...",
3384 "BGP community attribute\n"
3392 struct community
*com
= NULL
;
3397 b
= buffer_new (1024);
3399 for (i
= idx_aa_nn
; i
< argc
; i
++)
3401 if (strncmp (argv
[i
]->arg
, "additive", strlen (argv
[i
]->arg
)) == 0)
3408 buffer_putc (b
, ' ');
3412 if (strncmp (argv
[i
]->arg
, "internet", strlen (argv
[i
]->arg
)) == 0)
3414 buffer_putstr (b
, "internet");
3417 if (strncmp (argv
[i
]->arg
, "local-AS", strlen (argv
[i
]->arg
)) == 0)
3419 buffer_putstr (b
, "local-AS");
3422 if (strncmp (argv
[i
]->arg
, "no-a", strlen ("no-a")) == 0
3423 && strncmp (argv
[i
]->arg
, "no-advertise", strlen (argv
[i
]->arg
)) == 0)
3425 buffer_putstr (b
, "no-advertise");
3428 if (strncmp (argv
[i
]->arg
, "no-e", strlen ("no-e"))== 0
3429 && strncmp (argv
[i
]->arg
, "no-export", strlen (argv
[i
]->arg
)) == 0)
3431 buffer_putstr (b
, "no-export");
3434 buffer_putstr (b
, argv
[i
]->arg
);
3436 buffer_putc (b
, '\0');
3438 /* Fetch result string then compile it to communities attribute. */
3439 str
= buffer_getstr (b
);
3444 com
= community_str2com (str
);
3445 XFREE (MTYPE_TMP
, str
);
3448 /* Can't compile user input into communities attribute. */
3451 vty_out (vty
, "%% Malformed communities attribute%s", VTY_NEWLINE
);
3455 /* Set communites attribute string. */
3456 str
= community_str (com
);
3460 argstr
= XCALLOC (MTYPE_TMP
, strlen (str
) + strlen (" additive") + 1);
3461 strcpy (argstr
, str
);
3462 strcpy (argstr
+ strlen (str
), " additive");
3463 ret
= generic_set_add (vty
, vty
->index
, "community", argstr
);
3464 XFREE (MTYPE_TMP
, argstr
);
3467 ret
= generic_set_add (vty
, vty
->index
, "community", str
);
3469 community_free (com
);
3474 DEFUN (set_community_none
,
3475 set_community_none_cmd
,
3476 "set community none",
3478 "BGP community attribute\n"
3479 "No community attribute\n")
3481 return generic_set_add (vty
, vty
->index
, "community", "none");
3484 DEFUN (no_set_community
,
3485 no_set_community_cmd
,
3486 "no set community AA:NN...",
3489 "BGP community attribute\n"
3492 return generic_set_delete (vty
, vty
->index
, "community", NULL
);
3497 DEFUN (set_community_delete
,
3498 set_community_delete_cmd
,
3499 "set comm-list <(1-99)|(100-500)|WORD> delete",
3501 "set BGP community list (for deletion)\n"
3502 "Community-list number (standard)\n"
3503 "Community-list number (expanded)\n"
3504 "Community-list name\n"
3505 "Delete matching communities\n")
3507 int idx_comm_list
= 2;
3510 str
= XCALLOC (MTYPE_TMP
, strlen (argv
[idx_comm_list
]->arg
) + strlen (" delete") + 1);
3511 strcpy (str
, argv
[idx_comm_list
]->arg
);
3512 strcpy (str
+ strlen (argv
[idx_comm_list
]->arg
), " delete");
3514 generic_set_add (vty
, vty
->index
, "comm-list", str
);
3516 XFREE (MTYPE_TMP
, str
);
3520 DEFUN (no_set_community_delete
,
3521 no_set_community_delete_cmd
,
3522 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
3525 "set BGP community list (for deletion)\n"
3526 "Community-list number (standard)\n"
3527 "Community-list number (expanded)\n"
3528 "Community-list name\n"
3529 "Delete matching communities\n")
3531 return generic_set_delete (vty
, vty
->index
, "comm-list", NULL
);
3535 DEFUN (set_ecommunity_rt
,
3536 set_ecommunity_rt_cmd
,
3537 "set extcommunity rt ASN:nn_or_IP-address:nn...",
3539 "BGP extended community attribute\n"
3540 "Route Target extended community\n"
3541 "VPN extended community\n")
3547 str
= argv_concat (argv
, argc
, idx_asn_nn
);
3548 ret
= generic_set_add (vty
, vty
->index
, "extcommunity rt", str
);
3549 XFREE (MTYPE_TMP
, str
);
3554 DEFUN (no_set_ecommunity_rt
,
3555 no_set_ecommunity_rt_cmd
,
3556 "no set extcommunity rt ASN:nn_or_IP-address:nn...",
3559 "BGP extended community attribute\n"
3560 "Route Target extended community\n"
3561 "VPN extended community\n")
3563 return generic_set_delete (vty
, vty
->index
, "extcommunity rt", NULL
);
3567 DEFUN (set_ecommunity_soo
,
3568 set_ecommunity_soo_cmd
,
3569 "set extcommunity soo ASN:nn_or_IP-address:nn...",
3571 "BGP extended community attribute\n"
3572 "Site-of-Origin extended community\n"
3573 "VPN extended community\n")
3579 str
= argv_concat (argv
, argc
, idx_asn_nn
);
3580 ret
= generic_set_add (vty
, vty
->index
, "extcommunity soo", str
);
3581 XFREE (MTYPE_TMP
, str
);
3586 DEFUN (no_set_ecommunity_soo
,
3587 no_set_ecommunity_soo_cmd
,
3588 "no set extcommunity soo ASN:nn_or_IP-address:nn...",
3591 "BGP extended community attribute\n"
3592 "Site-of-Origin extended community\n"
3593 "VPN extended community\n")
3595 return generic_set_delete (vty
, vty
->index
, "extcommunity soo", NULL
);
3601 "set origin <egp|igp|incomplete>",
3606 "unknown heritage\n")
3609 if (strncmp (argv
[idx_origin
]->arg
, "igp", 2) == 0)
3610 return generic_set_add (vty
, vty
->index
, "origin", "igp");
3611 if (strncmp (argv
[idx_origin
]->arg
, "egp", 1) == 0)
3612 return generic_set_add (vty
, vty
->index
, "origin", "egp");
3613 if (strncmp (argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3614 return generic_set_add (vty
, vty
->index
, "origin", "incomplete");
3620 DEFUN (no_set_origin
,
3622 "no set origin [<egp|igp|incomplete>]",
3628 "unknown heritage\n")
3630 return generic_set_delete (vty
, vty
->index
, "origin", NULL
);
3634 DEFUN (set_atomic_aggregate
,
3635 set_atomic_aggregate_cmd
,
3636 "set atomic-aggregate",
3638 "BGP atomic aggregate attribute\n" )
3640 return generic_set_add (vty
, vty
->index
, "atomic-aggregate", NULL
);
3643 DEFUN (no_set_atomic_aggregate
,
3644 no_set_atomic_aggregate_cmd
,
3645 "no set atomic-aggregate",
3648 "BGP atomic aggregate attribute\n" )
3650 return generic_set_delete (vty
, vty
->index
, "atomic-aggregate", NULL
);
3653 DEFUN (set_aggregator_as
,
3654 set_aggregator_as_cmd
,
3655 "set aggregator as (1-4294967295) A.B.C.D",
3657 "BGP aggregator attribute\n"
3658 "AS number of aggregator\n"
3660 "IP address of aggregator\n")
3665 struct in_addr address
;
3668 ret
= inet_aton (argv
[idx_ipv4
]->arg
, &address
);
3671 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
3675 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3676 strlen (argv
[idx_number
]->arg
) + strlen (argv
[idx_ipv4
]->arg
) + 2);
3678 sprintf (argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
3680 ret
= generic_set_add (vty
, vty
->index
, "aggregator as", argstr
);
3682 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3688 DEFUN (no_set_aggregator_as
,
3689 no_set_aggregator_as_cmd
,
3690 "no set aggregator as [(1-4294967295) A.B.C.D]",
3693 "BGP aggregator attribute\n"
3694 "AS number of aggregator\n"
3696 "IP address of aggregator\n")
3701 struct in_addr address
;
3704 if (argc
<= idx_asn
)
3705 return generic_set_delete (vty
, vty
->index
, "aggregator as", NULL
);
3707 ret
= inet_aton (argv
[idx_ip
]->arg
, &address
);
3710 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
3714 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3715 strlen (argv
[idx_asn
]->arg
) + strlen (argv
[idx_ip
]->arg
) + 2);
3717 sprintf (argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
3719 ret
= generic_set_delete (vty
, vty
->index
, "aggregator as", argstr
);
3721 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3727 DEFUN (match_ipv6_next_hop
,
3728 match_ipv6_next_hop_cmd
,
3729 "match ipv6 next-hop X:X::X:X",
3732 "Match IPv6 next-hop address of route\n"
3733 "IPv6 address of next hop\n")
3736 return bgp_route_match_add (vty
, vty
->index
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
3737 RMAP_EVENT_MATCH_ADDED
);
3740 DEFUN (no_match_ipv6_next_hop
,
3741 no_match_ipv6_next_hop_cmd
,
3742 "no match ipv6 next-hop X:X::X:X",
3746 "Match IPv6 next-hop address of route\n"
3747 "IPv6 address of next hop\n")
3750 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
3751 RMAP_EVENT_MATCH_DELETED
);
3755 DEFUN (set_ipv6_nexthop_peer
,
3756 set_ipv6_nexthop_peer_cmd
,
3757 "set ipv6 next-hop peer-address",
3760 "Next hop address\n"
3761 "Use peer address (for BGP only)\n")
3763 return generic_set_add (vty
, vty
->index
, "ipv6 next-hop peer-address", NULL
);
3766 DEFUN (no_set_ipv6_nexthop_peer
,
3767 no_set_ipv6_nexthop_peer_cmd
,
3768 "no set ipv6 next-hop peer-address",
3772 "IPv6 next-hop address\n"
3773 "Use peer address (for BGP only)\n")
3775 return generic_set_delete (vty
, vty
->index
, "ipv6 next-hop peer-address", NULL
);
3778 DEFUN (set_ipv6_nexthop_prefer_global
,
3779 set_ipv6_nexthop_prefer_global_cmd
,
3780 "set ipv6 next-hop prefer-global",
3783 "IPv6 next-hop address\n"
3784 "Prefer global over link-local if both exist\n")
3786 return generic_set_add (vty
, vty
->index
, "ipv6 next-hop prefer-global", NULL
);;
3789 DEFUN (no_set_ipv6_nexthop_prefer_global
,
3790 no_set_ipv6_nexthop_prefer_global_cmd
,
3791 "no set ipv6 next-hop prefer-global",
3795 "IPv6 next-hop address\n"
3796 "Prefer global over link-local if both exist\n")
3798 return generic_set_delete (vty
, vty
->index
, "ipv6 next-hop prefer-global", NULL
);
3801 DEFUN (set_ipv6_nexthop_global
,
3802 set_ipv6_nexthop_global_cmd
,
3803 "set ipv6 next-hop global X:X::X:X",
3806 "IPv6 next-hop address\n"
3807 "IPv6 global address\n"
3808 "IPv6 address of next hop\n")
3811 struct in6_addr addr
;
3814 ret
= inet_pton (AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
3817 vty_out (vty
, "%% Malformed nexthop address%s", VTY_NEWLINE
);
3820 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) ||
3821 IN6_IS_ADDR_LOOPBACK(&addr
) ||
3822 IN6_IS_ADDR_MULTICAST(&addr
) ||
3823 IN6_IS_ADDR_LINKLOCAL(&addr
))
3825 vty_out (vty
, "%% Invalid global nexthop address%s", VTY_NEWLINE
);
3829 return generic_set_add (vty
, vty
->index
, "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
3833 DEFUN (no_set_ipv6_nexthop_global
,
3834 no_set_ipv6_nexthop_global_cmd
,
3835 "no set ipv6 next-hop global X:X::X:X",
3839 "IPv6 next-hop address\n"
3840 "IPv6 global address\n"
3841 "IPv6 address of next hop\n")
3844 if (argc
<= idx_ipv6
)
3845 return generic_set_delete (vty
, vty
->index
, "ipv6 next-hop global", NULL
);
3846 return generic_set_delete (vty
, vty
->index
, "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
3848 #endif /* HAVE_IPV6 */
3850 DEFUN (set_vpnv4_nexthop
,
3851 set_vpnv4_nexthop_cmd
,
3852 "set vpnv4 next-hop A.B.C.D",
3854 "VPNv4 information\n"
3855 "VPNv4 next-hop address\n"
3856 "IP address of next hop\n")
3859 return generic_set_add (vty
, vty
->index
, "vpnv4 next-hop", argv
[idx_ipv4
]->arg
);
3863 DEFUN (no_set_vpnv4_nexthop
,
3864 no_set_vpnv4_nexthop_cmd
,
3865 "no set vpnv4 next-hop [A.B.C.D]",
3868 "VPNv4 information\n"
3869 "VPNv4 next-hop address\n"
3870 "IP address of next hop\n")
3873 if (argc
<= idx_ipv4
)
3874 return generic_set_delete (vty
, vty
->index
, "vpnv4 next-hop", NULL
);
3875 return generic_set_delete (vty
, vty
->index
, "vpnv4 next-hop", argv
[idx_ipv4
]->arg
);
3879 DEFUN (set_originator_id
,
3880 set_originator_id_cmd
,
3881 "set originator-id A.B.C.D",
3883 "BGP originator ID attribute\n"
3884 "IP address of originator\n")
3887 return generic_set_add (vty
, vty
->index
, "originator-id", argv
[idx_ipv4
]->arg
);
3891 DEFUN (no_set_originator_id
,
3892 no_set_originator_id_cmd
,
3893 "no set originator-id [A.B.C.D]",
3896 "BGP originator ID attribute\n"
3897 "IP address of originator\n")
3901 return generic_set_delete (vty
, vty
->index
, "originator-id", NULL
);
3902 return generic_set_delete (vty
, vty
->index
, "originator-id", argv
[idx_id
]->arg
);
3906 /* Initialization of route map. */
3908 bgp_route_map_init (void)
3912 route_map_add_hook (bgp_route_map_add
);
3913 route_map_delete_hook (bgp_route_map_delete
);
3914 route_map_event_hook (bgp_route_map_event
);
3916 route_map_match_interface_hook (generic_match_add
);
3917 route_map_no_match_interface_hook (generic_match_delete
);
3919 route_map_match_ip_address_hook (generic_match_add
);
3920 route_map_no_match_ip_address_hook (generic_match_delete
);
3922 route_map_match_ip_address_prefix_list_hook (generic_match_add
);
3923 route_map_no_match_ip_address_prefix_list_hook (generic_match_delete
);
3925 route_map_match_ip_next_hop_hook (generic_match_add
);
3926 route_map_no_match_ip_next_hop_hook (generic_match_delete
);
3928 route_map_match_ip_next_hop_prefix_list_hook (generic_match_add
);
3929 route_map_no_match_ip_next_hop_prefix_list_hook (generic_match_delete
);
3931 route_map_match_ipv6_address_hook (generic_match_add
);
3932 route_map_no_match_ipv6_address_hook (generic_match_delete
);
3934 route_map_match_ipv6_address_prefix_list_hook (generic_match_add
);
3935 route_map_no_match_ipv6_address_prefix_list_hook (generic_match_delete
);
3937 route_map_match_metric_hook (generic_match_add
);
3938 route_map_no_match_metric_hook (generic_match_delete
);
3940 route_map_match_tag_hook (generic_match_add
);
3941 route_map_no_match_tag_hook (generic_match_delete
);
3943 route_map_set_ip_nexthop_hook (generic_set_add
);
3944 route_map_no_set_ip_nexthop_hook (generic_set_delete
);
3946 route_map_set_ipv6_nexthop_local_hook (generic_set_add
);
3947 route_map_no_set_ipv6_nexthop_local_hook (generic_set_delete
);
3949 route_map_set_metric_hook (generic_set_add
);
3950 route_map_no_set_metric_hook (generic_set_delete
);
3952 route_map_set_tag_hook (generic_set_add
);
3953 route_map_no_set_tag_hook (generic_set_delete
);
3955 route_map_install_match (&route_match_peer_cmd
);
3956 route_map_install_match (&route_match_local_pref_cmd
);
3957 route_map_install_match (&route_match_ip_address_cmd
);
3958 route_map_install_match (&route_match_ip_next_hop_cmd
);
3959 route_map_install_match (&route_match_ip_route_source_cmd
);
3960 route_map_install_match (&route_match_ip_address_prefix_list_cmd
);
3961 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd
);
3962 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd
);
3963 route_map_install_match (&route_match_aspath_cmd
);
3964 route_map_install_match (&route_match_community_cmd
);
3965 route_map_install_match (&route_match_ecommunity_cmd
);
3966 route_map_install_match (&route_match_local_pref_cmd
);
3967 route_map_install_match (&route_match_metric_cmd
);
3968 route_map_install_match (&route_match_origin_cmd
);
3969 route_map_install_match (&route_match_probability_cmd
);
3970 route_map_install_match (&route_match_interface_cmd
);
3971 route_map_install_match (&route_match_tag_cmd
);
3973 route_map_install_set (&route_set_ip_nexthop_cmd
);
3974 route_map_install_set (&route_set_local_pref_cmd
);
3975 route_map_install_set (&route_set_weight_cmd
);
3976 route_map_install_set (&route_set_metric_cmd
);
3977 route_map_install_set (&route_set_aspath_prepend_cmd
);
3978 route_map_install_set (&route_set_aspath_exclude_cmd
);
3979 route_map_install_set (&route_set_origin_cmd
);
3980 route_map_install_set (&route_set_atomic_aggregate_cmd
);
3981 route_map_install_set (&route_set_aggregator_as_cmd
);
3982 route_map_install_set (&route_set_community_cmd
);
3983 route_map_install_set (&route_set_community_delete_cmd
);
3984 route_map_install_set (&route_set_vpnv4_nexthop_cmd
);
3985 route_map_install_set (&route_set_originator_id_cmd
);
3986 route_map_install_set (&route_set_ecommunity_rt_cmd
);
3987 route_map_install_set (&route_set_ecommunity_soo_cmd
);
3988 route_map_install_set (&route_set_tag_cmd
);
3990 install_element (RMAP_NODE
, &match_peer_cmd
);
3991 install_element (RMAP_NODE
, &match_peer_local_cmd
);
3992 install_element (RMAP_NODE
, &no_match_peer_cmd
);
3993 install_element (RMAP_NODE
, &match_ip_route_source_cmd
);
3994 install_element (RMAP_NODE
, &no_match_ip_route_source_cmd
);
3995 install_element (RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
3996 install_element (RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
3998 install_element (RMAP_NODE
, &match_aspath_cmd
);
3999 install_element (RMAP_NODE
, &no_match_aspath_cmd
);
4000 install_element (RMAP_NODE
, &match_local_pref_cmd
);
4001 install_element (RMAP_NODE
, &no_match_local_pref_cmd
);
4002 install_element (RMAP_NODE
, &match_community_cmd
);
4003 install_element (RMAP_NODE
, &match_community_exact_cmd
);
4004 install_element (RMAP_NODE
, &no_match_community_cmd
);
4005 install_element (RMAP_NODE
, &match_ecommunity_cmd
);
4006 install_element (RMAP_NODE
, &no_match_ecommunity_cmd
);
4007 install_element (RMAP_NODE
, &match_origin_cmd
);
4008 install_element (RMAP_NODE
, &no_match_origin_cmd
);
4009 install_element (RMAP_NODE
, &match_probability_cmd
);
4010 install_element (RMAP_NODE
, &no_match_probability_cmd
);
4012 install_element (RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
4013 install_element (RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
4014 install_element (RMAP_NODE
, &set_local_pref_cmd
);
4015 install_element (RMAP_NODE
, &no_set_local_pref_cmd
);
4016 install_element (RMAP_NODE
, &set_weight_cmd
);
4017 install_element (RMAP_NODE
, &no_set_weight_cmd
);
4018 install_element (RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
4019 install_element (RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
4020 install_element (RMAP_NODE
, &set_aspath_exclude_cmd
);
4021 install_element (RMAP_NODE
, &no_set_aspath_prepend_cmd
);
4022 install_element (RMAP_NODE
, &no_set_aspath_exclude_cmd
);
4023 install_element (RMAP_NODE
, &set_origin_cmd
);
4024 install_element (RMAP_NODE
, &no_set_origin_cmd
);
4025 install_element (RMAP_NODE
, &set_atomic_aggregate_cmd
);
4026 install_element (RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
4027 install_element (RMAP_NODE
, &set_aggregator_as_cmd
);
4028 install_element (RMAP_NODE
, &no_set_aggregator_as_cmd
);
4029 install_element (RMAP_NODE
, &set_community_cmd
);
4030 install_element (RMAP_NODE
, &set_community_none_cmd
);
4031 install_element (RMAP_NODE
, &no_set_community_cmd
);
4032 install_element (RMAP_NODE
, &set_community_delete_cmd
);
4033 install_element (RMAP_NODE
, &no_set_community_delete_cmd
);
4034 install_element (RMAP_NODE
, &set_ecommunity_rt_cmd
);
4035 install_element (RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
4036 install_element (RMAP_NODE
, &set_ecommunity_soo_cmd
);
4037 install_element (RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
4038 install_element (RMAP_NODE
, &set_vpnv4_nexthop_cmd
);
4039 install_element (RMAP_NODE
, &no_set_vpnv4_nexthop_cmd
);
4040 install_element (RMAP_NODE
, &set_originator_id_cmd
);
4041 install_element (RMAP_NODE
, &no_set_originator_id_cmd
);
4044 route_map_install_match (&route_match_ipv6_address_cmd
);
4045 route_map_install_match (&route_match_ipv6_next_hop_cmd
);
4046 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd
);
4047 route_map_install_set (&route_set_ipv6_nexthop_global_cmd
);
4048 route_map_install_set (&route_set_ipv6_nexthop_prefer_global_cmd
);
4049 route_map_install_set (&route_set_ipv6_nexthop_local_cmd
);
4050 route_map_install_set (&route_set_ipv6_nexthop_peer_cmd
);
4052 install_element (RMAP_NODE
, &match_ipv6_next_hop_cmd
);
4053 install_element (RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
4054 install_element (RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
4055 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
4056 install_element (RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
4057 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
4058 install_element (RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
4059 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
4060 #endif /* HAVE_IPV6 */
4064 bgp_route_map_terminate (void)
4066 /* ToDo: Cleanup all the used memory */
4068 route_map_add_hook (NULL
);
4069 route_map_delete_hook (NULL
);
4070 route_map_event_hook (NULL
);