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
34 #include "regex-gnu.h"
35 #endif /* HAVE_GNU_REGEX */
37 #include "sockunion.h"
39 #include "bgpd/bgpd.h"
40 #include "bgpd/bgp_table.h"
41 #include "bgpd/bgp_attr.h"
42 #include "bgpd/bgp_aspath.h"
43 #include "bgpd/bgp_route.h"
44 #include "bgpd/bgp_regex.h"
45 #include "bgpd/bgp_community.h"
46 #include "bgpd/bgp_clist.h"
47 #include "bgpd/bgp_filter.h"
48 #include "bgpd/bgp_mplsvpn.h"
49 #include "bgpd/bgp_ecommunity.h"
51 /* Memo of route-map commands.
60 ip route-source : (This will not be implemented by bgpd)
64 ipv6 route-source: (This will not be implemented by bgpd)
65 ipv6 prefix-list : Done
66 length : (This will not be implemented by bgpd)
68 route-type : (This will not be implemented by bgpd)
69 tag : (This will not be implemented by bgpd)
71 set as-path prepend : Done
73 automatic-tag : (This will not be implemented by bgpd)
77 default : (This will not be implemented by bgpd)
78 interface : (This will not be implemented by bgpd)
79 ip default : (This will not be implemented by bgpd)
81 ip precedence : (This will not be implemented by bgpd)
82 ip tos : (This will not be implemented by bgpd)
83 level : (This will not be implemented by bgpd)
84 local-preference : Done
88 tag : (This will not be implemented by bgpd)
93 set ipv6 next-hop global: Done
94 set ipv6 next-hop local : Done
98 /* 'match peer (A.B.C.D|X:X::X:X)' */
100 /* Compares the peer specified in the 'match peer' clause with the peer
101 received in bgp_info->peer. If it is the same, or if the peer structure
102 received is a peer_group containing it, returns RMAP_MATCH. */
104 route_match_peer (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
108 union sockunion
*su2
;
109 struct peer_group
*group
;
113 if (type
== RMAP_BGP
)
116 peer
= ((struct bgp_info
*) object
)->peer
;
118 if ( ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
) &&
119 ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_EXPORT
) )
122 /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
123 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
124 su2
= sockunion_str2su ("0.0.0.0");
125 if ( sockunion_same (su
, su2
) )
127 if ( CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
) ||
128 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
) ||
129 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
131 XFREE (MTYPE_SOCKUNION
, su2
);
138 XFREE (MTYPE_SOCKUNION
, su2
);
140 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
142 if (sockunion_same (su
, &peer
->su
))
150 LIST_LOOP (group
->peer
, peer
, nn
)
152 if (sockunion_same (su
, &peer
->su
))
163 route_match_peer_compile (char *arg
)
168 su
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (union sockunion
));
170 ret
= str2sockunion ( (arg
)? arg
: "0.0.0.0", su
);
172 XFREE (MTYPE_ROUTE_MAP_COMPILED
, su
);
179 /* Free route map's compiled `ip address' value. */
181 route_match_peer_free (void *rule
)
183 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
186 /* Route map commands for ip address matching. */
187 struct route_map_rule_cmd route_match_peer_cmd
=
191 route_match_peer_compile
,
192 route_match_peer_free
195 /* `match ip address IP_ACCESS_LIST' */
197 /* Match function should return 1 if match is success else return
200 route_match_ip_address (void *rule
, struct prefix
*prefix
,
201 route_map_object_t type
, void *object
)
203 struct access_list
*alist
;
204 /* struct prefix_ipv4 match; */
206 if (type
== RMAP_BGP
)
208 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
212 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
213 RMAP_NOMATCH
: RMAP_MATCH
);
218 /* Route map `ip address' match statement. `arg' should be
221 route_match_ip_address_compile (char *arg
)
223 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
226 /* Free route map's compiled `ip address' value. */
228 route_match_ip_address_free (void *rule
)
230 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
233 /* Route map commands for ip address matching. */
234 struct route_map_rule_cmd route_match_ip_address_cmd
=
237 route_match_ip_address
,
238 route_match_ip_address_compile
,
239 route_match_ip_address_free
242 /* `match ip next-hop IP_ADDRESS' */
244 /* Match function return 1 if match is success else return zero. */
246 route_match_ip_next_hop (void *rule
, struct prefix
*prefix
,
247 route_map_object_t type
, void *object
)
249 struct access_list
*alist
;
250 struct bgp_info
*bgp_info
;
251 struct prefix_ipv4 p
;
253 if (type
== RMAP_BGP
)
257 p
.prefix
= bgp_info
->attr
->nexthop
;
258 p
.prefixlen
= IPV4_MAX_BITLEN
;
260 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
264 return (access_list_apply (alist
, &p
) == FILTER_DENY
?
265 RMAP_NOMATCH
: RMAP_MATCH
);
270 /* Route map `ip next-hop' match statement. `arg' is
273 route_match_ip_next_hop_compile (char *arg
)
275 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
278 /* Free route map's compiled `ip address' value. */
280 route_match_ip_next_hop_free (void *rule
)
282 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
285 /* Route map commands for ip next-hop matching. */
286 struct route_map_rule_cmd route_match_ip_next_hop_cmd
=
289 route_match_ip_next_hop
,
290 route_match_ip_next_hop_compile
,
291 route_match_ip_next_hop_free
294 /* `match ip address prefix-list PREFIX_LIST' */
297 route_match_ip_address_prefix_list (void *rule
, struct prefix
*prefix
,
298 route_map_object_t type
, void *object
)
300 struct prefix_list
*plist
;
302 if (type
== RMAP_BGP
)
304 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
308 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
309 RMAP_NOMATCH
: RMAP_MATCH
);
315 route_match_ip_address_prefix_list_compile (char *arg
)
317 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
321 route_match_ip_address_prefix_list_free (void *rule
)
323 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
326 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
=
328 "ip address prefix-list",
329 route_match_ip_address_prefix_list
,
330 route_match_ip_address_prefix_list_compile
,
331 route_match_ip_address_prefix_list_free
334 /* `match ip next-hop prefix-list PREFIX_LIST' */
337 route_match_ip_next_hop_prefix_list (void *rule
, struct prefix
*prefix
,
338 route_map_object_t type
, void *object
)
340 struct prefix_list
*plist
;
341 struct bgp_info
*bgp_info
;
342 struct prefix_ipv4 p
;
344 if (type
== RMAP_BGP
)
348 p
.prefix
= bgp_info
->attr
->nexthop
;
349 p
.prefixlen
= IPV4_MAX_BITLEN
;
351 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
355 return (prefix_list_apply (plist
, &p
) == PREFIX_DENY
?
356 RMAP_NOMATCH
: RMAP_MATCH
);
362 route_match_ip_next_hop_prefix_list_compile (char *arg
)
364 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
368 route_match_ip_next_hop_prefix_list_free (void *rule
)
370 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
373 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
=
375 "ip next-hop prefix-list",
376 route_match_ip_next_hop_prefix_list
,
377 route_match_ip_next_hop_prefix_list_compile
,
378 route_match_ip_next_hop_prefix_list_free
381 /* `match metric METRIC' */
383 /* Match function return 1 if match is success else return zero. */
385 route_match_metric (void *rule
, struct prefix
*prefix
,
386 route_map_object_t type
, void *object
)
389 struct bgp_info
*bgp_info
;
391 if (type
== RMAP_BGP
)
396 if (bgp_info
->attr
->med
== *med
)
404 /* Route map `match metric' match statement. `arg' is MED value */
406 route_match_metric_compile (char *arg
)
410 unsigned long tmpval
;
412 tmpval
= strtoul (arg
, &endptr
, 10);
413 if (*endptr
!= '\0' || tmpval
== ULONG_MAX
)
415 med
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
420 /* Free route map's compiled `match metric' value. */
422 route_match_metric_free (void *rule
)
424 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
427 /* Route map commands for metric matching. */
428 struct route_map_rule_cmd route_match_metric_cmd
=
432 route_match_metric_compile
,
433 route_match_metric_free
436 /* `match as-path ASPATH' */
438 /* Match function for as-path match. I assume given object is */
440 route_match_aspath (void *rule
, struct prefix
*prefix
,
441 route_map_object_t type
, void *object
)
444 struct as_list
*as_list
;
445 struct bgp_info
*bgp_info
;
447 if (type
== RMAP_BGP
)
449 as_list
= as_list_lookup ((char *) rule
);
456 return ((as_list_apply (as_list
, bgp_info
->attr
->aspath
) == AS_FILTER_DENY
) ? RMAP_NOMATCH
: RMAP_MATCH
);
461 /* Compile function for as-path match. */
463 route_match_aspath_compile (char *arg
)
465 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
468 /* Compile function for as-path match. */
470 route_match_aspath_free (void *rule
)
472 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
475 /* Route map commands for aspath matching. */
476 struct route_map_rule_cmd route_match_aspath_cmd
=
480 route_match_aspath_compile
,
481 route_match_aspath_free
484 #if ROUTE_MATCH_ASPATH_OLD
485 /* `match as-path ASPATH' */
487 /* Match function for as-path match. I assume given object is */
489 route_match_aspath (void *rule
, struct prefix
*prefix
, void *object
)
492 struct bgp_info
*bgp_info
;
498 return bgp_regexec (regex
, bgp_info
->attr
->aspath
);
501 /* Compile function for as-path match. */
503 route_match_aspath_compile (char *arg
)
507 regex
= bgp_regcomp (arg
);
514 /* Compile function for as-path match. */
516 route_match_aspath_free (void *rule
)
518 regex_t
*regex
= rule
;
520 bgp_regex_free (regex
);
523 /* Route map commands for aspath matching. */
524 struct route_map_rule_cmd route_match_aspath_cmd
=
528 route_match_aspath_compile
,
529 route_match_aspath_free
531 #endif /* ROUTE_MATCH_ASPATH_OLD */
533 /* `match community COMMUNIY' */
534 struct rmap_community
540 /* Match function for community match. */
542 route_match_community (void *rule
, struct prefix
*prefix
,
543 route_map_object_t type
, void *object
)
545 struct community_list
*list
;
546 struct bgp_info
*bgp_info
;
547 struct rmap_community
*rcom
;
549 if (type
== RMAP_BGP
)
554 list
= community_list_lookup (bgp_clist
, rcom
->name
, COMMUNITY_LIST_AUTO
);
560 if (community_list_exact_match (bgp_info
->attr
->community
, list
))
565 if (community_list_match (bgp_info
->attr
->community
, list
))
572 /* Compile function for community match. */
574 route_match_community_compile (char *arg
)
576 struct rmap_community
*rcom
;
580 rcom
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_community
));
582 p
= strchr (arg
, ' ');
586 rcom
->name
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
587 memcpy (rcom
->name
, arg
, len
);
592 rcom
->name
= XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
598 /* Compile function for community match. */
600 route_match_community_free (void *rule
)
602 struct rmap_community
*rcom
= rule
;
604 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
605 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
);
608 /* Route map commands for community matching. */
609 struct route_map_rule_cmd route_match_community_cmd
=
612 route_match_community
,
613 route_match_community_compile
,
614 route_match_community_free
617 /* Match function for extcommunity match. */
619 route_match_ecommunity (void *rule
, struct prefix
*prefix
,
620 route_map_object_t type
, void *object
)
622 struct community_list
*list
;
623 struct bgp_info
*bgp_info
;
625 if (type
== RMAP_BGP
)
629 list
= community_list_lookup (bgp_clist
, (char *) rule
,
630 EXTCOMMUNITY_LIST_AUTO
);
634 if (ecommunity_list_match (bgp_info
->attr
->ecommunity
, list
))
640 /* Compile function for extcommunity match. */
642 route_match_ecommunity_compile (char *arg
)
644 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
647 /* Compile function for extcommunity match. */
649 route_match_ecommunity_free (void *rule
)
651 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
654 /* Route map commands for community matching. */
655 struct route_map_rule_cmd route_match_ecommunity_cmd
=
658 route_match_ecommunity
,
659 route_match_ecommunity_compile
,
660 route_match_ecommunity_free
663 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
664 and `address-family vpnv4'. */
668 route_match_origin (void *rule
, struct prefix
*prefix
,
669 route_map_object_t type
, void *object
)
672 struct bgp_info
*bgp_info
;
674 if (type
== RMAP_BGP
)
679 if (bgp_info
->attr
->origin
== *origin
)
687 route_match_origin_compile (char *arg
)
691 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
693 if (strcmp (arg
, "igp") == 0)
695 else if (strcmp (arg
, "egp") == 0)
703 /* Free route map's compiled `ip address' value. */
705 route_match_origin_free (void *rule
)
707 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
710 /* Route map commands for origin matching. */
711 struct route_map_rule_cmd route_match_origin_cmd
=
715 route_match_origin_compile
,
716 route_match_origin_free
718 /* `set ip next-hop IP_ADDRESS' */
720 /* Set nexthop to object. ojbect must be pointer to struct attr. */
721 struct rmap_ip_nexthop_set
723 struct in_addr
*address
;
728 route_set_ip_nexthop (void *rule
, struct prefix
*prefix
,
729 route_map_object_t type
, void *object
)
731 struct rmap_ip_nexthop_set
*rins
= rule
;
732 struct in_addr peer_address
;
733 struct bgp_info
*bgp_info
;
736 if (type
== RMAP_BGP
)
739 peer
= bgp_info
->peer
;
741 if (rins
->peer_address
)
743 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
744 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
746 && sockunion_family (peer
->su_remote
) == AF_INET
)
748 inet_aton (sockunion_su2str (peer
->su_remote
), &peer_address
);
749 bgp_info
->attr
->nexthop
= peer_address
;
750 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
752 else if (CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)
754 && sockunion_family (peer
->su_local
) == AF_INET
)
756 inet_aton (sockunion_su2str (peer
->su_local
), &peer_address
);
757 bgp_info
->attr
->nexthop
= peer_address
;
758 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
763 /* Set next hop value. */
764 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
765 bgp_info
->attr
->nexthop
= *rins
->address
;
772 /* Route map `ip nexthop' compile function. Given string is converted
773 to struct in_addr structure. */
775 route_set_ip_nexthop_compile (char *arg
)
777 struct rmap_ip_nexthop_set
*rins
;
778 struct in_addr
*address
= NULL
;
779 int peer_address
= 0;
782 if (strcmp (arg
, "peer-address") == 0)
786 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
787 ret
= inet_aton (arg
, address
);
791 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
796 rins
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_ip_nexthop_set
));
797 memset (rins
, 0, sizeof (struct rmap_ip_nexthop_set
));
799 rins
->address
= address
;
800 rins
->peer_address
= peer_address
;
805 /* Free route map's compiled `ip nexthop' value. */
807 route_set_ip_nexthop_free (void *rule
)
809 struct rmap_ip_nexthop_set
*rins
= rule
;
812 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
814 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
);
817 /* Route map commands for ip nexthop set. */
818 struct route_map_rule_cmd route_set_ip_nexthop_cmd
=
821 route_set_ip_nexthop
,
822 route_set_ip_nexthop_compile
,
823 route_set_ip_nexthop_free
826 /* `set local-preference LOCAL_PREF' */
828 /* Set local preference. */
830 route_set_local_pref (void *rule
, struct prefix
*prefix
,
831 route_map_object_t type
, void *object
)
833 u_int32_t
*local_pref
;
834 struct bgp_info
*bgp_info
;
836 if (type
== RMAP_BGP
)
838 /* Fetch routemap's rule information. */
842 /* Set local preference value. */
843 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
);
844 bgp_info
->attr
->local_pref
= *local_pref
;
850 /* set local preference compilation. */
852 route_set_local_pref_compile (char *arg
)
854 u_int32_t
*local_pref
;
857 /* Local preference value shoud be integer. */
858 if (! all_digit (arg
))
861 local_pref
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
862 *local_pref
= strtoul (arg
, &endptr
, 10);
863 if (*endptr
!= '\0' || *local_pref
== ULONG_MAX
)
865 XFREE (MTYPE_ROUTE_MAP_COMPILED
, local_pref
);
871 /* Free route map's local preference value. */
873 route_set_local_pref_free (void *rule
)
875 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
878 /* Set local preference rule structure. */
879 struct route_map_rule_cmd route_set_local_pref_cmd
=
882 route_set_local_pref
,
883 route_set_local_pref_compile
,
884 route_set_local_pref_free
,
887 /* `set weight WEIGHT' */
891 route_set_weight (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
895 struct bgp_info
*bgp_info
;
897 if (type
== RMAP_BGP
)
899 /* Fetch routemap's rule information. */
903 /* Set weight value. */
904 bgp_info
->attr
->weight
= *weight
;
910 /* set local preference compilation. */
912 route_set_weight_compile (char *arg
)
917 /* Local preference value shoud be integer. */
918 if (! all_digit (arg
))
921 weight
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
922 *weight
= strtoul (arg
, &endptr
, 10);
923 if (*endptr
!= '\0' || *weight
== ULONG_MAX
)
925 XFREE (MTYPE_ROUTE_MAP_COMPILED
, weight
);
931 /* Free route map's local preference value. */
933 route_set_weight_free (void *rule
)
935 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
938 /* Set local preference rule structure. */
939 struct route_map_rule_cmd route_set_weight_cmd
=
943 route_set_weight_compile
,
944 route_set_weight_free
,
947 /* `set metric METRIC' */
949 /* Set metric to attribute. */
951 route_set_metric (void *rule
, struct prefix
*prefix
,
952 route_map_object_t type
, void *object
)
955 u_int32_t metric_val
;
956 struct bgp_info
*bgp_info
;
958 if (type
== RMAP_BGP
)
960 /* Fetch routemap's rule information. */
964 if (! (bgp_info
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
)))
965 bgp_info
->attr
->med
= 0;
966 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
);
968 if (all_digit (metric
))
970 metric_val
= strtoul (metric
, (char **)NULL
, 10);
971 bgp_info
->attr
->med
= metric_val
;
975 metric_val
= strtoul (metric
+1, (char **)NULL
, 10);
977 if (strncmp (metric
, "+", 1) == 0)
979 if (bgp_info
->attr
->med
/2 + metric_val
/2 > BGP_MED_MAX
/2)
980 bgp_info
->attr
->med
= BGP_MED_MAX
- 1;
982 bgp_info
->attr
->med
+= metric_val
;
984 else if (strncmp (metric
, "-", 1) == 0)
986 if (bgp_info
->attr
->med
<= metric_val
)
987 bgp_info
->attr
->med
= 0;
989 bgp_info
->attr
->med
-= metric_val
;
996 /* set metric compilation. */
998 route_set_metric_compile (char *arg
)
1001 char *endptr
= NULL
;
1003 if (all_digit (arg
))
1005 /* set metric value check*/
1006 metric
= strtoul (arg
, &endptr
, 10);
1007 if (*endptr
!= '\0' || metric
== ULONG_MAX
)
1012 /* set metric +/-value check */
1013 if ((strncmp (arg
, "+", 1) != 0
1014 && strncmp (arg
, "-", 1) != 0)
1015 || (! all_digit (arg
+1)))
1018 metric
= strtoul (arg
+1, &endptr
, 10);
1019 if (*endptr
!= '\0' || metric
== ULONG_MAX
)
1023 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1026 /* Free route map's compiled `set metric' value. */
1028 route_set_metric_free (void *rule
)
1030 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1033 /* Set metric rule structure. */
1034 struct route_map_rule_cmd route_set_metric_cmd
=
1038 route_set_metric_compile
,
1039 route_set_metric_free
,
1042 /* `set as-path prepend ASPATH' */
1044 /* For AS path prepend mechanism. */
1046 route_set_aspath_prepend (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1048 struct aspath
*aspath
;
1050 struct bgp_info
*binfo
;
1052 if (type
== RMAP_BGP
)
1057 if (binfo
->attr
->aspath
->refcnt
)
1058 new = aspath_dup (binfo
->attr
->aspath
);
1060 new = binfo
->attr
->aspath
;
1062 aspath_prepend (aspath
, new);
1063 binfo
->attr
->aspath
= new;
1069 /* Compile function for as-path prepend. */
1071 route_set_aspath_prepend_compile (char *arg
)
1073 struct aspath
*aspath
;
1075 aspath
= aspath_str2aspath (arg
);
1081 /* Compile function for as-path prepend. */
1083 route_set_aspath_prepend_free (void *rule
)
1085 struct aspath
*aspath
= rule
;
1086 aspath_free (aspath
);
1089 /* Set metric rule structure. */
1090 struct route_map_rule_cmd route_set_aspath_prepend_cmd
=
1093 route_set_aspath_prepend
,
1094 route_set_aspath_prepend_compile
,
1095 route_set_aspath_prepend_free
,
1098 /* `set community COMMUNITY' */
1101 struct community
*com
;
1106 /* For community set mechanism. */
1108 route_set_community (void *rule
, struct prefix
*prefix
,
1109 route_map_object_t type
, void *object
)
1111 struct rmap_com_set
*rcs
;
1112 struct bgp_info
*binfo
;
1114 struct community
*new = NULL
;
1115 struct community
*old
;
1116 struct community
*merge
;
1118 if (type
== RMAP_BGP
)
1123 old
= attr
->community
;
1128 attr
->flag
&= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
));
1129 attr
->community
= NULL
;
1133 /* "additive" case. */
1134 if (rcs
->additive
&& old
)
1136 merge
= community_merge (community_dup (old
), rcs
->com
);
1137 new = community_uniq_sort (merge
);
1138 community_free (merge
);
1141 new = community_dup (rcs
->com
);
1143 attr
->community
= new;
1144 attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1150 /* Compile function for set community. */
1152 route_set_community_compile (char *arg
)
1154 struct rmap_com_set
*rcs
;
1155 struct community
*com
= NULL
;
1160 if (strcmp (arg
, "none") == 0)
1164 sp
= strstr (arg
, "additive");
1168 /* "additive" keyworkd is included. */
1173 com
= community_str2com (arg
);
1182 rcs
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_com_set
));
1183 memset (rcs
, 0, sizeof (struct rmap_com_set
));
1186 rcs
->additive
= additive
;
1192 /* Free function for set community. */
1194 route_set_community_free (void *rule
)
1196 struct rmap_com_set
*rcs
= rule
;
1199 community_free (rcs
->com
);
1200 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1203 /* Set community rule structure. */
1204 struct route_map_rule_cmd route_set_community_cmd
=
1207 route_set_community
,
1208 route_set_community_compile
,
1209 route_set_community_free
,
1212 /* `set comm-list (<1-99>|<100-199>|WORD) delete' */
1214 /* For community set mechanism. */
1216 route_set_community_delete (void *rule
, struct prefix
*prefix
,
1217 route_map_object_t type
, void *object
)
1219 struct community_list
*list
;
1220 struct community
*merge
;
1221 struct community
*new;
1222 struct community
*old
;
1223 struct bgp_info
*binfo
;
1225 if (type
== RMAP_BGP
)
1231 list
= community_list_lookup (bgp_clist
, rule
, COMMUNITY_LIST_AUTO
);
1232 old
= binfo
->attr
->community
;
1236 merge
= community_list_match_delete (community_dup (old
), list
);
1237 new = community_uniq_sort (merge
);
1238 community_free (merge
);
1242 binfo
->attr
->community
= NULL
;
1243 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1244 community_free (new);
1248 binfo
->attr
->community
= new;
1249 binfo
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1257 /* Compile function for set community. */
1259 route_set_community_delete_compile (char *arg
)
1265 p
= strchr (arg
, ' ');
1269 str
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1270 memcpy (str
, arg
, len
);
1278 /* Free function for set community. */
1280 route_set_community_delete_free (void *rule
)
1282 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1285 /* Set community rule structure. */
1286 struct route_map_rule_cmd route_set_community_delete_cmd
=
1289 route_set_community_delete
,
1290 route_set_community_delete_compile
,
1291 route_set_community_delete_free
,
1294 /* `set extcommunity rt COMMUNITY' */
1296 /* For community set mechanism. */
1298 route_set_ecommunity_rt (void *rule
, struct prefix
*prefix
,
1299 route_map_object_t type
, void *object
)
1301 struct ecommunity
*ecom
;
1302 struct ecommunity
*new_ecom
;
1303 struct ecommunity
*old_ecom
;
1304 struct bgp_info
*bgp_info
;
1306 if (type
== RMAP_BGP
)
1314 /* We assume additive for Extended Community. */
1315 old_ecom
= bgp_info
->attr
->ecommunity
;
1318 new_ecom
= ecommunity_merge (ecommunity_dup (old_ecom
), ecom
);
1320 new_ecom
= ecommunity_dup (ecom
);
1322 bgp_info
->attr
->ecommunity
= new_ecom
;
1324 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES
);
1329 /* Compile function for set community. */
1331 route_set_ecommunity_rt_compile (char *arg
)
1333 struct ecommunity
*ecom
;
1335 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
1341 /* Free function for set community. */
1343 route_set_ecommunity_rt_free (void *rule
)
1345 struct ecommunity
*ecom
= rule
;
1346 ecommunity_free (ecom
);
1349 /* Set community rule structure. */
1350 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
=
1353 route_set_ecommunity_rt
,
1354 route_set_ecommunity_rt_compile
,
1355 route_set_ecommunity_rt_free
,
1358 /* `set extcommunity soo COMMUNITY' */
1360 /* For community set mechanism. */
1362 route_set_ecommunity_soo (void *rule
, struct prefix
*prefix
,
1363 route_map_object_t type
, void *object
)
1365 struct ecommunity
*ecom
;
1366 struct bgp_info
*bgp_info
;
1368 if (type
== RMAP_BGP
)
1376 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES
);
1377 bgp_info
->attr
->ecommunity
= ecommunity_dup (ecom
);
1382 /* Compile function for set community. */
1384 route_set_ecommunity_soo_compile (char *arg
)
1386 struct ecommunity
*ecom
;
1388 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
1395 /* Free function for set community. */
1397 route_set_ecommunity_soo_free (void *rule
)
1399 struct ecommunity
*ecom
= rule
;
1400 ecommunity_free (ecom
);
1403 /* Set community rule structure. */
1404 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
=
1407 route_set_ecommunity_soo
,
1408 route_set_ecommunity_soo_compile
,
1409 route_set_ecommunity_soo_free
,
1412 /* `set origin ORIGIN' */
1414 /* For origin set. */
1416 route_set_origin (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1419 struct bgp_info
*bgp_info
;
1421 if (type
== RMAP_BGP
)
1426 bgp_info
->attr
->origin
= *origin
;
1432 /* Compile function for origin set. */
1434 route_set_origin_compile (char *arg
)
1438 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
1440 if (strcmp (arg
, "igp") == 0)
1442 else if (strcmp (arg
, "egp") == 0)
1450 /* Compile function for origin set. */
1452 route_set_origin_free (void *rule
)
1454 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1457 /* Set metric rule structure. */
1458 struct route_map_rule_cmd route_set_origin_cmd
=
1462 route_set_origin_compile
,
1463 route_set_origin_free
,
1466 /* `set atomic-aggregate' */
1468 /* For atomic aggregate set. */
1470 route_set_atomic_aggregate (void *rule
, struct prefix
*prefix
,
1471 route_map_object_t type
, void *object
)
1473 struct bgp_info
*bgp_info
;
1475 if (type
== RMAP_BGP
)
1478 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
);
1484 /* Compile function for atomic aggregate. */
1486 route_set_atomic_aggregate_compile (char *arg
)
1491 /* Compile function for atomic aggregate. */
1493 route_set_atomic_aggregate_free (void *rule
)
1498 /* Set atomic aggregate rule structure. */
1499 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
=
1502 route_set_atomic_aggregate
,
1503 route_set_atomic_aggregate_compile
,
1504 route_set_atomic_aggregate_free
,
1507 /* `set aggregator as AS A.B.C.D' */
1511 struct in_addr address
;
1515 route_set_aggregator_as (void *rule
, struct prefix
*prefix
,
1516 route_map_object_t type
, void *object
)
1518 struct bgp_info
*bgp_info
;
1519 struct aggregator
*aggregator
;
1521 if (type
== RMAP_BGP
)
1526 bgp_info
->attr
->aggregator_as
= aggregator
->as
;
1527 bgp_info
->attr
->aggregator_addr
= aggregator
->address
;
1528 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR
);
1535 route_set_aggregator_as_compile (char *arg
)
1537 struct aggregator
*aggregator
;
1541 aggregator
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct aggregator
));
1542 memset (aggregator
, 0, sizeof (struct aggregator
));
1544 sscanf (arg
, "%s %s", as
, address
);
1546 aggregator
->as
= strtoul (as
, NULL
, 10);
1547 inet_aton (address
, &aggregator
->address
);
1553 route_set_aggregator_as_free (void *rule
)
1555 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1558 struct route_map_rule_cmd route_set_aggregator_as_cmd
=
1561 route_set_aggregator_as
,
1562 route_set_aggregator_as_compile
,
1563 route_set_aggregator_as_free
,
1567 /* `match ipv6 address IP_ACCESS_LIST' */
1570 route_match_ipv6_address (void *rule
, struct prefix
*prefix
,
1571 route_map_object_t type
, void *object
)
1573 struct access_list
*alist
;
1575 if (type
== RMAP_BGP
)
1577 alist
= access_list_lookup (AFI_IP6
, (char *) rule
);
1579 return RMAP_NOMATCH
;
1581 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
1582 RMAP_NOMATCH
: RMAP_MATCH
);
1584 return RMAP_NOMATCH
;
1588 route_match_ipv6_address_compile (char *arg
)
1590 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1594 route_match_ipv6_address_free (void *rule
)
1596 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1599 /* Route map commands for ip address matching. */
1600 struct route_map_rule_cmd route_match_ipv6_address_cmd
=
1603 route_match_ipv6_address
,
1604 route_match_ipv6_address_compile
,
1605 route_match_ipv6_address_free
1608 /* `match ipv6 next-hop IP_ADDRESS' */
1611 route_match_ipv6_next_hop (void *rule
, struct prefix
*prefix
,
1612 route_map_object_t type
, void *object
)
1614 struct in6_addr
*addr
;
1615 struct bgp_info
*bgp_info
;
1617 if (type
== RMAP_BGP
)
1622 if (IPV6_ADDR_SAME (&bgp_info
->attr
->mp_nexthop_global
, rule
))
1625 if (bgp_info
->attr
->mp_nexthop_len
== 32 &&
1626 IPV6_ADDR_SAME (&bgp_info
->attr
->mp_nexthop_local
, rule
))
1629 return RMAP_NOMATCH
;
1632 return RMAP_NOMATCH
;
1636 route_match_ipv6_next_hop_compile (char *arg
)
1638 struct in6_addr
*address
;
1641 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
1643 ret
= inet_pton (AF_INET6
, arg
, address
);
1646 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1654 route_match_ipv6_next_hop_free (void *rule
)
1656 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1659 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
=
1662 route_match_ipv6_next_hop
,
1663 route_match_ipv6_next_hop_compile
,
1664 route_match_ipv6_next_hop_free
1667 /* `match ipv6 address prefix-list PREFIX_LIST' */
1670 route_match_ipv6_address_prefix_list (void *rule
, struct prefix
*prefix
,
1671 route_map_object_t type
, void *object
)
1673 struct prefix_list
*plist
;
1675 if (type
== RMAP_BGP
)
1677 plist
= prefix_list_lookup (AFI_IP6
, (char *) rule
);
1679 return RMAP_NOMATCH
;
1681 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
1682 RMAP_NOMATCH
: RMAP_MATCH
);
1684 return RMAP_NOMATCH
;
1688 route_match_ipv6_address_prefix_list_compile (char *arg
)
1690 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1694 route_match_ipv6_address_prefix_list_free (void *rule
)
1696 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1699 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
=
1701 "ipv6 address prefix-list",
1702 route_match_ipv6_address_prefix_list
,
1703 route_match_ipv6_address_prefix_list_compile
,
1704 route_match_ipv6_address_prefix_list_free
1707 /* `set ipv6 nexthop global IP_ADDRESS' */
1709 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1711 route_set_ipv6_nexthop_global (void *rule
, struct prefix
*prefix
,
1712 route_map_object_t type
, void *object
)
1714 struct in6_addr
*address
;
1715 struct bgp_info
*bgp_info
;
1717 if (type
== RMAP_BGP
)
1719 /* Fetch routemap's rule information. */
1723 /* Set next hop value. */
1724 bgp_info
->attr
->mp_nexthop_global
= *address
;
1726 /* Set nexthop length. */
1727 if (bgp_info
->attr
->mp_nexthop_len
== 0)
1728 bgp_info
->attr
->mp_nexthop_len
= 16;
1734 /* Route map `ip next-hop' compile function. Given string is converted
1735 to struct in_addr structure. */
1737 route_set_ipv6_nexthop_global_compile (char *arg
)
1740 struct in6_addr
*address
;
1742 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
1744 ret
= inet_pton (AF_INET6
, arg
, address
);
1748 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1755 /* Free route map's compiled `ip next-hop' value. */
1757 route_set_ipv6_nexthop_global_free (void *rule
)
1759 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1762 /* Route map commands for ip nexthop set. */
1763 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
=
1765 "ipv6 next-hop global",
1766 route_set_ipv6_nexthop_global
,
1767 route_set_ipv6_nexthop_global_compile
,
1768 route_set_ipv6_nexthop_global_free
1771 /* `set ipv6 nexthop local IP_ADDRESS' */
1773 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1775 route_set_ipv6_nexthop_local (void *rule
, struct prefix
*prefix
,
1776 route_map_object_t type
, void *object
)
1778 struct in6_addr
*address
;
1779 struct bgp_info
*bgp_info
;
1781 if (type
== RMAP_BGP
)
1783 /* Fetch routemap's rule information. */
1787 /* Set next hop value. */
1788 bgp_info
->attr
->mp_nexthop_local
= *address
;
1790 /* Set nexthop length. */
1791 if (bgp_info
->attr
->mp_nexthop_len
!= 32)
1792 bgp_info
->attr
->mp_nexthop_len
= 32;
1798 /* Route map `ip nexthop' compile function. Given string is converted
1799 to struct in_addr structure. */
1801 route_set_ipv6_nexthop_local_compile (char *arg
)
1804 struct in6_addr
*address
;
1806 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
1808 ret
= inet_pton (AF_INET6
, arg
, address
);
1812 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1819 /* Free route map's compiled `ip nexthop' value. */
1821 route_set_ipv6_nexthop_local_free (void *rule
)
1823 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1826 /* Route map commands for ip nexthop set. */
1827 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
=
1829 "ipv6 next-hop local",
1830 route_set_ipv6_nexthop_local
,
1831 route_set_ipv6_nexthop_local_compile
,
1832 route_set_ipv6_nexthop_local_free
1834 #endif /* HAVE_IPV6 */
1836 /* `set vpnv4 nexthop A.B.C.D' */
1839 route_set_vpnv4_nexthop (void *rule
, struct prefix
*prefix
,
1840 route_map_object_t type
, void *object
)
1842 struct in_addr
*address
;
1843 struct bgp_info
*bgp_info
;
1845 if (type
== RMAP_BGP
)
1847 /* Fetch routemap's rule information. */
1851 /* Set next hop value. */
1852 bgp_info
->attr
->mp_nexthop_global_in
= *address
;
1859 route_set_vpnv4_nexthop_compile (char *arg
)
1862 struct in_addr
*address
;
1864 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
1866 ret
= inet_aton (arg
, address
);
1870 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1878 route_set_vpnv4_nexthop_free (void *rule
)
1880 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1883 /* Route map commands for ip nexthop set. */
1884 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
=
1887 route_set_vpnv4_nexthop
,
1888 route_set_vpnv4_nexthop_compile
,
1889 route_set_vpnv4_nexthop_free
1892 /* `set originator-id' */
1894 /* For origin set. */
1896 route_set_originator_id (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1898 struct in_addr
*address
;
1899 struct bgp_info
*bgp_info
;
1901 if (type
== RMAP_BGP
)
1906 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
);
1907 bgp_info
->attr
->originator_id
= *address
;
1913 /* Compile function for originator-id set. */
1915 route_set_originator_id_compile (char *arg
)
1918 struct in_addr
*address
;
1920 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
1922 ret
= inet_aton (arg
, address
);
1926 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1933 /* Compile function for originator_id set. */
1935 route_set_originator_id_free (void *rule
)
1937 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1940 /* Set metric rule structure. */
1941 struct route_map_rule_cmd route_set_originator_id_cmd
=
1944 route_set_originator_id
,
1945 route_set_originator_id_compile
,
1946 route_set_originator_id_free
,
1949 /* Add bgp route map rule. */
1951 bgp_route_match_add (struct vty
*vty
, struct route_map_index
*index
,
1952 char *command
, char *arg
)
1956 ret
= route_map_add_match (index
, command
, arg
);
1961 case RMAP_RULE_MISSING
:
1962 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
1965 case RMAP_COMPILE_ERROR
:
1966 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
1974 /* Delete bgp route map rule. */
1976 bgp_route_match_delete (struct vty
*vty
, struct route_map_index
*index
,
1977 char *command
, char *arg
)
1981 ret
= route_map_delete_match (index
, command
, arg
);
1986 case RMAP_RULE_MISSING
:
1987 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
1990 case RMAP_COMPILE_ERROR
:
1991 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
1999 /* Add bgp route map rule. */
2001 bgp_route_set_add (struct vty
*vty
, struct route_map_index
*index
,
2002 char *command
, char *arg
)
2006 ret
= route_map_add_set (index
, command
, arg
);
2011 case RMAP_RULE_MISSING
:
2012 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
2015 case RMAP_COMPILE_ERROR
:
2016 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
2024 /* Delete bgp route map rule. */
2026 bgp_route_set_delete (struct vty
*vty
, struct route_map_index
*index
,
2027 char *command
, char *arg
)
2031 ret
= route_map_delete_set (index
, command
, arg
);
2036 case RMAP_RULE_MISSING
:
2037 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
2040 case RMAP_COMPILE_ERROR
:
2041 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
2049 /* Hook function for updating route_map assignment. */
2051 bgp_route_map_update (char *unused
)
2057 struct listnode
*nn
, *nm
;
2060 struct peer_group
*group
;
2061 struct bgp_filter
*filter
;
2062 struct bgp_node
*bn
;
2063 struct bgp_static
*bgp_static
;
2065 /* For neighbor route-map updates. */
2066 LIST_LOOP (bm
->bgp
, bgp
, nn
)
2068 LIST_LOOP (bgp
->peer
, peer
, nm
)
2070 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2071 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2073 filter
= &peer
->filter
[afi
][safi
];
2075 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++)
2077 if (filter
->map
[direct
].name
)
2078 filter
->map
[direct
].map
=
2079 route_map_lookup_by_name (filter
->map
[direct
].name
);
2081 filter
->map
[direct
].map
= NULL
;
2084 if (filter
->usmap
.name
)
2085 filter
->usmap
.map
= route_map_lookup_by_name (filter
->usmap
.name
);
2087 filter
->usmap
.map
= NULL
;
2090 LIST_LOOP (bgp
->group
, group
, nm
)
2092 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2093 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2095 filter
= &group
->conf
->filter
[afi
][safi
];
2097 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++)
2099 if (filter
->map
[direct
].name
)
2100 filter
->map
[direct
].map
=
2101 route_map_lookup_by_name (filter
->map
[direct
].name
);
2103 filter
->map
[direct
].map
= NULL
;
2106 if (filter
->usmap
.name
)
2107 filter
->usmap
.map
= route_map_lookup_by_name (filter
->usmap
.name
);
2109 filter
->usmap
.map
= NULL
;
2114 /* For default-originate route-map updates. */
2115 LIST_LOOP (bm
->bgp
, bgp
, nn
)
2117 LIST_LOOP (bgp
->peer
, peer
, nm
)
2119 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2120 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2122 if (peer
->default_rmap
[afi
][safi
].name
)
2123 peer
->default_rmap
[afi
][safi
].map
=
2124 route_map_lookup_by_name (peer
->default_rmap
[afi
][safi
].name
);
2126 peer
->default_rmap
[afi
][safi
].map
= NULL
;
2131 /* For network route-map updates. */
2132 LIST_LOOP (bm
->bgp
, bgp
, nn
)
2134 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2135 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2136 for (bn
= bgp_table_top (bgp
->route
[afi
][safi
]); bn
;
2137 bn
= bgp_route_next (bn
))
2138 if ((bgp_static
= bn
->info
) != NULL
)
2140 if (bgp_static
->rmap
.name
)
2141 bgp_static
->rmap
.map
=
2142 route_map_lookup_by_name (bgp_static
->rmap
.name
);
2144 bgp_static
->rmap
.map
= NULL
;
2148 /* For redistribute route-map updates. */
2149 LIST_LOOP (bm
->bgp
, bgp
, nn
)
2151 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2153 if (bgp
->rmap
[ZEBRA_FAMILY_IPV4
][i
].name
)
2154 bgp
->rmap
[ZEBRA_FAMILY_IPV4
][i
].map
=
2155 route_map_lookup_by_name (bgp
->rmap
[ZEBRA_FAMILY_IPV4
][i
].name
);
2157 if (bgp
->rmap
[ZEBRA_FAMILY_IPV6
][i
].name
)
2158 bgp
->rmap
[ZEBRA_FAMILY_IPV6
][i
].map
=
2159 route_map_lookup_by_name (bgp
->rmap
[ZEBRA_FAMILY_IPV6
][i
].name
);
2160 #endif /* HAVE_IPV6 */
2167 "match peer (A.B.C.D|X:X::X:X)",
2169 "Match peer address\n"
2170 "IPv6 address of peer\n"
2171 "IP address of peer\n")
2173 return bgp_route_match_add (vty
, vty
->index
, "peer", argv
[0]);
2176 DEFUN (match_peer_local
,
2177 match_peer_local_cmd
,
2180 "Match peer address\n"
2181 "Static or Redistributed routes\n")
2183 return bgp_route_match_add (vty
, vty
->index
, "peer", NULL
);
2186 DEFUN (no_match_peer
,
2191 "Match peer address\n")
2194 return bgp_route_match_delete (vty
, vty
->index
, "peer", NULL
);
2196 return bgp_route_match_delete (vty
, vty
->index
, "peer", argv
[0]);
2199 ALIAS (no_match_peer
,
2200 no_match_peer_val_cmd
,
2201 "no match peer (A.B.C.D|X:X::X:X)",
2204 "Match peer address\n"
2205 "IPv6 address of peer\n"
2206 "IP address of peer\n")
2208 ALIAS (no_match_peer
,
2209 no_match_peer_local_cmd
,
2210 "no match peer local",
2213 "Match peer address\n"
2214 "Static or Redistributed routes\n")
2216 DEFUN (match_ip_address
,
2217 match_ip_address_cmd
,
2218 "match ip address (<1-199>|<1300-2699>|WORD)",
2221 "Match address of route\n"
2222 "IP access-list number\n"
2223 "IP access-list number (expanded range)\n"
2224 "IP Access-list name\n")
2226 return bgp_route_match_add (vty
, vty
->index
, "ip address", argv
[0]);
2229 DEFUN (no_match_ip_address
,
2230 no_match_ip_address_cmd
,
2231 "no match ip address",
2235 "Match address of route\n")
2238 return bgp_route_match_delete (vty
, vty
->index
, "ip address", NULL
);
2240 return bgp_route_match_delete (vty
, vty
->index
, "ip address", argv
[0]);
2243 ALIAS (no_match_ip_address
,
2244 no_match_ip_address_val_cmd
,
2245 "no match ip address (<1-199>|<1300-2699>|WORD)",
2249 "Match address of route\n"
2250 "IP access-list number\n"
2251 "IP access-list number (expanded range)\n"
2252 "IP Access-list name\n")
2254 DEFUN (match_ip_next_hop
,
2255 match_ip_next_hop_cmd
,
2256 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
2259 "Match next-hop address of route\n"
2260 "IP access-list number\n"
2261 "IP access-list number (expanded range)\n"
2262 "IP Access-list name\n")
2264 return bgp_route_match_add (vty
, vty
->index
, "ip next-hop", argv
[0]);
2267 DEFUN (no_match_ip_next_hop
,
2268 no_match_ip_next_hop_cmd
,
2269 "no match ip next-hop",
2273 "Match next-hop address of route\n")
2276 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop", NULL
);
2278 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop", argv
[0]);
2281 ALIAS (no_match_ip_next_hop
,
2282 no_match_ip_next_hop_val_cmd
,
2283 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2287 "Match next-hop address of route\n"
2288 "IP access-list number\n"
2289 "IP access-list number (expanded range)\n"
2290 "IP Access-list name\n")
2292 DEFUN (match_ip_address_prefix_list
,
2293 match_ip_address_prefix_list_cmd
,
2294 "match ip address prefix-list WORD",
2297 "Match address of route\n"
2298 "Match entries of prefix-lists\n"
2299 "IP prefix-list name\n")
2301 return bgp_route_match_add (vty
, vty
->index
, "ip address prefix-list", argv
[0]);
2304 DEFUN (no_match_ip_address_prefix_list
,
2305 no_match_ip_address_prefix_list_cmd
,
2306 "no match ip address prefix-list",
2310 "Match address of route\n"
2311 "Match entries of prefix-lists\n")
2314 return bgp_route_match_delete (vty
, vty
->index
, "ip address prefix-list", NULL
);
2316 return bgp_route_match_delete (vty
, vty
->index
, "ip address prefix-list", argv
[0]);
2319 ALIAS (no_match_ip_address_prefix_list
,
2320 no_match_ip_address_prefix_list_val_cmd
,
2321 "no match ip address prefix-list WORD",
2325 "Match address of route\n"
2326 "Match entries of prefix-lists\n"
2327 "IP prefix-list name\n")
2329 DEFUN (match_ip_next_hop_prefix_list
,
2330 match_ip_next_hop_prefix_list_cmd
,
2331 "match ip next-hop prefix-list WORD",
2334 "Match next-hop address of route\n"
2335 "Match entries of prefix-lists\n"
2336 "IP prefix-list name\n")
2338 return bgp_route_match_add (vty
, vty
->index
, "ip next-hop prefix-list", argv
[0]);
2341 DEFUN (no_match_ip_next_hop_prefix_list
,
2342 no_match_ip_next_hop_prefix_list_cmd
,
2343 "no match ip next-hop prefix-list",
2347 "Match next-hop address of route\n"
2348 "Match entries of prefix-lists\n")
2351 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop prefix-list", NULL
);
2353 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop prefix-list", argv
[0]);
2356 ALIAS (no_match_ip_next_hop_prefix_list
,
2357 no_match_ip_next_hop_prefix_list_val_cmd
,
2358 "no match ip next-hop prefix-list WORD",
2362 "Match next-hop address of route\n"
2363 "Match entries of prefix-lists\n"
2364 "IP prefix-list name\n")
2366 DEFUN (match_metric
,
2368 "match metric <0-4294967295>",
2370 "Match metric of route\n"
2373 return bgp_route_match_add (vty
, vty
->index
, "metric", argv
[0]);
2376 DEFUN (no_match_metric
,
2377 no_match_metric_cmd
,
2381 "Match metric of route\n")
2384 return bgp_route_match_delete (vty
, vty
->index
, "metric", NULL
);
2386 return bgp_route_match_delete (vty
, vty
->index
, "metric", argv
[0]);
2389 ALIAS (no_match_metric
,
2390 no_match_metric_val_cmd
,
2391 "no match metric <0-4294967295>",
2394 "Match metric of route\n"
2397 DEFUN (match_community
,
2398 match_community_cmd
,
2399 "match community (<1-99>|<100-199>|WORD)",
2401 "Match BGP community list\n"
2402 "Community-list number (standard)\n"
2403 "Community-list number (expanded)\n"
2404 "Community-list name\n")
2406 return bgp_route_match_add (vty
, vty
->index
, "community", argv
[0]);
2409 DEFUN (match_community_exact
,
2410 match_community_exact_cmd
,
2411 "match community (<1-99>|<100-199>|WORD) exact-match",
2413 "Match BGP community list\n"
2414 "Community-list number (standard)\n"
2415 "Community-list number (expanded)\n"
2416 "Community-list name\n"
2417 "Do exact matching of communities\n")
2422 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
2423 strlen (argv
[0]) + strlen ("exact-match") + 2);
2425 sprintf (argstr
, "%s exact-match", argv
[0]);
2427 ret
= bgp_route_match_add (vty
, vty
->index
, "community", argstr
);
2429 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
2434 DEFUN (no_match_community
,
2435 no_match_community_cmd
,
2436 "no match community",
2439 "Match BGP community list\n")
2441 return bgp_route_match_delete (vty
, vty
->index
, "community", NULL
);
2444 ALIAS (no_match_community
,
2445 no_match_community_val_cmd
,
2446 "no match community (<1-99>|<100-199>|WORD)",
2449 "Match BGP community list\n"
2450 "Community-list number (standard)\n"
2451 "Community-list number (expanded)\n"
2452 "Community-list name\n")
2454 ALIAS (no_match_community
,
2455 no_match_community_exact_cmd
,
2456 "no match community (<1-99>|<100-199>|WORD) exact-match",
2459 "Match BGP community list\n"
2460 "Community-list number (standard)\n"
2461 "Community-list number (expanded)\n"
2462 "Community-list name\n"
2463 "Do exact matching of communities\n")
2465 DEFUN (match_ecommunity
,
2466 match_ecommunity_cmd
,
2467 "match extcommunity (<1-99>|<100-199>|WORD)",
2469 "Match BGP/VPN extended community list\n"
2470 "Extended community-list number (standard)\n"
2471 "Extended community-list number (expanded)\n"
2472 "Extended community-list name\n")
2474 return bgp_route_match_add (vty
, vty
->index
, "extcommunity", argv
[0]);
2477 DEFUN (no_match_ecommunity
,
2478 no_match_ecommunity_cmd
,
2479 "no match extcommunity",
2482 "Match BGP/VPN extended community list\n")
2484 return bgp_route_match_delete (vty
, vty
->index
, "extcommunity", NULL
);
2487 ALIAS (no_match_ecommunity
,
2488 no_match_ecommunity_val_cmd
,
2489 "no match extcommunity (<1-99>|<100-199>|WORD)",
2492 "Match BGP/VPN extended community list\n"
2493 "Extended community-list number (standard)\n"
2494 "Extended community-list number (expanded)\n"
2495 "Extended community-list name\n")
2497 DEFUN (match_aspath
,
2499 "match as-path WORD",
2501 "Match BGP AS path list\n"
2502 "AS path access-list name\n")
2504 return bgp_route_match_add (vty
, vty
->index
, "as-path", argv
[0]);
2507 DEFUN (no_match_aspath
,
2508 no_match_aspath_cmd
,
2512 "Match BGP AS path list\n")
2514 return bgp_route_match_delete (vty
, vty
->index
, "as-path", NULL
);
2517 ALIAS (no_match_aspath
,
2518 no_match_aspath_val_cmd
,
2519 "no match as-path WORD",
2522 "Match BGP AS path list\n"
2523 "AS path access-list name\n")
2525 DEFUN (match_origin
,
2527 "match origin (egp|igp|incomplete)",
2532 "unknown heritage\n")
2534 if (strncmp (argv
[0], "igp", 2) == 0)
2535 return bgp_route_match_add (vty
, vty
->index
, "origin", "igp");
2536 if (strncmp (argv
[0], "egp", 1) == 0)
2537 return bgp_route_match_add (vty
, vty
->index
, "origin", "egp");
2538 if (strncmp (argv
[0], "incomplete", 2) == 0)
2539 return bgp_route_match_add (vty
, vty
->index
, "origin", "incomplete");
2544 DEFUN (no_match_origin
,
2545 no_match_origin_cmd
,
2549 "BGP origin code\n")
2551 return bgp_route_match_delete (vty
, vty
->index
, "origin", NULL
);
2554 ALIAS (no_match_origin
,
2555 no_match_origin_val_cmd
,
2556 "no match origin (egp|igp|incomplete)",
2562 "unknown heritage\n")
2564 DEFUN (set_ip_nexthop
,
2566 "set ip next-hop A.B.C.D",
2569 "Next hop address\n"
2570 "IP address of next hop\n")
2575 ret
= str2sockunion (argv
[0], &su
);
2578 vty_out (vty
, "%% Malformed Next-hop address%s", VTY_NEWLINE
);
2582 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", argv
[0]);
2585 DEFUN (set_ip_nexthop_peer
,
2586 set_ip_nexthop_peer_cmd
,
2587 "set ip next-hop peer-address",
2590 "Next hop address\n"
2591 "Use peer address (for BGP only)\n")
2593 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", "peer-address");
2596 DEFUN (no_set_ip_nexthop_peer
,
2597 no_set_ip_nexthop_peer_cmd
,
2598 "no set ip next-hop peer-address",
2602 "Next hop address\n"
2603 "Use peer address (for BGP only)\n")
2605 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", NULL
);
2609 DEFUN (no_set_ip_nexthop
,
2610 no_set_ip_nexthop_cmd
,
2611 "no set ip next-hop",
2614 "Next hop address\n")
2617 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", NULL
);
2619 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", argv
[0]);
2622 ALIAS (no_set_ip_nexthop
,
2623 no_set_ip_nexthop_val_cmd
,
2624 "no set ip next-hop A.B.C.D",
2628 "Next hop address\n"
2629 "IP address of next hop\n")
2633 "set metric <0-4294967295>",
2635 "Metric value for destination routing protocol\n"
2638 return bgp_route_set_add (vty
, vty
->index
, "metric", argv
[0]);
2642 set_metric_addsub_cmd
,
2643 "set metric <+/-metric>",
2645 "Metric value for destination routing protocol\n"
2646 "Add or subtract BGP metric\n")
2648 DEFUN (no_set_metric
,
2653 "Metric value for destination routing protocol\n")
2656 return bgp_route_set_delete (vty
, vty
->index
, "metric", NULL
);
2658 return bgp_route_set_delete (vty
, vty
->index
, "metric", argv
[0]);
2661 ALIAS (no_set_metric
,
2662 no_set_metric_val_cmd
,
2663 "no set metric <0-4294967295>",
2666 "Metric value for destination routing protocol\n"
2669 DEFUN (set_local_pref
,
2671 "set local-preference <0-4294967295>",
2673 "BGP local preference path attribute\n"
2674 "Preference value\n")
2676 return bgp_route_set_add (vty
, vty
->index
, "local-preference", argv
[0]);
2679 DEFUN (no_set_local_pref
,
2680 no_set_local_pref_cmd
,
2681 "no set local-preference",
2684 "BGP local preference path attribute\n")
2687 return bgp_route_set_delete (vty
, vty
->index
, "local-preference", NULL
);
2689 return bgp_route_set_delete (vty
, vty
->index
, "local-preference", argv
[0]);
2692 ALIAS (no_set_local_pref
,
2693 no_set_local_pref_val_cmd
,
2694 "no set local-preference <0-4294967295>",
2697 "BGP local preference path attribute\n"
2698 "Preference value\n")
2702 "set weight <0-4294967295>",
2704 "BGP weight for routing table\n"
2707 return bgp_route_set_add (vty
, vty
->index
, "weight", argv
[0]);
2710 DEFUN (no_set_weight
,
2715 "BGP weight for routing table\n")
2718 return bgp_route_set_delete (vty
, vty
->index
, "weight", NULL
);
2720 return bgp_route_set_delete (vty
, vty
->index
, "weight", argv
[0]);
2723 ALIAS (no_set_weight
,
2724 no_set_weight_val_cmd
,
2725 "no set weight <0-4294967295>",
2728 "BGP weight for routing table\n"
2731 DEFUN (set_aspath_prepend
,
2732 set_aspath_prepend_cmd
,
2733 "set as-path prepend .<1-65535>",
2735 "Prepend string for a BGP AS-path attribute\n"
2736 "Prepend to the as-path\n"
2742 str
= argv_concat (argv
, argc
, 0);
2743 ret
= bgp_route_set_add (vty
, vty
->index
, "as-path prepend", str
);
2744 XFREE (MTYPE_TMP
, str
);
2749 DEFUN (no_set_aspath_prepend
,
2750 no_set_aspath_prepend_cmd
,
2751 "no set as-path prepend",
2754 "Prepend string for a BGP AS-path attribute\n"
2755 "Prepend to the as-path\n")
2757 return bgp_route_set_delete (vty
, vty
->index
, "as-path prepend", NULL
);
2760 ALIAS (no_set_aspath_prepend
,
2761 no_set_aspath_prepend_val_cmd
,
2762 "no set as-path prepend .<1-65535>",
2765 "Prepend string for a BGP AS-path attribute\n"
2766 "Prepend to the as-path\n"
2769 DEFUN (set_community
,
2771 "set community .AA:NN",
2773 "BGP community attribute\n"
2774 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
2780 struct community
*com
= NULL
;
2785 b
= buffer_new (1024);
2787 for (i
= 0; i
< argc
; i
++)
2789 if (strncmp (argv
[i
], "additive", strlen (argv
[i
])) == 0)
2796 buffer_putc (b
, ' ');
2800 if (strncmp (argv
[i
], "internet", strlen (argv
[i
])) == 0)
2802 buffer_putstr (b
, "internet");
2805 if (strncmp (argv
[i
], "local-AS", strlen (argv
[i
])) == 0)
2807 buffer_putstr (b
, "local-AS");
2810 if (strncmp (argv
[i
], "no-a", strlen ("no-a")) == 0
2811 && strncmp (argv
[i
], "no-advertise", strlen (argv
[i
])) == 0)
2813 buffer_putstr (b
, "no-advertise");
2816 if (strncmp (argv
[i
], "no-e", strlen ("no-e"))== 0
2817 && strncmp (argv
[i
], "no-export", strlen (argv
[i
])) == 0)
2819 buffer_putstr (b
, "no-export");
2822 buffer_putstr (b
, argv
[i
]);
2824 buffer_putc (b
, '\0');
2826 /* Fetch result string then compile it to communities attribute. */
2827 str
= buffer_getstr (b
);
2832 com
= community_str2com (str
);
2836 /* Can't compile user input into communities attribute. */
2839 vty_out (vty
, "%% Malformed communities attribute%s", VTY_NEWLINE
);
2843 /* Set communites attribute string. */
2844 str
= community_str (com
);
2848 argstr
= XCALLOC (MTYPE_TMP
, strlen (str
) + strlen (" additive") + 1);
2849 strcpy (argstr
, str
);
2850 strcpy (argstr
+ strlen (str
), " additive");
2851 ret
= bgp_route_set_add (vty
, vty
->index
, "community", argstr
);
2852 XFREE (MTYPE_TMP
, argstr
);
2855 ret
= bgp_route_set_add (vty
, vty
->index
, "community", str
);
2857 community_free (com
);
2862 DEFUN (set_community_none
,
2863 set_community_none_cmd
,
2864 "set community none",
2866 "BGP community attribute\n"
2867 "No community attribute\n")
2869 return bgp_route_set_add (vty
, vty
->index
, "community", "none");
2872 DEFUN (no_set_community
,
2873 no_set_community_cmd
,
2877 "BGP community attribute\n")
2879 return bgp_route_set_delete (vty
, vty
->index
, "community", NULL
);
2882 ALIAS (no_set_community
,
2883 no_set_community_val_cmd
,
2884 "no set community .AA:NN",
2887 "BGP community attribute\n"
2888 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
2890 ALIAS (no_set_community
,
2891 no_set_community_none_cmd
,
2892 "no set community none",
2895 "BGP community attribute\n"
2896 "No community attribute\n")
2898 DEFUN (set_community_delete
,
2899 set_community_delete_cmd
,
2900 "set comm-list (<1-99>|<100-199>|WORD) delete",
2902 "set BGP community list (for deletion)\n"
2903 "Community-list number (standard)\n"
2904 "Communitly-list number (expanded)\n"
2905 "Community-list name\n"
2906 "Delete matching communities\n")
2910 str
= XCALLOC (MTYPE_TMP
, strlen (argv
[0]) + strlen (" delete") + 1);
2911 strcpy (str
, argv
[0]);
2912 strcpy (str
+ strlen (argv
[0]), " delete");
2914 bgp_route_set_add (vty
, vty
->index
, "comm-list", str
);
2916 XFREE (MTYPE_TMP
, str
);
2920 DEFUN (no_set_community_delete
,
2921 no_set_community_delete_cmd
,
2925 "set BGP community list (for deletion)\n")
2927 return bgp_route_set_delete (vty
, vty
->index
, "comm-list", NULL
);
2930 ALIAS (no_set_community_delete
,
2931 no_set_community_delete_val_cmd
,
2932 "no set comm-list (<1-99>|<100-199>|WORD) delete",
2935 "set BGP community list (for deletion)\n"
2936 "Community-list number (standard)\n"
2937 "Communitly-list number (expanded)\n"
2938 "Community-list name\n"
2939 "Delete matching communities\n")
2941 DEFUN (set_ecommunity_rt
,
2942 set_ecommunity_rt_cmd
,
2943 "set extcommunity rt .ASN:nn_or_IP-address:nn",
2945 "BGP extended community attribute\n"
2946 "Route Target extened communityt\n"
2947 "VPN extended community\n")
2952 str
= argv_concat (argv
, argc
, 0);
2953 ret
= bgp_route_set_add (vty
, vty
->index
, "extcommunity rt", str
);
2954 XFREE (MTYPE_TMP
, str
);
2959 DEFUN (no_set_ecommunity_rt
,
2960 no_set_ecommunity_rt_cmd
,
2961 "no set extcommunity rt",
2964 "BGP extended community attribute\n"
2965 "Route Target extened communityt\n")
2967 return bgp_route_set_delete (vty
, vty
->index
, "extcommunity rt", NULL
);
2970 ALIAS (no_set_ecommunity_rt
,
2971 no_set_ecommunity_rt_val_cmd
,
2972 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
2975 "BGP extended community attribute\n"
2976 "Route Target extened communityt\n"
2977 "VPN extended community\n")
2979 DEFUN (set_ecommunity_soo
,
2980 set_ecommunity_soo_cmd
,
2981 "set extcommunity soo .ASN:nn_or_IP-address:nn",
2983 "BGP extended community attribute\n"
2984 "Site-of-Origin extended community\n"
2985 "VPN extended community\n")
2990 str
= argv_concat (argv
, argc
, 0);
2991 ret
= bgp_route_set_add (vty
, vty
->index
, "extcommunity soo", str
);
2992 XFREE (MTYPE_TMP
, str
);
2996 DEFUN (no_set_ecommunity_soo
,
2997 no_set_ecommunity_soo_cmd
,
2998 "no set extcommunity soo",
3001 "BGP extended community attribute\n"
3002 "Site-of-Origin extended community\n")
3004 return bgp_route_set_delete (vty
, vty
->index
, "extcommunity soo", NULL
);
3007 ALIAS (no_set_ecommunity_soo
,
3008 no_set_ecommunity_soo_val_cmd
,
3009 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
3012 "BGP extended community attribute\n"
3013 "Site-of-Origin extended community\n"
3014 "VPN extended community\n")
3018 "set origin (egp|igp|incomplete)",
3023 "unknown heritage\n")
3025 if (strncmp (argv
[0], "igp", 2) == 0)
3026 return bgp_route_set_add (vty
, vty
->index
, "origin", "igp");
3027 if (strncmp (argv
[0], "egp", 1) == 0)
3028 return bgp_route_set_add (vty
, vty
->index
, "origin", "egp");
3029 if (strncmp (argv
[0], "incomplete", 2) == 0)
3030 return bgp_route_set_add (vty
, vty
->index
, "origin", "incomplete");
3035 DEFUN (no_set_origin
,
3040 "BGP origin code\n")
3042 return bgp_route_set_delete (vty
, vty
->index
, "origin", NULL
);
3045 ALIAS (no_set_origin
,
3046 no_set_origin_val_cmd
,
3047 "no set origin (egp|igp|incomplete)",
3053 "unknown heritage\n")
3055 DEFUN (set_atomic_aggregate
,
3056 set_atomic_aggregate_cmd
,
3057 "set atomic-aggregate",
3059 "BGP atomic aggregate attribute\n" )
3061 return bgp_route_set_add (vty
, vty
->index
, "atomic-aggregate", NULL
);
3064 DEFUN (no_set_atomic_aggregate
,
3065 no_set_atomic_aggregate_cmd
,
3066 "no set atomic-aggregate",
3069 "BGP atomic aggregate attribute\n" )
3071 return bgp_route_set_delete (vty
, vty
->index
, "atomic-aggregate", NULL
);
3074 DEFUN (set_aggregator_as
,
3075 set_aggregator_as_cmd
,
3076 "set aggregator as <1-65535> A.B.C.D",
3078 "BGP aggregator attribute\n"
3079 "AS number of aggregator\n"
3081 "IP address of aggregator\n")
3085 struct in_addr address
;
3086 char *endptr
= NULL
;
3089 as
= strtoul (argv
[0], &endptr
, 10);
3090 if (as
== 0 || as
== ULONG_MAX
|| *endptr
!= '\0')
3092 vty_out (vty
, "AS path value malformed%s", VTY_NEWLINE
);
3096 ret
= inet_aton (argv
[1], &address
);
3099 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
3103 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3104 strlen (argv
[0]) + strlen (argv
[1]) + 2);
3106 sprintf (argstr
, "%s %s", argv
[0], argv
[1]);
3108 ret
= bgp_route_set_add (vty
, vty
->index
, "aggregator as", argstr
);
3110 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3115 DEFUN (no_set_aggregator_as
,
3116 no_set_aggregator_as_cmd
,
3117 "no set aggregator as",
3120 "BGP aggregator attribute\n"
3121 "AS number of aggregator\n")
3125 struct in_addr address
;
3126 char *endptr
= NULL
;
3130 return bgp_route_set_delete (vty
, vty
->index
, "aggregator as", NULL
);
3132 as
= strtoul (argv
[0], &endptr
, 10);
3133 if (as
== 0 || as
== ULONG_MAX
|| *endptr
!= '\0')
3135 vty_out (vty
, "AS path value malformed%s", VTY_NEWLINE
);
3139 ret
= inet_aton (argv
[1], &address
);
3142 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
3146 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3147 strlen (argv
[0]) + strlen (argv
[1]) + 2);
3149 sprintf (argstr
, "%s %s", argv
[0], argv
[1]);
3151 ret
= bgp_route_set_delete (vty
, vty
->index
, "aggregator as", argstr
);
3153 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3158 ALIAS (no_set_aggregator_as
,
3159 no_set_aggregator_as_val_cmd
,
3160 "no set aggregator as <1-65535> A.B.C.D",
3163 "BGP aggregator attribute\n"
3164 "AS number of aggregator\n"
3166 "IP address of aggregator\n")
3170 DEFUN (match_ipv6_address
,
3171 match_ipv6_address_cmd
,
3172 "match ipv6 address WORD",
3175 "Match IPv6 address of route\n"
3176 "IPv6 access-list name\n")
3178 return bgp_route_match_add (vty
, vty
->index
, "ipv6 address", argv
[0]);
3181 DEFUN (no_match_ipv6_address
,
3182 no_match_ipv6_address_cmd
,
3183 "no match ipv6 address WORD",
3187 "Match IPv6 address of route\n"
3188 "IPv6 access-list name\n")
3190 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 address", argv
[0]);
3193 DEFUN (match_ipv6_next_hop
,
3194 match_ipv6_next_hop_cmd
,
3195 "match ipv6 next-hop X:X::X:X",
3198 "Match IPv6 next-hop address of route\n"
3199 "IPv6 address of next hop\n")
3201 return bgp_route_match_add (vty
, vty
->index
, "ipv6 next-hop", argv
[0]);
3204 DEFUN (no_match_ipv6_next_hop
,
3205 no_match_ipv6_next_hop_cmd
,
3206 "no match ipv6 next-hop X:X::X:X",
3210 "Match IPv6 next-hop address of route\n"
3211 "IPv6 address of next hop\n")
3213 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 next-hop", argv
[0]);
3216 DEFUN (match_ipv6_address_prefix_list
,
3217 match_ipv6_address_prefix_list_cmd
,
3218 "match ipv6 address prefix-list WORD",
3221 "Match address of route\n"
3222 "Match entries of prefix-lists\n"
3223 "IP prefix-list name\n")
3225 return bgp_route_match_add (vty
, vty
->index
, "ipv6 address prefix-list", argv
[0]);
3228 DEFUN (no_match_ipv6_address_prefix_list
,
3229 no_match_ipv6_address_prefix_list_cmd
,
3230 "no match ipv6 address prefix-list WORD",
3234 "Match address of route\n"
3235 "Match entries of prefix-lists\n"
3236 "IP prefix-list name\n")
3238 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 address prefix-list", argv
[0]);
3241 DEFUN (set_ipv6_nexthop_global
,
3242 set_ipv6_nexthop_global_cmd
,
3243 "set ipv6 next-hop global X:X::X:X",
3246 "IPv6 next-hop address\n"
3247 "IPv6 global address\n"
3248 "IPv6 address of next hop\n")
3250 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop global", argv
[0]);
3253 DEFUN (no_set_ipv6_nexthop_global
,
3254 no_set_ipv6_nexthop_global_cmd
,
3255 "no set ipv6 next-hop global",
3259 "IPv6 next-hop address\n"
3260 "IPv6 global address\n")
3263 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop global", NULL
);
3265 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop global", argv
[0]);
3268 ALIAS (no_set_ipv6_nexthop_global
,
3269 no_set_ipv6_nexthop_global_val_cmd
,
3270 "no set ipv6 next-hop global X:X::X:X",
3274 "IPv6 next-hop address\n"
3275 "IPv6 global address\n"
3276 "IPv6 address of next hop\n")
3278 DEFUN (set_ipv6_nexthop_local
,
3279 set_ipv6_nexthop_local_cmd
,
3280 "set ipv6 next-hop local X:X::X:X",
3283 "IPv6 next-hop address\n"
3284 "IPv6 local address\n"
3285 "IPv6 address of next hop\n")
3287 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop local", argv
[0]);
3290 DEFUN (no_set_ipv6_nexthop_local
,
3291 no_set_ipv6_nexthop_local_cmd
,
3292 "no set ipv6 next-hop local",
3296 "IPv6 next-hop address\n"
3297 "IPv6 local address\n")
3300 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop local", NULL
);
3302 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop local", argv
[0]);
3305 ALIAS (no_set_ipv6_nexthop_local
,
3306 no_set_ipv6_nexthop_local_val_cmd
,
3307 "no set ipv6 next-hop local X:X::X:X",
3311 "IPv6 next-hop address\n"
3312 "IPv6 local address\n"
3313 "IPv6 address of next hop\n")
3314 #endif /* HAVE_IPV6 */
3316 DEFUN (set_vpnv4_nexthop
,
3317 set_vpnv4_nexthop_cmd
,
3318 "set vpnv4 next-hop A.B.C.D",
3320 "VPNv4 information\n"
3321 "VPNv4 next-hop address\n"
3322 "IP address of next hop\n")
3324 return bgp_route_set_add (vty
, vty
->index
, "vpnv4 next-hop", argv
[0]);
3327 DEFUN (no_set_vpnv4_nexthop
,
3328 no_set_vpnv4_nexthop_cmd
,
3329 "no set vpnv4 next-hop",
3332 "VPNv4 information\n"
3333 "VPNv4 next-hop address\n")
3336 return bgp_route_set_delete (vty
, vty
->index
, "vpnv4 next-hop", NULL
);
3338 return bgp_route_set_delete (vty
, vty
->index
, "vpnv4 next-hop", argv
[0]);
3341 ALIAS (no_set_vpnv4_nexthop
,
3342 no_set_vpnv4_nexthop_val_cmd
,
3343 "no set vpnv4 next-hop A.B.C.D",
3346 "VPNv4 information\n"
3347 "VPNv4 next-hop address\n"
3348 "IP address of next hop\n")
3350 DEFUN (set_originator_id
,
3351 set_originator_id_cmd
,
3352 "set originator-id A.B.C.D",
3354 "BGP originator ID attribute\n"
3355 "IP address of originator\n")
3357 return bgp_route_set_add (vty
, vty
->index
, "originator-id", argv
[0]);
3360 DEFUN (no_set_originator_id
,
3361 no_set_originator_id_cmd
,
3362 "no set originator-id",
3365 "BGP originator ID attribute\n")
3368 return bgp_route_set_delete (vty
, vty
->index
, "originator-id", NULL
);
3370 return bgp_route_set_delete (vty
, vty
->index
, "originator-id", argv
[0]);
3373 ALIAS (no_set_originator_id
,
3374 no_set_originator_id_val_cmd
,
3375 "no set originator-id A.B.C.D",
3378 "BGP originator ID attribute\n"
3379 "IP address of originator\n")
3382 /* Initialization of route map. */
3384 bgp_route_map_init ()
3387 route_map_init_vty ();
3388 route_map_add_hook (bgp_route_map_update
);
3389 route_map_delete_hook (bgp_route_map_update
);
3391 route_map_install_match (&route_match_peer_cmd
);
3392 route_map_install_match (&route_match_ip_address_cmd
);
3393 route_map_install_match (&route_match_ip_next_hop_cmd
);
3394 route_map_install_match (&route_match_ip_address_prefix_list_cmd
);
3395 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd
);
3396 route_map_install_match (&route_match_aspath_cmd
);
3397 route_map_install_match (&route_match_community_cmd
);
3398 route_map_install_match (&route_match_ecommunity_cmd
);
3399 route_map_install_match (&route_match_metric_cmd
);
3400 route_map_install_match (&route_match_origin_cmd
);
3402 route_map_install_set (&route_set_ip_nexthop_cmd
);
3403 route_map_install_set (&route_set_local_pref_cmd
);
3404 route_map_install_set (&route_set_weight_cmd
);
3405 route_map_install_set (&route_set_metric_cmd
);
3406 route_map_install_set (&route_set_aspath_prepend_cmd
);
3407 route_map_install_set (&route_set_origin_cmd
);
3408 route_map_install_set (&route_set_atomic_aggregate_cmd
);
3409 route_map_install_set (&route_set_aggregator_as_cmd
);
3410 route_map_install_set (&route_set_community_cmd
);
3411 route_map_install_set (&route_set_community_delete_cmd
);
3412 route_map_install_set (&route_set_vpnv4_nexthop_cmd
);
3413 route_map_install_set (&route_set_originator_id_cmd
);
3414 route_map_install_set (&route_set_ecommunity_rt_cmd
);
3415 route_map_install_set (&route_set_ecommunity_soo_cmd
);
3417 install_element (RMAP_NODE
, &match_peer_cmd
);
3418 install_element (RMAP_NODE
, &match_peer_local_cmd
);
3419 install_element (RMAP_NODE
, &no_match_peer_cmd
);
3420 install_element (RMAP_NODE
, &no_match_peer_val_cmd
);
3421 install_element (RMAP_NODE
, &no_match_peer_local_cmd
);
3422 install_element (RMAP_NODE
, &match_ip_address_cmd
);
3423 install_element (RMAP_NODE
, &no_match_ip_address_cmd
);
3424 install_element (RMAP_NODE
, &no_match_ip_address_val_cmd
);
3425 install_element (RMAP_NODE
, &match_ip_next_hop_cmd
);
3426 install_element (RMAP_NODE
, &no_match_ip_next_hop_cmd
);
3427 install_element (RMAP_NODE
, &no_match_ip_next_hop_val_cmd
);
3429 install_element (RMAP_NODE
, &match_ip_address_prefix_list_cmd
);
3430 install_element (RMAP_NODE
, &no_match_ip_address_prefix_list_cmd
);
3431 install_element (RMAP_NODE
, &no_match_ip_address_prefix_list_val_cmd
);
3432 install_element (RMAP_NODE
, &match_ip_next_hop_prefix_list_cmd
);
3433 install_element (RMAP_NODE
, &no_match_ip_next_hop_prefix_list_cmd
);
3434 install_element (RMAP_NODE
, &no_match_ip_next_hop_prefix_list_val_cmd
);
3436 install_element (RMAP_NODE
, &match_aspath_cmd
);
3437 install_element (RMAP_NODE
, &no_match_aspath_cmd
);
3438 install_element (RMAP_NODE
, &no_match_aspath_val_cmd
);
3439 install_element (RMAP_NODE
, &match_metric_cmd
);
3440 install_element (RMAP_NODE
, &no_match_metric_cmd
);
3441 install_element (RMAP_NODE
, &no_match_metric_val_cmd
);
3442 install_element (RMAP_NODE
, &match_community_cmd
);
3443 install_element (RMAP_NODE
, &match_community_exact_cmd
);
3444 install_element (RMAP_NODE
, &no_match_community_cmd
);
3445 install_element (RMAP_NODE
, &no_match_community_val_cmd
);
3446 install_element (RMAP_NODE
, &no_match_community_exact_cmd
);
3447 install_element (RMAP_NODE
, &match_ecommunity_cmd
);
3448 install_element (RMAP_NODE
, &no_match_ecommunity_cmd
);
3449 install_element (RMAP_NODE
, &no_match_ecommunity_val_cmd
);
3450 install_element (RMAP_NODE
, &match_origin_cmd
);
3451 install_element (RMAP_NODE
, &no_match_origin_cmd
);
3452 install_element (RMAP_NODE
, &no_match_origin_val_cmd
);
3454 install_element (RMAP_NODE
, &set_ip_nexthop_cmd
);
3455 install_element (RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
3456 install_element (RMAP_NODE
, &no_set_ip_nexthop_cmd
);
3457 install_element (RMAP_NODE
, &no_set_ip_nexthop_val_cmd
);
3458 install_element (RMAP_NODE
, &set_local_pref_cmd
);
3459 install_element (RMAP_NODE
, &no_set_local_pref_cmd
);
3460 install_element (RMAP_NODE
, &no_set_local_pref_val_cmd
);
3461 install_element (RMAP_NODE
, &set_weight_cmd
);
3462 install_element (RMAP_NODE
, &no_set_weight_cmd
);
3463 install_element (RMAP_NODE
, &no_set_weight_val_cmd
);
3464 install_element (RMAP_NODE
, &set_metric_cmd
);
3465 install_element (RMAP_NODE
, &set_metric_addsub_cmd
);
3466 install_element (RMAP_NODE
, &no_set_metric_cmd
);
3467 install_element (RMAP_NODE
, &no_set_metric_val_cmd
);
3468 install_element (RMAP_NODE
, &set_aspath_prepend_cmd
);
3469 install_element (RMAP_NODE
, &no_set_aspath_prepend_cmd
);
3470 install_element (RMAP_NODE
, &no_set_aspath_prepend_val_cmd
);
3471 install_element (RMAP_NODE
, &set_origin_cmd
);
3472 install_element (RMAP_NODE
, &no_set_origin_cmd
);
3473 install_element (RMAP_NODE
, &no_set_origin_val_cmd
);
3474 install_element (RMAP_NODE
, &set_atomic_aggregate_cmd
);
3475 install_element (RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
3476 install_element (RMAP_NODE
, &set_aggregator_as_cmd
);
3477 install_element (RMAP_NODE
, &no_set_aggregator_as_cmd
);
3478 install_element (RMAP_NODE
, &no_set_aggregator_as_val_cmd
);
3479 install_element (RMAP_NODE
, &set_community_cmd
);
3480 install_element (RMAP_NODE
, &set_community_none_cmd
);
3481 install_element (RMAP_NODE
, &no_set_community_cmd
);
3482 install_element (RMAP_NODE
, &no_set_community_val_cmd
);
3483 install_element (RMAP_NODE
, &no_set_community_none_cmd
);
3484 install_element (RMAP_NODE
, &set_community_delete_cmd
);
3485 install_element (RMAP_NODE
, &no_set_community_delete_cmd
);
3486 install_element (RMAP_NODE
, &no_set_community_delete_val_cmd
);
3487 install_element (RMAP_NODE
, &set_ecommunity_rt_cmd
);
3488 install_element (RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
3489 install_element (RMAP_NODE
, &no_set_ecommunity_rt_val_cmd
);
3490 install_element (RMAP_NODE
, &set_ecommunity_soo_cmd
);
3491 install_element (RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
3492 install_element (RMAP_NODE
, &no_set_ecommunity_soo_val_cmd
);
3493 install_element (RMAP_NODE
, &set_vpnv4_nexthop_cmd
);
3494 install_element (RMAP_NODE
, &no_set_vpnv4_nexthop_cmd
);
3495 install_element (RMAP_NODE
, &no_set_vpnv4_nexthop_val_cmd
);
3496 install_element (RMAP_NODE
, &set_originator_id_cmd
);
3497 install_element (RMAP_NODE
, &no_set_originator_id_cmd
);
3498 install_element (RMAP_NODE
, &no_set_originator_id_val_cmd
);
3501 route_map_install_match (&route_match_ipv6_address_cmd
);
3502 route_map_install_match (&route_match_ipv6_next_hop_cmd
);
3503 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd
);
3504 route_map_install_set (&route_set_ipv6_nexthop_global_cmd
);
3505 route_map_install_set (&route_set_ipv6_nexthop_local_cmd
);
3507 install_element (RMAP_NODE
, &match_ipv6_address_cmd
);
3508 install_element (RMAP_NODE
, &no_match_ipv6_address_cmd
);
3509 install_element (RMAP_NODE
, &match_ipv6_next_hop_cmd
);
3510 install_element (RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
3511 install_element (RMAP_NODE
, &match_ipv6_address_prefix_list_cmd
);
3512 install_element (RMAP_NODE
, &no_match_ipv6_address_prefix_list_cmd
);
3513 install_element (RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
3514 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
3515 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_val_cmd
);
3516 install_element (RMAP_NODE
, &set_ipv6_nexthop_local_cmd
);
3517 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_local_cmd
);
3518 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_local_val_cmd
);
3519 #endif /* HAVE_IPV6 */