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"
43 #include "bgpd/bgpd.h"
44 #include "bgpd/bgp_table.h"
45 #include "bgpd/bgp_attr.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_route.h"
48 #include "bgpd/bgp_regex.h"
49 #include "bgpd/bgp_community.h"
50 #include "bgpd/bgp_clist.h"
51 #include "bgpd/bgp_filter.h"
52 #include "bgpd/bgp_mplsvpn.h"
53 #include "bgpd/bgp_ecommunity.h"
54 #include "bgpd/bgp_vty.h"
56 /* Memo of route-map commands.
65 ip route-source : Done
69 ipv6 route-source: (This will not be implemented by bgpd)
70 ipv6 prefix-list : Done
71 length : (This will not be implemented by bgpd)
73 route-type : (This will not be implemented by bgpd)
74 tag : (This will not be implemented by bgpd)
76 set as-path prepend : Done
78 automatic-tag : (This will not be implemented by bgpd)
82 default : (This will not be implemented by bgpd)
83 interface : (This will not be implemented by bgpd)
84 ip default : (This will not be implemented by bgpd)
86 ip precedence : (This will not be implemented by bgpd)
87 ip tos : (This will not be implemented by bgpd)
88 level : (This will not be implemented by bgpd)
89 local-preference : Done
93 tag : (This will not be implemented by bgpd)
99 set ipv6 next-hop global: Done
100 set ipv6 next-hop local : Done
101 set pathlimit ttl : Done
102 set as-path exclude : Done
103 match pathlimit as : Done
107 /* Compiles either AS or TTL argument. It is amused the VTY code
108 * has already range-checked the values to be suitable as TTL or ASN
111 route_pathlimit_compile (const char *arg
)
117 /* TTL or AS value shoud be integer. */
118 if (! all_digit (arg
))
121 tmp
= strtoul (arg
, &endptr
, 10);
122 if (*endptr
!= '\0' || tmp
== ULONG_MAX
|| tmp
> UINT32_MAX
)
125 if (!(val
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
))))
134 route_pathlimit_free (void *rule
)
136 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
139 static route_map_result_t
140 route_match_pathlimit_as (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
143 struct bgp_info
*info
= object
;
144 struct attr
*attr
= info
->attr
;
145 uint32_t as
= *(uint32_t *)rule
;
147 if (type
!= RMAP_BGP
)
150 if (!attr
->pathlimit
.as
)
153 if (as
== attr
->pathlimit
.as
)
159 /* 'match pathlimit as' */
160 struct route_map_rule_cmd route_match_pathlimit_as_cmd
=
163 route_match_pathlimit_as
,
164 route_pathlimit_compile
,
168 /* Set pathlimit TTL. */
169 static route_map_result_t
170 route_set_pathlimit_ttl (void *rule
, struct prefix
*prefix
,
171 route_map_object_t type
, void *object
)
173 struct bgp_info
*info
= object
;
174 struct attr
*attr
= info
->attr
;
175 u_char ttl
= *(uint32_t *)rule
;
177 if (type
== RMAP_BGP
)
179 attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT
);
180 attr
->pathlimit
.ttl
= ttl
;
181 attr
->pathlimit
.as
= 0;
187 /* Set local preference rule structure. */
188 struct route_map_rule_cmd route_set_pathlimit_ttl_cmd
=
191 route_set_pathlimit_ttl
,
192 route_pathlimit_compile
,
193 route_pathlimit_free
,
196 /* 'match peer (A.B.C.D|X:X::X:X)' */
198 /* Compares the peer specified in the 'match peer' clause with the peer
199 received in bgp_info->peer. If it is the same, or if the peer structure
200 received is a peer_group containing it, returns RMAP_MATCH. */
201 static route_map_result_t
202 route_match_peer (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
206 union sockunion
*su2
;
207 struct peer_group
*group
;
209 struct listnode
*node
, *nnode
;
211 if (type
== RMAP_BGP
)
214 peer
= ((struct bgp_info
*) object
)->peer
;
216 if ( ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
) &&
217 ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_EXPORT
) )
220 /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
221 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
222 su2
= sockunion_str2su ("0.0.0.0");
223 if ( sockunion_same (su
, su2
) )
226 if ( CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
) ||
227 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
) ||
228 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
233 sockunion_free (su2
);
236 sockunion_free (su2
);
238 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
240 if (sockunion_same (su
, &peer
->su
))
248 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
250 if (sockunion_same (su
, &peer
->su
))
260 route_match_peer_compile (const char *arg
)
265 su
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (union sockunion
));
267 ret
= str2sockunion ( (arg
)? arg
: "0.0.0.0", su
);
269 XFREE (MTYPE_ROUTE_MAP_COMPILED
, su
);
276 /* Free route map's compiled `ip address' value. */
278 route_match_peer_free (void *rule
)
280 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
283 /* Route map commands for ip address matching. */
284 struct route_map_rule_cmd route_match_peer_cmd
=
288 route_match_peer_compile
,
289 route_match_peer_free
292 /* `match ip address IP_ACCESS_LIST' */
294 /* Match function should return 1 if match is success else return
296 static route_map_result_t
297 route_match_ip_address (void *rule
, struct prefix
*prefix
,
298 route_map_object_t type
, void *object
)
300 struct access_list
*alist
;
301 /* struct prefix_ipv4 match; */
303 if (type
== RMAP_BGP
)
305 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
309 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
310 RMAP_NOMATCH
: RMAP_MATCH
);
315 /* Route map `ip address' match statement. `arg' should be
318 route_match_ip_address_compile (const char *arg
)
320 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
323 /* Free route map's compiled `ip address' value. */
325 route_match_ip_address_free (void *rule
)
327 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
330 /* Route map commands for ip address matching. */
331 struct route_map_rule_cmd route_match_ip_address_cmd
=
334 route_match_ip_address
,
335 route_match_ip_address_compile
,
336 route_match_ip_address_free
339 /* `match ip next-hop IP_ADDRESS' */
341 /* Match function return 1 if match is success else return zero. */
342 static route_map_result_t
343 route_match_ip_next_hop (void *rule
, struct prefix
*prefix
,
344 route_map_object_t type
, void *object
)
346 struct access_list
*alist
;
347 struct bgp_info
*bgp_info
;
348 struct prefix_ipv4 p
;
350 if (type
== RMAP_BGP
)
354 p
.prefix
= bgp_info
->attr
->nexthop
;
355 p
.prefixlen
= IPV4_MAX_BITLEN
;
357 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
361 return (access_list_apply (alist
, &p
) == FILTER_DENY
?
362 RMAP_NOMATCH
: RMAP_MATCH
);
367 /* Route map `ip next-hop' match statement. `arg' is
370 route_match_ip_next_hop_compile (const char *arg
)
372 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
375 /* Free route map's compiled `ip address' value. */
377 route_match_ip_next_hop_free (void *rule
)
379 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
382 /* Route map commands for ip next-hop matching. */
383 struct route_map_rule_cmd route_match_ip_next_hop_cmd
=
386 route_match_ip_next_hop
,
387 route_match_ip_next_hop_compile
,
388 route_match_ip_next_hop_free
391 /* `match ip route-source ACCESS-LIST' */
393 /* Match function return 1 if match is success else return zero. */
394 static route_map_result_t
395 route_match_ip_route_source (void *rule
, struct prefix
*prefix
,
396 route_map_object_t type
, void *object
)
398 struct access_list
*alist
;
399 struct bgp_info
*bgp_info
;
401 struct prefix_ipv4 p
;
403 if (type
== RMAP_BGP
)
406 peer
= bgp_info
->peer
;
408 if (! peer
|| sockunion_family (&peer
->su
) != AF_INET
)
412 p
.prefix
= peer
->su
.sin
.sin_addr
;
413 p
.prefixlen
= IPV4_MAX_BITLEN
;
415 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
419 return (access_list_apply (alist
, &p
) == FILTER_DENY
?
420 RMAP_NOMATCH
: RMAP_MATCH
);
425 /* Route map `ip route-source' match statement. `arg' is
428 route_match_ip_route_source_compile (const char *arg
)
430 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
433 /* Free route map's compiled `ip address' value. */
435 route_match_ip_route_source_free (void *rule
)
437 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
440 /* Route map commands for ip route-source matching. */
441 struct route_map_rule_cmd route_match_ip_route_source_cmd
=
444 route_match_ip_route_source
,
445 route_match_ip_route_source_compile
,
446 route_match_ip_route_source_free
449 /* `match ip address prefix-list PREFIX_LIST' */
451 static route_map_result_t
452 route_match_ip_address_prefix_list (void *rule
, struct prefix
*prefix
,
453 route_map_object_t type
, void *object
)
455 struct prefix_list
*plist
;
457 if (type
== RMAP_BGP
)
459 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
463 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
464 RMAP_NOMATCH
: RMAP_MATCH
);
470 route_match_ip_address_prefix_list_compile (const char *arg
)
472 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
476 route_match_ip_address_prefix_list_free (void *rule
)
478 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
481 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
=
483 "ip address prefix-list",
484 route_match_ip_address_prefix_list
,
485 route_match_ip_address_prefix_list_compile
,
486 route_match_ip_address_prefix_list_free
489 /* `match ip next-hop prefix-list PREFIX_LIST' */
491 static route_map_result_t
492 route_match_ip_next_hop_prefix_list (void *rule
, struct prefix
*prefix
,
493 route_map_object_t type
, void *object
)
495 struct prefix_list
*plist
;
496 struct bgp_info
*bgp_info
;
497 struct prefix_ipv4 p
;
499 if (type
== RMAP_BGP
)
503 p
.prefix
= bgp_info
->attr
->nexthop
;
504 p
.prefixlen
= IPV4_MAX_BITLEN
;
506 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
510 return (prefix_list_apply (plist
, &p
) == PREFIX_DENY
?
511 RMAP_NOMATCH
: RMAP_MATCH
);
517 route_match_ip_next_hop_prefix_list_compile (const char *arg
)
519 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
523 route_match_ip_next_hop_prefix_list_free (void *rule
)
525 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
528 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
=
530 "ip next-hop prefix-list",
531 route_match_ip_next_hop_prefix_list
,
532 route_match_ip_next_hop_prefix_list_compile
,
533 route_match_ip_next_hop_prefix_list_free
536 /* `match ip route-source prefix-list PREFIX_LIST' */
538 static route_map_result_t
539 route_match_ip_route_source_prefix_list (void *rule
, struct prefix
*prefix
,
540 route_map_object_t type
, void *object
)
542 struct prefix_list
*plist
;
543 struct bgp_info
*bgp_info
;
545 struct prefix_ipv4 p
;
547 if (type
== RMAP_BGP
)
550 peer
= bgp_info
->peer
;
552 if (! peer
|| sockunion_family (&peer
->su
) != AF_INET
)
556 p
.prefix
= peer
->su
.sin
.sin_addr
;
557 p
.prefixlen
= IPV4_MAX_BITLEN
;
559 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
563 return (prefix_list_apply (plist
, &p
) == PREFIX_DENY
?
564 RMAP_NOMATCH
: RMAP_MATCH
);
570 route_match_ip_route_source_prefix_list_compile (const char *arg
)
572 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
576 route_match_ip_route_source_prefix_list_free (void *rule
)
578 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
581 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
=
583 "ip route-source prefix-list",
584 route_match_ip_route_source_prefix_list
,
585 route_match_ip_route_source_prefix_list_compile
,
586 route_match_ip_route_source_prefix_list_free
589 /* `match metric METRIC' */
591 /* Match function return 1 if match is success else return zero. */
592 static route_map_result_t
593 route_match_metric (void *rule
, struct prefix
*prefix
,
594 route_map_object_t type
, void *object
)
597 struct bgp_info
*bgp_info
;
599 if (type
== RMAP_BGP
)
604 if (bgp_info
->attr
->med
== *med
)
612 /* Route map `match metric' match statement. `arg' is MED value */
614 route_match_metric_compile (const char *arg
)
618 unsigned long tmpval
;
620 tmpval
= strtoul (arg
, &endptr
, 10);
621 if (*endptr
!= '\0' || tmpval
== ULONG_MAX
|| tmpval
> UINT32_MAX
)
624 med
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
633 /* Free route map's compiled `match metric' value. */
635 route_match_metric_free (void *rule
)
637 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
640 /* Route map commands for metric matching. */
641 struct route_map_rule_cmd route_match_metric_cmd
=
645 route_match_metric_compile
,
646 route_match_metric_free
649 /* `match as-path ASPATH' */
651 /* Match function for as-path match. I assume given object is */
652 static route_map_result_t
653 route_match_aspath (void *rule
, struct prefix
*prefix
,
654 route_map_object_t type
, void *object
)
657 struct as_list
*as_list
;
658 struct bgp_info
*bgp_info
;
660 if (type
== RMAP_BGP
)
662 as_list
= as_list_lookup ((char *) rule
);
669 return ((as_list_apply (as_list
, bgp_info
->attr
->aspath
) == AS_FILTER_DENY
) ? RMAP_NOMATCH
: RMAP_MATCH
);
674 /* Compile function for as-path match. */
676 route_match_aspath_compile (const char *arg
)
678 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
681 /* Compile function for as-path match. */
683 route_match_aspath_free (void *rule
)
685 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
688 /* Route map commands for aspath matching. */
689 struct route_map_rule_cmd route_match_aspath_cmd
=
693 route_match_aspath_compile
,
694 route_match_aspath_free
697 /* `match community COMMUNIY' */
698 struct rmap_community
704 /* Match function for community match. */
705 static route_map_result_t
706 route_match_community (void *rule
, struct prefix
*prefix
,
707 route_map_object_t type
, void *object
)
709 struct community_list
*list
;
710 struct bgp_info
*bgp_info
;
711 struct rmap_community
*rcom
;
713 if (type
== RMAP_BGP
)
718 list
= community_list_lookup (bgp_clist
, rcom
->name
, COMMUNITY_LIST_MASTER
);
724 if (community_list_exact_match (bgp_info
->attr
->community
, list
))
729 if (community_list_match (bgp_info
->attr
->community
, list
))
736 /* Compile function for community match. */
738 route_match_community_compile (const char *arg
)
740 struct rmap_community
*rcom
;
744 rcom
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_community
));
746 p
= strchr (arg
, ' ');
750 rcom
->name
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
751 memcpy (rcom
->name
, arg
, len
);
756 rcom
->name
= XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
762 /* Compile function for community match. */
764 route_match_community_free (void *rule
)
766 struct rmap_community
*rcom
= rule
;
768 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
769 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
);
772 /* Route map commands for community matching. */
773 struct route_map_rule_cmd route_match_community_cmd
=
776 route_match_community
,
777 route_match_community_compile
,
778 route_match_community_free
781 /* Match function for extcommunity match. */
782 static route_map_result_t
783 route_match_ecommunity (void *rule
, struct prefix
*prefix
,
784 route_map_object_t type
, void *object
)
786 struct community_list
*list
;
787 struct bgp_info
*bgp_info
;
789 if (type
== RMAP_BGP
)
793 if (!bgp_info
->attr
->extra
)
796 list
= community_list_lookup (bgp_clist
, (char *) rule
,
797 EXTCOMMUNITY_LIST_MASTER
);
801 if (ecommunity_list_match (bgp_info
->attr
->extra
->ecommunity
, list
))
807 /* Compile function for extcommunity match. */
809 route_match_ecommunity_compile (const char *arg
)
811 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
814 /* Compile function for extcommunity match. */
816 route_match_ecommunity_free (void *rule
)
818 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
821 /* Route map commands for community matching. */
822 struct route_map_rule_cmd route_match_ecommunity_cmd
=
825 route_match_ecommunity
,
826 route_match_ecommunity_compile
,
827 route_match_ecommunity_free
830 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
831 and `address-family vpnv4'. */
834 static route_map_result_t
835 route_match_origin (void *rule
, struct prefix
*prefix
,
836 route_map_object_t type
, void *object
)
839 struct bgp_info
*bgp_info
;
841 if (type
== RMAP_BGP
)
846 if (bgp_info
->attr
->origin
== *origin
)
854 route_match_origin_compile (const char *arg
)
858 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
860 if (strcmp (arg
, "igp") == 0)
862 else if (strcmp (arg
, "egp") == 0)
870 /* Free route map's compiled `ip address' value. */
872 route_match_origin_free (void *rule
)
874 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
877 /* Route map commands for origin matching. */
878 struct route_map_rule_cmd route_match_origin_cmd
=
882 route_match_origin_compile
,
883 route_match_origin_free
885 /* `set ip next-hop IP_ADDRESS' */
887 /* Set nexthop to object. ojbect must be pointer to struct attr. */
888 struct rmap_ip_nexthop_set
890 struct in_addr
*address
;
894 static route_map_result_t
895 route_set_ip_nexthop (void *rule
, struct prefix
*prefix
,
896 route_map_object_t type
, void *object
)
898 struct rmap_ip_nexthop_set
*rins
= rule
;
899 struct in_addr peer_address
;
900 struct bgp_info
*bgp_info
;
903 if (type
== RMAP_BGP
)
906 peer
= bgp_info
->peer
;
908 if (rins
->peer_address
)
910 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
911 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
913 && sockunion_family (peer
->su_remote
) == AF_INET
)
915 inet_aton (sockunion_su2str (peer
->su_remote
), &peer_address
);
916 bgp_info
->attr
->nexthop
= peer_address
;
917 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
919 else if (CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)
921 && sockunion_family (peer
->su_local
) == AF_INET
)
923 inet_aton (sockunion_su2str (peer
->su_local
), &peer_address
);
924 bgp_info
->attr
->nexthop
= peer_address
;
925 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
930 /* Set next hop value. */
931 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
932 bgp_info
->attr
->nexthop
= *rins
->address
;
939 /* Route map `ip nexthop' compile function. Given string is converted
940 to struct in_addr structure. */
942 route_set_ip_nexthop_compile (const char *arg
)
944 struct rmap_ip_nexthop_set
*rins
;
945 struct in_addr
*address
= NULL
;
946 int peer_address
= 0;
949 if (strcmp (arg
, "peer-address") == 0)
953 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
954 ret
= inet_aton (arg
, address
);
958 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
963 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_ip_nexthop_set
));
965 rins
->address
= address
;
966 rins
->peer_address
= peer_address
;
971 /* Free route map's compiled `ip nexthop' value. */
973 route_set_ip_nexthop_free (void *rule
)
975 struct rmap_ip_nexthop_set
*rins
= rule
;
978 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
980 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
);
983 /* Route map commands for ip nexthop set. */
984 struct route_map_rule_cmd route_set_ip_nexthop_cmd
=
987 route_set_ip_nexthop
,
988 route_set_ip_nexthop_compile
,
989 route_set_ip_nexthop_free
992 /* `set local-preference LOCAL_PREF' */
994 /* Set local preference. */
995 static route_map_result_t
996 route_set_local_pref (void *rule
, struct prefix
*prefix
,
997 route_map_object_t type
, void *object
)
999 u_int32_t
*local_pref
;
1000 struct bgp_info
*bgp_info
;
1002 if (type
== RMAP_BGP
)
1004 /* Fetch routemap's rule information. */
1008 /* Set local preference value. */
1009 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
);
1010 bgp_info
->attr
->local_pref
= *local_pref
;
1016 /* set local preference compilation. */
1018 route_set_local_pref_compile (const char *arg
)
1021 u_int32_t
*local_pref
;
1022 char *endptr
= NULL
;
1024 /* Local preference value shoud be integer. */
1025 if (! all_digit (arg
))
1028 tmp
= strtoul (arg
, &endptr
, 10);
1029 if (*endptr
!= '\0' || tmp
== ULONG_MAX
|| tmp
> UINT32_MAX
)
1032 local_pref
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
1042 /* Free route map's local preference value. */
1044 route_set_local_pref_free (void *rule
)
1046 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1049 /* Set local preference rule structure. */
1050 struct route_map_rule_cmd route_set_local_pref_cmd
=
1053 route_set_local_pref
,
1054 route_set_local_pref_compile
,
1055 route_set_local_pref_free
,
1058 /* `set weight WEIGHT' */
1061 static route_map_result_t
1062 route_set_weight (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
1066 struct bgp_info
*bgp_info
;
1068 if (type
== RMAP_BGP
)
1070 /* Fetch routemap's rule information. */
1074 /* Set weight value. */
1076 (bgp_attr_extra_get (bgp_info
->attr
))->weight
= *weight
;
1077 else if (bgp_info
->attr
->extra
)
1078 bgp_info
->attr
->extra
->weight
= 0;
1084 /* set local preference compilation. */
1086 route_set_weight_compile (const char *arg
)
1090 char *endptr
= NULL
;
1092 /* Local preference value shoud be integer. */
1093 if (! all_digit (arg
))
1097 tmp
= strtoul (arg
, &endptr
, 10);
1098 if (*endptr
!= '\0' || tmp
== ULONG_MAX
|| tmp
> UINT32_MAX
)
1101 weight
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
1111 /* Free route map's local preference value. */
1113 route_set_weight_free (void *rule
)
1115 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1118 /* Set local preference rule structure. */
1119 struct route_map_rule_cmd route_set_weight_cmd
=
1123 route_set_weight_compile
,
1124 route_set_weight_free
,
1127 /* `set metric METRIC' */
1129 /* Set metric to attribute. */
1130 static route_map_result_t
1131 route_set_metric (void *rule
, struct prefix
*prefix
,
1132 route_map_object_t type
, void *object
)
1135 u_int32_t metric_val
;
1136 struct bgp_info
*bgp_info
;
1138 if (type
== RMAP_BGP
)
1140 /* Fetch routemap's rule information. */
1144 if (! (bgp_info
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
)))
1145 bgp_info
->attr
->med
= 0;
1146 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
);
1148 if (all_digit (metric
))
1150 metric_val
= strtoul (metric
, (char **)NULL
, 10);
1151 bgp_info
->attr
->med
= metric_val
;
1155 metric_val
= strtoul (metric
+1, (char **)NULL
, 10);
1157 if (strncmp (metric
, "+", 1) == 0)
1159 if (bgp_info
->attr
->med
/2 + metric_val
/2 > BGP_MED_MAX
/2)
1160 bgp_info
->attr
->med
= BGP_MED_MAX
- 1;
1162 bgp_info
->attr
->med
+= metric_val
;
1164 else if (strncmp (metric
, "-", 1) == 0)
1166 if (bgp_info
->attr
->med
<= metric_val
)
1167 bgp_info
->attr
->med
= 0;
1169 bgp_info
->attr
->med
-= metric_val
;
1176 /* set metric compilation. */
1178 route_set_metric_compile (const char *arg
)
1182 char *endptr
= NULL
;
1184 if (all_digit (arg
))
1186 /* set metric value check*/
1187 larg
= strtoul (arg
, &endptr
, 10);
1188 if (*endptr
!= '\0' || larg
== ULONG_MAX
|| larg
> UINT32_MAX
)
1194 /* set metric +/-value check */
1195 if ((strncmp (arg
, "+", 1) != 0
1196 && strncmp (arg
, "-", 1) != 0)
1197 || (! all_digit (arg
+1)))
1200 larg
= strtoul (arg
+1, &endptr
, 10);
1201 if (*endptr
!= '\0' || larg
== ULONG_MAX
|| larg
> UINT32_MAX
)
1206 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1209 /* Free route map's compiled `set metric' value. */
1211 route_set_metric_free (void *rule
)
1213 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1216 /* Set metric rule structure. */
1217 struct route_map_rule_cmd route_set_metric_cmd
=
1221 route_set_metric_compile
,
1222 route_set_metric_free
,
1225 /* `set as-path prepend ASPATH' */
1227 /* For AS path prepend mechanism. */
1228 static route_map_result_t
1229 route_set_aspath_prepend (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1231 struct aspath
*aspath
;
1233 struct bgp_info
*binfo
;
1235 if (type
== RMAP_BGP
)
1240 if (binfo
->attr
->aspath
->refcnt
)
1241 new = aspath_dup (binfo
->attr
->aspath
);
1243 new = binfo
->attr
->aspath
;
1245 aspath_prepend (aspath
, new);
1246 binfo
->attr
->aspath
= new;
1252 /* Compile function for as-path prepend. */
1254 route_set_aspath_prepend_compile (const char *arg
)
1256 struct aspath
*aspath
;
1258 aspath
= aspath_str2aspath (arg
);
1264 /* Compile function for as-path prepend. */
1266 route_set_aspath_prepend_free (void *rule
)
1268 struct aspath
*aspath
= rule
;
1269 aspath_free (aspath
);
1272 /* Set metric rule structure. */
1273 struct route_map_rule_cmd route_set_aspath_prepend_cmd
=
1276 route_set_aspath_prepend
,
1277 route_set_aspath_prepend_compile
,
1278 route_set_aspath_prepend_free
,
1281 /* `set as-path exclude ASn' */
1283 /* For ASN exclude mechanism.
1284 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1285 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1287 static route_map_result_t
1288 route_set_aspath_exclude (void *rule
, struct prefix
*dummy
, route_map_object_t type
, void *object
)
1290 struct aspath
* new_path
, * exclude_path
;
1291 struct bgp_info
*binfo
;
1293 if (type
== RMAP_BGP
)
1295 exclude_path
= rule
;
1297 if (binfo
->attr
->aspath
->refcnt
)
1298 new_path
= aspath_dup (binfo
->attr
->aspath
);
1300 new_path
= binfo
->attr
->aspath
;
1301 binfo
->attr
->aspath
= aspath_filter_exclude (new_path
, exclude_path
);
1306 /* FIXME: consider using route_set_aspath_prepend_compile() and
1307 * route_set_aspath_prepend_free(), which two below function are
1311 /* Compile function for as-path exclude. */
1313 route_set_aspath_exclude_compile (const char *arg
)
1315 struct aspath
*aspath
;
1317 aspath
= aspath_str2aspath (arg
);
1324 route_set_aspath_exclude_free (void *rule
)
1326 struct aspath
*aspath
= rule
;
1327 aspath_free (aspath
);
1330 /* Set ASn exlude rule structure. */
1331 struct route_map_rule_cmd route_set_aspath_exclude_cmd
=
1334 route_set_aspath_exclude
,
1335 route_set_aspath_exclude_compile
,
1336 route_set_aspath_exclude_free
,
1339 /* `set community COMMUNITY' */
1342 struct community
*com
;
1347 /* For community set mechanism. */
1348 static route_map_result_t
1349 route_set_community (void *rule
, struct prefix
*prefix
,
1350 route_map_object_t type
, void *object
)
1352 struct rmap_com_set
*rcs
;
1353 struct bgp_info
*binfo
;
1355 struct community
*new = NULL
;
1356 struct community
*old
;
1357 struct community
*merge
;
1359 if (type
== RMAP_BGP
)
1364 old
= attr
->community
;
1369 attr
->flag
&= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
));
1370 attr
->community
= NULL
;
1374 /* "additive" case. */
1375 if (rcs
->additive
&& old
)
1377 merge
= community_merge (community_dup (old
), rcs
->com
);
1379 /* HACK: if the old community is not intern'd,
1380 * we should free it here, or all reference to it may be lost.
1381 * Really need to cleanup attribute caching sometime.
1383 if (old
->refcnt
== 0)
1384 community_free (old
);
1385 new = community_uniq_sort (merge
);
1386 community_free (merge
);
1389 new = community_dup (rcs
->com
);
1391 /* will be interned by caller if required */
1392 attr
->community
= new;
1394 attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1400 /* Compile function for set community. */
1402 route_set_community_compile (const char *arg
)
1404 struct rmap_com_set
*rcs
;
1405 struct community
*com
= NULL
;
1410 if (strcmp (arg
, "none") == 0)
1414 sp
= strstr (arg
, "additive");
1418 /* "additive" keyworkd is included. */
1423 com
= community_str2com (arg
);
1432 rcs
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_com_set
));
1434 rcs
->additive
= additive
;
1440 /* Free function for set community. */
1442 route_set_community_free (void *rule
)
1444 struct rmap_com_set
*rcs
= rule
;
1447 community_free (rcs
->com
);
1448 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1451 /* Set community rule structure. */
1452 struct route_map_rule_cmd route_set_community_cmd
=
1455 route_set_community
,
1456 route_set_community_compile
,
1457 route_set_community_free
,
1460 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
1462 /* For community set mechanism. */
1463 static route_map_result_t
1464 route_set_community_delete (void *rule
, struct prefix
*prefix
,
1465 route_map_object_t type
, void *object
)
1467 struct community_list
*list
;
1468 struct community
*merge
;
1469 struct community
*new;
1470 struct community
*old
;
1471 struct bgp_info
*binfo
;
1473 if (type
== RMAP_BGP
)
1479 list
= community_list_lookup (bgp_clist
, rule
, COMMUNITY_LIST_MASTER
);
1480 old
= binfo
->attr
->community
;
1484 merge
= community_list_match_delete (community_dup (old
), list
);
1485 new = community_uniq_sort (merge
);
1486 community_free (merge
);
1490 binfo
->attr
->community
= NULL
;
1491 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1492 community_free (new);
1496 binfo
->attr
->community
= new;
1497 binfo
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1505 /* Compile function for set community. */
1507 route_set_community_delete_compile (const char *arg
)
1513 p
= strchr (arg
, ' ');
1517 str
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1518 memcpy (str
, arg
, len
);
1526 /* Free function for set community. */
1528 route_set_community_delete_free (void *rule
)
1530 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1533 /* Set community rule structure. */
1534 struct route_map_rule_cmd route_set_community_delete_cmd
=
1537 route_set_community_delete
,
1538 route_set_community_delete_compile
,
1539 route_set_community_delete_free
,
1542 /* `set extcommunity rt COMMUNITY' */
1544 /* For community set mechanism. */
1545 static route_map_result_t
1546 route_set_ecommunity_rt (void *rule
, struct prefix
*prefix
,
1547 route_map_object_t type
, void *object
)
1549 struct ecommunity
*ecom
;
1550 struct ecommunity
*new_ecom
;
1551 struct ecommunity
*old_ecom
;
1552 struct bgp_info
*bgp_info
;
1554 if (type
== RMAP_BGP
)
1562 /* We assume additive for Extended Community. */
1563 old_ecom
= (bgp_attr_extra_get (bgp_info
->attr
))->ecommunity
;
1566 new_ecom
= ecommunity_merge (ecommunity_dup (old_ecom
), ecom
);
1568 new_ecom
= ecommunity_dup (ecom
);
1570 bgp_info
->attr
->extra
->ecommunity
= new_ecom
;
1573 ecommunity_free (old_ecom
);
1575 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES
);
1580 /* Compile function for set community. */
1582 route_set_ecommunity_rt_compile (const char *arg
)
1584 struct ecommunity
*ecom
;
1586 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
1592 /* Free function for set community. */
1594 route_set_ecommunity_rt_free (void *rule
)
1596 struct ecommunity
*ecom
= rule
;
1597 ecommunity_free (ecom
);
1600 /* Set community rule structure. */
1601 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
=
1604 route_set_ecommunity_rt
,
1605 route_set_ecommunity_rt_compile
,
1606 route_set_ecommunity_rt_free
,
1609 /* `set extcommunity soo COMMUNITY' */
1611 /* For community set mechanism. */
1612 static route_map_result_t
1613 route_set_ecommunity_soo (void *rule
, struct prefix
*prefix
,
1614 route_map_object_t type
, void *object
)
1616 struct ecommunity
*ecom
;
1617 struct bgp_info
*bgp_info
;
1619 if (type
== RMAP_BGP
)
1627 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES
);
1628 (bgp_attr_extra_get (bgp_info
->attr
))->ecommunity
= ecommunity_dup (ecom
);
1633 /* Compile function for set community. */
1635 route_set_ecommunity_soo_compile (const char *arg
)
1637 struct ecommunity
*ecom
;
1639 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
1646 /* Free function for set community. */
1648 route_set_ecommunity_soo_free (void *rule
)
1650 struct ecommunity
*ecom
= rule
;
1651 ecommunity_free (ecom
);
1654 /* Set community rule structure. */
1655 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
=
1658 route_set_ecommunity_soo
,
1659 route_set_ecommunity_soo_compile
,
1660 route_set_ecommunity_soo_free
,
1663 /* `set origin ORIGIN' */
1665 /* For origin set. */
1666 static route_map_result_t
1667 route_set_origin (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1670 struct bgp_info
*bgp_info
;
1672 if (type
== RMAP_BGP
)
1677 bgp_info
->attr
->origin
= *origin
;
1683 /* Compile function for origin set. */
1685 route_set_origin_compile (const char *arg
)
1689 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
1691 if (strcmp (arg
, "igp") == 0)
1693 else if (strcmp (arg
, "egp") == 0)
1701 /* Compile function for origin set. */
1703 route_set_origin_free (void *rule
)
1705 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1708 /* Set metric rule structure. */
1709 struct route_map_rule_cmd route_set_origin_cmd
=
1713 route_set_origin_compile
,
1714 route_set_origin_free
,
1717 /* `set atomic-aggregate' */
1719 /* For atomic aggregate set. */
1720 static route_map_result_t
1721 route_set_atomic_aggregate (void *rule
, struct prefix
*prefix
,
1722 route_map_object_t type
, void *object
)
1724 struct bgp_info
*bgp_info
;
1726 if (type
== RMAP_BGP
)
1729 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
);
1735 /* Compile function for atomic aggregate. */
1737 route_set_atomic_aggregate_compile (const char *arg
)
1742 /* Compile function for atomic aggregate. */
1744 route_set_atomic_aggregate_free (void *rule
)
1749 /* Set atomic aggregate rule structure. */
1750 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
=
1753 route_set_atomic_aggregate
,
1754 route_set_atomic_aggregate_compile
,
1755 route_set_atomic_aggregate_free
,
1758 /* `set aggregator as AS A.B.C.D' */
1762 struct in_addr address
;
1765 static route_map_result_t
1766 route_set_aggregator_as (void *rule
, struct prefix
*prefix
,
1767 route_map_object_t type
, void *object
)
1769 struct bgp_info
*bgp_info
;
1770 struct aggregator
*aggregator
;
1771 struct attr_extra
*ae
;
1773 if (type
== RMAP_BGP
)
1777 ae
= bgp_attr_extra_get (bgp_info
->attr
);
1779 ae
->aggregator_as
= aggregator
->as
;
1780 ae
->aggregator_addr
= aggregator
->address
;
1781 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR
);
1788 route_set_aggregator_as_compile (const char *arg
)
1790 struct aggregator
*aggregator
;
1794 aggregator
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct aggregator
));
1795 sscanf (arg
, "%s %s", as
, address
);
1797 aggregator
->as
= strtoul (as
, NULL
, 10);
1798 inet_aton (address
, &aggregator
->address
);
1804 route_set_aggregator_as_free (void *rule
)
1806 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1809 struct route_map_rule_cmd route_set_aggregator_as_cmd
=
1812 route_set_aggregator_as
,
1813 route_set_aggregator_as_compile
,
1814 route_set_aggregator_as_free
,
1818 /* `match ipv6 address IP_ACCESS_LIST' */
1820 static route_map_result_t
1821 route_match_ipv6_address (void *rule
, struct prefix
*prefix
,
1822 route_map_object_t type
, void *object
)
1824 struct access_list
*alist
;
1826 if (type
== RMAP_BGP
)
1828 alist
= access_list_lookup (AFI_IP6
, (char *) rule
);
1830 return RMAP_NOMATCH
;
1832 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
1833 RMAP_NOMATCH
: RMAP_MATCH
);
1835 return RMAP_NOMATCH
;
1839 route_match_ipv6_address_compile (const char *arg
)
1841 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1845 route_match_ipv6_address_free (void *rule
)
1847 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1850 /* Route map commands for ip address matching. */
1851 struct route_map_rule_cmd route_match_ipv6_address_cmd
=
1854 route_match_ipv6_address
,
1855 route_match_ipv6_address_compile
,
1856 route_match_ipv6_address_free
1859 /* `match ipv6 next-hop IP_ADDRESS' */
1861 static route_map_result_t
1862 route_match_ipv6_next_hop (void *rule
, struct prefix
*prefix
,
1863 route_map_object_t type
, void *object
)
1865 struct in6_addr
*addr
;
1866 struct bgp_info
*bgp_info
;
1868 if (type
== RMAP_BGP
)
1873 if (!bgp_info
->attr
->extra
)
1874 return RMAP_NOMATCH
;
1876 if (IPV6_ADDR_SAME (&bgp_info
->attr
->extra
->mp_nexthop_global
, rule
))
1879 if (bgp_info
->attr
->extra
->mp_nexthop_len
== 32 &&
1880 IPV6_ADDR_SAME (&bgp_info
->attr
->extra
->mp_nexthop_local
, rule
))
1883 return RMAP_NOMATCH
;
1886 return RMAP_NOMATCH
;
1890 route_match_ipv6_next_hop_compile (const char *arg
)
1892 struct in6_addr
*address
;
1895 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
1897 ret
= inet_pton (AF_INET6
, arg
, address
);
1900 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1908 route_match_ipv6_next_hop_free (void *rule
)
1910 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1913 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
=
1916 route_match_ipv6_next_hop
,
1917 route_match_ipv6_next_hop_compile
,
1918 route_match_ipv6_next_hop_free
1921 /* `match ipv6 address prefix-list PREFIX_LIST' */
1923 static route_map_result_t
1924 route_match_ipv6_address_prefix_list (void *rule
, struct prefix
*prefix
,
1925 route_map_object_t type
, void *object
)
1927 struct prefix_list
*plist
;
1929 if (type
== RMAP_BGP
)
1931 plist
= prefix_list_lookup (AFI_IP6
, (char *) rule
);
1933 return RMAP_NOMATCH
;
1935 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
1936 RMAP_NOMATCH
: RMAP_MATCH
);
1938 return RMAP_NOMATCH
;
1942 route_match_ipv6_address_prefix_list_compile (const char *arg
)
1944 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1948 route_match_ipv6_address_prefix_list_free (void *rule
)
1950 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1953 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
=
1955 "ipv6 address prefix-list",
1956 route_match_ipv6_address_prefix_list
,
1957 route_match_ipv6_address_prefix_list_compile
,
1958 route_match_ipv6_address_prefix_list_free
1961 /* `set ipv6 nexthop global IP_ADDRESS' */
1963 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1964 static route_map_result_t
1965 route_set_ipv6_nexthop_global (void *rule
, struct prefix
*prefix
,
1966 route_map_object_t type
, void *object
)
1968 struct in6_addr
*address
;
1969 struct bgp_info
*bgp_info
;
1971 if (type
== RMAP_BGP
)
1973 /* Fetch routemap's rule information. */
1977 /* Set next hop value. */
1978 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
= *address
;
1980 /* Set nexthop length. */
1981 if (bgp_info
->attr
->extra
->mp_nexthop_len
== 0)
1982 bgp_info
->attr
->extra
->mp_nexthop_len
= 16;
1988 /* Route map `ip next-hop' compile function. Given string is converted
1989 to struct in_addr structure. */
1991 route_set_ipv6_nexthop_global_compile (const char *arg
)
1994 struct in6_addr
*address
;
1996 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
1998 ret
= inet_pton (AF_INET6
, arg
, address
);
2002 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2009 /* Free route map's compiled `ip next-hop' value. */
2011 route_set_ipv6_nexthop_global_free (void *rule
)
2013 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2016 /* Route map commands for ip nexthop set. */
2017 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
=
2019 "ipv6 next-hop global",
2020 route_set_ipv6_nexthop_global
,
2021 route_set_ipv6_nexthop_global_compile
,
2022 route_set_ipv6_nexthop_global_free
2025 /* `set ipv6 nexthop local IP_ADDRESS' */
2027 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2028 static route_map_result_t
2029 route_set_ipv6_nexthop_local (void *rule
, struct prefix
*prefix
,
2030 route_map_object_t type
, void *object
)
2032 struct in6_addr
*address
;
2033 struct bgp_info
*bgp_info
;
2035 if (type
== RMAP_BGP
)
2037 /* Fetch routemap's rule information. */
2041 /* Set next hop value. */
2042 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
= *address
;
2044 /* Set nexthop length. */
2045 if (bgp_info
->attr
->extra
->mp_nexthop_len
!= 32)
2046 bgp_info
->attr
->extra
->mp_nexthop_len
= 32;
2052 /* Route map `ip nexthop' compile function. Given string is converted
2053 to struct in_addr structure. */
2055 route_set_ipv6_nexthop_local_compile (const char *arg
)
2058 struct in6_addr
*address
;
2060 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2062 ret
= inet_pton (AF_INET6
, arg
, address
);
2066 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2073 /* Free route map's compiled `ip nexthop' value. */
2075 route_set_ipv6_nexthop_local_free (void *rule
)
2077 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2080 /* Route map commands for ip nexthop set. */
2081 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
=
2083 "ipv6 next-hop local",
2084 route_set_ipv6_nexthop_local
,
2085 route_set_ipv6_nexthop_local_compile
,
2086 route_set_ipv6_nexthop_local_free
2088 #endif /* HAVE_IPV6 */
2090 /* `set vpnv4 nexthop A.B.C.D' */
2092 static route_map_result_t
2093 route_set_vpnv4_nexthop (void *rule
, struct prefix
*prefix
,
2094 route_map_object_t type
, void *object
)
2096 struct in_addr
*address
;
2097 struct bgp_info
*bgp_info
;
2099 if (type
== RMAP_BGP
)
2101 /* Fetch routemap's rule information. */
2105 /* Set next hop value. */
2106 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global_in
= *address
;
2113 route_set_vpnv4_nexthop_compile (const char *arg
)
2116 struct in_addr
*address
;
2118 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
2120 ret
= inet_aton (arg
, address
);
2124 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2132 route_set_vpnv4_nexthop_free (void *rule
)
2134 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2137 /* Route map commands for ip nexthop set. */
2138 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
=
2141 route_set_vpnv4_nexthop
,
2142 route_set_vpnv4_nexthop_compile
,
2143 route_set_vpnv4_nexthop_free
2146 /* `set originator-id' */
2148 /* For origin set. */
2149 static route_map_result_t
2150 route_set_originator_id (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
2152 struct in_addr
*address
;
2153 struct bgp_info
*bgp_info
;
2155 if (type
== RMAP_BGP
)
2160 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
);
2161 (bgp_attr_extra_get (bgp_info
->attr
))->originator_id
= *address
;
2167 /* Compile function for originator-id set. */
2169 route_set_originator_id_compile (const char *arg
)
2172 struct in_addr
*address
;
2174 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
2176 ret
= inet_aton (arg
, address
);
2180 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2187 /* Compile function for originator_id set. */
2189 route_set_originator_id_free (void *rule
)
2191 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2194 /* Set metric rule structure. */
2195 struct route_map_rule_cmd route_set_originator_id_cmd
=
2198 route_set_originator_id
,
2199 route_set_originator_id_compile
,
2200 route_set_originator_id_free
,
2203 /* Add bgp route map rule. */
2205 bgp_route_match_add (struct vty
*vty
, struct route_map_index
*index
,
2206 const char *command
, const char *arg
)
2210 ret
= route_map_add_match (index
, command
, arg
);
2215 case RMAP_RULE_MISSING
:
2216 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
2218 case RMAP_COMPILE_ERROR
:
2219 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
2226 /* Delete bgp route map rule. */
2228 bgp_route_match_delete (struct vty
*vty
, struct route_map_index
*index
,
2229 const char *command
, const char *arg
)
2233 ret
= route_map_delete_match (index
, command
, arg
);
2238 case RMAP_RULE_MISSING
:
2239 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
2241 case RMAP_COMPILE_ERROR
:
2242 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
2249 /* Add bgp route map rule. */
2251 bgp_route_set_add (struct vty
*vty
, struct route_map_index
*index
,
2252 const char *command
, const char *arg
)
2256 ret
= route_map_add_set (index
, command
, arg
);
2261 case RMAP_RULE_MISSING
:
2262 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
2264 case RMAP_COMPILE_ERROR
:
2265 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
2272 /* Delete bgp route map rule. */
2274 bgp_route_set_delete (struct vty
*vty
, struct route_map_index
*index
,
2275 const char *command
, const char *arg
)
2279 ret
= route_map_delete_set (index
, command
, arg
);
2284 case RMAP_RULE_MISSING
:
2285 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
2287 case RMAP_COMPILE_ERROR
:
2288 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
2295 /* Hook function for updating route_map assignment. */
2297 bgp_route_map_update (const char *unused
)
2303 struct listnode
*node
, *nnode
;
2304 struct listnode
*mnode
, *mnnode
;
2307 struct peer_group
*group
;
2308 struct bgp_filter
*filter
;
2309 struct bgp_node
*bn
;
2310 struct bgp_static
*bgp_static
;
2312 /* For neighbor route-map updates. */
2313 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
2315 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
2317 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2318 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2320 filter
= &peer
->filter
[afi
][safi
];
2322 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++)
2324 if (filter
->map
[direct
].name
)
2325 filter
->map
[direct
].map
=
2326 route_map_lookup_by_name (filter
->map
[direct
].name
);
2328 filter
->map
[direct
].map
= NULL
;
2331 if (filter
->usmap
.name
)
2332 filter
->usmap
.map
= route_map_lookup_by_name (filter
->usmap
.name
);
2334 filter
->usmap
.map
= NULL
;
2337 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
2339 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2340 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2342 filter
= &group
->conf
->filter
[afi
][safi
];
2344 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++)
2346 if (filter
->map
[direct
].name
)
2347 filter
->map
[direct
].map
=
2348 route_map_lookup_by_name (filter
->map
[direct
].name
);
2350 filter
->map
[direct
].map
= NULL
;
2353 if (filter
->usmap
.name
)
2354 filter
->usmap
.map
= route_map_lookup_by_name (filter
->usmap
.name
);
2356 filter
->usmap
.map
= NULL
;
2361 /* For default-originate route-map updates. */
2362 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
2364 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
2366 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2367 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2369 if (peer
->default_rmap
[afi
][safi
].name
)
2370 peer
->default_rmap
[afi
][safi
].map
=
2371 route_map_lookup_by_name (peer
->default_rmap
[afi
][safi
].name
);
2373 peer
->default_rmap
[afi
][safi
].map
= NULL
;
2378 /* For network route-map updates. */
2379 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
2381 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2382 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2383 for (bn
= bgp_table_top (bgp
->route
[afi
][safi
]); bn
;
2384 bn
= bgp_route_next (bn
))
2385 if ((bgp_static
= bn
->info
) != NULL
)
2387 if (bgp_static
->rmap
.name
)
2388 bgp_static
->rmap
.map
=
2389 route_map_lookup_by_name (bgp_static
->rmap
.name
);
2391 bgp_static
->rmap
.map
= NULL
;
2395 /* For redistribute route-map updates. */
2396 for (ALL_LIST_ELEMENTS (bm
->bgp
, mnode
, mnnode
, bgp
))
2398 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2400 if (bgp
->rmap
[ZEBRA_FAMILY_IPV4
][i
].name
)
2401 bgp
->rmap
[ZEBRA_FAMILY_IPV4
][i
].map
=
2402 route_map_lookup_by_name (bgp
->rmap
[ZEBRA_FAMILY_IPV4
][i
].name
);
2404 if (bgp
->rmap
[ZEBRA_FAMILY_IPV6
][i
].name
)
2405 bgp
->rmap
[ZEBRA_FAMILY_IPV6
][i
].map
=
2406 route_map_lookup_by_name (bgp
->rmap
[ZEBRA_FAMILY_IPV6
][i
].name
);
2407 #endif /* HAVE_IPV6 */
2414 "match peer (A.B.C.D|X:X::X:X)",
2416 "Match peer address\n"
2417 "IPv6 address of peer\n"
2418 "IP address of peer\n")
2420 return bgp_route_match_add (vty
, vty
->index
, "peer", argv
[0]);
2423 DEFUN (match_peer_local
,
2424 match_peer_local_cmd
,
2427 "Match peer address\n"
2428 "Static or Redistributed routes\n")
2430 return bgp_route_match_add (vty
, vty
->index
, "peer", NULL
);
2433 DEFUN (no_match_peer
,
2438 "Match peer address\n")
2441 return bgp_route_match_delete (vty
, vty
->index
, "peer", NULL
);
2443 return bgp_route_match_delete (vty
, vty
->index
, "peer", argv
[0]);
2446 ALIAS (no_match_peer
,
2447 no_match_peer_val_cmd
,
2448 "no match peer (A.B.C.D|X:X::X:X)",
2451 "Match peer address\n"
2452 "IPv6 address of peer\n"
2453 "IP address of peer\n")
2455 ALIAS (no_match_peer
,
2456 no_match_peer_local_cmd
,
2457 "no match peer local",
2460 "Match peer address\n"
2461 "Static or Redistributed routes\n")
2463 DEFUN (match_ip_address
,
2464 match_ip_address_cmd
,
2465 "match ip address (<1-199>|<1300-2699>|WORD)",
2468 "Match address of route\n"
2469 "IP access-list number\n"
2470 "IP access-list number (expanded range)\n"
2471 "IP Access-list name\n")
2473 return bgp_route_match_add (vty
, vty
->index
, "ip address", argv
[0]);
2476 DEFUN (no_match_ip_address
,
2477 no_match_ip_address_cmd
,
2478 "no match ip address",
2482 "Match address of route\n")
2485 return bgp_route_match_delete (vty
, vty
->index
, "ip address", NULL
);
2487 return bgp_route_match_delete (vty
, vty
->index
, "ip address", argv
[0]);
2490 ALIAS (no_match_ip_address
,
2491 no_match_ip_address_val_cmd
,
2492 "no match ip address (<1-199>|<1300-2699>|WORD)",
2496 "Match address of route\n"
2497 "IP access-list number\n"
2498 "IP access-list number (expanded range)\n"
2499 "IP Access-list name\n")
2501 DEFUN (match_ip_next_hop
,
2502 match_ip_next_hop_cmd
,
2503 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
2506 "Match next-hop address of route\n"
2507 "IP access-list number\n"
2508 "IP access-list number (expanded range)\n"
2509 "IP Access-list name\n")
2511 return bgp_route_match_add (vty
, vty
->index
, "ip next-hop", argv
[0]);
2514 DEFUN (no_match_ip_next_hop
,
2515 no_match_ip_next_hop_cmd
,
2516 "no match ip next-hop",
2520 "Match next-hop address of route\n")
2523 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop", NULL
);
2525 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop", argv
[0]);
2528 ALIAS (no_match_ip_next_hop
,
2529 no_match_ip_next_hop_val_cmd
,
2530 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2534 "Match next-hop address of route\n"
2535 "IP access-list number\n"
2536 "IP access-list number (expanded range)\n"
2537 "IP Access-list name\n")
2539 DEFUN (match_ip_route_source
,
2540 match_ip_route_source_cmd
,
2541 "match ip route-source (<1-199>|<1300-2699>|WORD)",
2544 "Match advertising source address of route\n"
2545 "IP access-list number\n"
2546 "IP access-list number (expanded range)\n"
2547 "IP standard access-list name\n")
2549 return bgp_route_match_add (vty
, vty
->index
, "ip route-source", argv
[0]);
2552 DEFUN (no_match_ip_route_source
,
2553 no_match_ip_route_source_cmd
,
2554 "no match ip route-source",
2558 "Match advertising source address of route\n")
2561 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source", NULL
);
2563 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source", argv
[0]);
2566 ALIAS (no_match_ip_route_source
,
2567 no_match_ip_route_source_val_cmd
,
2568 "no match ip route-source (<1-199>|<1300-2699>|WORD)",
2572 "Match advertising source address of route\n"
2573 "IP access-list number\n"
2574 "IP access-list number (expanded range)\n"
2575 "IP standard access-list name\n")
2577 DEFUN (match_ip_address_prefix_list
,
2578 match_ip_address_prefix_list_cmd
,
2579 "match ip address prefix-list WORD",
2582 "Match address of route\n"
2583 "Match entries of prefix-lists\n"
2584 "IP prefix-list name\n")
2586 return bgp_route_match_add (vty
, vty
->index
, "ip address prefix-list", argv
[0]);
2589 DEFUN (no_match_ip_address_prefix_list
,
2590 no_match_ip_address_prefix_list_cmd
,
2591 "no match ip address prefix-list",
2595 "Match address of route\n"
2596 "Match entries of prefix-lists\n")
2599 return bgp_route_match_delete (vty
, vty
->index
, "ip address prefix-list", NULL
);
2601 return bgp_route_match_delete (vty
, vty
->index
, "ip address prefix-list", argv
[0]);
2604 ALIAS (no_match_ip_address_prefix_list
,
2605 no_match_ip_address_prefix_list_val_cmd
,
2606 "no match ip address prefix-list WORD",
2610 "Match address of route\n"
2611 "Match entries of prefix-lists\n"
2612 "IP prefix-list name\n")
2614 DEFUN (match_ip_next_hop_prefix_list
,
2615 match_ip_next_hop_prefix_list_cmd
,
2616 "match ip next-hop prefix-list WORD",
2619 "Match next-hop address of route\n"
2620 "Match entries of prefix-lists\n"
2621 "IP prefix-list name\n")
2623 return bgp_route_match_add (vty
, vty
->index
, "ip next-hop prefix-list", argv
[0]);
2626 DEFUN (no_match_ip_next_hop_prefix_list
,
2627 no_match_ip_next_hop_prefix_list_cmd
,
2628 "no match ip next-hop prefix-list",
2632 "Match next-hop address of route\n"
2633 "Match entries of prefix-lists\n")
2636 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop prefix-list", NULL
);
2638 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop prefix-list", argv
[0]);
2641 ALIAS (no_match_ip_next_hop_prefix_list
,
2642 no_match_ip_next_hop_prefix_list_val_cmd
,
2643 "no match ip next-hop prefix-list WORD",
2647 "Match next-hop address of route\n"
2648 "Match entries of prefix-lists\n"
2649 "IP prefix-list name\n")
2651 DEFUN (match_ip_route_source_prefix_list
,
2652 match_ip_route_source_prefix_list_cmd
,
2653 "match ip route-source prefix-list WORD",
2656 "Match advertising source address of route\n"
2657 "Match entries of prefix-lists\n"
2658 "IP prefix-list name\n")
2660 return bgp_route_match_add (vty
, vty
->index
, "ip route-source prefix-list", argv
[0]);
2663 DEFUN (no_match_ip_route_source_prefix_list
,
2664 no_match_ip_route_source_prefix_list_cmd
,
2665 "no match ip route-source prefix-list",
2669 "Match advertising source address of route\n"
2670 "Match entries of prefix-lists\n")
2673 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source prefix-list", NULL
);
2675 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source prefix-list", argv
[0]);
2678 ALIAS (no_match_ip_route_source_prefix_list
,
2679 no_match_ip_route_source_prefix_list_val_cmd
,
2680 "no match ip route-source prefix-list WORD",
2684 "Match advertising source address of route\n"
2685 "Match entries of prefix-lists\n"
2686 "IP prefix-list name\n")
2688 DEFUN (match_metric
,
2690 "match metric <0-4294967295>",
2692 "Match metric of route\n"
2695 return bgp_route_match_add (vty
, vty
->index
, "metric", argv
[0]);
2698 DEFUN (no_match_metric
,
2699 no_match_metric_cmd
,
2703 "Match metric of route\n")
2706 return bgp_route_match_delete (vty
, vty
->index
, "metric", NULL
);
2708 return bgp_route_match_delete (vty
, vty
->index
, "metric", argv
[0]);
2711 ALIAS (no_match_metric
,
2712 no_match_metric_val_cmd
,
2713 "no match metric <0-4294967295>",
2716 "Match metric of route\n"
2719 DEFUN (match_community
,
2720 match_community_cmd
,
2721 "match community (<1-99>|<100-500>|WORD)",
2723 "Match BGP community list\n"
2724 "Community-list number (standard)\n"
2725 "Community-list number (expanded)\n"
2726 "Community-list name\n")
2728 return bgp_route_match_add (vty
, vty
->index
, "community", argv
[0]);
2731 DEFUN (match_community_exact
,
2732 match_community_exact_cmd
,
2733 "match community (<1-99>|<100-500>|WORD) exact-match",
2735 "Match BGP community list\n"
2736 "Community-list number (standard)\n"
2737 "Community-list number (expanded)\n"
2738 "Community-list name\n"
2739 "Do exact matching of communities\n")
2744 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
2745 strlen (argv
[0]) + strlen ("exact-match") + 2);
2747 sprintf (argstr
, "%s exact-match", argv
[0]);
2749 ret
= bgp_route_match_add (vty
, vty
->index
, "community", argstr
);
2751 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
2756 DEFUN (no_match_community
,
2757 no_match_community_cmd
,
2758 "no match community",
2761 "Match BGP community list\n")
2763 return bgp_route_match_delete (vty
, vty
->index
, "community", NULL
);
2766 ALIAS (no_match_community
,
2767 no_match_community_val_cmd
,
2768 "no match community (<1-99>|<100-500>|WORD)",
2771 "Match BGP community list\n"
2772 "Community-list number (standard)\n"
2773 "Community-list number (expanded)\n"
2774 "Community-list name\n")
2776 ALIAS (no_match_community
,
2777 no_match_community_exact_cmd
,
2778 "no match community (<1-99>|<100-500>|WORD) exact-match",
2781 "Match BGP community list\n"
2782 "Community-list number (standard)\n"
2783 "Community-list number (expanded)\n"
2784 "Community-list name\n"
2785 "Do exact matching of communities\n")
2787 DEFUN (match_ecommunity
,
2788 match_ecommunity_cmd
,
2789 "match extcommunity (<1-99>|<100-500>|WORD)",
2791 "Match BGP/VPN extended community list\n"
2792 "Extended community-list number (standard)\n"
2793 "Extended community-list number (expanded)\n"
2794 "Extended community-list name\n")
2796 return bgp_route_match_add (vty
, vty
->index
, "extcommunity", argv
[0]);
2799 DEFUN (no_match_ecommunity
,
2800 no_match_ecommunity_cmd
,
2801 "no match extcommunity",
2804 "Match BGP/VPN extended community list\n")
2806 return bgp_route_match_delete (vty
, vty
->index
, "extcommunity", NULL
);
2809 ALIAS (no_match_ecommunity
,
2810 no_match_ecommunity_val_cmd
,
2811 "no match extcommunity (<1-99>|<100-500>|WORD)",
2814 "Match BGP/VPN extended community list\n"
2815 "Extended community-list number (standard)\n"
2816 "Extended community-list number (expanded)\n"
2817 "Extended community-list name\n")
2819 DEFUN (match_aspath
,
2821 "match as-path WORD",
2823 "Match BGP AS path list\n"
2824 "AS path access-list name\n")
2826 return bgp_route_match_add (vty
, vty
->index
, "as-path", argv
[0]);
2829 DEFUN (no_match_aspath
,
2830 no_match_aspath_cmd
,
2834 "Match BGP AS path list\n")
2836 return bgp_route_match_delete (vty
, vty
->index
, "as-path", NULL
);
2839 ALIAS (no_match_aspath
,
2840 no_match_aspath_val_cmd
,
2841 "no match as-path WORD",
2844 "Match BGP AS path list\n"
2845 "AS path access-list name\n")
2847 DEFUN (match_origin
,
2849 "match origin (egp|igp|incomplete)",
2854 "unknown heritage\n")
2856 if (strncmp (argv
[0], "igp", 2) == 0)
2857 return bgp_route_match_add (vty
, vty
->index
, "origin", "igp");
2858 if (strncmp (argv
[0], "egp", 1) == 0)
2859 return bgp_route_match_add (vty
, vty
->index
, "origin", "egp");
2860 if (strncmp (argv
[0], "incomplete", 2) == 0)
2861 return bgp_route_match_add (vty
, vty
->index
, "origin", "incomplete");
2866 DEFUN (no_match_origin
,
2867 no_match_origin_cmd
,
2871 "BGP origin code\n")
2873 return bgp_route_match_delete (vty
, vty
->index
, "origin", NULL
);
2876 ALIAS (no_match_origin
,
2877 no_match_origin_val_cmd
,
2878 "no match origin (egp|igp|incomplete)",
2884 "unknown heritage\n")
2886 DEFUN (set_ip_nexthop
,
2888 "set ip next-hop A.B.C.D",
2891 "Next hop address\n"
2892 "IP address of next hop\n")
2897 ret
= str2sockunion (argv
[0], &su
);
2900 vty_out (vty
, "%% Malformed Next-hop address%s", VTY_NEWLINE
);
2904 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", argv
[0]);
2907 DEFUN (set_ip_nexthop_peer
,
2908 set_ip_nexthop_peer_cmd
,
2909 "set ip next-hop peer-address",
2912 "Next hop address\n"
2913 "Use peer address (for BGP only)\n")
2915 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", "peer-address");
2918 DEFUN_DEPRECATED (no_set_ip_nexthop_peer
,
2919 no_set_ip_nexthop_peer_cmd
,
2920 "no set ip next-hop peer-address",
2924 "Next hop address\n"
2925 "Use peer address (for BGP only)\n")
2927 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", NULL
);
2931 DEFUN (no_set_ip_nexthop
,
2932 no_set_ip_nexthop_cmd
,
2933 "no set ip next-hop",
2936 "Next hop address\n")
2939 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", NULL
);
2941 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", argv
[0]);
2944 ALIAS (no_set_ip_nexthop
,
2945 no_set_ip_nexthop_val_cmd
,
2946 "no set ip next-hop A.B.C.D",
2950 "Next hop address\n"
2951 "IP address of next hop\n")
2955 "set metric <0-4294967295>",
2957 "Metric value for destination routing protocol\n"
2960 return bgp_route_set_add (vty
, vty
->index
, "metric", argv
[0]);
2964 set_metric_addsub_cmd
,
2965 "set metric <+/-metric>",
2967 "Metric value for destination routing protocol\n"
2968 "Add or subtract metric\n")
2970 DEFUN (no_set_metric
,
2975 "Metric value for destination routing protocol\n")
2978 return bgp_route_set_delete (vty
, vty
->index
, "metric", NULL
);
2980 return bgp_route_set_delete (vty
, vty
->index
, "metric", argv
[0]);
2983 ALIAS (no_set_metric
,
2984 no_set_metric_val_cmd
,
2985 "no set metric <0-4294967295>",
2988 "Metric value for destination routing protocol\n"
2991 DEFUN (set_local_pref
,
2993 "set local-preference <0-4294967295>",
2995 "BGP local preference path attribute\n"
2996 "Preference value\n")
2998 return bgp_route_set_add (vty
, vty
->index
, "local-preference", argv
[0]);
3001 DEFUN (no_set_local_pref
,
3002 no_set_local_pref_cmd
,
3003 "no set local-preference",
3006 "BGP local preference path attribute\n")
3009 return bgp_route_set_delete (vty
, vty
->index
, "local-preference", NULL
);
3011 return bgp_route_set_delete (vty
, vty
->index
, "local-preference", argv
[0]);
3014 ALIAS (no_set_local_pref
,
3015 no_set_local_pref_val_cmd
,
3016 "no set local-preference <0-4294967295>",
3019 "BGP local preference path attribute\n"
3020 "Preference value\n")
3024 "set weight <0-4294967295>",
3026 "BGP weight for routing table\n"
3029 return bgp_route_set_add (vty
, vty
->index
, "weight", argv
[0]);
3032 DEFUN (no_set_weight
,
3037 "BGP weight for routing table\n")
3040 return bgp_route_set_delete (vty
, vty
->index
, "weight", NULL
);
3042 return bgp_route_set_delete (vty
, vty
->index
, "weight", argv
[0]);
3045 ALIAS (no_set_weight
,
3046 no_set_weight_val_cmd
,
3047 "no set weight <0-4294967295>",
3050 "BGP weight for routing table\n"
3053 DEFUN (set_aspath_prepend
,
3054 set_aspath_prepend_cmd
,
3055 "set as-path prepend ." CMD_AS_RANGE
,
3057 "Transform BGP AS_PATH attribute\n"
3058 "Prepend to the as-path\n"
3064 str
= argv_concat (argv
, argc
, 0);
3065 ret
= bgp_route_set_add (vty
, vty
->index
, "as-path prepend", str
);
3066 XFREE (MTYPE_TMP
, str
);
3071 DEFUN (no_set_aspath_prepend
,
3072 no_set_aspath_prepend_cmd
,
3073 "no set as-path prepend",
3076 "Transform BGP AS_PATH attribute\n"
3077 "Prepend to the as-path\n")
3083 return bgp_route_set_delete (vty
, vty
->index
, "as-path prepend", NULL
);
3085 str
= argv_concat (argv
, argc
, 0);
3086 ret
= bgp_route_set_delete (vty
, vty
->index
, "as-path prepend", str
);
3087 XFREE (MTYPE_TMP
, str
);
3091 ALIAS (no_set_aspath_prepend
,
3092 no_set_aspath_prepend_val_cmd
,
3093 "no set as-path prepend ." CMD_AS_RANGE
,
3096 "Transform BGP AS_PATH attribute\n"
3097 "Prepend to the as-path\n"
3100 DEFUN (set_aspath_exclude
,
3101 set_aspath_exclude_cmd
,
3102 "set as-path exclude ." CMD_AS_RANGE
,
3104 "Transform BGP AS-path attribute\n"
3105 "Exclude from the as-path\n"
3111 str
= argv_concat (argv
, argc
, 0);
3112 ret
= bgp_route_set_add (vty
, vty
->index
, "as-path exclude", str
);
3113 XFREE (MTYPE_TMP
, str
);
3117 DEFUN (no_set_aspath_exclude
,
3118 no_set_aspath_exclude_cmd
,
3119 "no set as-path exclude",
3122 "Transform BGP AS_PATH attribute\n"
3123 "Exclude from the as-path\n")
3129 return bgp_route_set_delete (vty
, vty
->index
, "as-path exclude", NULL
);
3131 str
= argv_concat (argv
, argc
, 0);
3132 ret
= bgp_route_set_delete (vty
, vty
->index
, "as-path exclude", str
);
3133 XFREE (MTYPE_TMP
, str
);
3137 ALIAS (no_set_aspath_exclude
,
3138 no_set_aspath_exclude_val_cmd
,
3139 "no set as-path exclude ." CMD_AS_RANGE
,
3142 "Transform BGP AS_PATH attribute\n"
3143 "Exclude from the as-path\n"
3146 DEFUN (set_community
,
3148 "set community .AA:NN",
3150 "BGP community attribute\n"
3151 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3157 struct community
*com
= NULL
;
3162 b
= buffer_new (1024);
3164 for (i
= 0; i
< argc
; i
++)
3166 if (strncmp (argv
[i
], "additive", strlen (argv
[i
])) == 0)
3173 buffer_putc (b
, ' ');
3177 if (strncmp (argv
[i
], "internet", strlen (argv
[i
])) == 0)
3179 buffer_putstr (b
, "internet");
3182 if (strncmp (argv
[i
], "local-AS", strlen (argv
[i
])) == 0)
3184 buffer_putstr (b
, "local-AS");
3187 if (strncmp (argv
[i
], "no-a", strlen ("no-a")) == 0
3188 && strncmp (argv
[i
], "no-advertise", strlen (argv
[i
])) == 0)
3190 buffer_putstr (b
, "no-advertise");
3193 if (strncmp (argv
[i
], "no-e", strlen ("no-e"))== 0
3194 && strncmp (argv
[i
], "no-export", strlen (argv
[i
])) == 0)
3196 buffer_putstr (b
, "no-export");
3199 buffer_putstr (b
, argv
[i
]);
3201 buffer_putc (b
, '\0');
3203 /* Fetch result string then compile it to communities attribute. */
3204 str
= buffer_getstr (b
);
3209 com
= community_str2com (str
);
3210 XFREE (MTYPE_TMP
, str
);
3213 /* Can't compile user input into communities attribute. */
3216 vty_out (vty
, "%% Malformed communities attribute%s", VTY_NEWLINE
);
3220 /* Set communites attribute string. */
3221 str
= community_str (com
);
3225 argstr
= XCALLOC (MTYPE_TMP
, strlen (str
) + strlen (" additive") + 1);
3226 strcpy (argstr
, str
);
3227 strcpy (argstr
+ strlen (str
), " additive");
3228 ret
= bgp_route_set_add (vty
, vty
->index
, "community", argstr
);
3229 XFREE (MTYPE_TMP
, argstr
);
3232 ret
= bgp_route_set_add (vty
, vty
->index
, "community", str
);
3234 community_free (com
);
3239 DEFUN (set_community_none
,
3240 set_community_none_cmd
,
3241 "set community none",
3243 "BGP community attribute\n"
3244 "No community attribute\n")
3246 return bgp_route_set_add (vty
, vty
->index
, "community", "none");
3249 DEFUN (no_set_community
,
3250 no_set_community_cmd
,
3254 "BGP community attribute\n")
3256 return bgp_route_set_delete (vty
, vty
->index
, "community", NULL
);
3259 ALIAS (no_set_community
,
3260 no_set_community_val_cmd
,
3261 "no set community .AA:NN",
3264 "BGP community attribute\n"
3265 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3267 ALIAS (no_set_community
,
3268 no_set_community_none_cmd
,
3269 "no set community none",
3272 "BGP community attribute\n"
3273 "No community attribute\n")
3275 DEFUN (set_community_delete
,
3276 set_community_delete_cmd
,
3277 "set comm-list (<1-99>|<100-500>|WORD) delete",
3279 "set BGP community list (for deletion)\n"
3280 "Community-list number (standard)\n"
3281 "Communitly-list number (expanded)\n"
3282 "Community-list name\n"
3283 "Delete matching communities\n")
3287 str
= XCALLOC (MTYPE_TMP
, strlen (argv
[0]) + strlen (" delete") + 1);
3288 strcpy (str
, argv
[0]);
3289 strcpy (str
+ strlen (argv
[0]), " delete");
3291 bgp_route_set_add (vty
, vty
->index
, "comm-list", str
);
3293 XFREE (MTYPE_TMP
, str
);
3297 DEFUN (no_set_community_delete
,
3298 no_set_community_delete_cmd
,
3302 "set BGP community list (for deletion)\n")
3304 return bgp_route_set_delete (vty
, vty
->index
, "comm-list", NULL
);
3307 ALIAS (no_set_community_delete
,
3308 no_set_community_delete_val_cmd
,
3309 "no set comm-list (<1-99>|<100-500>|WORD) delete",
3312 "set BGP community list (for deletion)\n"
3313 "Community-list number (standard)\n"
3314 "Communitly-list number (expanded)\n"
3315 "Community-list name\n"
3316 "Delete matching communities\n")
3318 DEFUN (set_ecommunity_rt
,
3319 set_ecommunity_rt_cmd
,
3320 "set extcommunity rt .ASN:nn_or_IP-address:nn",
3322 "BGP extended community attribute\n"
3323 "Route Target extended community\n"
3324 "VPN extended community\n")
3329 str
= argv_concat (argv
, argc
, 0);
3330 ret
= bgp_route_set_add (vty
, vty
->index
, "extcommunity rt", str
);
3331 XFREE (MTYPE_TMP
, str
);
3336 DEFUN (no_set_ecommunity_rt
,
3337 no_set_ecommunity_rt_cmd
,
3338 "no set extcommunity rt",
3341 "BGP extended community attribute\n"
3342 "Route Target extended community\n")
3344 return bgp_route_set_delete (vty
, vty
->index
, "extcommunity rt", NULL
);
3347 ALIAS (no_set_ecommunity_rt
,
3348 no_set_ecommunity_rt_val_cmd
,
3349 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
3352 "BGP extended community attribute\n"
3353 "Route Target extended community\n"
3354 "VPN extended community\n")
3356 DEFUN (set_ecommunity_soo
,
3357 set_ecommunity_soo_cmd
,
3358 "set extcommunity soo .ASN:nn_or_IP-address:nn",
3360 "BGP extended community attribute\n"
3361 "Site-of-Origin extended community\n"
3362 "VPN extended community\n")
3367 str
= argv_concat (argv
, argc
, 0);
3368 ret
= bgp_route_set_add (vty
, vty
->index
, "extcommunity soo", str
);
3369 XFREE (MTYPE_TMP
, str
);
3373 DEFUN (no_set_ecommunity_soo
,
3374 no_set_ecommunity_soo_cmd
,
3375 "no set extcommunity soo",
3378 "BGP extended community attribute\n"
3379 "Site-of-Origin extended community\n")
3381 return bgp_route_set_delete (vty
, vty
->index
, "extcommunity soo", NULL
);
3384 ALIAS (no_set_ecommunity_soo
,
3385 no_set_ecommunity_soo_val_cmd
,
3386 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
3389 "BGP extended community attribute\n"
3390 "Site-of-Origin extended community\n"
3391 "VPN extended community\n")
3395 "set origin (egp|igp|incomplete)",
3400 "unknown heritage\n")
3402 if (strncmp (argv
[0], "igp", 2) == 0)
3403 return bgp_route_set_add (vty
, vty
->index
, "origin", "igp");
3404 if (strncmp (argv
[0], "egp", 1) == 0)
3405 return bgp_route_set_add (vty
, vty
->index
, "origin", "egp");
3406 if (strncmp (argv
[0], "incomplete", 2) == 0)
3407 return bgp_route_set_add (vty
, vty
->index
, "origin", "incomplete");
3412 DEFUN (no_set_origin
,
3417 "BGP origin code\n")
3419 return bgp_route_set_delete (vty
, vty
->index
, "origin", NULL
);
3422 ALIAS (no_set_origin
,
3423 no_set_origin_val_cmd
,
3424 "no set origin (egp|igp|incomplete)",
3430 "unknown heritage\n")
3432 DEFUN (set_atomic_aggregate
,
3433 set_atomic_aggregate_cmd
,
3434 "set atomic-aggregate",
3436 "BGP atomic aggregate attribute\n" )
3438 return bgp_route_set_add (vty
, vty
->index
, "atomic-aggregate", NULL
);
3441 DEFUN (no_set_atomic_aggregate
,
3442 no_set_atomic_aggregate_cmd
,
3443 "no set atomic-aggregate",
3446 "BGP atomic aggregate attribute\n" )
3448 return bgp_route_set_delete (vty
, vty
->index
, "atomic-aggregate", NULL
);
3451 DEFUN (set_aggregator_as
,
3452 set_aggregator_as_cmd
,
3453 "set aggregator as " CMD_AS_RANGE
" A.B.C.D",
3455 "BGP aggregator attribute\n"
3456 "AS number of aggregator\n"
3458 "IP address of aggregator\n")
3462 struct in_addr address
;
3465 VTY_GET_INTEGER_RANGE ("AS", as
, argv
[0], 1, BGP_AS4_MAX
);
3467 ret
= inet_aton (argv
[1], &address
);
3470 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
3474 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3475 strlen (argv
[0]) + strlen (argv
[1]) + 2);
3477 sprintf (argstr
, "%s %s", argv
[0], argv
[1]);
3479 ret
= bgp_route_set_add (vty
, vty
->index
, "aggregator as", argstr
);
3481 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3486 DEFUN (no_set_aggregator_as
,
3487 no_set_aggregator_as_cmd
,
3488 "no set aggregator as",
3491 "BGP aggregator attribute\n"
3492 "AS number of aggregator\n")
3496 struct in_addr address
;
3500 return bgp_route_set_delete (vty
, vty
->index
, "aggregator as", NULL
);
3502 VTY_GET_INTEGER_RANGE ("AS", as
, argv
[0], 1, BGP_AS4_MAX
);
3504 ret
= inet_aton (argv
[1], &address
);
3507 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
3511 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3512 strlen (argv
[0]) + strlen (argv
[1]) + 2);
3514 sprintf (argstr
, "%s %s", argv
[0], argv
[1]);
3516 ret
= bgp_route_set_delete (vty
, vty
->index
, "aggregator as", argstr
);
3518 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3523 ALIAS (no_set_aggregator_as
,
3524 no_set_aggregator_as_val_cmd
,
3525 "no set aggregator as " CMD_AS_RANGE
" A.B.C.D",
3528 "BGP aggregator attribute\n"
3529 "AS number of aggregator\n"
3531 "IP address of aggregator\n")
3535 DEFUN (match_ipv6_address
,
3536 match_ipv6_address_cmd
,
3537 "match ipv6 address WORD",
3540 "Match IPv6 address of route\n"
3541 "IPv6 access-list name\n")
3543 return bgp_route_match_add (vty
, vty
->index
, "ipv6 address", argv
[0]);
3546 DEFUN (no_match_ipv6_address
,
3547 no_match_ipv6_address_cmd
,
3548 "no match ipv6 address WORD",
3552 "Match IPv6 address of route\n"
3553 "IPv6 access-list name\n")
3555 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 address", argv
[0]);
3558 DEFUN (match_ipv6_next_hop
,
3559 match_ipv6_next_hop_cmd
,
3560 "match ipv6 next-hop X:X::X:X",
3563 "Match IPv6 next-hop address of route\n"
3564 "IPv6 address of next hop\n")
3566 return bgp_route_match_add (vty
, vty
->index
, "ipv6 next-hop", argv
[0]);
3569 DEFUN (no_match_ipv6_next_hop
,
3570 no_match_ipv6_next_hop_cmd
,
3571 "no match ipv6 next-hop X:X::X:X",
3575 "Match IPv6 next-hop address of route\n"
3576 "IPv6 address of next hop\n")
3578 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 next-hop", argv
[0]);
3581 DEFUN (match_ipv6_address_prefix_list
,
3582 match_ipv6_address_prefix_list_cmd
,
3583 "match ipv6 address prefix-list WORD",
3586 "Match address of route\n"
3587 "Match entries of prefix-lists\n"
3588 "IP prefix-list name\n")
3590 return bgp_route_match_add (vty
, vty
->index
, "ipv6 address prefix-list", argv
[0]);
3593 DEFUN (no_match_ipv6_address_prefix_list
,
3594 no_match_ipv6_address_prefix_list_cmd
,
3595 "no match ipv6 address prefix-list WORD",
3599 "Match address of route\n"
3600 "Match entries of prefix-lists\n"
3601 "IP prefix-list name\n")
3603 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 address prefix-list", argv
[0]);
3606 DEFUN (set_ipv6_nexthop_global
,
3607 set_ipv6_nexthop_global_cmd
,
3608 "set ipv6 next-hop global X:X::X:X",
3611 "IPv6 next-hop address\n"
3612 "IPv6 global address\n"
3613 "IPv6 address of next hop\n")
3615 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop global", argv
[0]);
3618 DEFUN (no_set_ipv6_nexthop_global
,
3619 no_set_ipv6_nexthop_global_cmd
,
3620 "no set ipv6 next-hop global",
3624 "IPv6 next-hop address\n"
3625 "IPv6 global address\n")
3628 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop global", NULL
);
3630 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop global", argv
[0]);
3633 ALIAS (no_set_ipv6_nexthop_global
,
3634 no_set_ipv6_nexthop_global_val_cmd
,
3635 "no set ipv6 next-hop global X:X::X:X",
3639 "IPv6 next-hop address\n"
3640 "IPv6 global address\n"
3641 "IPv6 address of next hop\n")
3643 DEFUN (set_ipv6_nexthop_local
,
3644 set_ipv6_nexthop_local_cmd
,
3645 "set ipv6 next-hop local X:X::X:X",
3648 "IPv6 next-hop address\n"
3649 "IPv6 local address\n"
3650 "IPv6 address of next hop\n")
3652 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop local", argv
[0]);
3655 DEFUN (no_set_ipv6_nexthop_local
,
3656 no_set_ipv6_nexthop_local_cmd
,
3657 "no set ipv6 next-hop local",
3661 "IPv6 next-hop address\n"
3662 "IPv6 local address\n")
3665 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop local", NULL
);
3667 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop local", argv
[0]);
3670 ALIAS (no_set_ipv6_nexthop_local
,
3671 no_set_ipv6_nexthop_local_val_cmd
,
3672 "no set ipv6 next-hop local X:X::X:X",
3676 "IPv6 next-hop address\n"
3677 "IPv6 local address\n"
3678 "IPv6 address of next hop\n")
3679 #endif /* HAVE_IPV6 */
3681 DEFUN (set_vpnv4_nexthop
,
3682 set_vpnv4_nexthop_cmd
,
3683 "set vpnv4 next-hop A.B.C.D",
3685 "VPNv4 information\n"
3686 "VPNv4 next-hop address\n"
3687 "IP address of next hop\n")
3689 return bgp_route_set_add (vty
, vty
->index
, "vpnv4 next-hop", argv
[0]);
3692 DEFUN (no_set_vpnv4_nexthop
,
3693 no_set_vpnv4_nexthop_cmd
,
3694 "no set vpnv4 next-hop",
3697 "VPNv4 information\n"
3698 "VPNv4 next-hop address\n")
3701 return bgp_route_set_delete (vty
, vty
->index
, "vpnv4 next-hop", NULL
);
3703 return bgp_route_set_delete (vty
, vty
->index
, "vpnv4 next-hop", argv
[0]);
3706 ALIAS (no_set_vpnv4_nexthop
,
3707 no_set_vpnv4_nexthop_val_cmd
,
3708 "no set vpnv4 next-hop A.B.C.D",
3711 "VPNv4 information\n"
3712 "VPNv4 next-hop address\n"
3713 "IP address of next hop\n")
3715 DEFUN (set_originator_id
,
3716 set_originator_id_cmd
,
3717 "set originator-id A.B.C.D",
3719 "BGP originator ID attribute\n"
3720 "IP address of originator\n")
3722 return bgp_route_set_add (vty
, vty
->index
, "originator-id", argv
[0]);
3725 DEFUN (no_set_originator_id
,
3726 no_set_originator_id_cmd
,
3727 "no set originator-id",
3730 "BGP originator ID attribute\n")
3733 return bgp_route_set_delete (vty
, vty
->index
, "originator-id", NULL
);
3735 return bgp_route_set_delete (vty
, vty
->index
, "originator-id", argv
[0]);
3738 ALIAS (no_set_originator_id
,
3739 no_set_originator_id_val_cmd
,
3740 "no set originator-id A.B.C.D",
3743 "BGP originator ID attribute\n"
3744 "IP address of originator\n")
3746 DEFUN (set_pathlimit_ttl
,
3747 set_pathlimit_ttl_cmd
,
3748 "set pathlimit ttl <1-255>",
3750 "BGP AS-Pathlimit attribute\n"
3751 "Set AS-Path Hop-count TTL\n")
3753 return bgp_route_set_add (vty
, vty
->index
, "pathlimit ttl", argv
[0]);
3756 DEFUN (no_set_pathlimit_ttl
,
3757 no_set_pathlimit_ttl_cmd
,
3758 "no set pathlimit ttl",
3761 "BGP AS-Pathlimit attribute\n"
3762 "Set AS-Path Hop-count TTL\n")
3765 return bgp_route_set_delete (vty
, vty
->index
, "pathlimit ttl", NULL
);
3767 return bgp_route_set_delete (vty
, vty
->index
, "pathlimit ttl", argv
[0]);
3770 ALIAS (no_set_pathlimit_ttl
,
3771 no_set_pathlimit_ttl_val_cmd
,
3772 "no set pathlimit ttl <1-255>",
3775 "BGP AS-Pathlimit attribute\n"
3776 "Set AS-Path Hop-count TTL\n")
3778 DEFUN (match_pathlimit_as
,
3779 match_pathlimit_as_cmd
,
3780 "match pathlimit as <1-65535>",
3782 "BGP AS-Pathlimit attribute\n"
3783 "Match Pathlimit AS number\n")
3785 return bgp_route_match_add (vty
, vty
->index
, "pathlimit as", argv
[0]);
3788 DEFUN (no_match_pathlimit_as
,
3789 no_match_pathlimit_as_cmd
,
3790 "no match pathlimit as",
3793 "BGP AS-Pathlimit attribute\n"
3794 "Match Pathlimit AS number\n")
3797 return bgp_route_match_delete (vty
, vty
->index
, "pathlimit as", NULL
);
3799 return bgp_route_match_delete (vty
, vty
->index
, "pathlimit as", argv
[0]);
3802 ALIAS (no_match_pathlimit_as
,
3803 no_match_pathlimit_as_val_cmd
,
3804 "no match pathlimit as <1-65535>",
3807 "BGP AS-Pathlimit attribute\n"
3808 "Match Pathlimit ASN\n")
3811 /* Initialization of route map. */
3813 bgp_route_map_init (void)
3816 route_map_init_vty ();
3817 route_map_add_hook (bgp_route_map_update
);
3818 route_map_delete_hook (bgp_route_map_update
);
3820 route_map_install_match (&route_match_peer_cmd
);
3821 route_map_install_match (&route_match_ip_address_cmd
);
3822 route_map_install_match (&route_match_ip_next_hop_cmd
);
3823 route_map_install_match (&route_match_ip_route_source_cmd
);
3824 route_map_install_match (&route_match_ip_address_prefix_list_cmd
);
3825 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd
);
3826 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd
);
3827 route_map_install_match (&route_match_aspath_cmd
);
3828 route_map_install_match (&route_match_community_cmd
);
3829 route_map_install_match (&route_match_ecommunity_cmd
);
3830 route_map_install_match (&route_match_metric_cmd
);
3831 route_map_install_match (&route_match_origin_cmd
);
3833 route_map_install_set (&route_set_ip_nexthop_cmd
);
3834 route_map_install_set (&route_set_local_pref_cmd
);
3835 route_map_install_set (&route_set_weight_cmd
);
3836 route_map_install_set (&route_set_metric_cmd
);
3837 route_map_install_set (&route_set_aspath_prepend_cmd
);
3838 route_map_install_set (&route_set_aspath_exclude_cmd
);
3839 route_map_install_set (&route_set_origin_cmd
);
3840 route_map_install_set (&route_set_atomic_aggregate_cmd
);
3841 route_map_install_set (&route_set_aggregator_as_cmd
);
3842 route_map_install_set (&route_set_community_cmd
);
3843 route_map_install_set (&route_set_community_delete_cmd
);
3844 route_map_install_set (&route_set_vpnv4_nexthop_cmd
);
3845 route_map_install_set (&route_set_originator_id_cmd
);
3846 route_map_install_set (&route_set_ecommunity_rt_cmd
);
3847 route_map_install_set (&route_set_ecommunity_soo_cmd
);
3849 install_element (RMAP_NODE
, &match_peer_cmd
);
3850 install_element (RMAP_NODE
, &match_peer_local_cmd
);
3851 install_element (RMAP_NODE
, &no_match_peer_cmd
);
3852 install_element (RMAP_NODE
, &no_match_peer_val_cmd
);
3853 install_element (RMAP_NODE
, &no_match_peer_local_cmd
);
3854 install_element (RMAP_NODE
, &match_ip_address_cmd
);
3855 install_element (RMAP_NODE
, &no_match_ip_address_cmd
);
3856 install_element (RMAP_NODE
, &no_match_ip_address_val_cmd
);
3857 install_element (RMAP_NODE
, &match_ip_next_hop_cmd
);
3858 install_element (RMAP_NODE
, &no_match_ip_next_hop_cmd
);
3859 install_element (RMAP_NODE
, &no_match_ip_next_hop_val_cmd
);
3860 install_element (RMAP_NODE
, &match_ip_route_source_cmd
);
3861 install_element (RMAP_NODE
, &no_match_ip_route_source_cmd
);
3862 install_element (RMAP_NODE
, &no_match_ip_route_source_val_cmd
);
3864 install_element (RMAP_NODE
, &match_ip_address_prefix_list_cmd
);
3865 install_element (RMAP_NODE
, &no_match_ip_address_prefix_list_cmd
);
3866 install_element (RMAP_NODE
, &no_match_ip_address_prefix_list_val_cmd
);
3867 install_element (RMAP_NODE
, &match_ip_next_hop_prefix_list_cmd
);
3868 install_element (RMAP_NODE
, &no_match_ip_next_hop_prefix_list_cmd
);
3869 install_element (RMAP_NODE
, &no_match_ip_next_hop_prefix_list_val_cmd
);
3870 install_element (RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
3871 install_element (RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
3872 install_element (RMAP_NODE
, &no_match_ip_route_source_prefix_list_val_cmd
);
3874 install_element (RMAP_NODE
, &match_aspath_cmd
);
3875 install_element (RMAP_NODE
, &no_match_aspath_cmd
);
3876 install_element (RMAP_NODE
, &no_match_aspath_val_cmd
);
3877 install_element (RMAP_NODE
, &match_metric_cmd
);
3878 install_element (RMAP_NODE
, &no_match_metric_cmd
);
3879 install_element (RMAP_NODE
, &no_match_metric_val_cmd
);
3880 install_element (RMAP_NODE
, &match_community_cmd
);
3881 install_element (RMAP_NODE
, &match_community_exact_cmd
);
3882 install_element (RMAP_NODE
, &no_match_community_cmd
);
3883 install_element (RMAP_NODE
, &no_match_community_val_cmd
);
3884 install_element (RMAP_NODE
, &no_match_community_exact_cmd
);
3885 install_element (RMAP_NODE
, &match_ecommunity_cmd
);
3886 install_element (RMAP_NODE
, &no_match_ecommunity_cmd
);
3887 install_element (RMAP_NODE
, &no_match_ecommunity_val_cmd
);
3888 install_element (RMAP_NODE
, &match_origin_cmd
);
3889 install_element (RMAP_NODE
, &no_match_origin_cmd
);
3890 install_element (RMAP_NODE
, &no_match_origin_val_cmd
);
3892 install_element (RMAP_NODE
, &set_ip_nexthop_cmd
);
3893 install_element (RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
3894 install_element (RMAP_NODE
, &no_set_ip_nexthop_cmd
);
3895 install_element (RMAP_NODE
, &no_set_ip_nexthop_val_cmd
);
3896 install_element (RMAP_NODE
, &set_local_pref_cmd
);
3897 install_element (RMAP_NODE
, &no_set_local_pref_cmd
);
3898 install_element (RMAP_NODE
, &no_set_local_pref_val_cmd
);
3899 install_element (RMAP_NODE
, &set_weight_cmd
);
3900 install_element (RMAP_NODE
, &no_set_weight_cmd
);
3901 install_element (RMAP_NODE
, &no_set_weight_val_cmd
);
3902 install_element (RMAP_NODE
, &set_metric_cmd
);
3903 install_element (RMAP_NODE
, &set_metric_addsub_cmd
);
3904 install_element (RMAP_NODE
, &no_set_metric_cmd
);
3905 install_element (RMAP_NODE
, &no_set_metric_val_cmd
);
3906 install_element (RMAP_NODE
, &set_aspath_prepend_cmd
);
3907 install_element (RMAP_NODE
, &set_aspath_exclude_cmd
);
3908 install_element (RMAP_NODE
, &no_set_aspath_prepend_cmd
);
3909 install_element (RMAP_NODE
, &no_set_aspath_prepend_val_cmd
);
3910 install_element (RMAP_NODE
, &no_set_aspath_exclude_cmd
);
3911 install_element (RMAP_NODE
, &no_set_aspath_exclude_val_cmd
);
3912 install_element (RMAP_NODE
, &set_origin_cmd
);
3913 install_element (RMAP_NODE
, &no_set_origin_cmd
);
3914 install_element (RMAP_NODE
, &no_set_origin_val_cmd
);
3915 install_element (RMAP_NODE
, &set_atomic_aggregate_cmd
);
3916 install_element (RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
3917 install_element (RMAP_NODE
, &set_aggregator_as_cmd
);
3918 install_element (RMAP_NODE
, &no_set_aggregator_as_cmd
);
3919 install_element (RMAP_NODE
, &no_set_aggregator_as_val_cmd
);
3920 install_element (RMAP_NODE
, &set_community_cmd
);
3921 install_element (RMAP_NODE
, &set_community_none_cmd
);
3922 install_element (RMAP_NODE
, &no_set_community_cmd
);
3923 install_element (RMAP_NODE
, &no_set_community_val_cmd
);
3924 install_element (RMAP_NODE
, &no_set_community_none_cmd
);
3925 install_element (RMAP_NODE
, &set_community_delete_cmd
);
3926 install_element (RMAP_NODE
, &no_set_community_delete_cmd
);
3927 install_element (RMAP_NODE
, &no_set_community_delete_val_cmd
);
3928 install_element (RMAP_NODE
, &set_ecommunity_rt_cmd
);
3929 install_element (RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
3930 install_element (RMAP_NODE
, &no_set_ecommunity_rt_val_cmd
);
3931 install_element (RMAP_NODE
, &set_ecommunity_soo_cmd
);
3932 install_element (RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
3933 install_element (RMAP_NODE
, &no_set_ecommunity_soo_val_cmd
);
3934 install_element (RMAP_NODE
, &set_vpnv4_nexthop_cmd
);
3935 install_element (RMAP_NODE
, &no_set_vpnv4_nexthop_cmd
);
3936 install_element (RMAP_NODE
, &no_set_vpnv4_nexthop_val_cmd
);
3937 install_element (RMAP_NODE
, &set_originator_id_cmd
);
3938 install_element (RMAP_NODE
, &no_set_originator_id_cmd
);
3939 install_element (RMAP_NODE
, &no_set_originator_id_val_cmd
);
3942 route_map_install_match (&route_match_ipv6_address_cmd
);
3943 route_map_install_match (&route_match_ipv6_next_hop_cmd
);
3944 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd
);
3945 route_map_install_set (&route_set_ipv6_nexthop_global_cmd
);
3946 route_map_install_set (&route_set_ipv6_nexthop_local_cmd
);
3948 install_element (RMAP_NODE
, &match_ipv6_address_cmd
);
3949 install_element (RMAP_NODE
, &no_match_ipv6_address_cmd
);
3950 install_element (RMAP_NODE
, &match_ipv6_next_hop_cmd
);
3951 install_element (RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
3952 install_element (RMAP_NODE
, &match_ipv6_address_prefix_list_cmd
);
3953 install_element (RMAP_NODE
, &no_match_ipv6_address_prefix_list_cmd
);
3954 install_element (RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
3955 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
3956 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_val_cmd
);
3957 install_element (RMAP_NODE
, &set_ipv6_nexthop_local_cmd
);
3958 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_local_cmd
);
3959 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_local_val_cmd
);
3960 #endif /* HAVE_IPV6 */
3963 route_map_install_match (&route_match_pathlimit_as_cmd
);
3964 route_map_install_set (&route_set_pathlimit_ttl_cmd
);
3966 install_element (RMAP_NODE
, &set_pathlimit_ttl_cmd
);
3967 install_element (RMAP_NODE
, &no_set_pathlimit_ttl_cmd
);
3968 install_element (RMAP_NODE
, &no_set_pathlimit_ttl_val_cmd
);
3969 install_element (RMAP_NODE
, &match_pathlimit_as_cmd
);
3970 install_element (RMAP_NODE
, &no_match_pathlimit_as_cmd
);
3971 install_element (RMAP_NODE
, &no_match_pathlimit_as_val_cmd
);