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 (const 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 (const 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 (const 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 (const 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 (const 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 (const char *arg
)
410 unsigned long tmpval
;
412 tmpval
= strtoul (arg
, &endptr
, 10);
413 if (*endptr
!= '\0' || tmpval
== ULONG_MAX
|| tmpval
> UINT32_MAX
)
416 med
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
425 /* Free route map's compiled `match metric' value. */
427 route_match_metric_free (void *rule
)
429 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
432 /* Route map commands for metric matching. */
433 struct route_map_rule_cmd route_match_metric_cmd
=
437 route_match_metric_compile
,
438 route_match_metric_free
441 /* `match as-path ASPATH' */
443 /* Match function for as-path match. I assume given object is */
445 route_match_aspath (void *rule
, struct prefix
*prefix
,
446 route_map_object_t type
, void *object
)
449 struct as_list
*as_list
;
450 struct bgp_info
*bgp_info
;
452 if (type
== RMAP_BGP
)
454 as_list
= as_list_lookup ((char *) rule
);
461 return ((as_list_apply (as_list
, bgp_info
->attr
->aspath
) == AS_FILTER_DENY
) ? RMAP_NOMATCH
: RMAP_MATCH
);
466 /* Compile function for as-path match. */
468 route_match_aspath_compile (const char *arg
)
470 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
473 /* Compile function for as-path match. */
475 route_match_aspath_free (void *rule
)
477 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
480 /* Route map commands for aspath matching. */
481 struct route_map_rule_cmd route_match_aspath_cmd
=
485 route_match_aspath_compile
,
486 route_match_aspath_free
489 #if ROUTE_MATCH_ASPATH_OLD
490 /* `match as-path ASPATH' */
492 /* Match function for as-path match. I assume given object is */
494 route_match_aspath (void *rule
, struct prefix
*prefix
, void *object
)
497 struct bgp_info
*bgp_info
;
503 return bgp_regexec (regex
, bgp_info
->attr
->aspath
);
506 /* Compile function for as-path match. */
508 route_match_aspath_compile (const char *arg
)
512 regex
= bgp_regcomp (arg
);
519 /* Compile function for as-path match. */
521 route_match_aspath_free (void *rule
)
523 regex_t
*regex
= rule
;
525 bgp_regex_free (regex
);
528 /* Route map commands for aspath matching. */
529 struct route_map_rule_cmd route_match_aspath_cmd
=
533 route_match_aspath_compile
,
534 route_match_aspath_free
536 #endif /* ROUTE_MATCH_ASPATH_OLD */
538 /* `match community COMMUNIY' */
539 struct rmap_community
545 /* Match function for community match. */
547 route_match_community (void *rule
, struct prefix
*prefix
,
548 route_map_object_t type
, void *object
)
550 struct community_list
*list
;
551 struct bgp_info
*bgp_info
;
552 struct rmap_community
*rcom
;
554 if (type
== RMAP_BGP
)
559 list
= community_list_lookup (bgp_clist
, rcom
->name
, COMMUNITY_LIST_AUTO
);
565 if (community_list_exact_match (bgp_info
->attr
->community
, list
))
570 if (community_list_match (bgp_info
->attr
->community
, list
))
577 /* Compile function for community match. */
579 route_match_community_compile (const char *arg
)
581 struct rmap_community
*rcom
;
585 rcom
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_community
));
587 p
= strchr (arg
, ' ');
591 rcom
->name
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
592 memcpy (rcom
->name
, arg
, len
);
597 rcom
->name
= XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
603 /* Compile function for community match. */
605 route_match_community_free (void *rule
)
607 struct rmap_community
*rcom
= rule
;
609 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
610 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
);
613 /* Route map commands for community matching. */
614 struct route_map_rule_cmd route_match_community_cmd
=
617 route_match_community
,
618 route_match_community_compile
,
619 route_match_community_free
622 /* Match function for extcommunity match. */
624 route_match_ecommunity (void *rule
, struct prefix
*prefix
,
625 route_map_object_t type
, void *object
)
627 struct community_list
*list
;
628 struct bgp_info
*bgp_info
;
630 if (type
== RMAP_BGP
)
634 list
= community_list_lookup (bgp_clist
, (char *) rule
,
635 EXTCOMMUNITY_LIST_AUTO
);
639 if (ecommunity_list_match (bgp_info
->attr
->ecommunity
, list
))
645 /* Compile function for extcommunity match. */
647 route_match_ecommunity_compile (const char *arg
)
649 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
652 /* Compile function for extcommunity match. */
654 route_match_ecommunity_free (void *rule
)
656 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
659 /* Route map commands for community matching. */
660 struct route_map_rule_cmd route_match_ecommunity_cmd
=
663 route_match_ecommunity
,
664 route_match_ecommunity_compile
,
665 route_match_ecommunity_free
668 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
669 and `address-family vpnv4'. */
673 route_match_origin (void *rule
, struct prefix
*prefix
,
674 route_map_object_t type
, void *object
)
677 struct bgp_info
*bgp_info
;
679 if (type
== RMAP_BGP
)
684 if (bgp_info
->attr
->origin
== *origin
)
692 route_match_origin_compile (const char *arg
)
696 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
698 if (strcmp (arg
, "igp") == 0)
700 else if (strcmp (arg
, "egp") == 0)
708 /* Free route map's compiled `ip address' value. */
710 route_match_origin_free (void *rule
)
712 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
715 /* Route map commands for origin matching. */
716 struct route_map_rule_cmd route_match_origin_cmd
=
720 route_match_origin_compile
,
721 route_match_origin_free
723 /* `set ip next-hop IP_ADDRESS' */
725 /* Set nexthop to object. ojbect must be pointer to struct attr. */
726 struct rmap_ip_nexthop_set
728 struct in_addr
*address
;
733 route_set_ip_nexthop (void *rule
, struct prefix
*prefix
,
734 route_map_object_t type
, void *object
)
736 struct rmap_ip_nexthop_set
*rins
= rule
;
737 struct in_addr peer_address
;
738 struct bgp_info
*bgp_info
;
741 if (type
== RMAP_BGP
)
744 peer
= bgp_info
->peer
;
746 if (rins
->peer_address
)
748 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
749 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
751 && sockunion_family (peer
->su_remote
) == AF_INET
)
753 inet_aton (sockunion_su2str (peer
->su_remote
), &peer_address
);
754 bgp_info
->attr
->nexthop
= peer_address
;
755 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
757 else if (CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
)
759 && sockunion_family (peer
->su_local
) == AF_INET
)
761 inet_aton (sockunion_su2str (peer
->su_local
), &peer_address
);
762 bgp_info
->attr
->nexthop
= peer_address
;
763 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
768 /* Set next hop value. */
769 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
770 bgp_info
->attr
->nexthop
= *rins
->address
;
777 /* Route map `ip nexthop' compile function. Given string is converted
778 to struct in_addr structure. */
780 route_set_ip_nexthop_compile (const char *arg
)
782 struct rmap_ip_nexthop_set
*rins
;
783 struct in_addr
*address
= NULL
;
784 int peer_address
= 0;
787 if (strcmp (arg
, "peer-address") == 0)
791 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
792 ret
= inet_aton (arg
, address
);
796 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
801 rins
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_ip_nexthop_set
));
802 memset (rins
, 0, sizeof (struct rmap_ip_nexthop_set
));
804 rins
->address
= address
;
805 rins
->peer_address
= peer_address
;
810 /* Free route map's compiled `ip nexthop' value. */
812 route_set_ip_nexthop_free (void *rule
)
814 struct rmap_ip_nexthop_set
*rins
= rule
;
817 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
819 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
);
822 /* Route map commands for ip nexthop set. */
823 struct route_map_rule_cmd route_set_ip_nexthop_cmd
=
826 route_set_ip_nexthop
,
827 route_set_ip_nexthop_compile
,
828 route_set_ip_nexthop_free
831 /* `set local-preference LOCAL_PREF' */
833 /* Set local preference. */
835 route_set_local_pref (void *rule
, struct prefix
*prefix
,
836 route_map_object_t type
, void *object
)
838 u_int32_t
*local_pref
;
839 struct bgp_info
*bgp_info
;
841 if (type
== RMAP_BGP
)
843 /* Fetch routemap's rule information. */
847 /* Set local preference value. */
848 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
);
849 bgp_info
->attr
->local_pref
= *local_pref
;
855 /* set local preference compilation. */
857 route_set_local_pref_compile (const char *arg
)
860 u_int32_t
*local_pref
;
863 /* Local preference value shoud be integer. */
864 if (! all_digit (arg
))
867 tmp
= strtoul (arg
, &endptr
, 10);
868 if (*endptr
!= '\0' || tmp
== ULONG_MAX
|| tmp
> UINT32_MAX
)
871 local_pref
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
881 /* Free route map's local preference value. */
883 route_set_local_pref_free (void *rule
)
885 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
888 /* Set local preference rule structure. */
889 struct route_map_rule_cmd route_set_local_pref_cmd
=
892 route_set_local_pref
,
893 route_set_local_pref_compile
,
894 route_set_local_pref_free
,
897 /* `set weight WEIGHT' */
901 route_set_weight (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
905 struct bgp_info
*bgp_info
;
907 if (type
== RMAP_BGP
)
909 /* Fetch routemap's rule information. */
913 /* Set weight value. */
914 bgp_info
->attr
->weight
= *weight
;
920 /* set local preference compilation. */
922 route_set_weight_compile (const char *arg
)
928 /* Local preference value shoud be integer. */
929 if (! all_digit (arg
))
933 tmp
= strtoul (arg
, &endptr
, 10);
934 if (*endptr
!= '\0' || tmp
== ULONG_MAX
|| tmp
> UINT32_MAX
)
937 weight
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
947 /* Free route map's local preference value. */
949 route_set_weight_free (void *rule
)
951 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
954 /* Set local preference rule structure. */
955 struct route_map_rule_cmd route_set_weight_cmd
=
959 route_set_weight_compile
,
960 route_set_weight_free
,
963 /* `set metric METRIC' */
965 /* Set metric to attribute. */
967 route_set_metric (void *rule
, struct prefix
*prefix
,
968 route_map_object_t type
, void *object
)
971 u_int32_t metric_val
;
972 struct bgp_info
*bgp_info
;
974 if (type
== RMAP_BGP
)
976 /* Fetch routemap's rule information. */
980 if (! (bgp_info
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
)))
981 bgp_info
->attr
->med
= 0;
982 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
);
984 if (all_digit (metric
))
986 metric_val
= strtoul (metric
, (char **)NULL
, 10);
987 bgp_info
->attr
->med
= metric_val
;
991 metric_val
= strtoul (metric
+1, (char **)NULL
, 10);
993 if (strncmp (metric
, "+", 1) == 0)
995 if (bgp_info
->attr
->med
/2 + metric_val
/2 > BGP_MED_MAX
/2)
996 bgp_info
->attr
->med
= BGP_MED_MAX
- 1;
998 bgp_info
->attr
->med
+= metric_val
;
1000 else if (strncmp (metric
, "-", 1) == 0)
1002 if (bgp_info
->attr
->med
<= metric_val
)
1003 bgp_info
->attr
->med
= 0;
1005 bgp_info
->attr
->med
-= metric_val
;
1012 /* set metric compilation. */
1014 route_set_metric_compile (const char *arg
)
1017 char *endptr
= NULL
;
1019 if (all_digit (arg
))
1021 /* set metric value check*/
1022 metric
= strtoul (arg
, &endptr
, 10);
1023 if (*endptr
!= '\0' || metric
== ULONG_MAX
)
1028 /* set metric +/-value check */
1029 if ((strncmp (arg
, "+", 1) != 0
1030 && strncmp (arg
, "-", 1) != 0)
1031 || (! all_digit (arg
+1)))
1034 metric
= strtoul (arg
+1, &endptr
, 10);
1035 if (*endptr
!= '\0' || metric
== ULONG_MAX
)
1039 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1042 /* Free route map's compiled `set metric' value. */
1044 route_set_metric_free (void *rule
)
1046 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1049 /* Set metric rule structure. */
1050 struct route_map_rule_cmd route_set_metric_cmd
=
1054 route_set_metric_compile
,
1055 route_set_metric_free
,
1058 /* `set as-path prepend ASPATH' */
1060 /* For AS path prepend mechanism. */
1062 route_set_aspath_prepend (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1064 struct aspath
*aspath
;
1066 struct bgp_info
*binfo
;
1068 if (type
== RMAP_BGP
)
1073 if (binfo
->attr
->aspath
->refcnt
)
1074 new = aspath_dup (binfo
->attr
->aspath
);
1076 new = binfo
->attr
->aspath
;
1078 aspath_prepend (aspath
, new);
1079 binfo
->attr
->aspath
= new;
1085 /* Compile function for as-path prepend. */
1087 route_set_aspath_prepend_compile (const char *arg
)
1089 struct aspath
*aspath
;
1091 aspath
= aspath_str2aspath (arg
);
1097 /* Compile function for as-path prepend. */
1099 route_set_aspath_prepend_free (void *rule
)
1101 struct aspath
*aspath
= rule
;
1102 aspath_free (aspath
);
1105 /* Set metric rule structure. */
1106 struct route_map_rule_cmd route_set_aspath_prepend_cmd
=
1109 route_set_aspath_prepend
,
1110 route_set_aspath_prepend_compile
,
1111 route_set_aspath_prepend_free
,
1114 /* `set community COMMUNITY' */
1117 struct community
*com
;
1122 /* For community set mechanism. */
1124 route_set_community (void *rule
, struct prefix
*prefix
,
1125 route_map_object_t type
, void *object
)
1127 struct rmap_com_set
*rcs
;
1128 struct bgp_info
*binfo
;
1130 struct community
*new = NULL
;
1131 struct community
*old
;
1132 struct community
*merge
;
1134 if (type
== RMAP_BGP
)
1139 old
= attr
->community
;
1144 attr
->flag
&= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
));
1145 attr
->community
= NULL
;
1149 /* "additive" case. */
1150 if (rcs
->additive
&& old
)
1152 merge
= community_merge (community_dup (old
), rcs
->com
);
1153 new = community_uniq_sort (merge
);
1154 community_free (merge
);
1157 new = community_dup (rcs
->com
);
1159 attr
->community
= new;
1160 attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1166 /* Compile function for set community. */
1168 route_set_community_compile (const char *arg
)
1170 struct rmap_com_set
*rcs
;
1171 struct community
*com
= NULL
;
1176 if (strcmp (arg
, "none") == 0)
1180 sp
= strstr (arg
, "additive");
1184 /* "additive" keyworkd is included. */
1189 com
= community_str2com (arg
);
1198 rcs
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_com_set
));
1199 memset (rcs
, 0, sizeof (struct rmap_com_set
));
1202 rcs
->additive
= additive
;
1208 /* Free function for set community. */
1210 route_set_community_free (void *rule
)
1212 struct rmap_com_set
*rcs
= rule
;
1215 community_free (rcs
->com
);
1216 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1219 /* Set community rule structure. */
1220 struct route_map_rule_cmd route_set_community_cmd
=
1223 route_set_community
,
1224 route_set_community_compile
,
1225 route_set_community_free
,
1228 /* `set comm-list (<1-99>|<100-199>|WORD) delete' */
1230 /* For community set mechanism. */
1232 route_set_community_delete (void *rule
, struct prefix
*prefix
,
1233 route_map_object_t type
, void *object
)
1235 struct community_list
*list
;
1236 struct community
*merge
;
1237 struct community
*new;
1238 struct community
*old
;
1239 struct bgp_info
*binfo
;
1241 if (type
== RMAP_BGP
)
1247 list
= community_list_lookup (bgp_clist
, rule
, COMMUNITY_LIST_AUTO
);
1248 old
= binfo
->attr
->community
;
1252 merge
= community_list_match_delete (community_dup (old
), list
);
1253 new = community_uniq_sort (merge
);
1254 community_free (merge
);
1258 binfo
->attr
->community
= NULL
;
1259 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1260 community_free (new);
1264 binfo
->attr
->community
= new;
1265 binfo
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1273 /* Compile function for set community. */
1275 route_set_community_delete_compile (const char *arg
)
1281 p
= strchr (arg
, ' ');
1285 str
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1286 memcpy (str
, arg
, len
);
1294 /* Free function for set community. */
1296 route_set_community_delete_free (void *rule
)
1298 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1301 /* Set community rule structure. */
1302 struct route_map_rule_cmd route_set_community_delete_cmd
=
1305 route_set_community_delete
,
1306 route_set_community_delete_compile
,
1307 route_set_community_delete_free
,
1310 /* `set extcommunity rt COMMUNITY' */
1312 /* For community set mechanism. */
1314 route_set_ecommunity_rt (void *rule
, struct prefix
*prefix
,
1315 route_map_object_t type
, void *object
)
1317 struct ecommunity
*ecom
;
1318 struct ecommunity
*new_ecom
;
1319 struct ecommunity
*old_ecom
;
1320 struct bgp_info
*bgp_info
;
1322 if (type
== RMAP_BGP
)
1330 /* We assume additive for Extended Community. */
1331 old_ecom
= bgp_info
->attr
->ecommunity
;
1334 new_ecom
= ecommunity_merge (ecommunity_dup (old_ecom
), ecom
);
1336 new_ecom
= ecommunity_dup (ecom
);
1338 bgp_info
->attr
->ecommunity
= new_ecom
;
1340 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES
);
1345 /* Compile function for set community. */
1347 route_set_ecommunity_rt_compile (const char *arg
)
1349 struct ecommunity
*ecom
;
1351 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
1357 /* Free function for set community. */
1359 route_set_ecommunity_rt_free (void *rule
)
1361 struct ecommunity
*ecom
= rule
;
1362 ecommunity_free (ecom
);
1365 /* Set community rule structure. */
1366 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
=
1369 route_set_ecommunity_rt
,
1370 route_set_ecommunity_rt_compile
,
1371 route_set_ecommunity_rt_free
,
1374 /* `set extcommunity soo COMMUNITY' */
1376 /* For community set mechanism. */
1378 route_set_ecommunity_soo (void *rule
, struct prefix
*prefix
,
1379 route_map_object_t type
, void *object
)
1381 struct ecommunity
*ecom
;
1382 struct bgp_info
*bgp_info
;
1384 if (type
== RMAP_BGP
)
1392 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES
);
1393 bgp_info
->attr
->ecommunity
= ecommunity_dup (ecom
);
1398 /* Compile function for set community. */
1400 route_set_ecommunity_soo_compile (const char *arg
)
1402 struct ecommunity
*ecom
;
1404 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
1411 /* Free function for set community. */
1413 route_set_ecommunity_soo_free (void *rule
)
1415 struct ecommunity
*ecom
= rule
;
1416 ecommunity_free (ecom
);
1419 /* Set community rule structure. */
1420 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
=
1423 route_set_ecommunity_soo
,
1424 route_set_ecommunity_soo_compile
,
1425 route_set_ecommunity_soo_free
,
1428 /* `set origin ORIGIN' */
1430 /* For origin set. */
1432 route_set_origin (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1435 struct bgp_info
*bgp_info
;
1437 if (type
== RMAP_BGP
)
1442 bgp_info
->attr
->origin
= *origin
;
1448 /* Compile function for origin set. */
1450 route_set_origin_compile (const char *arg
)
1454 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
1456 if (strcmp (arg
, "igp") == 0)
1458 else if (strcmp (arg
, "egp") == 0)
1466 /* Compile function for origin set. */
1468 route_set_origin_free (void *rule
)
1470 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1473 /* Set metric rule structure. */
1474 struct route_map_rule_cmd route_set_origin_cmd
=
1478 route_set_origin_compile
,
1479 route_set_origin_free
,
1482 /* `set atomic-aggregate' */
1484 /* For atomic aggregate set. */
1486 route_set_atomic_aggregate (void *rule
, struct prefix
*prefix
,
1487 route_map_object_t type
, void *object
)
1489 struct bgp_info
*bgp_info
;
1491 if (type
== RMAP_BGP
)
1494 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
);
1500 /* Compile function for atomic aggregate. */
1502 route_set_atomic_aggregate_compile (const char *arg
)
1507 /* Compile function for atomic aggregate. */
1509 route_set_atomic_aggregate_free (void *rule
)
1514 /* Set atomic aggregate rule structure. */
1515 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
=
1518 route_set_atomic_aggregate
,
1519 route_set_atomic_aggregate_compile
,
1520 route_set_atomic_aggregate_free
,
1523 /* `set aggregator as AS A.B.C.D' */
1527 struct in_addr address
;
1531 route_set_aggregator_as (void *rule
, struct prefix
*prefix
,
1532 route_map_object_t type
, void *object
)
1534 struct bgp_info
*bgp_info
;
1535 struct aggregator
*aggregator
;
1537 if (type
== RMAP_BGP
)
1542 bgp_info
->attr
->aggregator_as
= aggregator
->as
;
1543 bgp_info
->attr
->aggregator_addr
= aggregator
->address
;
1544 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR
);
1551 route_set_aggregator_as_compile (const char *arg
)
1553 struct aggregator
*aggregator
;
1557 aggregator
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct aggregator
));
1558 memset (aggregator
, 0, sizeof (struct aggregator
));
1560 sscanf (arg
, "%s %s", as
, address
);
1562 aggregator
->as
= strtoul (as
, NULL
, 10);
1563 inet_aton (address
, &aggregator
->address
);
1569 route_set_aggregator_as_free (void *rule
)
1571 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1574 struct route_map_rule_cmd route_set_aggregator_as_cmd
=
1577 route_set_aggregator_as
,
1578 route_set_aggregator_as_compile
,
1579 route_set_aggregator_as_free
,
1583 /* `match ipv6 address IP_ACCESS_LIST' */
1586 route_match_ipv6_address (void *rule
, struct prefix
*prefix
,
1587 route_map_object_t type
, void *object
)
1589 struct access_list
*alist
;
1591 if (type
== RMAP_BGP
)
1593 alist
= access_list_lookup (AFI_IP6
, (char *) rule
);
1595 return RMAP_NOMATCH
;
1597 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
1598 RMAP_NOMATCH
: RMAP_MATCH
);
1600 return RMAP_NOMATCH
;
1604 route_match_ipv6_address_compile (const char *arg
)
1606 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1610 route_match_ipv6_address_free (void *rule
)
1612 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1615 /* Route map commands for ip address matching. */
1616 struct route_map_rule_cmd route_match_ipv6_address_cmd
=
1619 route_match_ipv6_address
,
1620 route_match_ipv6_address_compile
,
1621 route_match_ipv6_address_free
1624 /* `match ipv6 next-hop IP_ADDRESS' */
1627 route_match_ipv6_next_hop (void *rule
, struct prefix
*prefix
,
1628 route_map_object_t type
, void *object
)
1630 struct in6_addr
*addr
;
1631 struct bgp_info
*bgp_info
;
1633 if (type
== RMAP_BGP
)
1638 if (IPV6_ADDR_SAME (&bgp_info
->attr
->mp_nexthop_global
, rule
))
1641 if (bgp_info
->attr
->mp_nexthop_len
== 32 &&
1642 IPV6_ADDR_SAME (&bgp_info
->attr
->mp_nexthop_local
, rule
))
1645 return RMAP_NOMATCH
;
1648 return RMAP_NOMATCH
;
1652 route_match_ipv6_next_hop_compile (const char *arg
)
1654 struct in6_addr
*address
;
1657 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
1659 ret
= inet_pton (AF_INET6
, arg
, address
);
1662 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1670 route_match_ipv6_next_hop_free (void *rule
)
1672 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1675 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
=
1678 route_match_ipv6_next_hop
,
1679 route_match_ipv6_next_hop_compile
,
1680 route_match_ipv6_next_hop_free
1683 /* `match ipv6 address prefix-list PREFIX_LIST' */
1686 route_match_ipv6_address_prefix_list (void *rule
, struct prefix
*prefix
,
1687 route_map_object_t type
, void *object
)
1689 struct prefix_list
*plist
;
1691 if (type
== RMAP_BGP
)
1693 plist
= prefix_list_lookup (AFI_IP6
, (char *) rule
);
1695 return RMAP_NOMATCH
;
1697 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
1698 RMAP_NOMATCH
: RMAP_MATCH
);
1700 return RMAP_NOMATCH
;
1704 route_match_ipv6_address_prefix_list_compile (const char *arg
)
1706 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1710 route_match_ipv6_address_prefix_list_free (void *rule
)
1712 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1715 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
=
1717 "ipv6 address prefix-list",
1718 route_match_ipv6_address_prefix_list
,
1719 route_match_ipv6_address_prefix_list_compile
,
1720 route_match_ipv6_address_prefix_list_free
1723 /* `set ipv6 nexthop global IP_ADDRESS' */
1725 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1727 route_set_ipv6_nexthop_global (void *rule
, struct prefix
*prefix
,
1728 route_map_object_t type
, void *object
)
1730 struct in6_addr
*address
;
1731 struct bgp_info
*bgp_info
;
1733 if (type
== RMAP_BGP
)
1735 /* Fetch routemap's rule information. */
1739 /* Set next hop value. */
1740 bgp_info
->attr
->mp_nexthop_global
= *address
;
1742 /* Set nexthop length. */
1743 if (bgp_info
->attr
->mp_nexthop_len
== 0)
1744 bgp_info
->attr
->mp_nexthop_len
= 16;
1750 /* Route map `ip next-hop' compile function. Given string is converted
1751 to struct in_addr structure. */
1753 route_set_ipv6_nexthop_global_compile (const char *arg
)
1756 struct in6_addr
*address
;
1758 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
1760 ret
= inet_pton (AF_INET6
, arg
, address
);
1764 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1771 /* Free route map's compiled `ip next-hop' value. */
1773 route_set_ipv6_nexthop_global_free (void *rule
)
1775 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1778 /* Route map commands for ip nexthop set. */
1779 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
=
1781 "ipv6 next-hop global",
1782 route_set_ipv6_nexthop_global
,
1783 route_set_ipv6_nexthop_global_compile
,
1784 route_set_ipv6_nexthop_global_free
1787 /* `set ipv6 nexthop local IP_ADDRESS' */
1789 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1791 route_set_ipv6_nexthop_local (void *rule
, struct prefix
*prefix
,
1792 route_map_object_t type
, void *object
)
1794 struct in6_addr
*address
;
1795 struct bgp_info
*bgp_info
;
1797 if (type
== RMAP_BGP
)
1799 /* Fetch routemap's rule information. */
1803 /* Set next hop value. */
1804 bgp_info
->attr
->mp_nexthop_local
= *address
;
1806 /* Set nexthop length. */
1807 if (bgp_info
->attr
->mp_nexthop_len
!= 32)
1808 bgp_info
->attr
->mp_nexthop_len
= 32;
1814 /* Route map `ip nexthop' compile function. Given string is converted
1815 to struct in_addr structure. */
1817 route_set_ipv6_nexthop_local_compile (const char *arg
)
1820 struct in6_addr
*address
;
1822 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
1824 ret
= inet_pton (AF_INET6
, arg
, address
);
1828 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1835 /* Free route map's compiled `ip nexthop' value. */
1837 route_set_ipv6_nexthop_local_free (void *rule
)
1839 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1842 /* Route map commands for ip nexthop set. */
1843 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
=
1845 "ipv6 next-hop local",
1846 route_set_ipv6_nexthop_local
,
1847 route_set_ipv6_nexthop_local_compile
,
1848 route_set_ipv6_nexthop_local_free
1850 #endif /* HAVE_IPV6 */
1852 /* `set vpnv4 nexthop A.B.C.D' */
1855 route_set_vpnv4_nexthop (void *rule
, struct prefix
*prefix
,
1856 route_map_object_t type
, void *object
)
1858 struct in_addr
*address
;
1859 struct bgp_info
*bgp_info
;
1861 if (type
== RMAP_BGP
)
1863 /* Fetch routemap's rule information. */
1867 /* Set next hop value. */
1868 bgp_info
->attr
->mp_nexthop_global_in
= *address
;
1875 route_set_vpnv4_nexthop_compile (const char *arg
)
1878 struct in_addr
*address
;
1880 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
1882 ret
= inet_aton (arg
, address
);
1886 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1894 route_set_vpnv4_nexthop_free (void *rule
)
1896 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1899 /* Route map commands for ip nexthop set. */
1900 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
=
1903 route_set_vpnv4_nexthop
,
1904 route_set_vpnv4_nexthop_compile
,
1905 route_set_vpnv4_nexthop_free
1908 /* `set originator-id' */
1910 /* For origin set. */
1912 route_set_originator_id (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1914 struct in_addr
*address
;
1915 struct bgp_info
*bgp_info
;
1917 if (type
== RMAP_BGP
)
1922 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
);
1923 bgp_info
->attr
->originator_id
= *address
;
1929 /* Compile function for originator-id set. */
1931 route_set_originator_id_compile (const char *arg
)
1934 struct in_addr
*address
;
1936 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
1938 ret
= inet_aton (arg
, address
);
1942 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1949 /* Compile function for originator_id set. */
1951 route_set_originator_id_free (void *rule
)
1953 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1956 /* Set metric rule structure. */
1957 struct route_map_rule_cmd route_set_originator_id_cmd
=
1960 route_set_originator_id
,
1961 route_set_originator_id_compile
,
1962 route_set_originator_id_free
,
1965 /* Add bgp route map rule. */
1967 bgp_route_match_add (struct vty
*vty
, struct route_map_index
*index
,
1968 const char *command
, const char *arg
)
1972 ret
= route_map_add_match (index
, command
, arg
);
1977 case RMAP_RULE_MISSING
:
1978 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
1981 case RMAP_COMPILE_ERROR
:
1982 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
1990 /* Delete bgp route map rule. */
1992 bgp_route_match_delete (struct vty
*vty
, struct route_map_index
*index
,
1993 const char *command
, const char *arg
)
1997 ret
= route_map_delete_match (index
, command
, arg
);
2002 case RMAP_RULE_MISSING
:
2003 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
2006 case RMAP_COMPILE_ERROR
:
2007 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
2015 /* Add bgp route map rule. */
2017 bgp_route_set_add (struct vty
*vty
, struct route_map_index
*index
,
2018 const char *command
, const char *arg
)
2022 ret
= route_map_add_set (index
, command
, arg
);
2027 case RMAP_RULE_MISSING
:
2028 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
2031 case RMAP_COMPILE_ERROR
:
2032 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
2040 /* Delete bgp route map rule. */
2042 bgp_route_set_delete (struct vty
*vty
, struct route_map_index
*index
,
2043 const char *command
, const char *arg
)
2047 ret
= route_map_delete_set (index
, command
, arg
);
2052 case RMAP_RULE_MISSING
:
2053 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
2056 case RMAP_COMPILE_ERROR
:
2057 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
2065 /* Hook function for updating route_map assignment. */
2067 bgp_route_map_update (const char *unused
)
2073 struct listnode
*nn
, *nm
;
2076 struct peer_group
*group
;
2077 struct bgp_filter
*filter
;
2078 struct bgp_node
*bn
;
2079 struct bgp_static
*bgp_static
;
2081 /* For neighbor route-map updates. */
2082 LIST_LOOP (bm
->bgp
, bgp
, nn
)
2084 LIST_LOOP (bgp
->peer
, peer
, nm
)
2086 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2087 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2089 filter
= &peer
->filter
[afi
][safi
];
2091 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++)
2093 if (filter
->map
[direct
].name
)
2094 filter
->map
[direct
].map
=
2095 route_map_lookup_by_name (filter
->map
[direct
].name
);
2097 filter
->map
[direct
].map
= NULL
;
2100 if (filter
->usmap
.name
)
2101 filter
->usmap
.map
= route_map_lookup_by_name (filter
->usmap
.name
);
2103 filter
->usmap
.map
= NULL
;
2106 LIST_LOOP (bgp
->group
, group
, nm
)
2108 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2109 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2111 filter
= &group
->conf
->filter
[afi
][safi
];
2113 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++)
2115 if (filter
->map
[direct
].name
)
2116 filter
->map
[direct
].map
=
2117 route_map_lookup_by_name (filter
->map
[direct
].name
);
2119 filter
->map
[direct
].map
= NULL
;
2122 if (filter
->usmap
.name
)
2123 filter
->usmap
.map
= route_map_lookup_by_name (filter
->usmap
.name
);
2125 filter
->usmap
.map
= NULL
;
2130 /* For default-originate route-map updates. */
2131 LIST_LOOP (bm
->bgp
, bgp
, nn
)
2133 LIST_LOOP (bgp
->peer
, peer
, nm
)
2135 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2136 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2138 if (peer
->default_rmap
[afi
][safi
].name
)
2139 peer
->default_rmap
[afi
][safi
].map
=
2140 route_map_lookup_by_name (peer
->default_rmap
[afi
][safi
].name
);
2142 peer
->default_rmap
[afi
][safi
].map
= NULL
;
2147 /* For network route-map updates. */
2148 LIST_LOOP (bm
->bgp
, bgp
, nn
)
2150 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2151 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2152 for (bn
= bgp_table_top (bgp
->route
[afi
][safi
]); bn
;
2153 bn
= bgp_route_next (bn
))
2154 if ((bgp_static
= bn
->info
) != NULL
)
2156 if (bgp_static
->rmap
.name
)
2157 bgp_static
->rmap
.map
=
2158 route_map_lookup_by_name (bgp_static
->rmap
.name
);
2160 bgp_static
->rmap
.map
= NULL
;
2164 /* For redistribute route-map updates. */
2165 LIST_LOOP (bm
->bgp
, bgp
, nn
)
2167 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2169 if (bgp
->rmap
[ZEBRA_FAMILY_IPV4
][i
].name
)
2170 bgp
->rmap
[ZEBRA_FAMILY_IPV4
][i
].map
=
2171 route_map_lookup_by_name (bgp
->rmap
[ZEBRA_FAMILY_IPV4
][i
].name
);
2173 if (bgp
->rmap
[ZEBRA_FAMILY_IPV6
][i
].name
)
2174 bgp
->rmap
[ZEBRA_FAMILY_IPV6
][i
].map
=
2175 route_map_lookup_by_name (bgp
->rmap
[ZEBRA_FAMILY_IPV6
][i
].name
);
2176 #endif /* HAVE_IPV6 */
2183 "match peer (A.B.C.D|X:X::X:X)",
2185 "Match peer address\n"
2186 "IPv6 address of peer\n"
2187 "IP address of peer\n")
2189 return bgp_route_match_add (vty
, vty
->index
, "peer", argv
[0]);
2192 DEFUN (match_peer_local
,
2193 match_peer_local_cmd
,
2196 "Match peer address\n"
2197 "Static or Redistributed routes\n")
2199 return bgp_route_match_add (vty
, vty
->index
, "peer", NULL
);
2202 DEFUN (no_match_peer
,
2207 "Match peer address\n")
2210 return bgp_route_match_delete (vty
, vty
->index
, "peer", NULL
);
2212 return bgp_route_match_delete (vty
, vty
->index
, "peer", argv
[0]);
2215 ALIAS (no_match_peer
,
2216 no_match_peer_val_cmd
,
2217 "no match peer (A.B.C.D|X:X::X:X)",
2220 "Match peer address\n"
2221 "IPv6 address of peer\n"
2222 "IP address of peer\n")
2224 ALIAS (no_match_peer
,
2225 no_match_peer_local_cmd
,
2226 "no match peer local",
2229 "Match peer address\n"
2230 "Static or Redistributed routes\n")
2232 DEFUN (match_ip_address
,
2233 match_ip_address_cmd
,
2234 "match ip address (<1-199>|<1300-2699>|WORD)",
2237 "Match address of route\n"
2238 "IP access-list number\n"
2239 "IP access-list number (expanded range)\n"
2240 "IP Access-list name\n")
2242 return bgp_route_match_add (vty
, vty
->index
, "ip address", argv
[0]);
2245 DEFUN (no_match_ip_address
,
2246 no_match_ip_address_cmd
,
2247 "no match ip address",
2251 "Match address of route\n")
2254 return bgp_route_match_delete (vty
, vty
->index
, "ip address", NULL
);
2256 return bgp_route_match_delete (vty
, vty
->index
, "ip address", argv
[0]);
2259 ALIAS (no_match_ip_address
,
2260 no_match_ip_address_val_cmd
,
2261 "no match ip address (<1-199>|<1300-2699>|WORD)",
2265 "Match address of route\n"
2266 "IP access-list number\n"
2267 "IP access-list number (expanded range)\n"
2268 "IP Access-list name\n")
2270 DEFUN (match_ip_next_hop
,
2271 match_ip_next_hop_cmd
,
2272 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
2275 "Match next-hop address of route\n"
2276 "IP access-list number\n"
2277 "IP access-list number (expanded range)\n"
2278 "IP Access-list name\n")
2280 return bgp_route_match_add (vty
, vty
->index
, "ip next-hop", argv
[0]);
2283 DEFUN (no_match_ip_next_hop
,
2284 no_match_ip_next_hop_cmd
,
2285 "no match ip next-hop",
2289 "Match next-hop address of route\n")
2292 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop", NULL
);
2294 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop", argv
[0]);
2297 ALIAS (no_match_ip_next_hop
,
2298 no_match_ip_next_hop_val_cmd
,
2299 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2303 "Match next-hop address of route\n"
2304 "IP access-list number\n"
2305 "IP access-list number (expanded range)\n"
2306 "IP Access-list name\n")
2308 DEFUN (match_ip_address_prefix_list
,
2309 match_ip_address_prefix_list_cmd
,
2310 "match ip address prefix-list WORD",
2313 "Match address of route\n"
2314 "Match entries of prefix-lists\n"
2315 "IP prefix-list name\n")
2317 return bgp_route_match_add (vty
, vty
->index
, "ip address prefix-list", argv
[0]);
2320 DEFUN (no_match_ip_address_prefix_list
,
2321 no_match_ip_address_prefix_list_cmd
,
2322 "no match ip address prefix-list",
2326 "Match address of route\n"
2327 "Match entries of prefix-lists\n")
2330 return bgp_route_match_delete (vty
, vty
->index
, "ip address prefix-list", NULL
);
2332 return bgp_route_match_delete (vty
, vty
->index
, "ip address prefix-list", argv
[0]);
2335 ALIAS (no_match_ip_address_prefix_list
,
2336 no_match_ip_address_prefix_list_val_cmd
,
2337 "no match ip address prefix-list WORD",
2341 "Match address of route\n"
2342 "Match entries of prefix-lists\n"
2343 "IP prefix-list name\n")
2345 DEFUN (match_ip_next_hop_prefix_list
,
2346 match_ip_next_hop_prefix_list_cmd
,
2347 "match ip next-hop prefix-list WORD",
2350 "Match next-hop address of route\n"
2351 "Match entries of prefix-lists\n"
2352 "IP prefix-list name\n")
2354 return bgp_route_match_add (vty
, vty
->index
, "ip next-hop prefix-list", argv
[0]);
2357 DEFUN (no_match_ip_next_hop_prefix_list
,
2358 no_match_ip_next_hop_prefix_list_cmd
,
2359 "no match ip next-hop prefix-list",
2363 "Match next-hop address of route\n"
2364 "Match entries of prefix-lists\n")
2367 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop prefix-list", NULL
);
2369 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop prefix-list", argv
[0]);
2372 ALIAS (no_match_ip_next_hop_prefix_list
,
2373 no_match_ip_next_hop_prefix_list_val_cmd
,
2374 "no match ip next-hop prefix-list WORD",
2378 "Match next-hop address of route\n"
2379 "Match entries of prefix-lists\n"
2380 "IP prefix-list name\n")
2382 DEFUN (match_metric
,
2384 "match metric <0-4294967295>",
2386 "Match metric of route\n"
2389 return bgp_route_match_add (vty
, vty
->index
, "metric", argv
[0]);
2392 DEFUN (no_match_metric
,
2393 no_match_metric_cmd
,
2397 "Match metric of route\n")
2400 return bgp_route_match_delete (vty
, vty
->index
, "metric", NULL
);
2402 return bgp_route_match_delete (vty
, vty
->index
, "metric", argv
[0]);
2405 ALIAS (no_match_metric
,
2406 no_match_metric_val_cmd
,
2407 "no match metric <0-4294967295>",
2410 "Match metric of route\n"
2413 DEFUN (match_community
,
2414 match_community_cmd
,
2415 "match community (<1-99>|<100-199>|WORD)",
2417 "Match BGP community list\n"
2418 "Community-list number (standard)\n"
2419 "Community-list number (expanded)\n"
2420 "Community-list name\n")
2422 return bgp_route_match_add (vty
, vty
->index
, "community", argv
[0]);
2425 DEFUN (match_community_exact
,
2426 match_community_exact_cmd
,
2427 "match community (<1-99>|<100-199>|WORD) exact-match",
2429 "Match BGP community list\n"
2430 "Community-list number (standard)\n"
2431 "Community-list number (expanded)\n"
2432 "Community-list name\n"
2433 "Do exact matching of communities\n")
2438 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
2439 strlen (argv
[0]) + strlen ("exact-match") + 2);
2441 sprintf (argstr
, "%s exact-match", argv
[0]);
2443 ret
= bgp_route_match_add (vty
, vty
->index
, "community", argstr
);
2445 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
2450 DEFUN (no_match_community
,
2451 no_match_community_cmd
,
2452 "no match community",
2455 "Match BGP community list\n")
2457 return bgp_route_match_delete (vty
, vty
->index
, "community", NULL
);
2460 ALIAS (no_match_community
,
2461 no_match_community_val_cmd
,
2462 "no match community (<1-99>|<100-199>|WORD)",
2465 "Match BGP community list\n"
2466 "Community-list number (standard)\n"
2467 "Community-list number (expanded)\n"
2468 "Community-list name\n")
2470 ALIAS (no_match_community
,
2471 no_match_community_exact_cmd
,
2472 "no match community (<1-99>|<100-199>|WORD) exact-match",
2475 "Match BGP community list\n"
2476 "Community-list number (standard)\n"
2477 "Community-list number (expanded)\n"
2478 "Community-list name\n"
2479 "Do exact matching of communities\n")
2481 DEFUN (match_ecommunity
,
2482 match_ecommunity_cmd
,
2483 "match extcommunity (<1-99>|<100-199>|WORD)",
2485 "Match BGP/VPN extended community list\n"
2486 "Extended community-list number (standard)\n"
2487 "Extended community-list number (expanded)\n"
2488 "Extended community-list name\n")
2490 return bgp_route_match_add (vty
, vty
->index
, "extcommunity", argv
[0]);
2493 DEFUN (no_match_ecommunity
,
2494 no_match_ecommunity_cmd
,
2495 "no match extcommunity",
2498 "Match BGP/VPN extended community list\n")
2500 return bgp_route_match_delete (vty
, vty
->index
, "extcommunity", NULL
);
2503 ALIAS (no_match_ecommunity
,
2504 no_match_ecommunity_val_cmd
,
2505 "no match extcommunity (<1-99>|<100-199>|WORD)",
2508 "Match BGP/VPN extended community list\n"
2509 "Extended community-list number (standard)\n"
2510 "Extended community-list number (expanded)\n"
2511 "Extended community-list name\n")
2513 DEFUN (match_aspath
,
2515 "match as-path WORD",
2517 "Match BGP AS path list\n"
2518 "AS path access-list name\n")
2520 return bgp_route_match_add (vty
, vty
->index
, "as-path", argv
[0]);
2523 DEFUN (no_match_aspath
,
2524 no_match_aspath_cmd
,
2528 "Match BGP AS path list\n")
2530 return bgp_route_match_delete (vty
, vty
->index
, "as-path", NULL
);
2533 ALIAS (no_match_aspath
,
2534 no_match_aspath_val_cmd
,
2535 "no match as-path WORD",
2538 "Match BGP AS path list\n"
2539 "AS path access-list name\n")
2541 DEFUN (match_origin
,
2543 "match origin (egp|igp|incomplete)",
2548 "unknown heritage\n")
2550 if (strncmp (argv
[0], "igp", 2) == 0)
2551 return bgp_route_match_add (vty
, vty
->index
, "origin", "igp");
2552 if (strncmp (argv
[0], "egp", 1) == 0)
2553 return bgp_route_match_add (vty
, vty
->index
, "origin", "egp");
2554 if (strncmp (argv
[0], "incomplete", 2) == 0)
2555 return bgp_route_match_add (vty
, vty
->index
, "origin", "incomplete");
2560 DEFUN (no_match_origin
,
2561 no_match_origin_cmd
,
2565 "BGP origin code\n")
2567 return bgp_route_match_delete (vty
, vty
->index
, "origin", NULL
);
2570 ALIAS (no_match_origin
,
2571 no_match_origin_val_cmd
,
2572 "no match origin (egp|igp|incomplete)",
2578 "unknown heritage\n")
2580 DEFUN (set_ip_nexthop
,
2582 "set ip next-hop A.B.C.D",
2585 "Next hop address\n"
2586 "IP address of next hop\n")
2591 ret
= str2sockunion (argv
[0], &su
);
2594 vty_out (vty
, "%% Malformed Next-hop address%s", VTY_NEWLINE
);
2598 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", argv
[0]);
2601 DEFUN (set_ip_nexthop_peer
,
2602 set_ip_nexthop_peer_cmd
,
2603 "set ip next-hop peer-address",
2606 "Next hop address\n"
2607 "Use peer address (for BGP only)\n")
2609 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", "peer-address");
2612 DEFUN (no_set_ip_nexthop_peer
,
2613 no_set_ip_nexthop_peer_cmd
,
2614 "no set ip next-hop peer-address",
2618 "Next hop address\n"
2619 "Use peer address (for BGP only)\n")
2621 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", NULL
);
2625 DEFUN (no_set_ip_nexthop
,
2626 no_set_ip_nexthop_cmd
,
2627 "no set ip next-hop",
2630 "Next hop address\n")
2633 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", NULL
);
2635 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", argv
[0]);
2638 ALIAS (no_set_ip_nexthop
,
2639 no_set_ip_nexthop_val_cmd
,
2640 "no set ip next-hop A.B.C.D",
2644 "Next hop address\n"
2645 "IP address of next hop\n")
2649 "set metric <0-4294967295>",
2651 "Metric value for destination routing protocol\n"
2654 return bgp_route_set_add (vty
, vty
->index
, "metric", argv
[0]);
2658 set_metric_addsub_cmd
,
2659 "set metric <+/-metric>",
2661 "Metric value for destination routing protocol\n"
2662 "Add or subtract BGP metric\n")
2664 DEFUN (no_set_metric
,
2669 "Metric value for destination routing protocol\n")
2672 return bgp_route_set_delete (vty
, vty
->index
, "metric", NULL
);
2674 return bgp_route_set_delete (vty
, vty
->index
, "metric", argv
[0]);
2677 ALIAS (no_set_metric
,
2678 no_set_metric_val_cmd
,
2679 "no set metric <0-4294967295>",
2682 "Metric value for destination routing protocol\n"
2685 DEFUN (set_local_pref
,
2687 "set local-preference <0-4294967295>",
2689 "BGP local preference path attribute\n"
2690 "Preference value\n")
2692 return bgp_route_set_add (vty
, vty
->index
, "local-preference", argv
[0]);
2695 DEFUN (no_set_local_pref
,
2696 no_set_local_pref_cmd
,
2697 "no set local-preference",
2700 "BGP local preference path attribute\n")
2703 return bgp_route_set_delete (vty
, vty
->index
, "local-preference", NULL
);
2705 return bgp_route_set_delete (vty
, vty
->index
, "local-preference", argv
[0]);
2708 ALIAS (no_set_local_pref
,
2709 no_set_local_pref_val_cmd
,
2710 "no set local-preference <0-4294967295>",
2713 "BGP local preference path attribute\n"
2714 "Preference value\n")
2718 "set weight <0-4294967295>",
2720 "BGP weight for routing table\n"
2723 return bgp_route_set_add (vty
, vty
->index
, "weight", argv
[0]);
2726 DEFUN (no_set_weight
,
2731 "BGP weight for routing table\n")
2734 return bgp_route_set_delete (vty
, vty
->index
, "weight", NULL
);
2736 return bgp_route_set_delete (vty
, vty
->index
, "weight", argv
[0]);
2739 ALIAS (no_set_weight
,
2740 no_set_weight_val_cmd
,
2741 "no set weight <0-4294967295>",
2744 "BGP weight for routing table\n"
2747 DEFUN (set_aspath_prepend
,
2748 set_aspath_prepend_cmd
,
2749 "set as-path prepend .<1-65535>",
2751 "Prepend string for a BGP AS-path attribute\n"
2752 "Prepend to the as-path\n"
2758 str
= argv_concat (argv
, argc
, 0);
2759 ret
= bgp_route_set_add (vty
, vty
->index
, "as-path prepend", str
);
2760 XFREE (MTYPE_TMP
, str
);
2765 DEFUN (no_set_aspath_prepend
,
2766 no_set_aspath_prepend_cmd
,
2767 "no set as-path prepend",
2770 "Prepend string for a BGP AS-path attribute\n"
2771 "Prepend to the as-path\n")
2773 return bgp_route_set_delete (vty
, vty
->index
, "as-path prepend", NULL
);
2776 ALIAS (no_set_aspath_prepend
,
2777 no_set_aspath_prepend_val_cmd
,
2778 "no set as-path prepend .<1-65535>",
2781 "Prepend string for a BGP AS-path attribute\n"
2782 "Prepend to the as-path\n"
2785 DEFUN (set_community
,
2787 "set community .AA:NN",
2789 "BGP community attribute\n"
2790 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
2796 struct community
*com
= NULL
;
2801 b
= buffer_new (1024);
2803 for (i
= 0; i
< argc
; i
++)
2805 if (strncmp (argv
[i
], "additive", strlen (argv
[i
])) == 0)
2812 buffer_putc (b
, ' ');
2816 if (strncmp (argv
[i
], "internet", strlen (argv
[i
])) == 0)
2818 buffer_putstr (b
, "internet");
2821 if (strncmp (argv
[i
], "local-AS", strlen (argv
[i
])) == 0)
2823 buffer_putstr (b
, "local-AS");
2826 if (strncmp (argv
[i
], "no-a", strlen ("no-a")) == 0
2827 && strncmp (argv
[i
], "no-advertise", strlen (argv
[i
])) == 0)
2829 buffer_putstr (b
, "no-advertise");
2832 if (strncmp (argv
[i
], "no-e", strlen ("no-e"))== 0
2833 && strncmp (argv
[i
], "no-export", strlen (argv
[i
])) == 0)
2835 buffer_putstr (b
, "no-export");
2838 buffer_putstr (b
, argv
[i
]);
2840 buffer_putc (b
, '\0');
2842 /* Fetch result string then compile it to communities attribute. */
2843 str
= buffer_getstr (b
);
2848 com
= community_str2com (str
);
2849 XFREE (MTYPE_TMP
, str
);
2852 /* Can't compile user input into communities attribute. */
2855 vty_out (vty
, "%% Malformed communities attribute%s", VTY_NEWLINE
);
2859 /* Set communites attribute string. */
2860 str
= community_str (com
);
2864 argstr
= XCALLOC (MTYPE_TMP
, strlen (str
) + strlen (" additive") + 1);
2865 strcpy (argstr
, str
);
2866 strcpy (argstr
+ strlen (str
), " additive");
2867 ret
= bgp_route_set_add (vty
, vty
->index
, "community", argstr
);
2868 XFREE (MTYPE_TMP
, argstr
);
2871 ret
= bgp_route_set_add (vty
, vty
->index
, "community", str
);
2873 community_free (com
);
2878 DEFUN (set_community_none
,
2879 set_community_none_cmd
,
2880 "set community none",
2882 "BGP community attribute\n"
2883 "No community attribute\n")
2885 return bgp_route_set_add (vty
, vty
->index
, "community", "none");
2888 DEFUN (no_set_community
,
2889 no_set_community_cmd
,
2893 "BGP community attribute\n")
2895 return bgp_route_set_delete (vty
, vty
->index
, "community", NULL
);
2898 ALIAS (no_set_community
,
2899 no_set_community_val_cmd
,
2900 "no set community .AA:NN",
2903 "BGP community attribute\n"
2904 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
2906 ALIAS (no_set_community
,
2907 no_set_community_none_cmd
,
2908 "no set community none",
2911 "BGP community attribute\n"
2912 "No community attribute\n")
2914 DEFUN (set_community_delete
,
2915 set_community_delete_cmd
,
2916 "set comm-list (<1-99>|<100-199>|WORD) delete",
2918 "set BGP community list (for deletion)\n"
2919 "Community-list number (standard)\n"
2920 "Communitly-list number (expanded)\n"
2921 "Community-list name\n"
2922 "Delete matching communities\n")
2926 str
= XCALLOC (MTYPE_TMP
, strlen (argv
[0]) + strlen (" delete") + 1);
2927 strcpy (str
, argv
[0]);
2928 strcpy (str
+ strlen (argv
[0]), " delete");
2930 bgp_route_set_add (vty
, vty
->index
, "comm-list", str
);
2932 XFREE (MTYPE_TMP
, str
);
2936 DEFUN (no_set_community_delete
,
2937 no_set_community_delete_cmd
,
2941 "set BGP community list (for deletion)\n")
2943 return bgp_route_set_delete (vty
, vty
->index
, "comm-list", NULL
);
2946 ALIAS (no_set_community_delete
,
2947 no_set_community_delete_val_cmd
,
2948 "no set comm-list (<1-99>|<100-199>|WORD) delete",
2951 "set BGP community list (for deletion)\n"
2952 "Community-list number (standard)\n"
2953 "Communitly-list number (expanded)\n"
2954 "Community-list name\n"
2955 "Delete matching communities\n")
2957 DEFUN (set_ecommunity_rt
,
2958 set_ecommunity_rt_cmd
,
2959 "set extcommunity rt .ASN:nn_or_IP-address:nn",
2961 "BGP extended community attribute\n"
2962 "Route Target extened communityt\n"
2963 "VPN extended community\n")
2968 str
= argv_concat (argv
, argc
, 0);
2969 ret
= bgp_route_set_add (vty
, vty
->index
, "extcommunity rt", str
);
2970 XFREE (MTYPE_TMP
, str
);
2975 DEFUN (no_set_ecommunity_rt
,
2976 no_set_ecommunity_rt_cmd
,
2977 "no set extcommunity rt",
2980 "BGP extended community attribute\n"
2981 "Route Target extened communityt\n")
2983 return bgp_route_set_delete (vty
, vty
->index
, "extcommunity rt", NULL
);
2986 ALIAS (no_set_ecommunity_rt
,
2987 no_set_ecommunity_rt_val_cmd
,
2988 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
2991 "BGP extended community attribute\n"
2992 "Route Target extened communityt\n"
2993 "VPN extended community\n")
2995 DEFUN (set_ecommunity_soo
,
2996 set_ecommunity_soo_cmd
,
2997 "set extcommunity soo .ASN:nn_or_IP-address:nn",
2999 "BGP extended community attribute\n"
3000 "Site-of-Origin extended community\n"
3001 "VPN extended community\n")
3006 str
= argv_concat (argv
, argc
, 0);
3007 ret
= bgp_route_set_add (vty
, vty
->index
, "extcommunity soo", str
);
3008 XFREE (MTYPE_TMP
, str
);
3012 DEFUN (no_set_ecommunity_soo
,
3013 no_set_ecommunity_soo_cmd
,
3014 "no set extcommunity soo",
3017 "BGP extended community attribute\n"
3018 "Site-of-Origin extended community\n")
3020 return bgp_route_set_delete (vty
, vty
->index
, "extcommunity soo", NULL
);
3023 ALIAS (no_set_ecommunity_soo
,
3024 no_set_ecommunity_soo_val_cmd
,
3025 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
3028 "BGP extended community attribute\n"
3029 "Site-of-Origin extended community\n"
3030 "VPN extended community\n")
3034 "set origin (egp|igp|incomplete)",
3039 "unknown heritage\n")
3041 if (strncmp (argv
[0], "igp", 2) == 0)
3042 return bgp_route_set_add (vty
, vty
->index
, "origin", "igp");
3043 if (strncmp (argv
[0], "egp", 1) == 0)
3044 return bgp_route_set_add (vty
, vty
->index
, "origin", "egp");
3045 if (strncmp (argv
[0], "incomplete", 2) == 0)
3046 return bgp_route_set_add (vty
, vty
->index
, "origin", "incomplete");
3051 DEFUN (no_set_origin
,
3056 "BGP origin code\n")
3058 return bgp_route_set_delete (vty
, vty
->index
, "origin", NULL
);
3061 ALIAS (no_set_origin
,
3062 no_set_origin_val_cmd
,
3063 "no set origin (egp|igp|incomplete)",
3069 "unknown heritage\n")
3071 DEFUN (set_atomic_aggregate
,
3072 set_atomic_aggregate_cmd
,
3073 "set atomic-aggregate",
3075 "BGP atomic aggregate attribute\n" )
3077 return bgp_route_set_add (vty
, vty
->index
, "atomic-aggregate", NULL
);
3080 DEFUN (no_set_atomic_aggregate
,
3081 no_set_atomic_aggregate_cmd
,
3082 "no set atomic-aggregate",
3085 "BGP atomic aggregate attribute\n" )
3087 return bgp_route_set_delete (vty
, vty
->index
, "atomic-aggregate", NULL
);
3090 DEFUN (set_aggregator_as
,
3091 set_aggregator_as_cmd
,
3092 "set aggregator as <1-65535> A.B.C.D",
3094 "BGP aggregator attribute\n"
3095 "AS number of aggregator\n"
3097 "IP address of aggregator\n")
3101 struct in_addr address
;
3104 VTY_GET_INTEGER_RANGE ("AS Path", as
, argv
[0], 1, BGP_AS_MAX
)
3106 ret
= inet_aton (argv
[1], &address
);
3109 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
3113 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3114 strlen (argv
[0]) + strlen (argv
[1]) + 2);
3116 sprintf (argstr
, "%s %s", argv
[0], argv
[1]);
3118 ret
= bgp_route_set_add (vty
, vty
->index
, "aggregator as", argstr
);
3120 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3125 DEFUN (no_set_aggregator_as
,
3126 no_set_aggregator_as_cmd
,
3127 "no set aggregator as",
3130 "BGP aggregator attribute\n"
3131 "AS number of aggregator\n")
3135 struct in_addr address
;
3139 return bgp_route_set_delete (vty
, vty
->index
, "aggregator as", NULL
);
3141 VTY_GET_INTEGER_RANGE ("AS Path", as
, argv
[0], 1, BGP_AS_MAX
)
3143 ret
= inet_aton (argv
[1], &address
);
3146 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
3150 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3151 strlen (argv
[0]) + strlen (argv
[1]) + 2);
3153 sprintf (argstr
, "%s %s", argv
[0], argv
[1]);
3155 ret
= bgp_route_set_delete (vty
, vty
->index
, "aggregator as", argstr
);
3157 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3162 ALIAS (no_set_aggregator_as
,
3163 no_set_aggregator_as_val_cmd
,
3164 "no set aggregator as <1-65535> A.B.C.D",
3167 "BGP aggregator attribute\n"
3168 "AS number of aggregator\n"
3170 "IP address of aggregator\n")
3174 DEFUN (match_ipv6_address
,
3175 match_ipv6_address_cmd
,
3176 "match ipv6 address WORD",
3179 "Match IPv6 address of route\n"
3180 "IPv6 access-list name\n")
3182 return bgp_route_match_add (vty
, vty
->index
, "ipv6 address", argv
[0]);
3185 DEFUN (no_match_ipv6_address
,
3186 no_match_ipv6_address_cmd
,
3187 "no match ipv6 address WORD",
3191 "Match IPv6 address of route\n"
3192 "IPv6 access-list name\n")
3194 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 address", argv
[0]);
3197 DEFUN (match_ipv6_next_hop
,
3198 match_ipv6_next_hop_cmd
,
3199 "match ipv6 next-hop X:X::X:X",
3202 "Match IPv6 next-hop address of route\n"
3203 "IPv6 address of next hop\n")
3205 return bgp_route_match_add (vty
, vty
->index
, "ipv6 next-hop", argv
[0]);
3208 DEFUN (no_match_ipv6_next_hop
,
3209 no_match_ipv6_next_hop_cmd
,
3210 "no match ipv6 next-hop X:X::X:X",
3214 "Match IPv6 next-hop address of route\n"
3215 "IPv6 address of next hop\n")
3217 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 next-hop", argv
[0]);
3220 DEFUN (match_ipv6_address_prefix_list
,
3221 match_ipv6_address_prefix_list_cmd
,
3222 "match ipv6 address prefix-list WORD",
3225 "Match address of route\n"
3226 "Match entries of prefix-lists\n"
3227 "IP prefix-list name\n")
3229 return bgp_route_match_add (vty
, vty
->index
, "ipv6 address prefix-list", argv
[0]);
3232 DEFUN (no_match_ipv6_address_prefix_list
,
3233 no_match_ipv6_address_prefix_list_cmd
,
3234 "no match ipv6 address prefix-list WORD",
3238 "Match address of route\n"
3239 "Match entries of prefix-lists\n"
3240 "IP prefix-list name\n")
3242 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 address prefix-list", argv
[0]);
3245 DEFUN (set_ipv6_nexthop_global
,
3246 set_ipv6_nexthop_global_cmd
,
3247 "set ipv6 next-hop global X:X::X:X",
3250 "IPv6 next-hop address\n"
3251 "IPv6 global address\n"
3252 "IPv6 address of next hop\n")
3254 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop global", argv
[0]);
3257 DEFUN (no_set_ipv6_nexthop_global
,
3258 no_set_ipv6_nexthop_global_cmd
,
3259 "no set ipv6 next-hop global",
3263 "IPv6 next-hop address\n"
3264 "IPv6 global address\n")
3267 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop global", NULL
);
3269 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop global", argv
[0]);
3272 ALIAS (no_set_ipv6_nexthop_global
,
3273 no_set_ipv6_nexthop_global_val_cmd
,
3274 "no set ipv6 next-hop global X:X::X:X",
3278 "IPv6 next-hop address\n"
3279 "IPv6 global address\n"
3280 "IPv6 address of next hop\n")
3282 DEFUN (set_ipv6_nexthop_local
,
3283 set_ipv6_nexthop_local_cmd
,
3284 "set ipv6 next-hop local X:X::X:X",
3287 "IPv6 next-hop address\n"
3288 "IPv6 local address\n"
3289 "IPv6 address of next hop\n")
3291 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop local", argv
[0]);
3294 DEFUN (no_set_ipv6_nexthop_local
,
3295 no_set_ipv6_nexthop_local_cmd
,
3296 "no set ipv6 next-hop local",
3300 "IPv6 next-hop address\n"
3301 "IPv6 local address\n")
3304 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop local", NULL
);
3306 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop local", argv
[0]);
3309 ALIAS (no_set_ipv6_nexthop_local
,
3310 no_set_ipv6_nexthop_local_val_cmd
,
3311 "no set ipv6 next-hop local X:X::X:X",
3315 "IPv6 next-hop address\n"
3316 "IPv6 local address\n"
3317 "IPv6 address of next hop\n")
3318 #endif /* HAVE_IPV6 */
3320 DEFUN (set_vpnv4_nexthop
,
3321 set_vpnv4_nexthop_cmd
,
3322 "set vpnv4 next-hop A.B.C.D",
3324 "VPNv4 information\n"
3325 "VPNv4 next-hop address\n"
3326 "IP address of next hop\n")
3328 return bgp_route_set_add (vty
, vty
->index
, "vpnv4 next-hop", argv
[0]);
3331 DEFUN (no_set_vpnv4_nexthop
,
3332 no_set_vpnv4_nexthop_cmd
,
3333 "no set vpnv4 next-hop",
3336 "VPNv4 information\n"
3337 "VPNv4 next-hop address\n")
3340 return bgp_route_set_delete (vty
, vty
->index
, "vpnv4 next-hop", NULL
);
3342 return bgp_route_set_delete (vty
, vty
->index
, "vpnv4 next-hop", argv
[0]);
3345 ALIAS (no_set_vpnv4_nexthop
,
3346 no_set_vpnv4_nexthop_val_cmd
,
3347 "no set vpnv4 next-hop A.B.C.D",
3350 "VPNv4 information\n"
3351 "VPNv4 next-hop address\n"
3352 "IP address of next hop\n")
3354 DEFUN (set_originator_id
,
3355 set_originator_id_cmd
,
3356 "set originator-id A.B.C.D",
3358 "BGP originator ID attribute\n"
3359 "IP address of originator\n")
3361 return bgp_route_set_add (vty
, vty
->index
, "originator-id", argv
[0]);
3364 DEFUN (no_set_originator_id
,
3365 no_set_originator_id_cmd
,
3366 "no set originator-id",
3369 "BGP originator ID attribute\n")
3372 return bgp_route_set_delete (vty
, vty
->index
, "originator-id", NULL
);
3374 return bgp_route_set_delete (vty
, vty
->index
, "originator-id", argv
[0]);
3377 ALIAS (no_set_originator_id
,
3378 no_set_originator_id_val_cmd
,
3379 "no set originator-id A.B.C.D",
3382 "BGP originator ID attribute\n"
3383 "IP address of originator\n")
3386 /* Initialization of route map. */
3388 bgp_route_map_init ()
3391 route_map_init_vty ();
3392 route_map_add_hook (bgp_route_map_update
);
3393 route_map_delete_hook (bgp_route_map_update
);
3395 route_map_install_match (&route_match_peer_cmd
);
3396 route_map_install_match (&route_match_ip_address_cmd
);
3397 route_map_install_match (&route_match_ip_next_hop_cmd
);
3398 route_map_install_match (&route_match_ip_address_prefix_list_cmd
);
3399 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd
);
3400 route_map_install_match (&route_match_aspath_cmd
);
3401 route_map_install_match (&route_match_community_cmd
);
3402 route_map_install_match (&route_match_ecommunity_cmd
);
3403 route_map_install_match (&route_match_metric_cmd
);
3404 route_map_install_match (&route_match_origin_cmd
);
3406 route_map_install_set (&route_set_ip_nexthop_cmd
);
3407 route_map_install_set (&route_set_local_pref_cmd
);
3408 route_map_install_set (&route_set_weight_cmd
);
3409 route_map_install_set (&route_set_metric_cmd
);
3410 route_map_install_set (&route_set_aspath_prepend_cmd
);
3411 route_map_install_set (&route_set_origin_cmd
);
3412 route_map_install_set (&route_set_atomic_aggregate_cmd
);
3413 route_map_install_set (&route_set_aggregator_as_cmd
);
3414 route_map_install_set (&route_set_community_cmd
);
3415 route_map_install_set (&route_set_community_delete_cmd
);
3416 route_map_install_set (&route_set_vpnv4_nexthop_cmd
);
3417 route_map_install_set (&route_set_originator_id_cmd
);
3418 route_map_install_set (&route_set_ecommunity_rt_cmd
);
3419 route_map_install_set (&route_set_ecommunity_soo_cmd
);
3421 install_element (RMAP_NODE
, &match_peer_cmd
);
3422 install_element (RMAP_NODE
, &match_peer_local_cmd
);
3423 install_element (RMAP_NODE
, &no_match_peer_cmd
);
3424 install_element (RMAP_NODE
, &no_match_peer_val_cmd
);
3425 install_element (RMAP_NODE
, &no_match_peer_local_cmd
);
3426 install_element (RMAP_NODE
, &match_ip_address_cmd
);
3427 install_element (RMAP_NODE
, &no_match_ip_address_cmd
);
3428 install_element (RMAP_NODE
, &no_match_ip_address_val_cmd
);
3429 install_element (RMAP_NODE
, &match_ip_next_hop_cmd
);
3430 install_element (RMAP_NODE
, &no_match_ip_next_hop_cmd
);
3431 install_element (RMAP_NODE
, &no_match_ip_next_hop_val_cmd
);
3433 install_element (RMAP_NODE
, &match_ip_address_prefix_list_cmd
);
3434 install_element (RMAP_NODE
, &no_match_ip_address_prefix_list_cmd
);
3435 install_element (RMAP_NODE
, &no_match_ip_address_prefix_list_val_cmd
);
3436 install_element (RMAP_NODE
, &match_ip_next_hop_prefix_list_cmd
);
3437 install_element (RMAP_NODE
, &no_match_ip_next_hop_prefix_list_cmd
);
3438 install_element (RMAP_NODE
, &no_match_ip_next_hop_prefix_list_val_cmd
);
3440 install_element (RMAP_NODE
, &match_aspath_cmd
);
3441 install_element (RMAP_NODE
, &no_match_aspath_cmd
);
3442 install_element (RMAP_NODE
, &no_match_aspath_val_cmd
);
3443 install_element (RMAP_NODE
, &match_metric_cmd
);
3444 install_element (RMAP_NODE
, &no_match_metric_cmd
);
3445 install_element (RMAP_NODE
, &no_match_metric_val_cmd
);
3446 install_element (RMAP_NODE
, &match_community_cmd
);
3447 install_element (RMAP_NODE
, &match_community_exact_cmd
);
3448 install_element (RMAP_NODE
, &no_match_community_cmd
);
3449 install_element (RMAP_NODE
, &no_match_community_val_cmd
);
3450 install_element (RMAP_NODE
, &no_match_community_exact_cmd
);
3451 install_element (RMAP_NODE
, &match_ecommunity_cmd
);
3452 install_element (RMAP_NODE
, &no_match_ecommunity_cmd
);
3453 install_element (RMAP_NODE
, &no_match_ecommunity_val_cmd
);
3454 install_element (RMAP_NODE
, &match_origin_cmd
);
3455 install_element (RMAP_NODE
, &no_match_origin_cmd
);
3456 install_element (RMAP_NODE
, &no_match_origin_val_cmd
);
3458 install_element (RMAP_NODE
, &set_ip_nexthop_cmd
);
3459 install_element (RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
3460 install_element (RMAP_NODE
, &no_set_ip_nexthop_cmd
);
3461 install_element (RMAP_NODE
, &no_set_ip_nexthop_val_cmd
);
3462 install_element (RMAP_NODE
, &set_local_pref_cmd
);
3463 install_element (RMAP_NODE
, &no_set_local_pref_cmd
);
3464 install_element (RMAP_NODE
, &no_set_local_pref_val_cmd
);
3465 install_element (RMAP_NODE
, &set_weight_cmd
);
3466 install_element (RMAP_NODE
, &no_set_weight_cmd
);
3467 install_element (RMAP_NODE
, &no_set_weight_val_cmd
);
3468 install_element (RMAP_NODE
, &set_metric_cmd
);
3469 install_element (RMAP_NODE
, &set_metric_addsub_cmd
);
3470 install_element (RMAP_NODE
, &no_set_metric_cmd
);
3471 install_element (RMAP_NODE
, &no_set_metric_val_cmd
);
3472 install_element (RMAP_NODE
, &set_aspath_prepend_cmd
);
3473 install_element (RMAP_NODE
, &no_set_aspath_prepend_cmd
);
3474 install_element (RMAP_NODE
, &no_set_aspath_prepend_val_cmd
);
3475 install_element (RMAP_NODE
, &set_origin_cmd
);
3476 install_element (RMAP_NODE
, &no_set_origin_cmd
);
3477 install_element (RMAP_NODE
, &no_set_origin_val_cmd
);
3478 install_element (RMAP_NODE
, &set_atomic_aggregate_cmd
);
3479 install_element (RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
3480 install_element (RMAP_NODE
, &set_aggregator_as_cmd
);
3481 install_element (RMAP_NODE
, &no_set_aggregator_as_cmd
);
3482 install_element (RMAP_NODE
, &no_set_aggregator_as_val_cmd
);
3483 install_element (RMAP_NODE
, &set_community_cmd
);
3484 install_element (RMAP_NODE
, &set_community_none_cmd
);
3485 install_element (RMAP_NODE
, &no_set_community_cmd
);
3486 install_element (RMAP_NODE
, &no_set_community_val_cmd
);
3487 install_element (RMAP_NODE
, &no_set_community_none_cmd
);
3488 install_element (RMAP_NODE
, &set_community_delete_cmd
);
3489 install_element (RMAP_NODE
, &no_set_community_delete_cmd
);
3490 install_element (RMAP_NODE
, &no_set_community_delete_val_cmd
);
3491 install_element (RMAP_NODE
, &set_ecommunity_rt_cmd
);
3492 install_element (RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
3493 install_element (RMAP_NODE
, &no_set_ecommunity_rt_val_cmd
);
3494 install_element (RMAP_NODE
, &set_ecommunity_soo_cmd
);
3495 install_element (RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
3496 install_element (RMAP_NODE
, &no_set_ecommunity_soo_val_cmd
);
3497 install_element (RMAP_NODE
, &set_vpnv4_nexthop_cmd
);
3498 install_element (RMAP_NODE
, &no_set_vpnv4_nexthop_cmd
);
3499 install_element (RMAP_NODE
, &no_set_vpnv4_nexthop_val_cmd
);
3500 install_element (RMAP_NODE
, &set_originator_id_cmd
);
3501 install_element (RMAP_NODE
, &no_set_originator_id_cmd
);
3502 install_element (RMAP_NODE
, &no_set_originator_id_val_cmd
);
3505 route_map_install_match (&route_match_ipv6_address_cmd
);
3506 route_map_install_match (&route_match_ipv6_next_hop_cmd
);
3507 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd
);
3508 route_map_install_set (&route_set_ipv6_nexthop_global_cmd
);
3509 route_map_install_set (&route_set_ipv6_nexthop_local_cmd
);
3511 install_element (RMAP_NODE
, &match_ipv6_address_cmd
);
3512 install_element (RMAP_NODE
, &no_match_ipv6_address_cmd
);
3513 install_element (RMAP_NODE
, &match_ipv6_next_hop_cmd
);
3514 install_element (RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
3515 install_element (RMAP_NODE
, &match_ipv6_address_prefix_list_cmd
);
3516 install_element (RMAP_NODE
, &no_match_ipv6_address_prefix_list_cmd
);
3517 install_element (RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
3518 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
3519 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_val_cmd
);
3520 install_element (RMAP_NODE
, &set_ipv6_nexthop_local_cmd
);
3521 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_local_cmd
);
3522 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_local_val_cmd
);
3523 #endif /* HAVE_IPV6 */