blob: b449cae0c472bb490397b926902fb2f459c7c8d0 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Route map function of bgpd.
2 Copyright (C) 1998, 1999 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "filter.h"
25#include "routemap.h"
26#include "command.h"
27#include "linklist.h"
28#include "plist.h"
29#include "memory.h"
30#include "log.h"
Jeremy Jackson25f45882009-01-12 16:06:12 -050031#ifdef HAVE_LIBPCREPOSIX
32# include <pcreposix.h>
paul718e3742002-12-13 20:15:29 +000033#else
Jeremy Jackson25f45882009-01-12 16:06:12 -050034# ifdef HAVE_GNU_REGEX
35# include <regex.h>
36# else
37# include "regex-gnu.h"
38# endif /* HAVE_GNU_REGEX */
39#endif /* HAVE_LIBPCREPOSIX */
paul718e3742002-12-13 20:15:29 +000040#include "buffer.h"
41#include "sockunion.h"
42
43#include "bgpd/bgpd.h"
44#include "bgpd/bgp_table.h"
45#include "bgpd/bgp_attr.h"
46#include "bgpd/bgp_aspath.h"
47#include "bgpd/bgp_route.h"
48#include "bgpd/bgp_regex.h"
49#include "bgpd/bgp_community.h"
50#include "bgpd/bgp_clist.h"
51#include "bgpd/bgp_filter.h"
52#include "bgpd/bgp_mplsvpn.h"
53#include "bgpd/bgp_ecommunity.h"
Paul Jakma320da872008-07-02 13:40:33 +000054#include "bgpd/bgp_vty.h"
paul718e3742002-12-13 20:15:29 +000055
56/* Memo of route-map commands.
57
58o Cisco route-map
59
60 match as-path : Done
61 community : Done
62 interface : Not yet
63 ip address : Done
64 ip next-hop : Done
hassoc1643bb2005-02-02 16:43:17 +000065 ip route-source : Done
paul718e3742002-12-13 20:15:29 +000066 ip prefix-list : Done
67 ipv6 address : Done
68 ipv6 next-hop : Done
69 ipv6 route-source: (This will not be implemented by bgpd)
70 ipv6 prefix-list : Done
71 length : (This will not be implemented by bgpd)
72 metric : Done
73 route-type : (This will not be implemented by bgpd)
74 tag : (This will not be implemented by bgpd)
75
76 set as-path prepend : Done
77 as-path tag : Not yet
78 automatic-tag : (This will not be implemented by bgpd)
79 community : Done
80 comm-list : Not yet
81 dampning : Not yet
82 default : (This will not be implemented by bgpd)
83 interface : (This will not be implemented by bgpd)
84 ip default : (This will not be implemented by bgpd)
85 ip next-hop : Done
86 ip precedence : (This will not be implemented by bgpd)
87 ip tos : (This will not be implemented by bgpd)
88 level : (This will not be implemented by bgpd)
89 local-preference : Done
90 metric : Done
91 metric-type : Not yet
92 origin : Done
93 tag : (This will not be implemented by bgpd)
94 weight : Done
95
Timo Teräs2aa640b2014-05-20 08:57:26 +030096o Local extensions
paul718e3742002-12-13 20:15:29 +000097
98 set ipv6 next-hop global: Done
99 set ipv6 next-hop local : Done
Denis Ovsienko841f7a52008-04-10 11:47:45 +0000100 set as-path exclude : Done
paul718e3742002-12-13 20:15:29 +0000101
102*/
David Lamparter6b0655a2014-06-04 06:53:35 +0200103
Timo Teräs38f22ab2015-04-29 09:43:02 +0300104 /* generic value manipulation to be shared in multiple rules */
105
106#define RMAP_VALUE_SET 0
107#define RMAP_VALUE_ADD 1
108#define RMAP_VALUE_SUB 2
109
110struct rmap_value
111{
112 u_int8_t action;
Timo Teräsef757702015-04-29 09:43:04 +0300113 u_int8_t variable;
Timo Teräs38f22ab2015-04-29 09:43:02 +0300114 u_int32_t value;
115};
116
117static int
118route_value_match (struct rmap_value *rv, u_int32_t value)
119{
Timo Teräsef757702015-04-29 09:43:04 +0300120 if (rv->variable == 0 && value == rv->value)
Timo Teräs38f22ab2015-04-29 09:43:02 +0300121 return RMAP_MATCH;
122
123 return RMAP_NOMATCH;
124}
125
126static u_int32_t
Timo Teräsef757702015-04-29 09:43:04 +0300127route_value_adjust (struct rmap_value *rv, u_int32_t current, struct peer *peer)
Timo Teräs38f22ab2015-04-29 09:43:02 +0300128{
Timo Teräsef757702015-04-29 09:43:04 +0300129 u_int32_t value;
130
131 switch (rv->variable)
132 {
133 case 1:
134 value = peer->rtt;
135 break;
136 default:
137 value = rv->value;
138 break;
139 }
Timo Teräs38f22ab2015-04-29 09:43:02 +0300140
141 switch (rv->action)
142 {
143 case RMAP_VALUE_ADD:
144 if (current > UINT32_MAX-value)
145 return UINT32_MAX;
146 return current + value;
147 case RMAP_VALUE_SUB:
148 if (current <= value)
149 return 0;
150 return current - value;
151 default:
152 return value;
153 }
154}
155
156static void *
157route_value_compile (const char *arg)
158{
Timo Teräsef757702015-04-29 09:43:04 +0300159 u_int8_t action = RMAP_VALUE_SET, var = 0;
160 unsigned long larg = 0;
Timo Teräs38f22ab2015-04-29 09:43:02 +0300161 char *endptr = NULL;
162 struct rmap_value *rv;
163
164 if (arg[0] == '+')
165 {
166 action = RMAP_VALUE_ADD;
167 arg++;
168 }
169 else if (arg[0] == '-')
170 {
171 action = RMAP_VALUE_SUB;
172 arg++;
173 }
174
Timo Teräsef757702015-04-29 09:43:04 +0300175 if (all_digit(arg))
176 {
177 errno = 0;
178 larg = strtoul (arg, &endptr, 10);
179 if (*arg == 0 || *endptr != 0 || errno || larg > UINT32_MAX)
180 return NULL;
181 }
182 else
183 {
184 if (strcmp(arg, "rtt") == 0)
185 var = 1;
186 else
187 return NULL;
188 }
Timo Teräs38f22ab2015-04-29 09:43:02 +0300189
190 rv = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_value));
191 if (!rv)
192 return NULL;
193
194 rv->action = action;
Timo Teräsef757702015-04-29 09:43:04 +0300195 rv->variable = var;
Timo Teräs38f22ab2015-04-29 09:43:02 +0300196 rv->value = larg;
197 return rv;
198}
199
200static void
201route_value_free (void *rule)
202{
203 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
204}
205
Timo Teräsb304dcb2014-05-20 09:04:49 +0300206 /* generic as path object to be shared in multiple rules */
207
208static void *
209route_aspath_compile (const char *arg)
210{
211 struct aspath *aspath;
212
213 aspath = aspath_str2aspath (arg);
214 if (! aspath)
215 return NULL;
216 return aspath;
217}
218
219static void
220route_aspath_free (void *rule)
221{
222 struct aspath *aspath = rule;
223 aspath_free (aspath);
224}
225
paulfee0f4c2004-09-13 05:12:46 +0000226 /* 'match peer (A.B.C.D|X:X::X:X)' */
227
228/* Compares the peer specified in the 'match peer' clause with the peer
229 received in bgp_info->peer. If it is the same, or if the peer structure
230 received is a peer_group containing it, returns RMAP_MATCH. */
paul94f2b392005-06-28 12:44:16 +0000231static route_map_result_t
paulfee0f4c2004-09-13 05:12:46 +0000232route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type,
233 void *object)
234{
235 union sockunion *su;
David Lamparter6ed810d2015-04-21 10:13:07 +0200236 union sockunion su_def = { .sin = { .sin_family = AF_INET,
237 .sin_addr.s_addr = INADDR_ANY } };
paulfee0f4c2004-09-13 05:12:46 +0000238 struct peer_group *group;
239 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +0000240 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +0000241
242 if (type == RMAP_BGP)
243 {
244 su = rule;
245 peer = ((struct bgp_info *) object)->peer;
246
247 if ( ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT) &&
248 ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_EXPORT) )
249 return RMAP_NOMATCH;
250
251 /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
252 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200253 if (sockunion_same (su, &su_def))
paulfee0f4c2004-09-13 05:12:46 +0000254 {
paul22db9de2005-05-19 01:50:11 +0000255 int ret;
paulfee0f4c2004-09-13 05:12:46 +0000256 if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) ||
257 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE) ||
258 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_DEFAULT))
paul22db9de2005-05-19 01:50:11 +0000259 ret = RMAP_MATCH;
paulfee0f4c2004-09-13 05:12:46 +0000260 else
paul22db9de2005-05-19 01:50:11 +0000261 ret = RMAP_NOMATCH;
paul22db9de2005-05-19 01:50:11 +0000262 return ret;
paulfee0f4c2004-09-13 05:12:46 +0000263 }
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200264
paulfee0f4c2004-09-13 05:12:46 +0000265 if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
266 {
267 if (sockunion_same (su, &peer->su))
268 return RMAP_MATCH;
269
270 return RMAP_NOMATCH;
271 }
272 else
273 {
274 group = peer->group;
paul1eb8ef22005-04-07 07:30:20 +0000275 for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
paulfee0f4c2004-09-13 05:12:46 +0000276 {
277 if (sockunion_same (su, &peer->su))
278 return RMAP_MATCH;
paulfee0f4c2004-09-13 05:12:46 +0000279 }
Paul Jakma30a22312008-08-15 14:05:22 +0100280 return RMAP_NOMATCH;
paulfee0f4c2004-09-13 05:12:46 +0000281 }
282 }
283 return RMAP_NOMATCH;
284}
285
paul94f2b392005-06-28 12:44:16 +0000286static void *
paulfd79ac92004-10-13 05:06:08 +0000287route_match_peer_compile (const char *arg)
paulfee0f4c2004-09-13 05:12:46 +0000288{
289 union sockunion *su;
290 int ret;
291
292 su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion));
293
Jorge Boncompte [DTI2]4fe080d2012-04-13 13:46:08 +0200294 ret = str2sockunion (strcmp(arg, "local") ? arg : "0.0.0.0", su);
paulfee0f4c2004-09-13 05:12:46 +0000295 if (ret < 0) {
296 XFREE (MTYPE_ROUTE_MAP_COMPILED, su);
297 return NULL;
298 }
299
300 return su;
301}
302
303/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000304static void
paulfee0f4c2004-09-13 05:12:46 +0000305route_match_peer_free (void *rule)
306{
307 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
308}
309
310/* Route map commands for ip address matching. */
311struct route_map_rule_cmd route_match_peer_cmd =
312{
313 "peer",
314 route_match_peer,
315 route_match_peer_compile,
316 route_match_peer_free
317};
318
paul718e3742002-12-13 20:15:29 +0000319/* `match ip address IP_ACCESS_LIST' */
320
321/* Match function should return 1 if match is success else return
322 zero. */
paul94f2b392005-06-28 12:44:16 +0000323static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000324route_match_ip_address (void *rule, struct prefix *prefix,
325 route_map_object_t type, void *object)
326{
327 struct access_list *alist;
328 /* struct prefix_ipv4 match; */
329
330 if (type == RMAP_BGP)
331 {
332 alist = access_list_lookup (AFI_IP, (char *) rule);
333 if (alist == NULL)
334 return RMAP_NOMATCH;
335
336 return (access_list_apply (alist, prefix) == FILTER_DENY ?
337 RMAP_NOMATCH : RMAP_MATCH);
338 }
339 return RMAP_NOMATCH;
340}
341
342/* Route map `ip address' match statement. `arg' should be
343 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000344static void *
paulfd79ac92004-10-13 05:06:08 +0000345route_match_ip_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000346{
347 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
348}
349
350/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000351static void
paul718e3742002-12-13 20:15:29 +0000352route_match_ip_address_free (void *rule)
353{
354 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
355}
356
357/* Route map commands for ip address matching. */
358struct route_map_rule_cmd route_match_ip_address_cmd =
359{
360 "ip address",
361 route_match_ip_address,
362 route_match_ip_address_compile,
363 route_match_ip_address_free
364};
David Lamparter6b0655a2014-06-04 06:53:35 +0200365
paul718e3742002-12-13 20:15:29 +0000366/* `match ip next-hop IP_ADDRESS' */
367
368/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000369static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000370route_match_ip_next_hop (void *rule, struct prefix *prefix,
371 route_map_object_t type, void *object)
372{
373 struct access_list *alist;
374 struct bgp_info *bgp_info;
375 struct prefix_ipv4 p;
376
377 if (type == RMAP_BGP)
378 {
379 bgp_info = object;
380 p.family = AF_INET;
381 p.prefix = bgp_info->attr->nexthop;
382 p.prefixlen = IPV4_MAX_BITLEN;
383
384 alist = access_list_lookup (AFI_IP, (char *) rule);
385 if (alist == NULL)
386 return RMAP_NOMATCH;
387
388 return (access_list_apply (alist, &p) == FILTER_DENY ?
389 RMAP_NOMATCH : RMAP_MATCH);
390 }
391 return RMAP_NOMATCH;
392}
393
394/* Route map `ip next-hop' match statement. `arg' is
395 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000396static void *
paulfd79ac92004-10-13 05:06:08 +0000397route_match_ip_next_hop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000398{
399 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
400}
401
402/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000403static void
paul718e3742002-12-13 20:15:29 +0000404route_match_ip_next_hop_free (void *rule)
405{
406 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
407}
408
409/* Route map commands for ip next-hop matching. */
410struct route_map_rule_cmd route_match_ip_next_hop_cmd =
411{
412 "ip next-hop",
413 route_match_ip_next_hop,
414 route_match_ip_next_hop_compile,
415 route_match_ip_next_hop_free
416};
David Lamparter6b0655a2014-06-04 06:53:35 +0200417
hassoc1643bb2005-02-02 16:43:17 +0000418/* `match ip route-source ACCESS-LIST' */
419
420/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000421static route_map_result_t
hassoc1643bb2005-02-02 16:43:17 +0000422route_match_ip_route_source (void *rule, struct prefix *prefix,
423 route_map_object_t type, void *object)
424{
425 struct access_list *alist;
426 struct bgp_info *bgp_info;
427 struct peer *peer;
428 struct prefix_ipv4 p;
429
430 if (type == RMAP_BGP)
431 {
432 bgp_info = object;
433 peer = bgp_info->peer;
434
435 if (! peer || sockunion_family (&peer->su) != AF_INET)
436 return RMAP_NOMATCH;
437
438 p.family = AF_INET;
439 p.prefix = peer->su.sin.sin_addr;
440 p.prefixlen = IPV4_MAX_BITLEN;
441
442 alist = access_list_lookup (AFI_IP, (char *) rule);
443 if (alist == NULL)
444 return RMAP_NOMATCH;
445
446 return (access_list_apply (alist, &p) == FILTER_DENY ?
447 RMAP_NOMATCH : RMAP_MATCH);
448 }
449 return RMAP_NOMATCH;
450}
451
452/* Route map `ip route-source' match statement. `arg' is
453 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000454static void *
hassoc1643bb2005-02-02 16:43:17 +0000455route_match_ip_route_source_compile (const char *arg)
456{
457 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
458}
459
460/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000461static void
hassoc1643bb2005-02-02 16:43:17 +0000462route_match_ip_route_source_free (void *rule)
463{
464 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
465}
466
467/* Route map commands for ip route-source matching. */
468struct route_map_rule_cmd route_match_ip_route_source_cmd =
469{
470 "ip route-source",
471 route_match_ip_route_source,
472 route_match_ip_route_source_compile,
473 route_match_ip_route_source_free
474};
David Lamparter6b0655a2014-06-04 06:53:35 +0200475
paul718e3742002-12-13 20:15:29 +0000476/* `match ip address prefix-list PREFIX_LIST' */
477
paul94f2b392005-06-28 12:44:16 +0000478static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000479route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
480 route_map_object_t type, void *object)
481{
482 struct prefix_list *plist;
483
484 if (type == RMAP_BGP)
485 {
486 plist = prefix_list_lookup (AFI_IP, (char *) rule);
487 if (plist == NULL)
488 return RMAP_NOMATCH;
489
490 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
491 RMAP_NOMATCH : RMAP_MATCH);
492 }
493 return RMAP_NOMATCH;
494}
495
paul94f2b392005-06-28 12:44:16 +0000496static void *
paulfd79ac92004-10-13 05:06:08 +0000497route_match_ip_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000498{
499 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
500}
501
paul94f2b392005-06-28 12:44:16 +0000502static void
paul718e3742002-12-13 20:15:29 +0000503route_match_ip_address_prefix_list_free (void *rule)
504{
505 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
506}
507
508struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
509{
510 "ip address prefix-list",
511 route_match_ip_address_prefix_list,
512 route_match_ip_address_prefix_list_compile,
513 route_match_ip_address_prefix_list_free
514};
David Lamparter6b0655a2014-06-04 06:53:35 +0200515
paul718e3742002-12-13 20:15:29 +0000516/* `match ip next-hop prefix-list PREFIX_LIST' */
517
paul94f2b392005-06-28 12:44:16 +0000518static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000519route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
520 route_map_object_t type, void *object)
521{
522 struct prefix_list *plist;
523 struct bgp_info *bgp_info;
524 struct prefix_ipv4 p;
525
526 if (type == RMAP_BGP)
527 {
528 bgp_info = object;
529 p.family = AF_INET;
530 p.prefix = bgp_info->attr->nexthop;
531 p.prefixlen = IPV4_MAX_BITLEN;
532
533 plist = prefix_list_lookup (AFI_IP, (char *) rule);
534 if (plist == NULL)
535 return RMAP_NOMATCH;
536
537 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
538 RMAP_NOMATCH : RMAP_MATCH);
539 }
540 return RMAP_NOMATCH;
541}
542
paul94f2b392005-06-28 12:44:16 +0000543static void *
paulfd79ac92004-10-13 05:06:08 +0000544route_match_ip_next_hop_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000545{
546 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
547}
548
paul94f2b392005-06-28 12:44:16 +0000549static void
paul718e3742002-12-13 20:15:29 +0000550route_match_ip_next_hop_prefix_list_free (void *rule)
551{
552 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
553}
554
555struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
556{
557 "ip next-hop prefix-list",
558 route_match_ip_next_hop_prefix_list,
559 route_match_ip_next_hop_prefix_list_compile,
560 route_match_ip_next_hop_prefix_list_free
561};
David Lamparter6b0655a2014-06-04 06:53:35 +0200562
hassoc1643bb2005-02-02 16:43:17 +0000563/* `match ip route-source prefix-list PREFIX_LIST' */
564
paul94f2b392005-06-28 12:44:16 +0000565static route_map_result_t
hassoc1643bb2005-02-02 16:43:17 +0000566route_match_ip_route_source_prefix_list (void *rule, struct prefix *prefix,
567 route_map_object_t type, void *object)
568{
569 struct prefix_list *plist;
570 struct bgp_info *bgp_info;
571 struct peer *peer;
572 struct prefix_ipv4 p;
573
574 if (type == RMAP_BGP)
575 {
576 bgp_info = object;
577 peer = bgp_info->peer;
578
579 if (! peer || sockunion_family (&peer->su) != AF_INET)
580 return RMAP_NOMATCH;
581
582 p.family = AF_INET;
583 p.prefix = peer->su.sin.sin_addr;
584 p.prefixlen = IPV4_MAX_BITLEN;
585
586 plist = prefix_list_lookup (AFI_IP, (char *) rule);
587 if (plist == NULL)
588 return RMAP_NOMATCH;
589
590 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
591 RMAP_NOMATCH : RMAP_MATCH);
592 }
593 return RMAP_NOMATCH;
594}
595
paul94f2b392005-06-28 12:44:16 +0000596static void *
hassoc1643bb2005-02-02 16:43:17 +0000597route_match_ip_route_source_prefix_list_compile (const char *arg)
598{
599 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
600}
601
paul94f2b392005-06-28 12:44:16 +0000602static void
hassoc1643bb2005-02-02 16:43:17 +0000603route_match_ip_route_source_prefix_list_free (void *rule)
604{
605 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
606}
607
608struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd =
609{
610 "ip route-source prefix-list",
611 route_match_ip_route_source_prefix_list,
612 route_match_ip_route_source_prefix_list_compile,
613 route_match_ip_route_source_prefix_list_free
614};
David Lamparter6b0655a2014-06-04 06:53:35 +0200615
paul718e3742002-12-13 20:15:29 +0000616/* `match metric METRIC' */
617
618/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000619static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000620route_match_metric (void *rule, struct prefix *prefix,
621 route_map_object_t type, void *object)
622{
Timo Teräs38f22ab2015-04-29 09:43:02 +0300623 struct rmap_value *rv;
paul718e3742002-12-13 20:15:29 +0000624 struct bgp_info *bgp_info;
625
626 if (type == RMAP_BGP)
627 {
Timo Teräs38f22ab2015-04-29 09:43:02 +0300628 rv = rule;
paul718e3742002-12-13 20:15:29 +0000629 bgp_info = object;
Timo Teräs38f22ab2015-04-29 09:43:02 +0300630 return route_value_match(rv, bgp_info->attr->med);
paul718e3742002-12-13 20:15:29 +0000631 }
632 return RMAP_NOMATCH;
633}
634
paul718e3742002-12-13 20:15:29 +0000635/* Route map commands for metric matching. */
636struct route_map_rule_cmd route_match_metric_cmd =
637{
638 "metric",
639 route_match_metric,
Timo Teräs38f22ab2015-04-29 09:43:02 +0300640 route_value_compile,
641 route_value_free,
paul718e3742002-12-13 20:15:29 +0000642};
David Lamparter6b0655a2014-06-04 06:53:35 +0200643
paul718e3742002-12-13 20:15:29 +0000644/* `match as-path ASPATH' */
645
646/* Match function for as-path match. I assume given object is */
paul94f2b392005-06-28 12:44:16 +0000647static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000648route_match_aspath (void *rule, struct prefix *prefix,
649 route_map_object_t type, void *object)
650{
651
652 struct as_list *as_list;
653 struct bgp_info *bgp_info;
654
655 if (type == RMAP_BGP)
656 {
657 as_list = as_list_lookup ((char *) rule);
658 if (as_list == NULL)
659 return RMAP_NOMATCH;
660
661 bgp_info = object;
662
663 /* Perform match. */
664 return ((as_list_apply (as_list, bgp_info->attr->aspath) == AS_FILTER_DENY) ? RMAP_NOMATCH : RMAP_MATCH);
665 }
666 return RMAP_NOMATCH;
667}
668
669/* Compile function for as-path match. */
paul94f2b392005-06-28 12:44:16 +0000670static void *
paulfd79ac92004-10-13 05:06:08 +0000671route_match_aspath_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000672{
673 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
674}
675
676/* Compile function for as-path match. */
paul94f2b392005-06-28 12:44:16 +0000677static void
paul718e3742002-12-13 20:15:29 +0000678route_match_aspath_free (void *rule)
679{
680 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
681}
682
683/* Route map commands for aspath matching. */
684struct route_map_rule_cmd route_match_aspath_cmd =
685{
686 "as-path",
687 route_match_aspath,
688 route_match_aspath_compile,
689 route_match_aspath_free
690};
David Lamparter6b0655a2014-06-04 06:53:35 +0200691
paul718e3742002-12-13 20:15:29 +0000692/* `match community COMMUNIY' */
693struct rmap_community
694{
695 char *name;
696 int exact;
697};
698
699/* Match function for community match. */
paul94f2b392005-06-28 12:44:16 +0000700static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000701route_match_community (void *rule, struct prefix *prefix,
702 route_map_object_t type, void *object)
703{
704 struct community_list *list;
705 struct bgp_info *bgp_info;
706 struct rmap_community *rcom;
707
708 if (type == RMAP_BGP)
709 {
710 bgp_info = object;
711 rcom = rule;
712
hassofee6e4e2005-02-02 16:29:31 +0000713 list = community_list_lookup (bgp_clist, rcom->name, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +0000714 if (! list)
715 return RMAP_NOMATCH;
716
717 if (rcom->exact)
718 {
719 if (community_list_exact_match (bgp_info->attr->community, list))
720 return RMAP_MATCH;
721 }
722 else
723 {
724 if (community_list_match (bgp_info->attr->community, list))
725 return RMAP_MATCH;
726 }
727 }
728 return RMAP_NOMATCH;
729}
730
731/* Compile function for community match. */
paul94f2b392005-06-28 12:44:16 +0000732static void *
paulfd79ac92004-10-13 05:06:08 +0000733route_match_community_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000734{
735 struct rmap_community *rcom;
736 int len;
737 char *p;
738
739 rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community));
740
741 p = strchr (arg, ' ');
742 if (p)
743 {
744 len = p - arg;
745 rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
746 memcpy (rcom->name, arg, len);
747 rcom->exact = 1;
748 }
749 else
750 {
751 rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
752 rcom->exact = 0;
753 }
754 return rcom;
755}
756
757/* Compile function for community match. */
paul94f2b392005-06-28 12:44:16 +0000758static void
paul718e3742002-12-13 20:15:29 +0000759route_match_community_free (void *rule)
760{
761 struct rmap_community *rcom = rule;
762
763 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name);
764 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom);
765}
766
767/* Route map commands for community matching. */
768struct route_map_rule_cmd route_match_community_cmd =
769{
770 "community",
771 route_match_community,
772 route_match_community_compile,
773 route_match_community_free
774};
David Lamparter6b0655a2014-06-04 06:53:35 +0200775
paul73ffb252003-04-19 15:49:49 +0000776/* Match function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000777static route_map_result_t
paul73ffb252003-04-19 15:49:49 +0000778route_match_ecommunity (void *rule, struct prefix *prefix,
779 route_map_object_t type, void *object)
780{
781 struct community_list *list;
782 struct bgp_info *bgp_info;
783
784 if (type == RMAP_BGP)
785 {
786 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +0000787
788 if (!bgp_info->attr->extra)
789 return RMAP_NOMATCH;
790
paul73ffb252003-04-19 15:49:49 +0000791 list = community_list_lookup (bgp_clist, (char *) rule,
hassofee6e4e2005-02-02 16:29:31 +0000792 EXTCOMMUNITY_LIST_MASTER);
paul73ffb252003-04-19 15:49:49 +0000793 if (! list)
794 return RMAP_NOMATCH;
795
Paul Jakmafb982c22007-05-04 20:15:47 +0000796 if (ecommunity_list_match (bgp_info->attr->extra->ecommunity, list))
paul73ffb252003-04-19 15:49:49 +0000797 return RMAP_MATCH;
798 }
799 return RMAP_NOMATCH;
800}
801
802/* Compile function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000803static void *
paulfd79ac92004-10-13 05:06:08 +0000804route_match_ecommunity_compile (const char *arg)
paul73ffb252003-04-19 15:49:49 +0000805{
806 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
807}
808
809/* Compile function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000810static void
paul73ffb252003-04-19 15:49:49 +0000811route_match_ecommunity_free (void *rule)
812{
813 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
814}
815
816/* Route map commands for community matching. */
817struct route_map_rule_cmd route_match_ecommunity_cmd =
818{
819 "extcommunity",
820 route_match_ecommunity,
821 route_match_ecommunity_compile,
822 route_match_ecommunity_free
823};
David Lamparter6b0655a2014-06-04 06:53:35 +0200824
paul718e3742002-12-13 20:15:29 +0000825/* `match nlri` and `set nlri` are replaced by `address-family ipv4`
826 and `address-family vpnv4'. */
David Lamparter6b0655a2014-06-04 06:53:35 +0200827
paul718e3742002-12-13 20:15:29 +0000828/* `match origin' */
paul94f2b392005-06-28 12:44:16 +0000829static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000830route_match_origin (void *rule, struct prefix *prefix,
831 route_map_object_t type, void *object)
832{
833 u_char *origin;
834 struct bgp_info *bgp_info;
835
836 if (type == RMAP_BGP)
837 {
838 origin = rule;
839 bgp_info = object;
840
841 if (bgp_info->attr->origin == *origin)
842 return RMAP_MATCH;
843 }
844
845 return RMAP_NOMATCH;
846}
847
paul94f2b392005-06-28 12:44:16 +0000848static void *
paulfd79ac92004-10-13 05:06:08 +0000849route_match_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000850{
851 u_char *origin;
852
853 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
854
855 if (strcmp (arg, "igp") == 0)
856 *origin = 0;
857 else if (strcmp (arg, "egp") == 0)
858 *origin = 1;
859 else
860 *origin = 2;
861
862 return origin;
863}
864
865/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000866static void
paul718e3742002-12-13 20:15:29 +0000867route_match_origin_free (void *rule)
868{
869 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
870}
871
872/* Route map commands for origin matching. */
873struct route_map_rule_cmd route_match_origin_cmd =
874{
875 "origin",
876 route_match_origin,
877 route_match_origin_compile,
878 route_match_origin_free
879};
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +0400880
881/* match probability { */
882
883static route_map_result_t
884route_match_probability (void *rule, struct prefix *prefix,
885 route_map_object_t type, void *object)
886{
Donald Sharpf31bab42015-06-19 19:26:19 -0400887 long r = random();
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +0400888
David Lamparter8c9cd852015-04-19 14:40:02 +0200889 switch (*(long *) rule)
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +0400890 {
891 case 0: break;
892 case RAND_MAX: return RMAP_MATCH;
893 default:
David Lamparter8c9cd852015-04-19 14:40:02 +0200894 if (r < *(long *) rule)
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +0400895 {
896 return RMAP_MATCH;
897 }
898 }
899
900 return RMAP_NOMATCH;
901}
902
903static void *
904route_match_probability_compile (const char *arg)
905{
David Lamparter8c9cd852015-04-19 14:40:02 +0200906 long *lobule;
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +0400907 unsigned perc;
908
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +0400909 perc = atoi (arg);
David Lamparter8c9cd852015-04-19 14:40:02 +0200910 lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (long));
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +0400911
912 switch (perc)
913 {
914 case 0: *lobule = 0; break;
915 case 100: *lobule = RAND_MAX; break;
916 default: *lobule = RAND_MAX / 100 * perc;
917 }
918
919 return lobule;
920}
921
922static void
923route_match_probability_free (void *rule)
924{
925 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
926}
927
928struct route_map_rule_cmd route_match_probability_cmd =
929{
930 "probability",
931 route_match_probability,
932 route_match_probability_compile,
933 route_match_probability_free
934};
935
936/* } */
937
paul718e3742002-12-13 20:15:29 +0000938/* `set ip next-hop IP_ADDRESS' */
939
940/* Set nexthop to object. ojbect must be pointer to struct attr. */
paulac41b2a2003-08-12 05:32:27 +0000941struct rmap_ip_nexthop_set
942{
943 struct in_addr *address;
944 int peer_address;
945};
946
paul94f2b392005-06-28 12:44:16 +0000947static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000948route_set_ip_nexthop (void *rule, struct prefix *prefix,
949 route_map_object_t type, void *object)
950{
paulac41b2a2003-08-12 05:32:27 +0000951 struct rmap_ip_nexthop_set *rins = rule;
paul718e3742002-12-13 20:15:29 +0000952 struct bgp_info *bgp_info;
paulac41b2a2003-08-12 05:32:27 +0000953 struct peer *peer;
paul718e3742002-12-13 20:15:29 +0000954
955 if (type == RMAP_BGP)
956 {
paul718e3742002-12-13 20:15:29 +0000957 bgp_info = object;
paulac41b2a2003-08-12 05:32:27 +0000958 peer = bgp_info->peer;
959
960 if (rins->peer_address)
961 {
paulfee0f4c2004-09-13 05:12:46 +0000962 if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) ||
963 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
paulac41b2a2003-08-12 05:32:27 +0000964 && peer->su_remote
965 && sockunion_family (peer->su_remote) == AF_INET)
966 {
Jorge Boncompte [DTI2]0c5ed3e2012-04-10 16:57:22 +0200967 bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_remote);
paulac41b2a2003-08-12 05:32:27 +0000968 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
969 }
970 else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
971 && peer->su_local
972 && sockunion_family (peer->su_local) == AF_INET)
973 {
Jorge Boncompte [DTI2]0c5ed3e2012-04-10 16:57:22 +0200974 bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_local);
paulac41b2a2003-08-12 05:32:27 +0000975 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
976 }
977 }
978 else
979 {
980 /* Set next hop value. */
981 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
982 bgp_info->attr->nexthop = *rins->address;
983 }
paul718e3742002-12-13 20:15:29 +0000984 }
985
986 return RMAP_OKAY;
987}
988
989/* Route map `ip nexthop' compile function. Given string is converted
990 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +0000991static void *
paulfd79ac92004-10-13 05:06:08 +0000992route_set_ip_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000993{
paulac41b2a2003-08-12 05:32:27 +0000994 struct rmap_ip_nexthop_set *rins;
995 struct in_addr *address = NULL;
996 int peer_address = 0;
paul718e3742002-12-13 20:15:29 +0000997 int ret;
paul718e3742002-12-13 20:15:29 +0000998
paulac41b2a2003-08-12 05:32:27 +0000999 if (strcmp (arg, "peer-address") == 0)
1000 peer_address = 1;
1001 else
paul718e3742002-12-13 20:15:29 +00001002 {
paulac41b2a2003-08-12 05:32:27 +00001003 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
1004 ret = inet_aton (arg, address);
1005
1006 if (ret == 0)
1007 {
1008 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1009 return NULL;
1010 }
paul718e3742002-12-13 20:15:29 +00001011 }
1012
Stephen Hemminger393deb92008-08-18 14:13:29 -07001013 rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set));
paulac41b2a2003-08-12 05:32:27 +00001014
1015 rins->address = address;
1016 rins->peer_address = peer_address;
1017
1018 return rins;
paul718e3742002-12-13 20:15:29 +00001019}
1020
1021/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +00001022static void
paul718e3742002-12-13 20:15:29 +00001023route_set_ip_nexthop_free (void *rule)
1024{
paulac41b2a2003-08-12 05:32:27 +00001025 struct rmap_ip_nexthop_set *rins = rule;
1026
1027 if (rins->address)
1028 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address);
1029
1030 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins);
paul718e3742002-12-13 20:15:29 +00001031}
1032
1033/* Route map commands for ip nexthop set. */
1034struct route_map_rule_cmd route_set_ip_nexthop_cmd =
1035{
1036 "ip next-hop",
1037 route_set_ip_nexthop,
1038 route_set_ip_nexthop_compile,
1039 route_set_ip_nexthop_free
1040};
David Lamparter6b0655a2014-06-04 06:53:35 +02001041
paul718e3742002-12-13 20:15:29 +00001042/* `set local-preference LOCAL_PREF' */
1043
1044/* Set local preference. */
paul94f2b392005-06-28 12:44:16 +00001045static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001046route_set_local_pref (void *rule, struct prefix *prefix,
1047 route_map_object_t type, void *object)
1048{
Timo Teräs38f22ab2015-04-29 09:43:02 +03001049 struct rmap_value *rv;
paul718e3742002-12-13 20:15:29 +00001050 struct bgp_info *bgp_info;
Timo Teräs38f22ab2015-04-29 09:43:02 +03001051 u_int32_t locpref = 0;
paul718e3742002-12-13 20:15:29 +00001052
1053 if (type == RMAP_BGP)
1054 {
1055 /* Fetch routemap's rule information. */
Timo Teräs38f22ab2015-04-29 09:43:02 +03001056 rv = rule;
paul718e3742002-12-13 20:15:29 +00001057 bgp_info = object;
1058
1059 /* Set local preference value. */
Timo Teräs38f22ab2015-04-29 09:43:02 +03001060 if (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
1061 locpref = bgp_info->attr->local_pref;
1062
paul718e3742002-12-13 20:15:29 +00001063 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
Timo Teräsef757702015-04-29 09:43:04 +03001064 bgp_info->attr->local_pref = route_value_adjust(rv, locpref, bgp_info->peer);
paul718e3742002-12-13 20:15:29 +00001065 }
1066
1067 return RMAP_OKAY;
1068}
1069
paul718e3742002-12-13 20:15:29 +00001070/* Set local preference rule structure. */
1071struct route_map_rule_cmd route_set_local_pref_cmd =
1072{
1073 "local-preference",
1074 route_set_local_pref,
Timo Teräs38f22ab2015-04-29 09:43:02 +03001075 route_value_compile,
1076 route_value_free,
paul718e3742002-12-13 20:15:29 +00001077};
David Lamparter6b0655a2014-06-04 06:53:35 +02001078
paul718e3742002-12-13 20:15:29 +00001079/* `set weight WEIGHT' */
1080
1081/* Set weight. */
paul94f2b392005-06-28 12:44:16 +00001082static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001083route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type,
1084 void *object)
1085{
Timo Teräs38f22ab2015-04-29 09:43:02 +03001086 struct rmap_value *rv;
paul718e3742002-12-13 20:15:29 +00001087 struct bgp_info *bgp_info;
Timo Teräs38f22ab2015-04-29 09:43:02 +03001088 u_int32_t weight;
paul718e3742002-12-13 20:15:29 +00001089
1090 if (type == RMAP_BGP)
1091 {
1092 /* Fetch routemap's rule information. */
Timo Teräs38f22ab2015-04-29 09:43:02 +03001093 rv = rule;
paul718e3742002-12-13 20:15:29 +00001094 bgp_info = object;
1095
1096 /* Set weight value. */
Timo Teräsef757702015-04-29 09:43:04 +03001097 weight = route_value_adjust(rv, 0, bgp_info->peer);
Timo Teräs38f22ab2015-04-29 09:43:02 +03001098 if (weight)
1099 (bgp_attr_extra_get (bgp_info->attr))->weight = weight;
Paul Jakmafb982c22007-05-04 20:15:47 +00001100 else if (bgp_info->attr->extra)
1101 bgp_info->attr->extra->weight = 0;
paul718e3742002-12-13 20:15:29 +00001102 }
1103
1104 return RMAP_OKAY;
1105}
1106
paul718e3742002-12-13 20:15:29 +00001107/* Set local preference rule structure. */
1108struct route_map_rule_cmd route_set_weight_cmd =
1109{
1110 "weight",
1111 route_set_weight,
Timo Teräs38f22ab2015-04-29 09:43:02 +03001112 route_value_compile,
1113 route_value_free,
paul718e3742002-12-13 20:15:29 +00001114};
David Lamparter6b0655a2014-06-04 06:53:35 +02001115
paul718e3742002-12-13 20:15:29 +00001116/* `set metric METRIC' */
1117
1118/* Set metric to attribute. */
paul94f2b392005-06-28 12:44:16 +00001119static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001120route_set_metric (void *rule, struct prefix *prefix,
1121 route_map_object_t type, void *object)
1122{
Timo Teräs38f22ab2015-04-29 09:43:02 +03001123 struct rmap_value *rv;
paul718e3742002-12-13 20:15:29 +00001124 struct bgp_info *bgp_info;
Timo Teräs38f22ab2015-04-29 09:43:02 +03001125 u_int32_t med = 0;
paul718e3742002-12-13 20:15:29 +00001126
1127 if (type == RMAP_BGP)
1128 {
1129 /* Fetch routemap's rule information. */
Timo Teräs38f22ab2015-04-29 09:43:02 +03001130 rv = rule;
paul718e3742002-12-13 20:15:29 +00001131 bgp_info = object;
1132
Timo Teräs38f22ab2015-04-29 09:43:02 +03001133 if (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
1134 med = bgp_info->attr->med;
1135
Timo Teräsef757702015-04-29 09:43:04 +03001136 bgp_info->attr->med = route_value_adjust(rv, med, bgp_info->peer);
paul718e3742002-12-13 20:15:29 +00001137 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00001138 }
1139 return RMAP_OKAY;
1140}
1141
paul718e3742002-12-13 20:15:29 +00001142/* Set metric rule structure. */
1143struct route_map_rule_cmd route_set_metric_cmd =
1144{
1145 "metric",
1146 route_set_metric,
Timo Teräs38f22ab2015-04-29 09:43:02 +03001147 route_value_compile,
1148 route_value_free,
paul718e3742002-12-13 20:15:29 +00001149};
David Lamparter6b0655a2014-06-04 06:53:35 +02001150
paul718e3742002-12-13 20:15:29 +00001151/* `set as-path prepend ASPATH' */
1152
1153/* For AS path prepend mechanism. */
paul94f2b392005-06-28 12:44:16 +00001154static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001155route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1156{
1157 struct aspath *aspath;
1158 struct aspath *new;
1159 struct bgp_info *binfo;
1160
1161 if (type == RMAP_BGP)
1162 {
paul718e3742002-12-13 20:15:29 +00001163 binfo = object;
1164
1165 if (binfo->attr->aspath->refcnt)
1166 new = aspath_dup (binfo->attr->aspath);
1167 else
1168 new = binfo->attr->aspath;
1169
Timo Teräs85c854a2014-09-30 11:31:53 +03001170 if ((uintptr_t)rule > 10)
1171 {
1172 aspath = rule;
1173 aspath_prepend (aspath, new);
1174 }
1175 else
1176 {
1177 as_t as = aspath_leftmost(new);
1178 if (!as) as = binfo->peer->as;
1179 new = aspath_add_seq_n (new, as, (uintptr_t) rule);
1180 }
1181
paul718e3742002-12-13 20:15:29 +00001182 binfo->attr->aspath = new;
1183 }
1184
1185 return RMAP_OKAY;
1186}
1187
Timo Teräs85c854a2014-09-30 11:31:53 +03001188static void *
1189route_set_aspath_prepend_compile (const char *arg)
1190{
1191 unsigned int num;
1192
1193 if (sscanf(arg, "last-as %u", &num) == 1 && num > 0 && num < 10)
1194 return (void*)(uintptr_t)num;
1195
1196 return route_aspath_compile(arg);
1197}
1198
1199static void
1200route_set_aspath_prepend_free (void *rule)
1201{
1202 if ((uintptr_t)rule > 10)
1203 route_aspath_free(rule);
1204}
1205
1206
Timo Teräs2aa640b2014-05-20 08:57:26 +03001207/* Set as-path prepend rule structure. */
paul718e3742002-12-13 20:15:29 +00001208struct route_map_rule_cmd route_set_aspath_prepend_cmd =
1209{
1210 "as-path prepend",
1211 route_set_aspath_prepend,
Timo Teräs85c854a2014-09-30 11:31:53 +03001212 route_set_aspath_prepend_compile,
1213 route_set_aspath_prepend_free,
paul718e3742002-12-13 20:15:29 +00001214};
David Lamparter6b0655a2014-06-04 06:53:35 +02001215
Denis Ovsienko841f7a52008-04-10 11:47:45 +00001216/* `set as-path exclude ASn' */
1217
1218/* For ASN exclude mechanism.
1219 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1220 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1221 */
1222static route_map_result_t
1223route_set_aspath_exclude (void *rule, struct prefix *dummy, route_map_object_t type, void *object)
1224{
1225 struct aspath * new_path, * exclude_path;
1226 struct bgp_info *binfo;
1227
1228 if (type == RMAP_BGP)
1229 {
1230 exclude_path = rule;
1231 binfo = object;
1232 if (binfo->attr->aspath->refcnt)
1233 new_path = aspath_dup (binfo->attr->aspath);
1234 else
1235 new_path = binfo->attr->aspath;
1236 binfo->attr->aspath = aspath_filter_exclude (new_path, exclude_path);
1237 }
1238 return RMAP_OKAY;
1239}
1240
Denis Ovsienko841f7a52008-04-10 11:47:45 +00001241/* Set ASn exlude rule structure. */
1242struct route_map_rule_cmd route_set_aspath_exclude_cmd =
1243{
1244 "as-path exclude",
1245 route_set_aspath_exclude,
Timo Teräsb304dcb2014-05-20 09:04:49 +03001246 route_aspath_compile,
1247 route_aspath_free,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00001248};
David Lamparter6b0655a2014-06-04 06:53:35 +02001249
paul718e3742002-12-13 20:15:29 +00001250/* `set community COMMUNITY' */
1251struct rmap_com_set
1252{
1253 struct community *com;
1254 int additive;
1255 int none;
1256};
1257
1258/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001259static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001260route_set_community (void *rule, struct prefix *prefix,
1261 route_map_object_t type, void *object)
1262{
1263 struct rmap_com_set *rcs;
1264 struct bgp_info *binfo;
1265 struct attr *attr;
1266 struct community *new = NULL;
1267 struct community *old;
1268 struct community *merge;
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001269
paul718e3742002-12-13 20:15:29 +00001270 if (type == RMAP_BGP)
1271 {
1272 rcs = rule;
1273 binfo = object;
1274 attr = binfo->attr;
1275 old = attr->community;
1276
1277 /* "none" case. */
1278 if (rcs->none)
1279 {
1280 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES));
1281 attr->community = NULL;
Christian Frankeb06b35f2012-12-07 14:26:09 +00001282 /* See the longer comment down below. */
1283 if (old && old->refcnt == 0)
1284 community_free(old);
paul718e3742002-12-13 20:15:29 +00001285 return RMAP_OKAY;
1286 }
1287
1288 /* "additive" case. */
1289 if (rcs->additive && old)
1290 {
1291 merge = community_merge (community_dup (old), rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001292
1293 /* HACK: if the old community is not intern'd,
1294 * we should free it here, or all reference to it may be lost.
1295 * Really need to cleanup attribute caching sometime.
1296 */
1297 if (old->refcnt == 0)
1298 community_free (old);
paul718e3742002-12-13 20:15:29 +00001299 new = community_uniq_sort (merge);
1300 community_free (merge);
1301 }
1302 else
1303 new = community_dup (rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001304
1305 /* will be interned by caller if required */
Paul Jakma4a2035f2011-04-01 15:58:27 +01001306 attr->community = new;
hasso70601e02005-05-27 03:26:57 +00001307
paul718e3742002-12-13 20:15:29 +00001308 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1309 }
1310
1311 return RMAP_OKAY;
1312}
1313
1314/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001315static void *
paulfd79ac92004-10-13 05:06:08 +00001316route_set_community_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001317{
1318 struct rmap_com_set *rcs;
1319 struct community *com = NULL;
1320 char *sp;
1321 int additive = 0;
1322 int none = 0;
1323
1324 if (strcmp (arg, "none") == 0)
1325 none = 1;
1326 else
1327 {
1328 sp = strstr (arg, "additive");
1329
1330 if (sp && sp > arg)
1331 {
1332 /* "additive" keyworkd is included. */
1333 additive = 1;
1334 *(sp - 1) = '\0';
1335 }
1336
1337 com = community_str2com (arg);
1338
1339 if (additive)
1340 *(sp - 1) = ' ';
1341
1342 if (! com)
1343 return NULL;
1344 }
1345
Stephen Hemminger393deb92008-08-18 14:13:29 -07001346 rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
Paul Jakma4a2035f2011-04-01 15:58:27 +01001347 rcs->com = com;
paul718e3742002-12-13 20:15:29 +00001348 rcs->additive = additive;
1349 rcs->none = none;
1350
1351 return rcs;
1352}
1353
1354/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001355static void
paul718e3742002-12-13 20:15:29 +00001356route_set_community_free (void *rule)
1357{
1358 struct rmap_com_set *rcs = rule;
1359
1360 if (rcs->com)
1361 community_free (rcs->com);
1362 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs);
1363}
1364
1365/* Set community rule structure. */
1366struct route_map_rule_cmd route_set_community_cmd =
1367{
1368 "community",
1369 route_set_community,
1370 route_set_community_compile,
1371 route_set_community_free,
1372};
David Lamparter6b0655a2014-06-04 06:53:35 +02001373
hassofee6e4e2005-02-02 16:29:31 +00001374/* `set comm-list (<1-99>|<100-500>|WORD) delete' */
paul718e3742002-12-13 20:15:29 +00001375
1376/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001377static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001378route_set_community_delete (void *rule, struct prefix *prefix,
1379 route_map_object_t type, void *object)
1380{
1381 struct community_list *list;
1382 struct community *merge;
1383 struct community *new;
1384 struct community *old;
1385 struct bgp_info *binfo;
1386
1387 if (type == RMAP_BGP)
1388 {
1389 if (! rule)
1390 return RMAP_OKAY;
1391
1392 binfo = object;
hassofee6e4e2005-02-02 16:29:31 +00001393 list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00001394 old = binfo->attr->community;
1395
1396 if (list && old)
1397 {
1398 merge = community_list_match_delete (community_dup (old), list);
1399 new = community_uniq_sort (merge);
1400 community_free (merge);
1401
Michael Lambert604a9b42010-09-13 11:48:11 -04001402 /* HACK: if the old community is not intern'd,
1403 * we should free it here, or all reference to it may be lost.
1404 * Really need to cleanup attribute caching sometime.
1405 */
1406 if (old->refcnt == 0)
1407 community_free (old);
1408
paul718e3742002-12-13 20:15:29 +00001409 if (new->size == 0)
1410 {
1411 binfo->attr->community = NULL;
1412 binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1413 community_free (new);
1414 }
1415 else
1416 {
Paul Jakma4a2035f2011-04-01 15:58:27 +01001417 binfo->attr->community = new;
paul718e3742002-12-13 20:15:29 +00001418 binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1419 }
1420 }
1421 }
1422
1423 return RMAP_OKAY;
1424}
1425
1426/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001427static void *
paulfd79ac92004-10-13 05:06:08 +00001428route_set_community_delete_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001429{
1430 char *p;
1431 char *str;
1432 int len;
1433
1434 p = strchr (arg, ' ');
1435 if (p)
1436 {
1437 len = p - arg;
1438 str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
1439 memcpy (str, arg, len);
1440 }
1441 else
1442 str = NULL;
1443
1444 return str;
1445}
1446
1447/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001448static void
paul718e3742002-12-13 20:15:29 +00001449route_set_community_delete_free (void *rule)
1450{
1451 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1452}
1453
1454/* Set community rule structure. */
1455struct route_map_rule_cmd route_set_community_delete_cmd =
1456{
1457 "comm-list",
1458 route_set_community_delete,
1459 route_set_community_delete_compile,
1460 route_set_community_delete_free,
1461};
David Lamparter6b0655a2014-06-04 06:53:35 +02001462
paul718e3742002-12-13 20:15:29 +00001463/* `set extcommunity rt COMMUNITY' */
1464
David Lamparter73d78ea2014-06-04 00:58:47 +02001465/* For community set mechanism. Used by _rt and _soo. */
paul94f2b392005-06-28 12:44:16 +00001466static route_map_result_t
David Lamparter73d78ea2014-06-04 00:58:47 +02001467route_set_ecommunity (void *rule, struct prefix *prefix,
1468 route_map_object_t type, void *object)
paul718e3742002-12-13 20:15:29 +00001469{
1470 struct ecommunity *ecom;
1471 struct ecommunity *new_ecom;
1472 struct ecommunity *old_ecom;
1473 struct bgp_info *bgp_info;
1474
1475 if (type == RMAP_BGP)
1476 {
1477 ecom = rule;
1478 bgp_info = object;
1479
1480 if (! ecom)
1481 return RMAP_OKAY;
1482
1483 /* We assume additive for Extended Community. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001484 old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
paul718e3742002-12-13 20:15:29 +00001485
1486 if (old_ecom)
David Lamparter27bf90a2014-06-04 00:59:01 +02001487 {
1488 new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
1489
1490 /* old_ecom->refcnt = 1 => owned elsewhere, e.g. bgp_update_receive()
1491 * ->refcnt = 0 => set by a previous route-map statement */
1492 if (!old_ecom->refcnt)
1493 ecommunity_free (&old_ecom);
1494 }
paul718e3742002-12-13 20:15:29 +00001495 else
1496 new_ecom = ecommunity_dup (ecom);
1497
David Lamparter27bf90a2014-06-04 00:59:01 +02001498 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1499 bgp_info->attr->extra->ecommunity = new_ecom;
hasso70601e02005-05-27 03:26:57 +00001500
paul718e3742002-12-13 20:15:29 +00001501 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
1502 }
1503 return RMAP_OKAY;
1504}
1505
1506/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001507static void *
paulfd79ac92004-10-13 05:06:08 +00001508route_set_ecommunity_rt_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001509{
1510 struct ecommunity *ecom;
1511
1512 ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0);
1513 if (! ecom)
1514 return NULL;
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001515 return ecommunity_intern (ecom);
paul718e3742002-12-13 20:15:29 +00001516}
1517
David Lamparter73d78ea2014-06-04 00:58:47 +02001518/* Free function for set community. Used by _rt and _soo */
paul94f2b392005-06-28 12:44:16 +00001519static void
David Lamparter73d78ea2014-06-04 00:58:47 +02001520route_set_ecommunity_free (void *rule)
paul718e3742002-12-13 20:15:29 +00001521{
1522 struct ecommunity *ecom = rule;
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001523 ecommunity_unintern (&ecom);
paul718e3742002-12-13 20:15:29 +00001524}
1525
1526/* Set community rule structure. */
1527struct route_map_rule_cmd route_set_ecommunity_rt_cmd =
1528{
1529 "extcommunity rt",
David Lamparter73d78ea2014-06-04 00:58:47 +02001530 route_set_ecommunity,
paul718e3742002-12-13 20:15:29 +00001531 route_set_ecommunity_rt_compile,
David Lamparter73d78ea2014-06-04 00:58:47 +02001532 route_set_ecommunity_free,
paul718e3742002-12-13 20:15:29 +00001533};
1534
1535/* `set extcommunity soo COMMUNITY' */
1536
paul718e3742002-12-13 20:15:29 +00001537/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001538static void *
paulfd79ac92004-10-13 05:06:08 +00001539route_set_ecommunity_soo_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001540{
1541 struct ecommunity *ecom;
1542
1543 ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0);
1544 if (! ecom)
1545 return NULL;
1546
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001547 return ecommunity_intern (ecom);
paul718e3742002-12-13 20:15:29 +00001548}
1549
paul718e3742002-12-13 20:15:29 +00001550/* Set community rule structure. */
1551struct route_map_rule_cmd route_set_ecommunity_soo_cmd =
1552{
1553 "extcommunity soo",
David Lamparter73d78ea2014-06-04 00:58:47 +02001554 route_set_ecommunity,
paul718e3742002-12-13 20:15:29 +00001555 route_set_ecommunity_soo_compile,
David Lamparter73d78ea2014-06-04 00:58:47 +02001556 route_set_ecommunity_free,
paul718e3742002-12-13 20:15:29 +00001557};
David Lamparter6b0655a2014-06-04 06:53:35 +02001558
paul718e3742002-12-13 20:15:29 +00001559/* `set origin ORIGIN' */
1560
1561/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00001562static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001563route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1564{
1565 u_char *origin;
1566 struct bgp_info *bgp_info;
1567
1568 if (type == RMAP_BGP)
1569 {
1570 origin = rule;
1571 bgp_info = object;
1572
1573 bgp_info->attr->origin = *origin;
1574 }
1575
1576 return RMAP_OKAY;
1577}
1578
1579/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001580static void *
paulfd79ac92004-10-13 05:06:08 +00001581route_set_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001582{
1583 u_char *origin;
1584
1585 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
1586
1587 if (strcmp (arg, "igp") == 0)
1588 *origin = 0;
1589 else if (strcmp (arg, "egp") == 0)
1590 *origin = 1;
1591 else
1592 *origin = 2;
1593
1594 return origin;
1595}
1596
1597/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001598static void
paul718e3742002-12-13 20:15:29 +00001599route_set_origin_free (void *rule)
1600{
1601 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1602}
1603
Timo Teräs2aa640b2014-05-20 08:57:26 +03001604/* Set origin rule structure. */
paul718e3742002-12-13 20:15:29 +00001605struct route_map_rule_cmd route_set_origin_cmd =
1606{
1607 "origin",
1608 route_set_origin,
1609 route_set_origin_compile,
1610 route_set_origin_free,
1611};
David Lamparter6b0655a2014-06-04 06:53:35 +02001612
paul718e3742002-12-13 20:15:29 +00001613/* `set atomic-aggregate' */
1614
1615/* For atomic aggregate set. */
paul94f2b392005-06-28 12:44:16 +00001616static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001617route_set_atomic_aggregate (void *rule, struct prefix *prefix,
1618 route_map_object_t type, void *object)
1619{
1620 struct bgp_info *bgp_info;
1621
1622 if (type == RMAP_BGP)
1623 {
1624 bgp_info = object;
1625 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
1626 }
1627
1628 return RMAP_OKAY;
1629}
1630
1631/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001632static void *
paulfd79ac92004-10-13 05:06:08 +00001633route_set_atomic_aggregate_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001634{
1635 return (void *)1;
1636}
1637
1638/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001639static void
paul718e3742002-12-13 20:15:29 +00001640route_set_atomic_aggregate_free (void *rule)
1641{
1642 return;
1643}
1644
1645/* Set atomic aggregate rule structure. */
1646struct route_map_rule_cmd route_set_atomic_aggregate_cmd =
1647{
1648 "atomic-aggregate",
1649 route_set_atomic_aggregate,
1650 route_set_atomic_aggregate_compile,
1651 route_set_atomic_aggregate_free,
1652};
David Lamparter6b0655a2014-06-04 06:53:35 +02001653
paul718e3742002-12-13 20:15:29 +00001654/* `set aggregator as AS A.B.C.D' */
1655struct aggregator
1656{
1657 as_t as;
1658 struct in_addr address;
1659};
1660
paul94f2b392005-06-28 12:44:16 +00001661static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001662route_set_aggregator_as (void *rule, struct prefix *prefix,
1663 route_map_object_t type, void *object)
1664{
1665 struct bgp_info *bgp_info;
1666 struct aggregator *aggregator;
Paul Jakmafb982c22007-05-04 20:15:47 +00001667 struct attr_extra *ae;
paul718e3742002-12-13 20:15:29 +00001668
1669 if (type == RMAP_BGP)
1670 {
1671 bgp_info = object;
1672 aggregator = rule;
Paul Jakmafb982c22007-05-04 20:15:47 +00001673 ae = bgp_attr_extra_get (bgp_info->attr);
1674
1675 ae->aggregator_as = aggregator->as;
1676 ae->aggregator_addr = aggregator->address;
paul718e3742002-12-13 20:15:29 +00001677 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
1678 }
1679
1680 return RMAP_OKAY;
1681}
1682
paul94f2b392005-06-28 12:44:16 +00001683static void *
paulfd79ac92004-10-13 05:06:08 +00001684route_set_aggregator_as_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001685{
1686 struct aggregator *aggregator;
1687 char as[10];
1688 char address[20];
1689
Stephen Hemminger393deb92008-08-18 14:13:29 -07001690 aggregator = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));
paul718e3742002-12-13 20:15:29 +00001691 sscanf (arg, "%s %s", as, address);
1692
1693 aggregator->as = strtoul (as, NULL, 10);
1694 inet_aton (address, &aggregator->address);
1695
1696 return aggregator;
1697}
1698
paul94f2b392005-06-28 12:44:16 +00001699static void
paul718e3742002-12-13 20:15:29 +00001700route_set_aggregator_as_free (void *rule)
1701{
1702 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1703}
1704
1705struct route_map_rule_cmd route_set_aggregator_as_cmd =
1706{
1707 "aggregator as",
1708 route_set_aggregator_as,
1709 route_set_aggregator_as_compile,
1710 route_set_aggregator_as_free,
1711};
David Lamparter6b0655a2014-06-04 06:53:35 +02001712
paul718e3742002-12-13 20:15:29 +00001713#ifdef HAVE_IPV6
1714/* `match ipv6 address IP_ACCESS_LIST' */
1715
paul94f2b392005-06-28 12:44:16 +00001716static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001717route_match_ipv6_address (void *rule, struct prefix *prefix,
1718 route_map_object_t type, void *object)
1719{
1720 struct access_list *alist;
1721
1722 if (type == RMAP_BGP)
1723 {
1724 alist = access_list_lookup (AFI_IP6, (char *) rule);
1725 if (alist == NULL)
1726 return RMAP_NOMATCH;
1727
1728 return (access_list_apply (alist, prefix) == FILTER_DENY ?
1729 RMAP_NOMATCH : RMAP_MATCH);
1730 }
1731 return RMAP_NOMATCH;
1732}
1733
paul94f2b392005-06-28 12:44:16 +00001734static void *
paulfd79ac92004-10-13 05:06:08 +00001735route_match_ipv6_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001736{
1737 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1738}
1739
paul94f2b392005-06-28 12:44:16 +00001740static void
paul718e3742002-12-13 20:15:29 +00001741route_match_ipv6_address_free (void *rule)
1742{
1743 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1744}
1745
1746/* Route map commands for ip address matching. */
1747struct route_map_rule_cmd route_match_ipv6_address_cmd =
1748{
1749 "ipv6 address",
1750 route_match_ipv6_address,
1751 route_match_ipv6_address_compile,
1752 route_match_ipv6_address_free
1753};
David Lamparter6b0655a2014-06-04 06:53:35 +02001754
paul718e3742002-12-13 20:15:29 +00001755/* `match ipv6 next-hop IP_ADDRESS' */
1756
paul94f2b392005-06-28 12:44:16 +00001757static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001758route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
1759 route_map_object_t type, void *object)
1760{
Paul Jakma7aa9dce2014-09-19 14:42:23 +01001761 struct in6_addr *addr = rule;
paul718e3742002-12-13 20:15:29 +00001762 struct bgp_info *bgp_info;
1763
1764 if (type == RMAP_BGP)
1765 {
paul718e3742002-12-13 20:15:29 +00001766 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +00001767
1768 if (!bgp_info->attr->extra)
1769 return RMAP_NOMATCH;
1770
Paul Jakma7aa9dce2014-09-19 14:42:23 +01001771 if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, addr))
paul718e3742002-12-13 20:15:29 +00001772 return RMAP_MATCH;
1773
Paul Jakmafb982c22007-05-04 20:15:47 +00001774 if (bgp_info->attr->extra->mp_nexthop_len == 32 &&
Paul Jakma7aa9dce2014-09-19 14:42:23 +01001775 IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, addr))
paul718e3742002-12-13 20:15:29 +00001776 return RMAP_MATCH;
1777
1778 return RMAP_NOMATCH;
1779 }
1780
1781 return RMAP_NOMATCH;
1782}
1783
paul94f2b392005-06-28 12:44:16 +00001784static void *
paulfd79ac92004-10-13 05:06:08 +00001785route_match_ipv6_next_hop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001786{
1787 struct in6_addr *address;
1788 int ret;
1789
1790 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1791
1792 ret = inet_pton (AF_INET6, arg, address);
1793 if (!ret)
1794 {
1795 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1796 return NULL;
1797 }
1798
1799 return address;
1800}
1801
paul94f2b392005-06-28 12:44:16 +00001802static void
paul718e3742002-12-13 20:15:29 +00001803route_match_ipv6_next_hop_free (void *rule)
1804{
1805 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1806}
1807
1808struct route_map_rule_cmd route_match_ipv6_next_hop_cmd =
1809{
1810 "ipv6 next-hop",
1811 route_match_ipv6_next_hop,
1812 route_match_ipv6_next_hop_compile,
1813 route_match_ipv6_next_hop_free
1814};
David Lamparter6b0655a2014-06-04 06:53:35 +02001815
paul718e3742002-12-13 20:15:29 +00001816/* `match ipv6 address prefix-list PREFIX_LIST' */
1817
paul94f2b392005-06-28 12:44:16 +00001818static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001819route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix,
1820 route_map_object_t type, void *object)
1821{
1822 struct prefix_list *plist;
1823
1824 if (type == RMAP_BGP)
1825 {
1826 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
1827 if (plist == NULL)
1828 return RMAP_NOMATCH;
1829
1830 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
1831 RMAP_NOMATCH : RMAP_MATCH);
1832 }
1833 return RMAP_NOMATCH;
1834}
1835
paul94f2b392005-06-28 12:44:16 +00001836static void *
paulfd79ac92004-10-13 05:06:08 +00001837route_match_ipv6_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001838{
1839 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1840}
1841
paul94f2b392005-06-28 12:44:16 +00001842static void
paul718e3742002-12-13 20:15:29 +00001843route_match_ipv6_address_prefix_list_free (void *rule)
1844{
1845 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1846}
1847
1848struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
1849{
1850 "ipv6 address prefix-list",
1851 route_match_ipv6_address_prefix_list,
1852 route_match_ipv6_address_prefix_list_compile,
1853 route_match_ipv6_address_prefix_list_free
1854};
David Lamparter6b0655a2014-06-04 06:53:35 +02001855
paul718e3742002-12-13 20:15:29 +00001856/* `set ipv6 nexthop global IP_ADDRESS' */
1857
1858/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001859static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001860route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix,
1861 route_map_object_t type, void *object)
1862{
1863 struct in6_addr *address;
1864 struct bgp_info *bgp_info;
1865
1866 if (type == RMAP_BGP)
1867 {
1868 /* Fetch routemap's rule information. */
1869 address = rule;
1870 bgp_info = object;
1871
1872 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001873 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address;
paul718e3742002-12-13 20:15:29 +00001874
1875 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001876 if (bgp_info->attr->extra->mp_nexthop_len == 0)
1877 bgp_info->attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001878 }
1879
1880 return RMAP_OKAY;
1881}
1882
1883/* Route map `ip next-hop' compile function. Given string is converted
1884 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00001885static void *
paulfd79ac92004-10-13 05:06:08 +00001886route_set_ipv6_nexthop_global_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001887{
1888 int ret;
1889 struct in6_addr *address;
1890
1891 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1892
1893 ret = inet_pton (AF_INET6, arg, address);
1894
1895 if (ret == 0)
1896 {
1897 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1898 return NULL;
1899 }
1900
1901 return address;
1902}
1903
1904/* Free route map's compiled `ip next-hop' value. */
paul94f2b392005-06-28 12:44:16 +00001905static void
paul718e3742002-12-13 20:15:29 +00001906route_set_ipv6_nexthop_global_free (void *rule)
1907{
1908 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1909}
1910
1911/* Route map commands for ip nexthop set. */
1912struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd =
1913{
1914 "ipv6 next-hop global",
1915 route_set_ipv6_nexthop_global,
1916 route_set_ipv6_nexthop_global_compile,
1917 route_set_ipv6_nexthop_global_free
1918};
David Lamparter6b0655a2014-06-04 06:53:35 +02001919
paul718e3742002-12-13 20:15:29 +00001920/* `set ipv6 nexthop local IP_ADDRESS' */
1921
1922/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001923static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001924route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
1925 route_map_object_t type, void *object)
1926{
1927 struct in6_addr *address;
1928 struct bgp_info *bgp_info;
1929
1930 if (type == RMAP_BGP)
1931 {
1932 /* Fetch routemap's rule information. */
1933 address = rule;
1934 bgp_info = object;
1935
1936 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001937 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address;
paul718e3742002-12-13 20:15:29 +00001938
1939 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001940 if (bgp_info->attr->extra->mp_nexthop_len != 32)
1941 bgp_info->attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001942 }
1943
1944 return RMAP_OKAY;
1945}
1946
1947/* Route map `ip nexthop' compile function. Given string is converted
1948 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00001949static void *
paulfd79ac92004-10-13 05:06:08 +00001950route_set_ipv6_nexthop_local_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001951{
1952 int ret;
1953 struct in6_addr *address;
1954
1955 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1956
1957 ret = inet_pton (AF_INET6, arg, address);
1958
1959 if (ret == 0)
1960 {
1961 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1962 return NULL;
1963 }
1964
1965 return address;
1966}
1967
1968/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +00001969static void
paul718e3742002-12-13 20:15:29 +00001970route_set_ipv6_nexthop_local_free (void *rule)
1971{
1972 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1973}
1974
1975/* Route map commands for ip nexthop set. */
1976struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd =
1977{
1978 "ipv6 next-hop local",
1979 route_set_ipv6_nexthop_local,
1980 route_set_ipv6_nexthop_local_compile,
1981 route_set_ipv6_nexthop_local_free
1982};
Dinesh G Duttad5233a2014-09-30 14:19:57 -07001983
1984/* `set ipv6 nexthop peer-address' */
1985
1986/* Set nexthop to object. ojbect must be pointer to struct attr. */
1987static route_map_result_t
1988route_set_ipv6_nexthop_peer (void *rule, struct prefix *prefix,
1989 route_map_object_t type, void *object)
1990{
Dinesh G Duttad5233a2014-09-30 14:19:57 -07001991 struct in6_addr peer_address;
1992 struct bgp_info *bgp_info;
1993 struct peer *peer;
1994 char peer_addr_buf[INET6_ADDRSTRLEN];
1995
1996 if (type == RMAP_BGP)
1997 {
1998 /* Fetch routemap's rule information. */
Dinesh G Duttad5233a2014-09-30 14:19:57 -07001999 bgp_info = object;
2000 peer = bgp_info->peer;
2001
2002 if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) ||
2003 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
2004 && peer->su_remote
2005 && sockunion_family (peer->su_remote) == AF_INET6)
2006 {
2007 inet_pton (AF_INET6, sockunion2str (peer->su_remote,
2008 peer_addr_buf,
2009 INET6_ADDRSTRLEN),
2010 &peer_address);
2011 }
2012 else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
2013 && peer->su_local
2014 && sockunion_family (peer->su_local) == AF_INET6)
2015 {
2016 inet_pton (AF_INET, sockunion2str (peer->su_local,
2017 peer_addr_buf,
2018 INET6_ADDRSTRLEN),
2019 &peer_address);
2020 }
2021
2022 if (IN6_IS_ADDR_LINKLOCAL(&peer_address))
2023 {
2024 /* Set next hop value. */
2025 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = peer_address;
2026
2027 /* Set nexthop length. */
2028 if (bgp_info->attr->extra->mp_nexthop_len != 32)
2029 bgp_info->attr->extra->mp_nexthop_len = 32;
2030 }
2031 else
2032 {
2033 /* Set next hop value. */
2034 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = peer_address;
2035
2036 /* Set nexthop length. */
2037 if (bgp_info->attr->extra->mp_nexthop_len == 0)
2038 bgp_info->attr->extra->mp_nexthop_len = 16;
2039 }
2040 }
2041
2042 return RMAP_OKAY;
2043}
2044
2045/* Route map `ip next-hop' compile function. Given string is converted
2046 to struct in_addr structure. */
2047static void *
2048route_set_ipv6_nexthop_peer_compile (const char *arg)
2049{
Dinesh G Duttad5233a2014-09-30 14:19:57 -07002050 int *rins = NULL;
2051
2052 rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (int));
2053 *rins = 1;
2054
2055 return rins;
2056}
2057
2058/* Free route map's compiled `ip next-hop' value. */
2059static void
2060route_set_ipv6_nexthop_peer_free (void *rule)
2061{
2062 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2063}
2064
2065/* Route map commands for ip nexthop set. */
2066struct route_map_rule_cmd route_set_ipv6_nexthop_peer_cmd =
2067{
2068 "ipv6 next-hop peer-address",
2069 route_set_ipv6_nexthop_peer,
2070 route_set_ipv6_nexthop_peer_compile,
2071 route_set_ipv6_nexthop_peer_free
2072};
2073
paul718e3742002-12-13 20:15:29 +00002074#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02002075
paul718e3742002-12-13 20:15:29 +00002076/* `set vpnv4 nexthop A.B.C.D' */
2077
paul94f2b392005-06-28 12:44:16 +00002078static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002079route_set_vpnv4_nexthop (void *rule, struct prefix *prefix,
2080 route_map_object_t type, void *object)
2081{
2082 struct in_addr *address;
2083 struct bgp_info *bgp_info;
2084
2085 if (type == RMAP_BGP)
2086 {
2087 /* Fetch routemap's rule information. */
2088 address = rule;
2089 bgp_info = object;
2090
2091 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002092 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address;
paul718e3742002-12-13 20:15:29 +00002093 }
2094
2095 return RMAP_OKAY;
2096}
2097
paul94f2b392005-06-28 12:44:16 +00002098static void *
paulfd79ac92004-10-13 05:06:08 +00002099route_set_vpnv4_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002100{
2101 int ret;
2102 struct in_addr *address;
2103
2104 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2105
2106 ret = inet_aton (arg, address);
2107
2108 if (ret == 0)
2109 {
2110 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2111 return NULL;
2112 }
2113
2114 return address;
2115}
2116
paul94f2b392005-06-28 12:44:16 +00002117static void
paul718e3742002-12-13 20:15:29 +00002118route_set_vpnv4_nexthop_free (void *rule)
2119{
2120 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2121}
2122
2123/* Route map commands for ip nexthop set. */
2124struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd =
2125{
2126 "vpnv4 next-hop",
2127 route_set_vpnv4_nexthop,
2128 route_set_vpnv4_nexthop_compile,
2129 route_set_vpnv4_nexthop_free
2130};
David Lamparter6b0655a2014-06-04 06:53:35 +02002131
paul718e3742002-12-13 20:15:29 +00002132/* `set originator-id' */
2133
2134/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00002135static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002136route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
2137{
2138 struct in_addr *address;
2139 struct bgp_info *bgp_info;
2140
2141 if (type == RMAP_BGP)
2142 {
2143 address = rule;
2144 bgp_info = object;
2145
2146 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);
Paul Jakmafb982c22007-05-04 20:15:47 +00002147 (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address;
paul718e3742002-12-13 20:15:29 +00002148 }
2149
2150 return RMAP_OKAY;
2151}
2152
2153/* Compile function for originator-id set. */
paul94f2b392005-06-28 12:44:16 +00002154static void *
paulfd79ac92004-10-13 05:06:08 +00002155route_set_originator_id_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002156{
2157 int ret;
2158 struct in_addr *address;
2159
2160 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2161
2162 ret = inet_aton (arg, address);
2163
2164 if (ret == 0)
2165 {
2166 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2167 return NULL;
2168 }
2169
2170 return address;
2171}
2172
2173/* Compile function for originator_id set. */
paul94f2b392005-06-28 12:44:16 +00002174static void
paul718e3742002-12-13 20:15:29 +00002175route_set_originator_id_free (void *rule)
2176{
2177 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2178}
2179
Timo Teräs2aa640b2014-05-20 08:57:26 +03002180/* Set originator-id rule structure. */
paul718e3742002-12-13 20:15:29 +00002181struct route_map_rule_cmd route_set_originator_id_cmd =
2182{
2183 "originator-id",
2184 route_set_originator_id,
2185 route_set_originator_id_compile,
2186 route_set_originator_id_free,
2187};
David Lamparter6b0655a2014-06-04 06:53:35 +02002188
paul718e3742002-12-13 20:15:29 +00002189/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002190static int
paul718e3742002-12-13 20:15:29 +00002191bgp_route_match_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002192 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002193{
2194 int ret;
2195
2196 ret = route_map_add_match (index, command, arg);
2197 if (ret)
2198 {
2199 switch (ret)
2200 {
2201 case RMAP_RULE_MISSING:
2202 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2203 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002204 case RMAP_COMPILE_ERROR:
2205 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2206 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002207 }
2208 }
2209 return CMD_SUCCESS;
2210}
2211
2212/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002213static int
paul718e3742002-12-13 20:15:29 +00002214bgp_route_match_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002215 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002216{
2217 int ret;
2218
2219 ret = route_map_delete_match (index, command, arg);
2220 if (ret)
2221 {
2222 switch (ret)
2223 {
2224 case RMAP_RULE_MISSING:
2225 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2226 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002227 case RMAP_COMPILE_ERROR:
2228 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2229 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002230 }
2231 }
2232 return CMD_SUCCESS;
2233}
2234
2235/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002236static int
paul718e3742002-12-13 20:15:29 +00002237bgp_route_set_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002238 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002239{
2240 int ret;
2241
2242 ret = route_map_add_set (index, command, arg);
2243 if (ret)
2244 {
2245 switch (ret)
2246 {
2247 case RMAP_RULE_MISSING:
2248 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2249 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002250 case RMAP_COMPILE_ERROR:
2251 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2252 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002253 }
2254 }
2255 return CMD_SUCCESS;
2256}
2257
2258/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002259static int
paul718e3742002-12-13 20:15:29 +00002260bgp_route_set_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002261 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002262{
2263 int ret;
2264
2265 ret = route_map_delete_set (index, command, arg);
2266 if (ret)
2267 {
2268 switch (ret)
2269 {
2270 case RMAP_RULE_MISSING:
2271 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2272 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002273 case RMAP_COMPILE_ERROR:
2274 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2275 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002276 }
2277 }
2278 return CMD_SUCCESS;
2279}
2280
2281/* Hook function for updating route_map assignment. */
paul94f2b392005-06-28 12:44:16 +00002282static void
paulfd79ac92004-10-13 05:06:08 +00002283bgp_route_map_update (const char *unused)
paul718e3742002-12-13 20:15:29 +00002284{
2285 int i;
2286 afi_t afi;
2287 safi_t safi;
2288 int direct;
paul1eb8ef22005-04-07 07:30:20 +00002289 struct listnode *node, *nnode;
2290 struct listnode *mnode, *mnnode;
paul718e3742002-12-13 20:15:29 +00002291 struct bgp *bgp;
2292 struct peer *peer;
2293 struct peer_group *group;
2294 struct bgp_filter *filter;
2295 struct bgp_node *bn;
2296 struct bgp_static *bgp_static;
2297
Lou Berger82dd7072016-01-12 13:41:57 -05002298 if (bm->bgp == NULL) /* may be called during cleanup */
2299 return;
2300
paul718e3742002-12-13 20:15:29 +00002301 /* For neighbor route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002302 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002303 {
paul1eb8ef22005-04-07 07:30:20 +00002304 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002305 {
2306 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2307 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2308 {
2309 filter = &peer->filter[afi][safi];
2310
paulfee0f4c2004-09-13 05:12:46 +00002311 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002312 {
2313 if (filter->map[direct].name)
2314 filter->map[direct].map =
2315 route_map_lookup_by_name (filter->map[direct].name);
2316 else
2317 filter->map[direct].map = NULL;
2318 }
2319
2320 if (filter->usmap.name)
2321 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2322 else
2323 filter->usmap.map = NULL;
2324 }
2325 }
paul1eb8ef22005-04-07 07:30:20 +00002326 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
paul718e3742002-12-13 20:15:29 +00002327 {
2328 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2329 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2330 {
2331 filter = &group->conf->filter[afi][safi];
2332
paulfee0f4c2004-09-13 05:12:46 +00002333 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002334 {
2335 if (filter->map[direct].name)
2336 filter->map[direct].map =
2337 route_map_lookup_by_name (filter->map[direct].name);
2338 else
2339 filter->map[direct].map = NULL;
2340 }
2341
2342 if (filter->usmap.name)
2343 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2344 else
2345 filter->usmap.map = NULL;
2346 }
2347 }
2348 }
2349
2350 /* For default-originate route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002351 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002352 {
paul1eb8ef22005-04-07 07:30:20 +00002353 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002354 {
2355 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2356 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2357 {
2358 if (peer->default_rmap[afi][safi].name)
2359 peer->default_rmap[afi][safi].map =
2360 route_map_lookup_by_name (peer->default_rmap[afi][safi].name);
2361 else
2362 peer->default_rmap[afi][safi].map = NULL;
2363 }
2364 }
2365 }
2366
2367 /* For network route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002368 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002369 {
2370 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2371 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2372 for (bn = bgp_table_top (bgp->route[afi][safi]); bn;
2373 bn = bgp_route_next (bn))
2374 if ((bgp_static = bn->info) != NULL)
2375 {
2376 if (bgp_static->rmap.name)
2377 bgp_static->rmap.map =
2378 route_map_lookup_by_name (bgp_static->rmap.name);
2379 else
2380 bgp_static->rmap.map = NULL;
2381 }
2382 }
2383
2384 /* For redistribute route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002385 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002386 {
2387 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2388 {
Donald Sharpf3cfc462016-01-07 09:33:28 -05002389 if (bgp->rmap[AFI_IP][i].name)
2390 bgp->rmap[AFI_IP][i].map =
2391 route_map_lookup_by_name (bgp->rmap[AFI_IP][i].name);
2392 if (bgp->rmap[AFI_IP6][i].name)
2393 bgp->rmap[AFI_IP6][i].map =
2394 route_map_lookup_by_name (bgp->rmap[AFI_IP][i].name);
paul718e3742002-12-13 20:15:29 +00002395 }
2396 }
2397}
David Lamparter6b0655a2014-06-04 06:53:35 +02002398
paulfee0f4c2004-09-13 05:12:46 +00002399DEFUN (match_peer,
2400 match_peer_cmd,
2401 "match peer (A.B.C.D|X:X::X:X)",
2402 MATCH_STR
2403 "Match peer address\n"
2404 "IPv6 address of peer\n"
2405 "IP address of peer\n")
2406{
2407 return bgp_route_match_add (vty, vty->index, "peer", argv[0]);
2408}
2409
2410DEFUN (match_peer_local,
2411 match_peer_local_cmd,
2412 "match peer local",
2413 MATCH_STR
2414 "Match peer address\n"
2415 "Static or Redistributed routes\n")
2416{
Jorge Boncompte [DTI2]4fe080d2012-04-13 13:46:08 +02002417 return bgp_route_match_add (vty, vty->index, "peer", "local");
paulfee0f4c2004-09-13 05:12:46 +00002418}
2419
2420DEFUN (no_match_peer,
2421 no_match_peer_cmd,
2422 "no match peer",
2423 NO_STR
2424 MATCH_STR
2425 "Match peer address\n")
2426{
2427 if (argc == 0)
2428 return bgp_route_match_delete (vty, vty->index, "peer", NULL);
2429
2430 return bgp_route_match_delete (vty, vty->index, "peer", argv[0]);
2431}
2432
2433ALIAS (no_match_peer,
2434 no_match_peer_val_cmd,
2435 "no match peer (A.B.C.D|X:X::X:X)",
2436 NO_STR
2437 MATCH_STR
2438 "Match peer address\n"
2439 "IPv6 address of peer\n"
2440 "IP address of peer\n")
2441
2442ALIAS (no_match_peer,
2443 no_match_peer_local_cmd,
2444 "no match peer local",
2445 NO_STR
2446 MATCH_STR
2447 "Match peer address\n"
2448 "Static or Redistributed routes\n")
2449
paul718e3742002-12-13 20:15:29 +00002450DEFUN (match_ip_address,
2451 match_ip_address_cmd,
2452 "match ip address (<1-199>|<1300-2699>|WORD)",
2453 MATCH_STR
2454 IP_STR
2455 "Match address of route\n"
2456 "IP access-list number\n"
2457 "IP access-list number (expanded range)\n"
2458 "IP Access-list name\n")
2459{
2460 return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);
2461}
2462
2463DEFUN (no_match_ip_address,
2464 no_match_ip_address_cmd,
2465 "no match ip address",
2466 NO_STR
2467 MATCH_STR
2468 IP_STR
2469 "Match address of route\n")
2470{
2471 if (argc == 0)
2472 return bgp_route_match_delete (vty, vty->index, "ip address", NULL);
2473
2474 return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);
2475}
2476
2477ALIAS (no_match_ip_address,
2478 no_match_ip_address_val_cmd,
2479 "no match ip address (<1-199>|<1300-2699>|WORD)",
2480 NO_STR
2481 MATCH_STR
2482 IP_STR
2483 "Match address of route\n"
2484 "IP access-list number\n"
2485 "IP access-list number (expanded range)\n"
2486 "IP Access-list name\n")
2487
2488DEFUN (match_ip_next_hop,
2489 match_ip_next_hop_cmd,
2490 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
2491 MATCH_STR
2492 IP_STR
2493 "Match next-hop address of route\n"
2494 "IP access-list number\n"
2495 "IP access-list number (expanded range)\n"
2496 "IP Access-list name\n")
2497{
2498 return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
2499}
2500
2501DEFUN (no_match_ip_next_hop,
2502 no_match_ip_next_hop_cmd,
2503 "no match ip next-hop",
2504 NO_STR
2505 MATCH_STR
2506 IP_STR
2507 "Match next-hop address of route\n")
2508{
2509 if (argc == 0)
2510 return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
2511
2512 return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
2513}
2514
2515ALIAS (no_match_ip_next_hop,
2516 no_match_ip_next_hop_val_cmd,
2517 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2518 NO_STR
2519 MATCH_STR
2520 IP_STR
2521 "Match next-hop address of route\n"
2522 "IP access-list number\n"
2523 "IP access-list number (expanded range)\n"
2524 "IP Access-list name\n")
2525
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +04002526/* match probability { */
2527
2528DEFUN (match_probability,
2529 match_probability_cmd,
2530 "match probability <0-100>",
2531 MATCH_STR
2532 "Match portion of routes defined by percentage value\n"
2533 "Percentage of routes\n")
2534{
2535 return bgp_route_match_add (vty, vty->index, "probability", argv[0]);
2536}
2537
2538DEFUN (no_match_probability,
2539 no_match_probability_cmd,
2540 "no match probability",
2541 NO_STR
2542 MATCH_STR
2543 "Match portion of routes defined by percentage value\n")
2544{
2545 return bgp_route_match_delete (vty, vty->index, "probability", argc ? argv[0] : NULL);
2546}
2547
2548ALIAS (no_match_probability,
2549 no_match_probability_val_cmd,
2550 "no match probability <1-99>",
2551 NO_STR
2552 MATCH_STR
2553 "Match portion of routes defined by percentage value\n"
2554 "Percentage of routes\n")
2555
2556/* } */
2557
hassoc1643bb2005-02-02 16:43:17 +00002558DEFUN (match_ip_route_source,
2559 match_ip_route_source_cmd,
2560 "match ip route-source (<1-199>|<1300-2699>|WORD)",
2561 MATCH_STR
2562 IP_STR
2563 "Match advertising source address of route\n"
2564 "IP access-list number\n"
2565 "IP access-list number (expanded range)\n"
2566 "IP standard access-list name\n")
2567{
2568 return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]);
2569}
2570
2571DEFUN (no_match_ip_route_source,
2572 no_match_ip_route_source_cmd,
2573 "no match ip route-source",
2574 NO_STR
2575 MATCH_STR
2576 IP_STR
2577 "Match advertising source address of route\n")
2578{
2579 if (argc == 0)
2580 return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL);
2581
2582 return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]);
2583}
2584
2585ALIAS (no_match_ip_route_source,
2586 no_match_ip_route_source_val_cmd,
2587 "no match ip route-source (<1-199>|<1300-2699>|WORD)",
2588 NO_STR
2589 MATCH_STR
2590 IP_STR
2591 "Match advertising source address of route\n"
2592 "IP access-list number\n"
2593 "IP access-list number (expanded range)\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002594 "IP standard access-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002595
paul718e3742002-12-13 20:15:29 +00002596DEFUN (match_ip_address_prefix_list,
2597 match_ip_address_prefix_list_cmd,
2598 "match ip address prefix-list WORD",
2599 MATCH_STR
2600 IP_STR
2601 "Match address of route\n"
2602 "Match entries of prefix-lists\n"
2603 "IP prefix-list name\n")
2604{
2605 return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
2606}
2607
2608DEFUN (no_match_ip_address_prefix_list,
2609 no_match_ip_address_prefix_list_cmd,
2610 "no match ip address prefix-list",
2611 NO_STR
2612 MATCH_STR
2613 IP_STR
2614 "Match address of route\n"
2615 "Match entries of prefix-lists\n")
2616{
2617 if (argc == 0)
2618 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
2619
2620 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
2621}
2622
2623ALIAS (no_match_ip_address_prefix_list,
2624 no_match_ip_address_prefix_list_val_cmd,
2625 "no match ip address prefix-list WORD",
2626 NO_STR
2627 MATCH_STR
2628 IP_STR
2629 "Match address of route\n"
2630 "Match entries of prefix-lists\n"
2631 "IP prefix-list name\n")
2632
2633DEFUN (match_ip_next_hop_prefix_list,
2634 match_ip_next_hop_prefix_list_cmd,
2635 "match ip next-hop prefix-list WORD",
2636 MATCH_STR
2637 IP_STR
2638 "Match next-hop address of route\n"
2639 "Match entries of prefix-lists\n"
2640 "IP prefix-list name\n")
2641{
2642 return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2643}
2644
2645DEFUN (no_match_ip_next_hop_prefix_list,
2646 no_match_ip_next_hop_prefix_list_cmd,
2647 "no match ip next-hop prefix-list",
2648 NO_STR
2649 MATCH_STR
2650 IP_STR
2651 "Match next-hop address of route\n"
2652 "Match entries of prefix-lists\n")
2653{
2654 if (argc == 0)
2655 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
2656
2657 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2658}
2659
2660ALIAS (no_match_ip_next_hop_prefix_list,
2661 no_match_ip_next_hop_prefix_list_val_cmd,
2662 "no match ip next-hop prefix-list WORD",
2663 NO_STR
2664 MATCH_STR
2665 IP_STR
2666 "Match next-hop address of route\n"
2667 "Match entries of prefix-lists\n"
2668 "IP prefix-list name\n")
2669
hassoc1643bb2005-02-02 16:43:17 +00002670DEFUN (match_ip_route_source_prefix_list,
2671 match_ip_route_source_prefix_list_cmd,
2672 "match ip route-source prefix-list WORD",
2673 MATCH_STR
2674 IP_STR
2675 "Match advertising source address of route\n"
2676 "Match entries of prefix-lists\n"
2677 "IP prefix-list name\n")
2678{
2679 return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]);
2680}
2681
2682DEFUN (no_match_ip_route_source_prefix_list,
2683 no_match_ip_route_source_prefix_list_cmd,
2684 "no match ip route-source prefix-list",
2685 NO_STR
2686 MATCH_STR
2687 IP_STR
2688 "Match advertising source address of route\n"
2689 "Match entries of prefix-lists\n")
2690{
2691 if (argc == 0)
2692 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL);
2693
2694 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]);
2695}
2696
2697ALIAS (no_match_ip_route_source_prefix_list,
2698 no_match_ip_route_source_prefix_list_val_cmd,
2699 "no match ip route-source prefix-list WORD",
2700 NO_STR
2701 MATCH_STR
2702 IP_STR
2703 "Match advertising source address of route\n"
2704 "Match entries of prefix-lists\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002705 "IP prefix-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002706
paul718e3742002-12-13 20:15:29 +00002707DEFUN (match_metric,
2708 match_metric_cmd,
2709 "match metric <0-4294967295>",
2710 MATCH_STR
2711 "Match metric of route\n"
2712 "Metric value\n")
2713{
2714 return bgp_route_match_add (vty, vty->index, "metric", argv[0]);
2715}
2716
2717DEFUN (no_match_metric,
2718 no_match_metric_cmd,
2719 "no match metric",
2720 NO_STR
2721 MATCH_STR
2722 "Match metric of route\n")
2723{
2724 if (argc == 0)
2725 return bgp_route_match_delete (vty, vty->index, "metric", NULL);
2726
2727 return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);
2728}
2729
2730ALIAS (no_match_metric,
2731 no_match_metric_val_cmd,
2732 "no match metric <0-4294967295>",
2733 NO_STR
2734 MATCH_STR
2735 "Match metric of route\n"
2736 "Metric value\n")
2737
2738DEFUN (match_community,
2739 match_community_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002740 "match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002741 MATCH_STR
2742 "Match BGP community list\n"
2743 "Community-list number (standard)\n"
2744 "Community-list number (expanded)\n"
2745 "Community-list name\n")
2746{
2747 return bgp_route_match_add (vty, vty->index, "community", argv[0]);
2748}
2749
2750DEFUN (match_community_exact,
2751 match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002752 "match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002753 MATCH_STR
2754 "Match BGP community list\n"
2755 "Community-list number (standard)\n"
2756 "Community-list number (expanded)\n"
2757 "Community-list name\n"
2758 "Do exact matching of communities\n")
2759{
2760 int ret;
2761 char *argstr;
2762
2763 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
2764 strlen (argv[0]) + strlen ("exact-match") + 2);
2765
2766 sprintf (argstr, "%s exact-match", argv[0]);
2767
2768 ret = bgp_route_match_add (vty, vty->index, "community", argstr);
2769
2770 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
2771
2772 return ret;
2773}
2774
2775DEFUN (no_match_community,
2776 no_match_community_cmd,
2777 "no match community",
2778 NO_STR
2779 MATCH_STR
2780 "Match BGP community list\n")
2781{
2782 return bgp_route_match_delete (vty, vty->index, "community", NULL);
2783}
2784
2785ALIAS (no_match_community,
2786 no_match_community_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002787 "no match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002788 NO_STR
2789 MATCH_STR
2790 "Match BGP community list\n"
2791 "Community-list number (standard)\n"
2792 "Community-list number (expanded)\n"
2793 "Community-list name\n")
2794
2795ALIAS (no_match_community,
2796 no_match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002797 "no match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002798 NO_STR
2799 MATCH_STR
2800 "Match BGP community list\n"
2801 "Community-list number (standard)\n"
2802 "Community-list number (expanded)\n"
2803 "Community-list name\n"
2804 "Do exact matching of communities\n")
2805
paul73ffb252003-04-19 15:49:49 +00002806DEFUN (match_ecommunity,
2807 match_ecommunity_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002808 "match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002809 MATCH_STR
2810 "Match BGP/VPN extended community list\n"
2811 "Extended community-list number (standard)\n"
2812 "Extended community-list number (expanded)\n"
2813 "Extended community-list name\n")
2814{
2815 return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]);
2816}
2817
2818DEFUN (no_match_ecommunity,
2819 no_match_ecommunity_cmd,
2820 "no match extcommunity",
2821 NO_STR
2822 MATCH_STR
2823 "Match BGP/VPN extended community list\n")
2824{
2825 return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL);
2826}
2827
2828ALIAS (no_match_ecommunity,
2829 no_match_ecommunity_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002830 "no match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002831 NO_STR
2832 MATCH_STR
2833 "Match BGP/VPN extended community list\n"
2834 "Extended community-list number (standard)\n"
2835 "Extended community-list number (expanded)\n"
2836 "Extended community-list name\n")
2837
paul718e3742002-12-13 20:15:29 +00002838DEFUN (match_aspath,
2839 match_aspath_cmd,
2840 "match as-path WORD",
2841 MATCH_STR
2842 "Match BGP AS path list\n"
2843 "AS path access-list name\n")
2844{
2845 return bgp_route_match_add (vty, vty->index, "as-path", argv[0]);
2846}
2847
2848DEFUN (no_match_aspath,
2849 no_match_aspath_cmd,
2850 "no match as-path",
2851 NO_STR
2852 MATCH_STR
2853 "Match BGP AS path list\n")
2854{
2855 return bgp_route_match_delete (vty, vty->index, "as-path", NULL);
2856}
2857
2858ALIAS (no_match_aspath,
2859 no_match_aspath_val_cmd,
2860 "no match as-path WORD",
2861 NO_STR
2862 MATCH_STR
2863 "Match BGP AS path list\n"
2864 "AS path access-list name\n")
2865
2866DEFUN (match_origin,
2867 match_origin_cmd,
2868 "match origin (egp|igp|incomplete)",
2869 MATCH_STR
2870 "BGP origin code\n"
2871 "remote EGP\n"
2872 "local IGP\n"
2873 "unknown heritage\n")
2874{
2875 if (strncmp (argv[0], "igp", 2) == 0)
2876 return bgp_route_match_add (vty, vty->index, "origin", "igp");
2877 if (strncmp (argv[0], "egp", 1) == 0)
2878 return bgp_route_match_add (vty, vty->index, "origin", "egp");
2879 if (strncmp (argv[0], "incomplete", 2) == 0)
2880 return bgp_route_match_add (vty, vty->index, "origin", "incomplete");
2881
2882 return CMD_WARNING;
2883}
2884
2885DEFUN (no_match_origin,
2886 no_match_origin_cmd,
2887 "no match origin",
2888 NO_STR
2889 MATCH_STR
2890 "BGP origin code\n")
2891{
2892 return bgp_route_match_delete (vty, vty->index, "origin", NULL);
2893}
2894
2895ALIAS (no_match_origin,
2896 no_match_origin_val_cmd,
2897 "no match origin (egp|igp|incomplete)",
2898 NO_STR
2899 MATCH_STR
2900 "BGP origin code\n"
2901 "remote EGP\n"
2902 "local IGP\n"
2903 "unknown heritage\n")
2904
2905DEFUN (set_ip_nexthop,
2906 set_ip_nexthop_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002907 "set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002908 SET_STR
2909 IP_STR
2910 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002911 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002912{
2913 union sockunion su;
2914 int ret;
2915
2916 ret = str2sockunion (argv[0], &su);
2917 if (ret < 0)
2918 {
2919 vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
2920 return CMD_WARNING;
2921 }
2922
2923 return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
2924}
2925
paulaf5cd0a2003-11-02 07:24:40 +00002926DEFUN (set_ip_nexthop_peer,
2927 set_ip_nexthop_peer_cmd,
2928 "set ip next-hop peer-address",
2929 SET_STR
2930 IP_STR
2931 "Next hop address\n"
2932 "Use peer address (for BGP only)\n")
2933{
2934 return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address");
2935}
2936
paul94f2b392005-06-28 12:44:16 +00002937DEFUN_DEPRECATED (no_set_ip_nexthop_peer,
paulaf5cd0a2003-11-02 07:24:40 +00002938 no_set_ip_nexthop_peer_cmd,
2939 "no set ip next-hop peer-address",
2940 NO_STR
2941 SET_STR
2942 IP_STR
2943 "Next hop address\n"
2944 "Use peer address (for BGP only)\n")
2945{
2946 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2947}
2948
2949
paul718e3742002-12-13 20:15:29 +00002950DEFUN (no_set_ip_nexthop,
2951 no_set_ip_nexthop_cmd,
2952 "no set ip next-hop",
2953 NO_STR
2954 SET_STR
paul718e3742002-12-13 20:15:29 +00002955 "Next hop address\n")
2956{
paulaf5cd0a2003-11-02 07:24:40 +00002957 if (argc == 0)
paul718e3742002-12-13 20:15:29 +00002958 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2959
2960 return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
2961}
2962
2963ALIAS (no_set_ip_nexthop,
2964 no_set_ip_nexthop_val_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002965 "no set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002966 NO_STR
2967 SET_STR
2968 IP_STR
2969 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002970 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002971
2972DEFUN (set_metric,
2973 set_metric_cmd,
paul73ffb252003-04-19 15:49:49 +00002974 "set metric <0-4294967295>",
paul718e3742002-12-13 20:15:29 +00002975 SET_STR
2976 "Metric value for destination routing protocol\n"
paul73ffb252003-04-19 15:49:49 +00002977 "Metric value\n")
paul718e3742002-12-13 20:15:29 +00002978{
2979 return bgp_route_set_add (vty, vty->index, "metric", argv[0]);
2980}
2981
paul73ffb252003-04-19 15:49:49 +00002982ALIAS (set_metric,
2983 set_metric_addsub_cmd,
2984 "set metric <+/-metric>",
2985 SET_STR
2986 "Metric value for destination routing protocol\n"
hasso033e8612005-05-28 04:50:54 +00002987 "Add or subtract metric\n")
paul73ffb252003-04-19 15:49:49 +00002988
Timo Teräsef757702015-04-29 09:43:04 +03002989ALIAS (set_metric,
2990 set_metric_rtt_cmd,
2991 "set metric (rtt|+rtt|-rtt)",
2992 SET_STR
2993 "Metric value for destination routing protocol\n"
2994 "Assign round trip time\n"
2995 "Add round trip time\n"
2996 "Subtract round trip time\n")
2997
paul718e3742002-12-13 20:15:29 +00002998DEFUN (no_set_metric,
2999 no_set_metric_cmd,
3000 "no set metric",
3001 NO_STR
3002 SET_STR
3003 "Metric value for destination routing protocol\n")
3004{
3005 if (argc == 0)
3006 return bgp_route_set_delete (vty, vty->index, "metric", NULL);
3007
3008 return bgp_route_set_delete (vty, vty->index, "metric", argv[0]);
3009}
3010
3011ALIAS (no_set_metric,
3012 no_set_metric_val_cmd,
3013 "no set metric <0-4294967295>",
3014 NO_STR
3015 SET_STR
3016 "Metric value for destination routing protocol\n"
3017 "Metric value\n")
3018
3019DEFUN (set_local_pref,
3020 set_local_pref_cmd,
3021 "set local-preference <0-4294967295>",
3022 SET_STR
3023 "BGP local preference path attribute\n"
3024 "Preference value\n")
3025{
3026 return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]);
3027}
3028
3029DEFUN (no_set_local_pref,
3030 no_set_local_pref_cmd,
3031 "no set local-preference",
3032 NO_STR
3033 SET_STR
3034 "BGP local preference path attribute\n")
3035{
3036 if (argc == 0)
3037 return bgp_route_set_delete (vty, vty->index, "local-preference", NULL);
3038
3039 return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]);
3040}
3041
3042ALIAS (no_set_local_pref,
3043 no_set_local_pref_val_cmd,
3044 "no set local-preference <0-4294967295>",
3045 NO_STR
3046 SET_STR
3047 "BGP local preference path attribute\n"
3048 "Preference value\n")
3049
3050DEFUN (set_weight,
3051 set_weight_cmd,
3052 "set weight <0-4294967295>",
3053 SET_STR
3054 "BGP weight for routing table\n"
3055 "Weight value\n")
3056{
3057 return bgp_route_set_add (vty, vty->index, "weight", argv[0]);
3058}
3059
3060DEFUN (no_set_weight,
3061 no_set_weight_cmd,
3062 "no set weight",
3063 NO_STR
3064 SET_STR
3065 "BGP weight for routing table\n")
3066{
3067 if (argc == 0)
3068 return bgp_route_set_delete (vty, vty->index, "weight", NULL);
3069
3070 return bgp_route_set_delete (vty, vty->index, "weight", argv[0]);
3071}
3072
3073ALIAS (no_set_weight,
3074 no_set_weight_val_cmd,
3075 "no set weight <0-4294967295>",
3076 NO_STR
3077 SET_STR
3078 "BGP weight for routing table\n"
3079 "Weight value\n")
3080
3081DEFUN (set_aspath_prepend,
3082 set_aspath_prepend_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003083 "set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003084 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003085 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003086 "Prepend to the as-path\n"
3087 "AS number\n")
3088{
3089 int ret;
3090 char *str;
3091
3092 str = argv_concat (argv, argc, 0);
3093 ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str);
3094 XFREE (MTYPE_TMP, str);
3095
3096 return ret;
3097}
3098
Timo Teräs85c854a2014-09-30 11:31:53 +03003099ALIAS (set_aspath_prepend,
3100 set_aspath_prepend_lastas_cmd,
3101 "set as-path prepend (last-as) <1-10>",
3102 SET_STR
3103 "Transform BGP AS_PATH attribute\n"
3104 "Prepend to the as-path\n"
3105 "Use the peer's AS-number\n"
David Lamparterb7d50212015-03-03 08:53:18 +01003106 "Number of times to insert")
Timo Teräs85c854a2014-09-30 11:31:53 +03003107
paul718e3742002-12-13 20:15:29 +00003108DEFUN (no_set_aspath_prepend,
3109 no_set_aspath_prepend_cmd,
3110 "no set as-path prepend",
3111 NO_STR
3112 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003113 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003114 "Prepend to the as-path\n")
3115{
Denis Ovsienkoa7f93f32007-12-18 15:13:06 +00003116 int ret;
3117 char *str;
3118
3119 if (argc == 0)
3120 return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL);
3121
3122 str = argv_concat (argv, argc, 0);
3123 ret = bgp_route_set_delete (vty, vty->index, "as-path prepend", str);
3124 XFREE (MTYPE_TMP, str);
3125 return ret;
paul718e3742002-12-13 20:15:29 +00003126}
3127
3128ALIAS (no_set_aspath_prepend,
3129 no_set_aspath_prepend_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003130 "no set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003131 NO_STR
3132 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003133 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003134 "Prepend to the as-path\n"
3135 "AS number\n")
3136
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003137DEFUN (set_aspath_exclude,
3138 set_aspath_exclude_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003139 "set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003140 SET_STR
3141 "Transform BGP AS-path attribute\n"
3142 "Exclude from the as-path\n"
3143 "AS number\n")
3144{
3145 int ret;
3146 char *str;
3147
3148 str = argv_concat (argv, argc, 0);
3149 ret = bgp_route_set_add (vty, vty->index, "as-path exclude", str);
3150 XFREE (MTYPE_TMP, str);
3151 return ret;
3152}
3153
3154DEFUN (no_set_aspath_exclude,
3155 no_set_aspath_exclude_cmd,
3156 "no set as-path exclude",
3157 NO_STR
3158 SET_STR
3159 "Transform BGP AS_PATH attribute\n"
3160 "Exclude from the as-path\n")
3161{
3162 int ret;
3163 char *str;
3164
3165 if (argc == 0)
3166 return bgp_route_set_delete (vty, vty->index, "as-path exclude", NULL);
3167
3168 str = argv_concat (argv, argc, 0);
3169 ret = bgp_route_set_delete (vty, vty->index, "as-path exclude", str);
3170 XFREE (MTYPE_TMP, str);
3171 return ret;
3172}
3173
3174ALIAS (no_set_aspath_exclude,
3175 no_set_aspath_exclude_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003176 "no set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003177 NO_STR
3178 SET_STR
3179 "Transform BGP AS_PATH attribute\n"
3180 "Exclude from the as-path\n"
3181 "AS number\n")
3182
paul718e3742002-12-13 20:15:29 +00003183DEFUN (set_community,
3184 set_community_cmd,
3185 "set community .AA:NN",
3186 SET_STR
3187 "BGP community attribute\n"
3188 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3189{
3190 int i;
3191 int first = 0;
3192 int additive = 0;
3193 struct buffer *b;
3194 struct community *com = NULL;
3195 char *str;
3196 char *argstr;
3197 int ret;
3198
3199 b = buffer_new (1024);
3200
3201 for (i = 0; i < argc; i++)
3202 {
3203 if (strncmp (argv[i], "additive", strlen (argv[i])) == 0)
3204 {
3205 additive = 1;
3206 continue;
3207 }
3208
3209 if (first)
3210 buffer_putc (b, ' ');
3211 else
3212 first = 1;
3213
3214 if (strncmp (argv[i], "internet", strlen (argv[i])) == 0)
3215 {
3216 buffer_putstr (b, "internet");
3217 continue;
3218 }
3219 if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0)
3220 {
3221 buffer_putstr (b, "local-AS");
3222 continue;
3223 }
3224 if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0
3225 && strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0)
3226 {
3227 buffer_putstr (b, "no-advertise");
3228 continue;
3229 }
3230 if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0
3231 && strncmp (argv[i], "no-export", strlen (argv[i])) == 0)
3232 {
3233 buffer_putstr (b, "no-export");
3234 continue;
3235 }
3236 buffer_putstr (b, argv[i]);
3237 }
3238 buffer_putc (b, '\0');
3239
3240 /* Fetch result string then compile it to communities attribute. */
3241 str = buffer_getstr (b);
3242 buffer_free (b);
3243
3244 if (str)
3245 {
3246 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00003247 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00003248 }
3249
3250 /* Can't compile user input into communities attribute. */
3251 if (! com)
3252 {
3253 vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE);
3254 return CMD_WARNING;
3255 }
3256
3257 /* Set communites attribute string. */
3258 str = community_str (com);
3259
3260 if (additive)
3261 {
3262 argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1);
3263 strcpy (argstr, str);
3264 strcpy (argstr + strlen (str), " additive");
3265 ret = bgp_route_set_add (vty, vty->index, "community", argstr);
3266 XFREE (MTYPE_TMP, argstr);
3267 }
3268 else
3269 ret = bgp_route_set_add (vty, vty->index, "community", str);
3270
3271 community_free (com);
3272
3273 return ret;
3274}
3275
3276DEFUN (set_community_none,
3277 set_community_none_cmd,
3278 "set community none",
3279 SET_STR
3280 "BGP community attribute\n"
3281 "No community attribute\n")
3282{
3283 return bgp_route_set_add (vty, vty->index, "community", "none");
3284}
3285
3286DEFUN (no_set_community,
3287 no_set_community_cmd,
3288 "no set community",
3289 NO_STR
3290 SET_STR
3291 "BGP community attribute\n")
3292{
3293 return bgp_route_set_delete (vty, vty->index, "community", NULL);
3294}
3295
3296ALIAS (no_set_community,
3297 no_set_community_val_cmd,
3298 "no set community .AA:NN",
3299 NO_STR
3300 SET_STR
3301 "BGP community attribute\n"
3302 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3303
3304ALIAS (no_set_community,
3305 no_set_community_none_cmd,
3306 "no set community none",
3307 NO_STR
3308 SET_STR
3309 "BGP community attribute\n"
3310 "No community attribute\n")
3311
3312DEFUN (set_community_delete,
3313 set_community_delete_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003314 "set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003315 SET_STR
3316 "set BGP community list (for deletion)\n"
3317 "Community-list number (standard)\n"
3318 "Communitly-list number (expanded)\n"
3319 "Community-list name\n"
3320 "Delete matching communities\n")
3321{
3322 char *str;
3323
3324 str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1);
3325 strcpy (str, argv[0]);
3326 strcpy (str + strlen (argv[0]), " delete");
3327
3328 bgp_route_set_add (vty, vty->index, "comm-list", str);
3329
3330 XFREE (MTYPE_TMP, str);
3331 return CMD_SUCCESS;
3332}
3333
3334DEFUN (no_set_community_delete,
3335 no_set_community_delete_cmd,
3336 "no set comm-list",
3337 NO_STR
3338 SET_STR
3339 "set BGP community list (for deletion)\n")
3340{
3341 return bgp_route_set_delete (vty, vty->index, "comm-list", NULL);
3342}
3343
3344ALIAS (no_set_community_delete,
3345 no_set_community_delete_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003346 "no set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003347 NO_STR
3348 SET_STR
3349 "set BGP community list (for deletion)\n"
3350 "Community-list number (standard)\n"
3351 "Communitly-list number (expanded)\n"
3352 "Community-list name\n"
3353 "Delete matching communities\n")
3354
3355DEFUN (set_ecommunity_rt,
3356 set_ecommunity_rt_cmd,
3357 "set extcommunity rt .ASN:nn_or_IP-address:nn",
3358 SET_STR
3359 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003360 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003361 "VPN extended community\n")
3362{
3363 int ret;
3364 char *str;
3365
3366 str = argv_concat (argv, argc, 0);
3367 ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str);
3368 XFREE (MTYPE_TMP, str);
3369
3370 return ret;
3371}
3372
3373DEFUN (no_set_ecommunity_rt,
3374 no_set_ecommunity_rt_cmd,
3375 "no set extcommunity rt",
3376 NO_STR
3377 SET_STR
3378 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003379 "Route Target extended community\n")
paul718e3742002-12-13 20:15:29 +00003380{
3381 return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL);
3382}
3383
3384ALIAS (no_set_ecommunity_rt,
3385 no_set_ecommunity_rt_val_cmd,
3386 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
3387 NO_STR
3388 SET_STR
3389 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003390 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003391 "VPN extended community\n")
3392
3393DEFUN (set_ecommunity_soo,
3394 set_ecommunity_soo_cmd,
3395 "set extcommunity soo .ASN:nn_or_IP-address:nn",
3396 SET_STR
3397 "BGP extended community attribute\n"
3398 "Site-of-Origin extended community\n"
3399 "VPN extended community\n")
3400{
3401 int ret;
3402 char *str;
3403
3404 str = argv_concat (argv, argc, 0);
3405 ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str);
3406 XFREE (MTYPE_TMP, str);
3407 return ret;
3408}
3409
3410DEFUN (no_set_ecommunity_soo,
3411 no_set_ecommunity_soo_cmd,
3412 "no set extcommunity soo",
3413 NO_STR
3414 SET_STR
3415 "BGP extended community attribute\n"
3416 "Site-of-Origin extended community\n")
3417{
3418 return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL);
3419}
3420
3421ALIAS (no_set_ecommunity_soo,
3422 no_set_ecommunity_soo_val_cmd,
3423 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
3424 NO_STR
3425 SET_STR
3426 "BGP extended community attribute\n"
3427 "Site-of-Origin extended community\n"
3428 "VPN extended community\n")
3429
3430DEFUN (set_origin,
3431 set_origin_cmd,
3432 "set origin (egp|igp|incomplete)",
3433 SET_STR
3434 "BGP origin code\n"
3435 "remote EGP\n"
3436 "local IGP\n"
3437 "unknown heritage\n")
3438{
3439 if (strncmp (argv[0], "igp", 2) == 0)
3440 return bgp_route_set_add (vty, vty->index, "origin", "igp");
3441 if (strncmp (argv[0], "egp", 1) == 0)
3442 return bgp_route_set_add (vty, vty->index, "origin", "egp");
3443 if (strncmp (argv[0], "incomplete", 2) == 0)
3444 return bgp_route_set_add (vty, vty->index, "origin", "incomplete");
3445
3446 return CMD_WARNING;
3447}
3448
3449DEFUN (no_set_origin,
3450 no_set_origin_cmd,
3451 "no set origin",
3452 NO_STR
3453 SET_STR
3454 "BGP origin code\n")
3455{
3456 return bgp_route_set_delete (vty, vty->index, "origin", NULL);
3457}
3458
3459ALIAS (no_set_origin,
3460 no_set_origin_val_cmd,
3461 "no set origin (egp|igp|incomplete)",
3462 NO_STR
3463 SET_STR
3464 "BGP origin code\n"
3465 "remote EGP\n"
3466 "local IGP\n"
3467 "unknown heritage\n")
3468
3469DEFUN (set_atomic_aggregate,
3470 set_atomic_aggregate_cmd,
3471 "set atomic-aggregate",
3472 SET_STR
3473 "BGP atomic aggregate attribute\n" )
3474{
3475 return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL);
3476}
3477
3478DEFUN (no_set_atomic_aggregate,
3479 no_set_atomic_aggregate_cmd,
3480 "no set atomic-aggregate",
3481 NO_STR
3482 SET_STR
3483 "BGP atomic aggregate attribute\n" )
3484{
3485 return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL);
3486}
3487
3488DEFUN (set_aggregator_as,
3489 set_aggregator_as_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003490 "set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003491 SET_STR
3492 "BGP aggregator attribute\n"
3493 "AS number of aggregator\n"
3494 "AS number\n"
3495 "IP address of aggregator\n")
3496{
3497 int ret;
Paul Jakma7aa9dce2014-09-19 14:42:23 +01003498 as_t as __attribute__((unused)); /* dummy for VTY_GET_INTEGER_RANGE */
paul718e3742002-12-13 20:15:29 +00003499 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003500 char *argstr;
3501
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003502 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paulfd79ac92004-10-13 05:06:08 +00003503
paul718e3742002-12-13 20:15:29 +00003504 ret = inet_aton (argv[1], &address);
3505 if (ret == 0)
3506 {
3507 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3508 return CMD_WARNING;
3509 }
3510
3511 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3512 strlen (argv[0]) + strlen (argv[1]) + 2);
3513
3514 sprintf (argstr, "%s %s", argv[0], argv[1]);
3515
3516 ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr);
3517
3518 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3519
3520 return ret;
3521}
3522
3523DEFUN (no_set_aggregator_as,
3524 no_set_aggregator_as_cmd,
3525 "no set aggregator as",
3526 NO_STR
3527 SET_STR
3528 "BGP aggregator attribute\n"
3529 "AS number of aggregator\n")
3530{
3531 int ret;
Paul Jakma7aa9dce2014-09-19 14:42:23 +01003532 as_t as __attribute__((unused)); /* dummy for VTY_GET_INTEGER_RANGE */
paul718e3742002-12-13 20:15:29 +00003533 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003534 char *argstr;
3535
3536 if (argv == 0)
3537 return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL);
3538
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003539 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paul718e3742002-12-13 20:15:29 +00003540
3541 ret = inet_aton (argv[1], &address);
3542 if (ret == 0)
3543 {
3544 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3545 return CMD_WARNING;
3546 }
3547
3548 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3549 strlen (argv[0]) + strlen (argv[1]) + 2);
3550
3551 sprintf (argstr, "%s %s", argv[0], argv[1]);
3552
3553 ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr);
3554
3555 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3556
3557 return ret;
3558}
3559
3560ALIAS (no_set_aggregator_as,
3561 no_set_aggregator_as_val_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003562 "no set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003563 NO_STR
3564 SET_STR
3565 "BGP aggregator attribute\n"
3566 "AS number of aggregator\n"
3567 "AS number\n"
3568 "IP address of aggregator\n")
3569
David Lamparter6b0655a2014-06-04 06:53:35 +02003570
paul718e3742002-12-13 20:15:29 +00003571#ifdef HAVE_IPV6
3572DEFUN (match_ipv6_address,
3573 match_ipv6_address_cmd,
3574 "match ipv6 address WORD",
3575 MATCH_STR
3576 IPV6_STR
3577 "Match IPv6 address of route\n"
3578 "IPv6 access-list name\n")
3579{
3580 return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]);
3581}
3582
3583DEFUN (no_match_ipv6_address,
3584 no_match_ipv6_address_cmd,
3585 "no match ipv6 address WORD",
3586 NO_STR
3587 MATCH_STR
3588 IPV6_STR
3589 "Match IPv6 address of route\n"
3590 "IPv6 access-list name\n")
3591{
3592 return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]);
3593}
3594
3595DEFUN (match_ipv6_next_hop,
3596 match_ipv6_next_hop_cmd,
3597 "match ipv6 next-hop X:X::X:X",
3598 MATCH_STR
3599 IPV6_STR
3600 "Match IPv6 next-hop address of route\n"
3601 "IPv6 address of next hop\n")
3602{
3603 return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]);
3604}
3605
3606DEFUN (no_match_ipv6_next_hop,
3607 no_match_ipv6_next_hop_cmd,
3608 "no match ipv6 next-hop X:X::X:X",
3609 NO_STR
3610 MATCH_STR
3611 IPV6_STR
3612 "Match IPv6 next-hop address of route\n"
3613 "IPv6 address of next hop\n")
3614{
3615 return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
3616}
3617
3618DEFUN (match_ipv6_address_prefix_list,
3619 match_ipv6_address_prefix_list_cmd,
3620 "match ipv6 address prefix-list WORD",
3621 MATCH_STR
3622 IPV6_STR
3623 "Match address of route\n"
3624 "Match entries of prefix-lists\n"
3625 "IP prefix-list name\n")
3626{
3627 return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3628}
3629
3630DEFUN (no_match_ipv6_address_prefix_list,
3631 no_match_ipv6_address_prefix_list_cmd,
3632 "no match ipv6 address prefix-list WORD",
3633 NO_STR
3634 MATCH_STR
3635 IPV6_STR
3636 "Match address of route\n"
3637 "Match entries of prefix-lists\n"
3638 "IP prefix-list name\n")
3639{
3640 return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3641}
3642
Dinesh G Duttad5233a2014-09-30 14:19:57 -07003643DEFUN (set_ipv6_nexthop_peer,
3644 set_ipv6_nexthop_peer_cmd,
3645 "set ipv6 next-hop peer-address",
3646 SET_STR
3647 IPV6_STR
3648 "Next hop address\n"
3649 "Use peer address (for BGP only)\n")
3650{
3651 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop peer-address", NULL);
3652}
3653
3654DEFUN (no_set_ipv6_nexthop_peer,
3655 no_set_ipv6_nexthop_peer_cmd,
3656 "no set ipv6 next-hop peer-address",
3657 NO_STR
3658 SET_STR
3659 IPV6_STR
3660 "IPv6 next-hop address\n"
3661 )
3662{
3663 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
3664}
3665
paul718e3742002-12-13 20:15:29 +00003666DEFUN (set_ipv6_nexthop_global,
3667 set_ipv6_nexthop_global_cmd,
3668 "set ipv6 next-hop global X:X::X:X",
3669 SET_STR
3670 IPV6_STR
3671 "IPv6 next-hop address\n"
3672 "IPv6 global address\n"
3673 "IPv6 address of next hop\n")
3674{
3675 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]);
3676}
3677
3678DEFUN (no_set_ipv6_nexthop_global,
3679 no_set_ipv6_nexthop_global_cmd,
3680 "no set ipv6 next-hop global",
3681 NO_STR
3682 SET_STR
3683 IPV6_STR
3684 "IPv6 next-hop address\n"
3685 "IPv6 global address\n")
3686{
3687 if (argc == 0)
3688 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL);
3689
3690 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]);
3691}
3692
3693ALIAS (no_set_ipv6_nexthop_global,
3694 no_set_ipv6_nexthop_global_val_cmd,
3695 "no set ipv6 next-hop global X:X::X:X",
3696 NO_STR
3697 SET_STR
3698 IPV6_STR
3699 "IPv6 next-hop address\n"
3700 "IPv6 global address\n"
3701 "IPv6 address of next hop\n")
3702
3703DEFUN (set_ipv6_nexthop_local,
3704 set_ipv6_nexthop_local_cmd,
3705 "set ipv6 next-hop local X:X::X:X",
3706 SET_STR
3707 IPV6_STR
3708 "IPv6 next-hop address\n"
3709 "IPv6 local address\n"
3710 "IPv6 address of next hop\n")
3711{
3712 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
3713}
3714
3715DEFUN (no_set_ipv6_nexthop_local,
3716 no_set_ipv6_nexthop_local_cmd,
3717 "no set ipv6 next-hop local",
3718 NO_STR
3719 SET_STR
3720 IPV6_STR
3721 "IPv6 next-hop address\n"
3722 "IPv6 local address\n")
3723{
3724 if (argc == 0)
3725 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
3726
3727 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
3728}
3729
3730ALIAS (no_set_ipv6_nexthop_local,
3731 no_set_ipv6_nexthop_local_val_cmd,
3732 "no set ipv6 next-hop local X:X::X:X",
3733 NO_STR
3734 SET_STR
3735 IPV6_STR
3736 "IPv6 next-hop address\n"
3737 "IPv6 local address\n"
3738 "IPv6 address of next hop\n")
3739#endif /* HAVE_IPV6 */
3740
3741DEFUN (set_vpnv4_nexthop,
3742 set_vpnv4_nexthop_cmd,
3743 "set vpnv4 next-hop A.B.C.D",
3744 SET_STR
3745 "VPNv4 information\n"
3746 "VPNv4 next-hop address\n"
3747 "IP address of next hop\n")
3748{
3749 return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]);
3750}
3751
3752DEFUN (no_set_vpnv4_nexthop,
3753 no_set_vpnv4_nexthop_cmd,
3754 "no set vpnv4 next-hop",
3755 NO_STR
3756 SET_STR
3757 "VPNv4 information\n"
3758 "VPNv4 next-hop address\n")
3759{
3760 if (argc == 0)
3761 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL);
3762
3763 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]);
3764}
3765
3766ALIAS (no_set_vpnv4_nexthop,
3767 no_set_vpnv4_nexthop_val_cmd,
3768 "no set vpnv4 next-hop A.B.C.D",
3769 NO_STR
3770 SET_STR
3771 "VPNv4 information\n"
3772 "VPNv4 next-hop address\n"
3773 "IP address of next hop\n")
3774
3775DEFUN (set_originator_id,
3776 set_originator_id_cmd,
3777 "set originator-id A.B.C.D",
3778 SET_STR
3779 "BGP originator ID attribute\n"
3780 "IP address of originator\n")
3781{
3782 return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]);
3783}
3784
3785DEFUN (no_set_originator_id,
3786 no_set_originator_id_cmd,
3787 "no set originator-id",
3788 NO_STR
3789 SET_STR
3790 "BGP originator ID attribute\n")
3791{
3792 if (argc == 0)
3793 return bgp_route_set_delete (vty, vty->index, "originator-id", NULL);
3794
3795 return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]);
3796}
3797
3798ALIAS (no_set_originator_id,
3799 no_set_originator_id_val_cmd,
3800 "no set originator-id A.B.C.D",
3801 NO_STR
3802 SET_STR
3803 "BGP originator ID attribute\n"
3804 "IP address of originator\n")
3805
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003806DEFUN_DEPRECATED (set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003807 set_pathlimit_ttl_cmd,
3808 "set pathlimit ttl <1-255>",
3809 SET_STR
3810 "BGP AS-Pathlimit attribute\n"
3811 "Set AS-Path Hop-count TTL\n")
3812{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003813 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003814}
3815
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003816DEFUN_DEPRECATED (no_set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003817 no_set_pathlimit_ttl_cmd,
3818 "no set pathlimit ttl",
3819 NO_STR
3820 SET_STR
3821 "BGP AS-Pathlimit attribute\n"
3822 "Set AS-Path Hop-count TTL\n")
3823{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003824 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003825}
3826
3827ALIAS (no_set_pathlimit_ttl,
3828 no_set_pathlimit_ttl_val_cmd,
3829 "no set pathlimit ttl <1-255>",
3830 NO_STR
3831 MATCH_STR
3832 "BGP AS-Pathlimit attribute\n"
3833 "Set AS-Path Hop-count TTL\n")
3834
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003835DEFUN_DEPRECATED (match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003836 match_pathlimit_as_cmd,
3837 "match pathlimit as <1-65535>",
3838 MATCH_STR
3839 "BGP AS-Pathlimit attribute\n"
3840 "Match Pathlimit AS number\n")
3841{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003842 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003843}
3844
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003845DEFUN_DEPRECATED (no_match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003846 no_match_pathlimit_as_cmd,
3847 "no match pathlimit as",
3848 NO_STR
3849 MATCH_STR
3850 "BGP AS-Pathlimit attribute\n"
3851 "Match Pathlimit AS number\n")
3852{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003853 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003854}
3855
3856ALIAS (no_match_pathlimit_as,
3857 no_match_pathlimit_as_val_cmd,
3858 "no match pathlimit as <1-65535>",
3859 NO_STR
3860 MATCH_STR
3861 "BGP AS-Pathlimit attribute\n"
3862 "Match Pathlimit ASN\n")
3863
David Lamparter6b0655a2014-06-04 06:53:35 +02003864
paul718e3742002-12-13 20:15:29 +00003865/* Initialization of route map. */
3866void
paul94f2b392005-06-28 12:44:16 +00003867bgp_route_map_init (void)
paul718e3742002-12-13 20:15:29 +00003868{
3869 route_map_init ();
3870 route_map_init_vty ();
3871 route_map_add_hook (bgp_route_map_update);
3872 route_map_delete_hook (bgp_route_map_update);
3873
paulfee0f4c2004-09-13 05:12:46 +00003874 route_map_install_match (&route_match_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003875 route_map_install_match (&route_match_ip_address_cmd);
3876 route_map_install_match (&route_match_ip_next_hop_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003877 route_map_install_match (&route_match_ip_route_source_cmd);
paul718e3742002-12-13 20:15:29 +00003878 route_map_install_match (&route_match_ip_address_prefix_list_cmd);
3879 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003880 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +00003881 route_map_install_match (&route_match_aspath_cmd);
3882 route_map_install_match (&route_match_community_cmd);
paul73ffb252003-04-19 15:49:49 +00003883 route_map_install_match (&route_match_ecommunity_cmd);
paul718e3742002-12-13 20:15:29 +00003884 route_map_install_match (&route_match_metric_cmd);
3885 route_map_install_match (&route_match_origin_cmd);
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +04003886 route_map_install_match (&route_match_probability_cmd);
paul718e3742002-12-13 20:15:29 +00003887
3888 route_map_install_set (&route_set_ip_nexthop_cmd);
3889 route_map_install_set (&route_set_local_pref_cmd);
3890 route_map_install_set (&route_set_weight_cmd);
3891 route_map_install_set (&route_set_metric_cmd);
3892 route_map_install_set (&route_set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003893 route_map_install_set (&route_set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003894 route_map_install_set (&route_set_origin_cmd);
3895 route_map_install_set (&route_set_atomic_aggregate_cmd);
3896 route_map_install_set (&route_set_aggregator_as_cmd);
3897 route_map_install_set (&route_set_community_cmd);
3898 route_map_install_set (&route_set_community_delete_cmd);
3899 route_map_install_set (&route_set_vpnv4_nexthop_cmd);
3900 route_map_install_set (&route_set_originator_id_cmd);
3901 route_map_install_set (&route_set_ecommunity_rt_cmd);
3902 route_map_install_set (&route_set_ecommunity_soo_cmd);
3903
paulfee0f4c2004-09-13 05:12:46 +00003904 install_element (RMAP_NODE, &match_peer_cmd);
3905 install_element (RMAP_NODE, &match_peer_local_cmd);
3906 install_element (RMAP_NODE, &no_match_peer_cmd);
3907 install_element (RMAP_NODE, &no_match_peer_val_cmd);
3908 install_element (RMAP_NODE, &no_match_peer_local_cmd);
paul718e3742002-12-13 20:15:29 +00003909 install_element (RMAP_NODE, &match_ip_address_cmd);
3910 install_element (RMAP_NODE, &no_match_ip_address_cmd);
3911 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
3912 install_element (RMAP_NODE, &match_ip_next_hop_cmd);
3913 install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
3914 install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003915 install_element (RMAP_NODE, &match_ip_route_source_cmd);
3916 install_element (RMAP_NODE, &no_match_ip_route_source_cmd);
3917 install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd);
paul718e3742002-12-13 20:15:29 +00003918 install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
3919 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
3920 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
3921 install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
3922 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
3923 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003924 install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
3925 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
3926 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd);
paul718e3742002-12-13 20:15:29 +00003927
3928 install_element (RMAP_NODE, &match_aspath_cmd);
3929 install_element (RMAP_NODE, &no_match_aspath_cmd);
3930 install_element (RMAP_NODE, &no_match_aspath_val_cmd);
3931 install_element (RMAP_NODE, &match_metric_cmd);
3932 install_element (RMAP_NODE, &no_match_metric_cmd);
3933 install_element (RMAP_NODE, &no_match_metric_val_cmd);
3934 install_element (RMAP_NODE, &match_community_cmd);
3935 install_element (RMAP_NODE, &match_community_exact_cmd);
3936 install_element (RMAP_NODE, &no_match_community_cmd);
3937 install_element (RMAP_NODE, &no_match_community_val_cmd);
3938 install_element (RMAP_NODE, &no_match_community_exact_cmd);
paul73ffb252003-04-19 15:49:49 +00003939 install_element (RMAP_NODE, &match_ecommunity_cmd);
3940 install_element (RMAP_NODE, &no_match_ecommunity_cmd);
3941 install_element (RMAP_NODE, &no_match_ecommunity_val_cmd);
paul718e3742002-12-13 20:15:29 +00003942 install_element (RMAP_NODE, &match_origin_cmd);
3943 install_element (RMAP_NODE, &no_match_origin_cmd);
3944 install_element (RMAP_NODE, &no_match_origin_val_cmd);
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +04003945 install_element (RMAP_NODE, &match_probability_cmd);
3946 install_element (RMAP_NODE, &no_match_probability_cmd);
3947 install_element (RMAP_NODE, &no_match_probability_val_cmd);
paul718e3742002-12-13 20:15:29 +00003948
3949 install_element (RMAP_NODE, &set_ip_nexthop_cmd);
paulaf5cd0a2003-11-02 07:24:40 +00003950 install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003951 install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
3952 install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
3953 install_element (RMAP_NODE, &set_local_pref_cmd);
3954 install_element (RMAP_NODE, &no_set_local_pref_cmd);
3955 install_element (RMAP_NODE, &no_set_local_pref_val_cmd);
3956 install_element (RMAP_NODE, &set_weight_cmd);
3957 install_element (RMAP_NODE, &no_set_weight_cmd);
3958 install_element (RMAP_NODE, &no_set_weight_val_cmd);
3959 install_element (RMAP_NODE, &set_metric_cmd);
paul73ffb252003-04-19 15:49:49 +00003960 install_element (RMAP_NODE, &set_metric_addsub_cmd);
Timo Teräsef757702015-04-29 09:43:04 +03003961 install_element (RMAP_NODE, &set_metric_rtt_cmd);
paul718e3742002-12-13 20:15:29 +00003962 install_element (RMAP_NODE, &no_set_metric_cmd);
3963 install_element (RMAP_NODE, &no_set_metric_val_cmd);
3964 install_element (RMAP_NODE, &set_aspath_prepend_cmd);
Timo Teräs85c854a2014-09-30 11:31:53 +03003965 install_element (RMAP_NODE, &set_aspath_prepend_lastas_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003966 install_element (RMAP_NODE, &set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003967 install_element (RMAP_NODE, &no_set_aspath_prepend_cmd);
3968 install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003969 install_element (RMAP_NODE, &no_set_aspath_exclude_cmd);
3970 install_element (RMAP_NODE, &no_set_aspath_exclude_val_cmd);
paul718e3742002-12-13 20:15:29 +00003971 install_element (RMAP_NODE, &set_origin_cmd);
3972 install_element (RMAP_NODE, &no_set_origin_cmd);
3973 install_element (RMAP_NODE, &no_set_origin_val_cmd);
3974 install_element (RMAP_NODE, &set_atomic_aggregate_cmd);
3975 install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd);
3976 install_element (RMAP_NODE, &set_aggregator_as_cmd);
3977 install_element (RMAP_NODE, &no_set_aggregator_as_cmd);
3978 install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd);
3979 install_element (RMAP_NODE, &set_community_cmd);
3980 install_element (RMAP_NODE, &set_community_none_cmd);
3981 install_element (RMAP_NODE, &no_set_community_cmd);
3982 install_element (RMAP_NODE, &no_set_community_val_cmd);
3983 install_element (RMAP_NODE, &no_set_community_none_cmd);
3984 install_element (RMAP_NODE, &set_community_delete_cmd);
3985 install_element (RMAP_NODE, &no_set_community_delete_cmd);
3986 install_element (RMAP_NODE, &no_set_community_delete_val_cmd);
3987 install_element (RMAP_NODE, &set_ecommunity_rt_cmd);
3988 install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd);
3989 install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd);
3990 install_element (RMAP_NODE, &set_ecommunity_soo_cmd);
3991 install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd);
3992 install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd);
3993 install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd);
3994 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd);
3995 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd);
3996 install_element (RMAP_NODE, &set_originator_id_cmd);
3997 install_element (RMAP_NODE, &no_set_originator_id_cmd);
3998 install_element (RMAP_NODE, &no_set_originator_id_val_cmd);
3999
4000#ifdef HAVE_IPV6
4001 route_map_install_match (&route_match_ipv6_address_cmd);
4002 route_map_install_match (&route_match_ipv6_next_hop_cmd);
4003 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd);
4004 route_map_install_set (&route_set_ipv6_nexthop_global_cmd);
4005 route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
Dinesh G Duttad5233a2014-09-30 14:19:57 -07004006 route_map_install_set (&route_set_ipv6_nexthop_peer_cmd);
4007
paul718e3742002-12-13 20:15:29 +00004008 install_element (RMAP_NODE, &match_ipv6_address_cmd);
4009 install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
4010 install_element (RMAP_NODE, &match_ipv6_next_hop_cmd);
4011 install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd);
4012 install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
4013 install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
4014 install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd);
4015 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
4016 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd);
4017 install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
4018 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
4019 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
Dinesh G Duttad5233a2014-09-30 14:19:57 -07004020 install_element (RMAP_NODE, &set_ipv6_nexthop_peer_cmd);
4021 install_element (RMAP_NODE, &no_set_ipv6_nexthop_peer_cmd);
paul718e3742002-12-13 20:15:29 +00004022#endif /* HAVE_IPV6 */
Paul Jakma41367172007-08-06 15:24:51 +00004023
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004024 /* AS-Pathlimit: functionality removed, commands kept for
4025 * compatibility.
4026 */
Paul Jakma41367172007-08-06 15:24:51 +00004027 install_element (RMAP_NODE, &set_pathlimit_ttl_cmd);
4028 install_element (RMAP_NODE, &no_set_pathlimit_ttl_cmd);
4029 install_element (RMAP_NODE, &no_set_pathlimit_ttl_val_cmd);
4030 install_element (RMAP_NODE, &match_pathlimit_as_cmd);
4031 install_element (RMAP_NODE, &no_match_pathlimit_as_cmd);
4032 install_element (RMAP_NODE, &no_match_pathlimit_as_val_cmd);
paul718e3742002-12-13 20:15:29 +00004033}