1
/* Route map function of bgpd.
2
Copyright (C) 1998, 1999 Kunihiro Ishiguro
4
This file is part of GNU Zebra.
6
GNU Zebra is free software; you can redistribute it and/or modify it
7
under the terms of the GNU General Public License as published by the
8
Free Software Foundation; either version 2, or (at your option) any
11
GNU Zebra is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with GNU Zebra; see the file COPYING. If not, write to the Free
18
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
34
#include "regex-gnu.h"
35
#endif /* HAVE_GNU_REGEX */
37
#include "sockunion.h"
39
#include "bgpd/bgpd.h"
40
#include "bgpd/bgp_table.h"
41
#include "bgpd/bgp_attr.h"
42
#include "bgpd/bgp_aspath.h"
43
#include "bgpd/bgp_route.h"
44
#include "bgpd/bgp_regex.h"
45
#include "bgpd/bgp_community.h"
46
#include "bgpd/bgp_clist.h"
47
#include "bgpd/bgp_filter.h"
48
#include "bgpd/bgp_mplsvpn.h"
49
#include "bgpd/bgp_ecommunity.h"
51
/* Memo of route-map commands.
60
ip route-source : Done
64
ipv6 route-source: (This will not be implemented by bgpd)
65
ipv6 prefix-list : Done
66
length : (This will not be implemented by bgpd)
68
route-type : (This will not be implemented by bgpd)
69
tag : (This will not be implemented by bgpd)
71
set as-path prepend : Done
73
automatic-tag : (This will not be implemented by bgpd)
77
default : (This will not be implemented by bgpd)
78
interface : (This will not be implemented by bgpd)
79
ip default : (This will not be implemented by bgpd)
81
ip precedence : (This will not be implemented by bgpd)
82
ip tos : (This will not be implemented by bgpd)
83
level : (This will not be implemented by bgpd)
84
local-preference : Done
88
tag : (This will not be implemented by bgpd)
93
set ipv6 next-hop global: Done
94
set ipv6 next-hop local : Done
98
/* 'match peer (A.B.C.D|X:X::X:X)' */
100
/* Compares the peer specified in the 'match peer' clause with the peer
101
received in bgp_info->peer. If it is the same, or if the peer structure
102
received is a peer_group containing it, returns RMAP_MATCH. */
104
route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type,
108
union sockunion *su2;
109
struct peer_group *group;
111
struct listnode *node, *nnode;
113
if (type == RMAP_BGP)
116
peer = ((struct bgp_info *) object)->peer;
118
if ( ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT) &&
119
! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_EXPORT) )
122
/* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
123
REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
124
su2 = sockunion_str2su ("0.0.0.0");
125
if ( sockunion_same (su, su2) )
127
if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) ||
128
CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE) ||
129
CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_DEFAULT))
131
XFREE (MTYPE_SOCKUNION, su2);
138
XFREE (MTYPE_SOCKUNION, su2);
140
if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
142
if (sockunion_same (su, &peer->su))
150
for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
152
if (sockunion_same (su, &peer->su))
163
route_match_peer_compile (const char *arg)
168
su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion));
170
ret = str2sockunion ( (arg)? arg : "0.0.0.0", su);
172
XFREE (MTYPE_ROUTE_MAP_COMPILED, su);
179
/* Free route map's compiled `ip address' value. */
181
route_match_peer_free (void *rule)
183
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
186
/* Route map commands for ip address matching. */
187
struct route_map_rule_cmd route_match_peer_cmd =
191
route_match_peer_compile,
192
route_match_peer_free
195
/* `match ip address IP_ACCESS_LIST' */
197
/* Match function should return 1 if match is success else return
200
route_match_ip_address (void *rule, struct prefix *prefix,
201
route_map_object_t type, void *object)
203
struct access_list *alist;
204
/* struct prefix_ipv4 match; */
206
if (type == RMAP_BGP)
208
alist = access_list_lookup (AFI_IP, (char *) rule);
212
return (access_list_apply (alist, prefix) == FILTER_DENY ?
213
RMAP_NOMATCH : RMAP_MATCH);
218
/* Route map `ip address' match statement. `arg' should be
221
route_match_ip_address_compile (const char *arg)
223
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
226
/* Free route map's compiled `ip address' value. */
228
route_match_ip_address_free (void *rule)
230
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
233
/* Route map commands for ip address matching. */
234
struct route_map_rule_cmd route_match_ip_address_cmd =
237
route_match_ip_address,
238
route_match_ip_address_compile,
239
route_match_ip_address_free
242
/* `match ip next-hop IP_ADDRESS' */
244
/* Match function return 1 if match is success else return zero. */
246
route_match_ip_next_hop (void *rule, struct prefix *prefix,
247
route_map_object_t type, void *object)
249
struct access_list *alist;
250
struct bgp_info *bgp_info;
251
struct prefix_ipv4 p;
253
if (type == RMAP_BGP)
257
p.prefix = bgp_info->attr->nexthop;
258
p.prefixlen = IPV4_MAX_BITLEN;
260
alist = access_list_lookup (AFI_IP, (char *) rule);
264
return (access_list_apply (alist, &p) == FILTER_DENY ?
265
RMAP_NOMATCH : RMAP_MATCH);
270
/* Route map `ip next-hop' match statement. `arg' is
273
route_match_ip_next_hop_compile (const char *arg)
275
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
278
/* Free route map's compiled `ip address' value. */
280
route_match_ip_next_hop_free (void *rule)
282
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
285
/* Route map commands for ip next-hop matching. */
286
struct route_map_rule_cmd route_match_ip_next_hop_cmd =
289
route_match_ip_next_hop,
290
route_match_ip_next_hop_compile,
291
route_match_ip_next_hop_free
294
/* `match ip route-source ACCESS-LIST' */
296
/* Match function return 1 if match is success else return zero. */
298
route_match_ip_route_source (void *rule, struct prefix *prefix,
299
route_map_object_t type, void *object)
301
struct access_list *alist;
302
struct bgp_info *bgp_info;
304
struct prefix_ipv4 p;
306
if (type == RMAP_BGP)
309
peer = bgp_info->peer;
311
if (! peer || sockunion_family (&peer->su) != AF_INET)
315
p.prefix = peer->su.sin.sin_addr;
316
p.prefixlen = IPV4_MAX_BITLEN;
318
alist = access_list_lookup (AFI_IP, (char *) rule);
322
return (access_list_apply (alist, &p) == FILTER_DENY ?
323
RMAP_NOMATCH : RMAP_MATCH);
328
/* Route map `ip route-source' match statement. `arg' is
331
route_match_ip_route_source_compile (const char *arg)
333
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
336
/* Free route map's compiled `ip address' value. */
338
route_match_ip_route_source_free (void *rule)
340
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
343
/* Route map commands for ip route-source matching. */
344
struct route_map_rule_cmd route_match_ip_route_source_cmd =
347
route_match_ip_route_source,
348
route_match_ip_route_source_compile,
349
route_match_ip_route_source_free
352
/* `match ip address prefix-list PREFIX_LIST' */
355
route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
356
route_map_object_t type, void *object)
358
struct prefix_list *plist;
360
if (type == RMAP_BGP)
362
plist = prefix_list_lookup (AFI_IP, (char *) rule);
366
return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
367
RMAP_NOMATCH : RMAP_MATCH);
373
route_match_ip_address_prefix_list_compile (const char *arg)
375
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
379
route_match_ip_address_prefix_list_free (void *rule)
381
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
384
struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
386
"ip address prefix-list",
387
route_match_ip_address_prefix_list,
388
route_match_ip_address_prefix_list_compile,
389
route_match_ip_address_prefix_list_free
392
/* `match ip next-hop prefix-list PREFIX_LIST' */
395
route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
396
route_map_object_t type, void *object)
398
struct prefix_list *plist;
399
struct bgp_info *bgp_info;
400
struct prefix_ipv4 p;
402
if (type == RMAP_BGP)
406
p.prefix = bgp_info->attr->nexthop;
407
p.prefixlen = IPV4_MAX_BITLEN;
409
plist = prefix_list_lookup (AFI_IP, (char *) rule);
413
return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
414
RMAP_NOMATCH : RMAP_MATCH);
420
route_match_ip_next_hop_prefix_list_compile (const char *arg)
422
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
426
route_match_ip_next_hop_prefix_list_free (void *rule)
428
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
431
struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
433
"ip next-hop prefix-list",
434
route_match_ip_next_hop_prefix_list,
435
route_match_ip_next_hop_prefix_list_compile,
436
route_match_ip_next_hop_prefix_list_free
439
/* `match ip route-source prefix-list PREFIX_LIST' */
442
route_match_ip_route_source_prefix_list (void *rule, struct prefix *prefix,
443
route_map_object_t type, void *object)
445
struct prefix_list *plist;
446
struct bgp_info *bgp_info;
448
struct prefix_ipv4 p;
450
if (type == RMAP_BGP)
453
peer = bgp_info->peer;
455
if (! peer || sockunion_family (&peer->su) != AF_INET)
459
p.prefix = peer->su.sin.sin_addr;
460
p.prefixlen = IPV4_MAX_BITLEN;
462
plist = prefix_list_lookup (AFI_IP, (char *) rule);
466
return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
467
RMAP_NOMATCH : RMAP_MATCH);
473
route_match_ip_route_source_prefix_list_compile (const char *arg)
475
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
479
route_match_ip_route_source_prefix_list_free (void *rule)
481
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
484
struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd =
486
"ip route-source prefix-list",
487
route_match_ip_route_source_prefix_list,
488
route_match_ip_route_source_prefix_list_compile,
489
route_match_ip_route_source_prefix_list_free
492
/* `match metric METRIC' */
494
/* Match function return 1 if match is success else return zero. */
496
route_match_metric (void *rule, struct prefix *prefix,
497
route_map_object_t type, void *object)
500
struct bgp_info *bgp_info;
502
if (type == RMAP_BGP)
507
if (bgp_info->attr->med == *med)
515
/* Route map `match metric' match statement. `arg' is MED value */
517
route_match_metric_compile (const char *arg)
521
unsigned long tmpval;
523
tmpval = strtoul (arg, &endptr, 10);
524
if (*endptr != '\0' || tmpval == ULONG_MAX || tmpval > UINT32_MAX)
527
med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
536
/* Free route map's compiled `match metric' value. */
538
route_match_metric_free (void *rule)
540
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
543
/* Route map commands for metric matching. */
544
struct route_map_rule_cmd route_match_metric_cmd =
548
route_match_metric_compile,
549
route_match_metric_free
552
/* `match as-path ASPATH' */
554
/* Match function for as-path match. I assume given object is */
556
route_match_aspath (void *rule, struct prefix *prefix,
557
route_map_object_t type, void *object)
560
struct as_list *as_list;
561
struct bgp_info *bgp_info;
563
if (type == RMAP_BGP)
565
as_list = as_list_lookup ((char *) rule);
572
return ((as_list_apply (as_list, bgp_info->attr->aspath) == AS_FILTER_DENY) ? RMAP_NOMATCH : RMAP_MATCH);
577
/* Compile function for as-path match. */
579
route_match_aspath_compile (const char *arg)
581
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
584
/* Compile function for as-path match. */
586
route_match_aspath_free (void *rule)
588
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
591
/* Route map commands for aspath matching. */
592
struct route_map_rule_cmd route_match_aspath_cmd =
596
route_match_aspath_compile,
597
route_match_aspath_free
600
#if ROUTE_MATCH_ASPATH_OLD
601
/* `match as-path ASPATH' */
603
/* Match function for as-path match. I assume given object is */
605
route_match_aspath (void *rule, struct prefix *prefix, void *object)
608
struct bgp_info *bgp_info;
614
return bgp_regexec (regex, bgp_info->attr->aspath);
617
/* Compile function for as-path match. */
619
route_match_aspath_compile (const char *arg)
623
regex = bgp_regcomp (arg);
630
/* Compile function for as-path match. */
632
route_match_aspath_free (void *rule)
634
regex_t *regex = rule;
636
bgp_regex_free (regex);
639
/* Route map commands for aspath matching. */
640
struct route_map_rule_cmd route_match_aspath_cmd =
644
route_match_aspath_compile,
645
route_match_aspath_free
647
#endif /* ROUTE_MATCH_ASPATH_OLD */
649
/* `match community COMMUNIY' */
650
struct rmap_community
656
/* Match function for community match. */
658
route_match_community (void *rule, struct prefix *prefix,
659
route_map_object_t type, void *object)
661
struct community_list *list;
662
struct bgp_info *bgp_info;
663
struct rmap_community *rcom;
665
if (type == RMAP_BGP)
670
list = community_list_lookup (bgp_clist, rcom->name, COMMUNITY_LIST_MASTER);
676
if (community_list_exact_match (bgp_info->attr->community, list))
681
if (community_list_match (bgp_info->attr->community, list))
688
/* Compile function for community match. */
690
route_match_community_compile (const char *arg)
692
struct rmap_community *rcom;
696
rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community));
698
p = strchr (arg, ' ');
702
rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
703
memcpy (rcom->name, arg, len);
708
rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
714
/* Compile function for community match. */
716
route_match_community_free (void *rule)
718
struct rmap_community *rcom = rule;
720
XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name);
721
XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom);
724
/* Route map commands for community matching. */
725
struct route_map_rule_cmd route_match_community_cmd =
728
route_match_community,
729
route_match_community_compile,
730
route_match_community_free
733
/* Match function for extcommunity match. */
735
route_match_ecommunity (void *rule, struct prefix *prefix,
736
route_map_object_t type, void *object)
738
struct community_list *list;
739
struct bgp_info *bgp_info;
741
if (type == RMAP_BGP)
745
list = community_list_lookup (bgp_clist, (char *) rule,
746
EXTCOMMUNITY_LIST_MASTER);
750
if (ecommunity_list_match (bgp_info->attr->ecommunity, list))
756
/* Compile function for extcommunity match. */
758
route_match_ecommunity_compile (const char *arg)
760
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
763
/* Compile function for extcommunity match. */
765
route_match_ecommunity_free (void *rule)
767
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
770
/* Route map commands for community matching. */
771
struct route_map_rule_cmd route_match_ecommunity_cmd =
774
route_match_ecommunity,
775
route_match_ecommunity_compile,
776
route_match_ecommunity_free
779
/* `match nlri` and `set nlri` are replaced by `address-family ipv4`
780
and `address-family vpnv4'. */
784
route_match_origin (void *rule, struct prefix *prefix,
785
route_map_object_t type, void *object)
788
struct bgp_info *bgp_info;
790
if (type == RMAP_BGP)
795
if (bgp_info->attr->origin == *origin)
803
route_match_origin_compile (const char *arg)
807
origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
809
if (strcmp (arg, "igp") == 0)
811
else if (strcmp (arg, "egp") == 0)
819
/* Free route map's compiled `ip address' value. */
821
route_match_origin_free (void *rule)
823
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
826
/* Route map commands for origin matching. */
827
struct route_map_rule_cmd route_match_origin_cmd =
831
route_match_origin_compile,
832
route_match_origin_free
834
/* `set ip next-hop IP_ADDRESS' */
836
/* Set nexthop to object. ojbect must be pointer to struct attr. */
837
struct rmap_ip_nexthop_set
839
struct in_addr *address;
844
route_set_ip_nexthop (void *rule, struct prefix *prefix,
845
route_map_object_t type, void *object)
847
struct rmap_ip_nexthop_set *rins = rule;
848
struct in_addr peer_address;
849
struct bgp_info *bgp_info;
852
if (type == RMAP_BGP)
855
peer = bgp_info->peer;
857
if (rins->peer_address)
859
if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) ||
860
CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
862
&& sockunion_family (peer->su_remote) == AF_INET)
864
inet_aton (sockunion_su2str (peer->su_remote), &peer_address);
865
bgp_info->attr->nexthop = peer_address;
866
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
868
else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
870
&& sockunion_family (peer->su_local) == AF_INET)
872
inet_aton (sockunion_su2str (peer->su_local), &peer_address);
873
bgp_info->attr->nexthop = peer_address;
874
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
879
/* Set next hop value. */
880
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
881
bgp_info->attr->nexthop = *rins->address;
888
/* Route map `ip nexthop' compile function. Given string is converted
889
to struct in_addr structure. */
891
route_set_ip_nexthop_compile (const char *arg)
893
struct rmap_ip_nexthop_set *rins;
894
struct in_addr *address = NULL;
895
int peer_address = 0;
898
if (strcmp (arg, "peer-address") == 0)
902
address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
903
ret = inet_aton (arg, address);
907
XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
912
rins = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set));
913
memset (rins, 0, sizeof (struct rmap_ip_nexthop_set));
915
rins->address = address;
916
rins->peer_address = peer_address;
921
/* Free route map's compiled `ip nexthop' value. */
923
route_set_ip_nexthop_free (void *rule)
925
struct rmap_ip_nexthop_set *rins = rule;
928
XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address);
930
XFREE (MTYPE_ROUTE_MAP_COMPILED, rins);
933
/* Route map commands for ip nexthop set. */
934
struct route_map_rule_cmd route_set_ip_nexthop_cmd =
937
route_set_ip_nexthop,
938
route_set_ip_nexthop_compile,
939
route_set_ip_nexthop_free
942
/* `set local-preference LOCAL_PREF' */
944
/* Set local preference. */
946
route_set_local_pref (void *rule, struct prefix *prefix,
947
route_map_object_t type, void *object)
949
u_int32_t *local_pref;
950
struct bgp_info *bgp_info;
952
if (type == RMAP_BGP)
954
/* Fetch routemap's rule information. */
958
/* Set local preference value. */
959
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
960
bgp_info->attr->local_pref = *local_pref;
966
/* set local preference compilation. */
968
route_set_local_pref_compile (const char *arg)
971
u_int32_t *local_pref;
974
/* Local preference value shoud be integer. */
975
if (! all_digit (arg))
978
tmp = strtoul (arg, &endptr, 10);
979
if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX)
982
local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
992
/* Free route map's local preference value. */
994
route_set_local_pref_free (void *rule)
996
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
999
/* Set local preference rule structure. */
1000
struct route_map_rule_cmd route_set_local_pref_cmd =
1003
route_set_local_pref,
1004
route_set_local_pref_compile,
1005
route_set_local_pref_free,
1008
/* `set weight WEIGHT' */
1012
route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type,
1016
struct bgp_info *bgp_info;
1018
if (type == RMAP_BGP)
1020
/* Fetch routemap's rule information. */
1024
/* Set weight value. */
1025
bgp_info->attr->weight = *weight;
1031
/* set local preference compilation. */
1033
route_set_weight_compile (const char *arg)
1037
char *endptr = NULL;
1039
/* Local preference value shoud be integer. */
1040
if (! all_digit (arg))
1044
tmp = strtoul (arg, &endptr, 10);
1045
if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX)
1048
weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
1058
/* Free route map's local preference value. */
1060
route_set_weight_free (void *rule)
1062
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1065
/* Set local preference rule structure. */
1066
struct route_map_rule_cmd route_set_weight_cmd =
1070
route_set_weight_compile,
1071
route_set_weight_free,
1074
/* `set metric METRIC' */
1076
/* Set metric to attribute. */
1078
route_set_metric (void *rule, struct prefix *prefix,
1079
route_map_object_t type, void *object)
1082
u_int32_t metric_val;
1083
struct bgp_info *bgp_info;
1085
if (type == RMAP_BGP)
1087
/* Fetch routemap's rule information. */
1091
if (! (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
1092
bgp_info->attr->med = 0;
1093
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
1095
if (all_digit (metric))
1097
metric_val = strtoul (metric, (char **)NULL, 10);
1098
bgp_info->attr->med = metric_val;
1102
metric_val = strtoul (metric+1, (char **)NULL, 10);
1104
if (strncmp (metric, "+", 1) == 0)
1106
if (bgp_info->attr->med/2 + metric_val/2 > BGP_MED_MAX/2)
1107
bgp_info->attr->med = BGP_MED_MAX - 1;
1109
bgp_info->attr->med += metric_val;
1111
else if (strncmp (metric, "-", 1) == 0)
1113
if (bgp_info->attr->med <= metric_val)
1114
bgp_info->attr->med = 0;
1116
bgp_info->attr->med -= metric_val;
1123
/* set metric compilation. */
1125
route_set_metric_compile (const char *arg)
1128
char *endptr = NULL;
1130
if (all_digit (arg))
1132
/* set metric value check*/
1133
metric = strtoul (arg, &endptr, 10);
1134
if (*endptr != '\0' || metric == ULONG_MAX)
1139
/* set metric +/-value check */
1140
if ((strncmp (arg, "+", 1) != 0
1141
&& strncmp (arg, "-", 1) != 0)
1142
|| (! all_digit (arg+1)))
1145
metric = strtoul (arg+1, &endptr, 10);
1146
if (*endptr != '\0' || metric == ULONG_MAX)
1150
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1153
/* Free route map's compiled `set metric' value. */
1155
route_set_metric_free (void *rule)
1157
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1160
/* Set metric rule structure. */
1161
struct route_map_rule_cmd route_set_metric_cmd =
1165
route_set_metric_compile,
1166
route_set_metric_free,
1169
/* `set as-path prepend ASPATH' */
1171
/* For AS path prepend mechanism. */
1173
route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1175
struct aspath *aspath;
1177
struct bgp_info *binfo;
1179
if (type == RMAP_BGP)
1184
if (binfo->attr->aspath->refcnt)
1185
new = aspath_dup (binfo->attr->aspath);
1187
new = binfo->attr->aspath;
1189
aspath_prepend (aspath, new);
1190
binfo->attr->aspath = new;
1196
/* Compile function for as-path prepend. */
1198
route_set_aspath_prepend_compile (const char *arg)
1200
struct aspath *aspath;
1202
aspath = aspath_str2aspath (arg);
1208
/* Compile function for as-path prepend. */
1210
route_set_aspath_prepend_free (void *rule)
1212
struct aspath *aspath = rule;
1213
aspath_free (aspath);
1216
/* Set metric rule structure. */
1217
struct route_map_rule_cmd route_set_aspath_prepend_cmd =
1220
route_set_aspath_prepend,
1221
route_set_aspath_prepend_compile,
1222
route_set_aspath_prepend_free,
1225
/* `set community COMMUNITY' */
1228
struct community *com;
1233
/* For community set mechanism. */
1235
route_set_community (void *rule, struct prefix *prefix,
1236
route_map_object_t type, void *object)
1238
struct rmap_com_set *rcs;
1239
struct bgp_info *binfo;
1241
struct community *new = NULL;
1242
struct community *old;
1243
struct community *merge;
1245
if (type == RMAP_BGP)
1250
old = attr->community;
1255
attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES));
1256
attr->community = NULL;
1260
/* "additive" case. */
1261
if (rcs->additive && old)
1263
merge = community_merge (community_dup (old), rcs->com);
1264
new = community_uniq_sort (merge);
1265
community_free (merge);
1268
new = community_dup (rcs->com);
1270
attr->community = new;
1271
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1277
/* Compile function for set community. */
1279
route_set_community_compile (const char *arg)
1281
struct rmap_com_set *rcs;
1282
struct community *com = NULL;
1287
if (strcmp (arg, "none") == 0)
1291
sp = strstr (arg, "additive");
1295
/* "additive" keyworkd is included. */
1300
com = community_str2com (arg);
1309
rcs = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
1310
memset (rcs, 0, sizeof (struct rmap_com_set));
1313
rcs->additive = additive;
1319
/* Free function for set community. */
1321
route_set_community_free (void *rule)
1323
struct rmap_com_set *rcs = rule;
1326
community_free (rcs->com);
1327
XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs);
1330
/* Set community rule structure. */
1331
struct route_map_rule_cmd route_set_community_cmd =
1334
route_set_community,
1335
route_set_community_compile,
1336
route_set_community_free,
1339
/* `set comm-list (<1-99>|<100-500>|WORD) delete' */
1341
/* For community set mechanism. */
1343
route_set_community_delete (void *rule, struct prefix *prefix,
1344
route_map_object_t type, void *object)
1346
struct community_list *list;
1347
struct community *merge;
1348
struct community *new;
1349
struct community *old;
1350
struct bgp_info *binfo;
1352
if (type == RMAP_BGP)
1358
list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER);
1359
old = binfo->attr->community;
1363
merge = community_list_match_delete (community_dup (old), list);
1364
new = community_uniq_sort (merge);
1365
community_free (merge);
1369
binfo->attr->community = NULL;
1370
binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1371
community_free (new);
1375
binfo->attr->community = new;
1376
binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1384
/* Compile function for set community. */
1386
route_set_community_delete_compile (const char *arg)
1392
p = strchr (arg, ' ');
1396
str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
1397
memcpy (str, arg, len);
1405
/* Free function for set community. */
1407
route_set_community_delete_free (void *rule)
1409
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1412
/* Set community rule structure. */
1413
struct route_map_rule_cmd route_set_community_delete_cmd =
1416
route_set_community_delete,
1417
route_set_community_delete_compile,
1418
route_set_community_delete_free,
1421
/* `set extcommunity rt COMMUNITY' */
1423
/* For community set mechanism. */
1425
route_set_ecommunity_rt (void *rule, struct prefix *prefix,
1426
route_map_object_t type, void *object)
1428
struct ecommunity *ecom;
1429
struct ecommunity *new_ecom;
1430
struct ecommunity *old_ecom;
1431
struct bgp_info *bgp_info;
1433
if (type == RMAP_BGP)
1441
/* We assume additive for Extended Community. */
1442
old_ecom = bgp_info->attr->ecommunity;
1445
new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
1447
new_ecom = ecommunity_dup (ecom);
1449
bgp_info->attr->ecommunity = new_ecom;
1451
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
1456
/* Compile function for set community. */
1458
route_set_ecommunity_rt_compile (const char *arg)
1460
struct ecommunity *ecom;
1462
ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0);
1468
/* Free function for set community. */
1470
route_set_ecommunity_rt_free (void *rule)
1472
struct ecommunity *ecom = rule;
1473
ecommunity_free (ecom);
1476
/* Set community rule structure. */
1477
struct route_map_rule_cmd route_set_ecommunity_rt_cmd =
1480
route_set_ecommunity_rt,
1481
route_set_ecommunity_rt_compile,
1482
route_set_ecommunity_rt_free,
1485
/* `set extcommunity soo COMMUNITY' */
1487
/* For community set mechanism. */
1489
route_set_ecommunity_soo (void *rule, struct prefix *prefix,
1490
route_map_object_t type, void *object)
1492
struct ecommunity *ecom;
1493
struct bgp_info *bgp_info;
1495
if (type == RMAP_BGP)
1503
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
1504
bgp_info->attr->ecommunity = ecommunity_dup (ecom);
1509
/* Compile function for set community. */
1511
route_set_ecommunity_soo_compile (const char *arg)
1513
struct ecommunity *ecom;
1515
ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0);
1522
/* Free function for set community. */
1524
route_set_ecommunity_soo_free (void *rule)
1526
struct ecommunity *ecom = rule;
1527
ecommunity_free (ecom);
1530
/* Set community rule structure. */
1531
struct route_map_rule_cmd route_set_ecommunity_soo_cmd =
1534
route_set_ecommunity_soo,
1535
route_set_ecommunity_soo_compile,
1536
route_set_ecommunity_soo_free,
1539
/* `set origin ORIGIN' */
1541
/* For origin set. */
1543
route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1546
struct bgp_info *bgp_info;
1548
if (type == RMAP_BGP)
1553
bgp_info->attr->origin = *origin;
1559
/* Compile function for origin set. */
1561
route_set_origin_compile (const char *arg)
1565
origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
1567
if (strcmp (arg, "igp") == 0)
1569
else if (strcmp (arg, "egp") == 0)
1577
/* Compile function for origin set. */
1579
route_set_origin_free (void *rule)
1581
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1584
/* Set metric rule structure. */
1585
struct route_map_rule_cmd route_set_origin_cmd =
1589
route_set_origin_compile,
1590
route_set_origin_free,
1593
/* `set atomic-aggregate' */
1595
/* For atomic aggregate set. */
1597
route_set_atomic_aggregate (void *rule, struct prefix *prefix,
1598
route_map_object_t type, void *object)
1600
struct bgp_info *bgp_info;
1602
if (type == RMAP_BGP)
1605
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
1611
/* Compile function for atomic aggregate. */
1613
route_set_atomic_aggregate_compile (const char *arg)
1618
/* Compile function for atomic aggregate. */
1620
route_set_atomic_aggregate_free (void *rule)
1625
/* Set atomic aggregate rule structure. */
1626
struct route_map_rule_cmd route_set_atomic_aggregate_cmd =
1629
route_set_atomic_aggregate,
1630
route_set_atomic_aggregate_compile,
1631
route_set_atomic_aggregate_free,
1634
/* `set aggregator as AS A.B.C.D' */
1638
struct in_addr address;
1642
route_set_aggregator_as (void *rule, struct prefix *prefix,
1643
route_map_object_t type, void *object)
1645
struct bgp_info *bgp_info;
1646
struct aggregator *aggregator;
1648
if (type == RMAP_BGP)
1653
bgp_info->attr->aggregator_as = aggregator->as;
1654
bgp_info->attr->aggregator_addr = aggregator->address;
1655
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
1662
route_set_aggregator_as_compile (const char *arg)
1664
struct aggregator *aggregator;
1668
aggregator = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));
1669
memset (aggregator, 0, sizeof (struct aggregator));
1671
sscanf (arg, "%s %s", as, address);
1673
aggregator->as = strtoul (as, NULL, 10);
1674
inet_aton (address, &aggregator->address);
1680
route_set_aggregator_as_free (void *rule)
1682
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1685
struct route_map_rule_cmd route_set_aggregator_as_cmd =
1688
route_set_aggregator_as,
1689
route_set_aggregator_as_compile,
1690
route_set_aggregator_as_free,
1694
/* `match ipv6 address IP_ACCESS_LIST' */
1697
route_match_ipv6_address (void *rule, struct prefix *prefix,
1698
route_map_object_t type, void *object)
1700
struct access_list *alist;
1702
if (type == RMAP_BGP)
1704
alist = access_list_lookup (AFI_IP6, (char *) rule);
1706
return RMAP_NOMATCH;
1708
return (access_list_apply (alist, prefix) == FILTER_DENY ?
1709
RMAP_NOMATCH : RMAP_MATCH);
1711
return RMAP_NOMATCH;
1715
route_match_ipv6_address_compile (const char *arg)
1717
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1721
route_match_ipv6_address_free (void *rule)
1723
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1726
/* Route map commands for ip address matching. */
1727
struct route_map_rule_cmd route_match_ipv6_address_cmd =
1730
route_match_ipv6_address,
1731
route_match_ipv6_address_compile,
1732
route_match_ipv6_address_free
1735
/* `match ipv6 next-hop IP_ADDRESS' */
1738
route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
1739
route_map_object_t type, void *object)
1741
struct in6_addr *addr;
1742
struct bgp_info *bgp_info;
1744
if (type == RMAP_BGP)
1749
if (IPV6_ADDR_SAME (&bgp_info->attr->mp_nexthop_global, rule))
1752
if (bgp_info->attr->mp_nexthop_len == 32 &&
1753
IPV6_ADDR_SAME (&bgp_info->attr->mp_nexthop_local, rule))
1756
return RMAP_NOMATCH;
1759
return RMAP_NOMATCH;
1763
route_match_ipv6_next_hop_compile (const char *arg)
1765
struct in6_addr *address;
1768
address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1770
ret = inet_pton (AF_INET6, arg, address);
1773
XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1781
route_match_ipv6_next_hop_free (void *rule)
1783
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1786
struct route_map_rule_cmd route_match_ipv6_next_hop_cmd =
1789
route_match_ipv6_next_hop,
1790
route_match_ipv6_next_hop_compile,
1791
route_match_ipv6_next_hop_free
1794
/* `match ipv6 address prefix-list PREFIX_LIST' */
1797
route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix,
1798
route_map_object_t type, void *object)
1800
struct prefix_list *plist;
1802
if (type == RMAP_BGP)
1804
plist = prefix_list_lookup (AFI_IP6, (char *) rule);
1806
return RMAP_NOMATCH;
1808
return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
1809
RMAP_NOMATCH : RMAP_MATCH);
1811
return RMAP_NOMATCH;
1815
route_match_ipv6_address_prefix_list_compile (const char *arg)
1817
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1821
route_match_ipv6_address_prefix_list_free (void *rule)
1823
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1826
struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
1828
"ipv6 address prefix-list",
1829
route_match_ipv6_address_prefix_list,
1830
route_match_ipv6_address_prefix_list_compile,
1831
route_match_ipv6_address_prefix_list_free
1834
/* `set ipv6 nexthop global IP_ADDRESS' */
1836
/* Set nexthop to object. ojbect must be pointer to struct attr. */
1838
route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix,
1839
route_map_object_t type, void *object)
1841
struct in6_addr *address;
1842
struct bgp_info *bgp_info;
1844
if (type == RMAP_BGP)
1846
/* Fetch routemap's rule information. */
1850
/* Set next hop value. */
1851
bgp_info->attr->mp_nexthop_global = *address;
1853
/* Set nexthop length. */
1854
if (bgp_info->attr->mp_nexthop_len == 0)
1855
bgp_info->attr->mp_nexthop_len = 16;
1861
/* Route map `ip next-hop' compile function. Given string is converted
1862
to struct in_addr structure. */
1864
route_set_ipv6_nexthop_global_compile (const char *arg)
1867
struct in6_addr *address;
1869
address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1871
ret = inet_pton (AF_INET6, arg, address);
1875
XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1882
/* Free route map's compiled `ip next-hop' value. */
1884
route_set_ipv6_nexthop_global_free (void *rule)
1886
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1889
/* Route map commands for ip nexthop set. */
1890
struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd =
1892
"ipv6 next-hop global",
1893
route_set_ipv6_nexthop_global,
1894
route_set_ipv6_nexthop_global_compile,
1895
route_set_ipv6_nexthop_global_free
1898
/* `set ipv6 nexthop local IP_ADDRESS' */
1900
/* Set nexthop to object. ojbect must be pointer to struct attr. */
1902
route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
1903
route_map_object_t type, void *object)
1905
struct in6_addr *address;
1906
struct bgp_info *bgp_info;
1908
if (type == RMAP_BGP)
1910
/* Fetch routemap's rule information. */
1914
/* Set next hop value. */
1915
bgp_info->attr->mp_nexthop_local = *address;
1917
/* Set nexthop length. */
1918
if (bgp_info->attr->mp_nexthop_len != 32)
1919
bgp_info->attr->mp_nexthop_len = 32;
1925
/* Route map `ip nexthop' compile function. Given string is converted
1926
to struct in_addr structure. */
1928
route_set_ipv6_nexthop_local_compile (const char *arg)
1931
struct in6_addr *address;
1933
address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1935
ret = inet_pton (AF_INET6, arg, address);
1939
XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1946
/* Free route map's compiled `ip nexthop' value. */
1948
route_set_ipv6_nexthop_local_free (void *rule)
1950
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1953
/* Route map commands for ip nexthop set. */
1954
struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd =
1956
"ipv6 next-hop local",
1957
route_set_ipv6_nexthop_local,
1958
route_set_ipv6_nexthop_local_compile,
1959
route_set_ipv6_nexthop_local_free
1961
#endif /* HAVE_IPV6 */
1963
/* `set vpnv4 nexthop A.B.C.D' */
1966
route_set_vpnv4_nexthop (void *rule, struct prefix *prefix,
1967
route_map_object_t type, void *object)
1969
struct in_addr *address;
1970
struct bgp_info *bgp_info;
1972
if (type == RMAP_BGP)
1974
/* Fetch routemap's rule information. */
1978
/* Set next hop value. */
1979
bgp_info->attr->mp_nexthop_global_in = *address;
1986
route_set_vpnv4_nexthop_compile (const char *arg)
1989
struct in_addr *address;
1991
address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
1993
ret = inet_aton (arg, address);
1997
XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2005
route_set_vpnv4_nexthop_free (void *rule)
2007
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2010
/* Route map commands for ip nexthop set. */
2011
struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd =
2014
route_set_vpnv4_nexthop,
2015
route_set_vpnv4_nexthop_compile,
2016
route_set_vpnv4_nexthop_free
2019
/* `set originator-id' */
2021
/* For origin set. */
2023
route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
2025
struct in_addr *address;
2026
struct bgp_info *bgp_info;
2028
if (type == RMAP_BGP)
2033
bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);
2034
bgp_info->attr->originator_id = *address;
2040
/* Compile function for originator-id set. */
2042
route_set_originator_id_compile (const char *arg)
2045
struct in_addr *address;
2047
address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2049
ret = inet_aton (arg, address);
2053
XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2060
/* Compile function for originator_id set. */
2062
route_set_originator_id_free (void *rule)
2064
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2067
/* Set metric rule structure. */
2068
struct route_map_rule_cmd route_set_originator_id_cmd =
2071
route_set_originator_id,
2072
route_set_originator_id_compile,
2073
route_set_originator_id_free,
2076
/* Add bgp route map rule. */
2078
bgp_route_match_add (struct vty *vty, struct route_map_index *index,
2079
const char *command, const char *arg)
2083
ret = route_map_add_match (index, command, arg);
2088
case RMAP_RULE_MISSING:
2089
vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2092
case RMAP_COMPILE_ERROR:
2093
vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2101
/* Delete bgp route map rule. */
2103
bgp_route_match_delete (struct vty *vty, struct route_map_index *index,
2104
const char *command, const char *arg)
2108
ret = route_map_delete_match (index, command, arg);
2113
case RMAP_RULE_MISSING:
2114
vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2117
case RMAP_COMPILE_ERROR:
2118
vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2126
/* Add bgp route map rule. */
2128
bgp_route_set_add (struct vty *vty, struct route_map_index *index,
2129
const char *command, const char *arg)
2133
ret = route_map_add_set (index, command, arg);
2138
case RMAP_RULE_MISSING:
2139
vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2142
case RMAP_COMPILE_ERROR:
2143
vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2151
/* Delete bgp route map rule. */
2153
bgp_route_set_delete (struct vty *vty, struct route_map_index *index,
2154
const char *command, const char *arg)
2158
ret = route_map_delete_set (index, command, arg);
2163
case RMAP_RULE_MISSING:
2164
vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2167
case RMAP_COMPILE_ERROR:
2168
vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2176
/* Hook function for updating route_map assignment. */
2178
bgp_route_map_update (const char *unused)
2184
struct listnode *node, *nnode;
2185
struct listnode *mnode, *mnnode;
2188
struct peer_group *group;
2189
struct bgp_filter *filter;
2190
struct bgp_node *bn;
2191
struct bgp_static *bgp_static;
2193
/* For neighbor route-map updates. */
2194
for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
2196
for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
2198
for (afi = AFI_IP; afi < AFI_MAX; afi++)
2199
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2201
filter = &peer->filter[afi][safi];
2203
for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
2205
if (filter->map[direct].name)
2206
filter->map[direct].map =
2207
route_map_lookup_by_name (filter->map[direct].name);
2209
filter->map[direct].map = NULL;
2212
if (filter->usmap.name)
2213
filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2215
filter->usmap.map = NULL;
2218
for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
2220
for (afi = AFI_IP; afi < AFI_MAX; afi++)
2221
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2223
filter = &group->conf->filter[afi][safi];
2225
for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
2227
if (filter->map[direct].name)
2228
filter->map[direct].map =
2229
route_map_lookup_by_name (filter->map[direct].name);
2231
filter->map[direct].map = NULL;
2234
if (filter->usmap.name)
2235
filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2237
filter->usmap.map = NULL;
2242
/* For default-originate route-map updates. */
2243
for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
2245
for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
2247
for (afi = AFI_IP; afi < AFI_MAX; afi++)
2248
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2250
if (peer->default_rmap[afi][safi].name)
2251
peer->default_rmap[afi][safi].map =
2252
route_map_lookup_by_name (peer->default_rmap[afi][safi].name);
2254
peer->default_rmap[afi][safi].map = NULL;
2259
/* For network route-map updates. */
2260
for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
2262
for (afi = AFI_IP; afi < AFI_MAX; afi++)
2263
for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2264
for (bn = bgp_table_top (bgp->route[afi][safi]); bn;
2265
bn = bgp_route_next (bn))
2266
if ((bgp_static = bn->info) != NULL)
2268
if (bgp_static->rmap.name)
2269
bgp_static->rmap.map =
2270
route_map_lookup_by_name (bgp_static->rmap.name);
2272
bgp_static->rmap.map = NULL;
2276
/* For redistribute route-map updates. */
2277
for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
2279
for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2281
if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)
2282
bgp->rmap[ZEBRA_FAMILY_IPV4][i].map =
2283
route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);
2285
if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)
2286
bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =
2287
route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);
2288
#endif /* HAVE_IPV6 */
2295
"match peer (A.B.C.D|X:X::X:X)",
2297
"Match peer address\n"
2298
"IPv6 address of peer\n"
2299
"IP address of peer\n")
2301
return bgp_route_match_add (vty, vty->index, "peer", argv[0]);
2304
DEFUN (match_peer_local,
2305
match_peer_local_cmd,
2308
"Match peer address\n"
2309
"Static or Redistributed routes\n")
2311
return bgp_route_match_add (vty, vty->index, "peer", NULL);
2314
DEFUN (no_match_peer,
2319
"Match peer address\n")
2322
return bgp_route_match_delete (vty, vty->index, "peer", NULL);
2324
return bgp_route_match_delete (vty, vty->index, "peer", argv[0]);
2327
ALIAS (no_match_peer,
2328
no_match_peer_val_cmd,
2329
"no match peer (A.B.C.D|X:X::X:X)",
2332
"Match peer address\n"
2333
"IPv6 address of peer\n"
2334
"IP address of peer\n")
2336
ALIAS (no_match_peer,
2337
no_match_peer_local_cmd,
2338
"no match peer local",
2341
"Match peer address\n"
2342
"Static or Redistributed routes\n")
2344
DEFUN (match_ip_address,
2345
match_ip_address_cmd,
2346
"match ip address (<1-199>|<1300-2699>|WORD)",
2349
"Match address of route\n"
2350
"IP access-list number\n"
2351
"IP access-list number (expanded range)\n"
2352
"IP Access-list name\n")
2354
return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);
2357
DEFUN (no_match_ip_address,
2358
no_match_ip_address_cmd,
2359
"no match ip address",
2363
"Match address of route\n")
2366
return bgp_route_match_delete (vty, vty->index, "ip address", NULL);
2368
return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);
2371
ALIAS (no_match_ip_address,
2372
no_match_ip_address_val_cmd,
2373
"no match ip address (<1-199>|<1300-2699>|WORD)",
2377
"Match address of route\n"
2378
"IP access-list number\n"
2379
"IP access-list number (expanded range)\n"
2380
"IP Access-list name\n")
2382
DEFUN (match_ip_next_hop,
2383
match_ip_next_hop_cmd,
2384
"match ip next-hop (<1-199>|<1300-2699>|WORD)",
2387
"Match next-hop address of route\n"
2388
"IP access-list number\n"
2389
"IP access-list number (expanded range)\n"
2390
"IP Access-list name\n")
2392
return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
2395
DEFUN (no_match_ip_next_hop,
2396
no_match_ip_next_hop_cmd,
2397
"no match ip next-hop",
2401
"Match next-hop address of route\n")
2404
return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
2406
return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
2409
ALIAS (no_match_ip_next_hop,
2410
no_match_ip_next_hop_val_cmd,
2411
"no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2415
"Match next-hop address of route\n"
2416
"IP access-list number\n"
2417
"IP access-list number (expanded range)\n"
2418
"IP Access-list name\n")
2420
DEFUN (match_ip_route_source,
2421
match_ip_route_source_cmd,
2422
"match ip route-source (<1-199>|<1300-2699>|WORD)",
2425
"Match advertising source address of route\n"
2426
"IP access-list number\n"
2427
"IP access-list number (expanded range)\n"
2428
"IP standard access-list name\n")
2430
return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]);
2433
DEFUN (no_match_ip_route_source,
2434
no_match_ip_route_source_cmd,
2435
"no match ip route-source",
2439
"Match advertising source address of route\n")
2442
return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL);
2444
return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]);
2447
ALIAS (no_match_ip_route_source,
2448
no_match_ip_route_source_val_cmd,
2449
"no match ip route-source (<1-199>|<1300-2699>|WORD)",
2453
"Match advertising source address of route\n"
2454
"IP access-list number\n"
2455
"IP access-list number (expanded range)\n"
2456
"IP standard access-list name\n");
2458
DEFUN (match_ip_address_prefix_list,
2459
match_ip_address_prefix_list_cmd,
2460
"match ip address prefix-list WORD",
2463
"Match address of route\n"
2464
"Match entries of prefix-lists\n"
2465
"IP prefix-list name\n")
2467
return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
2470
DEFUN (no_match_ip_address_prefix_list,
2471
no_match_ip_address_prefix_list_cmd,
2472
"no match ip address prefix-list",
2476
"Match address of route\n"
2477
"Match entries of prefix-lists\n")
2480
return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
2482
return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
2485
ALIAS (no_match_ip_address_prefix_list,
2486
no_match_ip_address_prefix_list_val_cmd,
2487
"no match ip address prefix-list WORD",
2491
"Match address of route\n"
2492
"Match entries of prefix-lists\n"
2493
"IP prefix-list name\n")
2495
DEFUN (match_ip_next_hop_prefix_list,
2496
match_ip_next_hop_prefix_list_cmd,
2497
"match ip next-hop prefix-list WORD",
2500
"Match next-hop address of route\n"
2501
"Match entries of prefix-lists\n"
2502
"IP prefix-list name\n")
2504
return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2507
DEFUN (no_match_ip_next_hop_prefix_list,
2508
no_match_ip_next_hop_prefix_list_cmd,
2509
"no match ip next-hop prefix-list",
2513
"Match next-hop address of route\n"
2514
"Match entries of prefix-lists\n")
2517
return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
2519
return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2522
ALIAS (no_match_ip_next_hop_prefix_list,
2523
no_match_ip_next_hop_prefix_list_val_cmd,
2524
"no match ip next-hop prefix-list WORD",
2528
"Match next-hop address of route\n"
2529
"Match entries of prefix-lists\n"
2530
"IP prefix-list name\n")
2532
DEFUN (match_ip_route_source_prefix_list,
2533
match_ip_route_source_prefix_list_cmd,
2534
"match ip route-source prefix-list WORD",
2537
"Match advertising source address of route\n"
2538
"Match entries of prefix-lists\n"
2539
"IP prefix-list name\n")
2541
return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]);
2544
DEFUN (no_match_ip_route_source_prefix_list,
2545
no_match_ip_route_source_prefix_list_cmd,
2546
"no match ip route-source prefix-list",
2550
"Match advertising source address of route\n"
2551
"Match entries of prefix-lists\n")
2554
return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL);
2556
return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]);
2559
ALIAS (no_match_ip_route_source_prefix_list,
2560
no_match_ip_route_source_prefix_list_val_cmd,
2561
"no match ip route-source prefix-list WORD",
2565
"Match advertising source address of route\n"
2566
"Match entries of prefix-lists\n"
2567
"IP prefix-list name\n");
2569
DEFUN (match_metric,
2571
"match metric <0-4294967295>",
2573
"Match metric of route\n"
2576
return bgp_route_match_add (vty, vty->index, "metric", argv[0]);
2579
DEFUN (no_match_metric,
2580
no_match_metric_cmd,
2584
"Match metric of route\n")
2587
return bgp_route_match_delete (vty, vty->index, "metric", NULL);
2589
return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);
2592
ALIAS (no_match_metric,
2593
no_match_metric_val_cmd,
2594
"no match metric <0-4294967295>",
2597
"Match metric of route\n"
2600
DEFUN (match_community,
2601
match_community_cmd,
2602
"match community (<1-99>|<100-500>|WORD)",
2604
"Match BGP community list\n"
2605
"Community-list number (standard)\n"
2606
"Community-list number (expanded)\n"
2607
"Community-list name\n")
2609
return bgp_route_match_add (vty, vty->index, "community", argv[0]);
2612
DEFUN (match_community_exact,
2613
match_community_exact_cmd,
2614
"match community (<1-99>|<100-500>|WORD) exact-match",
2616
"Match BGP community list\n"
2617
"Community-list number (standard)\n"
2618
"Community-list number (expanded)\n"
2619
"Community-list name\n"
2620
"Do exact matching of communities\n")
2625
argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
2626
strlen (argv[0]) + strlen ("exact-match") + 2);
2628
sprintf (argstr, "%s exact-match", argv[0]);
2630
ret = bgp_route_match_add (vty, vty->index, "community", argstr);
2632
XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
2637
DEFUN (no_match_community,
2638
no_match_community_cmd,
2639
"no match community",
2642
"Match BGP community list\n")
2644
return bgp_route_match_delete (vty, vty->index, "community", NULL);
2647
ALIAS (no_match_community,
2648
no_match_community_val_cmd,
2649
"no match community (<1-99>|<100-500>|WORD)",
2652
"Match BGP community list\n"
2653
"Community-list number (standard)\n"
2654
"Community-list number (expanded)\n"
2655
"Community-list name\n")
2657
ALIAS (no_match_community,
2658
no_match_community_exact_cmd,
2659
"no match community (<1-99>|<100-500>|WORD) exact-match",
2662
"Match BGP community list\n"
2663
"Community-list number (standard)\n"
2664
"Community-list number (expanded)\n"
2665
"Community-list name\n"
2666
"Do exact matching of communities\n")
2668
DEFUN (match_ecommunity,
2669
match_ecommunity_cmd,
2670
"match extcommunity (<1-99>|<100-500>|WORD)",
2672
"Match BGP/VPN extended community list\n"
2673
"Extended community-list number (standard)\n"
2674
"Extended community-list number (expanded)\n"
2675
"Extended community-list name\n")
2677
return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]);
2680
DEFUN (no_match_ecommunity,
2681
no_match_ecommunity_cmd,
2682
"no match extcommunity",
2685
"Match BGP/VPN extended community list\n")
2687
return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL);
2690
ALIAS (no_match_ecommunity,
2691
no_match_ecommunity_val_cmd,
2692
"no match extcommunity (<1-99>|<100-500>|WORD)",
2695
"Match BGP/VPN extended community list\n"
2696
"Extended community-list number (standard)\n"
2697
"Extended community-list number (expanded)\n"
2698
"Extended community-list name\n")
2700
DEFUN (match_aspath,
2702
"match as-path WORD",
2704
"Match BGP AS path list\n"
2705
"AS path access-list name\n")
2707
return bgp_route_match_add (vty, vty->index, "as-path", argv[0]);
2710
DEFUN (no_match_aspath,
2711
no_match_aspath_cmd,
2715
"Match BGP AS path list\n")
2717
return bgp_route_match_delete (vty, vty->index, "as-path", NULL);
2720
ALIAS (no_match_aspath,
2721
no_match_aspath_val_cmd,
2722
"no match as-path WORD",
2725
"Match BGP AS path list\n"
2726
"AS path access-list name\n")
2728
DEFUN (match_origin,
2730
"match origin (egp|igp|incomplete)",
2735
"unknown heritage\n")
2737
if (strncmp (argv[0], "igp", 2) == 0)
2738
return bgp_route_match_add (vty, vty->index, "origin", "igp");
2739
if (strncmp (argv[0], "egp", 1) == 0)
2740
return bgp_route_match_add (vty, vty->index, "origin", "egp");
2741
if (strncmp (argv[0], "incomplete", 2) == 0)
2742
return bgp_route_match_add (vty, vty->index, "origin", "incomplete");
2747
DEFUN (no_match_origin,
2748
no_match_origin_cmd,
2752
"BGP origin code\n")
2754
return bgp_route_match_delete (vty, vty->index, "origin", NULL);
2757
ALIAS (no_match_origin,
2758
no_match_origin_val_cmd,
2759
"no match origin (egp|igp|incomplete)",
2765
"unknown heritage\n")
2767
DEFUN (set_ip_nexthop,
2769
"set ip next-hop A.B.C.D",
2772
"Next hop address\n"
2773
"IP address of next hop\n")
2778
ret = str2sockunion (argv[0], &su);
2781
vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
2785
return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
2788
DEFUN (set_ip_nexthop_peer,
2789
set_ip_nexthop_peer_cmd,
2790
"set ip next-hop peer-address",
2793
"Next hop address\n"
2794
"Use peer address (for BGP only)\n")
2796
return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address");
2799
DEFUN (no_set_ip_nexthop_peer,
2800
no_set_ip_nexthop_peer_cmd,
2801
"no set ip next-hop peer-address",
2805
"Next hop address\n"
2806
"Use peer address (for BGP only)\n")
2808
return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2812
DEFUN (no_set_ip_nexthop,
2813
no_set_ip_nexthop_cmd,
2814
"no set ip next-hop",
2817
"Next hop address\n")
2820
return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2822
return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
2825
ALIAS (no_set_ip_nexthop,
2826
no_set_ip_nexthop_val_cmd,
2827
"no set ip next-hop A.B.C.D",
2831
"Next hop address\n"
2832
"IP address of next hop\n")
2836
"set metric <0-4294967295>",
2838
"Metric value for destination routing protocol\n"
2841
return bgp_route_set_add (vty, vty->index, "metric", argv[0]);
2845
set_metric_addsub_cmd,
2846
"set metric <+/-metric>",
2848
"Metric value for destination routing protocol\n"
2849
"Add or subtract BGP metric\n")
2851
DEFUN (no_set_metric,
2856
"Metric value for destination routing protocol\n")
2859
return bgp_route_set_delete (vty, vty->index, "metric", NULL);
2861
return bgp_route_set_delete (vty, vty->index, "metric", argv[0]);
2864
ALIAS (no_set_metric,
2865
no_set_metric_val_cmd,
2866
"no set metric <0-4294967295>",
2869
"Metric value for destination routing protocol\n"
2872
DEFUN (set_local_pref,
2874
"set local-preference <0-4294967295>",
2876
"BGP local preference path attribute\n"
2877
"Preference value\n")
2879
return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]);
2882
DEFUN (no_set_local_pref,
2883
no_set_local_pref_cmd,
2884
"no set local-preference",
2887
"BGP local preference path attribute\n")
2890
return bgp_route_set_delete (vty, vty->index, "local-preference", NULL);
2892
return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]);
2895
ALIAS (no_set_local_pref,
2896
no_set_local_pref_val_cmd,
2897
"no set local-preference <0-4294967295>",
2900
"BGP local preference path attribute\n"
2901
"Preference value\n")
2905
"set weight <0-4294967295>",
2907
"BGP weight for routing table\n"
2910
return bgp_route_set_add (vty, vty->index, "weight", argv[0]);
2913
DEFUN (no_set_weight,
2918
"BGP weight for routing table\n")
2921
return bgp_route_set_delete (vty, vty->index, "weight", NULL);
2923
return bgp_route_set_delete (vty, vty->index, "weight", argv[0]);
2926
ALIAS (no_set_weight,
2927
no_set_weight_val_cmd,
2928
"no set weight <0-4294967295>",
2931
"BGP weight for routing table\n"
2934
DEFUN (set_aspath_prepend,
2935
set_aspath_prepend_cmd,
2936
"set as-path prepend .<1-65535>",
2938
"Prepend string for a BGP AS-path attribute\n"
2939
"Prepend to the as-path\n"
2945
str = argv_concat (argv, argc, 0);
2946
ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str);
2947
XFREE (MTYPE_TMP, str);
2952
DEFUN (no_set_aspath_prepend,
2953
no_set_aspath_prepend_cmd,
2954
"no set as-path prepend",
2957
"Prepend string for a BGP AS-path attribute\n"
2958
"Prepend to the as-path\n")
2960
return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL);
2963
ALIAS (no_set_aspath_prepend,
2964
no_set_aspath_prepend_val_cmd,
2965
"no set as-path prepend .<1-65535>",
2968
"Prepend string for a BGP AS-path attribute\n"
2969
"Prepend to the as-path\n"
2972
DEFUN (set_community,
2974
"set community .AA:NN",
2976
"BGP community attribute\n"
2977
"Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
2983
struct community *com = NULL;
2988
b = buffer_new (1024);
2990
for (i = 0; i < argc; i++)
2992
if (strncmp (argv[i], "additive", strlen (argv[i])) == 0)
2999
buffer_putc (b, ' ');
3003
if (strncmp (argv[i], "internet", strlen (argv[i])) == 0)
3005
buffer_putstr (b, "internet");
3008
if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0)
3010
buffer_putstr (b, "local-AS");
3013
if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0
3014
&& strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0)
3016
buffer_putstr (b, "no-advertise");
3019
if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0
3020
&& strncmp (argv[i], "no-export", strlen (argv[i])) == 0)
3022
buffer_putstr (b, "no-export");
3025
buffer_putstr (b, argv[i]);
3027
buffer_putc (b, '\0');
3029
/* Fetch result string then compile it to communities attribute. */
3030
str = buffer_getstr (b);
3035
com = community_str2com (str);
3036
XFREE (MTYPE_TMP, str);
3039
/* Can't compile user input into communities attribute. */
3042
vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE);
3046
/* Set communites attribute string. */
3047
str = community_str (com);
3051
argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1);
3052
strcpy (argstr, str);
3053
strcpy (argstr + strlen (str), " additive");
3054
ret = bgp_route_set_add (vty, vty->index, "community", argstr);
3055
XFREE (MTYPE_TMP, argstr);
3058
ret = bgp_route_set_add (vty, vty->index, "community", str);
3060
community_free (com);
3065
DEFUN (set_community_none,
3066
set_community_none_cmd,
3067
"set community none",
3069
"BGP community attribute\n"
3070
"No community attribute\n")
3072
return bgp_route_set_add (vty, vty->index, "community", "none");
3075
DEFUN (no_set_community,
3076
no_set_community_cmd,
3080
"BGP community attribute\n")
3082
return bgp_route_set_delete (vty, vty->index, "community", NULL);
3085
ALIAS (no_set_community,
3086
no_set_community_val_cmd,
3087
"no set community .AA:NN",
3090
"BGP community attribute\n"
3091
"Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3093
ALIAS (no_set_community,
3094
no_set_community_none_cmd,
3095
"no set community none",
3098
"BGP community attribute\n"
3099
"No community attribute\n")
3101
DEFUN (set_community_delete,
3102
set_community_delete_cmd,
3103
"set comm-list (<1-99>|<100-500>|WORD) delete",
3105
"set BGP community list (for deletion)\n"
3106
"Community-list number (standard)\n"
3107
"Communitly-list number (expanded)\n"
3108
"Community-list name\n"
3109
"Delete matching communities\n")
3113
str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1);
3114
strcpy (str, argv[0]);
3115
strcpy (str + strlen (argv[0]), " delete");
3117
bgp_route_set_add (vty, vty->index, "comm-list", str);
3119
XFREE (MTYPE_TMP, str);
3123
DEFUN (no_set_community_delete,
3124
no_set_community_delete_cmd,
3128
"set BGP community list (for deletion)\n")
3130
return bgp_route_set_delete (vty, vty->index, "comm-list", NULL);
3133
ALIAS (no_set_community_delete,
3134
no_set_community_delete_val_cmd,
3135
"no set comm-list (<1-99>|<100-500>|WORD) delete",
3138
"set BGP community list (for deletion)\n"
3139
"Community-list number (standard)\n"
3140
"Communitly-list number (expanded)\n"
3141
"Community-list name\n"
3142
"Delete matching communities\n")
3144
DEFUN (set_ecommunity_rt,
3145
set_ecommunity_rt_cmd,
3146
"set extcommunity rt .ASN:nn_or_IP-address:nn",
3148
"BGP extended community attribute\n"
3149
"Route Target extened communityt\n"
3150
"VPN extended community\n")
3155
str = argv_concat (argv, argc, 0);
3156
ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str);
3157
XFREE (MTYPE_TMP, str);
3162
DEFUN (no_set_ecommunity_rt,
3163
no_set_ecommunity_rt_cmd,
3164
"no set extcommunity rt",
3167
"BGP extended community attribute\n"
3168
"Route Target extened communityt\n")
3170
return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL);
3173
ALIAS (no_set_ecommunity_rt,
3174
no_set_ecommunity_rt_val_cmd,
3175
"no set extcommunity rt .ASN:nn_or_IP-address:nn",
3178
"BGP extended community attribute\n"
3179
"Route Target extened communityt\n"
3180
"VPN extended community\n")
3182
DEFUN (set_ecommunity_soo,
3183
set_ecommunity_soo_cmd,
3184
"set extcommunity soo .ASN:nn_or_IP-address:nn",
3186
"BGP extended community attribute\n"
3187
"Site-of-Origin extended community\n"
3188
"VPN extended community\n")
3193
str = argv_concat (argv, argc, 0);
3194
ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str);
3195
XFREE (MTYPE_TMP, str);
3199
DEFUN (no_set_ecommunity_soo,
3200
no_set_ecommunity_soo_cmd,
3201
"no set extcommunity soo",
3204
"BGP extended community attribute\n"
3205
"Site-of-Origin extended community\n")
3207
return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL);
3210
ALIAS (no_set_ecommunity_soo,
3211
no_set_ecommunity_soo_val_cmd,
3212
"no set extcommunity soo .ASN:nn_or_IP-address:nn",
3215
"BGP extended community attribute\n"
3216
"Site-of-Origin extended community\n"
3217
"VPN extended community\n")
3221
"set origin (egp|igp|incomplete)",
3226
"unknown heritage\n")
3228
if (strncmp (argv[0], "igp", 2) == 0)
3229
return bgp_route_set_add (vty, vty->index, "origin", "igp");
3230
if (strncmp (argv[0], "egp", 1) == 0)
3231
return bgp_route_set_add (vty, vty->index, "origin", "egp");
3232
if (strncmp (argv[0], "incomplete", 2) == 0)
3233
return bgp_route_set_add (vty, vty->index, "origin", "incomplete");
3238
DEFUN (no_set_origin,
3243
"BGP origin code\n")
3245
return bgp_route_set_delete (vty, vty->index, "origin", NULL);
3248
ALIAS (no_set_origin,
3249
no_set_origin_val_cmd,
3250
"no set origin (egp|igp|incomplete)",
3256
"unknown heritage\n")
3258
DEFUN (set_atomic_aggregate,
3259
set_atomic_aggregate_cmd,
3260
"set atomic-aggregate",
3262
"BGP atomic aggregate attribute\n" )
3264
return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL);
3267
DEFUN (no_set_atomic_aggregate,
3268
no_set_atomic_aggregate_cmd,
3269
"no set atomic-aggregate",
3272
"BGP atomic aggregate attribute\n" )
3274
return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL);
3277
DEFUN (set_aggregator_as,
3278
set_aggregator_as_cmd,
3279
"set aggregator as <1-65535> A.B.C.D",
3281
"BGP aggregator attribute\n"
3282
"AS number of aggregator\n"
3284
"IP address of aggregator\n")
3288
struct in_addr address;
3291
VTY_GET_INTEGER_RANGE ("AS Path", as, argv[0], 1, BGP_AS_MAX)
3293
ret = inet_aton (argv[1], &address);
3296
vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3300
argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3301
strlen (argv[0]) + strlen (argv[1]) + 2);
3303
sprintf (argstr, "%s %s", argv[0], argv[1]);
3305
ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr);
3307
XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3312
DEFUN (no_set_aggregator_as,
3313
no_set_aggregator_as_cmd,
3314
"no set aggregator as",
3317
"BGP aggregator attribute\n"
3318
"AS number of aggregator\n")
3322
struct in_addr address;
3326
return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL);
3328
VTY_GET_INTEGER_RANGE ("AS Path", as, argv[0], 1, BGP_AS_MAX)
3330
ret = inet_aton (argv[1], &address);
3333
vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3337
argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3338
strlen (argv[0]) + strlen (argv[1]) + 2);
3340
sprintf (argstr, "%s %s", argv[0], argv[1]);
3342
ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr);
3344
XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3349
ALIAS (no_set_aggregator_as,
3350
no_set_aggregator_as_val_cmd,
3351
"no set aggregator as <1-65535> A.B.C.D",
3354
"BGP aggregator attribute\n"
3355
"AS number of aggregator\n"
3357
"IP address of aggregator\n")
3361
DEFUN (match_ipv6_address,
3362
match_ipv6_address_cmd,
3363
"match ipv6 address WORD",
3366
"Match IPv6 address of route\n"
3367
"IPv6 access-list name\n")
3369
return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]);
3372
DEFUN (no_match_ipv6_address,
3373
no_match_ipv6_address_cmd,
3374
"no match ipv6 address WORD",
3378
"Match IPv6 address of route\n"
3379
"IPv6 access-list name\n")
3381
return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]);
3384
DEFUN (match_ipv6_next_hop,
3385
match_ipv6_next_hop_cmd,
3386
"match ipv6 next-hop X:X::X:X",
3389
"Match IPv6 next-hop address of route\n"
3390
"IPv6 address of next hop\n")
3392
return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]);
3395
DEFUN (no_match_ipv6_next_hop,
3396
no_match_ipv6_next_hop_cmd,
3397
"no match ipv6 next-hop X:X::X:X",
3401
"Match IPv6 next-hop address of route\n"
3402
"IPv6 address of next hop\n")
3404
return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
3407
DEFUN (match_ipv6_address_prefix_list,
3408
match_ipv6_address_prefix_list_cmd,
3409
"match ipv6 address prefix-list WORD",
3412
"Match address of route\n"
3413
"Match entries of prefix-lists\n"
3414
"IP prefix-list name\n")
3416
return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3419
DEFUN (no_match_ipv6_address_prefix_list,
3420
no_match_ipv6_address_prefix_list_cmd,
3421
"no match ipv6 address prefix-list WORD",
3425
"Match address of route\n"
3426
"Match entries of prefix-lists\n"
3427
"IP prefix-list name\n")
3429
return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3432
DEFUN (set_ipv6_nexthop_global,
3433
set_ipv6_nexthop_global_cmd,
3434
"set ipv6 next-hop global X:X::X:X",
3437
"IPv6 next-hop address\n"
3438
"IPv6 global address\n"
3439
"IPv6 address of next hop\n")
3441
return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]);
3444
DEFUN (no_set_ipv6_nexthop_global,
3445
no_set_ipv6_nexthop_global_cmd,
3446
"no set ipv6 next-hop global",
3450
"IPv6 next-hop address\n"
3451
"IPv6 global address\n")
3454
return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL);
3456
return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]);
3459
ALIAS (no_set_ipv6_nexthop_global,
3460
no_set_ipv6_nexthop_global_val_cmd,
3461
"no set ipv6 next-hop global X:X::X:X",
3465
"IPv6 next-hop address\n"
3466
"IPv6 global address\n"
3467
"IPv6 address of next hop\n")
3469
DEFUN (set_ipv6_nexthop_local,
3470
set_ipv6_nexthop_local_cmd,
3471
"set ipv6 next-hop local X:X::X:X",
3474
"IPv6 next-hop address\n"
3475
"IPv6 local address\n"
3476
"IPv6 address of next hop\n")
3478
return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
3481
DEFUN (no_set_ipv6_nexthop_local,
3482
no_set_ipv6_nexthop_local_cmd,
3483
"no set ipv6 next-hop local",
3487
"IPv6 next-hop address\n"
3488
"IPv6 local address\n")
3491
return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
3493
return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
3496
ALIAS (no_set_ipv6_nexthop_local,
3497
no_set_ipv6_nexthop_local_val_cmd,
3498
"no set ipv6 next-hop local X:X::X:X",
3502
"IPv6 next-hop address\n"
3503
"IPv6 local address\n"
3504
"IPv6 address of next hop\n")
3505
#endif /* HAVE_IPV6 */
3507
DEFUN (set_vpnv4_nexthop,
3508
set_vpnv4_nexthop_cmd,
3509
"set vpnv4 next-hop A.B.C.D",
3511
"VPNv4 information\n"
3512
"VPNv4 next-hop address\n"
3513
"IP address of next hop\n")
3515
return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]);
3518
DEFUN (no_set_vpnv4_nexthop,
3519
no_set_vpnv4_nexthop_cmd,
3520
"no set vpnv4 next-hop",
3523
"VPNv4 information\n"
3524
"VPNv4 next-hop address\n")
3527
return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL);
3529
return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]);
3532
ALIAS (no_set_vpnv4_nexthop,
3533
no_set_vpnv4_nexthop_val_cmd,
3534
"no set vpnv4 next-hop A.B.C.D",
3537
"VPNv4 information\n"
3538
"VPNv4 next-hop address\n"
3539
"IP address of next hop\n")
3541
DEFUN (set_originator_id,
3542
set_originator_id_cmd,
3543
"set originator-id A.B.C.D",
3545
"BGP originator ID attribute\n"
3546
"IP address of originator\n")
3548
return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]);
3551
DEFUN (no_set_originator_id,
3552
no_set_originator_id_cmd,
3553
"no set originator-id",
3556
"BGP originator ID attribute\n")
3559
return bgp_route_set_delete (vty, vty->index, "originator-id", NULL);
3561
return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]);
3564
ALIAS (no_set_originator_id,
3565
no_set_originator_id_val_cmd,
3566
"no set originator-id A.B.C.D",
3569
"BGP originator ID attribute\n"
3570
"IP address of originator\n")
3573
/* Initialization of route map. */
3575
bgp_route_map_init ()
3578
route_map_init_vty ();
3579
route_map_add_hook (bgp_route_map_update);
3580
route_map_delete_hook (bgp_route_map_update);
3582
route_map_install_match (&route_match_peer_cmd);
3583
route_map_install_match (&route_match_ip_address_cmd);
3584
route_map_install_match (&route_match_ip_next_hop_cmd);
3585
route_map_install_match (&route_match_ip_route_source_cmd);
3586
route_map_install_match (&route_match_ip_address_prefix_list_cmd);
3587
route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
3588
route_map_install_match (&route_match_ip_route_source_prefix_list_cmd);
3589
route_map_install_match (&route_match_aspath_cmd);
3590
route_map_install_match (&route_match_community_cmd);
3591
route_map_install_match (&route_match_ecommunity_cmd);
3592
route_map_install_match (&route_match_metric_cmd);
3593
route_map_install_match (&route_match_origin_cmd);
3595
route_map_install_set (&route_set_ip_nexthop_cmd);
3596
route_map_install_set (&route_set_local_pref_cmd);
3597
route_map_install_set (&route_set_weight_cmd);
3598
route_map_install_set (&route_set_metric_cmd);
3599
route_map_install_set (&route_set_aspath_prepend_cmd);
3600
route_map_install_set (&route_set_origin_cmd);
3601
route_map_install_set (&route_set_atomic_aggregate_cmd);
3602
route_map_install_set (&route_set_aggregator_as_cmd);
3603
route_map_install_set (&route_set_community_cmd);
3604
route_map_install_set (&route_set_community_delete_cmd);
3605
route_map_install_set (&route_set_vpnv4_nexthop_cmd);
3606
route_map_install_set (&route_set_originator_id_cmd);
3607
route_map_install_set (&route_set_ecommunity_rt_cmd);
3608
route_map_install_set (&route_set_ecommunity_soo_cmd);
3610
install_element (RMAP_NODE, &match_peer_cmd);
3611
install_element (RMAP_NODE, &match_peer_local_cmd);
3612
install_element (RMAP_NODE, &no_match_peer_cmd);
3613
install_element (RMAP_NODE, &no_match_peer_val_cmd);
3614
install_element (RMAP_NODE, &no_match_peer_local_cmd);
3615
install_element (RMAP_NODE, &match_ip_address_cmd);
3616
install_element (RMAP_NODE, &no_match_ip_address_cmd);
3617
install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
3618
install_element (RMAP_NODE, &match_ip_next_hop_cmd);
3619
install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
3620
install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
3621
install_element (RMAP_NODE, &match_ip_route_source_cmd);
3622
install_element (RMAP_NODE, &no_match_ip_route_source_cmd);
3623
install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd);
3625
install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
3626
install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
3627
install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
3628
install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
3629
install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
3630
install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
3631
install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
3632
install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
3633
install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd);
3635
install_element (RMAP_NODE, &match_aspath_cmd);
3636
install_element (RMAP_NODE, &no_match_aspath_cmd);
3637
install_element (RMAP_NODE, &no_match_aspath_val_cmd);
3638
install_element (RMAP_NODE, &match_metric_cmd);
3639
install_element (RMAP_NODE, &no_match_metric_cmd);
3640
install_element (RMAP_NODE, &no_match_metric_val_cmd);
3641
install_element (RMAP_NODE, &match_community_cmd);
3642
install_element (RMAP_NODE, &match_community_exact_cmd);
3643
install_element (RMAP_NODE, &no_match_community_cmd);
3644
install_element (RMAP_NODE, &no_match_community_val_cmd);
3645
install_element (RMAP_NODE, &no_match_community_exact_cmd);
3646
install_element (RMAP_NODE, &match_ecommunity_cmd);
3647
install_element (RMAP_NODE, &no_match_ecommunity_cmd);
3648
install_element (RMAP_NODE, &no_match_ecommunity_val_cmd);
3649
install_element (RMAP_NODE, &match_origin_cmd);
3650
install_element (RMAP_NODE, &no_match_origin_cmd);
3651
install_element (RMAP_NODE, &no_match_origin_val_cmd);
3653
install_element (RMAP_NODE, &set_ip_nexthop_cmd);
3654
install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd);
3655
install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
3656
install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
3657
install_element (RMAP_NODE, &set_local_pref_cmd);
3658
install_element (RMAP_NODE, &no_set_local_pref_cmd);
3659
install_element (RMAP_NODE, &no_set_local_pref_val_cmd);
3660
install_element (RMAP_NODE, &set_weight_cmd);
3661
install_element (RMAP_NODE, &no_set_weight_cmd);
3662
install_element (RMAP_NODE, &no_set_weight_val_cmd);
3663
install_element (RMAP_NODE, &set_metric_cmd);
3664
install_element (RMAP_NODE, &set_metric_addsub_cmd);
3665
install_element (RMAP_NODE, &no_set_metric_cmd);
3666
install_element (RMAP_NODE, &no_set_metric_val_cmd);
3667
install_element (RMAP_NODE, &set_aspath_prepend_cmd);
3668
install_element (RMAP_NODE, &no_set_aspath_prepend_cmd);
3669
install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd);
3670
install_element (RMAP_NODE, &set_origin_cmd);
3671
install_element (RMAP_NODE, &no_set_origin_cmd);
3672
install_element (RMAP_NODE, &no_set_origin_val_cmd);
3673
install_element (RMAP_NODE, &set_atomic_aggregate_cmd);
3674
install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd);
3675
install_element (RMAP_NODE, &set_aggregator_as_cmd);
3676
install_element (RMAP_NODE, &no_set_aggregator_as_cmd);
3677
install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd);
3678
install_element (RMAP_NODE, &set_community_cmd);
3679
install_element (RMAP_NODE, &set_community_none_cmd);
3680
install_element (RMAP_NODE, &no_set_community_cmd);
3681
install_element (RMAP_NODE, &no_set_community_val_cmd);
3682
install_element (RMAP_NODE, &no_set_community_none_cmd);
3683
install_element (RMAP_NODE, &set_community_delete_cmd);
3684
install_element (RMAP_NODE, &no_set_community_delete_cmd);
3685
install_element (RMAP_NODE, &no_set_community_delete_val_cmd);
3686
install_element (RMAP_NODE, &set_ecommunity_rt_cmd);
3687
install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd);
3688
install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd);
3689
install_element (RMAP_NODE, &set_ecommunity_soo_cmd);
3690
install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd);
3691
install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd);
3692
install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd);
3693
install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd);
3694
install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd);
3695
install_element (RMAP_NODE, &set_originator_id_cmd);
3696
install_element (RMAP_NODE, &no_set_originator_id_cmd);
3697
install_element (RMAP_NODE, &no_set_originator_id_val_cmd);
3700
route_map_install_match (&route_match_ipv6_address_cmd);
3701
route_map_install_match (&route_match_ipv6_next_hop_cmd);
3702
route_map_install_match (&route_match_ipv6_address_prefix_list_cmd);
3703
route_map_install_set (&route_set_ipv6_nexthop_global_cmd);
3704
route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
3706
install_element (RMAP_NODE, &match_ipv6_address_cmd);
3707
install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
3708
install_element (RMAP_NODE, &match_ipv6_next_hop_cmd);
3709
install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd);
3710
install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
3711
install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
3712
install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd);
3713
install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
3714
install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd);
3715
install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
3716
install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
3717
install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
3718
#endif /* HAVE_IPV6 */