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
31 #ifdef HAVE_LIBPCREPOSIX
32 # include <pcreposix.h>
34 # ifdef HAVE_GNU_REGEX
37 # include "regex-gnu.h"
38 # endif /* HAVE_GNU_REGEX */
39 #endif /* HAVE_LIBPCREPOSIX */
41 #include "sockunion.h"
45 #include "bgpd/bgpd.h"
46 #include "bgpd/bgp_table.h"
47 #include "bgpd/bgp_attr.h"
48 #include "bgpd/bgp_aspath.h"
49 #include "bgpd/bgp_packet.h"
50 #include "bgpd/bgp_route.h"
51 #include "bgpd/bgp_zebra.h"
52 #include "bgpd/bgp_regex.h"
53 #include "bgpd/bgp_community.h"
54 #include "bgpd/bgp_clist.h"
55 #include "bgpd/bgp_filter.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_ecommunity.h"
58 #include "bgpd/bgp_vty.h"
59 #include "bgpd/bgp_debug.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 local : Done
107 set as-path exclude : Done
111 /* generic value manipulation to be shared in multiple rules */
113 #define RMAP_VALUE_SET 0
114 #define RMAP_VALUE_ADD 1
115 #define RMAP_VALUE_SUB 2
125 route_value_match (struct rmap_value
*rv
, u_int32_t value
)
127 if (rv
->variable
== 0 && value
== rv
->value
)
134 route_value_adjust (struct rmap_value
*rv
, u_int32_t current
, struct peer
*peer
)
138 switch (rv
->variable
)
151 if (current
> UINT32_MAX
-value
)
153 return current
+ value
;
155 if (current
<= value
)
157 return current
- value
;
164 route_value_compile (const char *arg
)
166 u_int8_t action
= RMAP_VALUE_SET
, var
= 0;
167 unsigned long larg
= 0;
169 struct rmap_value
*rv
;
173 action
= RMAP_VALUE_ADD
;
176 else if (arg
[0] == '-')
178 action
= RMAP_VALUE_SUB
;
185 larg
= strtoul (arg
, &endptr
, 10);
186 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
191 if (strcmp(arg
, "rtt") == 0)
197 rv
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
208 route_value_free (void *rule
)
210 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
213 /* generic as path object to be shared in multiple rules */
216 route_aspath_compile (const char *arg
)
218 struct aspath
*aspath
;
220 aspath
= aspath_str2aspath (arg
);
227 route_aspath_free (void *rule
)
229 struct aspath
*aspath
= rule
;
230 aspath_free (aspath
);
233 /* 'match peer (A.B.C.D|X:X::X:X)' */
235 /* Compares the peer specified in the 'match peer' clause with the peer
236 received in bgp_info->peer. If it is the same, or if the peer structure
237 received is a peer_group containing it, returns RMAP_MATCH. */
238 static route_map_result_t
239 route_match_peer (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
243 union sockunion su_def
= { .sin
= { .sin_family
= AF_INET
,
244 .sin_addr
.s_addr
= INADDR_ANY
} };
245 struct peer_group
*group
;
247 struct listnode
*node
, *nnode
;
249 if (type
== RMAP_BGP
)
252 peer
= ((struct bgp_info
*) object
)->peer
;
254 if ( ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
) &&
255 ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_EXPORT
) )
258 /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
259 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
260 if (sockunion_same (su
, &su_def
))
263 if ( CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
) ||
264 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
) ||
265 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
272 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
274 if (sockunion_same (su
, &peer
->su
))
282 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
284 if (sockunion_same (su
, &peer
->su
))
294 route_match_peer_compile (const char *arg
)
299 su
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (union sockunion
));
301 ret
= str2sockunion (strcmp(arg
, "local") ? arg
: "0.0.0.0", su
);
303 XFREE (MTYPE_ROUTE_MAP_COMPILED
, su
);
310 /* Free route map's compiled `ip address' value. */
312 route_match_peer_free (void *rule
)
314 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
317 /* Route map commands for ip address matching. */
318 struct route_map_rule_cmd route_match_peer_cmd
=
322 route_match_peer_compile
,
323 route_match_peer_free
326 /* `match ip address IP_ACCESS_LIST' */
328 /* Match function should return 1 if match is success else return
330 static route_map_result_t
331 route_match_ip_address (void *rule
, struct prefix
*prefix
,
332 route_map_object_t type
, void *object
)
334 struct access_list
*alist
;
335 /* struct prefix_ipv4 match; */
337 if (type
== RMAP_BGP
)
339 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
343 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
344 RMAP_NOMATCH
: RMAP_MATCH
);
349 /* Route map `ip address' match statement. `arg' should be
352 route_match_ip_address_compile (const char *arg
)
354 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
357 /* Free route map's compiled `ip address' value. */
359 route_match_ip_address_free (void *rule
)
361 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
364 /* Route map commands for ip address matching. */
365 struct route_map_rule_cmd route_match_ip_address_cmd
=
368 route_match_ip_address
,
369 route_match_ip_address_compile
,
370 route_match_ip_address_free
373 /* `match ip next-hop IP_ADDRESS' */
375 /* Match function return 1 if match is success else return zero. */
376 static route_map_result_t
377 route_match_ip_next_hop (void *rule
, struct prefix
*prefix
,
378 route_map_object_t type
, void *object
)
380 struct access_list
*alist
;
381 struct bgp_info
*bgp_info
;
382 struct prefix_ipv4 p
;
384 if (type
== RMAP_BGP
)
388 p
.prefix
= bgp_info
->attr
->nexthop
;
389 p
.prefixlen
= IPV4_MAX_BITLEN
;
391 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
395 return (access_list_apply (alist
, &p
) == FILTER_DENY
?
396 RMAP_NOMATCH
: RMAP_MATCH
);
401 /* Route map `ip next-hop' match statement. `arg' is
404 route_match_ip_next_hop_compile (const char *arg
)
406 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
409 /* Free route map's compiled `ip address' value. */
411 route_match_ip_next_hop_free (void *rule
)
413 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
416 /* Route map commands for ip next-hop matching. */
417 struct route_map_rule_cmd route_match_ip_next_hop_cmd
=
420 route_match_ip_next_hop
,
421 route_match_ip_next_hop_compile
,
422 route_match_ip_next_hop_free
425 /* `match ip route-source ACCESS-LIST' */
427 /* Match function return 1 if match is success else return zero. */
428 static route_map_result_t
429 route_match_ip_route_source (void *rule
, struct prefix
*prefix
,
430 route_map_object_t type
, void *object
)
432 struct access_list
*alist
;
433 struct bgp_info
*bgp_info
;
435 struct prefix_ipv4 p
;
437 if (type
== RMAP_BGP
)
440 peer
= bgp_info
->peer
;
442 if (! peer
|| sockunion_family (&peer
->su
) != AF_INET
)
446 p
.prefix
= peer
->su
.sin
.sin_addr
;
447 p
.prefixlen
= IPV4_MAX_BITLEN
;
449 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
453 return (access_list_apply (alist
, &p
) == FILTER_DENY
?
454 RMAP_NOMATCH
: RMAP_MATCH
);
459 /* Route map `ip route-source' match statement. `arg' is
462 route_match_ip_route_source_compile (const char *arg
)
464 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
467 /* Free route map's compiled `ip address' value. */
469 route_match_ip_route_source_free (void *rule
)
471 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
474 /* Route map commands for ip route-source matching. */
475 struct route_map_rule_cmd route_match_ip_route_source_cmd
=
478 route_match_ip_route_source
,
479 route_match_ip_route_source_compile
,
480 route_match_ip_route_source_free
483 /* `match ip address prefix-list PREFIX_LIST' */
485 static route_map_result_t
486 route_match_ip_address_prefix_list (void *rule
, struct prefix
*prefix
,
487 route_map_object_t type
, void *object
)
489 struct prefix_list
*plist
;
491 if (type
== RMAP_BGP
)
493 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
497 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
498 RMAP_NOMATCH
: RMAP_MATCH
);
504 route_match_ip_address_prefix_list_compile (const char *arg
)
506 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
510 route_match_ip_address_prefix_list_free (void *rule
)
512 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
515 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
=
517 "ip address prefix-list",
518 route_match_ip_address_prefix_list
,
519 route_match_ip_address_prefix_list_compile
,
520 route_match_ip_address_prefix_list_free
523 /* `match ip next-hop prefix-list PREFIX_LIST' */
525 static route_map_result_t
526 route_match_ip_next_hop_prefix_list (void *rule
, struct prefix
*prefix
,
527 route_map_object_t type
, void *object
)
529 struct prefix_list
*plist
;
530 struct bgp_info
*bgp_info
;
531 struct prefix_ipv4 p
;
533 if (type
== RMAP_BGP
)
537 p
.prefix
= bgp_info
->attr
->nexthop
;
538 p
.prefixlen
= IPV4_MAX_BITLEN
;
540 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
544 return (prefix_list_apply (plist
, &p
) == PREFIX_DENY
?
545 RMAP_NOMATCH
: RMAP_MATCH
);
551 route_match_ip_next_hop_prefix_list_compile (const char *arg
)
553 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
557 route_match_ip_next_hop_prefix_list_free (void *rule
)
559 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
562 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
=
564 "ip next-hop prefix-list",
565 route_match_ip_next_hop_prefix_list
,
566 route_match_ip_next_hop_prefix_list_compile
,
567 route_match_ip_next_hop_prefix_list_free
570 /* `match ip route-source prefix-list PREFIX_LIST' */
572 static route_map_result_t
573 route_match_ip_route_source_prefix_list (void *rule
, struct prefix
*prefix
,
574 route_map_object_t type
, void *object
)
576 struct prefix_list
*plist
;
577 struct bgp_info
*bgp_info
;
579 struct prefix_ipv4 p
;
581 if (type
== RMAP_BGP
)
584 peer
= bgp_info
->peer
;
586 if (! peer
|| sockunion_family (&peer
->su
) != AF_INET
)
590 p
.prefix
= peer
->su
.sin
.sin_addr
;
591 p
.prefixlen
= IPV4_MAX_BITLEN
;
593 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
597 return (prefix_list_apply (plist
, &p
) == PREFIX_DENY
?
598 RMAP_NOMATCH
: RMAP_MATCH
);
604 route_match_ip_route_source_prefix_list_compile (const char *arg
)
606 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
610 route_match_ip_route_source_prefix_list_free (void *rule
)
612 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
615 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
=
617 "ip route-source prefix-list",
618 route_match_ip_route_source_prefix_list
,
619 route_match_ip_route_source_prefix_list_compile
,
620 route_match_ip_route_source_prefix_list_free
623 /* `match local-preference LOCAL-PREF' */
625 /* Match function return 1 if match is success else return zero. */
626 static route_map_result_t
627 route_match_local_pref (void *rule
, struct prefix
*prefix
,
628 route_map_object_t type
, void *object
)
630 u_int32_t
*local_pref
;
631 struct bgp_info
*bgp_info
;
633 if (type
== RMAP_BGP
)
638 if (bgp_info
->attr
->local_pref
== *local_pref
)
646 /* Route map `match local-preference' match statement.
647 `arg' is local-pref value */
649 route_match_local_pref_compile (const char *arg
)
651 u_int32_t
*local_pref
;
653 unsigned long tmpval
;
655 /* Locpref value shoud be integer. */
656 if (! all_digit (arg
))
660 tmpval
= strtoul (arg
, &endptr
, 10);
661 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
664 local_pref
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
669 *local_pref
= tmpval
;
673 /* Free route map's compiled `match local-preference' value. */
675 route_match_local_pref_free (void *rule
)
677 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
680 /* Route map commands for metric matching. */
681 struct route_map_rule_cmd route_match_local_pref_cmd
=
684 route_match_local_pref
,
685 route_match_local_pref_compile
,
686 route_match_local_pref_free
689 /* `match metric METRIC' */
691 /* Match function return 1 if match is success else return zero. */
692 static route_map_result_t
693 route_match_metric (void *rule
, struct prefix
*prefix
,
694 route_map_object_t type
, void *object
)
696 struct rmap_value
*rv
;
697 struct bgp_info
*bgp_info
;
699 if (type
== RMAP_BGP
)
703 return route_value_match(rv
, bgp_info
->attr
->med
);
708 /* Route map commands for metric matching. */
709 struct route_map_rule_cmd route_match_metric_cmd
=
717 /* `match as-path ASPATH' */
719 /* Match function for as-path match. I assume given object is */
720 static route_map_result_t
721 route_match_aspath (void *rule
, struct prefix
*prefix
,
722 route_map_object_t type
, void *object
)
725 struct as_list
*as_list
;
726 struct bgp_info
*bgp_info
;
728 if (type
== RMAP_BGP
)
730 as_list
= as_list_lookup ((char *) rule
);
737 return ((as_list_apply (as_list
, bgp_info
->attr
->aspath
) == AS_FILTER_DENY
) ? RMAP_NOMATCH
: RMAP_MATCH
);
742 /* Compile function for as-path match. */
744 route_match_aspath_compile (const char *arg
)
746 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
749 /* Compile function for as-path match. */
751 route_match_aspath_free (void *rule
)
753 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
756 /* Route map commands for aspath matching. */
757 struct route_map_rule_cmd route_match_aspath_cmd
=
761 route_match_aspath_compile
,
762 route_match_aspath_free
765 /* `match community COMMUNIY' */
766 struct rmap_community
772 /* Match function for community match. */
773 static route_map_result_t
774 route_match_community (void *rule
, struct prefix
*prefix
,
775 route_map_object_t type
, void *object
)
777 struct community_list
*list
;
778 struct bgp_info
*bgp_info
;
779 struct rmap_community
*rcom
;
781 if (type
== RMAP_BGP
)
786 list
= community_list_lookup (bgp_clist
, rcom
->name
, COMMUNITY_LIST_MASTER
);
792 if (community_list_exact_match (bgp_info
->attr
->community
, list
))
797 if (community_list_match (bgp_info
->attr
->community
, list
))
804 /* Compile function for community match. */
806 route_match_community_compile (const char *arg
)
808 struct rmap_community
*rcom
;
812 rcom
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_community
));
814 p
= strchr (arg
, ' ');
818 rcom
->name
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
819 memcpy (rcom
->name
, arg
, len
);
824 rcom
->name
= XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
830 /* Compile function for community match. */
832 route_match_community_free (void *rule
)
834 struct rmap_community
*rcom
= rule
;
836 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
837 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
);
840 /* Route map commands for community matching. */
841 struct route_map_rule_cmd route_match_community_cmd
=
844 route_match_community
,
845 route_match_community_compile
,
846 route_match_community_free
849 /* Match function for extcommunity match. */
850 static route_map_result_t
851 route_match_ecommunity (void *rule
, struct prefix
*prefix
,
852 route_map_object_t type
, void *object
)
854 struct community_list
*list
;
855 struct bgp_info
*bgp_info
;
857 if (type
== RMAP_BGP
)
861 if (!bgp_info
->attr
->extra
)
864 list
= community_list_lookup (bgp_clist
, (char *) rule
,
865 EXTCOMMUNITY_LIST_MASTER
);
869 if (ecommunity_list_match (bgp_info
->attr
->extra
->ecommunity
, list
))
875 /* Compile function for extcommunity match. */
877 route_match_ecommunity_compile (const char *arg
)
879 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
882 /* Compile function for extcommunity match. */
884 route_match_ecommunity_free (void *rule
)
886 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
889 /* Route map commands for community matching. */
890 struct route_map_rule_cmd route_match_ecommunity_cmd
=
893 route_match_ecommunity
,
894 route_match_ecommunity_compile
,
895 route_match_ecommunity_free
898 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
899 and `address-family vpnv4'. */
902 static route_map_result_t
903 route_match_origin (void *rule
, struct prefix
*prefix
,
904 route_map_object_t type
, void *object
)
907 struct bgp_info
*bgp_info
;
909 if (type
== RMAP_BGP
)
914 if (bgp_info
->attr
->origin
== *origin
)
922 route_match_origin_compile (const char *arg
)
926 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
928 if (strcmp (arg
, "igp") == 0)
930 else if (strcmp (arg
, "egp") == 0)
938 /* Free route map's compiled `ip address' value. */
940 route_match_origin_free (void *rule
)
942 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
945 /* Route map commands for origin matching. */
946 struct route_map_rule_cmd route_match_origin_cmd
=
950 route_match_origin_compile
,
951 route_match_origin_free
954 /* match probability { */
956 static route_map_result_t
957 route_match_probability (void *rule
, struct prefix
*prefix
,
958 route_map_object_t type
, void *object
)
962 switch (*(long *) rule
)
965 case RAND_MAX
: return RMAP_MATCH
;
967 if (r
< *(long *) rule
)
977 route_match_probability_compile (const char *arg
)
983 lobule
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (long));
987 case 0: *lobule
= 0; break;
988 case 100: *lobule
= RAND_MAX
; break;
989 default: *lobule
= RAND_MAX
/ 100 * perc
;
996 route_match_probability_free (void *rule
)
998 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1001 struct route_map_rule_cmd route_match_probability_cmd
=
1004 route_match_probability
,
1005 route_match_probability_compile
,
1006 route_match_probability_free
1009 /* `match interface IFNAME' */
1010 /* Match function should return 1 if match is success else return
1012 static route_map_result_t
1013 route_match_interface (void *rule
, struct prefix
*prefix
,
1014 route_map_object_t type
, void *object
)
1016 struct interface
*ifp
;
1017 struct bgp_info
*info
;
1019 if (type
== RMAP_BGP
)
1023 if (!info
|| !info
->attr
)
1024 return RMAP_NOMATCH
;
1026 ifp
= if_lookup_by_name_all_vrf ((char *)rule
);
1028 if (ifp
== NULL
|| ifp
->ifindex
!= info
->attr
->nh_ifindex
)
1029 return RMAP_NOMATCH
;
1033 return RMAP_NOMATCH
;
1036 /* Route map `interface' match statement. `arg' should be
1039 route_match_interface_compile (const char *arg
)
1041 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1044 /* Free route map's compiled `interface' value. */
1046 route_match_interface_free (void *rule
)
1048 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1051 /* Route map commands for ip address matching. */
1052 struct route_map_rule_cmd route_match_interface_cmd
=
1055 route_match_interface
,
1056 route_match_interface_compile
,
1057 route_match_interface_free
1062 /* `set ip next-hop IP_ADDRESS' */
1064 /* Match function return 1 if match is success else return zero. */
1065 static route_map_result_t
1066 route_match_tag (void *rule
, struct prefix
*prefix
,
1067 route_map_object_t type
, void *object
)
1070 struct bgp_info
*bgp_info
;
1072 if (type
== RMAP_BGP
)
1077 if (!bgp_info
->attr
->extra
)
1078 return RMAP_NOMATCH
;
1080 return ((bgp_info
->attr
->extra
->tag
== *tag
)? RMAP_MATCH
: RMAP_NOMATCH
);
1083 return RMAP_NOMATCH
;
1087 /* Route map `match tag' match statement. `arg' is TAG value */
1089 route_match_tag_compile (const char *arg
)
1094 /* tag value shoud be integer. */
1095 if (! all_digit (arg
))
1102 tag
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_short
));
1113 /* Free route map's compiled 'match tag' value. */
1115 route_match_tag_free (void *rule
)
1117 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1120 /* Route map commands for tag matching. */
1121 struct route_map_rule_cmd route_match_tag_cmd
=
1125 route_match_tag_compile
,
1126 route_match_tag_free
,
1130 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1131 struct rmap_ip_nexthop_set
1133 struct in_addr
*address
;
1138 static route_map_result_t
1139 route_set_ip_nexthop (void *rule
, struct prefix
*prefix
,
1140 route_map_object_t type
, void *object
)
1142 struct rmap_ip_nexthop_set
*rins
= rule
;
1143 struct bgp_info
*bgp_info
;
1146 if (type
== RMAP_BGP
)
1149 peer
= bgp_info
->peer
;
1151 if (rins
->unchanged
)
1153 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1154 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1156 else if (rins
->peer_address
)
1158 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
1159 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1161 && sockunion_family (peer
->su_remote
) == AF_INET
)
1163 bgp_info
->attr
->nexthop
.s_addr
= sockunion2ip (peer
->su_remote
);
1164 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
1166 else if (CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
))
1168 /* The next hop value will be set as part of packet rewrite.
1169 * Set the flags here to indicate that rewrite needs to be done.
1170 * Also, clear the value.
1172 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1173 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1174 bgp_info
->attr
->nexthop
.s_addr
= 0;
1179 /* Set next hop value. */
1180 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
1181 bgp_info
->attr
->nexthop
= *rins
->address
;
1182 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1183 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1190 /* Route map `ip nexthop' compile function. Given string is converted
1191 to struct in_addr structure. */
1193 route_set_ip_nexthop_compile (const char *arg
)
1195 struct rmap_ip_nexthop_set
*rins
;
1196 struct in_addr
*address
= NULL
;
1197 int peer_address
= 0;
1201 if (strcmp (arg
, "peer-address") == 0)
1203 else if (strcmp (arg
, "unchanged") == 0)
1207 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
1208 ret
= inet_aton (arg
, address
);
1212 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1217 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_ip_nexthop_set
));
1219 rins
->address
= address
;
1220 rins
->peer_address
= peer_address
;
1221 rins
->unchanged
= unchanged
;
1226 /* Free route map's compiled `ip nexthop' value. */
1228 route_set_ip_nexthop_free (void *rule
)
1230 struct rmap_ip_nexthop_set
*rins
= rule
;
1233 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1235 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
);
1238 /* Route map commands for ip nexthop set. */
1239 struct route_map_rule_cmd route_set_ip_nexthop_cmd
=
1242 route_set_ip_nexthop
,
1243 route_set_ip_nexthop_compile
,
1244 route_set_ip_nexthop_free
1247 /* `set local-preference LOCAL_PREF' */
1249 /* Set local preference. */
1250 static route_map_result_t
1251 route_set_local_pref (void *rule
, struct prefix
*prefix
,
1252 route_map_object_t type
, void *object
)
1254 struct rmap_value
*rv
;
1255 struct bgp_info
*bgp_info
;
1256 u_int32_t locpref
= 0;
1258 if (type
== RMAP_BGP
)
1260 /* Fetch routemap's rule information. */
1264 /* Set local preference value. */
1265 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
1266 locpref
= bgp_info
->attr
->local_pref
;
1268 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
);
1269 bgp_info
->attr
->local_pref
= route_value_adjust(rv
, locpref
, bgp_info
->peer
);
1275 /* Set local preference rule structure. */
1276 struct route_map_rule_cmd route_set_local_pref_cmd
=
1279 route_set_local_pref
,
1280 route_value_compile
,
1284 /* `set weight WEIGHT' */
1287 static route_map_result_t
1288 route_set_weight (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
1291 struct rmap_value
*rv
;
1292 struct bgp_info
*bgp_info
;
1295 if (type
== RMAP_BGP
)
1297 /* Fetch routemap's rule information. */
1301 /* Set weight value. */
1302 weight
= route_value_adjust(rv
, 0, bgp_info
->peer
);
1304 (bgp_attr_extra_get (bgp_info
->attr
))->weight
= weight
;
1305 else if (bgp_info
->attr
->extra
)
1306 bgp_info
->attr
->extra
->weight
= 0;
1312 /* Set local preference rule structure. */
1313 struct route_map_rule_cmd route_set_weight_cmd
=
1317 route_value_compile
,
1321 /* `set metric METRIC' */
1323 /* Set metric to attribute. */
1324 static route_map_result_t
1325 route_set_metric (void *rule
, struct prefix
*prefix
,
1326 route_map_object_t type
, void *object
)
1328 struct rmap_value
*rv
;
1329 struct bgp_info
*bgp_info
;
1332 if (type
== RMAP_BGP
)
1334 /* Fetch routemap's rule information. */
1338 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
))
1339 med
= bgp_info
->attr
->med
;
1341 bgp_info
->attr
->med
= route_value_adjust(rv
, med
, bgp_info
->peer
);
1342 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
);
1347 /* Set metric rule structure. */
1348 struct route_map_rule_cmd route_set_metric_cmd
=
1352 route_value_compile
,
1356 /* `set as-path prepend ASPATH' */
1358 /* For AS path prepend mechanism. */
1359 static route_map_result_t
1360 route_set_aspath_prepend (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1362 struct aspath
*aspath
;
1364 struct bgp_info
*binfo
;
1366 if (type
== RMAP_BGP
)
1370 if (binfo
->attr
->aspath
->refcnt
)
1371 new = aspath_dup (binfo
->attr
->aspath
);
1373 new = binfo
->attr
->aspath
;
1375 if ((uintptr_t)rule
> 10)
1378 aspath_prepend (aspath
, new);
1382 as_t as
= aspath_leftmost(new);
1383 if (!as
) as
= binfo
->peer
->as
;
1384 new = aspath_add_seq_n (new, as
, (uintptr_t) rule
);
1387 binfo
->attr
->aspath
= new;
1394 route_set_aspath_prepend_compile (const char *arg
)
1398 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
< 10)
1399 return (void*)(uintptr_t)num
;
1401 return route_aspath_compile(arg
);
1405 route_set_aspath_prepend_free (void *rule
)
1407 if ((uintptr_t)rule
> 10)
1408 route_aspath_free(rule
);
1412 /* Set as-path prepend rule structure. */
1413 struct route_map_rule_cmd route_set_aspath_prepend_cmd
=
1416 route_set_aspath_prepend
,
1417 route_set_aspath_prepend_compile
,
1418 route_set_aspath_prepend_free
,
1421 /* `set as-path exclude ASn' */
1423 /* For ASN exclude mechanism.
1424 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1425 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1427 static route_map_result_t
1428 route_set_aspath_exclude (void *rule
, struct prefix
*dummy
, route_map_object_t type
, void *object
)
1430 struct aspath
* new_path
, * exclude_path
;
1431 struct bgp_info
*binfo
;
1433 if (type
== RMAP_BGP
)
1435 exclude_path
= rule
;
1437 if (binfo
->attr
->aspath
->refcnt
)
1438 new_path
= aspath_dup (binfo
->attr
->aspath
);
1440 new_path
= binfo
->attr
->aspath
;
1441 binfo
->attr
->aspath
= aspath_filter_exclude (new_path
, exclude_path
);
1446 /* Set ASn exlude rule structure. */
1447 struct route_map_rule_cmd route_set_aspath_exclude_cmd
=
1450 route_set_aspath_exclude
,
1451 route_aspath_compile
,
1455 /* `set community COMMUNITY' */
1458 struct community
*com
;
1463 /* For community set mechanism. */
1464 static route_map_result_t
1465 route_set_community (void *rule
, struct prefix
*prefix
,
1466 route_map_object_t type
, void *object
)
1468 struct rmap_com_set
*rcs
;
1469 struct bgp_info
*binfo
;
1471 struct community
*new = NULL
;
1472 struct community
*old
;
1473 struct community
*merge
;
1475 if (type
== RMAP_BGP
)
1480 old
= attr
->community
;
1485 attr
->flag
&= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
));
1486 attr
->community
= NULL
;
1487 /* See the longer comment down below. */
1488 if (old
&& old
->refcnt
== 0)
1489 community_free(old
);
1493 /* "additive" case. */
1494 if (rcs
->additive
&& old
)
1496 merge
= community_merge (community_dup (old
), rcs
->com
);
1498 /* HACK: if the old community is not intern'd,
1499 * we should free it here, or all reference to it may be lost.
1500 * Really need to cleanup attribute caching sometime.
1502 if (old
->refcnt
== 0)
1503 community_free (old
);
1504 new = community_uniq_sort (merge
);
1505 community_free (merge
);
1508 new = community_dup (rcs
->com
);
1510 /* will be interned by caller if required */
1511 attr
->community
= new;
1513 attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1519 /* Compile function for set community. */
1521 route_set_community_compile (const char *arg
)
1523 struct rmap_com_set
*rcs
;
1524 struct community
*com
= NULL
;
1529 if (strcmp (arg
, "none") == 0)
1533 sp
= strstr (arg
, "additive");
1537 /* "additive" keyworkd is included. */
1542 com
= community_str2com (arg
);
1551 rcs
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_com_set
));
1553 rcs
->additive
= additive
;
1559 /* Free function for set community. */
1561 route_set_community_free (void *rule
)
1563 struct rmap_com_set
*rcs
= rule
;
1566 community_free (rcs
->com
);
1567 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1570 /* Set community rule structure. */
1571 struct route_map_rule_cmd route_set_community_cmd
=
1574 route_set_community
,
1575 route_set_community_compile
,
1576 route_set_community_free
,
1579 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
1581 /* For community set mechanism. */
1582 static route_map_result_t
1583 route_set_community_delete (void *rule
, struct prefix
*prefix
,
1584 route_map_object_t type
, void *object
)
1586 struct community_list
*list
;
1587 struct community
*merge
;
1588 struct community
*new;
1589 struct community
*old
;
1590 struct bgp_info
*binfo
;
1592 if (type
== RMAP_BGP
)
1598 list
= community_list_lookup (bgp_clist
, rule
, COMMUNITY_LIST_MASTER
);
1599 old
= binfo
->attr
->community
;
1603 merge
= community_list_match_delete (community_dup (old
), list
);
1604 new = community_uniq_sort (merge
);
1605 community_free (merge
);
1607 /* HACK: if the old community is not intern'd,
1608 * we should free it here, or all reference to it may be lost.
1609 * Really need to cleanup attribute caching sometime.
1611 if (old
->refcnt
== 0)
1612 community_free (old
);
1616 binfo
->attr
->community
= NULL
;
1617 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1618 community_free (new);
1622 binfo
->attr
->community
= new;
1623 binfo
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1631 /* Compile function for set community. */
1633 route_set_community_delete_compile (const char *arg
)
1639 p
= strchr (arg
, ' ');
1643 str
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1644 memcpy (str
, arg
, len
);
1652 /* Free function for set community. */
1654 route_set_community_delete_free (void *rule
)
1656 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1659 /* Set community rule structure. */
1660 struct route_map_rule_cmd route_set_community_delete_cmd
=
1663 route_set_community_delete
,
1664 route_set_community_delete_compile
,
1665 route_set_community_delete_free
,
1668 /* `set extcommunity rt COMMUNITY' */
1670 /* For community set mechanism. Used by _rt and _soo. */
1671 static route_map_result_t
1672 route_set_ecommunity (void *rule
, struct prefix
*prefix
,
1673 route_map_object_t type
, void *object
)
1675 struct ecommunity
*ecom
;
1676 struct ecommunity
*new_ecom
;
1677 struct ecommunity
*old_ecom
;
1678 struct bgp_info
*bgp_info
;
1680 if (type
== RMAP_BGP
)
1688 /* We assume additive for Extended Community. */
1689 old_ecom
= (bgp_attr_extra_get (bgp_info
->attr
))->ecommunity
;
1693 new_ecom
= ecommunity_merge (ecommunity_dup (old_ecom
), ecom
);
1695 /* old_ecom->refcnt = 1 => owned elsewhere, e.g. bgp_update_receive()
1696 * ->refcnt = 0 => set by a previous route-map statement */
1697 if (!old_ecom
->refcnt
)
1698 ecommunity_free (&old_ecom
);
1701 new_ecom
= ecommunity_dup (ecom
);
1703 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1704 bgp_info
->attr
->extra
->ecommunity
= new_ecom
;
1706 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES
);
1711 /* Compile function for set community. */
1713 route_set_ecommunity_rt_compile (const char *arg
)
1715 struct ecommunity
*ecom
;
1717 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
1720 return ecommunity_intern (ecom
);
1723 /* Free function for set community. Used by _rt and _soo */
1725 route_set_ecommunity_free (void *rule
)
1727 struct ecommunity
*ecom
= rule
;
1728 ecommunity_unintern (&ecom
);
1731 /* Set community rule structure. */
1732 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
=
1735 route_set_ecommunity
,
1736 route_set_ecommunity_rt_compile
,
1737 route_set_ecommunity_free
,
1740 /* `set extcommunity soo COMMUNITY' */
1742 /* Compile function for set community. */
1744 route_set_ecommunity_soo_compile (const char *arg
)
1746 struct ecommunity
*ecom
;
1748 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
1752 return ecommunity_intern (ecom
);
1755 /* Set community rule structure. */
1756 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
=
1759 route_set_ecommunity
,
1760 route_set_ecommunity_soo_compile
,
1761 route_set_ecommunity_free
,
1764 /* `set origin ORIGIN' */
1766 /* For origin set. */
1767 static route_map_result_t
1768 route_set_origin (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1771 struct bgp_info
*bgp_info
;
1773 if (type
== RMAP_BGP
)
1778 bgp_info
->attr
->origin
= *origin
;
1784 /* Compile function for origin set. */
1786 route_set_origin_compile (const char *arg
)
1790 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
1792 if (strcmp (arg
, "igp") == 0)
1794 else if (strcmp (arg
, "egp") == 0)
1802 /* Compile function for origin set. */
1804 route_set_origin_free (void *rule
)
1806 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1809 /* Set origin rule structure. */
1810 struct route_map_rule_cmd route_set_origin_cmd
=
1814 route_set_origin_compile
,
1815 route_set_origin_free
,
1818 /* `set atomic-aggregate' */
1820 /* For atomic aggregate set. */
1821 static route_map_result_t
1822 route_set_atomic_aggregate (void *rule
, struct prefix
*prefix
,
1823 route_map_object_t type
, void *object
)
1825 struct bgp_info
*bgp_info
;
1827 if (type
== RMAP_BGP
)
1830 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
);
1836 /* Compile function for atomic aggregate. */
1838 route_set_atomic_aggregate_compile (const char *arg
)
1843 /* Compile function for atomic aggregate. */
1845 route_set_atomic_aggregate_free (void *rule
)
1850 /* Set atomic aggregate rule structure. */
1851 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
=
1854 route_set_atomic_aggregate
,
1855 route_set_atomic_aggregate_compile
,
1856 route_set_atomic_aggregate_free
,
1859 /* `set aggregator as AS A.B.C.D' */
1863 struct in_addr address
;
1866 static route_map_result_t
1867 route_set_aggregator_as (void *rule
, struct prefix
*prefix
,
1868 route_map_object_t type
, void *object
)
1870 struct bgp_info
*bgp_info
;
1871 struct aggregator
*aggregator
;
1872 struct attr_extra
*ae
;
1874 if (type
== RMAP_BGP
)
1878 ae
= bgp_attr_extra_get (bgp_info
->attr
);
1880 ae
->aggregator_as
= aggregator
->as
;
1881 ae
->aggregator_addr
= aggregator
->address
;
1882 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR
);
1889 route_set_aggregator_as_compile (const char *arg
)
1891 struct aggregator
*aggregator
;
1895 aggregator
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct aggregator
));
1896 sscanf (arg
, "%s %s", as
, address
);
1898 aggregator
->as
= strtoul (as
, NULL
, 10);
1899 inet_aton (address
, &aggregator
->address
);
1905 route_set_aggregator_as_free (void *rule
)
1907 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1910 struct route_map_rule_cmd route_set_aggregator_as_cmd
=
1913 route_set_aggregator_as
,
1914 route_set_aggregator_as_compile
,
1915 route_set_aggregator_as_free
,
1918 /* Set tag to object. object must be pointer to struct bgp_info */
1919 static route_map_result_t
1920 route_set_tag (void *rule
, struct prefix
*prefix
,
1921 route_map_object_t type
, void *object
)
1924 struct bgp_info
*bgp_info
;
1925 struct attr_extra
*ae
;
1927 if (type
== RMAP_BGP
)
1931 ae
= bgp_attr_extra_get (bgp_info
->attr
);
1941 /* Route map `tag' compile function. Given string is converted to u_short. */
1943 route_set_tag_compile (const char *arg
)
1948 /* tag value shoud be integer. */
1949 if (! all_digit (arg
))
1957 tag
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_short
));
1967 /* Free route map's tag value. */
1969 route_set_tag_free (void *rule
)
1971 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1975 /* Route map commands for tag set. */
1976 struct route_map_rule_cmd route_set_tag_cmd
=
1980 route_set_tag_compile
,
1986 /* `match ipv6 address IP_ACCESS_LIST' */
1988 static route_map_result_t
1989 route_match_ipv6_address (void *rule
, struct prefix
*prefix
,
1990 route_map_object_t type
, void *object
)
1992 struct access_list
*alist
;
1994 if (type
== RMAP_BGP
)
1996 alist
= access_list_lookup (AFI_IP6
, (char *) rule
);
1998 return RMAP_NOMATCH
;
2000 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
2001 RMAP_NOMATCH
: RMAP_MATCH
);
2003 return RMAP_NOMATCH
;
2007 route_match_ipv6_address_compile (const char *arg
)
2009 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
2013 route_match_ipv6_address_free (void *rule
)
2015 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2018 /* Route map commands for ip address matching. */
2019 struct route_map_rule_cmd route_match_ipv6_address_cmd
=
2022 route_match_ipv6_address
,
2023 route_match_ipv6_address_compile
,
2024 route_match_ipv6_address_free
2027 /* `match ipv6 next-hop IP_ADDRESS' */
2029 static route_map_result_t
2030 route_match_ipv6_next_hop (void *rule
, struct prefix
*prefix
,
2031 route_map_object_t type
, void *object
)
2033 struct in6_addr
*addr
= rule
;
2034 struct bgp_info
*bgp_info
;
2036 if (type
== RMAP_BGP
)
2040 if (!bgp_info
->attr
->extra
)
2041 return RMAP_NOMATCH
;
2043 if (IPV6_ADDR_SAME (&bgp_info
->attr
->extra
->mp_nexthop_global
, addr
))
2046 if (bgp_info
->attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
&&
2047 IPV6_ADDR_SAME (&bgp_info
->attr
->extra
->mp_nexthop_local
, rule
))
2050 return RMAP_NOMATCH
;
2053 return RMAP_NOMATCH
;
2057 route_match_ipv6_next_hop_compile (const char *arg
)
2059 struct in6_addr
*address
;
2062 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2064 ret
= inet_pton (AF_INET6
, arg
, address
);
2067 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2075 route_match_ipv6_next_hop_free (void *rule
)
2077 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2080 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
=
2083 route_match_ipv6_next_hop
,
2084 route_match_ipv6_next_hop_compile
,
2085 route_match_ipv6_next_hop_free
2088 /* `match ipv6 address prefix-list PREFIX_LIST' */
2090 static route_map_result_t
2091 route_match_ipv6_address_prefix_list (void *rule
, struct prefix
*prefix
,
2092 route_map_object_t type
, void *object
)
2094 struct prefix_list
*plist
;
2096 if (type
== RMAP_BGP
)
2098 plist
= prefix_list_lookup (AFI_IP6
, (char *) rule
);
2100 return RMAP_NOMATCH
;
2102 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
2103 RMAP_NOMATCH
: RMAP_MATCH
);
2105 return RMAP_NOMATCH
;
2109 route_match_ipv6_address_prefix_list_compile (const char *arg
)
2111 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
2115 route_match_ipv6_address_prefix_list_free (void *rule
)
2117 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2120 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
=
2122 "ipv6 address prefix-list",
2123 route_match_ipv6_address_prefix_list
,
2124 route_match_ipv6_address_prefix_list_compile
,
2125 route_match_ipv6_address_prefix_list_free
2128 /* `set ipv6 nexthop global IP_ADDRESS' */
2130 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2131 static route_map_result_t
2132 route_set_ipv6_nexthop_global (void *rule
, struct prefix
*prefix
,
2133 route_map_object_t type
, void *object
)
2135 struct in6_addr
*address
;
2136 struct bgp_info
*bgp_info
;
2138 if (type
== RMAP_BGP
)
2140 /* Fetch routemap's rule information. */
2144 /* Set next hop value. */
2145 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
= *address
;
2147 /* Set nexthop length. */
2148 if (bgp_info
->attr
->extra
->mp_nexthop_len
== 0)
2149 bgp_info
->attr
->extra
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2151 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2152 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2158 /* Route map `ip next-hop' compile function. Given string is converted
2159 to struct in_addr structure. */
2161 route_set_ipv6_nexthop_global_compile (const char *arg
)
2164 struct in6_addr
*address
;
2166 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2168 ret
= inet_pton (AF_INET6
, arg
, address
);
2172 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2179 /* Free route map's compiled `ip next-hop' value. */
2181 route_set_ipv6_nexthop_global_free (void *rule
)
2183 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2186 /* Route map commands for ip nexthop set. */
2187 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
=
2189 "ipv6 next-hop global",
2190 route_set_ipv6_nexthop_global
,
2191 route_set_ipv6_nexthop_global_compile
,
2192 route_set_ipv6_nexthop_global_free
2195 /* `set ipv6 nexthop local IP_ADDRESS' */
2197 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2198 static route_map_result_t
2199 route_set_ipv6_nexthop_local (void *rule
, struct prefix
*prefix
,
2200 route_map_object_t type
, void *object
)
2202 struct in6_addr
*address
;
2203 struct bgp_info
*bgp_info
;
2205 if (type
== RMAP_BGP
)
2207 /* Fetch routemap's rule information. */
2211 /* Set next hop value. */
2212 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
= *address
;
2214 /* Set nexthop length. */
2215 if (bgp_info
->attr
->extra
->mp_nexthop_len
!= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2216 bgp_info
->attr
->extra
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2218 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2219 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2225 /* Route map `ip nexthop' compile function. Given string is converted
2226 to struct in_addr structure. */
2228 route_set_ipv6_nexthop_local_compile (const char *arg
)
2231 struct in6_addr
*address
;
2233 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2235 ret
= inet_pton (AF_INET6
, arg
, address
);
2239 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2246 /* Free route map's compiled `ip nexthop' value. */
2248 route_set_ipv6_nexthop_local_free (void *rule
)
2250 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2253 /* Route map commands for ip nexthop set. */
2254 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
=
2256 "ipv6 next-hop local",
2257 route_set_ipv6_nexthop_local
,
2258 route_set_ipv6_nexthop_local_compile
,
2259 route_set_ipv6_nexthop_local_free
2262 /* `set ipv6 nexthop peer-address' */
2264 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2265 static route_map_result_t
2266 route_set_ipv6_nexthop_peer (void *rule
, struct prefix
*prefix
,
2267 route_map_object_t type
, void *object
)
2269 struct in6_addr peer_address
;
2270 struct bgp_info
*bgp_info
;
2272 char peer_addr_buf
[INET6_ADDRSTRLEN
];
2274 if (type
== RMAP_BGP
)
2276 /* Fetch routemap's rule information. */
2278 peer
= bgp_info
->peer
;
2280 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
2281 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2283 && sockunion_family (peer
->su_remote
) == AF_INET6
)
2285 inet_pton (AF_INET6
, sockunion2str (peer
->su_remote
,
2289 /* Set next hop value and length in attribute. */
2290 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
))
2292 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
= peer_address
;
2293 if (bgp_info
->attr
->extra
->mp_nexthop_len
!= 32)
2294 bgp_info
->attr
->extra
->mp_nexthop_len
= 32;
2298 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
= peer_address
;
2299 if (bgp_info
->attr
->extra
->mp_nexthop_len
== 0)
2300 bgp_info
->attr
->extra
->mp_nexthop_len
= 16;
2304 else if (CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
))
2306 /* The next hop value will be set as part of packet rewrite.
2307 * Set the flags here to indicate that rewrite needs to be done.
2308 * Also, clear the value - we clear both global and link-local
2309 * nexthops, whether we send one or both is determined elsewhere.
2311 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2312 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2313 /* clear next hop value. */
2314 memset (&((bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
),
2315 0, sizeof (struct in6_addr
));
2316 memset (&((bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
),
2317 0, sizeof (struct in6_addr
));
2324 /* Route map `ip next-hop' compile function. Given string is converted
2325 to struct in_addr structure. */
2327 route_set_ipv6_nexthop_peer_compile (const char *arg
)
2331 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (int));
2337 /* Free route map's compiled `ip next-hop' value. */
2339 route_set_ipv6_nexthop_peer_free (void *rule
)
2341 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2344 /* Route map commands for ip nexthop set. */
2345 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
=
2347 "ipv6 next-hop peer-address",
2348 route_set_ipv6_nexthop_peer
,
2349 route_set_ipv6_nexthop_peer_compile
,
2350 route_set_ipv6_nexthop_peer_free
2353 #endif /* HAVE_IPV6 */
2355 /* `set vpnv4 nexthop A.B.C.D' */
2357 static route_map_result_t
2358 route_set_vpnv4_nexthop (void *rule
, struct prefix
*prefix
,
2359 route_map_object_t type
, void *object
)
2361 struct in_addr
*address
;
2362 struct bgp_info
*bgp_info
;
2364 if (type
== RMAP_BGP
)
2366 /* Fetch routemap's rule information. */
2370 /* Set next hop value. */
2371 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global_in
= *address
;
2372 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_len
= 4;
2379 route_set_vpnv4_nexthop_compile (const char *arg
)
2382 struct in_addr
*address
;
2384 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
2386 ret
= inet_aton (arg
, address
);
2390 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2398 route_set_vpnv4_nexthop_free (void *rule
)
2400 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2403 /* Route map commands for ip nexthop set. */
2404 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
=
2407 route_set_vpnv4_nexthop
,
2408 route_set_vpnv4_nexthop_compile
,
2409 route_set_vpnv4_nexthop_free
2412 /* `set originator-id' */
2414 /* For origin set. */
2415 static route_map_result_t
2416 route_set_originator_id (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
2418 struct in_addr
*address
;
2419 struct bgp_info
*bgp_info
;
2421 if (type
== RMAP_BGP
)
2426 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
);
2427 (bgp_attr_extra_get (bgp_info
->attr
))->originator_id
= *address
;
2433 /* Compile function for originator-id set. */
2435 route_set_originator_id_compile (const char *arg
)
2438 struct in_addr
*address
;
2440 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
2442 ret
= inet_aton (arg
, address
);
2446 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2453 /* Compile function for originator_id set. */
2455 route_set_originator_id_free (void *rule
)
2457 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2460 /* Set originator-id rule structure. */
2461 struct route_map_rule_cmd route_set_originator_id_cmd
=
2464 route_set_originator_id
,
2465 route_set_originator_id_compile
,
2466 route_set_originator_id_free
,
2469 /* Add bgp route map rule. */
2471 bgp_route_match_add (struct vty
*vty
, struct route_map_index
*index
,
2472 const char *command
, const char *arg
,
2473 route_map_event_t type
)
2477 ret
= route_map_add_match (index
, command
, arg
);
2482 case RMAP_RULE_MISSING
:
2483 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2485 case RMAP_COMPILE_ERROR
:
2486 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2491 if (type
!= RMAP_EVENT_MATCH_ADDED
)
2493 route_map_upd8_dependency (type
, arg
, index
->map
->name
);
2499 /* Delete bgp route map rule. */
2501 bgp_route_match_delete (struct vty
*vty
, struct route_map_index
*index
,
2502 const char *command
, const char *arg
,
2503 route_map_event_t type
)
2506 char *dep_name
= NULL
;
2508 char *rmap_name
= NULL
;
2510 if (type
!= RMAP_EVENT_MATCH_DELETED
)
2512 /* ignore the mundane, the types without any dependency */
2515 if ((tmpstr
= route_map_get_match_arg(index
, command
)) != NULL
)
2516 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
2520 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
2522 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
2525 ret
= route_map_delete_match (index
, command
, dep_name
);
2530 case RMAP_RULE_MISSING
:
2531 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2533 case RMAP_COMPILE_ERROR
:
2534 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2538 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2540 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2544 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
2545 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
2548 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2550 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2555 /* Add bgp route map rule. */
2557 bgp_route_set_add (struct vty
*vty
, struct route_map_index
*index
,
2558 const char *command
, const char *arg
)
2562 ret
= route_map_add_set (index
, command
, arg
);
2567 case RMAP_RULE_MISSING
:
2568 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2570 case RMAP_COMPILE_ERROR
:
2571 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2578 /* Delete bgp route map rule. */
2580 bgp_route_set_delete (struct vty
*vty
, struct route_map_index
*index
,
2581 const char *command
, const char *arg
)
2585 ret
= route_map_delete_set (index
, command
, arg
);
2590 case RMAP_RULE_MISSING
:
2591 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2593 case RMAP_COMPILE_ERROR
:
2594 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2602 * This is the workhorse routine for processing in/out routemap
2606 bgp_route_map_process_peer (const char *rmap_name
, struct route_map
*map
,
2607 struct peer
*peer
, int afi
, int safi
,
2612 struct bgp_filter
*filter
;
2614 if (!peer
|| !rmap_name
)
2617 filter
= &peer
->filter
[afi
][safi
];
2619 * in is for non-route-server clients,
2620 * out is for all peers
2622 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
))
2624 if (filter
->map
[RMAP_IN
].name
&&
2625 (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0))
2627 filter
->map
[RMAP_IN
].map
= map
;
2629 if (route_update
&& peer
->status
== Established
)
2631 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
],
2632 PEER_FLAG_SOFT_RECONFIG
))
2634 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2635 zlog_debug("Processing route_map %s update on "
2636 "peer %s (inbound, soft-reconfig)",
2637 rmap_name
, peer
->host
);
2639 bgp_soft_reconfig_in (peer
, afi
, safi
);
2641 else if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
2642 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
2645 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2646 zlog_debug("Processing route_map %s update on "
2647 "peer %s (inbound, route-refresh)",
2648 rmap_name
, peer
->host
);
2649 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
2655 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
))
2659 if (update
&& route_update
&& peer
->status
== Established
)
2661 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
],
2662 PEER_FLAG_SOFT_RECONFIG
))
2664 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2665 zlog_debug("Processing route_map %s update on "
2666 "peer %s (import, soft-reconfig)",
2667 rmap_name
, peer
->host
);
2669 bgp_soft_reconfig_in (peer
, afi
, safi
);
2671 else if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
2672 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
2674 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2675 zlog_debug("Processing route_map %s update on "
2676 "peer %s (import, route-refresh)",
2677 rmap_name
, peer
->host
);
2678 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
2680 /* DD: Else, what else do we do ? Reset peer ? */
2685 * For outbound, unsuppress and default-originate map change (content or
2686 * map created), merely update the "config" here, the actual route
2687 * announcement happens at the group level.
2689 if (filter
->map
[RMAP_OUT
].name
&&
2690 (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
2691 filter
->map
[RMAP_OUT
].map
= map
;
2693 if (filter
->usmap
.name
&&
2694 (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
2695 filter
->usmap
.map
= map
;
2697 if (peer
->default_rmap
[afi
][safi
].name
&&
2698 (strcmp (rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
2699 peer
->default_rmap
[afi
][safi
].map
= map
;
2703 bgp_route_map_update_peer_group(const char *rmap_name
, struct route_map
*map
,
2706 struct peer_group
*group
;
2707 struct listnode
*node
, *nnode
;
2708 struct bgp_filter
*filter
;
2715 /* All the peers have been updated correctly already. This is
2716 * just updating the placeholder data. No real update required.
2718 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
2719 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2720 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2722 filter
= &group
->conf
->filter
[afi
][safi
];
2724 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++)
2726 if ((filter
->map
[direct
].name
) &&
2727 (strcmp(rmap_name
, filter
->map
[direct
].name
) == 0))
2728 filter
->map
[direct
].map
= map
;
2731 if (filter
->usmap
.name
&&
2732 (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
2733 filter
->usmap
.map
= map
;
2738 * Note that if an extreme number (tens of thousands) of route-maps are in use
2739 * and if bgp has an extreme number of peers, network statements, etc then this
2740 * function can consume a lot of cycles. This is due to this function being
2741 * called for each route-map and within this function we walk the list of peers,
2742 * network statements, etc looking to see if they use this route-map.
2745 bgp_route_map_process_update (struct bgp
*bgp
, const char *rmap_name
, int route_update
)
2751 struct bgp_node
*bn
;
2752 struct bgp_static
*bgp_static
;
2753 struct listnode
*node
, *nnode
;
2754 struct route_map
*map
;
2755 char buf
[INET6_ADDRSTRLEN
];
2757 map
= route_map_lookup_by_name (rmap_name
);
2759 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
2762 /* Ignore dummy peer-group structure */
2763 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
2766 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2767 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2769 /* Ignore inactive AFI/SAFI */
2770 if (! peer
->afc
[afi
][safi
])
2773 /* process in/out/import/export/default-orig route-maps */
2774 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
, safi
, route_update
);
2778 /* for outbound/default-orig route-maps, process for groups */
2779 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
2782 /* update peer-group config (template) */
2783 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
2785 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2786 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2788 /* For table route-map updates. */
2789 if (bgp
->table_map
[afi
][safi
].name
&&
2790 (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
) == 0))
2792 bgp
->table_map
[afi
][safi
].map
= map
;
2794 if (BGP_DEBUG (zebra
, ZEBRA
))
2795 zlog_debug("Processing route_map %s update on "
2796 "table map", rmap_name
);
2798 bgp_zebra_announce_table(bgp
, afi
, safi
);
2801 /* For network route-map updates. */
2802 for (bn
= bgp_table_top (bgp
->route
[afi
][safi
]); bn
; bn
= bgp_route_next (bn
))
2803 if ((bgp_static
= bn
->info
) != NULL
)
2805 if (bgp_static
->rmap
.name
&&
2806 (strcmp(rmap_name
, bgp_static
->rmap
.name
) == 0))
2808 bgp_static
->rmap
.map
= map
;
2811 if (!bgp_static
->backdoor
)
2813 if (bgp_debug_zebra(&bn
->p
))
2814 zlog_debug("Processing route_map %s update on "
2815 "static route %s", rmap_name
,
2816 inet_ntop (bn
->p
.family
, &bn
->p
.u
.prefix
,
2817 buf
, INET6_ADDRSTRLEN
));
2818 bgp_static_update (bgp
, &bn
->p
, bgp_static
, afi
, safi
);
2824 /* For redistribute route-map updates. */
2825 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2826 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2828 struct list
*red_list
;
2829 struct listnode
*node
;
2830 struct bgp_redist
*red
;
2832 red_list
= bgp
->redist
[afi
][i
];
2836 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
))
2838 if (red
->rmap
.name
&&
2839 (strcmp(rmap_name
, red
->rmap
.name
) == 0))
2841 red
->rmap
.map
= map
;
2845 if (BGP_DEBUG (zebra
, ZEBRA
))
2846 zlog_debug("Processing route_map %s update on "
2847 "redistributed routes", rmap_name
);
2849 bgp_redistribute_resend (bgp
, afi
, i
, red
->instance
);
2857 bgp_route_map_process_update_cb (char *rmap_name
)
2859 struct listnode
*node
, *nnode
;
2862 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
2863 bgp_route_map_process_update(bgp
, rmap_name
, 1);
2869 bgp_route_map_update_timer(struct thread
*thread
)
2871 bm
->t_rmap_update
= NULL
;
2873 route_map_walk_update_list(bgp_route_map_process_update_cb
);
2879 bgp_route_map_mark_update (const char *rmap_name
)
2881 if (bm
->t_rmap_update
== NULL
)
2883 struct listnode
*node
, *nnode
;
2886 /* rmap_update_timer of 0 means don't do route updates */
2887 if (bm
->rmap_update_timer
)
2890 thread_add_timer(bm
->master
, bgp_route_map_update_timer
, NULL
,
2891 bm
->rmap_update_timer
);
2893 /* Signal the groups that a route-map update event has started */
2894 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
2895 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
, 1, 1);
2899 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
2900 bgp_route_map_process_update(bgp
, rmap_name
, 0);
2906 bgp_route_map_add (const char *rmap_name
)
2908 if (route_map_mark_updated(rmap_name
, 0) == 0)
2909 bgp_route_map_mark_update(rmap_name
);
2911 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
2915 bgp_route_map_delete (const char *rmap_name
)
2917 if (route_map_mark_updated(rmap_name
, 1) == 0)
2918 bgp_route_map_mark_update(rmap_name
);
2920 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
2924 bgp_route_map_event (route_map_event_t event
, const char *rmap_name
)
2926 if (route_map_mark_updated(rmap_name
, 0) == 0)
2927 bgp_route_map_mark_update(rmap_name
);
2929 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
2935 "match peer (A.B.C.D|X:X::X:X)",
2937 "Match peer address\n"
2938 "IPv6 address of peer\n"
2939 "IP address of peer\n")
2941 return bgp_route_match_add (vty
, vty
->index
, "peer", argv
[0],
2942 RMAP_EVENT_MATCH_ADDED
);
2945 DEFUN (match_peer_local
,
2946 match_peer_local_cmd
,
2949 "Match peer address\n"
2950 "Static or Redistributed routes\n")
2952 return bgp_route_match_add (vty
, vty
->index
, "peer", "local",
2953 RMAP_EVENT_MATCH_DELETED
);
2956 DEFUN (no_match_peer
,
2961 "Match peer address\n")
2964 return bgp_route_match_delete (vty
, vty
->index
, "peer", NULL
,
2965 RMAP_EVENT_MATCH_DELETED
);
2967 return bgp_route_match_delete (vty
, vty
->index
, "peer", argv
[0],
2968 RMAP_EVENT_MATCH_DELETED
);
2971 ALIAS (no_match_peer
,
2972 no_match_peer_val_cmd
,
2973 "no match peer (A.B.C.D|X:X::X:X)",
2976 "Match peer address\n"
2977 "IPv6 address of peer\n"
2978 "IP address of peer\n")
2980 ALIAS (no_match_peer
,
2981 no_match_peer_local_cmd
,
2982 "no match peer local",
2985 "Match peer address\n"
2986 "Static or Redistributed routes\n")
2988 DEFUN (match_ip_address
,
2989 match_ip_address_cmd
,
2990 "match ip address (<1-199>|<1300-2699>|WORD)",
2993 "Match address of route\n"
2994 "IP access-list number\n"
2995 "IP access-list number (expanded range)\n"
2996 "IP Access-list name\n")
2998 return bgp_route_match_add (vty
, vty
->index
, "ip address", argv
[0],
2999 RMAP_EVENT_FILTER_ADDED
);
3002 DEFUN (no_match_ip_address
,
3003 no_match_ip_address_cmd
,
3004 "no match ip address",
3008 "Match address of route\n")
3011 return bgp_route_match_delete (vty
, vty
->index
, "ip address", NULL
,
3012 RMAP_EVENT_FILTER_DELETED
);
3014 return bgp_route_match_delete (vty
, vty
->index
, "ip address", argv
[0],
3015 RMAP_EVENT_FILTER_DELETED
);
3018 ALIAS (no_match_ip_address
,
3019 no_match_ip_address_val_cmd
,
3020 "no match ip address (<1-199>|<1300-2699>|WORD)",
3024 "Match address of route\n"
3025 "IP access-list number\n"
3026 "IP access-list number (expanded range)\n"
3027 "IP Access-list name\n")
3029 DEFUN (match_ip_next_hop
,
3030 match_ip_next_hop_cmd
,
3031 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
3034 "Match next-hop address of route\n"
3035 "IP access-list number\n"
3036 "IP access-list number (expanded range)\n"
3037 "IP Access-list name\n")
3039 return bgp_route_match_add (vty
, vty
->index
, "ip next-hop", argv
[0],
3040 RMAP_EVENT_FILTER_ADDED
);
3043 DEFUN (no_match_ip_next_hop
,
3044 no_match_ip_next_hop_cmd
,
3045 "no match ip next-hop",
3049 "Match next-hop address of route\n")
3052 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop", NULL
,
3053 RMAP_EVENT_FILTER_DELETED
);
3055 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop", argv
[0],
3056 RMAP_EVENT_FILTER_DELETED
);
3059 ALIAS (no_match_ip_next_hop
,
3060 no_match_ip_next_hop_val_cmd
,
3061 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
3065 "Match next-hop address of route\n"
3066 "IP access-list number\n"
3067 "IP access-list number (expanded range)\n"
3068 "IP Access-list name\n")
3070 /* match probability { */
3072 DEFUN (match_probability
,
3073 match_probability_cmd
,
3074 "match probability <0-100>",
3076 "Match portion of routes defined by percentage value\n"
3077 "Percentage of routes\n")
3079 return bgp_route_match_add (vty
, vty
->index
, "probability", argv
[0],
3080 RMAP_EVENT_MATCH_ADDED
);
3083 DEFUN (no_match_probability
,
3084 no_match_probability_cmd
,
3085 "no match probability",
3088 "Match portion of routes defined by percentage value\n")
3090 return bgp_route_match_delete (vty
, vty
->index
, "probability", argc
? argv
[0] : NULL
,
3091 RMAP_EVENT_MATCH_DELETED
);
3094 ALIAS (no_match_probability
,
3095 no_match_probability_val_cmd
,
3096 "no match probability <1-99>",
3099 "Match portion of routes defined by percentage value\n"
3100 "Percentage of routes\n")
3104 DEFUN (match_ip_route_source
,
3105 match_ip_route_source_cmd
,
3106 "match ip route-source (<1-199>|<1300-2699>|WORD)",
3109 "Match advertising source address of route\n"
3110 "IP access-list number\n"
3111 "IP access-list number (expanded range)\n"
3112 "IP standard access-list name\n")
3114 return bgp_route_match_add (vty
, vty
->index
, "ip route-source", argv
[0],
3115 RMAP_EVENT_FILTER_ADDED
);
3118 DEFUN (no_match_ip_route_source
,
3119 no_match_ip_route_source_cmd
,
3120 "no match ip route-source",
3124 "Match advertising source address of route\n")
3127 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source", NULL
,
3128 RMAP_EVENT_FILTER_DELETED
);
3130 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source",
3131 argv
[0], RMAP_EVENT_FILTER_DELETED
);
3134 ALIAS (no_match_ip_route_source
,
3135 no_match_ip_route_source_val_cmd
,
3136 "no match ip route-source (<1-199>|<1300-2699>|WORD)",
3140 "Match advertising source address of route\n"
3141 "IP access-list number\n"
3142 "IP access-list number (expanded range)\n"
3143 "IP standard access-list name\n")
3145 DEFUN (match_ip_address_prefix_list
,
3146 match_ip_address_prefix_list_cmd
,
3147 "match ip address prefix-list WORD",
3150 "Match address of route\n"
3151 "Match entries of prefix-lists\n"
3152 "IP prefix-list name\n")
3154 return bgp_route_match_add (vty
, vty
->index
, "ip address prefix-list",
3155 argv
[0], RMAP_EVENT_PLIST_ADDED
);
3158 DEFUN (no_match_ip_address_prefix_list
,
3159 no_match_ip_address_prefix_list_cmd
,
3160 "no match ip address prefix-list",
3164 "Match address of route\n"
3165 "Match entries of prefix-lists\n")
3167 return bgp_route_match_delete (vty
, vty
->index
, "ip address prefix-list",
3168 argc
== 0 ? NULL
: argv
[0],
3169 RMAP_EVENT_PLIST_DELETED
);
3172 ALIAS (no_match_ip_address_prefix_list
,
3173 no_match_ip_address_prefix_list_val_cmd
,
3174 "no match ip address prefix-list WORD",
3178 "Match address of route\n"
3179 "Match entries of prefix-lists\n"
3180 "IP prefix-list name\n")
3182 DEFUN (match_ip_next_hop_prefix_list
,
3183 match_ip_next_hop_prefix_list_cmd
,
3184 "match ip next-hop prefix-list WORD",
3187 "Match next-hop address of route\n"
3188 "Match entries of prefix-lists\n"
3189 "IP prefix-list name\n")
3191 return bgp_route_match_add (vty
, vty
->index
, "ip next-hop prefix-list",
3192 argv
[0], RMAP_EVENT_PLIST_ADDED
);
3195 DEFUN (no_match_ip_next_hop_prefix_list
,
3196 no_match_ip_next_hop_prefix_list_cmd
,
3197 "no match ip next-hop prefix-list",
3201 "Match next-hop address of route\n"
3202 "Match entries of prefix-lists\n")
3204 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop prefix-list",
3205 argc
== 0 ? NULL
: argv
[0],
3206 RMAP_EVENT_PLIST_DELETED
);
3209 ALIAS (no_match_ip_next_hop_prefix_list
,
3210 no_match_ip_next_hop_prefix_list_val_cmd
,
3211 "no match ip next-hop prefix-list WORD",
3215 "Match next-hop address of route\n"
3216 "Match entries of prefix-lists\n"
3217 "IP prefix-list name\n")
3219 DEFUN (match_ip_route_source_prefix_list
,
3220 match_ip_route_source_prefix_list_cmd
,
3221 "match ip route-source prefix-list WORD",
3224 "Match advertising source address of route\n"
3225 "Match entries of prefix-lists\n"
3226 "IP prefix-list name\n")
3228 return bgp_route_match_add (vty
, vty
->index
, "ip route-source prefix-list",
3229 argv
[0], RMAP_EVENT_PLIST_ADDED
);
3232 DEFUN (no_match_ip_route_source_prefix_list
,
3233 no_match_ip_route_source_prefix_list_cmd
,
3234 "no match ip route-source prefix-list",
3238 "Match advertising source address of route\n"
3239 "Match entries of prefix-lists\n")
3241 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source prefix-list",
3242 argc
== 0 ? NULL
: argv
[0],
3243 RMAP_EVENT_PLIST_DELETED
);
3246 ALIAS (no_match_ip_route_source_prefix_list
,
3247 no_match_ip_route_source_prefix_list_val_cmd
,
3248 "no match ip route-source prefix-list WORD",
3252 "Match advertising source address of route\n"
3253 "Match entries of prefix-lists\n"
3254 "IP prefix-list name\n")
3256 DEFUN (match_metric
,
3258 "match metric <0-4294967295>",
3260 "Match metric of route\n"
3263 return bgp_route_match_add (vty
, vty
->index
, "metric", argv
[0],
3264 RMAP_EVENT_MATCH_ADDED
);
3267 DEFUN (no_match_metric
,
3268 no_match_metric_cmd
,
3272 "Match metric of route\n")
3274 return bgp_route_match_delete (vty
, vty
->index
, "metric",
3275 argc
== 0 ? NULL
: argv
[0],
3276 RMAP_EVENT_MATCH_DELETED
);
3279 ALIAS (no_match_metric
,
3280 no_match_metric_val_cmd
,
3281 "no match metric <0-4294967295>",
3284 "Match metric of route\n"
3287 DEFUN (match_local_pref
,
3288 match_local_pref_cmd
,
3289 "match local-preference <0-4294967295>",
3291 "Match local-preference of route\n"
3294 return bgp_route_match_add (vty
, vty
->index
, "local-preference", argv
[0],
3295 RMAP_EVENT_MATCH_ADDED
);
3298 DEFUN (no_match_local_pref
,
3299 no_match_local_pref_cmd
,
3300 "no match local-preference",
3303 "Match local preference of route\n")
3305 return bgp_route_match_delete (vty
, vty
->index
, "local-preference",
3306 argc
== 0 ? NULL
: argv
[0],
3307 RMAP_EVENT_MATCH_DELETED
);
3309 return bgp_route_match_delete (vty
, vty
->index
, "local-preference", argv
[0],
3310 RMAP_EVENT_MATCH_DELETED
);
3313 ALIAS (no_match_local_pref
,
3314 no_match_local_pref_val_cmd
,
3315 "no match local-preference <0-4294967295>",
3318 "Match local preference of route\n"
3319 "Local preference value\n")
3321 DEFUN (match_community
,
3322 match_community_cmd
,
3323 "match community (<1-99>|<100-500>|WORD)",
3325 "Match BGP community list\n"
3326 "Community-list number (standard)\n"
3327 "Community-list number (expanded)\n"
3328 "Community-list name\n")
3330 return bgp_route_match_add (vty
, vty
->index
, "community", argv
[0],
3331 RMAP_EVENT_CLIST_ADDED
);
3334 DEFUN (match_community_exact
,
3335 match_community_exact_cmd
,
3336 "match community (<1-99>|<100-500>|WORD) exact-match",
3338 "Match BGP community list\n"
3339 "Community-list number (standard)\n"
3340 "Community-list number (expanded)\n"
3341 "Community-list name\n"
3342 "Do exact matching of communities\n")
3347 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3348 strlen (argv
[0]) + strlen ("exact-match") + 2);
3350 sprintf (argstr
, "%s exact-match", argv
[0]);
3352 ret
= bgp_route_match_add (vty
, vty
->index
, "community", argstr
,
3353 RMAP_EVENT_CLIST_ADDED
);
3355 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3360 DEFUN (no_match_community
,
3361 no_match_community_cmd
,
3362 "no match community",
3365 "Match BGP community list\n")
3367 return bgp_route_match_delete (vty
, vty
->index
, "community", NULL
,
3368 RMAP_EVENT_CLIST_DELETED
);
3371 ALIAS (no_match_community
,
3372 no_match_community_val_cmd
,
3373 "no match community (<1-99>|<100-500>|WORD)",
3376 "Match BGP community list\n"
3377 "Community-list number (standard)\n"
3378 "Community-list number (expanded)\n"
3379 "Community-list name\n")
3381 ALIAS (no_match_community
,
3382 no_match_community_exact_cmd
,
3383 "no match community (<1-99>|<100-500>|WORD) exact-match",
3386 "Match BGP community list\n"
3387 "Community-list number (standard)\n"
3388 "Community-list number (expanded)\n"
3389 "Community-list name\n"
3390 "Do exact matching of communities\n")
3392 DEFUN (match_ecommunity
,
3393 match_ecommunity_cmd
,
3394 "match extcommunity (<1-99>|<100-500>|WORD)",
3396 "Match BGP/VPN extended community list\n"
3397 "Extended community-list number (standard)\n"
3398 "Extended community-list number (expanded)\n"
3399 "Extended community-list name\n")
3401 return bgp_route_match_add (vty
, vty
->index
, "extcommunity", argv
[0],
3402 RMAP_EVENT_ECLIST_ADDED
);
3405 DEFUN (no_match_ecommunity
,
3406 no_match_ecommunity_cmd
,
3407 "no match extcommunity",
3410 "Match BGP/VPN extended community list\n")
3412 return bgp_route_match_delete (vty
, vty
->index
, "extcommunity", NULL
,
3413 RMAP_EVENT_ECLIST_DELETED
);
3416 ALIAS (no_match_ecommunity
,
3417 no_match_ecommunity_val_cmd
,
3418 "no match extcommunity (<1-99>|<100-500>|WORD)",
3421 "Match BGP/VPN extended community list\n"
3422 "Extended community-list number (standard)\n"
3423 "Extended community-list number (expanded)\n"
3424 "Extended community-list name\n")
3426 DEFUN (match_aspath
,
3428 "match as-path WORD",
3430 "Match BGP AS path list\n"
3431 "AS path access-list name\n")
3433 return bgp_route_match_add (vty
, vty
->index
, "as-path", argv
[0],
3434 RMAP_EVENT_ASLIST_ADDED
);
3437 DEFUN (no_match_aspath
,
3438 no_match_aspath_cmd
,
3442 "Match BGP AS path list\n")
3444 return bgp_route_match_delete (vty
, vty
->index
, "as-path", NULL
,
3445 RMAP_EVENT_ASLIST_DELETED
);
3448 ALIAS (no_match_aspath
,
3449 no_match_aspath_val_cmd
,
3450 "no match as-path WORD",
3453 "Match BGP AS path list\n"
3454 "AS path access-list name\n")
3456 DEFUN (match_origin
,
3458 "match origin (egp|igp|incomplete)",
3463 "unknown heritage\n")
3465 if (strncmp (argv
[0], "igp", 2) == 0)
3466 return bgp_route_match_add (vty
, vty
->index
, "origin", "igp",
3467 RMAP_EVENT_MATCH_ADDED
);
3468 if (strncmp (argv
[0], "egp", 1) == 0)
3469 return bgp_route_match_add (vty
, vty
->index
, "origin", "egp",
3470 RMAP_EVENT_MATCH_ADDED
);
3471 if (strncmp (argv
[0], "incomplete", 2) == 0)
3472 return bgp_route_match_add (vty
, vty
->index
, "origin", "incomplete",
3473 RMAP_EVENT_MATCH_ADDED
);
3478 DEFUN (no_match_origin
,
3479 no_match_origin_cmd
,
3483 "BGP origin code\n")
3485 return bgp_route_match_delete (vty
, vty
->index
, "origin", NULL
,
3486 RMAP_EVENT_MATCH_DELETED
);
3489 ALIAS (no_match_origin
,
3490 no_match_origin_val_cmd
,
3491 "no match origin (egp|igp|incomplete)",
3497 "unknown heritage\n")
3499 DEFUN (match_interface
,
3500 match_interface_cmd
,
3501 "match interface WORD",
3503 "Match first hop interface of route\n"
3506 return bgp_route_match_add (vty
, vty
->index
, "interface", argv
[0],
3507 RMAP_EVENT_MATCH_ADDED
);
3510 DEFUN (no_match_interface
,
3511 no_match_interface_cmd
,
3512 "no match interface",
3515 "Match first hop interface of route\n")
3518 return bgp_route_match_delete (vty
, vty
->index
, "interface", NULL
,
3519 RMAP_EVENT_MATCH_DELETED
);
3521 return bgp_route_match_delete (vty
, vty
->index
, "interface", argv
[0],
3522 RMAP_EVENT_MATCH_DELETED
);
3525 ALIAS (no_match_interface
,
3526 no_match_interface_val_cmd
,
3527 "no match interface WORD",
3530 "Match first hop interface of route\n"
3535 "match tag <1-65535>",
3537 "Match tag of route\n"
3540 return bgp_route_match_add (vty
, vty
->index
, "tag", argv
[0],
3541 RMAP_EVENT_MATCH_ADDED
);
3544 DEFUN (no_match_tag
,
3549 "Match tag of route\n")
3552 return bgp_route_match_delete (vty
, vty
->index
, "tag", NULL
,
3553 RMAP_EVENT_MATCH_DELETED
);
3555 return bgp_route_match_delete (vty
, vty
->index
, "tag", argv
[0],
3556 RMAP_EVENT_MATCH_DELETED
);
3559 ALIAS (no_match_tag
,
3560 no_match_tag_val_cmd
,
3561 "no match tag <1-65535>",
3564 "Match tag of route\n"
3568 DEFUN (set_ip_nexthop
,
3570 "set ip next-hop A.B.C.D",
3573 "Next hop address\n"
3574 "IP address of next hop\n")
3579 ret
= str2sockunion (argv
[0], &su
);
3582 vty_out (vty
, "%% Malformed nexthop address%s", VTY_NEWLINE
);
3585 if (su
.sin
.sin_addr
.s_addr
== 0 ||
3586 IPV4_CLASS_DE(su
.sin
.sin_addr
.s_addr
))
3588 vty_out (vty
, "%% nexthop address cannot be 0.0.0.0, multicast "
3589 "or reserved%s", VTY_NEWLINE
);
3593 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", argv
[0]);
3596 DEFUN (set_ip_nexthop_peer
,
3597 set_ip_nexthop_peer_cmd
,
3598 "set ip next-hop peer-address",
3601 "Next hop address\n"
3602 "Use peer address (for BGP only)\n")
3604 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", "peer-address");
3607 DEFUN (set_ip_nexthop_unchanged
,
3608 set_ip_nexthop_unchanged_cmd
,
3609 "set ip next-hop unchanged",
3612 "Next hop address\n"
3613 "Don't modify existing Next hop address\n")
3615 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", "unchanged");
3618 DEFUN (no_set_ip_nexthop
,
3619 no_set_ip_nexthop_cmd
,
3620 "no set ip next-hop",
3623 "Next hop address\n")
3626 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", NULL
);
3628 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", argv
[0]);
3631 ALIAS (no_set_ip_nexthop
,
3632 no_set_ip_nexthop_val_cmd
,
3633 "no set ip next-hop A.B.C.D",
3637 "Next hop address\n"
3638 "IP address of next hop\n")
3640 ALIAS (no_set_ip_nexthop
,
3641 no_set_ip_nexthop_peer_cmd
,
3642 "no set ip next-hop peer-address",
3646 "Next hop address\n"
3647 "Use peer address (for BGP only)\n")
3651 "set metric <0-4294967295>",
3653 "Metric value for destination routing protocol\n"
3656 return bgp_route_set_add (vty
, vty
->index
, "metric", argv
[0]);
3660 set_metric_addsub_cmd
,
3661 "set metric <+/-metric>",
3663 "Metric value for destination routing protocol\n"
3664 "Add or subtract metric\n")
3668 "set metric (rtt|+rtt|-rtt)",
3670 "Metric value for destination routing protocol\n"
3671 "Assign round trip time\n"
3672 "Add round trip time\n"
3673 "Subtract round trip time\n")
3675 DEFUN (no_set_metric
,
3680 "Metric value for destination routing protocol\n")
3683 return bgp_route_set_delete (vty
, vty
->index
, "metric", NULL
);
3685 return bgp_route_set_delete (vty
, vty
->index
, "metric", argv
[0]);
3688 ALIAS (no_set_metric
,
3689 no_set_metric_val_cmd
,
3690 "no set metric <0-4294967295>",
3693 "Metric value for destination routing protocol\n"
3696 DEFUN (set_local_pref
,
3698 "set local-preference <0-4294967295>",
3700 "BGP local preference path attribute\n"
3701 "Preference value\n")
3703 return bgp_route_set_add (vty
, vty
->index
, "local-preference", argv
[0]);
3706 DEFUN (no_set_local_pref
,
3707 no_set_local_pref_cmd
,
3708 "no set local-preference",
3711 "BGP local preference path attribute\n")
3714 return bgp_route_set_delete (vty
, vty
->index
, "local-preference", NULL
);
3716 return bgp_route_set_delete (vty
, vty
->index
, "local-preference", argv
[0]);
3719 ALIAS (no_set_local_pref
,
3720 no_set_local_pref_val_cmd
,
3721 "no set local-preference <0-4294967295>",
3724 "BGP local preference path attribute\n"
3725 "Preference value\n")
3729 "set weight <0-4294967295>",
3731 "BGP weight for routing table\n"
3734 return bgp_route_set_add (vty
, vty
->index
, "weight", argv
[0]);
3737 DEFUN (no_set_weight
,
3742 "BGP weight for routing table\n")
3745 return bgp_route_set_delete (vty
, vty
->index
, "weight", NULL
);
3747 return bgp_route_set_delete (vty
, vty
->index
, "weight", argv
[0]);
3750 ALIAS (no_set_weight
,
3751 no_set_weight_val_cmd
,
3752 "no set weight <0-4294967295>",
3755 "BGP weight for routing table\n"
3758 DEFUN (set_aspath_prepend
,
3759 set_aspath_prepend_cmd
,
3760 "set as-path prepend ." CMD_AS_RANGE
,
3762 "Transform BGP AS_PATH attribute\n"
3763 "Prepend to the as-path\n"
3769 str
= argv_concat (argv
, argc
, 0);
3770 ret
= bgp_route_set_add (vty
, vty
->index
, "as-path prepend", str
);
3771 XFREE (MTYPE_TMP
, str
);
3776 ALIAS (set_aspath_prepend
,
3777 set_aspath_prepend_lastas_cmd
,
3778 "set as-path prepend (last-as) <1-10>",
3780 "Transform BGP AS_PATH attribute\n"
3781 "Prepend to the as-path\n"
3782 "Use the peer's AS-number\n"
3783 "Number of times to insert")
3785 DEFUN (no_set_aspath_prepend
,
3786 no_set_aspath_prepend_cmd
,
3787 "no set as-path prepend",
3790 "Transform BGP AS_PATH attribute\n"
3791 "Prepend to the as-path\n")
3797 return bgp_route_set_delete (vty
, vty
->index
, "as-path prepend", NULL
);
3799 str
= argv_concat (argv
, argc
, 0);
3800 ret
= bgp_route_set_delete (vty
, vty
->index
, "as-path prepend", str
);
3801 XFREE (MTYPE_TMP
, str
);
3805 ALIAS (no_set_aspath_prepend
,
3806 no_set_aspath_prepend_val_cmd
,
3807 "no set as-path prepend ." CMD_AS_RANGE
,
3810 "Transform BGP AS_PATH attribute\n"
3811 "Prepend to the as-path\n"
3814 DEFUN (set_aspath_exclude
,
3815 set_aspath_exclude_cmd
,
3816 "set as-path exclude ." CMD_AS_RANGE
,
3818 "Transform BGP AS-path attribute\n"
3819 "Exclude from the as-path\n"
3825 str
= argv_concat (argv
, argc
, 0);
3826 ret
= bgp_route_set_add (vty
, vty
->index
, "as-path exclude", str
);
3827 XFREE (MTYPE_TMP
, str
);
3831 DEFUN (no_set_aspath_exclude
,
3832 no_set_aspath_exclude_cmd
,
3833 "no set as-path exclude",
3836 "Transform BGP AS_PATH attribute\n"
3837 "Exclude from the as-path\n")
3843 return bgp_route_set_delete (vty
, vty
->index
, "as-path exclude", NULL
);
3845 str
= argv_concat (argv
, argc
, 0);
3846 ret
= bgp_route_set_delete (vty
, vty
->index
, "as-path exclude", str
);
3847 XFREE (MTYPE_TMP
, str
);
3851 ALIAS (no_set_aspath_exclude
,
3852 no_set_aspath_exclude_val_cmd
,
3853 "no set as-path exclude ." CMD_AS_RANGE
,
3856 "Transform BGP AS_PATH attribute\n"
3857 "Exclude from the as-path\n"
3860 DEFUN (set_community
,
3862 "set community .AA:NN",
3864 "BGP community attribute\n"
3871 struct community
*com
= NULL
;
3876 b
= buffer_new (1024);
3878 for (i
= 0; i
< argc
; i
++)
3880 if (strncmp (argv
[i
], "additive", strlen (argv
[i
])) == 0)
3887 buffer_putc (b
, ' ');
3891 if (strncmp (argv
[i
], "internet", strlen (argv
[i
])) == 0)
3893 buffer_putstr (b
, "internet");
3896 if (strncmp (argv
[i
], "local-AS", strlen (argv
[i
])) == 0)
3898 buffer_putstr (b
, "local-AS");
3901 if (strncmp (argv
[i
], "no-a", strlen ("no-a")) == 0
3902 && strncmp (argv
[i
], "no-advertise", strlen (argv
[i
])) == 0)
3904 buffer_putstr (b
, "no-advertise");
3907 if (strncmp (argv
[i
], "no-e", strlen ("no-e"))== 0
3908 && strncmp (argv
[i
], "no-export", strlen (argv
[i
])) == 0)
3910 buffer_putstr (b
, "no-export");
3913 buffer_putstr (b
, argv
[i
]);
3915 buffer_putc (b
, '\0');
3917 /* Fetch result string then compile it to communities attribute. */
3918 str
= buffer_getstr (b
);
3923 com
= community_str2com (str
);
3924 XFREE (MTYPE_TMP
, str
);
3927 /* Can't compile user input into communities attribute. */
3930 vty_out (vty
, "%% Malformed communities attribute%s", VTY_NEWLINE
);
3934 /* Set communites attribute string. */
3935 str
= community_str (com
);
3939 argstr
= XCALLOC (MTYPE_TMP
, strlen (str
) + strlen (" additive") + 1);
3940 strcpy (argstr
, str
);
3941 strcpy (argstr
+ strlen (str
), " additive");
3942 ret
= bgp_route_set_add (vty
, vty
->index
, "community", argstr
);
3943 XFREE (MTYPE_TMP
, argstr
);
3946 ret
= bgp_route_set_add (vty
, vty
->index
, "community", str
);
3948 community_free (com
);
3953 DEFUN (set_community_none
,
3954 set_community_none_cmd
,
3955 "set community none",
3957 "BGP community attribute\n"
3958 "No community attribute\n")
3960 return bgp_route_set_add (vty
, vty
->index
, "community", "none");
3963 DEFUN (no_set_community
,
3964 no_set_community_cmd
,
3968 "BGP community attribute\n")
3970 return bgp_route_set_delete (vty
, vty
->index
, "community", NULL
);
3973 ALIAS (no_set_community
,
3974 no_set_community_val_cmd
,
3975 "no set community .AA:NN",
3978 "BGP community attribute\n"
3981 ALIAS (no_set_community
,
3982 no_set_community_none_cmd
,
3983 "no set community none",
3986 "BGP community attribute\n"
3987 "No community attribute\n")
3989 DEFUN (set_community_delete
,
3990 set_community_delete_cmd
,
3991 "set comm-list (<1-99>|<100-500>|WORD) delete",
3993 "set BGP community list (for deletion)\n"
3994 "Community-list number (standard)\n"
3995 "Community-list number (expanded)\n"
3996 "Community-list name\n"
3997 "Delete matching communities\n")
4001 str
= XCALLOC (MTYPE_TMP
, strlen (argv
[0]) + strlen (" delete") + 1);
4002 strcpy (str
, argv
[0]);
4003 strcpy (str
+ strlen (argv
[0]), " delete");
4005 bgp_route_set_add (vty
, vty
->index
, "comm-list", str
);
4007 XFREE (MTYPE_TMP
, str
);
4011 DEFUN (no_set_community_delete
,
4012 no_set_community_delete_cmd
,
4016 "set BGP community list (for deletion)\n")
4018 return bgp_route_set_delete (vty
, vty
->index
, "comm-list", NULL
);
4021 ALIAS (no_set_community_delete
,
4022 no_set_community_delete_val_cmd
,
4023 "no set comm-list (<1-99>|<100-500>|WORD) delete",
4026 "set BGP community list (for deletion)\n"
4027 "Community-list number (standard)\n"
4028 "Community-list number (expanded)\n"
4029 "Community-list name\n"
4030 "Delete matching communities\n")
4032 DEFUN (set_ecommunity_rt
,
4033 set_ecommunity_rt_cmd
,
4034 "set extcommunity rt .ASN:nn_or_IP-address:nn",
4036 "BGP extended community attribute\n"
4037 "Route Target extended community\n"
4038 "VPN extended community\n")
4043 str
= argv_concat (argv
, argc
, 0);
4044 ret
= bgp_route_set_add (vty
, vty
->index
, "extcommunity rt", str
);
4045 XFREE (MTYPE_TMP
, str
);
4050 DEFUN (no_set_ecommunity_rt
,
4051 no_set_ecommunity_rt_cmd
,
4052 "no set extcommunity rt",
4055 "BGP extended community attribute\n"
4056 "Route Target extended community\n")
4058 return bgp_route_set_delete (vty
, vty
->index
, "extcommunity rt", NULL
);
4061 ALIAS (no_set_ecommunity_rt
,
4062 no_set_ecommunity_rt_val_cmd
,
4063 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
4066 "BGP extended community attribute\n"
4067 "Route Target extended community\n"
4068 "VPN extended community\n")
4070 DEFUN (set_ecommunity_soo
,
4071 set_ecommunity_soo_cmd
,
4072 "set extcommunity soo .ASN:nn_or_IP-address:nn",
4074 "BGP extended community attribute\n"
4075 "Site-of-Origin extended community\n"
4076 "VPN extended community\n")
4081 str
= argv_concat (argv
, argc
, 0);
4082 ret
= bgp_route_set_add (vty
, vty
->index
, "extcommunity soo", str
);
4083 XFREE (MTYPE_TMP
, str
);
4087 DEFUN (no_set_ecommunity_soo
,
4088 no_set_ecommunity_soo_cmd
,
4089 "no set extcommunity soo",
4092 "BGP extended community attribute\n"
4093 "Site-of-Origin extended community\n")
4095 return bgp_route_set_delete (vty
, vty
->index
, "extcommunity soo", NULL
);
4098 ALIAS (no_set_ecommunity_soo
,
4099 no_set_ecommunity_soo_val_cmd
,
4100 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
4103 "BGP extended community attribute\n"
4104 "Site-of-Origin extended community\n"
4105 "VPN extended community\n")
4109 "set origin (egp|igp|incomplete)",
4114 "unknown heritage\n")
4116 if (strncmp (argv
[0], "igp", 2) == 0)
4117 return bgp_route_set_add (vty
, vty
->index
, "origin", "igp");
4118 if (strncmp (argv
[0], "egp", 1) == 0)
4119 return bgp_route_set_add (vty
, vty
->index
, "origin", "egp");
4120 if (strncmp (argv
[0], "incomplete", 2) == 0)
4121 return bgp_route_set_add (vty
, vty
->index
, "origin", "incomplete");
4126 DEFUN (no_set_origin
,
4131 "BGP origin code\n")
4133 return bgp_route_set_delete (vty
, vty
->index
, "origin", NULL
);
4136 ALIAS (no_set_origin
,
4137 no_set_origin_val_cmd
,
4138 "no set origin (egp|igp|incomplete)",
4144 "unknown heritage\n")
4146 DEFUN (set_atomic_aggregate
,
4147 set_atomic_aggregate_cmd
,
4148 "set atomic-aggregate",
4150 "BGP atomic aggregate attribute\n" )
4152 return bgp_route_set_add (vty
, vty
->index
, "atomic-aggregate", NULL
);
4155 DEFUN (no_set_atomic_aggregate
,
4156 no_set_atomic_aggregate_cmd
,
4157 "no set atomic-aggregate",
4160 "BGP atomic aggregate attribute\n" )
4162 return bgp_route_set_delete (vty
, vty
->index
, "atomic-aggregate", NULL
);
4165 DEFUN (set_aggregator_as
,
4166 set_aggregator_as_cmd
,
4167 "set aggregator as " CMD_AS_RANGE
" A.B.C.D",
4169 "BGP aggregator attribute\n"
4170 "AS number of aggregator\n"
4172 "IP address of aggregator\n")
4175 struct in_addr address
;
4178 ret
= inet_aton (argv
[1], &address
);
4181 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
4185 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
4186 strlen (argv
[0]) + strlen (argv
[1]) + 2);
4188 sprintf (argstr
, "%s %s", argv
[0], argv
[1]);
4190 ret
= bgp_route_set_add (vty
, vty
->index
, "aggregator as", argstr
);
4192 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4197 DEFUN (no_set_aggregator_as
,
4198 no_set_aggregator_as_cmd
,
4199 "no set aggregator as",
4202 "BGP aggregator attribute\n"
4203 "AS number of aggregator\n")
4206 struct in_addr address
;
4210 return bgp_route_set_delete (vty
, vty
->index
, "aggregator as", NULL
);
4212 ret
= inet_aton (argv
[1], &address
);
4215 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
4219 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
4220 strlen (argv
[0]) + strlen (argv
[1]) + 2);
4222 sprintf (argstr
, "%s %s", argv
[0], argv
[1]);
4224 ret
= bgp_route_set_delete (vty
, vty
->index
, "aggregator as", argstr
);
4226 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4231 ALIAS (no_set_aggregator_as
,
4232 no_set_aggregator_as_val_cmd
,
4233 "no set aggregator as " CMD_AS_RANGE
" A.B.C.D",
4236 "BGP aggregator attribute\n"
4237 "AS number of aggregator\n"
4239 "IP address of aggregator\n")
4243 "set tag <1-65535>",
4245 "Tag value for routing protocol\n"
4248 return bgp_route_set_add (vty
, vty
->index
, "tag", argv
[0]);
4256 "Tag value for routing protocol\n")
4259 bgp_route_set_delete(vty
, vty
->index
, "tag", NULL
);
4261 return bgp_route_set_delete (vty
, vty
->index
, "tag", argv
[0]);
4266 "no set tag <1-65535>",
4269 "Tag value for routing protocol\n"
4274 DEFUN (match_ipv6_address
,
4275 match_ipv6_address_cmd
,
4276 "match ipv6 address WORD",
4279 "Match IPv6 address of route\n"
4280 "IPv6 access-list name\n")
4282 return bgp_route_match_add (vty
, vty
->index
, "ipv6 address", argv
[0],
4283 RMAP_EVENT_FILTER_ADDED
);
4286 DEFUN (no_match_ipv6_address
,
4287 no_match_ipv6_address_cmd
,
4288 "no match ipv6 address WORD",
4292 "Match IPv6 address of route\n"
4293 "IPv6 access-list name\n")
4295 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 address", argv
[0],
4296 RMAP_EVENT_FILTER_DELETED
);
4299 DEFUN (match_ipv6_next_hop
,
4300 match_ipv6_next_hop_cmd
,
4301 "match ipv6 next-hop X:X::X:X",
4304 "Match IPv6 next-hop address of route\n"
4305 "IPv6 address of next hop\n")
4307 return bgp_route_match_add (vty
, vty
->index
, "ipv6 next-hop", argv
[0],
4308 RMAP_EVENT_MATCH_ADDED
);
4311 DEFUN (no_match_ipv6_next_hop
,
4312 no_match_ipv6_next_hop_cmd
,
4313 "no match ipv6 next-hop X:X::X:X",
4317 "Match IPv6 next-hop address of route\n"
4318 "IPv6 address of next hop\n")
4320 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 next-hop", argv
[0],
4321 RMAP_EVENT_MATCH_DELETED
);
4324 DEFUN (match_ipv6_address_prefix_list
,
4325 match_ipv6_address_prefix_list_cmd
,
4326 "match ipv6 address prefix-list WORD",
4329 "Match address of route\n"
4330 "Match entries of prefix-lists\n"
4331 "IP prefix-list name\n")
4333 return bgp_route_match_add (vty
, vty
->index
, "ipv6 address prefix-list",
4334 argv
[0], RMAP_EVENT_PLIST_ADDED
);
4337 DEFUN (no_match_ipv6_address_prefix_list
,
4338 no_match_ipv6_address_prefix_list_cmd
,
4339 "no match ipv6 address prefix-list WORD",
4343 "Match address of route\n"
4344 "Match entries of prefix-lists\n"
4345 "IP prefix-list name\n")
4347 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 address prefix-list",
4348 argv
[0], RMAP_EVENT_PLIST_DELETED
);
4351 DEFUN (set_ipv6_nexthop_peer
,
4352 set_ipv6_nexthop_peer_cmd
,
4353 "set ipv6 next-hop peer-address",
4356 "Next hop address\n"
4357 "Use peer address (for BGP only)\n")
4359 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop peer-address", NULL
);
4362 DEFUN (no_set_ipv6_nexthop_peer
,
4363 no_set_ipv6_nexthop_peer_cmd
,
4364 "no set ipv6 next-hop peer-address",
4368 "IPv6 next-hop address\n"
4371 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop peer-address", NULL
);
4374 DEFUN (set_ipv6_nexthop_global
,
4375 set_ipv6_nexthop_global_cmd
,
4376 "set ipv6 next-hop global X:X::X:X",
4379 "IPv6 next-hop address\n"
4380 "IPv6 global address\n"
4381 "IPv6 address of next hop\n")
4383 struct in6_addr addr
;
4386 ret
= inet_pton (AF_INET6
, argv
[0], &addr
);
4389 vty_out (vty
, "%% Malformed nexthop address%s", VTY_NEWLINE
);
4392 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) ||
4393 IN6_IS_ADDR_LOOPBACK(&addr
) ||
4394 IN6_IS_ADDR_MULTICAST(&addr
) ||
4395 IN6_IS_ADDR_LINKLOCAL(&addr
))
4397 vty_out (vty
, "%% Invalid global nexthop address%s", VTY_NEWLINE
);
4401 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop global", argv
[0]);
4404 DEFUN (no_set_ipv6_nexthop_global
,
4405 no_set_ipv6_nexthop_global_cmd
,
4406 "no set ipv6 next-hop global",
4410 "IPv6 next-hop address\n"
4411 "IPv6 global address\n")
4414 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop global", NULL
);
4416 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop global", argv
[0]);
4419 ALIAS (no_set_ipv6_nexthop_global
,
4420 no_set_ipv6_nexthop_global_val_cmd
,
4421 "no set ipv6 next-hop global X:X::X:X",
4425 "IPv6 next-hop address\n"
4426 "IPv6 global address\n"
4427 "IPv6 address of next hop\n")
4429 DEFUN (set_ipv6_nexthop_local
,
4430 set_ipv6_nexthop_local_cmd
,
4431 "set ipv6 next-hop local X:X::X:X",
4434 "IPv6 next-hop address\n"
4435 "IPv6 local address\n"
4436 "IPv6 address of next hop\n")
4438 struct in6_addr addr
;
4441 ret
= inet_pton (AF_INET6
, argv
[0], &addr
);
4444 vty_out (vty
, "%% Malformed nexthop address%s", VTY_NEWLINE
);
4447 if (!IN6_IS_ADDR_LINKLOCAL(&addr
))
4449 vty_out (vty
, "%% Invalid link-local nexthop address%s", VTY_NEWLINE
);
4453 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop local", argv
[0]);
4456 DEFUN (no_set_ipv6_nexthop_local
,
4457 no_set_ipv6_nexthop_local_cmd
,
4458 "no set ipv6 next-hop local",
4462 "IPv6 next-hop address\n"
4463 "IPv6 local address\n")
4466 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop local", NULL
);
4468 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop local", argv
[0]);
4471 ALIAS (no_set_ipv6_nexthop_local
,
4472 no_set_ipv6_nexthop_local_val_cmd
,
4473 "no set ipv6 next-hop local X:X::X:X",
4477 "IPv6 next-hop address\n"
4478 "IPv6 local address\n"
4479 "IPv6 address of next hop\n")
4480 #endif /* HAVE_IPV6 */
4482 DEFUN (set_vpnv4_nexthop
,
4483 set_vpnv4_nexthop_cmd
,
4484 "set vpnv4 next-hop A.B.C.D",
4486 "VPNv4 information\n"
4487 "VPNv4 next-hop address\n"
4488 "IP address of next hop\n")
4490 return bgp_route_set_add (vty
, vty
->index
, "vpnv4 next-hop", argv
[0]);
4493 DEFUN (no_set_vpnv4_nexthop
,
4494 no_set_vpnv4_nexthop_cmd
,
4495 "no set vpnv4 next-hop",
4498 "VPNv4 information\n"
4499 "VPNv4 next-hop address\n")
4502 return bgp_route_set_delete (vty
, vty
->index
, "vpnv4 next-hop", NULL
);
4504 return bgp_route_set_delete (vty
, vty
->index
, "vpnv4 next-hop", argv
[0]);
4507 ALIAS (no_set_vpnv4_nexthop
,
4508 no_set_vpnv4_nexthop_val_cmd
,
4509 "no set vpnv4 next-hop A.B.C.D",
4512 "VPNv4 information\n"
4513 "VPNv4 next-hop address\n"
4514 "IP address of next hop\n")
4516 DEFUN (set_originator_id
,
4517 set_originator_id_cmd
,
4518 "set originator-id A.B.C.D",
4520 "BGP originator ID attribute\n"
4521 "IP address of originator\n")
4523 return bgp_route_set_add (vty
, vty
->index
, "originator-id", argv
[0]);
4526 DEFUN (no_set_originator_id
,
4527 no_set_originator_id_cmd
,
4528 "no set originator-id",
4531 "BGP originator ID attribute\n")
4534 return bgp_route_set_delete (vty
, vty
->index
, "originator-id", NULL
);
4536 return bgp_route_set_delete (vty
, vty
->index
, "originator-id", argv
[0]);
4539 ALIAS (no_set_originator_id
,
4540 no_set_originator_id_val_cmd
,
4541 "no set originator-id A.B.C.D",
4544 "BGP originator ID attribute\n"
4545 "IP address of originator\n")
4547 /* Initialization of route map. */
4549 bgp_route_map_init (void)
4552 route_map_init_vty ();
4553 route_map_add_hook (bgp_route_map_add
);
4554 route_map_delete_hook (bgp_route_map_delete
);
4555 route_map_event_hook (bgp_route_map_event
);
4557 route_map_install_match (&route_match_peer_cmd
);
4558 route_map_install_match (&route_match_local_pref_cmd
);
4559 route_map_install_match (&route_match_ip_address_cmd
);
4560 route_map_install_match (&route_match_ip_next_hop_cmd
);
4561 route_map_install_match (&route_match_ip_route_source_cmd
);
4562 route_map_install_match (&route_match_ip_address_prefix_list_cmd
);
4563 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd
);
4564 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd
);
4565 route_map_install_match (&route_match_aspath_cmd
);
4566 route_map_install_match (&route_match_community_cmd
);
4567 route_map_install_match (&route_match_ecommunity_cmd
);
4568 route_map_install_match (&route_match_local_pref_cmd
);
4569 route_map_install_match (&route_match_metric_cmd
);
4570 route_map_install_match (&route_match_origin_cmd
);
4571 route_map_install_match (&route_match_probability_cmd
);
4572 route_map_install_match (&route_match_interface_cmd
);
4573 route_map_install_match (&route_match_tag_cmd
);
4575 route_map_install_set (&route_set_ip_nexthop_cmd
);
4576 route_map_install_set (&route_set_local_pref_cmd
);
4577 route_map_install_set (&route_set_weight_cmd
);
4578 route_map_install_set (&route_set_metric_cmd
);
4579 route_map_install_set (&route_set_aspath_prepend_cmd
);
4580 route_map_install_set (&route_set_aspath_exclude_cmd
);
4581 route_map_install_set (&route_set_origin_cmd
);
4582 route_map_install_set (&route_set_atomic_aggregate_cmd
);
4583 route_map_install_set (&route_set_aggregator_as_cmd
);
4584 route_map_install_set (&route_set_community_cmd
);
4585 route_map_install_set (&route_set_community_delete_cmd
);
4586 route_map_install_set (&route_set_vpnv4_nexthop_cmd
);
4587 route_map_install_set (&route_set_originator_id_cmd
);
4588 route_map_install_set (&route_set_ecommunity_rt_cmd
);
4589 route_map_install_set (&route_set_ecommunity_soo_cmd
);
4590 route_map_install_set (&route_set_tag_cmd
);
4592 install_element (RMAP_NODE
, &match_peer_cmd
);
4593 install_element (RMAP_NODE
, &match_peer_local_cmd
);
4594 install_element (RMAP_NODE
, &no_match_peer_cmd
);
4595 install_element (RMAP_NODE
, &no_match_peer_val_cmd
);
4596 install_element (RMAP_NODE
, &no_match_peer_local_cmd
);
4597 install_element (RMAP_NODE
, &match_ip_address_cmd
);
4598 install_element (RMAP_NODE
, &no_match_ip_address_cmd
);
4599 install_element (RMAP_NODE
, &no_match_ip_address_val_cmd
);
4600 install_element (RMAP_NODE
, &match_ip_next_hop_cmd
);
4601 install_element (RMAP_NODE
, &no_match_ip_next_hop_cmd
);
4602 install_element (RMAP_NODE
, &no_match_ip_next_hop_val_cmd
);
4603 install_element (RMAP_NODE
, &match_ip_route_source_cmd
);
4604 install_element (RMAP_NODE
, &no_match_ip_route_source_cmd
);
4605 install_element (RMAP_NODE
, &no_match_ip_route_source_val_cmd
);
4606 install_element (RMAP_NODE
, &match_ip_address_prefix_list_cmd
);
4607 install_element (RMAP_NODE
, &no_match_ip_address_prefix_list_cmd
);
4608 install_element (RMAP_NODE
, &no_match_ip_address_prefix_list_val_cmd
);
4609 install_element (RMAP_NODE
, &match_ip_next_hop_prefix_list_cmd
);
4610 install_element (RMAP_NODE
, &no_match_ip_next_hop_prefix_list_cmd
);
4611 install_element (RMAP_NODE
, &no_match_ip_next_hop_prefix_list_val_cmd
);
4612 install_element (RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
4613 install_element (RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
4614 install_element (RMAP_NODE
, &no_match_ip_route_source_prefix_list_val_cmd
);
4616 install_element (RMAP_NODE
, &match_aspath_cmd
);
4617 install_element (RMAP_NODE
, &no_match_aspath_cmd
);
4618 install_element (RMAP_NODE
, &no_match_aspath_val_cmd
);
4619 install_element (RMAP_NODE
, &match_metric_cmd
);
4620 install_element (RMAP_NODE
, &no_match_metric_cmd
);
4621 install_element (RMAP_NODE
, &no_match_metric_val_cmd
);
4622 install_element (RMAP_NODE
, &match_local_pref_cmd
);
4623 install_element (RMAP_NODE
, &no_match_local_pref_cmd
);
4624 install_element (RMAP_NODE
, &no_match_local_pref_val_cmd
);
4625 install_element (RMAP_NODE
, &match_community_cmd
);
4626 install_element (RMAP_NODE
, &match_community_exact_cmd
);
4627 install_element (RMAP_NODE
, &no_match_community_cmd
);
4628 install_element (RMAP_NODE
, &no_match_community_val_cmd
);
4629 install_element (RMAP_NODE
, &no_match_community_exact_cmd
);
4630 install_element (RMAP_NODE
, &match_ecommunity_cmd
);
4631 install_element (RMAP_NODE
, &no_match_ecommunity_cmd
);
4632 install_element (RMAP_NODE
, &no_match_ecommunity_val_cmd
);
4633 install_element (RMAP_NODE
, &match_origin_cmd
);
4634 install_element (RMAP_NODE
, &no_match_origin_cmd
);
4635 install_element (RMAP_NODE
, &no_match_origin_val_cmd
);
4636 install_element (RMAP_NODE
, &match_probability_cmd
);
4637 install_element (RMAP_NODE
, &no_match_probability_cmd
);
4638 install_element (RMAP_NODE
, &no_match_probability_val_cmd
);
4639 install_element (RMAP_NODE
, &match_interface_cmd
);
4640 install_element (RMAP_NODE
, &no_match_interface_cmd
);
4641 install_element (RMAP_NODE
, &no_match_interface_val_cmd
);
4642 install_element (RMAP_NODE
, &match_tag_cmd
);
4643 install_element (RMAP_NODE
, &no_match_tag_cmd
);
4644 install_element (RMAP_NODE
, &no_match_tag_val_cmd
);
4646 install_element (RMAP_NODE
, &set_ip_nexthop_cmd
);
4647 install_element (RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
4648 install_element (RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
4649 install_element (RMAP_NODE
, &no_set_ip_nexthop_cmd
);
4650 install_element (RMAP_NODE
, &no_set_ip_nexthop_val_cmd
);
4651 install_element (RMAP_NODE
, &no_set_ip_nexthop_peer_cmd
);
4652 install_element (RMAP_NODE
, &set_local_pref_cmd
);
4653 install_element (RMAP_NODE
, &no_set_local_pref_cmd
);
4654 install_element (RMAP_NODE
, &no_set_local_pref_val_cmd
);
4655 install_element (RMAP_NODE
, &set_weight_cmd
);
4656 install_element (RMAP_NODE
, &no_set_weight_cmd
);
4657 install_element (RMAP_NODE
, &no_set_weight_val_cmd
);
4658 install_element (RMAP_NODE
, &set_metric_cmd
);
4659 install_element (RMAP_NODE
, &set_metric_addsub_cmd
);
4660 install_element (RMAP_NODE
, &set_metric_rtt_cmd
);
4661 install_element (RMAP_NODE
, &no_set_metric_cmd
);
4662 install_element (RMAP_NODE
, &no_set_metric_val_cmd
);
4663 install_element (RMAP_NODE
, &set_aspath_prepend_cmd
);
4664 install_element (RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
4665 install_element (RMAP_NODE
, &set_aspath_exclude_cmd
);
4666 install_element (RMAP_NODE
, &no_set_aspath_prepend_cmd
);
4667 install_element (RMAP_NODE
, &no_set_aspath_prepend_val_cmd
);
4668 install_element (RMAP_NODE
, &no_set_aspath_exclude_cmd
);
4669 install_element (RMAP_NODE
, &no_set_aspath_exclude_val_cmd
);
4670 install_element (RMAP_NODE
, &set_origin_cmd
);
4671 install_element (RMAP_NODE
, &no_set_origin_cmd
);
4672 install_element (RMAP_NODE
, &no_set_origin_val_cmd
);
4673 install_element (RMAP_NODE
, &set_atomic_aggregate_cmd
);
4674 install_element (RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
4675 install_element (RMAP_NODE
, &set_aggregator_as_cmd
);
4676 install_element (RMAP_NODE
, &no_set_aggregator_as_cmd
);
4677 install_element (RMAP_NODE
, &no_set_aggregator_as_val_cmd
);
4678 install_element (RMAP_NODE
, &set_community_cmd
);
4679 install_element (RMAP_NODE
, &set_community_none_cmd
);
4680 install_element (RMAP_NODE
, &no_set_community_cmd
);
4681 install_element (RMAP_NODE
, &no_set_community_val_cmd
);
4682 install_element (RMAP_NODE
, &no_set_community_none_cmd
);
4683 install_element (RMAP_NODE
, &set_community_delete_cmd
);
4684 install_element (RMAP_NODE
, &no_set_community_delete_cmd
);
4685 install_element (RMAP_NODE
, &no_set_community_delete_val_cmd
);
4686 install_element (RMAP_NODE
, &set_ecommunity_rt_cmd
);
4687 install_element (RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
4688 install_element (RMAP_NODE
, &no_set_ecommunity_rt_val_cmd
);
4689 install_element (RMAP_NODE
, &set_ecommunity_soo_cmd
);
4690 install_element (RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
4691 install_element (RMAP_NODE
, &no_set_ecommunity_soo_val_cmd
);
4692 install_element (RMAP_NODE
, &set_vpnv4_nexthop_cmd
);
4693 install_element (RMAP_NODE
, &no_set_vpnv4_nexthop_cmd
);
4694 install_element (RMAP_NODE
, &no_set_vpnv4_nexthop_val_cmd
);
4695 install_element (RMAP_NODE
, &set_originator_id_cmd
);
4696 install_element (RMAP_NODE
, &no_set_originator_id_cmd
);
4697 install_element (RMAP_NODE
, &no_set_originator_id_val_cmd
);
4698 install_element (RMAP_NODE
, &set_tag_cmd
);
4699 install_element (RMAP_NODE
, &no_set_tag_cmd
);
4700 install_element (RMAP_NODE
, &no_set_tag_val_cmd
);
4703 route_map_install_match (&route_match_ipv6_address_cmd
);
4704 route_map_install_match (&route_match_ipv6_next_hop_cmd
);
4705 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd
);
4706 route_map_install_set (&route_set_ipv6_nexthop_global_cmd
);
4707 route_map_install_set (&route_set_ipv6_nexthop_local_cmd
);
4708 route_map_install_set (&route_set_ipv6_nexthop_peer_cmd
);
4710 install_element (RMAP_NODE
, &match_ipv6_address_cmd
);
4711 install_element (RMAP_NODE
, &no_match_ipv6_address_cmd
);
4712 install_element (RMAP_NODE
, &match_ipv6_next_hop_cmd
);
4713 install_element (RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
4714 install_element (RMAP_NODE
, &match_ipv6_address_prefix_list_cmd
);
4715 install_element (RMAP_NODE
, &no_match_ipv6_address_prefix_list_cmd
);
4716 install_element (RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
4717 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
4718 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_val_cmd
);
4719 install_element (RMAP_NODE
, &set_ipv6_nexthop_local_cmd
);
4720 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_local_cmd
);
4721 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_local_val_cmd
);
4722 install_element (RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
4723 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
4724 #endif /* HAVE_IPV6 */
4728 bgp_route_map_terminate (void)
4730 /* ToDo: Cleanup all the used memory */
4732 route_map_add_hook (NULL
);
4733 route_map_delete_hook (NULL
);
4734 route_map_event_hook (NULL
);