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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #ifdef HAVE_LIBPCREPOSIX
32 # include <pcreposix.h>
35 #endif /* HAVE_LIBPCREPOSIX */
37 #include "sockunion.h"
41 #include "bgpd/bgpd.h"
42 #include "bgpd/bgp_table.h"
43 #include "bgpd/bgp_attr.h"
44 #include "bgpd/bgp_aspath.h"
45 #include "bgpd/bgp_packet.h"
46 #include "bgpd/bgp_route.h"
47 #include "bgpd/bgp_zebra.h"
48 #include "bgpd/bgp_regex.h"
49 #include "bgpd/bgp_community.h"
50 #include "bgpd/bgp_clist.h"
51 #include "bgpd/bgp_filter.h"
52 #include "bgpd/bgp_mplsvpn.h"
53 #include "bgpd/bgp_ecommunity.h"
54 #include "bgpd/bgp_lcommunity.h"
55 #include "bgpd/bgp_vty.h"
56 #include "bgpd/bgp_debug.h"
59 # include "bgpd/rfapi/bgp_rfapi_cfg.h"
62 /* Memo of route-map commands.
71 ip route-source : Done
75 ipv6 route-source: (This will not be implemented by bgpd)
76 ipv6 prefix-list : Done
77 length : (This will not be implemented by bgpd)
79 route-type : (This will not be implemented by bgpd)
81 local-preference : Done
83 set as-path prepend : Done
85 automatic-tag : (This will not be implemented by bgpd)
87 large-community : Done
88 large-comm-list : Done
91 default : (This will not be implemented by bgpd)
92 interface : (This will not be implemented by bgpd)
93 ip default : (This will not be implemented by bgpd)
95 ip precedence : (This will not be implemented by bgpd)
96 ip tos : (This will not be implemented by bgpd)
97 level : (This will not be implemented by bgpd)
98 local-preference : Done
100 metric-type : Not yet
107 set ipv6 next-hop global: Done
108 set ipv6 next-hop prefer-global: Done
109 set ipv6 next-hop local : Done
110 set as-path exclude : Done
114 /* generic value manipulation to be shared in multiple rules */
116 #define RMAP_VALUE_SET 0
117 #define RMAP_VALUE_ADD 1
118 #define RMAP_VALUE_SUB 2
128 route_value_match (struct rmap_value
*rv
, u_int32_t value
)
130 if (rv
->variable
== 0 && value
== rv
->value
)
137 route_value_adjust (struct rmap_value
*rv
, u_int32_t current
, struct peer
*peer
)
141 switch (rv
->variable
)
154 if (current
> UINT32_MAX
-value
)
156 return current
+ value
;
158 if (current
<= value
)
160 return current
- value
;
167 route_value_compile (const char *arg
)
169 u_int8_t action
= RMAP_VALUE_SET
, var
= 0;
170 unsigned long larg
= 0;
172 struct rmap_value
*rv
;
176 action
= RMAP_VALUE_ADD
;
179 else if (arg
[0] == '-')
181 action
= RMAP_VALUE_SUB
;
188 larg
= strtoul (arg
, &endptr
, 10);
189 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
194 if (strcmp(arg
, "rtt") == 0)
200 rv
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
211 route_value_free (void *rule
)
213 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
216 /* generic as path object to be shared in multiple rules */
219 route_aspath_compile (const char *arg
)
221 struct aspath
*aspath
;
223 aspath
= aspath_str2aspath (arg
);
230 route_aspath_free (void *rule
)
232 struct aspath
*aspath
= rule
;
233 aspath_free (aspath
);
236 /* 'match peer (A.B.C.D|X:X::X:X)' */
238 /* Compares the peer specified in the 'match peer' clause with the peer
239 received in bgp_info->peer. If it is the same, or if the peer structure
240 received is a peer_group containing it, returns RMAP_MATCH. */
241 static route_map_result_t
242 route_match_peer (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
246 union sockunion su_def
= { .sin
= { .sin_family
= AF_INET
,
247 .sin_addr
.s_addr
= INADDR_ANY
} };
248 struct peer_group
*group
;
250 struct listnode
*node
, *nnode
;
252 if (type
== RMAP_BGP
)
255 peer
= ((struct bgp_info
*) object
)->peer
;
257 if ( ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
) &&
258 ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_EXPORT
) )
261 /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
262 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
263 if (sockunion_same (su
, &su_def
))
266 if ( CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
) ||
267 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
) ||
268 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
275 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
277 if (sockunion_same (su
, &peer
->su
))
285 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
287 if (sockunion_same (su
, &peer
->su
))
297 route_match_peer_compile (const char *arg
)
302 su
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (union sockunion
));
304 ret
= str2sockunion (strcmp(arg
, "local") ? arg
: "0.0.0.0", su
);
306 XFREE (MTYPE_ROUTE_MAP_COMPILED
, su
);
313 /* Free route map's compiled `ip address' value. */
315 route_match_peer_free (void *rule
)
317 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
320 /* Route map commands for ip address matching. */
321 struct route_map_rule_cmd route_match_peer_cmd
=
325 route_match_peer_compile
,
326 route_match_peer_free
329 /* `match ip address IP_ACCESS_LIST' */
331 /* Match function should return 1 if match is success else return
333 static route_map_result_t
334 route_match_ip_address (void *rule
, struct prefix
*prefix
,
335 route_map_object_t type
, void *object
)
337 struct access_list
*alist
;
338 /* struct prefix_ipv4 match; */
340 if (type
== RMAP_BGP
)
342 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
346 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
347 RMAP_NOMATCH
: RMAP_MATCH
);
352 /* Route map `ip address' match statement. `arg' should be
355 route_match_ip_address_compile (const char *arg
)
357 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
360 /* Free route map's compiled `ip address' value. */
362 route_match_ip_address_free (void *rule
)
364 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
367 /* Route map commands for ip address matching. */
368 struct route_map_rule_cmd route_match_ip_address_cmd
=
371 route_match_ip_address
,
372 route_match_ip_address_compile
,
373 route_match_ip_address_free
376 /* `match ip next-hop IP_ADDRESS' */
378 /* Match function return 1 if match is success else return zero. */
379 static route_map_result_t
380 route_match_ip_next_hop (void *rule
, struct prefix
*prefix
,
381 route_map_object_t type
, void *object
)
383 struct access_list
*alist
;
384 struct bgp_info
*bgp_info
;
385 struct prefix_ipv4 p
;
387 if (type
== RMAP_BGP
)
391 p
.prefix
= bgp_info
->attr
->nexthop
;
392 p
.prefixlen
= IPV4_MAX_BITLEN
;
394 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
398 return (access_list_apply (alist
, &p
) == FILTER_DENY
?
399 RMAP_NOMATCH
: RMAP_MATCH
);
404 /* Route map `ip next-hop' match statement. `arg' is
407 route_match_ip_next_hop_compile (const char *arg
)
409 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
412 /* Free route map's compiled `ip address' value. */
414 route_match_ip_next_hop_free (void *rule
)
416 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
419 /* Route map commands for ip next-hop matching. */
420 struct route_map_rule_cmd route_match_ip_next_hop_cmd
=
423 route_match_ip_next_hop
,
424 route_match_ip_next_hop_compile
,
425 route_match_ip_next_hop_free
428 /* `match ip route-source ACCESS-LIST' */
430 /* Match function return 1 if match is success else return zero. */
431 static route_map_result_t
432 route_match_ip_route_source (void *rule
, struct prefix
*prefix
,
433 route_map_object_t type
, void *object
)
435 struct access_list
*alist
;
436 struct bgp_info
*bgp_info
;
438 struct prefix_ipv4 p
;
440 if (type
== RMAP_BGP
)
443 peer
= bgp_info
->peer
;
445 if (! peer
|| sockunion_family (&peer
->su
) != AF_INET
)
449 p
.prefix
= peer
->su
.sin
.sin_addr
;
450 p
.prefixlen
= IPV4_MAX_BITLEN
;
452 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
456 return (access_list_apply (alist
, &p
) == FILTER_DENY
?
457 RMAP_NOMATCH
: RMAP_MATCH
);
462 /* Route map `ip route-source' match statement. `arg' is
465 route_match_ip_route_source_compile (const char *arg
)
467 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
470 /* Free route map's compiled `ip address' value. */
472 route_match_ip_route_source_free (void *rule
)
474 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
477 /* Route map commands for ip route-source matching. */
478 struct route_map_rule_cmd route_match_ip_route_source_cmd
=
481 route_match_ip_route_source
,
482 route_match_ip_route_source_compile
,
483 route_match_ip_route_source_free
486 /* `match ip address prefix-list PREFIX_LIST' */
488 static route_map_result_t
489 route_match_ip_address_prefix_list (void *rule
, struct prefix
*prefix
,
490 route_map_object_t type
, void *object
)
492 struct prefix_list
*plist
;
494 if (type
== RMAP_BGP
)
496 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
500 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
501 RMAP_NOMATCH
: RMAP_MATCH
);
507 route_match_ip_address_prefix_list_compile (const char *arg
)
509 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
513 route_match_ip_address_prefix_list_free (void *rule
)
515 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
518 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
=
520 "ip address prefix-list",
521 route_match_ip_address_prefix_list
,
522 route_match_ip_address_prefix_list_compile
,
523 route_match_ip_address_prefix_list_free
526 /* `match ip next-hop prefix-list PREFIX_LIST' */
528 static route_map_result_t
529 route_match_ip_next_hop_prefix_list (void *rule
, struct prefix
*prefix
,
530 route_map_object_t type
, void *object
)
532 struct prefix_list
*plist
;
533 struct bgp_info
*bgp_info
;
534 struct prefix_ipv4 p
;
536 if (type
== RMAP_BGP
)
540 p
.prefix
= bgp_info
->attr
->nexthop
;
541 p
.prefixlen
= IPV4_MAX_BITLEN
;
543 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
547 return (prefix_list_apply (plist
, &p
) == PREFIX_DENY
?
548 RMAP_NOMATCH
: RMAP_MATCH
);
554 route_match_ip_next_hop_prefix_list_compile (const char *arg
)
556 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
560 route_match_ip_next_hop_prefix_list_free (void *rule
)
562 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
565 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
=
567 "ip next-hop prefix-list",
568 route_match_ip_next_hop_prefix_list
,
569 route_match_ip_next_hop_prefix_list_compile
,
570 route_match_ip_next_hop_prefix_list_free
573 /* `match ip route-source prefix-list PREFIX_LIST' */
575 static route_map_result_t
576 route_match_ip_route_source_prefix_list (void *rule
, struct prefix
*prefix
,
577 route_map_object_t type
, void *object
)
579 struct prefix_list
*plist
;
580 struct bgp_info
*bgp_info
;
582 struct prefix_ipv4 p
;
584 if (type
== RMAP_BGP
)
587 peer
= bgp_info
->peer
;
589 if (! peer
|| sockunion_family (&peer
->su
) != AF_INET
)
593 p
.prefix
= peer
->su
.sin
.sin_addr
;
594 p
.prefixlen
= IPV4_MAX_BITLEN
;
596 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
600 return (prefix_list_apply (plist
, &p
) == PREFIX_DENY
?
601 RMAP_NOMATCH
: RMAP_MATCH
);
607 route_match_ip_route_source_prefix_list_compile (const char *arg
)
609 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
613 route_match_ip_route_source_prefix_list_free (void *rule
)
615 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
618 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
=
620 "ip route-source prefix-list",
621 route_match_ip_route_source_prefix_list
,
622 route_match_ip_route_source_prefix_list_compile
,
623 route_match_ip_route_source_prefix_list_free
626 /* `match local-preference LOCAL-PREF' */
628 /* Match function return 1 if match is success else return zero. */
629 static route_map_result_t
630 route_match_local_pref (void *rule
, struct prefix
*prefix
,
631 route_map_object_t type
, void *object
)
633 u_int32_t
*local_pref
;
634 struct bgp_info
*bgp_info
;
636 if (type
== RMAP_BGP
)
641 if (bgp_info
->attr
->local_pref
== *local_pref
)
649 /* Route map `match local-preference' match statement.
650 `arg' is local-pref value */
652 route_match_local_pref_compile (const char *arg
)
654 u_int32_t
*local_pref
;
656 unsigned long tmpval
;
658 /* Locpref value shoud be integer. */
659 if (! all_digit (arg
))
663 tmpval
= strtoul (arg
, &endptr
, 10);
664 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
667 local_pref
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
672 *local_pref
= tmpval
;
676 /* Free route map's compiled `match local-preference' value. */
678 route_match_local_pref_free (void *rule
)
680 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
683 /* Route map commands for metric matching. */
684 struct route_map_rule_cmd route_match_local_pref_cmd
=
687 route_match_local_pref
,
688 route_match_local_pref_compile
,
689 route_match_local_pref_free
692 /* `match metric METRIC' */
694 /* Match function return 1 if match is success else return zero. */
695 static route_map_result_t
696 route_match_metric (void *rule
, struct prefix
*prefix
,
697 route_map_object_t type
, void *object
)
699 struct rmap_value
*rv
;
700 struct bgp_info
*bgp_info
;
702 if (type
== RMAP_BGP
)
706 return route_value_match(rv
, bgp_info
->attr
->med
);
711 /* Route map commands for metric matching. */
712 struct route_map_rule_cmd route_match_metric_cmd
=
720 /* `match as-path ASPATH' */
722 /* Match function for as-path match. I assume given object is */
723 static route_map_result_t
724 route_match_aspath (void *rule
, struct prefix
*prefix
,
725 route_map_object_t type
, void *object
)
728 struct as_list
*as_list
;
729 struct bgp_info
*bgp_info
;
731 if (type
== RMAP_BGP
)
733 as_list
= as_list_lookup ((char *) rule
);
740 return ((as_list_apply (as_list
, bgp_info
->attr
->aspath
) == AS_FILTER_DENY
) ? RMAP_NOMATCH
: RMAP_MATCH
);
745 /* Compile function for as-path match. */
747 route_match_aspath_compile (const char *arg
)
749 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
752 /* Compile function for as-path match. */
754 route_match_aspath_free (void *rule
)
756 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
759 /* Route map commands for aspath matching. */
760 struct route_map_rule_cmd route_match_aspath_cmd
=
764 route_match_aspath_compile
,
765 route_match_aspath_free
768 /* `match community COMMUNIY' */
769 struct rmap_community
775 /* Match function for community match. */
776 static route_map_result_t
777 route_match_community (void *rule
, struct prefix
*prefix
,
778 route_map_object_t type
, void *object
)
780 struct community_list
*list
;
781 struct bgp_info
*bgp_info
;
782 struct rmap_community
*rcom
;
784 if (type
== RMAP_BGP
)
789 list
= community_list_lookup (bgp_clist
, rcom
->name
, COMMUNITY_LIST_MASTER
);
795 if (community_list_exact_match (bgp_info
->attr
->community
, list
))
800 if (community_list_match (bgp_info
->attr
->community
, list
))
807 /* Compile function for community match. */
809 route_match_community_compile (const char *arg
)
811 struct rmap_community
*rcom
;
815 rcom
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_community
));
817 p
= strchr (arg
, ' ');
821 rcom
->name
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
822 memcpy (rcom
->name
, arg
, len
);
827 rcom
->name
= XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
833 /* Compile function for community match. */
835 route_match_community_free (void *rule
)
837 struct rmap_community
*rcom
= rule
;
839 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
840 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
);
843 /* Route map commands for community matching. */
844 struct route_map_rule_cmd route_match_community_cmd
=
847 route_match_community
,
848 route_match_community_compile
,
849 route_match_community_free
852 /* Match function for lcommunity match. */
853 static route_map_result_t
854 route_match_lcommunity (void *rule
, struct prefix
*prefix
,
855 route_map_object_t type
, void *object
)
857 struct community_list
*list
;
858 struct bgp_info
*bgp_info
;
859 struct rmap_community
*rcom
;
861 if (type
== RMAP_BGP
)
866 list
= community_list_lookup (bgp_clist
, rcom
->name
,
867 LARGE_COMMUNITY_LIST_MASTER
);
871 if (bgp_info
->attr
->extra
&&
872 lcommunity_list_match (bgp_info
->attr
->extra
->lcommunity
, list
))
879 /* Compile function for community match. */
881 route_match_lcommunity_compile (const char *arg
)
883 struct rmap_community
*rcom
;
887 rcom
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_community
));
889 p
= strchr (arg
, ' ');
893 rcom
->name
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
894 memcpy (rcom
->name
, arg
, len
);
898 rcom
->name
= XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
904 /* Compile function for community match. */
906 route_match_lcommunity_free (void *rule
)
908 struct rmap_community
*rcom
= rule
;
910 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
911 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
);
914 /* Route map commands for community matching. */
915 struct route_map_rule_cmd route_match_lcommunity_cmd
=
918 route_match_lcommunity
,
919 route_match_lcommunity_compile
,
920 route_match_lcommunity_free
924 /* Match function for extcommunity match. */
925 static route_map_result_t
926 route_match_ecommunity (void *rule
, struct prefix
*prefix
,
927 route_map_object_t type
, void *object
)
929 struct community_list
*list
;
930 struct bgp_info
*bgp_info
;
932 if (type
== RMAP_BGP
)
936 if (!bgp_info
->attr
->extra
)
939 list
= community_list_lookup (bgp_clist
, (char *) rule
,
940 EXTCOMMUNITY_LIST_MASTER
);
944 if (ecommunity_list_match (bgp_info
->attr
->extra
->ecommunity
, list
))
950 /* Compile function for extcommunity match. */
952 route_match_ecommunity_compile (const char *arg
)
954 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
957 /* Compile function for extcommunity match. */
959 route_match_ecommunity_free (void *rule
)
961 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
964 /* Route map commands for community matching. */
965 struct route_map_rule_cmd route_match_ecommunity_cmd
=
968 route_match_ecommunity
,
969 route_match_ecommunity_compile
,
970 route_match_ecommunity_free
973 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
974 and `address-family vpnv4'. */
977 static route_map_result_t
978 route_match_origin (void *rule
, struct prefix
*prefix
,
979 route_map_object_t type
, void *object
)
982 struct bgp_info
*bgp_info
;
984 if (type
== RMAP_BGP
)
989 if (bgp_info
->attr
->origin
== *origin
)
997 route_match_origin_compile (const char *arg
)
1001 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
1003 if (strcmp (arg
, "igp") == 0)
1005 else if (strcmp (arg
, "egp") == 0)
1013 /* Free route map's compiled `ip address' value. */
1015 route_match_origin_free (void *rule
)
1017 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1020 /* Route map commands for origin matching. */
1021 struct route_map_rule_cmd route_match_origin_cmd
=
1025 route_match_origin_compile
,
1026 route_match_origin_free
1029 /* match probability { */
1031 static route_map_result_t
1032 route_match_probability (void *rule
, struct prefix
*prefix
,
1033 route_map_object_t type
, void *object
)
1037 switch (*(long *) rule
)
1040 case RAND_MAX
: return RMAP_MATCH
;
1042 if (r
< *(long *) rule
)
1048 return RMAP_NOMATCH
;
1052 route_match_probability_compile (const char *arg
)
1058 lobule
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (long));
1062 case 0: *lobule
= 0; break;
1063 case 100: *lobule
= RAND_MAX
; break;
1064 default: *lobule
= RAND_MAX
/ 100 * perc
;
1071 route_match_probability_free (void *rule
)
1073 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1076 struct route_map_rule_cmd route_match_probability_cmd
=
1079 route_match_probability
,
1080 route_match_probability_compile
,
1081 route_match_probability_free
1084 /* `match interface IFNAME' */
1085 /* Match function should return 1 if match is success else return
1087 static route_map_result_t
1088 route_match_interface (void *rule
, struct prefix
*prefix
,
1089 route_map_object_t type
, void *object
)
1091 struct interface
*ifp
;
1092 struct bgp_info
*info
;
1094 if (type
== RMAP_BGP
)
1098 if (!info
|| !info
->attr
)
1099 return RMAP_NOMATCH
;
1101 ifp
= if_lookup_by_name_all_vrf ((char *)rule
);
1103 if (ifp
== NULL
|| ifp
->ifindex
!= info
->attr
->nh_ifindex
)
1104 return RMAP_NOMATCH
;
1108 return RMAP_NOMATCH
;
1111 /* Route map `interface' match statement. `arg' should be
1114 route_match_interface_compile (const char *arg
)
1116 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1119 /* Free route map's compiled `interface' value. */
1121 route_match_interface_free (void *rule
)
1123 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1126 /* Route map commands for ip address matching. */
1127 struct route_map_rule_cmd route_match_interface_cmd
=
1130 route_match_interface
,
1131 route_match_interface_compile
,
1132 route_match_interface_free
1137 /* `set ip next-hop IP_ADDRESS' */
1139 /* Match function return 1 if match is success else return zero. */
1140 static route_map_result_t
1141 route_match_tag (void *rule
, struct prefix
*prefix
,
1142 route_map_object_t type
, void *object
)
1145 struct bgp_info
*bgp_info
;
1147 if (type
== RMAP_BGP
)
1152 if (!bgp_info
->attr
->extra
)
1153 return RMAP_NOMATCH
;
1155 return ((bgp_info
->attr
->extra
->tag
== *tag
)? RMAP_MATCH
: RMAP_NOMATCH
);
1158 return RMAP_NOMATCH
;
1162 /* Route map commands for tag matching. */
1163 static struct route_map_rule_cmd route_match_tag_cmd
=
1167 route_map_rule_tag_compile
,
1168 route_map_rule_tag_free
,
1172 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1173 struct rmap_ip_nexthop_set
1175 struct in_addr
*address
;
1180 static route_map_result_t
1181 route_set_ip_nexthop (void *rule
, struct prefix
*prefix
,
1182 route_map_object_t type
, void *object
)
1184 struct rmap_ip_nexthop_set
*rins
= rule
;
1185 struct bgp_info
*bgp_info
;
1188 if (type
== RMAP_BGP
)
1191 peer
= bgp_info
->peer
;
1193 if (rins
->unchanged
)
1195 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1196 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1198 else if (rins
->peer_address
)
1200 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
1201 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1203 && sockunion_family (peer
->su_remote
) == AF_INET
)
1205 bgp_info
->attr
->nexthop
.s_addr
= sockunion2ip (peer
->su_remote
);
1206 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
1208 else if (CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
))
1210 /* The next hop value will be set as part of packet rewrite.
1211 * Set the flags here to indicate that rewrite needs to be done.
1212 * Also, clear the value.
1214 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1215 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1216 bgp_info
->attr
->nexthop
.s_addr
= 0;
1221 /* Set next hop value. */
1222 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
1223 bgp_info
->attr
->nexthop
= *rins
->address
;
1224 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1225 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1232 /* Route map `ip nexthop' compile function. Given string is converted
1233 to struct in_addr structure. */
1235 route_set_ip_nexthop_compile (const char *arg
)
1237 struct rmap_ip_nexthop_set
*rins
;
1238 struct in_addr
*address
= NULL
;
1239 int peer_address
= 0;
1243 if (strcmp (arg
, "peer-address") == 0)
1245 else if (strcmp (arg
, "unchanged") == 0)
1249 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
1250 ret
= inet_aton (arg
, address
);
1254 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1259 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_ip_nexthop_set
));
1261 rins
->address
= address
;
1262 rins
->peer_address
= peer_address
;
1263 rins
->unchanged
= unchanged
;
1268 /* Free route map's compiled `ip nexthop' value. */
1270 route_set_ip_nexthop_free (void *rule
)
1272 struct rmap_ip_nexthop_set
*rins
= rule
;
1275 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1277 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
);
1280 /* Route map commands for ip nexthop set. */
1281 struct route_map_rule_cmd route_set_ip_nexthop_cmd
=
1284 route_set_ip_nexthop
,
1285 route_set_ip_nexthop_compile
,
1286 route_set_ip_nexthop_free
1289 /* `set local-preference LOCAL_PREF' */
1291 /* Set local preference. */
1292 static route_map_result_t
1293 route_set_local_pref (void *rule
, struct prefix
*prefix
,
1294 route_map_object_t type
, void *object
)
1296 struct rmap_value
*rv
;
1297 struct bgp_info
*bgp_info
;
1298 u_int32_t locpref
= 0;
1300 if (type
== RMAP_BGP
)
1302 /* Fetch routemap's rule information. */
1306 /* Set local preference value. */
1307 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
1308 locpref
= bgp_info
->attr
->local_pref
;
1310 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
);
1311 bgp_info
->attr
->local_pref
= route_value_adjust(rv
, locpref
, bgp_info
->peer
);
1317 /* Set local preference rule structure. */
1318 struct route_map_rule_cmd route_set_local_pref_cmd
=
1321 route_set_local_pref
,
1322 route_value_compile
,
1326 /* `set weight WEIGHT' */
1329 static route_map_result_t
1330 route_set_weight (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
1333 struct rmap_value
*rv
;
1334 struct bgp_info
*bgp_info
;
1337 if (type
== RMAP_BGP
)
1339 /* Fetch routemap's rule information. */
1343 /* Set weight value. */
1344 weight
= route_value_adjust(rv
, 0, bgp_info
->peer
);
1346 (bgp_attr_extra_get (bgp_info
->attr
))->weight
= weight
;
1347 else if (bgp_info
->attr
->extra
)
1348 bgp_info
->attr
->extra
->weight
= 0;
1354 /* Set local preference rule structure. */
1355 struct route_map_rule_cmd route_set_weight_cmd
=
1359 route_value_compile
,
1363 /* `set metric METRIC' */
1365 /* Set metric to attribute. */
1366 static route_map_result_t
1367 route_set_metric (void *rule
, struct prefix
*prefix
,
1368 route_map_object_t type
, void *object
)
1370 struct rmap_value
*rv
;
1371 struct bgp_info
*bgp_info
;
1374 if (type
== RMAP_BGP
)
1376 /* Fetch routemap's rule information. */
1380 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
))
1381 med
= bgp_info
->attr
->med
;
1383 bgp_info
->attr
->med
= route_value_adjust(rv
, med
, bgp_info
->peer
);
1384 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
);
1389 /* Set metric rule structure. */
1390 struct route_map_rule_cmd route_set_metric_cmd
=
1394 route_value_compile
,
1398 /* `set as-path prepend ASPATH' */
1400 /* For AS path prepend mechanism. */
1401 static route_map_result_t
1402 route_set_aspath_prepend (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1404 struct aspath
*aspath
;
1406 struct bgp_info
*binfo
;
1408 if (type
== RMAP_BGP
)
1412 if (binfo
->attr
->aspath
->refcnt
)
1413 new = aspath_dup (binfo
->attr
->aspath
);
1415 new = binfo
->attr
->aspath
;
1417 if ((uintptr_t)rule
> 10)
1420 aspath_prepend (aspath
, new);
1424 as_t as
= aspath_leftmost(new);
1425 if (!as
) as
= binfo
->peer
->as
;
1426 new = aspath_add_seq_n (new, as
, (uintptr_t) rule
);
1429 binfo
->attr
->aspath
= new;
1436 route_set_aspath_prepend_compile (const char *arg
)
1440 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
<= 10)
1441 return (void*)(uintptr_t)num
;
1443 return route_aspath_compile(arg
);
1447 route_set_aspath_prepend_free (void *rule
)
1449 if ((uintptr_t)rule
> 10)
1450 route_aspath_free(rule
);
1454 /* Set as-path prepend rule structure. */
1455 struct route_map_rule_cmd route_set_aspath_prepend_cmd
=
1458 route_set_aspath_prepend
,
1459 route_set_aspath_prepend_compile
,
1460 route_set_aspath_prepend_free
,
1463 /* `set as-path exclude ASn' */
1465 /* For ASN exclude mechanism.
1466 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1467 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1469 static route_map_result_t
1470 route_set_aspath_exclude (void *rule
, struct prefix
*dummy
, route_map_object_t type
, void *object
)
1472 struct aspath
* new_path
, * exclude_path
;
1473 struct bgp_info
*binfo
;
1475 if (type
== RMAP_BGP
)
1477 exclude_path
= rule
;
1479 if (binfo
->attr
->aspath
->refcnt
)
1480 new_path
= aspath_dup (binfo
->attr
->aspath
);
1482 new_path
= binfo
->attr
->aspath
;
1483 binfo
->attr
->aspath
= aspath_filter_exclude (new_path
, exclude_path
);
1488 /* Set ASn exlude rule structure. */
1489 struct route_map_rule_cmd route_set_aspath_exclude_cmd
=
1492 route_set_aspath_exclude
,
1493 route_aspath_compile
,
1497 /* `set community COMMUNITY' */
1500 struct community
*com
;
1505 /* For community set mechanism. */
1506 static route_map_result_t
1507 route_set_community (void *rule
, struct prefix
*prefix
,
1508 route_map_object_t type
, void *object
)
1510 struct rmap_com_set
*rcs
;
1511 struct bgp_info
*binfo
;
1513 struct community
*new = NULL
;
1514 struct community
*old
;
1515 struct community
*merge
;
1517 if (type
== RMAP_BGP
)
1522 old
= attr
->community
;
1527 attr
->flag
&= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
));
1528 attr
->community
= NULL
;
1529 /* See the longer comment down below. */
1530 if (old
&& old
->refcnt
== 0)
1531 community_free(old
);
1535 /* "additive" case. */
1536 if (rcs
->additive
&& old
)
1538 merge
= community_merge (community_dup (old
), rcs
->com
);
1540 /* HACK: if the old community is not intern'd,
1541 * we should free it here, or all reference to it may be lost.
1542 * Really need to cleanup attribute caching sometime.
1544 if (old
->refcnt
== 0)
1545 community_free (old
);
1546 new = community_uniq_sort (merge
);
1547 community_free (merge
);
1550 new = community_dup (rcs
->com
);
1552 /* will be interned by caller if required */
1553 attr
->community
= new;
1555 attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1561 /* Compile function for set community. */
1563 route_set_community_compile (const char *arg
)
1565 struct rmap_com_set
*rcs
;
1566 struct community
*com
= NULL
;
1571 if (strcmp (arg
, "none") == 0)
1575 sp
= strstr (arg
, "additive");
1579 /* "additive" keyworkd is included. */
1584 com
= community_str2com (arg
);
1593 rcs
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_com_set
));
1595 rcs
->additive
= additive
;
1601 /* Free function for set community. */
1603 route_set_community_free (void *rule
)
1605 struct rmap_com_set
*rcs
= rule
;
1608 community_free (rcs
->com
);
1609 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1612 /* Set community rule structure. */
1613 struct route_map_rule_cmd route_set_community_cmd
=
1616 route_set_community
,
1617 route_set_community_compile
,
1618 route_set_community_free
,
1621 /* `set community COMMUNITY' */
1622 struct rmap_lcom_set
1624 struct lcommunity
*lcom
;
1630 /* For lcommunity set mechanism. */
1631 static route_map_result_t
1632 route_set_lcommunity (void *rule
, struct prefix
*prefix
,
1633 route_map_object_t type
, void *object
)
1635 struct rmap_lcom_set
*rcs
;
1636 struct bgp_info
*binfo
;
1638 struct lcommunity
*new = NULL
;
1639 struct lcommunity
*old
;
1640 struct lcommunity
*merge
;
1642 if (type
== RMAP_BGP
)
1647 old
= (attr
->extra
) ? attr
->extra
->lcommunity
: NULL
;
1652 attr
->flag
&= ~(ATTR_FLAG_BIT (BGP_ATTR_LARGE_COMMUNITIES
));
1654 attr
->extra
->lcommunity
= NULL
;
1656 /* See the longer comment down below. */
1657 if (old
&& old
->refcnt
== 0)
1658 lcommunity_free(&old
);
1662 if (rcs
->additive
&& old
)
1664 merge
= lcommunity_merge (lcommunity_dup (old
), rcs
->lcom
);
1666 /* HACK: if the old large-community is not intern'd,
1667 * we should free it here, or all reference to it may be lost.
1668 * Really need to cleanup attribute caching sometime.
1670 if (old
->refcnt
== 0)
1671 lcommunity_free (&old
);
1672 new = lcommunity_uniq_sort (merge
);
1673 lcommunity_free (&merge
);
1676 new = lcommunity_dup (rcs
->lcom
);
1678 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1679 (bgp_attr_extra_get (attr
))->lcommunity
= new;
1681 attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_LARGE_COMMUNITIES
);
1687 /* Compile function for set community. */
1689 route_set_lcommunity_compile (const char *arg
)
1691 struct rmap_lcom_set
*rcs
;
1692 struct lcommunity
*lcom
= NULL
;
1697 if (strcmp (arg
, "none") == 0)
1701 sp
= strstr (arg
, "additive");
1705 /* "additive" keyworkd is included. */
1710 lcom
= lcommunity_str2com (arg
);
1719 rcs
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_com_set
));
1721 rcs
->additive
= additive
;
1727 /* Free function for set lcommunity. */
1729 route_set_lcommunity_free (void *rule
)
1731 struct rmap_lcom_set
*rcs
= rule
;
1734 lcommunity_free (&rcs
->lcom
);
1736 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1739 /* Set community rule structure. */
1740 struct route_map_rule_cmd route_set_lcommunity_cmd
=
1743 route_set_lcommunity
,
1744 route_set_lcommunity_compile
,
1745 route_set_lcommunity_free
,
1748 /* `set large-comm-list (<1-99>|<100-500>|WORD) delete' */
1750 /* For large community set mechanism. */
1751 static route_map_result_t
1752 route_set_lcommunity_delete (void *rule
, struct prefix
*prefix
,
1753 route_map_object_t type
, void *object
)
1755 struct community_list
*list
;
1756 struct lcommunity
*merge
;
1757 struct lcommunity
*new;
1758 struct lcommunity
*old
;
1759 struct bgp_info
*binfo
;
1761 if (type
== RMAP_BGP
)
1767 list
= community_list_lookup (bgp_clist
, rule
,
1768 LARGE_COMMUNITY_LIST_MASTER
);
1769 old
= ((binfo
->attr
->extra
) ? binfo
->attr
->extra
->lcommunity
: NULL
);
1773 merge
= lcommunity_list_match_delete (lcommunity_dup (old
), list
);
1774 new = lcommunity_uniq_sort (merge
);
1775 lcommunity_free (&merge
);
1777 /* HACK: if the old community is not intern'd,
1778 * we should free it here, or all reference to it may be lost.
1779 * Really need to cleanup attribute caching sometime.
1781 if (old
->refcnt
== 0)
1782 lcommunity_free (&old
);
1786 binfo
->attr
->extra
->lcommunity
= NULL
;
1787 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT (BGP_ATTR_LARGE_COMMUNITIES
);
1788 lcommunity_free (&new);
1792 binfo
->attr
->extra
->lcommunity
= new;
1793 binfo
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_LARGE_COMMUNITIES
);
1801 /* Compile function for set lcommunity. */
1803 route_set_lcommunity_delete_compile (const char *arg
)
1809 p
= strchr (arg
, ' ');
1813 str
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1814 memcpy (str
, arg
, len
);
1822 /* Free function for set lcommunity. */
1824 route_set_lcommunity_delete_free (void *rule
)
1826 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1829 /* Set lcommunity rule structure. */
1830 struct route_map_rule_cmd route_set_lcommunity_delete_cmd
=
1833 route_set_lcommunity_delete
,
1834 route_set_lcommunity_delete_compile
,
1835 route_set_lcommunity_delete_free
,
1839 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
1841 /* For community set mechanism. */
1842 static route_map_result_t
1843 route_set_community_delete (void *rule
, struct prefix
*prefix
,
1844 route_map_object_t type
, void *object
)
1846 struct community_list
*list
;
1847 struct community
*merge
;
1848 struct community
*new;
1849 struct community
*old
;
1850 struct bgp_info
*binfo
;
1852 if (type
== RMAP_BGP
)
1858 list
= community_list_lookup (bgp_clist
, rule
, COMMUNITY_LIST_MASTER
);
1859 old
= binfo
->attr
->community
;
1863 merge
= community_list_match_delete (community_dup (old
), list
);
1864 new = community_uniq_sort (merge
);
1865 community_free (merge
);
1867 /* HACK: if the old community is not intern'd,
1868 * we should free it here, or all reference to it may be lost.
1869 * Really need to cleanup attribute caching sometime.
1871 if (old
->refcnt
== 0)
1872 community_free (old
);
1876 binfo
->attr
->community
= NULL
;
1877 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1878 community_free (new);
1882 binfo
->attr
->community
= new;
1883 binfo
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1891 /* Compile function for set community. */
1893 route_set_community_delete_compile (const char *arg
)
1899 p
= strchr (arg
, ' ');
1903 str
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1904 memcpy (str
, arg
, len
);
1912 /* Free function for set community. */
1914 route_set_community_delete_free (void *rule
)
1916 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1919 /* Set community rule structure. */
1920 struct route_map_rule_cmd route_set_community_delete_cmd
=
1923 route_set_community_delete
,
1924 route_set_community_delete_compile
,
1925 route_set_community_delete_free
,
1928 /* `set extcommunity rt COMMUNITY' */
1930 /* For community set mechanism. Used by _rt and _soo. */
1931 static route_map_result_t
1932 route_set_ecommunity (void *rule
, struct prefix
*prefix
,
1933 route_map_object_t type
, void *object
)
1935 struct ecommunity
*ecom
;
1936 struct ecommunity
*new_ecom
;
1937 struct ecommunity
*old_ecom
;
1938 struct bgp_info
*bgp_info
;
1940 if (type
== RMAP_BGP
)
1948 /* We assume additive for Extended Community. */
1949 old_ecom
= (bgp_attr_extra_get (bgp_info
->attr
))->ecommunity
;
1953 new_ecom
= ecommunity_merge (ecommunity_dup (old_ecom
), ecom
);
1955 /* old_ecom->refcnt = 1 => owned elsewhere, e.g. bgp_update_receive()
1956 * ->refcnt = 0 => set by a previous route-map statement */
1957 if (!old_ecom
->refcnt
)
1958 ecommunity_free (&old_ecom
);
1961 new_ecom
= ecommunity_dup (ecom
);
1963 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1964 bgp_info
->attr
->extra
->ecommunity
= new_ecom
;
1966 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES
);
1971 /* Compile function for set community. */
1973 route_set_ecommunity_rt_compile (const char *arg
)
1975 struct ecommunity
*ecom
;
1977 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
1980 return ecommunity_intern (ecom
);
1983 /* Free function for set community. Used by _rt and _soo */
1985 route_set_ecommunity_free (void *rule
)
1987 struct ecommunity
*ecom
= rule
;
1988 ecommunity_unintern (&ecom
);
1991 /* Set community rule structure. */
1992 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
=
1995 route_set_ecommunity
,
1996 route_set_ecommunity_rt_compile
,
1997 route_set_ecommunity_free
,
2000 /* `set extcommunity soo COMMUNITY' */
2002 /* Compile function for set community. */
2004 route_set_ecommunity_soo_compile (const char *arg
)
2006 struct ecommunity
*ecom
;
2008 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
2012 return ecommunity_intern (ecom
);
2015 /* Set community rule structure. */
2016 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
=
2019 route_set_ecommunity
,
2020 route_set_ecommunity_soo_compile
,
2021 route_set_ecommunity_free
,
2024 /* `set origin ORIGIN' */
2026 /* For origin set. */
2027 static route_map_result_t
2028 route_set_origin (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
2031 struct bgp_info
*bgp_info
;
2033 if (type
== RMAP_BGP
)
2038 bgp_info
->attr
->origin
= *origin
;
2044 /* Compile function for origin set. */
2046 route_set_origin_compile (const char *arg
)
2050 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
2052 if (strcmp (arg
, "igp") == 0)
2054 else if (strcmp (arg
, "egp") == 0)
2062 /* Compile function for origin set. */
2064 route_set_origin_free (void *rule
)
2066 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2069 /* Set origin rule structure. */
2070 struct route_map_rule_cmd route_set_origin_cmd
=
2074 route_set_origin_compile
,
2075 route_set_origin_free
,
2078 /* `set atomic-aggregate' */
2080 /* For atomic aggregate set. */
2081 static route_map_result_t
2082 route_set_atomic_aggregate (void *rule
, struct prefix
*prefix
,
2083 route_map_object_t type
, void *object
)
2085 struct bgp_info
*bgp_info
;
2087 if (type
== RMAP_BGP
)
2090 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
);
2096 /* Compile function for atomic aggregate. */
2098 route_set_atomic_aggregate_compile (const char *arg
)
2103 /* Compile function for atomic aggregate. */
2105 route_set_atomic_aggregate_free (void *rule
)
2110 /* Set atomic aggregate rule structure. */
2111 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
=
2114 route_set_atomic_aggregate
,
2115 route_set_atomic_aggregate_compile
,
2116 route_set_atomic_aggregate_free
,
2119 /* `set aggregator as AS A.B.C.D' */
2123 struct in_addr address
;
2126 static route_map_result_t
2127 route_set_aggregator_as (void *rule
, struct prefix
*prefix
,
2128 route_map_object_t type
, void *object
)
2130 struct bgp_info
*bgp_info
;
2131 struct aggregator
*aggregator
;
2132 struct attr_extra
*ae
;
2134 if (type
== RMAP_BGP
)
2138 ae
= bgp_attr_extra_get (bgp_info
->attr
);
2140 ae
->aggregator_as
= aggregator
->as
;
2141 ae
->aggregator_addr
= aggregator
->address
;
2142 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR
);
2149 route_set_aggregator_as_compile (const char *arg
)
2151 struct aggregator
*aggregator
;
2156 aggregator
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct aggregator
));
2157 sscanf (arg
, "%s %s", as
, address
);
2159 aggregator
->as
= strtoul (as
, NULL
, 10);
2160 ret
= inet_aton (address
, &aggregator
->address
);
2163 XFREE (MTYPE_ROUTE_MAP_COMPILED
, aggregator
);
2170 route_set_aggregator_as_free (void *rule
)
2172 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2175 struct route_map_rule_cmd route_set_aggregator_as_cmd
=
2178 route_set_aggregator_as
,
2179 route_set_aggregator_as_compile
,
2180 route_set_aggregator_as_free
,
2183 /* Set tag to object. object must be pointer to struct bgp_info */
2184 static route_map_result_t
2185 route_set_tag (void *rule
, struct prefix
*prefix
,
2186 route_map_object_t type
, void *object
)
2189 struct bgp_info
*bgp_info
;
2190 struct attr_extra
*ae
;
2192 if (type
== RMAP_BGP
)
2196 ae
= bgp_attr_extra_get (bgp_info
->attr
);
2206 /* Route map commands for tag set. */
2207 static struct route_map_rule_cmd route_set_tag_cmd
=
2211 route_map_rule_tag_compile
,
2212 route_map_rule_tag_free
,
2215 /* Set label-index to object. object must be pointer to struct bgp_info */
2216 static route_map_result_t
2217 route_set_label_index (void *rule
, struct prefix
*prefix
,
2218 route_map_object_t type
, void *object
)
2220 struct rmap_value
*rv
;
2221 struct bgp_info
*bgp_info
;
2222 u_int32_t label_index
;
2224 if (type
== RMAP_BGP
)
2226 /* Fetch routemap's rule information. */
2230 /* Set label-index value. */
2231 label_index
= rv
->value
;
2234 (bgp_attr_extra_get (bgp_info
->attr
))->label_index
= label_index
;
2235 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_PREFIX_SID
);
2242 /* Route map commands for label-index set. */
2243 static struct route_map_rule_cmd route_set_label_index_cmd
=
2246 route_set_label_index
,
2247 route_value_compile
,
2251 /* `match ipv6 address IP_ACCESS_LIST' */
2253 static route_map_result_t
2254 route_match_ipv6_address (void *rule
, struct prefix
*prefix
,
2255 route_map_object_t type
, void *object
)
2257 struct access_list
*alist
;
2259 if (type
== RMAP_BGP
)
2261 alist
= access_list_lookup (AFI_IP6
, (char *) rule
);
2263 return RMAP_NOMATCH
;
2265 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
2266 RMAP_NOMATCH
: RMAP_MATCH
);
2268 return RMAP_NOMATCH
;
2272 route_match_ipv6_address_compile (const char *arg
)
2274 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
2278 route_match_ipv6_address_free (void *rule
)
2280 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2283 /* Route map commands for ip address matching. */
2284 struct route_map_rule_cmd route_match_ipv6_address_cmd
=
2287 route_match_ipv6_address
,
2288 route_match_ipv6_address_compile
,
2289 route_match_ipv6_address_free
2292 /* `match ipv6 next-hop IP_ADDRESS' */
2294 static route_map_result_t
2295 route_match_ipv6_next_hop (void *rule
, struct prefix
*prefix
,
2296 route_map_object_t type
, void *object
)
2298 struct in6_addr
*addr
= rule
;
2299 struct bgp_info
*bgp_info
;
2301 if (type
== RMAP_BGP
)
2305 if (!bgp_info
->attr
->extra
)
2306 return RMAP_NOMATCH
;
2308 if (IPV6_ADDR_SAME (&bgp_info
->attr
->extra
->mp_nexthop_global
, addr
))
2311 if (bgp_info
->attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
&&
2312 IPV6_ADDR_SAME (&bgp_info
->attr
->extra
->mp_nexthop_local
, rule
))
2315 return RMAP_NOMATCH
;
2318 return RMAP_NOMATCH
;
2322 route_match_ipv6_next_hop_compile (const char *arg
)
2324 struct in6_addr
*address
;
2327 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2329 ret
= inet_pton (AF_INET6
, arg
, address
);
2332 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2340 route_match_ipv6_next_hop_free (void *rule
)
2342 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2345 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
=
2348 route_match_ipv6_next_hop
,
2349 route_match_ipv6_next_hop_compile
,
2350 route_match_ipv6_next_hop_free
2353 /* `match ipv6 address prefix-list PREFIX_LIST' */
2355 static route_map_result_t
2356 route_match_ipv6_address_prefix_list (void *rule
, struct prefix
*prefix
,
2357 route_map_object_t type
, void *object
)
2359 struct prefix_list
*plist
;
2361 if (type
== RMAP_BGP
)
2363 plist
= prefix_list_lookup (AFI_IP6
, (char *) rule
);
2365 return RMAP_NOMATCH
;
2367 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
2368 RMAP_NOMATCH
: RMAP_MATCH
);
2370 return RMAP_NOMATCH
;
2374 route_match_ipv6_address_prefix_list_compile (const char *arg
)
2376 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
2380 route_match_ipv6_address_prefix_list_free (void *rule
)
2382 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2385 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
=
2387 "ipv6 address prefix-list",
2388 route_match_ipv6_address_prefix_list
,
2389 route_match_ipv6_address_prefix_list_compile
,
2390 route_match_ipv6_address_prefix_list_free
2393 /* `set ipv6 nexthop global IP_ADDRESS' */
2395 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2396 static route_map_result_t
2397 route_set_ipv6_nexthop_global (void *rule
, struct prefix
*prefix
,
2398 route_map_object_t type
, void *object
)
2400 struct in6_addr
*address
;
2401 struct bgp_info
*bgp_info
;
2403 if (type
== RMAP_BGP
)
2405 /* Fetch routemap's rule information. */
2409 /* Set next hop value. */
2410 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
= *address
;
2412 /* Set nexthop length. */
2413 if (bgp_info
->attr
->extra
->mp_nexthop_len
== 0)
2414 bgp_info
->attr
->extra
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2416 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2417 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2423 /* Route map `ip next-hop' compile function. Given string is converted
2424 to struct in_addr structure. */
2426 route_set_ipv6_nexthop_global_compile (const char *arg
)
2429 struct in6_addr
*address
;
2431 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2433 ret
= inet_pton (AF_INET6
, arg
, address
);
2437 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2444 /* Free route map's compiled `ip next-hop' value. */
2446 route_set_ipv6_nexthop_global_free (void *rule
)
2448 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2451 /* Route map commands for ip nexthop set. */
2452 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
=
2454 "ipv6 next-hop global",
2455 route_set_ipv6_nexthop_global
,
2456 route_set_ipv6_nexthop_global_compile
,
2457 route_set_ipv6_nexthop_global_free
2460 /* Set next-hop preference value. */
2461 static route_map_result_t
2462 route_set_ipv6_nexthop_prefer_global (void *rule
, struct prefix
*prefix
,
2463 route_map_object_t type
, void *object
)
2465 struct bgp_info
*bgp_info
;
2468 if (type
== RMAP_BGP
)
2470 /* Fetch routemap's rule information. */
2472 peer
= bgp_info
->peer
;
2474 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
2475 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2477 && sockunion_family (peer
->su_remote
) == AF_INET6
)
2479 /* Set next hop preference to global */
2480 bgp_info
->attr
->extra
->mp_nexthop_prefer_global
= TRUE
;
2481 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2482 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2486 bgp_info
->attr
->extra
->mp_nexthop_prefer_global
= FALSE
;
2487 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2488 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2495 route_set_ipv6_nexthop_prefer_global_compile (const char *arg
)
2499 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (int));
2505 /* Free route map's compiled `ip next-hop' value. */
2507 route_set_ipv6_nexthop_prefer_global_free (void *rule
)
2509 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2512 /* Route map commands for ip nexthop set preferred. */
2513 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
=
2515 "ipv6 next-hop prefer-global",
2516 route_set_ipv6_nexthop_prefer_global
,
2517 route_set_ipv6_nexthop_prefer_global_compile
,
2518 route_set_ipv6_nexthop_prefer_global_free
2521 /* `set ipv6 nexthop local IP_ADDRESS' */
2523 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2524 static route_map_result_t
2525 route_set_ipv6_nexthop_local (void *rule
, struct prefix
*prefix
,
2526 route_map_object_t type
, void *object
)
2528 struct in6_addr
*address
;
2529 struct bgp_info
*bgp_info
;
2531 if (type
== RMAP_BGP
)
2533 /* Fetch routemap's rule information. */
2537 /* Set next hop value. */
2538 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
= *address
;
2540 /* Set nexthop length. */
2541 if (bgp_info
->attr
->extra
->mp_nexthop_len
!= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2542 bgp_info
->attr
->extra
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2544 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2545 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2551 /* Route map `ip nexthop' compile function. Given string is converted
2552 to struct in_addr structure. */
2554 route_set_ipv6_nexthop_local_compile (const char *arg
)
2557 struct in6_addr
*address
;
2559 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2561 ret
= inet_pton (AF_INET6
, arg
, address
);
2565 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2572 /* Free route map's compiled `ip nexthop' value. */
2574 route_set_ipv6_nexthop_local_free (void *rule
)
2576 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2579 /* Route map commands for ip nexthop set. */
2580 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
=
2582 "ipv6 next-hop local",
2583 route_set_ipv6_nexthop_local
,
2584 route_set_ipv6_nexthop_local_compile
,
2585 route_set_ipv6_nexthop_local_free
2588 /* `set ipv6 nexthop peer-address' */
2590 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2591 static route_map_result_t
2592 route_set_ipv6_nexthop_peer (void *rule
, struct prefix
*prefix
,
2593 route_map_object_t type
, void *object
)
2595 struct in6_addr peer_address
;
2596 struct bgp_info
*bgp_info
;
2599 if (type
== RMAP_BGP
)
2601 /* Fetch routemap's rule information. */
2603 peer
= bgp_info
->peer
;
2605 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
2606 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2608 && sockunion_family (peer
->su_remote
) == AF_INET6
)
2610 peer_address
= peer
->su_remote
->sin6
.sin6_addr
;
2611 /* Set next hop value and length in attribute. */
2612 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
))
2614 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
= peer_address
;
2615 if (bgp_info
->attr
->extra
->mp_nexthop_len
!= 32)
2616 bgp_info
->attr
->extra
->mp_nexthop_len
= 32;
2620 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
= peer_address
;
2621 if (bgp_info
->attr
->extra
->mp_nexthop_len
== 0)
2622 bgp_info
->attr
->extra
->mp_nexthop_len
= 16;
2626 else if (CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
))
2628 /* The next hop value will be set as part of packet rewrite.
2629 * Set the flags here to indicate that rewrite needs to be done.
2630 * Also, clear the value - we clear both global and link-local
2631 * nexthops, whether we send one or both is determined elsewhere.
2633 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2634 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2635 /* clear next hop value. */
2636 memset (&((bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
),
2637 0, sizeof (struct in6_addr
));
2638 memset (&((bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
),
2639 0, sizeof (struct in6_addr
));
2646 /* Route map `ip next-hop' compile function. Given string is converted
2647 to struct in_addr structure. */
2649 route_set_ipv6_nexthop_peer_compile (const char *arg
)
2653 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (int));
2659 /* Free route map's compiled `ip next-hop' value. */
2661 route_set_ipv6_nexthop_peer_free (void *rule
)
2663 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2666 /* Route map commands for ip nexthop set. */
2667 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
=
2669 "ipv6 next-hop peer-address",
2670 route_set_ipv6_nexthop_peer
,
2671 route_set_ipv6_nexthop_peer_compile
,
2672 route_set_ipv6_nexthop_peer_free
2675 /* `set ip vpn nexthop A.B.C.D' */
2677 static route_map_result_t
2678 route_set_vpnv4_nexthop (void *rule
, struct prefix
*prefix
,
2679 route_map_object_t type
, void *object
)
2681 struct in_addr
*address
;
2682 struct bgp_info
*bgp_info
;
2684 if (type
== RMAP_BGP
)
2686 /* Fetch routemap's rule information. */
2690 /* Set next hop value. */
2691 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global_in
= *address
;
2692 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_len
= 4;
2699 route_set_vpnv4_nexthop_compile (const char *arg
)
2702 struct in_addr
*address
;
2704 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
2706 ret
= inet_aton (arg
, address
);
2710 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2717 /* `set ipv6 vpn nexthop A.B.C.D' */
2719 static route_map_result_t
2720 route_set_vpnv6_nexthop (void *rule
, struct prefix
*prefix
,
2721 route_map_object_t type
, void *object
)
2723 struct in6_addr
*address
;
2724 struct bgp_info
*bgp_info
;
2726 if (type
== RMAP_BGP
)
2728 /* Fetch routemap's rule information. */
2732 /* Set next hop value. */
2733 memcpy (&(bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
, address
, sizeof(struct in6_addr
));
2734 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_len
= BGP_ATTR_NHLEN_VPNV6_GLOBAL
;
2741 route_set_vpnv6_nexthop_compile (const char *arg
)
2744 struct in6_addr
*address
;
2746 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2747 ret
= inet_pton (AF_INET6
, arg
, address
);
2751 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2759 route_set_vpn_nexthop_free (void *rule
)
2761 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2764 /* Route map commands for ip nexthop set. */
2765 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
=
2768 route_set_vpnv4_nexthop
,
2769 route_set_vpnv4_nexthop_compile
,
2770 route_set_vpn_nexthop_free
2773 /* Route map commands for ip nexthop set. */
2774 struct route_map_rule_cmd route_set_vpnv6_nexthop_cmd
=
2776 "ipv6 vpn next-hop",
2777 route_set_vpnv6_nexthop
,
2778 route_set_vpnv6_nexthop_compile
,
2779 route_set_vpn_nexthop_free
2782 /* `set originator-id' */
2784 /* For origin set. */
2785 static route_map_result_t
2786 route_set_originator_id (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
2788 struct in_addr
*address
;
2789 struct bgp_info
*bgp_info
;
2791 if (type
== RMAP_BGP
)
2796 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
);
2797 (bgp_attr_extra_get (bgp_info
->attr
))->originator_id
= *address
;
2803 /* Compile function for originator-id set. */
2805 route_set_originator_id_compile (const char *arg
)
2808 struct in_addr
*address
;
2810 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
2812 ret
= inet_aton (arg
, address
);
2816 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2823 /* Compile function for originator_id set. */
2825 route_set_originator_id_free (void *rule
)
2827 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2830 /* Set originator-id rule structure. */
2831 struct route_map_rule_cmd route_set_originator_id_cmd
=
2834 route_set_originator_id
,
2835 route_set_originator_id_compile
,
2836 route_set_originator_id_free
,
2839 /* Add bgp route map rule. */
2841 bgp_route_match_add (struct vty
*vty
,
2842 const char *command
, const char *arg
,
2843 route_map_event_t type
)
2845 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2848 ret
= route_map_add_match (index
, command
, arg
);
2853 case RMAP_RULE_MISSING
:
2854 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2856 case RMAP_COMPILE_ERROR
:
2857 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2862 if (type
!= RMAP_EVENT_MATCH_ADDED
)
2864 route_map_upd8_dependency (type
, arg
, index
->map
->name
);
2870 /* Delete bgp route map rule. */
2872 bgp_route_match_delete (struct vty
*vty
,
2873 const char *command
, const char *arg
,
2874 route_map_event_t type
)
2876 VTY_DECLVAR_CONTEXT(route_map_index
, index
);
2878 char *dep_name
= NULL
;
2880 char *rmap_name
= NULL
;
2882 if (type
!= RMAP_EVENT_MATCH_DELETED
)
2884 /* ignore the mundane, the types without any dependency */
2887 if ((tmpstr
= route_map_get_match_arg(index
, command
)) != NULL
)
2888 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
2892 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
2894 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
2897 ret
= route_map_delete_match (index
, command
, dep_name
);
2902 case RMAP_RULE_MISSING
:
2903 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2905 case RMAP_COMPILE_ERROR
:
2906 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2910 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2912 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2916 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
2917 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
2920 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2922 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2928 * This is the workhorse routine for processing in/out routemap
2932 bgp_route_map_process_peer (const char *rmap_name
, struct route_map
*map
,
2933 struct peer
*peer
, int afi
, int safi
,
2938 struct bgp_filter
*filter
;
2940 if (!peer
|| !rmap_name
)
2943 filter
= &peer
->filter
[afi
][safi
];
2945 * in is for non-route-server clients,
2946 * out is for all peers
2948 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
))
2950 if (filter
->map
[RMAP_IN
].name
&&
2951 (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0))
2953 filter
->map
[RMAP_IN
].map
= map
;
2955 if (route_update
&& peer
->status
== Established
)
2957 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
],
2958 PEER_FLAG_SOFT_RECONFIG
))
2960 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2961 zlog_debug("Processing route_map %s update on "
2962 "peer %s (inbound, soft-reconfig)",
2963 rmap_name
, peer
->host
);
2965 bgp_soft_reconfig_in (peer
, afi
, safi
);
2967 else if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
2968 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
2971 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2972 zlog_debug("Processing route_map %s update on "
2973 "peer %s (inbound, route-refresh)",
2974 rmap_name
, peer
->host
);
2975 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
2981 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
))
2985 if (update
&& route_update
&& peer
->status
== Established
)
2987 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
],
2988 PEER_FLAG_SOFT_RECONFIG
))
2990 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2991 zlog_debug("Processing route_map %s update on "
2992 "peer %s (import, soft-reconfig)",
2993 rmap_name
, peer
->host
);
2995 bgp_soft_reconfig_in (peer
, afi
, safi
);
2997 else if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
2998 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
3000 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
3001 zlog_debug("Processing route_map %s update on "
3002 "peer %s (import, route-refresh)",
3003 rmap_name
, peer
->host
);
3004 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
3006 /* DD: Else, what else do we do ? Reset peer ? */
3011 * For outbound, unsuppress and default-originate map change (content or
3012 * map created), merely update the "config" here, the actual route
3013 * announcement happens at the group level.
3015 if (filter
->map
[RMAP_OUT
].name
&&
3016 (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
3017 filter
->map
[RMAP_OUT
].map
= map
;
3019 if (filter
->usmap
.name
&&
3020 (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3021 filter
->usmap
.map
= map
;
3023 if (peer
->default_rmap
[afi
][safi
].name
&&
3024 (strcmp (rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
3025 peer
->default_rmap
[afi
][safi
].map
= map
;
3029 bgp_route_map_update_peer_group(const char *rmap_name
, struct route_map
*map
,
3032 struct peer_group
*group
;
3033 struct listnode
*node
, *nnode
;
3034 struct bgp_filter
*filter
;
3041 /* All the peers have been updated correctly already. This is
3042 * just updating the placeholder data. No real update required.
3044 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
3045 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3046 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3048 filter
= &group
->conf
->filter
[afi
][safi
];
3050 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++)
3052 if ((filter
->map
[direct
].name
) &&
3053 (strcmp(rmap_name
, filter
->map
[direct
].name
) == 0))
3054 filter
->map
[direct
].map
= map
;
3057 if (filter
->usmap
.name
&&
3058 (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
3059 filter
->usmap
.map
= map
;
3064 * Note that if an extreme number (tens of thousands) of route-maps are in use
3065 * and if bgp has an extreme number of peers, network statements, etc then this
3066 * function can consume a lot of cycles. This is due to this function being
3067 * called for each route-map and within this function we walk the list of peers,
3068 * network statements, etc looking to see if they use this route-map.
3071 bgp_route_map_process_update (struct bgp
*bgp
, const char *rmap_name
, int route_update
)
3077 struct bgp_node
*bn
;
3078 struct bgp_static
*bgp_static
;
3079 struct listnode
*node
, *nnode
;
3080 struct route_map
*map
;
3081 char buf
[INET6_ADDRSTRLEN
];
3083 map
= route_map_lookup_by_name (rmap_name
);
3085 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
3088 /* Ignore dummy peer-group structure */
3089 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
3092 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3093 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3095 /* Ignore inactive AFI/SAFI */
3096 if (! peer
->afc
[afi
][safi
])
3099 /* process in/out/import/export/default-orig route-maps */
3100 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
, safi
, route_update
);
3104 /* for outbound/default-orig route-maps, process for groups */
3105 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
3108 /* update peer-group config (template) */
3109 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
3111 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3112 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
3114 /* For table route-map updates. */
3115 if (bgp
->table_map
[afi
][safi
].name
&&
3116 (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
) == 0))
3118 bgp
->table_map
[afi
][safi
].map
= map
;
3120 if (BGP_DEBUG (zebra
, ZEBRA
))
3121 zlog_debug("Processing route_map %s update on "
3122 "table map", rmap_name
);
3124 bgp_zebra_announce_table(bgp
, afi
, safi
);
3127 /* For network route-map updates. */
3128 for (bn
= bgp_table_top (bgp
->route
[afi
][safi
]); bn
; bn
= bgp_route_next (bn
))
3129 if ((bgp_static
= bn
->info
) != NULL
)
3131 if (bgp_static
->rmap
.name
&&
3132 (strcmp(rmap_name
, bgp_static
->rmap
.name
) == 0))
3134 bgp_static
->rmap
.map
= map
;
3137 if (!bgp_static
->backdoor
)
3139 if (bgp_debug_zebra(&bn
->p
))
3140 zlog_debug("Processing route_map %s update on "
3141 "static route %s", rmap_name
,
3142 inet_ntop (bn
->p
.family
, &bn
->p
.u
.prefix
,
3143 buf
, INET6_ADDRSTRLEN
));
3144 bgp_static_update (bgp
, &bn
->p
, bgp_static
, afi
, safi
);
3150 /* For redistribute route-map updates. */
3151 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
3152 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
3154 struct list
*red_list
;
3155 struct listnode
*node
;
3156 struct bgp_redist
*red
;
3158 red_list
= bgp
->redist
[afi
][i
];
3162 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
))
3164 if (red
->rmap
.name
&&
3165 (strcmp(rmap_name
, red
->rmap
.name
) == 0))
3167 red
->rmap
.map
= map
;
3171 if (BGP_DEBUG (zebra
, ZEBRA
))
3172 zlog_debug("Processing route_map %s update on "
3173 "redistributed routes", rmap_name
);
3175 bgp_redistribute_resend (bgp
, afi
, i
, red
->instance
);
3183 bgp_route_map_process_update_cb (char *rmap_name
)
3185 struct listnode
*node
, *nnode
;
3188 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
3189 bgp_route_map_process_update(bgp
, rmap_name
, 1);
3192 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3193 vnc_routemap_update(bgp
, __func__
);
3199 bgp_route_map_update_timer(struct thread
*thread
)
3201 bm
->t_rmap_update
= NULL
;
3203 route_map_walk_update_list(bgp_route_map_process_update_cb
);
3209 bgp_route_map_mark_update (const char *rmap_name
)
3211 if (bm
->t_rmap_update
== NULL
)
3213 struct listnode
*node
, *nnode
;
3216 /* rmap_update_timer of 0 means don't do route updates */
3217 if (bm
->rmap_update_timer
)
3219 bm
->t_rmap_update
= NULL
;
3220 thread_add_timer(bm
->master
, bgp_route_map_update_timer
, NULL
, bm
->rmap_update_timer
,
3221 &bm
->t_rmap_update
);
3223 /* Signal the groups that a route-map update event has started */
3224 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
3225 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
, 1, 1);
3229 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
3230 bgp_route_map_process_update(bgp
, rmap_name
, 0);
3232 zlog_debug("%s: calling vnc_routemap_update", __func__
);
3233 vnc_routemap_update(bgp
, __func__
);
3240 bgp_route_map_add (const char *rmap_name
)
3242 if (route_map_mark_updated(rmap_name
, 0) == 0)
3243 bgp_route_map_mark_update(rmap_name
);
3245 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3249 bgp_route_map_delete (const char *rmap_name
)
3251 if (route_map_mark_updated(rmap_name
, 1) == 0)
3252 bgp_route_map_mark_update(rmap_name
);
3254 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
3258 bgp_route_map_event (route_map_event_t event
, const char *rmap_name
)
3260 if (route_map_mark_updated(rmap_name
, 0) == 0)
3261 bgp_route_map_mark_update(rmap_name
);
3263 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3269 "match peer <A.B.C.D|X:X::X:X>",
3271 "Match peer address\n"
3272 "IP address of peer\n"
3273 "IPv6 address of peer\n")
3276 return bgp_route_match_add (vty
, "peer", argv
[idx_ip
]->arg
,
3277 RMAP_EVENT_MATCH_ADDED
);
3280 DEFUN (match_peer_local
,
3281 match_peer_local_cmd
,
3284 "Match peer address\n"
3285 "Static or Redistributed routes\n")
3287 return bgp_route_match_add (vty
, "peer", "local",
3288 RMAP_EVENT_MATCH_DELETED
);
3291 DEFUN (no_match_peer
,
3293 "no match peer [<local|A.B.C.D|X:X::X:X>]",
3296 "Match peer address\n"
3297 "Static or Redistributed routes\n"
3298 "IP address of peer\n"
3299 "IPv6 address of peer\n")
3303 if (argc
<= idx_peer
)
3304 return bgp_route_match_delete (vty
, "peer", NULL
,
3305 RMAP_EVENT_MATCH_DELETED
);
3306 return bgp_route_match_delete (vty
, "peer", argv
[idx_peer
]->arg
,
3307 RMAP_EVENT_MATCH_DELETED
);
3311 /* match probability */
3312 DEFUN (match_probability
,
3313 match_probability_cmd
,
3314 "match probability (0-100)",
3316 "Match portion of routes defined by percentage value\n"
3317 "Percentage of routes\n")
3320 return bgp_route_match_add (vty
, "probability", argv
[idx_number
]->arg
,
3321 RMAP_EVENT_MATCH_ADDED
);
3325 DEFUN (no_match_probability
,
3326 no_match_probability_cmd
,
3327 "no match probability [(1-99)]",
3330 "Match portion of routes defined by percentage value\n"
3331 "Percentage of routes\n")
3334 if (argc
<= idx_number
)
3335 return bgp_route_match_delete (vty
, "probability", NULL
,
3336 RMAP_EVENT_MATCH_DELETED
);
3337 return bgp_route_match_delete (vty
, "probability", argv
[idx_number
]->arg
,
3338 RMAP_EVENT_MATCH_DELETED
);
3342 DEFUN (match_ip_route_source
,
3343 match_ip_route_source_cmd
,
3344 "match ip route-source <(1-199)|(1300-2699)|WORD>",
3347 "Match advertising source address of route\n"
3348 "IP access-list number\n"
3349 "IP access-list number (expanded range)\n"
3350 "IP standard access-list name\n")
3353 return bgp_route_match_add (vty
, "ip route-source", argv
[idx_acl
]->arg
,
3354 RMAP_EVENT_FILTER_ADDED
);
3358 DEFUN (no_match_ip_route_source
,
3359 no_match_ip_route_source_cmd
,
3360 "no match ip route-source [<(1-199)|(1300-2699)|WORD>]",
3364 "Match advertising source address of route\n"
3365 "IP access-list number\n"
3366 "IP access-list number (expanded range)\n"
3367 "IP standard access-list name\n")
3370 if (argc
<= idx_number
)
3371 return bgp_route_match_delete (vty
, "ip route-source",
3372 NULL
, RMAP_EVENT_FILTER_DELETED
);
3373 return bgp_route_match_delete (vty
, "ip route-source",
3374 argv
[idx_number
]->arg
, RMAP_EVENT_FILTER_DELETED
);
3378 DEFUN (match_ip_route_source_prefix_list
,
3379 match_ip_route_source_prefix_list_cmd
,
3380 "match ip route-source prefix-list WORD",
3383 "Match advertising source address of route\n"
3384 "Match entries of prefix-lists\n"
3385 "IP prefix-list name\n")
3388 return bgp_route_match_add (vty
, "ip route-source prefix-list",
3389 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_ADDED
);
3393 DEFUN (no_match_ip_route_source_prefix_list
,
3394 no_match_ip_route_source_prefix_list_cmd
,
3395 "no match ip route-source prefix-list [WORD]",
3399 "Match advertising source address of route\n"
3400 "Match entries of prefix-lists\n"
3401 "IP prefix-list name\n")
3404 if (argc
<= idx_word
)
3405 return bgp_route_match_delete (vty
, "ip route-source prefix-list",
3406 NULL
, RMAP_EVENT_PLIST_DELETED
);
3407 return bgp_route_match_delete (vty
, "ip route-source prefix-list",
3408 argv
[idx_word
]->arg
, RMAP_EVENT_PLIST_DELETED
);
3412 DEFUN (match_local_pref
,
3413 match_local_pref_cmd
,
3414 "match local-preference (0-4294967295)",
3416 "Match local-preference of route\n"
3420 return bgp_route_match_add (vty
, "local-preference", argv
[idx_number
]->arg
,
3421 RMAP_EVENT_MATCH_ADDED
);
3425 DEFUN (no_match_local_pref
,
3426 no_match_local_pref_cmd
,
3427 "no match local-preference [(0-4294967295)]",
3430 "Match local preference of route\n"
3431 "Local preference value\n")
3433 int idx_localpref
= 3;
3434 if (argc
<= idx_localpref
)
3435 return bgp_route_match_delete (vty
, "local-preference",
3436 NULL
, RMAP_EVENT_MATCH_DELETED
);
3437 return bgp_route_match_delete (vty
, "local-preference",
3438 argv
[idx_localpref
]->arg
,
3439 RMAP_EVENT_MATCH_DELETED
);
3443 DEFUN (match_community
,
3444 match_community_cmd
,
3445 "match community <(1-99)|(100-500)|WORD> [exact-match]",
3447 "Match BGP community list\n"
3448 "Community-list number (standard)\n"
3449 "Community-list number (expanded)\n"
3450 "Community-list name\n"
3451 "Do exact matching of communities\n")
3453 int idx_comm_list
= 2;
3459 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3460 strlen (argv
[idx_comm_list
]->arg
) +
3461 strlen ("exact-match") + 2);
3463 sprintf (argstr
, "%s exact-match", argv
[idx_comm_list
]->arg
);
3466 argstr
= argv
[idx_comm_list
]->arg
;
3468 ret
= bgp_route_match_add (vty
, "community", argstr
,
3469 RMAP_EVENT_CLIST_ADDED
);
3471 if (argstr
!= argv
[idx_comm_list
]->arg
)
3472 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3477 DEFUN (no_match_community
,
3478 no_match_community_cmd
,
3479 "no match community [<(1-99)|(100-500)|WORD> [exact-match]]",
3482 "Match BGP community list\n"
3483 "Community-list number (standard)\n"
3484 "Community-list number (expanded)\n"
3485 "Community-list name\n"
3486 "Do exact matching of communities\n")
3488 return bgp_route_match_delete (vty
, "community", NULL
,
3489 RMAP_EVENT_CLIST_DELETED
);
3492 DEFUN (match_lcommunity
,
3493 match_lcommunity_cmd
,
3494 "match large-community <(1-99)|(100-500)|WORD>",
3496 "Match BGP large community list\n"
3497 "Large Community-list number (standard)\n"
3498 "Large Community-list number (expanded)\n"
3499 "Large Community-list name\n")
3501 return bgp_route_match_add (vty
, "large-community", argv
[2]->arg
,
3502 RMAP_EVENT_LLIST_ADDED
);
3505 DEFUN (no_match_lcommunity
,
3506 no_match_lcommunity_cmd
,
3507 "no match large-community [<(1-99)|(100-500)|WORD>]",
3510 "Match BGP large community list\n"
3511 "Large Community-list number (standard)\n"
3512 "Large Community-list number (expanded)\n"
3513 "Large Community-list name\n")
3515 return bgp_route_match_delete (vty
, "large-community", NULL
,
3516 RMAP_EVENT_LLIST_DELETED
);
3519 DEFUN (match_ecommunity
,
3520 match_ecommunity_cmd
,
3521 "match extcommunity <(1-99)|(100-500)|WORD>",
3523 "Match BGP/VPN extended community list\n"
3524 "Extended community-list number (standard)\n"
3525 "Extended community-list number (expanded)\n"
3526 "Extended community-list name\n")
3528 int idx_comm_list
= 2;
3529 return bgp_route_match_add (vty
, "extcommunity", argv
[idx_comm_list
]->arg
,
3530 RMAP_EVENT_ECLIST_ADDED
);
3534 DEFUN (no_match_ecommunity
,
3535 no_match_ecommunity_cmd
,
3536 "no match extcommunity [<(1-99)|(100-500)|WORD>]",
3539 "Match BGP/VPN extended community list\n"
3540 "Extended community-list number (standard)\n"
3541 "Extended community-list number (expanded)\n"
3542 "Extended community-list name\n")
3544 return bgp_route_match_delete (vty
, "extcommunity", NULL
,
3545 RMAP_EVENT_ECLIST_DELETED
);
3549 DEFUN (match_aspath
,
3551 "match as-path WORD",
3553 "Match BGP AS path list\n"
3554 "AS path access-list name\n")
3557 return bgp_route_match_add (vty
, "as-path", argv
[idx_word
]->arg
,
3558 RMAP_EVENT_ASLIST_ADDED
);
3562 DEFUN (no_match_aspath
,
3563 no_match_aspath_cmd
,
3564 "no match as-path [WORD]",
3567 "Match BGP AS path list\n"
3568 "AS path access-list name\n")
3570 return bgp_route_match_delete (vty
, "as-path", NULL
,
3571 RMAP_EVENT_ASLIST_DELETED
);
3575 DEFUN (match_origin
,
3577 "match origin <egp|igp|incomplete>",
3582 "unknown heritage\n")
3585 if (strncmp (argv
[idx_origin
]->arg
, "igp", 2) == 0)
3586 return bgp_route_match_add (vty
, "origin", "igp",
3587 RMAP_EVENT_MATCH_ADDED
);
3588 if (strncmp (argv
[idx_origin
]->arg
, "egp", 1) == 0)
3589 return bgp_route_match_add (vty
, "origin", "egp",
3590 RMAP_EVENT_MATCH_ADDED
);
3591 if (strncmp (argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
3592 return bgp_route_match_add (vty
, "origin", "incomplete",
3593 RMAP_EVENT_MATCH_ADDED
);
3599 DEFUN (no_match_origin
,
3600 no_match_origin_cmd
,
3601 "no match origin [<egp|igp|incomplete>]",
3607 "unknown heritage\n")
3609 return bgp_route_match_delete (vty
, "origin", NULL
,
3610 RMAP_EVENT_MATCH_DELETED
);
3613 DEFUN (set_ip_nexthop_peer
,
3614 set_ip_nexthop_peer_cmd
,
3615 "set ip next-hop peer-address",
3618 "Next hop address\n"
3619 "Use peer address (for BGP only)\n")
3621 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
3622 "ip next-hop", "peer-address");
3625 DEFUN (set_ip_nexthop_unchanged
,
3626 set_ip_nexthop_unchanged_cmd
,
3627 "set ip next-hop unchanged",
3630 "Next hop address\n"
3631 "Don't modify existing Next hop address\n")
3633 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
3634 "ip next-hop", "unchanged");
3638 DEFUN (set_local_pref
,
3640 "set local-preference (0-4294967295)",
3642 "BGP local preference path attribute\n"
3643 "Preference value\n")
3646 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
3647 "local-preference", argv
[idx_number
]->arg
);
3651 DEFUN (no_set_local_pref
,
3652 no_set_local_pref_cmd
,
3653 "no set local-preference [(0-4294967295)]",
3656 "BGP local preference path attribute\n"
3657 "Preference value\n")
3659 int idx_localpref
= 3;
3660 if (argc
<= idx_localpref
)
3661 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
3662 "local-preference", NULL
);
3663 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
3664 "local-preference", argv
[idx_localpref
]->arg
);
3670 "set weight (0-4294967295)",
3672 "BGP weight for routing table\n"
3676 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
3677 argv
[idx_number
]->arg
);
3681 DEFUN (no_set_weight
,
3683 "no set weight [(0-4294967295)]",
3686 "BGP weight for routing table\n"
3690 if (argc
<= idx_weight
)
3691 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
3693 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
), "weight",
3694 argv
[idx_weight
]->arg
);
3697 DEFUN (set_label_index
,
3698 set_label_index_cmd
,
3699 "set label-index (0-1048560)",
3701 "Label index to associate with the prefix\n"
3702 "Label index value\n")
3705 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
), "label-index",
3706 argv
[idx_number
]->arg
);
3709 DEFUN (no_set_label_index
,
3710 no_set_label_index_cmd
,
3711 "no set label-index [(0-1048560)]",
3714 "Label index to associate with the prefix\n"
3715 "Label index value\n")
3717 int idx_label_index
= 3;
3718 if (argc
<= idx_label_index
)
3719 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
3720 "label-index", NULL
);
3721 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
), "label-index",
3722 argv
[idx_label_index
]->arg
);
3725 DEFUN (set_aspath_prepend_asn
,
3726 set_aspath_prepend_asn_cmd
,
3727 "set as-path prepend (1-4294967295)...",
3729 "Transform BGP AS_PATH attribute\n"
3730 "Prepend to the as-path\n"
3737 str
= argv_concat (argv
, argc
, idx_asn
);
3738 ret
= generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
3739 "as-path prepend", str
);
3740 XFREE (MTYPE_TMP
, str
);
3745 DEFUN (set_aspath_prepend_lastas
,
3746 set_aspath_prepend_lastas_cmd
,
3747 "set as-path prepend last-as (1-10)",
3749 "Transform BGP AS_PATH attribute\n"
3750 "Prepend to the as-path\n"
3751 "Use the peer's AS-number\n"
3752 "Number of times to insert\n")
3754 return set_aspath_prepend_asn (self
, vty
, argc
, argv
);
3757 DEFUN (no_set_aspath_prepend
,
3758 no_set_aspath_prepend_cmd
,
3759 "no set as-path prepend [(1-4294967295)]",
3762 "Transform BGP AS_PATH attribute\n"
3763 "Prepend to the as-path\n"
3770 str
= argv_concat (argv
, argc
, idx_asn
);
3771 ret
= generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
3772 "as-path prepend", str
);
3773 XFREE (MTYPE_TMP
, str
);
3778 DEFUN (set_aspath_exclude
,
3779 set_aspath_exclude_cmd
,
3780 "set as-path exclude (1-4294967295)...",
3782 "Transform BGP AS-path attribute\n"
3783 "Exclude from the as-path\n"
3790 str
= argv_concat (argv
, argc
, idx_asn
);
3791 ret
= generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
3792 "as-path exclude", str
);
3793 XFREE (MTYPE_TMP
, str
);
3797 DEFUN (no_set_aspath_exclude
,
3798 no_set_aspath_exclude_cmd
,
3799 "no set as-path exclude (1-4294967295)...",
3802 "Transform BGP AS_PATH attribute\n"
3803 "Exclude from the as-path\n"
3810 str
= argv_concat (argv
, argc
, idx_asn
);
3811 ret
= generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
3812 "as-path exclude", str
);
3813 XFREE (MTYPE_TMP
, str
);
3818 DEFUN (set_community
,
3820 "set community AA:NN...",
3822 "BGP community attribute\n"
3830 struct community
*com
= NULL
;
3835 b
= buffer_new (1024);
3837 for (i
= idx_aa_nn
; i
< argc
; i
++)
3839 if (strncmp (argv
[i
]->arg
, "additive", strlen (argv
[i
]->arg
)) == 0)
3846 buffer_putc (b
, ' ');
3850 if (strncmp (argv
[i
]->arg
, "internet", strlen (argv
[i
]->arg
)) == 0)
3852 buffer_putstr (b
, "internet");
3855 if (strncmp (argv
[i
]->arg
, "local-AS", strlen (argv
[i
]->arg
)) == 0)
3857 buffer_putstr (b
, "local-AS");
3860 if (strncmp (argv
[i
]->arg
, "no-a", strlen ("no-a")) == 0
3861 && strncmp (argv
[i
]->arg
, "no-advertise", strlen (argv
[i
]->arg
)) == 0)
3863 buffer_putstr (b
, "no-advertise");
3866 if (strncmp (argv
[i
]->arg
, "no-e", strlen ("no-e"))== 0
3867 && strncmp (argv
[i
]->arg
, "no-export", strlen (argv
[i
]->arg
)) == 0)
3869 buffer_putstr (b
, "no-export");
3872 buffer_putstr (b
, argv
[i
]->arg
);
3874 buffer_putc (b
, '\0');
3876 /* Fetch result string then compile it to communities attribute. */
3877 str
= buffer_getstr (b
);
3882 com
= community_str2com (str
);
3883 XFREE (MTYPE_TMP
, str
);
3886 /* Can't compile user input into communities attribute. */
3889 vty_out (vty
, "%% Malformed communities attribute%s", VTY_NEWLINE
);
3893 /* Set communites attribute string. */
3894 str
= community_str (com
);
3898 argstr
= XCALLOC (MTYPE_TMP
, strlen (str
) + strlen (" additive") + 1);
3899 strcpy (argstr
, str
);
3900 strcpy (argstr
+ strlen (str
), " additive");
3901 ret
= generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
3902 "community", argstr
);
3903 XFREE (MTYPE_TMP
, argstr
);
3906 ret
= generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
3909 community_free (com
);
3914 DEFUN (set_community_none
,
3915 set_community_none_cmd
,
3916 "set community none",
3918 "BGP community attribute\n"
3919 "No community attribute\n")
3921 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
), "community",
3925 DEFUN (no_set_community
,
3926 no_set_community_cmd
,
3927 "no set community AA:NN...",
3930 "BGP community attribute\n"
3933 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
3939 DEFUN (set_community_delete
,
3940 set_community_delete_cmd
,
3941 "set comm-list <(1-99)|(100-500)|WORD> delete",
3943 "set BGP community list (for deletion)\n"
3944 "Community-list number (standard)\n"
3945 "Community-list number (expanded)\n"
3946 "Community-list name\n"
3947 "Delete matching communities\n")
3949 int idx_comm_list
= 2;
3952 str
= XCALLOC (MTYPE_TMP
, strlen (argv
[idx_comm_list
]->arg
) + strlen (" delete") + 1);
3953 strcpy (str
, argv
[idx_comm_list
]->arg
);
3954 strcpy (str
+ strlen (argv
[idx_comm_list
]->arg
), " delete");
3956 generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
), "comm-list", str
);
3958 XFREE (MTYPE_TMP
, str
);
3962 DEFUN (no_set_community_delete
,
3963 no_set_community_delete_cmd
,
3964 "no set comm-list [<(1-99)|(100-500)|WORD> delete]",
3967 "set BGP community list (for deletion)\n"
3968 "Community-list number (standard)\n"
3969 "Community-list number (expanded)\n"
3970 "Community-list name\n"
3971 "Delete matching communities\n")
3973 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
3977 DEFUN (set_lcommunity
,
3979 "set large-community AA:BB:CC...",
3981 "BGP large community attribute\n"
3982 "Large Community number in aa:bb:cc format or additive\n")
3987 str
= argv_concat (argv
, argc
, 2);
3988 ret
= generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
), "large-community", str
);
3989 XFREE (MTYPE_TMP
, str
);
3994 DEFUN (set_lcommunity_none
,
3995 set_lcommunity_none_cmd
,
3996 "set large-community none",
3998 "BGP large community attribute\n"
3999 "No large community attribute\n")
4001 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4002 "large-community", "none");
4005 DEFUN (no_set_lcommunity
,
4006 no_set_lcommunity_cmd
,
4007 "no set large-community none",
4010 "BGP large community attribute\n"
4011 "No community attribute\n")
4013 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4014 "large-community", NULL
);
4017 DEFUN (no_set_lcommunity1
,
4018 no_set_lcommunity1_cmd
,
4019 "no set large-community AA:BB:CC...",
4022 "BGP large community attribute\n"
4023 "Large community in AA:BB:CC... format or additive\n")
4025 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4026 "large-community", NULL
);
4029 DEFUN (set_lcommunity_delete
,
4030 set_lcommunity_delete_cmd
,
4031 "set large-comm-list <(1-99)|(100-500)|WORD> delete",
4033 "set BGP large community list (for deletion)\n"
4034 "Large Community-list number (standard)\n"
4035 "Large Communitly-list number (expanded)\n"
4036 "Large Community-list name\n"
4037 "Delete matching large communities\n")
4041 str
= XCALLOC (MTYPE_TMP
, strlen (argv
[2]->arg
) + strlen (" delete") + 1);
4042 strcpy (str
, argv
[2]->arg
);
4043 strcpy (str
+ strlen (argv
[2]->arg
), " delete");
4045 generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4046 "large-comm-list", str
);
4048 XFREE (MTYPE_TMP
, str
);
4052 DEFUN (no_set_lcommunity_delete
,
4053 no_set_lcommunity_delete_cmd
,
4054 "no set large-comm-list <(1-99)|(100-500)|WORD> [delete]",
4057 "set BGP large community list (for deletion)\n"
4058 "Large Community-list number (standard)\n"
4059 "Large Communitly-list number (expanded)\n"
4060 "Large Community-list name\n"
4061 "Delete matching large communities\n")
4063 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4064 "large-comm-list", NULL
);
4067 DEFUN (set_ecommunity_rt
,
4068 set_ecommunity_rt_cmd
,
4069 "set extcommunity rt ASN:nn_or_IP-address:nn...",
4071 "BGP extended community attribute\n"
4072 "Route Target extended community\n"
4073 "VPN extended community\n")
4079 str
= argv_concat (argv
, argc
, idx_asn_nn
);
4080 ret
= generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4081 "extcommunity rt", str
);
4082 XFREE (MTYPE_TMP
, str
);
4087 DEFUN (no_set_ecommunity_rt
,
4088 no_set_ecommunity_rt_cmd
,
4089 "no set extcommunity rt ASN:nn_or_IP-address:nn...",
4092 "BGP extended community attribute\n"
4093 "Route Target extended community\n"
4094 "VPN extended community\n")
4096 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4097 "extcommunity rt", NULL
);
4101 DEFUN (set_ecommunity_soo
,
4102 set_ecommunity_soo_cmd
,
4103 "set extcommunity soo ASN:nn_or_IP-address:nn...",
4105 "BGP extended community attribute\n"
4106 "Site-of-Origin extended community\n"
4107 "VPN extended community\n")
4113 str
= argv_concat (argv
, argc
, idx_asn_nn
);
4114 ret
= generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4115 "extcommunity soo", str
);
4116 XFREE (MTYPE_TMP
, str
);
4121 DEFUN (no_set_ecommunity_soo
,
4122 no_set_ecommunity_soo_cmd
,
4123 "no set extcommunity soo ASN:nn_or_IP-address:nn...",
4126 "BGP extended community attribute\n"
4127 "Site-of-Origin extended community\n"
4128 "VPN extended community\n")
4130 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4131 "extcommunity soo", NULL
);
4137 "set origin <egp|igp|incomplete>",
4142 "unknown heritage\n")
4145 if (strncmp (argv
[idx_origin
]->arg
, "igp", 2) == 0)
4146 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
), "origin",
4148 if (strncmp (argv
[idx_origin
]->arg
, "egp", 1) == 0)
4149 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
), "origin",
4151 if (strncmp (argv
[idx_origin
]->arg
, "incomplete", 2) == 0)
4152 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
), "origin",
4159 DEFUN (no_set_origin
,
4161 "no set origin [<egp|igp|incomplete>]",
4167 "unknown heritage\n")
4169 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
), "origin",
4174 DEFUN (set_atomic_aggregate
,
4175 set_atomic_aggregate_cmd
,
4176 "set atomic-aggregate",
4178 "BGP atomic aggregate attribute\n" )
4180 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4181 "atomic-aggregate", NULL
);
4184 DEFUN (no_set_atomic_aggregate
,
4185 no_set_atomic_aggregate_cmd
,
4186 "no set atomic-aggregate",
4189 "BGP atomic aggregate attribute\n" )
4191 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4192 "atomic-aggregate", NULL
);
4195 DEFUN (set_aggregator_as
,
4196 set_aggregator_as_cmd
,
4197 "set aggregator as (1-4294967295) A.B.C.D",
4199 "BGP aggregator attribute\n"
4200 "AS number of aggregator\n"
4202 "IP address of aggregator\n")
4207 struct in_addr address
;
4210 ret
= inet_aton (argv
[idx_ipv4
]->arg
, &address
);
4213 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
4217 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
4218 strlen (argv
[idx_number
]->arg
) + strlen (argv
[idx_ipv4
]->arg
) + 2);
4220 sprintf (argstr
, "%s %s", argv
[idx_number
]->arg
, argv
[idx_ipv4
]->arg
);
4222 ret
= generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4223 "aggregator as", argstr
);
4225 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4231 DEFUN (no_set_aggregator_as
,
4232 no_set_aggregator_as_cmd
,
4233 "no set aggregator as [(1-4294967295) A.B.C.D]",
4236 "BGP aggregator attribute\n"
4237 "AS number of aggregator\n"
4239 "IP address of aggregator\n")
4244 struct in_addr address
;
4247 if (argc
<= idx_asn
)
4248 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4249 "aggregator as", NULL
);
4251 ret
= inet_aton (argv
[idx_ip
]->arg
, &address
);
4254 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
4258 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
4259 strlen (argv
[idx_asn
]->arg
) + strlen (argv
[idx_ip
]->arg
) + 2);
4261 sprintf (argstr
, "%s %s", argv
[idx_asn
]->arg
, argv
[idx_ip
]->arg
);
4263 ret
= generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4264 "aggregator as", argstr
);
4266 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4271 DEFUN (match_ipv6_next_hop
,
4272 match_ipv6_next_hop_cmd
,
4273 "match ipv6 next-hop X:X::X:X",
4276 "Match IPv6 next-hop address of route\n"
4277 "IPv6 address of next hop\n")
4280 return bgp_route_match_add (vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4281 RMAP_EVENT_MATCH_ADDED
);
4284 DEFUN (no_match_ipv6_next_hop
,
4285 no_match_ipv6_next_hop_cmd
,
4286 "no match ipv6 next-hop X:X::X:X",
4290 "Match IPv6 next-hop address of route\n"
4291 "IPv6 address of next hop\n")
4294 return bgp_route_match_delete (vty
, "ipv6 next-hop", argv
[idx_ipv6
]->arg
,
4295 RMAP_EVENT_MATCH_DELETED
);
4299 DEFUN (set_ipv6_nexthop_peer
,
4300 set_ipv6_nexthop_peer_cmd
,
4301 "set ipv6 next-hop peer-address",
4304 "Next hop address\n"
4305 "Use peer address (for BGP only)\n")
4307 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4308 "ipv6 next-hop peer-address", NULL
);
4311 DEFUN (no_set_ipv6_nexthop_peer
,
4312 no_set_ipv6_nexthop_peer_cmd
,
4313 "no set ipv6 next-hop peer-address",
4317 "IPv6 next-hop address\n"
4318 "Use peer address (for BGP only)\n")
4320 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4321 "ipv6 next-hop peer-address", NULL
);
4324 DEFUN (set_ipv6_nexthop_prefer_global
,
4325 set_ipv6_nexthop_prefer_global_cmd
,
4326 "set ipv6 next-hop prefer-global",
4329 "IPv6 next-hop address\n"
4330 "Prefer global over link-local if both exist\n")
4332 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4333 "ipv6 next-hop prefer-global", NULL
);;
4336 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4337 no_set_ipv6_nexthop_prefer_global_cmd
,
4338 "no set ipv6 next-hop prefer-global",
4342 "IPv6 next-hop address\n"
4343 "Prefer global over link-local if both exist\n")
4345 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4346 "ipv6 next-hop prefer-global", NULL
);
4349 DEFUN (set_ipv6_nexthop_global
,
4350 set_ipv6_nexthop_global_cmd
,
4351 "set ipv6 next-hop global X:X::X:X",
4354 "IPv6 next-hop address\n"
4355 "IPv6 global address\n"
4356 "IPv6 address of next hop\n")
4359 struct in6_addr addr
;
4362 ret
= inet_pton (AF_INET6
, argv
[idx_ipv6
]->arg
, &addr
);
4365 vty_out (vty
, "%% Malformed nexthop address%s", VTY_NEWLINE
);
4368 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) ||
4369 IN6_IS_ADDR_LOOPBACK(&addr
) ||
4370 IN6_IS_ADDR_MULTICAST(&addr
) ||
4371 IN6_IS_ADDR_LINKLOCAL(&addr
))
4373 vty_out (vty
, "%% Invalid global nexthop address%s", VTY_NEWLINE
);
4377 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4378 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4382 DEFUN (no_set_ipv6_nexthop_global
,
4383 no_set_ipv6_nexthop_global_cmd
,
4384 "no set ipv6 next-hop global X:X::X:X",
4388 "IPv6 next-hop address\n"
4389 "IPv6 global address\n"
4390 "IPv6 address of next hop\n")
4393 if (argc
<= idx_ipv6
)
4394 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4395 "ipv6 next-hop global", NULL
);
4396 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4397 "ipv6 next-hop global", argv
[idx_ipv6
]->arg
);
4400 #ifdef KEEP_OLD_VPN_COMMANDS
4401 DEFUN (set_vpn_nexthop
,
4402 set_vpn_nexthop_cmd
,
4403 "set <vpnv4|vpnv6> next-hop <A.B.C.D|X:X::X:X>",
4405 "VPNv4 information\n"
4406 "VPNv6 information\n"
4407 "VPN next-hop address\n"
4408 "IP address of next hop\n"
4409 "IPv6 address of next hop\n")
4415 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
4418 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4419 "ip vpn next-hop", argv
[idx_ip
]->arg
);
4421 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4422 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4427 DEFUN (no_set_vpn_nexthop
,
4428 no_set_vpn_nexthop_cmd
,
4429 "no set vpn next-hop <A.B.C.D|X:X::X:X>",
4433 "VPN next-hop address\n"
4434 "IP address of next hop\n"
4435 "IPv6 address of next hop\n")
4445 arg
= argv
[idx_ip
]->arg
;
4446 if (argv_find_and_parse_vpnvx (argv
, argc
, &idx
, &afi
))
4449 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4450 "ip vpn next-hop", arg
);
4452 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4453 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4457 #endif /* KEEP_OLD_VPN_COMMANDS */
4459 DEFUN (set_ipx_vpn_nexthop
,
4460 set_ipx_vpn_nexthop_cmd
,
4461 "set <ipv4|ipv6> vpn next-hop <A.B.C.D|X:X::X:X>",
4463 "IPv4 information\n"
4464 "IPv6 information\n"
4466 "VPN next-hop address\n"
4467 "IP address of next hop\n"
4468 "IPv6 address of next hop\n")
4474 if (argv_find_and_parse_afi (argv
, argc
, &idx
, &afi
))
4477 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4478 "ip vpn next-hop", argv
[idx_ip
]->arg
);
4480 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4481 "ipv6 vpn next-hop", argv
[idx_ip
]->arg
);
4486 DEFUN (no_set_ipx_vpn_nexthop
,
4487 no_set_ipx_vpn_nexthop_cmd
,
4488 "no set <ipv4|ipv6> vpn next-hop [<A.B.C.D|X:X::X:X>]",
4491 "IPv4 information\n"
4492 "IPv6 information\n"
4494 "VPN next-hop address\n"
4495 "IP address of next hop\n"
4496 "IPv6 address of next hop\n")
4506 arg
= argv
[idx_ip
]->arg
;
4507 if (argv_find_and_parse_afi (argv
, argc
, &idx
, &afi
))
4510 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4511 "ip vpn next-hop", arg
);
4513 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4514 "ipv6 vpn next-hop", arg
);
4519 DEFUN (set_originator_id
,
4520 set_originator_id_cmd
,
4521 "set originator-id A.B.C.D",
4523 "BGP originator ID attribute\n"
4524 "IP address of originator\n")
4527 return generic_set_add (vty
, VTY_GET_CONTEXT(route_map_index
),
4528 "originator-id", argv
[idx_ipv4
]->arg
);
4532 DEFUN (no_set_originator_id
,
4533 no_set_originator_id_cmd
,
4534 "no set originator-id [A.B.C.D]",
4537 "BGP originator ID attribute\n"
4538 "IP address of originator\n")
4541 char *arg
= argv_find (argv
, argc
, "A.B.C.D", &idx
) ? argv
[idx
]->arg
: NULL
;
4543 return generic_set_delete (vty
, VTY_GET_CONTEXT(route_map_index
),
4544 "originator-id", arg
);
4548 /* Initialization of route map. */
4550 bgp_route_map_init (void)
4554 route_map_add_hook (bgp_route_map_add
);
4555 route_map_delete_hook (bgp_route_map_delete
);
4556 route_map_event_hook (bgp_route_map_event
);
4558 route_map_match_interface_hook (generic_match_add
);
4559 route_map_no_match_interface_hook (generic_match_delete
);
4561 route_map_match_ip_address_hook (generic_match_add
);
4562 route_map_no_match_ip_address_hook (generic_match_delete
);
4564 route_map_match_ip_address_prefix_list_hook (generic_match_add
);
4565 route_map_no_match_ip_address_prefix_list_hook (generic_match_delete
);
4567 route_map_match_ip_next_hop_hook (generic_match_add
);
4568 route_map_no_match_ip_next_hop_hook (generic_match_delete
);
4570 route_map_match_ip_next_hop_prefix_list_hook (generic_match_add
);
4571 route_map_no_match_ip_next_hop_prefix_list_hook (generic_match_delete
);
4573 route_map_match_ipv6_address_hook (generic_match_add
);
4574 route_map_no_match_ipv6_address_hook (generic_match_delete
);
4576 route_map_match_ipv6_address_prefix_list_hook (generic_match_add
);
4577 route_map_no_match_ipv6_address_prefix_list_hook (generic_match_delete
);
4579 route_map_match_metric_hook (generic_match_add
);
4580 route_map_no_match_metric_hook (generic_match_delete
);
4582 route_map_match_tag_hook (generic_match_add
);
4583 route_map_no_match_tag_hook (generic_match_delete
);
4585 route_map_set_ip_nexthop_hook (generic_set_add
);
4586 route_map_no_set_ip_nexthop_hook (generic_set_delete
);
4588 route_map_set_ipv6_nexthop_local_hook (generic_set_add
);
4589 route_map_no_set_ipv6_nexthop_local_hook (generic_set_delete
);
4591 route_map_set_metric_hook (generic_set_add
);
4592 route_map_no_set_metric_hook (generic_set_delete
);
4594 route_map_set_tag_hook (generic_set_add
);
4595 route_map_no_set_tag_hook (generic_set_delete
);
4597 route_map_install_match (&route_match_peer_cmd
);
4598 route_map_install_match (&route_match_local_pref_cmd
);
4599 route_map_install_match (&route_match_ip_address_cmd
);
4600 route_map_install_match (&route_match_ip_next_hop_cmd
);
4601 route_map_install_match (&route_match_ip_route_source_cmd
);
4602 route_map_install_match (&route_match_ip_address_prefix_list_cmd
);
4603 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd
);
4604 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd
);
4605 route_map_install_match (&route_match_aspath_cmd
);
4606 route_map_install_match (&route_match_community_cmd
);
4607 route_map_install_match (&route_match_lcommunity_cmd
);
4608 route_map_install_match (&route_match_ecommunity_cmd
);
4609 route_map_install_match (&route_match_local_pref_cmd
);
4610 route_map_install_match (&route_match_metric_cmd
);
4611 route_map_install_match (&route_match_origin_cmd
);
4612 route_map_install_match (&route_match_probability_cmd
);
4613 route_map_install_match (&route_match_interface_cmd
);
4614 route_map_install_match (&route_match_tag_cmd
);
4616 route_map_install_set (&route_set_ip_nexthop_cmd
);
4617 route_map_install_set (&route_set_local_pref_cmd
);
4618 route_map_install_set (&route_set_weight_cmd
);
4619 route_map_install_set (&route_set_label_index_cmd
);
4620 route_map_install_set (&route_set_metric_cmd
);
4621 route_map_install_set (&route_set_aspath_prepend_cmd
);
4622 route_map_install_set (&route_set_aspath_exclude_cmd
);
4623 route_map_install_set (&route_set_origin_cmd
);
4624 route_map_install_set (&route_set_atomic_aggregate_cmd
);
4625 route_map_install_set (&route_set_aggregator_as_cmd
);
4626 route_map_install_set (&route_set_community_cmd
);
4627 route_map_install_set (&route_set_community_delete_cmd
);
4628 route_map_install_set (&route_set_lcommunity_cmd
);
4629 route_map_install_set (&route_set_lcommunity_delete_cmd
);
4630 route_map_install_set (&route_set_vpnv4_nexthop_cmd
);
4631 route_map_install_set (&route_set_vpnv6_nexthop_cmd
);
4632 route_map_install_set (&route_set_originator_id_cmd
);
4633 route_map_install_set (&route_set_ecommunity_rt_cmd
);
4634 route_map_install_set (&route_set_ecommunity_soo_cmd
);
4635 route_map_install_set (&route_set_tag_cmd
);
4636 route_map_install_set (&route_set_label_index_cmd
);
4638 install_element (RMAP_NODE
, &match_peer_cmd
);
4639 install_element (RMAP_NODE
, &match_peer_local_cmd
);
4640 install_element (RMAP_NODE
, &no_match_peer_cmd
);
4641 install_element (RMAP_NODE
, &match_ip_route_source_cmd
);
4642 install_element (RMAP_NODE
, &no_match_ip_route_source_cmd
);
4643 install_element (RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
4644 install_element (RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
4646 install_element (RMAP_NODE
, &match_aspath_cmd
);
4647 install_element (RMAP_NODE
, &no_match_aspath_cmd
);
4648 install_element (RMAP_NODE
, &match_local_pref_cmd
);
4649 install_element (RMAP_NODE
, &no_match_local_pref_cmd
);
4650 install_element (RMAP_NODE
, &match_community_cmd
);
4651 install_element (RMAP_NODE
, &no_match_community_cmd
);
4652 install_element (RMAP_NODE
, &match_lcommunity_cmd
);
4653 install_element (RMAP_NODE
, &no_match_lcommunity_cmd
);
4654 install_element (RMAP_NODE
, &match_ecommunity_cmd
);
4655 install_element (RMAP_NODE
, &no_match_ecommunity_cmd
);
4656 install_element (RMAP_NODE
, &match_origin_cmd
);
4657 install_element (RMAP_NODE
, &no_match_origin_cmd
);
4658 install_element (RMAP_NODE
, &match_probability_cmd
);
4659 install_element (RMAP_NODE
, &no_match_probability_cmd
);
4661 install_element (RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
4662 install_element (RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
4663 install_element (RMAP_NODE
, &set_local_pref_cmd
);
4664 install_element (RMAP_NODE
, &no_set_local_pref_cmd
);
4665 install_element (RMAP_NODE
, &set_weight_cmd
);
4666 install_element (RMAP_NODE
, &set_label_index_cmd
);
4667 install_element (RMAP_NODE
, &no_set_weight_cmd
);
4668 install_element (RMAP_NODE
, &no_set_label_index_cmd
);
4669 install_element (RMAP_NODE
, &set_aspath_prepend_asn_cmd
);
4670 install_element (RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
4671 install_element (RMAP_NODE
, &set_aspath_exclude_cmd
);
4672 install_element (RMAP_NODE
, &no_set_aspath_prepend_cmd
);
4673 install_element (RMAP_NODE
, &no_set_aspath_exclude_cmd
);
4674 install_element (RMAP_NODE
, &set_origin_cmd
);
4675 install_element (RMAP_NODE
, &no_set_origin_cmd
);
4676 install_element (RMAP_NODE
, &set_atomic_aggregate_cmd
);
4677 install_element (RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
4678 install_element (RMAP_NODE
, &set_aggregator_as_cmd
);
4679 install_element (RMAP_NODE
, &no_set_aggregator_as_cmd
);
4680 install_element (RMAP_NODE
, &set_community_cmd
);
4681 install_element (RMAP_NODE
, &set_community_none_cmd
);
4682 install_element (RMAP_NODE
, &no_set_community_cmd
);
4683 install_element (RMAP_NODE
, &set_community_delete_cmd
);
4684 install_element (RMAP_NODE
, &no_set_community_delete_cmd
);
4685 install_element (RMAP_NODE
, &set_lcommunity_cmd
);
4686 install_element (RMAP_NODE
, &set_lcommunity_none_cmd
);
4687 install_element (RMAP_NODE
, &no_set_lcommunity_cmd
);
4688 install_element (RMAP_NODE
, &no_set_lcommunity1_cmd
);
4689 install_element (RMAP_NODE
, &set_lcommunity_delete_cmd
);
4690 install_element (RMAP_NODE
, &no_set_lcommunity_delete_cmd
);
4691 install_element (RMAP_NODE
, &set_ecommunity_rt_cmd
);
4692 install_element (RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
4693 install_element (RMAP_NODE
, &set_ecommunity_soo_cmd
);
4694 install_element (RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
4695 #ifdef KEEP_OLD_VPN_COMMANDS
4696 install_element (RMAP_NODE
, &set_vpn_nexthop_cmd
);
4697 install_element (RMAP_NODE
, &no_set_vpn_nexthop_cmd
);
4698 #endif /* KEEP_OLD_VPN_COMMANDS */
4699 install_element (RMAP_NODE
, &set_ipx_vpn_nexthop_cmd
);
4700 install_element (RMAP_NODE
, &no_set_ipx_vpn_nexthop_cmd
);
4701 install_element (RMAP_NODE
, &set_originator_id_cmd
);
4702 install_element (RMAP_NODE
, &no_set_originator_id_cmd
);
4704 route_map_install_match (&route_match_ipv6_address_cmd
);
4705 route_map_install_match (&route_match_ipv6_next_hop_cmd
);
4706 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd
);
4707 route_map_install_set (&route_set_ipv6_nexthop_global_cmd
);
4708 route_map_install_set (&route_set_ipv6_nexthop_prefer_global_cmd
);
4709 route_map_install_set (&route_set_ipv6_nexthop_local_cmd
);
4710 route_map_install_set (&route_set_ipv6_nexthop_peer_cmd
);
4712 install_element (RMAP_NODE
, &match_ipv6_next_hop_cmd
);
4713 install_element (RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
4714 install_element (RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
4715 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
4716 install_element (RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
4717 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
4718 install_element (RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
4719 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
4723 bgp_route_map_terminate (void)
4725 /* ToDo: Cleanup all the used memory */
4727 route_map_add_hook (NULL
);
4728 route_map_delete_hook (NULL
);
4729 route_map_event_hook (NULL
);