1 /* Route map function of bgpd.
2 Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 #ifdef HAVE_LIBPCREPOSIX
32 # include <pcreposix.h>
34 # ifdef HAVE_GNU_REGEX
37 # include "regex-gnu.h"
38 # endif /* HAVE_GNU_REGEX */
39 #endif /* HAVE_LIBPCREPOSIX */
41 #include "sockunion.h"
45 #include "bgpd/bgpd.h"
46 #include "bgpd/bgp_table.h"
47 #include "bgpd/bgp_attr.h"
48 #include "bgpd/bgp_aspath.h"
49 #include "bgpd/bgp_packet.h"
50 #include "bgpd/bgp_route.h"
51 #include "bgpd/bgp_zebra.h"
52 #include "bgpd/bgp_regex.h"
53 #include "bgpd/bgp_community.h"
54 #include "bgpd/bgp_clist.h"
55 #include "bgpd/bgp_filter.h"
56 #include "bgpd/bgp_mplsvpn.h"
57 #include "bgpd/bgp_ecommunity.h"
58 #include "bgpd/bgp_vty.h"
59 #include "bgpd/bgp_debug.h"
62 # include "bgp_rfapi_cfg.h"
65 /* Memo of route-map commands.
74 ip route-source : Done
78 ipv6 route-source: (This will not be implemented by bgpd)
79 ipv6 prefix-list : Done
80 length : (This will not be implemented by bgpd)
82 route-type : (This will not be implemented by bgpd)
84 local-preference : Done
86 set as-path prepend : Done
88 automatic-tag : (This will not be implemented by bgpd)
92 default : (This will not be implemented by bgpd)
93 interface : (This will not be implemented by bgpd)
94 ip default : (This will not be implemented by bgpd)
96 ip precedence : (This will not be implemented by bgpd)
97 ip tos : (This will not be implemented by bgpd)
98 level : (This will not be implemented by bgpd)
99 local-preference : Done
101 metric-type : Not yet
108 set ipv6 next-hop global: Done
109 set ipv6 next-hop prefer-global: Done
110 set ipv6 next-hop local : Done
111 set as-path exclude : Done
115 /* generic value manipulation to be shared in multiple rules */
117 #define RMAP_VALUE_SET 0
118 #define RMAP_VALUE_ADD 1
119 #define RMAP_VALUE_SUB 2
129 route_value_match (struct rmap_value
*rv
, u_int32_t value
)
131 if (rv
->variable
== 0 && value
== rv
->value
)
138 route_value_adjust (struct rmap_value
*rv
, u_int32_t current
, struct peer
*peer
)
142 switch (rv
->variable
)
155 if (current
> UINT32_MAX
-value
)
157 return current
+ value
;
159 if (current
<= value
)
161 return current
- value
;
168 route_value_compile (const char *arg
)
170 u_int8_t action
= RMAP_VALUE_SET
, var
= 0;
171 unsigned long larg
= 0;
173 struct rmap_value
*rv
;
177 action
= RMAP_VALUE_ADD
;
180 else if (arg
[0] == '-')
182 action
= RMAP_VALUE_SUB
;
189 larg
= strtoul (arg
, &endptr
, 10);
190 if (*arg
== 0 || *endptr
!= 0 || errno
|| larg
> UINT32_MAX
)
195 if (strcmp(arg
, "rtt") == 0)
201 rv
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof(struct rmap_value
));
212 route_value_free (void *rule
)
214 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
217 /* generic as path object to be shared in multiple rules */
220 route_aspath_compile (const char *arg
)
222 struct aspath
*aspath
;
224 aspath
= aspath_str2aspath (arg
);
231 route_aspath_free (void *rule
)
233 struct aspath
*aspath
= rule
;
234 aspath_free (aspath
);
237 /* 'match peer (A.B.C.D|X:X::X:X)' */
239 /* Compares the peer specified in the 'match peer' clause with the peer
240 received in bgp_info->peer. If it is the same, or if the peer structure
241 received is a peer_group containing it, returns RMAP_MATCH. */
242 static route_map_result_t
243 route_match_peer (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
247 union sockunion su_def
= { .sin
= { .sin_family
= AF_INET
,
248 .sin_addr
.s_addr
= INADDR_ANY
} };
249 struct peer_group
*group
;
251 struct listnode
*node
, *nnode
;
253 if (type
== RMAP_BGP
)
256 peer
= ((struct bgp_info
*) object
)->peer
;
258 if ( ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
) &&
259 ! CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_EXPORT
) )
262 /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
263 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
264 if (sockunion_same (su
, &su_def
))
267 if ( CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_NETWORK
) ||
268 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_REDISTRIBUTE
) ||
269 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_DEFAULT
))
276 if (! CHECK_FLAG (peer
->sflags
, PEER_STATUS_GROUP
))
278 if (sockunion_same (su
, &peer
->su
))
286 for (ALL_LIST_ELEMENTS (group
->peer
, node
, nnode
, peer
))
288 if (sockunion_same (su
, &peer
->su
))
298 route_match_peer_compile (const char *arg
)
303 su
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (union sockunion
));
305 ret
= str2sockunion (strcmp(arg
, "local") ? arg
: "0.0.0.0", su
);
307 XFREE (MTYPE_ROUTE_MAP_COMPILED
, su
);
314 /* Free route map's compiled `ip address' value. */
316 route_match_peer_free (void *rule
)
318 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
321 /* Route map commands for ip address matching. */
322 struct route_map_rule_cmd route_match_peer_cmd
=
326 route_match_peer_compile
,
327 route_match_peer_free
330 /* `match ip address IP_ACCESS_LIST' */
332 /* Match function should return 1 if match is success else return
334 static route_map_result_t
335 route_match_ip_address (void *rule
, struct prefix
*prefix
,
336 route_map_object_t type
, void *object
)
338 struct access_list
*alist
;
339 /* struct prefix_ipv4 match; */
341 if (type
== RMAP_BGP
)
343 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
347 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
348 RMAP_NOMATCH
: RMAP_MATCH
);
353 /* Route map `ip address' match statement. `arg' should be
356 route_match_ip_address_compile (const char *arg
)
358 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
361 /* Free route map's compiled `ip address' value. */
363 route_match_ip_address_free (void *rule
)
365 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
368 /* Route map commands for ip address matching. */
369 struct route_map_rule_cmd route_match_ip_address_cmd
=
372 route_match_ip_address
,
373 route_match_ip_address_compile
,
374 route_match_ip_address_free
377 /* `match ip next-hop IP_ADDRESS' */
379 /* Match function return 1 if match is success else return zero. */
380 static route_map_result_t
381 route_match_ip_next_hop (void *rule
, struct prefix
*prefix
,
382 route_map_object_t type
, void *object
)
384 struct access_list
*alist
;
385 struct bgp_info
*bgp_info
;
386 struct prefix_ipv4 p
;
388 if (type
== RMAP_BGP
)
392 p
.prefix
= bgp_info
->attr
->nexthop
;
393 p
.prefixlen
= IPV4_MAX_BITLEN
;
395 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
399 return (access_list_apply (alist
, &p
) == FILTER_DENY
?
400 RMAP_NOMATCH
: RMAP_MATCH
);
405 /* Route map `ip next-hop' match statement. `arg' is
408 route_match_ip_next_hop_compile (const char *arg
)
410 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
413 /* Free route map's compiled `ip address' value. */
415 route_match_ip_next_hop_free (void *rule
)
417 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
420 /* Route map commands for ip next-hop matching. */
421 struct route_map_rule_cmd route_match_ip_next_hop_cmd
=
424 route_match_ip_next_hop
,
425 route_match_ip_next_hop_compile
,
426 route_match_ip_next_hop_free
429 /* `match ip route-source ACCESS-LIST' */
431 /* Match function return 1 if match is success else return zero. */
432 static route_map_result_t
433 route_match_ip_route_source (void *rule
, struct prefix
*prefix
,
434 route_map_object_t type
, void *object
)
436 struct access_list
*alist
;
437 struct bgp_info
*bgp_info
;
439 struct prefix_ipv4 p
;
441 if (type
== RMAP_BGP
)
444 peer
= bgp_info
->peer
;
446 if (! peer
|| sockunion_family (&peer
->su
) != AF_INET
)
450 p
.prefix
= peer
->su
.sin
.sin_addr
;
451 p
.prefixlen
= IPV4_MAX_BITLEN
;
453 alist
= access_list_lookup (AFI_IP
, (char *) rule
);
457 return (access_list_apply (alist
, &p
) == FILTER_DENY
?
458 RMAP_NOMATCH
: RMAP_MATCH
);
463 /* Route map `ip route-source' match statement. `arg' is
466 route_match_ip_route_source_compile (const char *arg
)
468 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
471 /* Free route map's compiled `ip address' value. */
473 route_match_ip_route_source_free (void *rule
)
475 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
478 /* Route map commands for ip route-source matching. */
479 struct route_map_rule_cmd route_match_ip_route_source_cmd
=
482 route_match_ip_route_source
,
483 route_match_ip_route_source_compile
,
484 route_match_ip_route_source_free
487 /* `match ip address prefix-list PREFIX_LIST' */
489 static route_map_result_t
490 route_match_ip_address_prefix_list (void *rule
, struct prefix
*prefix
,
491 route_map_object_t type
, void *object
)
493 struct prefix_list
*plist
;
495 if (type
== RMAP_BGP
)
497 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
501 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
502 RMAP_NOMATCH
: RMAP_MATCH
);
508 route_match_ip_address_prefix_list_compile (const char *arg
)
510 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
514 route_match_ip_address_prefix_list_free (void *rule
)
516 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
519 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
=
521 "ip address prefix-list",
522 route_match_ip_address_prefix_list
,
523 route_match_ip_address_prefix_list_compile
,
524 route_match_ip_address_prefix_list_free
527 /* `match ip next-hop prefix-list PREFIX_LIST' */
529 static route_map_result_t
530 route_match_ip_next_hop_prefix_list (void *rule
, struct prefix
*prefix
,
531 route_map_object_t type
, void *object
)
533 struct prefix_list
*plist
;
534 struct bgp_info
*bgp_info
;
535 struct prefix_ipv4 p
;
537 if (type
== RMAP_BGP
)
541 p
.prefix
= bgp_info
->attr
->nexthop
;
542 p
.prefixlen
= IPV4_MAX_BITLEN
;
544 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
548 return (prefix_list_apply (plist
, &p
) == PREFIX_DENY
?
549 RMAP_NOMATCH
: RMAP_MATCH
);
555 route_match_ip_next_hop_prefix_list_compile (const char *arg
)
557 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
561 route_match_ip_next_hop_prefix_list_free (void *rule
)
563 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
566 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd
=
568 "ip next-hop prefix-list",
569 route_match_ip_next_hop_prefix_list
,
570 route_match_ip_next_hop_prefix_list_compile
,
571 route_match_ip_next_hop_prefix_list_free
574 /* `match ip route-source prefix-list PREFIX_LIST' */
576 static route_map_result_t
577 route_match_ip_route_source_prefix_list (void *rule
, struct prefix
*prefix
,
578 route_map_object_t type
, void *object
)
580 struct prefix_list
*plist
;
581 struct bgp_info
*bgp_info
;
583 struct prefix_ipv4 p
;
585 if (type
== RMAP_BGP
)
588 peer
= bgp_info
->peer
;
590 if (! peer
|| sockunion_family (&peer
->su
) != AF_INET
)
594 p
.prefix
= peer
->su
.sin
.sin_addr
;
595 p
.prefixlen
= IPV4_MAX_BITLEN
;
597 plist
= prefix_list_lookup (AFI_IP
, (char *) rule
);
601 return (prefix_list_apply (plist
, &p
) == PREFIX_DENY
?
602 RMAP_NOMATCH
: RMAP_MATCH
);
608 route_match_ip_route_source_prefix_list_compile (const char *arg
)
610 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
614 route_match_ip_route_source_prefix_list_free (void *rule
)
616 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
619 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd
=
621 "ip route-source prefix-list",
622 route_match_ip_route_source_prefix_list
,
623 route_match_ip_route_source_prefix_list_compile
,
624 route_match_ip_route_source_prefix_list_free
627 /* `match local-preference LOCAL-PREF' */
629 /* Match function return 1 if match is success else return zero. */
630 static route_map_result_t
631 route_match_local_pref (void *rule
, struct prefix
*prefix
,
632 route_map_object_t type
, void *object
)
634 u_int32_t
*local_pref
;
635 struct bgp_info
*bgp_info
;
637 if (type
== RMAP_BGP
)
642 if (bgp_info
->attr
->local_pref
== *local_pref
)
650 /* Route map `match local-preference' match statement.
651 `arg' is local-pref value */
653 route_match_local_pref_compile (const char *arg
)
655 u_int32_t
*local_pref
;
657 unsigned long tmpval
;
659 /* Locpref value shoud be integer. */
660 if (! all_digit (arg
))
664 tmpval
= strtoul (arg
, &endptr
, 10);
665 if (*endptr
!= '\0' || errno
|| tmpval
> UINT32_MAX
)
668 local_pref
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_int32_t
));
673 *local_pref
= tmpval
;
677 /* Free route map's compiled `match local-preference' value. */
679 route_match_local_pref_free (void *rule
)
681 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
684 /* Route map commands for metric matching. */
685 struct route_map_rule_cmd route_match_local_pref_cmd
=
688 route_match_local_pref
,
689 route_match_local_pref_compile
,
690 route_match_local_pref_free
693 /* `match metric METRIC' */
695 /* Match function return 1 if match is success else return zero. */
696 static route_map_result_t
697 route_match_metric (void *rule
, struct prefix
*prefix
,
698 route_map_object_t type
, void *object
)
700 struct rmap_value
*rv
;
701 struct bgp_info
*bgp_info
;
703 if (type
== RMAP_BGP
)
707 return route_value_match(rv
, bgp_info
->attr
->med
);
712 /* Route map commands for metric matching. */
713 struct route_map_rule_cmd route_match_metric_cmd
=
721 /* `match as-path ASPATH' */
723 /* Match function for as-path match. I assume given object is */
724 static route_map_result_t
725 route_match_aspath (void *rule
, struct prefix
*prefix
,
726 route_map_object_t type
, void *object
)
729 struct as_list
*as_list
;
730 struct bgp_info
*bgp_info
;
732 if (type
== RMAP_BGP
)
734 as_list
= as_list_lookup ((char *) rule
);
741 return ((as_list_apply (as_list
, bgp_info
->attr
->aspath
) == AS_FILTER_DENY
) ? RMAP_NOMATCH
: RMAP_MATCH
);
746 /* Compile function for as-path match. */
748 route_match_aspath_compile (const char *arg
)
750 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
753 /* Compile function for as-path match. */
755 route_match_aspath_free (void *rule
)
757 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
760 /* Route map commands for aspath matching. */
761 struct route_map_rule_cmd route_match_aspath_cmd
=
765 route_match_aspath_compile
,
766 route_match_aspath_free
769 /* `match community COMMUNIY' */
770 struct rmap_community
776 /* Match function for community match. */
777 static route_map_result_t
778 route_match_community (void *rule
, struct prefix
*prefix
,
779 route_map_object_t type
, void *object
)
781 struct community_list
*list
;
782 struct bgp_info
*bgp_info
;
783 struct rmap_community
*rcom
;
785 if (type
== RMAP_BGP
)
790 list
= community_list_lookup (bgp_clist
, rcom
->name
, COMMUNITY_LIST_MASTER
);
796 if (community_list_exact_match (bgp_info
->attr
->community
, list
))
801 if (community_list_match (bgp_info
->attr
->community
, list
))
808 /* Compile function for community match. */
810 route_match_community_compile (const char *arg
)
812 struct rmap_community
*rcom
;
816 rcom
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_community
));
818 p
= strchr (arg
, ' ');
822 rcom
->name
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
823 memcpy (rcom
->name
, arg
, len
);
828 rcom
->name
= XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
834 /* Compile function for community match. */
836 route_match_community_free (void *rule
)
838 struct rmap_community
*rcom
= rule
;
840 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
->name
);
841 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcom
);
844 /* Route map commands for community matching. */
845 struct route_map_rule_cmd route_match_community_cmd
=
848 route_match_community
,
849 route_match_community_compile
,
850 route_match_community_free
853 /* Match function for extcommunity match. */
854 static route_map_result_t
855 route_match_ecommunity (void *rule
, struct prefix
*prefix
,
856 route_map_object_t type
, void *object
)
858 struct community_list
*list
;
859 struct bgp_info
*bgp_info
;
861 if (type
== RMAP_BGP
)
865 if (!bgp_info
->attr
->extra
)
868 list
= community_list_lookup (bgp_clist
, (char *) rule
,
869 EXTCOMMUNITY_LIST_MASTER
);
873 if (ecommunity_list_match (bgp_info
->attr
->extra
->ecommunity
, list
))
879 /* Compile function for extcommunity match. */
881 route_match_ecommunity_compile (const char *arg
)
883 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
886 /* Compile function for extcommunity match. */
888 route_match_ecommunity_free (void *rule
)
890 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
893 /* Route map commands for community matching. */
894 struct route_map_rule_cmd route_match_ecommunity_cmd
=
897 route_match_ecommunity
,
898 route_match_ecommunity_compile
,
899 route_match_ecommunity_free
902 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
903 and `address-family vpnv4'. */
906 static route_map_result_t
907 route_match_origin (void *rule
, struct prefix
*prefix
,
908 route_map_object_t type
, void *object
)
911 struct bgp_info
*bgp_info
;
913 if (type
== RMAP_BGP
)
918 if (bgp_info
->attr
->origin
== *origin
)
926 route_match_origin_compile (const char *arg
)
930 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
932 if (strcmp (arg
, "igp") == 0)
934 else if (strcmp (arg
, "egp") == 0)
942 /* Free route map's compiled `ip address' value. */
944 route_match_origin_free (void *rule
)
946 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
949 /* Route map commands for origin matching. */
950 struct route_map_rule_cmd route_match_origin_cmd
=
954 route_match_origin_compile
,
955 route_match_origin_free
958 /* match probability { */
960 static route_map_result_t
961 route_match_probability (void *rule
, struct prefix
*prefix
,
962 route_map_object_t type
, void *object
)
966 switch (*(long *) rule
)
969 case RAND_MAX
: return RMAP_MATCH
;
971 if (r
< *(long *) rule
)
981 route_match_probability_compile (const char *arg
)
987 lobule
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (long));
991 case 0: *lobule
= 0; break;
992 case 100: *lobule
= RAND_MAX
; break;
993 default: *lobule
= RAND_MAX
/ 100 * perc
;
1000 route_match_probability_free (void *rule
)
1002 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1005 struct route_map_rule_cmd route_match_probability_cmd
=
1008 route_match_probability
,
1009 route_match_probability_compile
,
1010 route_match_probability_free
1013 /* `match interface IFNAME' */
1014 /* Match function should return 1 if match is success else return
1016 static route_map_result_t
1017 route_match_interface (void *rule
, struct prefix
*prefix
,
1018 route_map_object_t type
, void *object
)
1020 struct interface
*ifp
;
1021 struct bgp_info
*info
;
1023 if (type
== RMAP_BGP
)
1027 if (!info
|| !info
->attr
)
1028 return RMAP_NOMATCH
;
1030 ifp
= if_lookup_by_name_all_vrf ((char *)rule
);
1032 if (ifp
== NULL
|| ifp
->ifindex
!= info
->attr
->nh_ifindex
)
1033 return RMAP_NOMATCH
;
1037 return RMAP_NOMATCH
;
1040 /* Route map `interface' match statement. `arg' should be
1043 route_match_interface_compile (const char *arg
)
1045 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
1048 /* Free route map's compiled `interface' value. */
1050 route_match_interface_free (void *rule
)
1052 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1055 /* Route map commands for ip address matching. */
1056 struct route_map_rule_cmd route_match_interface_cmd
=
1059 route_match_interface
,
1060 route_match_interface_compile
,
1061 route_match_interface_free
1066 /* `set ip next-hop IP_ADDRESS' */
1068 /* Match function return 1 if match is success else return zero. */
1069 static route_map_result_t
1070 route_match_tag (void *rule
, struct prefix
*prefix
,
1071 route_map_object_t type
, void *object
)
1074 struct bgp_info
*bgp_info
;
1076 if (type
== RMAP_BGP
)
1081 if (!bgp_info
->attr
->extra
)
1082 return RMAP_NOMATCH
;
1084 return ((bgp_info
->attr
->extra
->tag
== *tag
)? RMAP_MATCH
: RMAP_NOMATCH
);
1087 return RMAP_NOMATCH
;
1091 /* Route map `match tag' match statement. `arg' is TAG value */
1093 route_match_tag_compile (const char *arg
)
1098 /* tag value shoud be integer. */
1099 if (! all_digit (arg
))
1106 tag
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_short
));
1117 /* Free route map's compiled 'match tag' value. */
1119 route_match_tag_free (void *rule
)
1121 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1124 /* Route map commands for tag matching. */
1125 struct route_map_rule_cmd route_match_tag_cmd
=
1129 route_match_tag_compile
,
1130 route_match_tag_free
,
1134 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1135 struct rmap_ip_nexthop_set
1137 struct in_addr
*address
;
1142 static route_map_result_t
1143 route_set_ip_nexthop (void *rule
, struct prefix
*prefix
,
1144 route_map_object_t type
, void *object
)
1146 struct rmap_ip_nexthop_set
*rins
= rule
;
1147 struct bgp_info
*bgp_info
;
1150 if (type
== RMAP_BGP
)
1153 peer
= bgp_info
->peer
;
1155 if (rins
->unchanged
)
1157 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1158 BATTR_RMAP_NEXTHOP_UNCHANGED
);
1160 else if (rins
->peer_address
)
1162 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
1163 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
1165 && sockunion_family (peer
->su_remote
) == AF_INET
)
1167 bgp_info
->attr
->nexthop
.s_addr
= sockunion2ip (peer
->su_remote
);
1168 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
1170 else if (CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
))
1172 /* The next hop value will be set as part of packet rewrite.
1173 * Set the flags here to indicate that rewrite needs to be done.
1174 * Also, clear the value.
1176 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1177 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
1178 bgp_info
->attr
->nexthop
.s_addr
= 0;
1183 /* Set next hop value. */
1184 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP
);
1185 bgp_info
->attr
->nexthop
= *rins
->address
;
1186 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
1187 BATTR_RMAP_IPV4_NHOP_CHANGED
);
1194 /* Route map `ip nexthop' compile function. Given string is converted
1195 to struct in_addr structure. */
1197 route_set_ip_nexthop_compile (const char *arg
)
1199 struct rmap_ip_nexthop_set
*rins
;
1200 struct in_addr
*address
= NULL
;
1201 int peer_address
= 0;
1205 if (strcmp (arg
, "peer-address") == 0)
1207 else if (strcmp (arg
, "unchanged") == 0)
1211 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
1212 ret
= inet_aton (arg
, address
);
1216 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
1221 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_ip_nexthop_set
));
1223 rins
->address
= address
;
1224 rins
->peer_address
= peer_address
;
1225 rins
->unchanged
= unchanged
;
1230 /* Free route map's compiled `ip nexthop' value. */
1232 route_set_ip_nexthop_free (void *rule
)
1234 struct rmap_ip_nexthop_set
*rins
= rule
;
1237 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
->address
);
1239 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rins
);
1242 /* Route map commands for ip nexthop set. */
1243 struct route_map_rule_cmd route_set_ip_nexthop_cmd
=
1246 route_set_ip_nexthop
,
1247 route_set_ip_nexthop_compile
,
1248 route_set_ip_nexthop_free
1251 /* `set local-preference LOCAL_PREF' */
1253 /* Set local preference. */
1254 static route_map_result_t
1255 route_set_local_pref (void *rule
, struct prefix
*prefix
,
1256 route_map_object_t type
, void *object
)
1258 struct rmap_value
*rv
;
1259 struct bgp_info
*bgp_info
;
1260 u_int32_t locpref
= 0;
1262 if (type
== RMAP_BGP
)
1264 /* Fetch routemap's rule information. */
1268 /* Set local preference value. */
1269 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
))
1270 locpref
= bgp_info
->attr
->local_pref
;
1272 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF
);
1273 bgp_info
->attr
->local_pref
= route_value_adjust(rv
, locpref
, bgp_info
->peer
);
1279 /* Set local preference rule structure. */
1280 struct route_map_rule_cmd route_set_local_pref_cmd
=
1283 route_set_local_pref
,
1284 route_value_compile
,
1288 /* `set weight WEIGHT' */
1291 static route_map_result_t
1292 route_set_weight (void *rule
, struct prefix
*prefix
, route_map_object_t type
,
1295 struct rmap_value
*rv
;
1296 struct bgp_info
*bgp_info
;
1299 if (type
== RMAP_BGP
)
1301 /* Fetch routemap's rule information. */
1305 /* Set weight value. */
1306 weight
= route_value_adjust(rv
, 0, bgp_info
->peer
);
1308 (bgp_attr_extra_get (bgp_info
->attr
))->weight
= weight
;
1309 else if (bgp_info
->attr
->extra
)
1310 bgp_info
->attr
->extra
->weight
= 0;
1316 /* Set local preference rule structure. */
1317 struct route_map_rule_cmd route_set_weight_cmd
=
1321 route_value_compile
,
1325 /* `set metric METRIC' */
1327 /* Set metric to attribute. */
1328 static route_map_result_t
1329 route_set_metric (void *rule
, struct prefix
*prefix
,
1330 route_map_object_t type
, void *object
)
1332 struct rmap_value
*rv
;
1333 struct bgp_info
*bgp_info
;
1336 if (type
== RMAP_BGP
)
1338 /* Fetch routemap's rule information. */
1342 if (bgp_info
->attr
->flag
& ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
))
1343 med
= bgp_info
->attr
->med
;
1345 bgp_info
->attr
->med
= route_value_adjust(rv
, med
, bgp_info
->peer
);
1346 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC
);
1351 /* Set metric rule structure. */
1352 struct route_map_rule_cmd route_set_metric_cmd
=
1356 route_value_compile
,
1360 /* `set as-path prepend ASPATH' */
1362 /* For AS path prepend mechanism. */
1363 static route_map_result_t
1364 route_set_aspath_prepend (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1366 struct aspath
*aspath
;
1368 struct bgp_info
*binfo
;
1370 if (type
== RMAP_BGP
)
1374 if (binfo
->attr
->aspath
->refcnt
)
1375 new = aspath_dup (binfo
->attr
->aspath
);
1377 new = binfo
->attr
->aspath
;
1379 if ((uintptr_t)rule
> 10)
1382 aspath_prepend (aspath
, new);
1386 as_t as
= aspath_leftmost(new);
1387 if (!as
) as
= binfo
->peer
->as
;
1388 new = aspath_add_seq_n (new, as
, (uintptr_t) rule
);
1391 binfo
->attr
->aspath
= new;
1398 route_set_aspath_prepend_compile (const char *arg
)
1402 if (sscanf(arg
, "last-as %u", &num
) == 1 && num
> 0 && num
< 10)
1403 return (void*)(uintptr_t)num
;
1405 return route_aspath_compile(arg
);
1409 route_set_aspath_prepend_free (void *rule
)
1411 if ((uintptr_t)rule
> 10)
1412 route_aspath_free(rule
);
1416 /* Set as-path prepend rule structure. */
1417 struct route_map_rule_cmd route_set_aspath_prepend_cmd
=
1420 route_set_aspath_prepend
,
1421 route_set_aspath_prepend_compile
,
1422 route_set_aspath_prepend_free
,
1425 /* `set as-path exclude ASn' */
1427 /* For ASN exclude mechanism.
1428 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1429 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1431 static route_map_result_t
1432 route_set_aspath_exclude (void *rule
, struct prefix
*dummy
, route_map_object_t type
, void *object
)
1434 struct aspath
* new_path
, * exclude_path
;
1435 struct bgp_info
*binfo
;
1437 if (type
== RMAP_BGP
)
1439 exclude_path
= rule
;
1441 if (binfo
->attr
->aspath
->refcnt
)
1442 new_path
= aspath_dup (binfo
->attr
->aspath
);
1444 new_path
= binfo
->attr
->aspath
;
1445 binfo
->attr
->aspath
= aspath_filter_exclude (new_path
, exclude_path
);
1450 /* Set ASn exlude rule structure. */
1451 struct route_map_rule_cmd route_set_aspath_exclude_cmd
=
1454 route_set_aspath_exclude
,
1455 route_aspath_compile
,
1459 /* `set community COMMUNITY' */
1462 struct community
*com
;
1467 /* For community set mechanism. */
1468 static route_map_result_t
1469 route_set_community (void *rule
, struct prefix
*prefix
,
1470 route_map_object_t type
, void *object
)
1472 struct rmap_com_set
*rcs
;
1473 struct bgp_info
*binfo
;
1475 struct community
*new = NULL
;
1476 struct community
*old
;
1477 struct community
*merge
;
1479 if (type
== RMAP_BGP
)
1484 old
= attr
->community
;
1489 attr
->flag
&= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
));
1490 attr
->community
= NULL
;
1491 /* See the longer comment down below. */
1492 if (old
&& old
->refcnt
== 0)
1493 community_free(old
);
1497 /* "additive" case. */
1498 if (rcs
->additive
&& old
)
1500 merge
= community_merge (community_dup (old
), rcs
->com
);
1502 /* HACK: if the old community is not intern'd,
1503 * we should free it here, or all reference to it may be lost.
1504 * Really need to cleanup attribute caching sometime.
1506 if (old
->refcnt
== 0)
1507 community_free (old
);
1508 new = community_uniq_sort (merge
);
1509 community_free (merge
);
1512 new = community_dup (rcs
->com
);
1514 /* will be interned by caller if required */
1515 attr
->community
= new;
1517 attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1523 /* Compile function for set community. */
1525 route_set_community_compile (const char *arg
)
1527 struct rmap_com_set
*rcs
;
1528 struct community
*com
= NULL
;
1533 if (strcmp (arg
, "none") == 0)
1537 sp
= strstr (arg
, "additive");
1541 /* "additive" keyworkd is included. */
1546 com
= community_str2com (arg
);
1555 rcs
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct rmap_com_set
));
1557 rcs
->additive
= additive
;
1563 /* Free function for set community. */
1565 route_set_community_free (void *rule
)
1567 struct rmap_com_set
*rcs
= rule
;
1570 community_free (rcs
->com
);
1571 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rcs
);
1574 /* Set community rule structure. */
1575 struct route_map_rule_cmd route_set_community_cmd
=
1578 route_set_community
,
1579 route_set_community_compile
,
1580 route_set_community_free
,
1583 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
1585 /* For community set mechanism. */
1586 static route_map_result_t
1587 route_set_community_delete (void *rule
, struct prefix
*prefix
,
1588 route_map_object_t type
, void *object
)
1590 struct community_list
*list
;
1591 struct community
*merge
;
1592 struct community
*new;
1593 struct community
*old
;
1594 struct bgp_info
*binfo
;
1596 if (type
== RMAP_BGP
)
1602 list
= community_list_lookup (bgp_clist
, rule
, COMMUNITY_LIST_MASTER
);
1603 old
= binfo
->attr
->community
;
1607 merge
= community_list_match_delete (community_dup (old
), list
);
1608 new = community_uniq_sort (merge
);
1609 community_free (merge
);
1611 /* HACK: if the old community is not intern'd,
1612 * we should free it here, or all reference to it may be lost.
1613 * Really need to cleanup attribute caching sometime.
1615 if (old
->refcnt
== 0)
1616 community_free (old
);
1620 binfo
->attr
->community
= NULL
;
1621 binfo
->attr
->flag
&= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1622 community_free (new);
1626 binfo
->attr
->community
= new;
1627 binfo
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES
);
1635 /* Compile function for set community. */
1637 route_set_community_delete_compile (const char *arg
)
1643 p
= strchr (arg
, ' ');
1647 str
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, len
+ 1);
1648 memcpy (str
, arg
, len
);
1656 /* Free function for set community. */
1658 route_set_community_delete_free (void *rule
)
1660 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1663 /* Set community rule structure. */
1664 struct route_map_rule_cmd route_set_community_delete_cmd
=
1667 route_set_community_delete
,
1668 route_set_community_delete_compile
,
1669 route_set_community_delete_free
,
1672 /* `set extcommunity rt COMMUNITY' */
1674 /* For community set mechanism. Used by _rt and _soo. */
1675 static route_map_result_t
1676 route_set_ecommunity (void *rule
, struct prefix
*prefix
,
1677 route_map_object_t type
, void *object
)
1679 struct ecommunity
*ecom
;
1680 struct ecommunity
*new_ecom
;
1681 struct ecommunity
*old_ecom
;
1682 struct bgp_info
*bgp_info
;
1684 if (type
== RMAP_BGP
)
1692 /* We assume additive for Extended Community. */
1693 old_ecom
= (bgp_attr_extra_get (bgp_info
->attr
))->ecommunity
;
1697 new_ecom
= ecommunity_merge (ecommunity_dup (old_ecom
), ecom
);
1699 /* old_ecom->refcnt = 1 => owned elsewhere, e.g. bgp_update_receive()
1700 * ->refcnt = 0 => set by a previous route-map statement */
1701 if (!old_ecom
->refcnt
)
1702 ecommunity_free (&old_ecom
);
1705 new_ecom
= ecommunity_dup (ecom
);
1707 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1708 bgp_info
->attr
->extra
->ecommunity
= new_ecom
;
1710 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES
);
1715 /* Compile function for set community. */
1717 route_set_ecommunity_rt_compile (const char *arg
)
1719 struct ecommunity
*ecom
;
1721 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
1724 return ecommunity_intern (ecom
);
1727 /* Free function for set community. Used by _rt and _soo */
1729 route_set_ecommunity_free (void *rule
)
1731 struct ecommunity
*ecom
= rule
;
1732 ecommunity_unintern (&ecom
);
1735 /* Set community rule structure. */
1736 struct route_map_rule_cmd route_set_ecommunity_rt_cmd
=
1739 route_set_ecommunity
,
1740 route_set_ecommunity_rt_compile
,
1741 route_set_ecommunity_free
,
1744 /* `set extcommunity soo COMMUNITY' */
1746 /* Compile function for set community. */
1748 route_set_ecommunity_soo_compile (const char *arg
)
1750 struct ecommunity
*ecom
;
1752 ecom
= ecommunity_str2com (arg
, ECOMMUNITY_SITE_ORIGIN
, 0);
1756 return ecommunity_intern (ecom
);
1759 /* Set community rule structure. */
1760 struct route_map_rule_cmd route_set_ecommunity_soo_cmd
=
1763 route_set_ecommunity
,
1764 route_set_ecommunity_soo_compile
,
1765 route_set_ecommunity_free
,
1768 /* `set origin ORIGIN' */
1770 /* For origin set. */
1771 static route_map_result_t
1772 route_set_origin (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
1775 struct bgp_info
*bgp_info
;
1777 if (type
== RMAP_BGP
)
1782 bgp_info
->attr
->origin
= *origin
;
1788 /* Compile function for origin set. */
1790 route_set_origin_compile (const char *arg
)
1794 origin
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_char
));
1796 if (strcmp (arg
, "igp") == 0)
1798 else if (strcmp (arg
, "egp") == 0)
1806 /* Compile function for origin set. */
1808 route_set_origin_free (void *rule
)
1810 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1813 /* Set origin rule structure. */
1814 struct route_map_rule_cmd route_set_origin_cmd
=
1818 route_set_origin_compile
,
1819 route_set_origin_free
,
1822 /* `set atomic-aggregate' */
1824 /* For atomic aggregate set. */
1825 static route_map_result_t
1826 route_set_atomic_aggregate (void *rule
, struct prefix
*prefix
,
1827 route_map_object_t type
, void *object
)
1829 struct bgp_info
*bgp_info
;
1831 if (type
== RMAP_BGP
)
1834 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE
);
1840 /* Compile function for atomic aggregate. */
1842 route_set_atomic_aggregate_compile (const char *arg
)
1847 /* Compile function for atomic aggregate. */
1849 route_set_atomic_aggregate_free (void *rule
)
1854 /* Set atomic aggregate rule structure. */
1855 struct route_map_rule_cmd route_set_atomic_aggregate_cmd
=
1858 route_set_atomic_aggregate
,
1859 route_set_atomic_aggregate_compile
,
1860 route_set_atomic_aggregate_free
,
1863 /* `set aggregator as AS A.B.C.D' */
1867 struct in_addr address
;
1870 static route_map_result_t
1871 route_set_aggregator_as (void *rule
, struct prefix
*prefix
,
1872 route_map_object_t type
, void *object
)
1874 struct bgp_info
*bgp_info
;
1875 struct aggregator
*aggregator
;
1876 struct attr_extra
*ae
;
1878 if (type
== RMAP_BGP
)
1882 ae
= bgp_attr_extra_get (bgp_info
->attr
);
1884 ae
->aggregator_as
= aggregator
->as
;
1885 ae
->aggregator_addr
= aggregator
->address
;
1886 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR
);
1893 route_set_aggregator_as_compile (const char *arg
)
1895 struct aggregator
*aggregator
;
1899 aggregator
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct aggregator
));
1900 sscanf (arg
, "%s %s", as
, address
);
1902 aggregator
->as
= strtoul (as
, NULL
, 10);
1903 inet_aton (address
, &aggregator
->address
);
1909 route_set_aggregator_as_free (void *rule
)
1911 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1914 struct route_map_rule_cmd route_set_aggregator_as_cmd
=
1917 route_set_aggregator_as
,
1918 route_set_aggregator_as_compile
,
1919 route_set_aggregator_as_free
,
1922 /* Set tag to object. object must be pointer to struct bgp_info */
1923 static route_map_result_t
1924 route_set_tag (void *rule
, struct prefix
*prefix
,
1925 route_map_object_t type
, void *object
)
1928 struct bgp_info
*bgp_info
;
1929 struct attr_extra
*ae
;
1931 if (type
== RMAP_BGP
)
1935 ae
= bgp_attr_extra_get (bgp_info
->attr
);
1945 /* Route map `tag' compile function. Given string is converted to u_short. */
1947 route_set_tag_compile (const char *arg
)
1952 /* tag value shoud be integer. */
1953 if (! all_digit (arg
))
1961 tag
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (u_short
));
1971 /* Free route map's tag value. */
1973 route_set_tag_free (void *rule
)
1975 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
1979 /* Route map commands for tag set. */
1980 struct route_map_rule_cmd route_set_tag_cmd
=
1984 route_set_tag_compile
,
1990 /* `match ipv6 address IP_ACCESS_LIST' */
1992 static route_map_result_t
1993 route_match_ipv6_address (void *rule
, struct prefix
*prefix
,
1994 route_map_object_t type
, void *object
)
1996 struct access_list
*alist
;
1998 if (type
== RMAP_BGP
)
2000 alist
= access_list_lookup (AFI_IP6
, (char *) rule
);
2002 return RMAP_NOMATCH
;
2004 return (access_list_apply (alist
, prefix
) == FILTER_DENY
?
2005 RMAP_NOMATCH
: RMAP_MATCH
);
2007 return RMAP_NOMATCH
;
2011 route_match_ipv6_address_compile (const char *arg
)
2013 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
2017 route_match_ipv6_address_free (void *rule
)
2019 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2022 /* Route map commands for ip address matching. */
2023 struct route_map_rule_cmd route_match_ipv6_address_cmd
=
2026 route_match_ipv6_address
,
2027 route_match_ipv6_address_compile
,
2028 route_match_ipv6_address_free
2031 /* `match ipv6 next-hop IP_ADDRESS' */
2033 static route_map_result_t
2034 route_match_ipv6_next_hop (void *rule
, struct prefix
*prefix
,
2035 route_map_object_t type
, void *object
)
2037 struct in6_addr
*addr
= rule
;
2038 struct bgp_info
*bgp_info
;
2040 if (type
== RMAP_BGP
)
2044 if (!bgp_info
->attr
->extra
)
2045 return RMAP_NOMATCH
;
2047 if (IPV6_ADDR_SAME (&bgp_info
->attr
->extra
->mp_nexthop_global
, addr
))
2050 if (bgp_info
->attr
->extra
->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
&&
2051 IPV6_ADDR_SAME (&bgp_info
->attr
->extra
->mp_nexthop_local
, rule
))
2054 return RMAP_NOMATCH
;
2057 return RMAP_NOMATCH
;
2061 route_match_ipv6_next_hop_compile (const char *arg
)
2063 struct in6_addr
*address
;
2066 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2068 ret
= inet_pton (AF_INET6
, arg
, address
);
2071 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2079 route_match_ipv6_next_hop_free (void *rule
)
2081 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2084 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd
=
2087 route_match_ipv6_next_hop
,
2088 route_match_ipv6_next_hop_compile
,
2089 route_match_ipv6_next_hop_free
2092 /* `match ipv6 address prefix-list PREFIX_LIST' */
2094 static route_map_result_t
2095 route_match_ipv6_address_prefix_list (void *rule
, struct prefix
*prefix
,
2096 route_map_object_t type
, void *object
)
2098 struct prefix_list
*plist
;
2100 if (type
== RMAP_BGP
)
2102 plist
= prefix_list_lookup (AFI_IP6
, (char *) rule
);
2104 return RMAP_NOMATCH
;
2106 return (prefix_list_apply (plist
, prefix
) == PREFIX_DENY
?
2107 RMAP_NOMATCH
: RMAP_MATCH
);
2109 return RMAP_NOMATCH
;
2113 route_match_ipv6_address_prefix_list_compile (const char *arg
)
2115 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
2119 route_match_ipv6_address_prefix_list_free (void *rule
)
2121 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2124 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
=
2126 "ipv6 address prefix-list",
2127 route_match_ipv6_address_prefix_list
,
2128 route_match_ipv6_address_prefix_list_compile
,
2129 route_match_ipv6_address_prefix_list_free
2132 /* `set ipv6 nexthop global IP_ADDRESS' */
2134 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2135 static route_map_result_t
2136 route_set_ipv6_nexthop_global (void *rule
, struct prefix
*prefix
,
2137 route_map_object_t type
, void *object
)
2139 struct in6_addr
*address
;
2140 struct bgp_info
*bgp_info
;
2142 if (type
== RMAP_BGP
)
2144 /* Fetch routemap's rule information. */
2148 /* Set next hop value. */
2149 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
= *address
;
2151 /* Set nexthop length. */
2152 if (bgp_info
->attr
->extra
->mp_nexthop_len
== 0)
2153 bgp_info
->attr
->extra
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL
;
2155 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2156 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
);
2162 /* Route map `ip next-hop' compile function. Given string is converted
2163 to struct in_addr structure. */
2165 route_set_ipv6_nexthop_global_compile (const char *arg
)
2168 struct in6_addr
*address
;
2170 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2172 ret
= inet_pton (AF_INET6
, arg
, address
);
2176 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2183 /* Free route map's compiled `ip next-hop' value. */
2185 route_set_ipv6_nexthop_global_free (void *rule
)
2187 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2190 /* Route map commands for ip nexthop set. */
2191 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd
=
2193 "ipv6 next-hop global",
2194 route_set_ipv6_nexthop_global
,
2195 route_set_ipv6_nexthop_global_compile
,
2196 route_set_ipv6_nexthop_global_free
2199 /* Set next-hop preference value. */
2200 static route_map_result_t
2201 route_set_ipv6_nexthop_prefer_global (void *rule
, struct prefix
*prefix
,
2202 route_map_object_t type
, void *object
)
2204 struct bgp_info
*bgp_info
;
2207 if (type
== RMAP_BGP
)
2209 /* Fetch routemap's rule information. */
2211 peer
= bgp_info
->peer
;
2213 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
2214 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2216 && sockunion_family (peer
->su_remote
) == AF_INET6
)
2218 /* Set next hop preference to global */
2219 bgp_info
->attr
->extra
->mp_nexthop_prefer_global
= TRUE
;
2220 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2221 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2225 bgp_info
->attr
->extra
->mp_nexthop_prefer_global
= FALSE
;
2226 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2227 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
);
2234 route_set_ipv6_nexthop_prefer_global_compile (const char *arg
)
2238 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (int));
2244 /* Free route map's compiled `ip next-hop' value. */
2246 route_set_ipv6_nexthop_prefer_global_free (void *rule
)
2248 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2251 /* Route map commands for ip nexthop set preferred. */
2252 struct route_map_rule_cmd route_set_ipv6_nexthop_prefer_global_cmd
=
2254 "ipv6 next-hop prefer-global",
2255 route_set_ipv6_nexthop_prefer_global
,
2256 route_set_ipv6_nexthop_prefer_global_compile
,
2257 route_set_ipv6_nexthop_prefer_global_free
2260 /* `set ipv6 nexthop local IP_ADDRESS' */
2262 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2263 static route_map_result_t
2264 route_set_ipv6_nexthop_local (void *rule
, struct prefix
*prefix
,
2265 route_map_object_t type
, void *object
)
2267 struct in6_addr
*address
;
2268 struct bgp_info
*bgp_info
;
2270 if (type
== RMAP_BGP
)
2272 /* Fetch routemap's rule information. */
2276 /* Set next hop value. */
2277 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
= *address
;
2279 /* Set nexthop length. */
2280 if (bgp_info
->attr
->extra
->mp_nexthop_len
!= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
)
2281 bgp_info
->attr
->extra
->mp_nexthop_len
= BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL
;
2283 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2284 BATTR_RMAP_IPV6_LL_NHOP_CHANGED
);
2290 /* Route map `ip nexthop' compile function. Given string is converted
2291 to struct in_addr structure. */
2293 route_set_ipv6_nexthop_local_compile (const char *arg
)
2296 struct in6_addr
*address
;
2298 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in6_addr
));
2300 ret
= inet_pton (AF_INET6
, arg
, address
);
2304 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2311 /* Free route map's compiled `ip nexthop' value. */
2313 route_set_ipv6_nexthop_local_free (void *rule
)
2315 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2318 /* Route map commands for ip nexthop set. */
2319 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd
=
2321 "ipv6 next-hop local",
2322 route_set_ipv6_nexthop_local
,
2323 route_set_ipv6_nexthop_local_compile
,
2324 route_set_ipv6_nexthop_local_free
2327 /* `set ipv6 nexthop peer-address' */
2329 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2330 static route_map_result_t
2331 route_set_ipv6_nexthop_peer (void *rule
, struct prefix
*prefix
,
2332 route_map_object_t type
, void *object
)
2334 struct in6_addr peer_address
;
2335 struct bgp_info
*bgp_info
;
2337 char peer_addr_buf
[INET6_ADDRSTRLEN
];
2339 if (type
== RMAP_BGP
)
2341 /* Fetch routemap's rule information. */
2343 peer
= bgp_info
->peer
;
2345 if ((CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IN
) ||
2346 CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_IMPORT
))
2348 && sockunion_family (peer
->su_remote
) == AF_INET6
)
2350 inet_pton (AF_INET6
, sockunion2str (peer
->su_remote
,
2354 /* Set next hop value and length in attribute. */
2355 if (IN6_IS_ADDR_LINKLOCAL(&peer_address
))
2357 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
= peer_address
;
2358 if (bgp_info
->attr
->extra
->mp_nexthop_len
!= 32)
2359 bgp_info
->attr
->extra
->mp_nexthop_len
= 32;
2363 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
= peer_address
;
2364 if (bgp_info
->attr
->extra
->mp_nexthop_len
== 0)
2365 bgp_info
->attr
->extra
->mp_nexthop_len
= 16;
2369 else if (CHECK_FLAG (peer
->rmap_type
, PEER_RMAP_TYPE_OUT
))
2371 /* The next hop value will be set as part of packet rewrite.
2372 * Set the flags here to indicate that rewrite needs to be done.
2373 * Also, clear the value - we clear both global and link-local
2374 * nexthops, whether we send one or both is determined elsewhere.
2376 SET_FLAG(bgp_info
->attr
->rmap_change_flags
,
2377 BATTR_RMAP_NEXTHOP_PEER_ADDRESS
);
2378 /* clear next hop value. */
2379 memset (&((bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global
),
2380 0, sizeof (struct in6_addr
));
2381 memset (&((bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_local
),
2382 0, sizeof (struct in6_addr
));
2389 /* Route map `ip next-hop' compile function. Given string is converted
2390 to struct in_addr structure. */
2392 route_set_ipv6_nexthop_peer_compile (const char *arg
)
2396 rins
= XCALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (int));
2402 /* Free route map's compiled `ip next-hop' value. */
2404 route_set_ipv6_nexthop_peer_free (void *rule
)
2406 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2409 /* Route map commands for ip nexthop set. */
2410 struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd
=
2412 "ipv6 next-hop peer-address",
2413 route_set_ipv6_nexthop_peer
,
2414 route_set_ipv6_nexthop_peer_compile
,
2415 route_set_ipv6_nexthop_peer_free
2418 #endif /* HAVE_IPV6 */
2420 /* `set vpnv4 nexthop A.B.C.D' */
2422 static route_map_result_t
2423 route_set_vpnv4_nexthop (void *rule
, struct prefix
*prefix
,
2424 route_map_object_t type
, void *object
)
2426 struct in_addr
*address
;
2427 struct bgp_info
*bgp_info
;
2429 if (type
== RMAP_BGP
)
2431 /* Fetch routemap's rule information. */
2435 /* Set next hop value. */
2436 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_global_in
= *address
;
2437 (bgp_attr_extra_get (bgp_info
->attr
))->mp_nexthop_len
= 4;
2444 route_set_vpnv4_nexthop_compile (const char *arg
)
2447 struct in_addr
*address
;
2449 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
2451 ret
= inet_aton (arg
, address
);
2455 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2463 route_set_vpnv4_nexthop_free (void *rule
)
2465 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2468 /* Route map commands for ip nexthop set. */
2469 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd
=
2472 route_set_vpnv4_nexthop
,
2473 route_set_vpnv4_nexthop_compile
,
2474 route_set_vpnv4_nexthop_free
2477 /* `set originator-id' */
2479 /* For origin set. */
2480 static route_map_result_t
2481 route_set_originator_id (void *rule
, struct prefix
*prefix
, route_map_object_t type
, void *object
)
2483 struct in_addr
*address
;
2484 struct bgp_info
*bgp_info
;
2486 if (type
== RMAP_BGP
)
2491 bgp_info
->attr
->flag
|= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID
);
2492 (bgp_attr_extra_get (bgp_info
->attr
))->originator_id
= *address
;
2498 /* Compile function for originator-id set. */
2500 route_set_originator_id_compile (const char *arg
)
2503 struct in_addr
*address
;
2505 address
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
, sizeof (struct in_addr
));
2507 ret
= inet_aton (arg
, address
);
2511 XFREE (MTYPE_ROUTE_MAP_COMPILED
, address
);
2518 /* Compile function for originator_id set. */
2520 route_set_originator_id_free (void *rule
)
2522 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
2525 /* Set originator-id rule structure. */
2526 struct route_map_rule_cmd route_set_originator_id_cmd
=
2529 route_set_originator_id
,
2530 route_set_originator_id_compile
,
2531 route_set_originator_id_free
,
2534 /* Add bgp route map rule. */
2536 bgp_route_match_add (struct vty
*vty
, struct route_map_index
*index
,
2537 const char *command
, const char *arg
,
2538 route_map_event_t type
)
2542 ret
= route_map_add_match (index
, command
, arg
);
2547 case RMAP_RULE_MISSING
:
2548 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2550 case RMAP_COMPILE_ERROR
:
2551 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2556 if (type
!= RMAP_EVENT_MATCH_ADDED
)
2558 route_map_upd8_dependency (type
, arg
, index
->map
->name
);
2564 /* Delete bgp route map rule. */
2566 bgp_route_match_delete (struct vty
*vty
, struct route_map_index
*index
,
2567 const char *command
, const char *arg
,
2568 route_map_event_t type
)
2571 char *dep_name
= NULL
;
2573 char *rmap_name
= NULL
;
2575 if (type
!= RMAP_EVENT_MATCH_DELETED
)
2577 /* ignore the mundane, the types without any dependency */
2580 if ((tmpstr
= route_map_get_match_arg(index
, command
)) != NULL
)
2581 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, tmpstr
);
2585 dep_name
= XSTRDUP(MTYPE_ROUTE_MAP_RULE
, arg
);
2587 rmap_name
= XSTRDUP(MTYPE_ROUTE_MAP_NAME
, index
->map
->name
);
2590 ret
= route_map_delete_match (index
, command
, dep_name
);
2595 case RMAP_RULE_MISSING
:
2596 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2598 case RMAP_COMPILE_ERROR
:
2599 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2603 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2605 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2609 if (type
!= RMAP_EVENT_MATCH_DELETED
&& dep_name
)
2610 route_map_upd8_dependency(type
, dep_name
, rmap_name
);
2613 XFREE(MTYPE_ROUTE_MAP_RULE
, dep_name
);
2615 XFREE(MTYPE_ROUTE_MAP_NAME
, rmap_name
);
2620 /* Add bgp route map rule. */
2622 bgp_route_set_add (struct vty
*vty
, struct route_map_index
*index
,
2623 const char *command
, const char *arg
)
2627 ret
= route_map_add_set (index
, command
, arg
);
2632 case RMAP_RULE_MISSING
:
2633 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2635 case RMAP_COMPILE_ERROR
:
2636 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2643 /* Delete bgp route map rule. */
2645 bgp_route_set_delete (struct vty
*vty
, struct route_map_index
*index
,
2646 const char *command
, const char *arg
)
2650 ret
= route_map_delete_set (index
, command
, arg
);
2655 case RMAP_RULE_MISSING
:
2656 vty_out (vty
, "%% BGP Can't find rule.%s", VTY_NEWLINE
);
2658 case RMAP_COMPILE_ERROR
:
2659 vty_out (vty
, "%% BGP Argument is malformed.%s", VTY_NEWLINE
);
2667 * This is the workhorse routine for processing in/out routemap
2671 bgp_route_map_process_peer (const char *rmap_name
, struct route_map
*map
,
2672 struct peer
*peer
, int afi
, int safi
,
2677 struct bgp_filter
*filter
;
2679 if (!peer
|| !rmap_name
)
2682 filter
= &peer
->filter
[afi
][safi
];
2684 * in is for non-route-server clients,
2685 * out is for all peers
2687 if (!CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
))
2689 if (filter
->map
[RMAP_IN
].name
&&
2690 (strcmp(rmap_name
, filter
->map
[RMAP_IN
].name
) == 0))
2692 filter
->map
[RMAP_IN
].map
= map
;
2694 if (route_update
&& peer
->status
== Established
)
2696 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
],
2697 PEER_FLAG_SOFT_RECONFIG
))
2699 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2700 zlog_debug("Processing route_map %s update on "
2701 "peer %s (inbound, soft-reconfig)",
2702 rmap_name
, peer
->host
);
2704 bgp_soft_reconfig_in (peer
, afi
, safi
);
2706 else if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
2707 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
2710 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2711 zlog_debug("Processing route_map %s update on "
2712 "peer %s (inbound, route-refresh)",
2713 rmap_name
, peer
->host
);
2714 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
2720 if (CHECK_FLAG(peer
->flags
, PEER_FLAG_RSERVER_CLIENT
))
2724 if (update
&& route_update
&& peer
->status
== Established
)
2726 if (CHECK_FLAG (peer
->af_flags
[afi
][safi
],
2727 PEER_FLAG_SOFT_RECONFIG
))
2729 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2730 zlog_debug("Processing route_map %s update on "
2731 "peer %s (import, soft-reconfig)",
2732 rmap_name
, peer
->host
);
2734 bgp_soft_reconfig_in (peer
, afi
, safi
);
2736 else if (CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_OLD_RCV
)
2737 || CHECK_FLAG (peer
->cap
, PEER_CAP_REFRESH_NEW_RCV
))
2739 if (bgp_debug_update(peer
, NULL
, NULL
, 1))
2740 zlog_debug("Processing route_map %s update on "
2741 "peer %s (import, route-refresh)",
2742 rmap_name
, peer
->host
);
2743 bgp_route_refresh_send (peer
, afi
, safi
, 0, 0, 0);
2745 /* DD: Else, what else do we do ? Reset peer ? */
2750 * For outbound, unsuppress and default-originate map change (content or
2751 * map created), merely update the "config" here, the actual route
2752 * announcement happens at the group level.
2754 if (filter
->map
[RMAP_OUT
].name
&&
2755 (strcmp(rmap_name
, filter
->map
[RMAP_OUT
].name
) == 0))
2756 filter
->map
[RMAP_OUT
].map
= map
;
2758 if (filter
->usmap
.name
&&
2759 (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
2760 filter
->usmap
.map
= map
;
2762 if (peer
->default_rmap
[afi
][safi
].name
&&
2763 (strcmp (rmap_name
, peer
->default_rmap
[afi
][safi
].name
) == 0))
2764 peer
->default_rmap
[afi
][safi
].map
= map
;
2768 bgp_route_map_update_peer_group(const char *rmap_name
, struct route_map
*map
,
2771 struct peer_group
*group
;
2772 struct listnode
*node
, *nnode
;
2773 struct bgp_filter
*filter
;
2780 /* All the peers have been updated correctly already. This is
2781 * just updating the placeholder data. No real update required.
2783 for (ALL_LIST_ELEMENTS (bgp
->group
, node
, nnode
, group
))
2784 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2785 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2787 filter
= &group
->conf
->filter
[afi
][safi
];
2789 for (direct
= RMAP_IN
; direct
< RMAP_MAX
; direct
++)
2791 if ((filter
->map
[direct
].name
) &&
2792 (strcmp(rmap_name
, filter
->map
[direct
].name
) == 0))
2793 filter
->map
[direct
].map
= map
;
2796 if (filter
->usmap
.name
&&
2797 (strcmp(rmap_name
, filter
->usmap
.name
) == 0))
2798 filter
->usmap
.map
= map
;
2803 * Note that if an extreme number (tens of thousands) of route-maps are in use
2804 * and if bgp has an extreme number of peers, network statements, etc then this
2805 * function can consume a lot of cycles. This is due to this function being
2806 * called for each route-map and within this function we walk the list of peers,
2807 * network statements, etc looking to see if they use this route-map.
2810 bgp_route_map_process_update (struct bgp
*bgp
, const char *rmap_name
, int route_update
)
2816 struct bgp_node
*bn
;
2817 struct bgp_static
*bgp_static
;
2818 struct listnode
*node
, *nnode
;
2819 struct route_map
*map
;
2820 char buf
[INET6_ADDRSTRLEN
];
2822 map
= route_map_lookup_by_name (rmap_name
);
2824 for (ALL_LIST_ELEMENTS (bgp
->peer
, node
, nnode
, peer
))
2827 /* Ignore dummy peer-group structure */
2828 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_GROUP
))
2831 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2832 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2834 /* Ignore inactive AFI/SAFI */
2835 if (! peer
->afc
[afi
][safi
])
2838 /* process in/out/import/export/default-orig route-maps */
2839 bgp_route_map_process_peer(rmap_name
, map
, peer
, afi
, safi
, route_update
);
2843 /* for outbound/default-orig route-maps, process for groups */
2844 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
,
2847 /* update peer-group config (template) */
2848 bgp_route_map_update_peer_group(rmap_name
, map
, bgp
);
2850 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2851 for (safi
= SAFI_UNICAST
; safi
< SAFI_MAX
; safi
++)
2853 /* For table route-map updates. */
2854 if (bgp
->table_map
[afi
][safi
].name
&&
2855 (strcmp(rmap_name
, bgp
->table_map
[afi
][safi
].name
) == 0))
2857 bgp
->table_map
[afi
][safi
].map
= map
;
2859 if (BGP_DEBUG (zebra
, ZEBRA
))
2860 zlog_debug("Processing route_map %s update on "
2861 "table map", rmap_name
);
2863 bgp_zebra_announce_table(bgp
, afi
, safi
);
2866 /* For network route-map updates. */
2867 for (bn
= bgp_table_top (bgp
->route
[afi
][safi
]); bn
; bn
= bgp_route_next (bn
))
2868 if ((bgp_static
= bn
->info
) != NULL
)
2870 if (bgp_static
->rmap
.name
&&
2871 (strcmp(rmap_name
, bgp_static
->rmap
.name
) == 0))
2873 bgp_static
->rmap
.map
= map
;
2876 if (!bgp_static
->backdoor
)
2878 if (bgp_debug_zebra(&bn
->p
))
2879 zlog_debug("Processing route_map %s update on "
2880 "static route %s", rmap_name
,
2881 inet_ntop (bn
->p
.family
, &bn
->p
.u
.prefix
,
2882 buf
, INET6_ADDRSTRLEN
));
2883 bgp_static_update (bgp
, &bn
->p
, bgp_static
, afi
, safi
);
2889 /* For redistribute route-map updates. */
2890 for (afi
= AFI_IP
; afi
< AFI_MAX
; afi
++)
2891 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
2893 struct list
*red_list
;
2894 struct listnode
*node
;
2895 struct bgp_redist
*red
;
2897 red_list
= bgp
->redist
[afi
][i
];
2901 for (ALL_LIST_ELEMENTS_RO(red_list
, node
, red
))
2903 if (red
->rmap
.name
&&
2904 (strcmp(rmap_name
, red
->rmap
.name
) == 0))
2906 red
->rmap
.map
= map
;
2910 if (BGP_DEBUG (zebra
, ZEBRA
))
2911 zlog_debug("Processing route_map %s update on "
2912 "redistributed routes", rmap_name
);
2914 bgp_redistribute_resend (bgp
, afi
, i
, red
->instance
);
2922 bgp_route_map_process_update_cb (char *rmap_name
)
2924 struct listnode
*node
, *nnode
;
2927 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
2928 bgp_route_map_process_update(bgp
, rmap_name
, 1);
2931 zlog_debug("%s: calling vnc_routemap_update", __func__
);
2932 vnc_routemap_update(bgp
, __func__
);
2938 bgp_route_map_update_timer(struct thread
*thread
)
2940 bm
->t_rmap_update
= NULL
;
2942 route_map_walk_update_list(bgp_route_map_process_update_cb
);
2948 bgp_route_map_mark_update (const char *rmap_name
)
2950 if (bm
->t_rmap_update
== NULL
)
2952 struct listnode
*node
, *nnode
;
2955 /* rmap_update_timer of 0 means don't do route updates */
2956 if (bm
->rmap_update_timer
)
2959 thread_add_timer(bm
->master
, bgp_route_map_update_timer
, NULL
,
2960 bm
->rmap_update_timer
);
2962 /* Signal the groups that a route-map update event has started */
2963 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
2964 update_group_policy_update(bgp
, BGP_POLICY_ROUTE_MAP
, rmap_name
, 1, 1);
2968 for (ALL_LIST_ELEMENTS (bm
->bgp
, node
, nnode
, bgp
))
2969 bgp_route_map_process_update(bgp
, rmap_name
, 0);
2971 zlog_debug("%s: calling vnc_routemap_update", __func__
);
2972 vnc_routemap_update(bgp
, __func__
);
2979 bgp_route_map_add (const char *rmap_name
)
2981 if (route_map_mark_updated(rmap_name
, 0) == 0)
2982 bgp_route_map_mark_update(rmap_name
);
2984 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
2988 bgp_route_map_delete (const char *rmap_name
)
2990 if (route_map_mark_updated(rmap_name
, 1) == 0)
2991 bgp_route_map_mark_update(rmap_name
);
2993 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_DELETED
);
2997 bgp_route_map_event (route_map_event_t event
, const char *rmap_name
)
2999 if (route_map_mark_updated(rmap_name
, 0) == 0)
3000 bgp_route_map_mark_update(rmap_name
);
3002 route_map_notify_dependencies(rmap_name
, RMAP_EVENT_MATCH_ADDED
);
3008 "match peer (A.B.C.D|X:X::X:X)",
3010 "Match peer address\n"
3011 "IP address of peer\n"
3012 "IPv6 address of peer\n")
3014 return bgp_route_match_add (vty
, vty
->index
, "peer", argv
[0],
3015 RMAP_EVENT_MATCH_ADDED
);
3018 DEFUN (match_peer_local
,
3019 match_peer_local_cmd
,
3022 "Match peer address\n"
3023 "Static or Redistributed routes\n")
3025 return bgp_route_match_add (vty
, vty
->index
, "peer", "local",
3026 RMAP_EVENT_MATCH_DELETED
);
3029 DEFUN (no_match_peer
,
3034 "Match peer address\n")
3037 return bgp_route_match_delete (vty
, vty
->index
, "peer", NULL
,
3038 RMAP_EVENT_MATCH_DELETED
);
3040 return bgp_route_match_delete (vty
, vty
->index
, "peer", argv
[0],
3041 RMAP_EVENT_MATCH_DELETED
);
3044 ALIAS (no_match_peer
,
3045 no_match_peer_val_cmd
,
3046 "no match peer (A.B.C.D|X:X::X:X)",
3049 "Match peer address\n"
3050 "IP address of peer\n"
3051 "IPv6 address of peer\n")
3053 ALIAS (no_match_peer
,
3054 no_match_peer_local_cmd
,
3055 "no match peer local",
3058 "Match peer address\n"
3059 "Static or Redistributed routes\n")
3061 DEFUN (match_ip_address
,
3062 match_ip_address_cmd
,
3063 "match ip address (<1-199>|<1300-2699>|WORD)",
3066 "Match address of route\n"
3067 "IP access-list number\n"
3068 "IP access-list number (expanded range)\n"
3069 "IP Access-list name\n")
3071 return bgp_route_match_add (vty
, vty
->index
, "ip address", argv
[0],
3072 RMAP_EVENT_FILTER_ADDED
);
3075 DEFUN (no_match_ip_address
,
3076 no_match_ip_address_cmd
,
3077 "no match ip address",
3081 "Match address of route\n")
3084 return bgp_route_match_delete (vty
, vty
->index
, "ip address", NULL
,
3085 RMAP_EVENT_FILTER_DELETED
);
3087 return bgp_route_match_delete (vty
, vty
->index
, "ip address", argv
[0],
3088 RMAP_EVENT_FILTER_DELETED
);
3091 ALIAS (no_match_ip_address
,
3092 no_match_ip_address_val_cmd
,
3093 "no match ip address (<1-199>|<1300-2699>|WORD)",
3097 "Match address of route\n"
3098 "IP access-list number\n"
3099 "IP access-list number (expanded range)\n"
3100 "IP Access-list name\n")
3102 DEFUN (match_ip_next_hop
,
3103 match_ip_next_hop_cmd
,
3104 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
3107 "Match next-hop address of route\n"
3108 "IP access-list number\n"
3109 "IP access-list number (expanded range)\n"
3110 "IP Access-list name\n")
3112 return bgp_route_match_add (vty
, vty
->index
, "ip next-hop", argv
[0],
3113 RMAP_EVENT_FILTER_ADDED
);
3116 DEFUN (no_match_ip_next_hop
,
3117 no_match_ip_next_hop_cmd
,
3118 "no match ip next-hop",
3122 "Match next-hop address of route\n")
3125 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop", NULL
,
3126 RMAP_EVENT_FILTER_DELETED
);
3128 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop", argv
[0],
3129 RMAP_EVENT_FILTER_DELETED
);
3132 ALIAS (no_match_ip_next_hop
,
3133 no_match_ip_next_hop_val_cmd
,
3134 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
3138 "Match next-hop address of route\n"
3139 "IP access-list number\n"
3140 "IP access-list number (expanded range)\n"
3141 "IP Access-list name\n")
3143 /* match probability { */
3145 DEFUN (match_probability
,
3146 match_probability_cmd
,
3147 "match probability <0-100>",
3149 "Match portion of routes defined by percentage value\n"
3150 "Percentage of routes\n")
3152 return bgp_route_match_add (vty
, vty
->index
, "probability", argv
[0],
3153 RMAP_EVENT_MATCH_ADDED
);
3156 DEFUN (no_match_probability
,
3157 no_match_probability_cmd
,
3158 "no match probability",
3161 "Match portion of routes defined by percentage value\n")
3163 return bgp_route_match_delete (vty
, vty
->index
, "probability", argc
? argv
[0] : NULL
,
3164 RMAP_EVENT_MATCH_DELETED
);
3167 ALIAS (no_match_probability
,
3168 no_match_probability_val_cmd
,
3169 "no match probability <1-99>",
3172 "Match portion of routes defined by percentage value\n"
3173 "Percentage of routes\n")
3177 DEFUN (match_ip_route_source
,
3178 match_ip_route_source_cmd
,
3179 "match ip route-source (<1-199>|<1300-2699>|WORD)",
3182 "Match advertising source address of route\n"
3183 "IP access-list number\n"
3184 "IP access-list number (expanded range)\n"
3185 "IP standard access-list name\n")
3187 return bgp_route_match_add (vty
, vty
->index
, "ip route-source", argv
[0],
3188 RMAP_EVENT_FILTER_ADDED
);
3191 DEFUN (no_match_ip_route_source
,
3192 no_match_ip_route_source_cmd
,
3193 "no match ip route-source",
3197 "Match advertising source address of route\n")
3200 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source", NULL
,
3201 RMAP_EVENT_FILTER_DELETED
);
3203 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source",
3204 argv
[0], RMAP_EVENT_FILTER_DELETED
);
3207 ALIAS (no_match_ip_route_source
,
3208 no_match_ip_route_source_val_cmd
,
3209 "no match ip route-source (<1-199>|<1300-2699>|WORD)",
3213 "Match advertising source address of route\n"
3214 "IP access-list number\n"
3215 "IP access-list number (expanded range)\n"
3216 "IP standard access-list name\n")
3218 DEFUN (match_ip_address_prefix_list
,
3219 match_ip_address_prefix_list_cmd
,
3220 "match ip address prefix-list WORD",
3223 "Match address of route\n"
3224 "Match entries of prefix-lists\n"
3225 "IP prefix-list name\n")
3227 return bgp_route_match_add (vty
, vty
->index
, "ip address prefix-list",
3228 argv
[0], RMAP_EVENT_PLIST_ADDED
);
3231 DEFUN (no_match_ip_address_prefix_list
,
3232 no_match_ip_address_prefix_list_cmd
,
3233 "no match ip address prefix-list",
3237 "Match address of route\n"
3238 "Match entries of prefix-lists\n")
3240 return bgp_route_match_delete (vty
, vty
->index
, "ip address prefix-list",
3241 argc
== 0 ? NULL
: argv
[0],
3242 RMAP_EVENT_PLIST_DELETED
);
3245 ALIAS (no_match_ip_address_prefix_list
,
3246 no_match_ip_address_prefix_list_val_cmd
,
3247 "no match ip address prefix-list WORD",
3251 "Match address of route\n"
3252 "Match entries of prefix-lists\n"
3253 "IP prefix-list name\n")
3255 DEFUN (match_ip_next_hop_prefix_list
,
3256 match_ip_next_hop_prefix_list_cmd
,
3257 "match ip next-hop prefix-list WORD",
3260 "Match next-hop address of route\n"
3261 "Match entries of prefix-lists\n"
3262 "IP prefix-list name\n")
3264 return bgp_route_match_add (vty
, vty
->index
, "ip next-hop prefix-list",
3265 argv
[0], RMAP_EVENT_PLIST_ADDED
);
3268 DEFUN (no_match_ip_next_hop_prefix_list
,
3269 no_match_ip_next_hop_prefix_list_cmd
,
3270 "no match ip next-hop prefix-list",
3274 "Match next-hop address of route\n"
3275 "Match entries of prefix-lists\n")
3277 return bgp_route_match_delete (vty
, vty
->index
, "ip next-hop prefix-list",
3278 argc
== 0 ? NULL
: argv
[0],
3279 RMAP_EVENT_PLIST_DELETED
);
3282 ALIAS (no_match_ip_next_hop_prefix_list
,
3283 no_match_ip_next_hop_prefix_list_val_cmd
,
3284 "no match ip next-hop prefix-list WORD",
3288 "Match next-hop address of route\n"
3289 "Match entries of prefix-lists\n"
3290 "IP prefix-list name\n")
3292 DEFUN (match_ip_route_source_prefix_list
,
3293 match_ip_route_source_prefix_list_cmd
,
3294 "match ip route-source prefix-list WORD",
3297 "Match advertising source address of route\n"
3298 "Match entries of prefix-lists\n"
3299 "IP prefix-list name\n")
3301 return bgp_route_match_add (vty
, vty
->index
, "ip route-source prefix-list",
3302 argv
[0], RMAP_EVENT_PLIST_ADDED
);
3305 DEFUN (no_match_ip_route_source_prefix_list
,
3306 no_match_ip_route_source_prefix_list_cmd
,
3307 "no match ip route-source prefix-list",
3311 "Match advertising source address of route\n"
3312 "Match entries of prefix-lists\n")
3314 return bgp_route_match_delete (vty
, vty
->index
, "ip route-source prefix-list",
3315 argc
== 0 ? NULL
: argv
[0],
3316 RMAP_EVENT_PLIST_DELETED
);
3319 ALIAS (no_match_ip_route_source_prefix_list
,
3320 no_match_ip_route_source_prefix_list_val_cmd
,
3321 "no match ip route-source prefix-list WORD",
3325 "Match advertising source address of route\n"
3326 "Match entries of prefix-lists\n"
3327 "IP prefix-list name\n")
3329 DEFUN (match_metric
,
3331 "match metric <0-4294967295>",
3333 "Match metric of route\n"
3336 return bgp_route_match_add (vty
, vty
->index
, "metric", argv
[0],
3337 RMAP_EVENT_MATCH_ADDED
);
3340 DEFUN (no_match_metric
,
3341 no_match_metric_cmd
,
3345 "Match metric of route\n")
3347 return bgp_route_match_delete (vty
, vty
->index
, "metric",
3348 argc
== 0 ? NULL
: argv
[0],
3349 RMAP_EVENT_MATCH_DELETED
);
3352 ALIAS (no_match_metric
,
3353 no_match_metric_val_cmd
,
3354 "no match metric <0-4294967295>",
3357 "Match metric of route\n"
3360 DEFUN (match_local_pref
,
3361 match_local_pref_cmd
,
3362 "match local-preference <0-4294967295>",
3364 "Match local-preference of route\n"
3367 return bgp_route_match_add (vty
, vty
->index
, "local-preference", argv
[0],
3368 RMAP_EVENT_MATCH_ADDED
);
3371 DEFUN (no_match_local_pref
,
3372 no_match_local_pref_cmd
,
3373 "no match local-preference",
3376 "Match local preference of route\n")
3378 return bgp_route_match_delete (vty
, vty
->index
, "local-preference",
3379 argc
== 0 ? NULL
: argv
[0],
3380 RMAP_EVENT_MATCH_DELETED
);
3382 return bgp_route_match_delete (vty
, vty
->index
, "local-preference", argv
[0],
3383 RMAP_EVENT_MATCH_DELETED
);
3386 ALIAS (no_match_local_pref
,
3387 no_match_local_pref_val_cmd
,
3388 "no match local-preference <0-4294967295>",
3391 "Match local preference of route\n"
3392 "Local preference value\n")
3394 DEFUN (match_community
,
3395 match_community_cmd
,
3396 "match community (<1-99>|<100-500>|WORD)",
3398 "Match BGP community list\n"
3399 "Community-list number (standard)\n"
3400 "Community-list number (expanded)\n"
3401 "Community-list name\n")
3403 return bgp_route_match_add (vty
, vty
->index
, "community", argv
[0],
3404 RMAP_EVENT_CLIST_ADDED
);
3407 DEFUN (match_community_exact
,
3408 match_community_exact_cmd
,
3409 "match community (<1-99>|<100-500>|WORD) exact-match",
3411 "Match BGP community list\n"
3412 "Community-list number (standard)\n"
3413 "Community-list number (expanded)\n"
3414 "Community-list name\n"
3415 "Do exact matching of communities\n")
3420 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
3421 strlen (argv
[0]) + strlen ("exact-match") + 2);
3423 sprintf (argstr
, "%s exact-match", argv
[0]);
3425 ret
= bgp_route_match_add (vty
, vty
->index
, "community", argstr
,
3426 RMAP_EVENT_CLIST_ADDED
);
3428 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
3433 DEFUN (no_match_community
,
3434 no_match_community_cmd
,
3435 "no match community",
3438 "Match BGP community list\n")
3440 return bgp_route_match_delete (vty
, vty
->index
, "community", NULL
,
3441 RMAP_EVENT_CLIST_DELETED
);
3444 ALIAS (no_match_community
,
3445 no_match_community_val_cmd
,
3446 "no match community (<1-99>|<100-500>|WORD)",
3449 "Match BGP community list\n"
3450 "Community-list number (standard)\n"
3451 "Community-list number (expanded)\n"
3452 "Community-list name\n")
3454 ALIAS (no_match_community
,
3455 no_match_community_exact_cmd
,
3456 "no match community (<1-99>|<100-500>|WORD) exact-match",
3459 "Match BGP community list\n"
3460 "Community-list number (standard)\n"
3461 "Community-list number (expanded)\n"
3462 "Community-list name\n"
3463 "Do exact matching of communities\n")
3465 DEFUN (match_ecommunity
,
3466 match_ecommunity_cmd
,
3467 "match extcommunity (<1-99>|<100-500>|WORD)",
3469 "Match BGP/VPN extended community list\n"
3470 "Extended community-list number (standard)\n"
3471 "Extended community-list number (expanded)\n"
3472 "Extended community-list name\n")
3474 return bgp_route_match_add (vty
, vty
->index
, "extcommunity", argv
[0],
3475 RMAP_EVENT_ECLIST_ADDED
);
3478 DEFUN (no_match_ecommunity
,
3479 no_match_ecommunity_cmd
,
3480 "no match extcommunity",
3483 "Match BGP/VPN extended community list\n")
3485 return bgp_route_match_delete (vty
, vty
->index
, "extcommunity", NULL
,
3486 RMAP_EVENT_ECLIST_DELETED
);
3489 ALIAS (no_match_ecommunity
,
3490 no_match_ecommunity_val_cmd
,
3491 "no match extcommunity (<1-99>|<100-500>|WORD)",
3494 "Match BGP/VPN extended community list\n"
3495 "Extended community-list number (standard)\n"
3496 "Extended community-list number (expanded)\n"
3497 "Extended community-list name\n")
3499 DEFUN (match_aspath
,
3501 "match as-path WORD",
3503 "Match BGP AS path list\n"
3504 "AS path access-list name\n")
3506 return bgp_route_match_add (vty
, vty
->index
, "as-path", argv
[0],
3507 RMAP_EVENT_ASLIST_ADDED
);
3510 DEFUN (no_match_aspath
,
3511 no_match_aspath_cmd
,
3515 "Match BGP AS path list\n")
3517 return bgp_route_match_delete (vty
, vty
->index
, "as-path", NULL
,
3518 RMAP_EVENT_ASLIST_DELETED
);
3521 ALIAS (no_match_aspath
,
3522 no_match_aspath_val_cmd
,
3523 "no match as-path WORD",
3526 "Match BGP AS path list\n"
3527 "AS path access-list name\n")
3529 DEFUN (match_origin
,
3531 "match origin (egp|igp|incomplete)",
3536 "unknown heritage\n")
3538 if (strncmp (argv
[0], "igp", 2) == 0)
3539 return bgp_route_match_add (vty
, vty
->index
, "origin", "igp",
3540 RMAP_EVENT_MATCH_ADDED
);
3541 if (strncmp (argv
[0], "egp", 1) == 0)
3542 return bgp_route_match_add (vty
, vty
->index
, "origin", "egp",
3543 RMAP_EVENT_MATCH_ADDED
);
3544 if (strncmp (argv
[0], "incomplete", 2) == 0)
3545 return bgp_route_match_add (vty
, vty
->index
, "origin", "incomplete",
3546 RMAP_EVENT_MATCH_ADDED
);
3551 DEFUN (no_match_origin
,
3552 no_match_origin_cmd
,
3556 "BGP origin code\n")
3558 return bgp_route_match_delete (vty
, vty
->index
, "origin", NULL
,
3559 RMAP_EVENT_MATCH_DELETED
);
3562 ALIAS (no_match_origin
,
3563 no_match_origin_val_cmd
,
3564 "no match origin (egp|igp|incomplete)",
3570 "unknown heritage\n")
3572 DEFUN (match_interface
,
3573 match_interface_cmd
,
3574 "match interface WORD",
3576 "Match first hop interface of route\n"
3579 return bgp_route_match_add (vty
, vty
->index
, "interface", argv
[0],
3580 RMAP_EVENT_MATCH_ADDED
);
3583 DEFUN (no_match_interface
,
3584 no_match_interface_cmd
,
3585 "no match interface",
3588 "Match first hop interface of route\n")
3591 return bgp_route_match_delete (vty
, vty
->index
, "interface", NULL
,
3592 RMAP_EVENT_MATCH_DELETED
);
3594 return bgp_route_match_delete (vty
, vty
->index
, "interface", argv
[0],
3595 RMAP_EVENT_MATCH_DELETED
);
3598 ALIAS (no_match_interface
,
3599 no_match_interface_val_cmd
,
3600 "no match interface WORD",
3603 "Match first hop interface of route\n"
3608 "match tag <1-65535>",
3610 "Match tag of route\n"
3613 return bgp_route_match_add (vty
, vty
->index
, "tag", argv
[0],
3614 RMAP_EVENT_MATCH_ADDED
);
3617 DEFUN (no_match_tag
,
3622 "Match tag of route\n")
3625 return bgp_route_match_delete (vty
, vty
->index
, "tag", NULL
,
3626 RMAP_EVENT_MATCH_DELETED
);
3628 return bgp_route_match_delete (vty
, vty
->index
, "tag", argv
[0],
3629 RMAP_EVENT_MATCH_DELETED
);
3632 ALIAS (no_match_tag
,
3633 no_match_tag_val_cmd
,
3634 "no match tag <1-65535>",
3637 "Match tag of route\n"
3641 DEFUN (set_ip_nexthop
,
3643 "set ip next-hop A.B.C.D",
3646 "Next hop address\n"
3647 "IP address of next hop\n")
3652 ret
= str2sockunion (argv
[0], &su
);
3655 vty_out (vty
, "%% Malformed nexthop address%s", VTY_NEWLINE
);
3658 if (su
.sin
.sin_addr
.s_addr
== 0 ||
3659 IPV4_CLASS_DE(su
.sin
.sin_addr
.s_addr
))
3661 vty_out (vty
, "%% nexthop address cannot be 0.0.0.0, multicast "
3662 "or reserved%s", VTY_NEWLINE
);
3666 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", argv
[0]);
3669 DEFUN (set_ip_nexthop_peer
,
3670 set_ip_nexthop_peer_cmd
,
3671 "set ip next-hop peer-address",
3674 "Next hop address\n"
3675 "Use peer address (for BGP only)\n")
3677 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", "peer-address");
3680 DEFUN (set_ip_nexthop_unchanged
,
3681 set_ip_nexthop_unchanged_cmd
,
3682 "set ip next-hop unchanged",
3685 "Next hop address\n"
3686 "Don't modify existing Next hop address\n")
3688 return bgp_route_set_add (vty
, vty
->index
, "ip next-hop", "unchanged");
3691 DEFUN (no_set_ip_nexthop
,
3692 no_set_ip_nexthop_cmd
,
3693 "no set ip next-hop",
3696 "Next hop address\n")
3699 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", NULL
);
3701 return bgp_route_set_delete (vty
, vty
->index
, "ip next-hop", argv
[0]);
3704 ALIAS (no_set_ip_nexthop
,
3705 no_set_ip_nexthop_val_cmd
,
3706 "no set ip next-hop A.B.C.D",
3710 "Next hop address\n"
3711 "IP address of next hop\n")
3713 ALIAS (no_set_ip_nexthop
,
3714 no_set_ip_nexthop_peer_cmd
,
3715 "no set ip next-hop peer-address",
3719 "Next hop address\n"
3720 "Use peer address (for BGP only)\n")
3724 "set metric <0-4294967295>",
3726 "Metric value for destination routing protocol\n"
3729 return bgp_route_set_add (vty
, vty
->index
, "metric", argv
[0]);
3733 set_metric_addsub_cmd
,
3734 "set metric <+/-metric>",
3736 "Metric value for destination routing protocol\n"
3737 "Add or subtract metric\n")
3741 "set metric (rtt|+rtt|-rtt)",
3743 "Metric value for destination routing protocol\n"
3744 "Assign round trip time\n"
3745 "Add round trip time\n"
3746 "Subtract round trip time\n")
3748 DEFUN (no_set_metric
,
3753 "Metric value for destination routing protocol\n")
3756 return bgp_route_set_delete (vty
, vty
->index
, "metric", NULL
);
3758 return bgp_route_set_delete (vty
, vty
->index
, "metric", argv
[0]);
3761 ALIAS (no_set_metric
,
3762 no_set_metric_val_cmd
,
3763 "no set metric <0-4294967295>",
3766 "Metric value for destination routing protocol\n"
3769 DEFUN (set_local_pref
,
3771 "set local-preference <0-4294967295>",
3773 "BGP local preference path attribute\n"
3774 "Preference value\n")
3776 return bgp_route_set_add (vty
, vty
->index
, "local-preference", argv
[0]);
3779 DEFUN (no_set_local_pref
,
3780 no_set_local_pref_cmd
,
3781 "no set local-preference",
3784 "BGP local preference path attribute\n")
3787 return bgp_route_set_delete (vty
, vty
->index
, "local-preference", NULL
);
3789 return bgp_route_set_delete (vty
, vty
->index
, "local-preference", argv
[0]);
3792 ALIAS (no_set_local_pref
,
3793 no_set_local_pref_val_cmd
,
3794 "no set local-preference <0-4294967295>",
3797 "BGP local preference path attribute\n"
3798 "Preference value\n")
3802 "set weight <0-4294967295>",
3804 "BGP weight for routing table\n"
3807 return bgp_route_set_add (vty
, vty
->index
, "weight", argv
[0]);
3810 DEFUN (no_set_weight
,
3815 "BGP weight for routing table\n")
3818 return bgp_route_set_delete (vty
, vty
->index
, "weight", NULL
);
3820 return bgp_route_set_delete (vty
, vty
->index
, "weight", argv
[0]);
3823 ALIAS (no_set_weight
,
3824 no_set_weight_val_cmd
,
3825 "no set weight <0-4294967295>",
3828 "BGP weight for routing table\n"
3831 DEFUN (set_aspath_prepend
,
3832 set_aspath_prepend_cmd
,
3833 "set as-path prepend ." CMD_AS_RANGE
,
3835 "Transform BGP AS_PATH attribute\n"
3836 "Prepend to the as-path\n"
3842 str
= argv_concat (argv
, argc
, 0);
3843 ret
= bgp_route_set_add (vty
, vty
->index
, "as-path prepend", str
);
3844 XFREE (MTYPE_TMP
, str
);
3849 ALIAS (set_aspath_prepend
,
3850 set_aspath_prepend_lastas_cmd
,
3851 "set as-path prepend (last-as) <1-10>",
3853 "Transform BGP AS_PATH attribute\n"
3854 "Prepend to the as-path\n"
3855 "Use the peer's AS-number\n"
3856 "Number of times to insert")
3858 DEFUN (no_set_aspath_prepend
,
3859 no_set_aspath_prepend_cmd
,
3860 "no set as-path prepend",
3863 "Transform BGP AS_PATH attribute\n"
3864 "Prepend to the as-path\n")
3870 return bgp_route_set_delete (vty
, vty
->index
, "as-path prepend", NULL
);
3872 str
= argv_concat (argv
, argc
, 0);
3873 ret
= bgp_route_set_delete (vty
, vty
->index
, "as-path prepend", str
);
3874 XFREE (MTYPE_TMP
, str
);
3878 ALIAS (no_set_aspath_prepend
,
3879 no_set_aspath_prepend_val_cmd
,
3880 "no set as-path prepend ." CMD_AS_RANGE
,
3883 "Transform BGP AS_PATH attribute\n"
3884 "Prepend to the as-path\n"
3887 DEFUN (set_aspath_exclude
,
3888 set_aspath_exclude_cmd
,
3889 "set as-path exclude ." CMD_AS_RANGE
,
3891 "Transform BGP AS-path attribute\n"
3892 "Exclude from the as-path\n"
3898 str
= argv_concat (argv
, argc
, 0);
3899 ret
= bgp_route_set_add (vty
, vty
->index
, "as-path exclude", str
);
3900 XFREE (MTYPE_TMP
, str
);
3904 DEFUN (no_set_aspath_exclude
,
3905 no_set_aspath_exclude_cmd
,
3906 "no set as-path exclude",
3909 "Transform BGP AS_PATH attribute\n"
3910 "Exclude from the as-path\n")
3916 return bgp_route_set_delete (vty
, vty
->index
, "as-path exclude", NULL
);
3918 str
= argv_concat (argv
, argc
, 0);
3919 ret
= bgp_route_set_delete (vty
, vty
->index
, "as-path exclude", str
);
3920 XFREE (MTYPE_TMP
, str
);
3924 ALIAS (no_set_aspath_exclude
,
3925 no_set_aspath_exclude_val_cmd
,
3926 "no set as-path exclude ." CMD_AS_RANGE
,
3929 "Transform BGP AS_PATH attribute\n"
3930 "Exclude from the as-path\n"
3933 DEFUN (set_community
,
3935 "set community .AA:NN",
3937 "BGP community attribute\n"
3944 struct community
*com
= NULL
;
3949 b
= buffer_new (1024);
3951 for (i
= 0; i
< argc
; i
++)
3953 if (strncmp (argv
[i
], "additive", strlen (argv
[i
])) == 0)
3960 buffer_putc (b
, ' ');
3964 if (strncmp (argv
[i
], "internet", strlen (argv
[i
])) == 0)
3966 buffer_putstr (b
, "internet");
3969 if (strncmp (argv
[i
], "local-AS", strlen (argv
[i
])) == 0)
3971 buffer_putstr (b
, "local-AS");
3974 if (strncmp (argv
[i
], "no-a", strlen ("no-a")) == 0
3975 && strncmp (argv
[i
], "no-advertise", strlen (argv
[i
])) == 0)
3977 buffer_putstr (b
, "no-advertise");
3980 if (strncmp (argv
[i
], "no-e", strlen ("no-e"))== 0
3981 && strncmp (argv
[i
], "no-export", strlen (argv
[i
])) == 0)
3983 buffer_putstr (b
, "no-export");
3986 buffer_putstr (b
, argv
[i
]);
3988 buffer_putc (b
, '\0');
3990 /* Fetch result string then compile it to communities attribute. */
3991 str
= buffer_getstr (b
);
3996 com
= community_str2com (str
);
3997 XFREE (MTYPE_TMP
, str
);
4000 /* Can't compile user input into communities attribute. */
4003 vty_out (vty
, "%% Malformed communities attribute%s", VTY_NEWLINE
);
4007 /* Set communites attribute string. */
4008 str
= community_str (com
);
4012 argstr
= XCALLOC (MTYPE_TMP
, strlen (str
) + strlen (" additive") + 1);
4013 strcpy (argstr
, str
);
4014 strcpy (argstr
+ strlen (str
), " additive");
4015 ret
= bgp_route_set_add (vty
, vty
->index
, "community", argstr
);
4016 XFREE (MTYPE_TMP
, argstr
);
4019 ret
= bgp_route_set_add (vty
, vty
->index
, "community", str
);
4021 community_free (com
);
4026 DEFUN (set_community_none
,
4027 set_community_none_cmd
,
4028 "set community none",
4030 "BGP community attribute\n"
4031 "No community attribute\n")
4033 return bgp_route_set_add (vty
, vty
->index
, "community", "none");
4036 DEFUN (no_set_community
,
4037 no_set_community_cmd
,
4041 "BGP community attribute\n")
4043 return bgp_route_set_delete (vty
, vty
->index
, "community", NULL
);
4046 ALIAS (no_set_community
,
4047 no_set_community_val_cmd
,
4048 "no set community .AA:NN",
4051 "BGP community attribute\n"
4054 ALIAS (no_set_community
,
4055 no_set_community_none_cmd
,
4056 "no set community none",
4059 "BGP community attribute\n"
4060 "No community attribute\n")
4062 DEFUN (set_community_delete
,
4063 set_community_delete_cmd
,
4064 "set comm-list (<1-99>|<100-500>|WORD) delete",
4066 "set BGP community list (for deletion)\n"
4067 "Community-list number (standard)\n"
4068 "Community-list number (expanded)\n"
4069 "Community-list name\n"
4070 "Delete matching communities\n")
4074 str
= XCALLOC (MTYPE_TMP
, strlen (argv
[0]) + strlen (" delete") + 1);
4075 strcpy (str
, argv
[0]);
4076 strcpy (str
+ strlen (argv
[0]), " delete");
4078 bgp_route_set_add (vty
, vty
->index
, "comm-list", str
);
4080 XFREE (MTYPE_TMP
, str
);
4084 DEFUN (no_set_community_delete
,
4085 no_set_community_delete_cmd
,
4089 "set BGP community list (for deletion)\n")
4091 return bgp_route_set_delete (vty
, vty
->index
, "comm-list", NULL
);
4094 ALIAS (no_set_community_delete
,
4095 no_set_community_delete_val_cmd
,
4096 "no set comm-list (<1-99>|<100-500>|WORD) delete",
4099 "set BGP community list (for deletion)\n"
4100 "Community-list number (standard)\n"
4101 "Community-list number (expanded)\n"
4102 "Community-list name\n"
4103 "Delete matching communities\n")
4105 DEFUN (set_ecommunity_rt
,
4106 set_ecommunity_rt_cmd
,
4107 "set extcommunity rt .ASN:nn_or_IP-address:nn",
4109 "BGP extended community attribute\n"
4110 "Route Target extended community\n"
4111 "VPN extended community\n")
4116 str
= argv_concat (argv
, argc
, 0);
4117 ret
= bgp_route_set_add (vty
, vty
->index
, "extcommunity rt", str
);
4118 XFREE (MTYPE_TMP
, str
);
4123 DEFUN (no_set_ecommunity_rt
,
4124 no_set_ecommunity_rt_cmd
,
4125 "no set extcommunity rt",
4128 "BGP extended community attribute\n"
4129 "Route Target extended community\n")
4131 return bgp_route_set_delete (vty
, vty
->index
, "extcommunity rt", NULL
);
4134 ALIAS (no_set_ecommunity_rt
,
4135 no_set_ecommunity_rt_val_cmd
,
4136 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
4139 "BGP extended community attribute\n"
4140 "Route Target extended community\n"
4141 "VPN extended community\n")
4143 DEFUN (set_ecommunity_soo
,
4144 set_ecommunity_soo_cmd
,
4145 "set extcommunity soo .ASN:nn_or_IP-address:nn",
4147 "BGP extended community attribute\n"
4148 "Site-of-Origin extended community\n"
4149 "VPN extended community\n")
4154 str
= argv_concat (argv
, argc
, 0);
4155 ret
= bgp_route_set_add (vty
, vty
->index
, "extcommunity soo", str
);
4156 XFREE (MTYPE_TMP
, str
);
4160 DEFUN (no_set_ecommunity_soo
,
4161 no_set_ecommunity_soo_cmd
,
4162 "no set extcommunity soo",
4165 "BGP extended community attribute\n"
4166 "Site-of-Origin extended community\n")
4168 return bgp_route_set_delete (vty
, vty
->index
, "extcommunity soo", NULL
);
4171 ALIAS (no_set_ecommunity_soo
,
4172 no_set_ecommunity_soo_val_cmd
,
4173 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
4176 "BGP extended community attribute\n"
4177 "Site-of-Origin extended community\n"
4178 "VPN extended community\n")
4182 "set origin (egp|igp|incomplete)",
4187 "unknown heritage\n")
4189 if (strncmp (argv
[0], "igp", 2) == 0)
4190 return bgp_route_set_add (vty
, vty
->index
, "origin", "igp");
4191 if (strncmp (argv
[0], "egp", 1) == 0)
4192 return bgp_route_set_add (vty
, vty
->index
, "origin", "egp");
4193 if (strncmp (argv
[0], "incomplete", 2) == 0)
4194 return bgp_route_set_add (vty
, vty
->index
, "origin", "incomplete");
4199 DEFUN (no_set_origin
,
4204 "BGP origin code\n")
4206 return bgp_route_set_delete (vty
, vty
->index
, "origin", NULL
);
4209 ALIAS (no_set_origin
,
4210 no_set_origin_val_cmd
,
4211 "no set origin (egp|igp|incomplete)",
4217 "unknown heritage\n")
4219 DEFUN (set_atomic_aggregate
,
4220 set_atomic_aggregate_cmd
,
4221 "set atomic-aggregate",
4223 "BGP atomic aggregate attribute\n" )
4225 return bgp_route_set_add (vty
, vty
->index
, "atomic-aggregate", NULL
);
4228 DEFUN (no_set_atomic_aggregate
,
4229 no_set_atomic_aggregate_cmd
,
4230 "no set atomic-aggregate",
4233 "BGP atomic aggregate attribute\n" )
4235 return bgp_route_set_delete (vty
, vty
->index
, "atomic-aggregate", NULL
);
4238 DEFUN (set_aggregator_as
,
4239 set_aggregator_as_cmd
,
4240 "set aggregator as " CMD_AS_RANGE
" A.B.C.D",
4242 "BGP aggregator attribute\n"
4243 "AS number of aggregator\n"
4245 "IP address of aggregator\n")
4248 struct in_addr address
;
4251 ret
= inet_aton (argv
[1], &address
);
4254 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
4258 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
4259 strlen (argv
[0]) + strlen (argv
[1]) + 2);
4261 sprintf (argstr
, "%s %s", argv
[0], argv
[1]);
4263 ret
= bgp_route_set_add (vty
, vty
->index
, "aggregator as", argstr
);
4265 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4270 DEFUN (no_set_aggregator_as
,
4271 no_set_aggregator_as_cmd
,
4272 "no set aggregator as",
4275 "BGP aggregator attribute\n"
4276 "AS number of aggregator\n")
4279 struct in_addr address
;
4283 return bgp_route_set_delete (vty
, vty
->index
, "aggregator as", NULL
);
4285 ret
= inet_aton (argv
[1], &address
);
4288 vty_out (vty
, "Aggregator IP address is invalid%s", VTY_NEWLINE
);
4292 argstr
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
4293 strlen (argv
[0]) + strlen (argv
[1]) + 2);
4295 sprintf (argstr
, "%s %s", argv
[0], argv
[1]);
4297 ret
= bgp_route_set_delete (vty
, vty
->index
, "aggregator as", argstr
);
4299 XFREE (MTYPE_ROUTE_MAP_COMPILED
, argstr
);
4304 ALIAS (no_set_aggregator_as
,
4305 no_set_aggregator_as_val_cmd
,
4306 "no set aggregator as " CMD_AS_RANGE
" A.B.C.D",
4309 "BGP aggregator attribute\n"
4310 "AS number of aggregator\n"
4312 "IP address of aggregator\n")
4316 "set tag <1-65535>",
4318 "Tag value for routing protocol\n"
4321 return bgp_route_set_add (vty
, vty
->index
, "tag", argv
[0]);
4329 "Tag value for routing protocol\n")
4332 bgp_route_set_delete(vty
, vty
->index
, "tag", NULL
);
4334 return bgp_route_set_delete (vty
, vty
->index
, "tag", argv
[0]);
4339 "no set tag <1-65535>",
4342 "Tag value for routing protocol\n"
4347 DEFUN (match_ipv6_address
,
4348 match_ipv6_address_cmd
,
4349 "match ipv6 address WORD",
4352 "Match IPv6 address of route\n"
4353 "IPv6 access-list name\n")
4355 return bgp_route_match_add (vty
, vty
->index
, "ipv6 address", argv
[0],
4356 RMAP_EVENT_FILTER_ADDED
);
4359 DEFUN (no_match_ipv6_address
,
4360 no_match_ipv6_address_cmd
,
4361 "no match ipv6 address WORD",
4365 "Match IPv6 address of route\n"
4366 "IPv6 access-list name\n")
4368 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 address", argv
[0],
4369 RMAP_EVENT_FILTER_DELETED
);
4372 DEFUN (match_ipv6_next_hop
,
4373 match_ipv6_next_hop_cmd
,
4374 "match ipv6 next-hop X:X::X:X",
4377 "Match IPv6 next-hop address of route\n"
4378 "IPv6 address of next hop\n")
4380 return bgp_route_match_add (vty
, vty
->index
, "ipv6 next-hop", argv
[0],
4381 RMAP_EVENT_MATCH_ADDED
);
4384 DEFUN (no_match_ipv6_next_hop
,
4385 no_match_ipv6_next_hop_cmd
,
4386 "no match ipv6 next-hop X:X::X:X",
4390 "Match IPv6 next-hop address of route\n"
4391 "IPv6 address of next hop\n")
4393 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 next-hop", argv
[0],
4394 RMAP_EVENT_MATCH_DELETED
);
4397 DEFUN (match_ipv6_address_prefix_list
,
4398 match_ipv6_address_prefix_list_cmd
,
4399 "match ipv6 address prefix-list WORD",
4402 "Match address of route\n"
4403 "Match entries of prefix-lists\n"
4404 "IP prefix-list name\n")
4406 return bgp_route_match_add (vty
, vty
->index
, "ipv6 address prefix-list",
4407 argv
[0], RMAP_EVENT_PLIST_ADDED
);
4410 DEFUN (no_match_ipv6_address_prefix_list
,
4411 no_match_ipv6_address_prefix_list_cmd
,
4412 "no match ipv6 address prefix-list WORD",
4416 "Match address of route\n"
4417 "Match entries of prefix-lists\n"
4418 "IP prefix-list name\n")
4420 return bgp_route_match_delete (vty
, vty
->index
, "ipv6 address prefix-list",
4421 argv
[0], RMAP_EVENT_PLIST_DELETED
);
4424 DEFUN (set_ipv6_nexthop_peer
,
4425 set_ipv6_nexthop_peer_cmd
,
4426 "set ipv6 next-hop peer-address",
4429 "Next hop address\n"
4430 "Use peer address (for BGP only)\n")
4432 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop peer-address", NULL
);
4435 DEFUN (no_set_ipv6_nexthop_peer
,
4436 no_set_ipv6_nexthop_peer_cmd
,
4437 "no set ipv6 next-hop peer-address",
4441 "IPv6 next-hop address\n"
4442 "Use peer address (for BGP only)\n")
4444 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop peer-address", NULL
);
4447 DEFUN (set_ipv6_nexthop_prefer_global
,
4448 set_ipv6_nexthop_prefer_global_cmd
,
4449 "set ipv6 next-hop prefer-global",
4452 "IPv6 next-hop address\n"
4453 "Prefer global over link-local if both exist\n")
4455 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop prefer-global", NULL
);;
4458 DEFUN (no_set_ipv6_nexthop_prefer_global
,
4459 no_set_ipv6_nexthop_prefer_global_cmd
,
4460 "no set ipv6 next-hop prefer-global",
4464 "IPv6 next-hop address\n"
4465 "Prefer global over link-local if both exist\n")
4467 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop prefer-global", NULL
);
4470 DEFUN (set_ipv6_nexthop_global
,
4471 set_ipv6_nexthop_global_cmd
,
4472 "set ipv6 next-hop global X:X::X:X",
4475 "IPv6 next-hop address\n"
4476 "IPv6 global address\n"
4477 "IPv6 address of next hop\n")
4479 struct in6_addr addr
;
4482 ret
= inet_pton (AF_INET6
, argv
[0], &addr
);
4485 vty_out (vty
, "%% Malformed nexthop address%s", VTY_NEWLINE
);
4488 if (IN6_IS_ADDR_UNSPECIFIED(&addr
) ||
4489 IN6_IS_ADDR_LOOPBACK(&addr
) ||
4490 IN6_IS_ADDR_MULTICAST(&addr
) ||
4491 IN6_IS_ADDR_LINKLOCAL(&addr
))
4493 vty_out (vty
, "%% Invalid global nexthop address%s", VTY_NEWLINE
);
4497 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop global", argv
[0]);
4500 DEFUN (no_set_ipv6_nexthop_global
,
4501 no_set_ipv6_nexthop_global_cmd
,
4502 "no set ipv6 next-hop global",
4506 "IPv6 next-hop address\n"
4507 "IPv6 global address\n")
4510 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop global", NULL
);
4512 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop global", argv
[0]);
4515 ALIAS (no_set_ipv6_nexthop_global
,
4516 no_set_ipv6_nexthop_global_val_cmd
,
4517 "no set ipv6 next-hop global X:X::X:X",
4521 "IPv6 next-hop address\n"
4522 "IPv6 global address\n"
4523 "IPv6 address of next hop\n")
4525 DEFUN (set_ipv6_nexthop_local
,
4526 set_ipv6_nexthop_local_cmd
,
4527 "set ipv6 next-hop local X:X::X:X",
4530 "IPv6 next-hop address\n"
4531 "IPv6 local address\n"
4532 "IPv6 address of next hop\n")
4534 struct in6_addr addr
;
4537 ret
= inet_pton (AF_INET6
, argv
[0], &addr
);
4540 vty_out (vty
, "%% Malformed nexthop address%s", VTY_NEWLINE
);
4543 if (!IN6_IS_ADDR_LINKLOCAL(&addr
))
4545 vty_out (vty
, "%% Invalid link-local nexthop address%s", VTY_NEWLINE
);
4549 return bgp_route_set_add (vty
, vty
->index
, "ipv6 next-hop local", argv
[0]);
4552 DEFUN (no_set_ipv6_nexthop_local
,
4553 no_set_ipv6_nexthop_local_cmd
,
4554 "no set ipv6 next-hop local",
4558 "IPv6 next-hop address\n"
4559 "IPv6 local address\n")
4562 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop local", NULL
);
4564 return bgp_route_set_delete (vty
, vty
->index
, "ipv6 next-hop local", argv
[0]);
4567 ALIAS (no_set_ipv6_nexthop_local
,
4568 no_set_ipv6_nexthop_local_val_cmd
,
4569 "no set ipv6 next-hop local X:X::X:X",
4573 "IPv6 next-hop address\n"
4574 "IPv6 local address\n"
4575 "IPv6 address of next hop\n")
4576 #endif /* HAVE_IPV6 */
4578 DEFUN (set_vpnv4_nexthop
,
4579 set_vpnv4_nexthop_cmd
,
4580 "set vpnv4 next-hop A.B.C.D",
4582 "VPNv4 information\n"
4583 "VPNv4 next-hop address\n"
4584 "IP address of next hop\n")
4586 return bgp_route_set_add (vty
, vty
->index
, "vpnv4 next-hop", argv
[0]);
4589 DEFUN (no_set_vpnv4_nexthop
,
4590 no_set_vpnv4_nexthop_cmd
,
4591 "no set vpnv4 next-hop",
4594 "VPNv4 information\n"
4595 "VPNv4 next-hop address\n")
4598 return bgp_route_set_delete (vty
, vty
->index
, "vpnv4 next-hop", NULL
);
4600 return bgp_route_set_delete (vty
, vty
->index
, "vpnv4 next-hop", argv
[0]);
4603 ALIAS (no_set_vpnv4_nexthop
,
4604 no_set_vpnv4_nexthop_val_cmd
,
4605 "no set vpnv4 next-hop A.B.C.D",
4608 "VPNv4 information\n"
4609 "VPNv4 next-hop address\n"
4610 "IP address of next hop\n")
4612 DEFUN (set_originator_id
,
4613 set_originator_id_cmd
,
4614 "set originator-id A.B.C.D",
4616 "BGP originator ID attribute\n"
4617 "IP address of originator\n")
4619 return bgp_route_set_add (vty
, vty
->index
, "originator-id", argv
[0]);
4622 DEFUN (no_set_originator_id
,
4623 no_set_originator_id_cmd
,
4624 "no set originator-id",
4627 "BGP originator ID attribute\n")
4630 return bgp_route_set_delete (vty
, vty
->index
, "originator-id", NULL
);
4632 return bgp_route_set_delete (vty
, vty
->index
, "originator-id", argv
[0]);
4635 ALIAS (no_set_originator_id
,
4636 no_set_originator_id_val_cmd
,
4637 "no set originator-id A.B.C.D",
4640 "BGP originator ID attribute\n"
4641 "IP address of originator\n")
4643 /* Initialization of route map. */
4645 bgp_route_map_init (void)
4648 route_map_init_vty ();
4649 route_map_add_hook (bgp_route_map_add
);
4650 route_map_delete_hook (bgp_route_map_delete
);
4651 route_map_event_hook (bgp_route_map_event
);
4653 route_map_install_match (&route_match_peer_cmd
);
4654 route_map_install_match (&route_match_local_pref_cmd
);
4655 route_map_install_match (&route_match_ip_address_cmd
);
4656 route_map_install_match (&route_match_ip_next_hop_cmd
);
4657 route_map_install_match (&route_match_ip_route_source_cmd
);
4658 route_map_install_match (&route_match_ip_address_prefix_list_cmd
);
4659 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd
);
4660 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd
);
4661 route_map_install_match (&route_match_aspath_cmd
);
4662 route_map_install_match (&route_match_community_cmd
);
4663 route_map_install_match (&route_match_ecommunity_cmd
);
4664 route_map_install_match (&route_match_local_pref_cmd
);
4665 route_map_install_match (&route_match_metric_cmd
);
4666 route_map_install_match (&route_match_origin_cmd
);
4667 route_map_install_match (&route_match_probability_cmd
);
4668 route_map_install_match (&route_match_interface_cmd
);
4669 route_map_install_match (&route_match_tag_cmd
);
4671 route_map_install_set (&route_set_ip_nexthop_cmd
);
4672 route_map_install_set (&route_set_local_pref_cmd
);
4673 route_map_install_set (&route_set_weight_cmd
);
4674 route_map_install_set (&route_set_metric_cmd
);
4675 route_map_install_set (&route_set_aspath_prepend_cmd
);
4676 route_map_install_set (&route_set_aspath_exclude_cmd
);
4677 route_map_install_set (&route_set_origin_cmd
);
4678 route_map_install_set (&route_set_atomic_aggregate_cmd
);
4679 route_map_install_set (&route_set_aggregator_as_cmd
);
4680 route_map_install_set (&route_set_community_cmd
);
4681 route_map_install_set (&route_set_community_delete_cmd
);
4682 route_map_install_set (&route_set_vpnv4_nexthop_cmd
);
4683 route_map_install_set (&route_set_originator_id_cmd
);
4684 route_map_install_set (&route_set_ecommunity_rt_cmd
);
4685 route_map_install_set (&route_set_ecommunity_soo_cmd
);
4686 route_map_install_set (&route_set_tag_cmd
);
4688 install_element (RMAP_NODE
, &match_peer_cmd
);
4689 install_element (RMAP_NODE
, &match_peer_local_cmd
);
4690 install_element (RMAP_NODE
, &no_match_peer_cmd
);
4691 install_element (RMAP_NODE
, &no_match_peer_val_cmd
);
4692 install_element (RMAP_NODE
, &no_match_peer_local_cmd
);
4693 install_element (RMAP_NODE
, &match_ip_address_cmd
);
4694 install_element (RMAP_NODE
, &no_match_ip_address_cmd
);
4695 install_element (RMAP_NODE
, &no_match_ip_address_val_cmd
);
4696 install_element (RMAP_NODE
, &match_ip_next_hop_cmd
);
4697 install_element (RMAP_NODE
, &no_match_ip_next_hop_cmd
);
4698 install_element (RMAP_NODE
, &no_match_ip_next_hop_val_cmd
);
4699 install_element (RMAP_NODE
, &match_ip_route_source_cmd
);
4700 install_element (RMAP_NODE
, &no_match_ip_route_source_cmd
);
4701 install_element (RMAP_NODE
, &no_match_ip_route_source_val_cmd
);
4702 install_element (RMAP_NODE
, &match_ip_address_prefix_list_cmd
);
4703 install_element (RMAP_NODE
, &no_match_ip_address_prefix_list_cmd
);
4704 install_element (RMAP_NODE
, &no_match_ip_address_prefix_list_val_cmd
);
4705 install_element (RMAP_NODE
, &match_ip_next_hop_prefix_list_cmd
);
4706 install_element (RMAP_NODE
, &no_match_ip_next_hop_prefix_list_cmd
);
4707 install_element (RMAP_NODE
, &no_match_ip_next_hop_prefix_list_val_cmd
);
4708 install_element (RMAP_NODE
, &match_ip_route_source_prefix_list_cmd
);
4709 install_element (RMAP_NODE
, &no_match_ip_route_source_prefix_list_cmd
);
4710 install_element (RMAP_NODE
, &no_match_ip_route_source_prefix_list_val_cmd
);
4712 install_element (RMAP_NODE
, &match_aspath_cmd
);
4713 install_element (RMAP_NODE
, &no_match_aspath_cmd
);
4714 install_element (RMAP_NODE
, &no_match_aspath_val_cmd
);
4715 install_element (RMAP_NODE
, &match_metric_cmd
);
4716 install_element (RMAP_NODE
, &no_match_metric_cmd
);
4717 install_element (RMAP_NODE
, &no_match_metric_val_cmd
);
4718 install_element (RMAP_NODE
, &match_local_pref_cmd
);
4719 install_element (RMAP_NODE
, &no_match_local_pref_cmd
);
4720 install_element (RMAP_NODE
, &no_match_local_pref_val_cmd
);
4721 install_element (RMAP_NODE
, &match_community_cmd
);
4722 install_element (RMAP_NODE
, &match_community_exact_cmd
);
4723 install_element (RMAP_NODE
, &no_match_community_cmd
);
4724 install_element (RMAP_NODE
, &no_match_community_val_cmd
);
4725 install_element (RMAP_NODE
, &no_match_community_exact_cmd
);
4726 install_element (RMAP_NODE
, &match_ecommunity_cmd
);
4727 install_element (RMAP_NODE
, &no_match_ecommunity_cmd
);
4728 install_element (RMAP_NODE
, &no_match_ecommunity_val_cmd
);
4729 install_element (RMAP_NODE
, &match_origin_cmd
);
4730 install_element (RMAP_NODE
, &no_match_origin_cmd
);
4731 install_element (RMAP_NODE
, &no_match_origin_val_cmd
);
4732 install_element (RMAP_NODE
, &match_probability_cmd
);
4733 install_element (RMAP_NODE
, &no_match_probability_cmd
);
4734 install_element (RMAP_NODE
, &no_match_probability_val_cmd
);
4735 install_element (RMAP_NODE
, &match_interface_cmd
);
4736 install_element (RMAP_NODE
, &no_match_interface_cmd
);
4737 install_element (RMAP_NODE
, &no_match_interface_val_cmd
);
4738 install_element (RMAP_NODE
, &match_tag_cmd
);
4739 install_element (RMAP_NODE
, &no_match_tag_cmd
);
4740 install_element (RMAP_NODE
, &no_match_tag_val_cmd
);
4742 install_element (RMAP_NODE
, &set_ip_nexthop_cmd
);
4743 install_element (RMAP_NODE
, &set_ip_nexthop_peer_cmd
);
4744 install_element (RMAP_NODE
, &set_ip_nexthop_unchanged_cmd
);
4745 install_element (RMAP_NODE
, &no_set_ip_nexthop_cmd
);
4746 install_element (RMAP_NODE
, &no_set_ip_nexthop_val_cmd
);
4747 install_element (RMAP_NODE
, &no_set_ip_nexthop_peer_cmd
);
4748 install_element (RMAP_NODE
, &set_local_pref_cmd
);
4749 install_element (RMAP_NODE
, &no_set_local_pref_cmd
);
4750 install_element (RMAP_NODE
, &no_set_local_pref_val_cmd
);
4751 install_element (RMAP_NODE
, &set_weight_cmd
);
4752 install_element (RMAP_NODE
, &no_set_weight_cmd
);
4753 install_element (RMAP_NODE
, &no_set_weight_val_cmd
);
4754 install_element (RMAP_NODE
, &set_metric_cmd
);
4755 install_element (RMAP_NODE
, &set_metric_addsub_cmd
);
4756 install_element (RMAP_NODE
, &set_metric_rtt_cmd
);
4757 install_element (RMAP_NODE
, &no_set_metric_cmd
);
4758 install_element (RMAP_NODE
, &no_set_metric_val_cmd
);
4759 install_element (RMAP_NODE
, &set_aspath_prepend_cmd
);
4760 install_element (RMAP_NODE
, &set_aspath_prepend_lastas_cmd
);
4761 install_element (RMAP_NODE
, &set_aspath_exclude_cmd
);
4762 install_element (RMAP_NODE
, &no_set_aspath_prepend_cmd
);
4763 install_element (RMAP_NODE
, &no_set_aspath_prepend_val_cmd
);
4764 install_element (RMAP_NODE
, &no_set_aspath_exclude_cmd
);
4765 install_element (RMAP_NODE
, &no_set_aspath_exclude_val_cmd
);
4766 install_element (RMAP_NODE
, &set_origin_cmd
);
4767 install_element (RMAP_NODE
, &no_set_origin_cmd
);
4768 install_element (RMAP_NODE
, &no_set_origin_val_cmd
);
4769 install_element (RMAP_NODE
, &set_atomic_aggregate_cmd
);
4770 install_element (RMAP_NODE
, &no_set_atomic_aggregate_cmd
);
4771 install_element (RMAP_NODE
, &set_aggregator_as_cmd
);
4772 install_element (RMAP_NODE
, &no_set_aggregator_as_cmd
);
4773 install_element (RMAP_NODE
, &no_set_aggregator_as_val_cmd
);
4774 install_element (RMAP_NODE
, &set_community_cmd
);
4775 install_element (RMAP_NODE
, &set_community_none_cmd
);
4776 install_element (RMAP_NODE
, &no_set_community_cmd
);
4777 install_element (RMAP_NODE
, &no_set_community_val_cmd
);
4778 install_element (RMAP_NODE
, &no_set_community_none_cmd
);
4779 install_element (RMAP_NODE
, &set_community_delete_cmd
);
4780 install_element (RMAP_NODE
, &no_set_community_delete_cmd
);
4781 install_element (RMAP_NODE
, &no_set_community_delete_val_cmd
);
4782 install_element (RMAP_NODE
, &set_ecommunity_rt_cmd
);
4783 install_element (RMAP_NODE
, &no_set_ecommunity_rt_cmd
);
4784 install_element (RMAP_NODE
, &no_set_ecommunity_rt_val_cmd
);
4785 install_element (RMAP_NODE
, &set_ecommunity_soo_cmd
);
4786 install_element (RMAP_NODE
, &no_set_ecommunity_soo_cmd
);
4787 install_element (RMAP_NODE
, &no_set_ecommunity_soo_val_cmd
);
4788 install_element (RMAP_NODE
, &set_vpnv4_nexthop_cmd
);
4789 install_element (RMAP_NODE
, &no_set_vpnv4_nexthop_cmd
);
4790 install_element (RMAP_NODE
, &no_set_vpnv4_nexthop_val_cmd
);
4791 install_element (RMAP_NODE
, &set_originator_id_cmd
);
4792 install_element (RMAP_NODE
, &no_set_originator_id_cmd
);
4793 install_element (RMAP_NODE
, &no_set_originator_id_val_cmd
);
4794 install_element (RMAP_NODE
, &set_tag_cmd
);
4795 install_element (RMAP_NODE
, &no_set_tag_cmd
);
4796 install_element (RMAP_NODE
, &no_set_tag_val_cmd
);
4799 route_map_install_match (&route_match_ipv6_address_cmd
);
4800 route_map_install_match (&route_match_ipv6_next_hop_cmd
);
4801 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd
);
4802 route_map_install_set (&route_set_ipv6_nexthop_global_cmd
);
4803 route_map_install_set (&route_set_ipv6_nexthop_prefer_global_cmd
);
4804 route_map_install_set (&route_set_ipv6_nexthop_local_cmd
);
4805 route_map_install_set (&route_set_ipv6_nexthop_peer_cmd
);
4807 install_element (RMAP_NODE
, &match_ipv6_address_cmd
);
4808 install_element (RMAP_NODE
, &no_match_ipv6_address_cmd
);
4809 install_element (RMAP_NODE
, &match_ipv6_next_hop_cmd
);
4810 install_element (RMAP_NODE
, &no_match_ipv6_next_hop_cmd
);
4811 install_element (RMAP_NODE
, &match_ipv6_address_prefix_list_cmd
);
4812 install_element (RMAP_NODE
, &no_match_ipv6_address_prefix_list_cmd
);
4813 install_element (RMAP_NODE
, &set_ipv6_nexthop_global_cmd
);
4814 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_cmd
);
4815 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_global_val_cmd
);
4816 install_element (RMAP_NODE
, &set_ipv6_nexthop_prefer_global_cmd
);
4817 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_prefer_global_cmd
);
4818 install_element (RMAP_NODE
, &set_ipv6_nexthop_local_cmd
);
4819 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_local_cmd
);
4820 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_local_val_cmd
);
4821 install_element (RMAP_NODE
, &set_ipv6_nexthop_peer_cmd
);
4822 install_element (RMAP_NODE
, &no_set_ipv6_nexthop_peer_cmd
);
4823 #endif /* HAVE_IPV6 */
4827 bgp_route_map_terminate (void)
4829 /* ToDo: Cleanup all the used memory */
4831 route_map_add_hook (NULL
);
4832 route_map_delete_hook (NULL
);
4833 route_map_event_hook (NULL
);