blob: 42c3e053e59fee3402791d9d65831b21bdb0f49d [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
96o Local extention
97
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*/
103
paulfee0f4c2004-09-13 05:12:46 +0000104 /* 'match peer (A.B.C.D|X:X::X:X)' */
105
106/* Compares the peer specified in the 'match peer' clause with the peer
107 received in bgp_info->peer. If it is the same, or if the peer structure
108 received is a peer_group containing it, returns RMAP_MATCH. */
paul94f2b392005-06-28 12:44:16 +0000109static route_map_result_t
paulfee0f4c2004-09-13 05:12:46 +0000110route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type,
111 void *object)
112{
113 union sockunion *su;
114 union sockunion *su2;
115 struct peer_group *group;
116 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +0000117 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +0000118
119 if (type == RMAP_BGP)
120 {
121 su = rule;
122 peer = ((struct bgp_info *) object)->peer;
123
124 if ( ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT) &&
125 ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_EXPORT) )
126 return RMAP_NOMATCH;
127
128 /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
129 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
130 su2 = sockunion_str2su ("0.0.0.0");
131 if ( sockunion_same (su, su2) )
132 {
paul22db9de2005-05-19 01:50:11 +0000133 int ret;
paulfee0f4c2004-09-13 05:12:46 +0000134 if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) ||
135 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE) ||
136 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_DEFAULT))
paul22db9de2005-05-19 01:50:11 +0000137 ret = RMAP_MATCH;
paulfee0f4c2004-09-13 05:12:46 +0000138 else
paul22db9de2005-05-19 01:50:11 +0000139 ret = RMAP_NOMATCH;
140
141 sockunion_free (su2);
142 return ret;
paulfee0f4c2004-09-13 05:12:46 +0000143 }
paul22db9de2005-05-19 01:50:11 +0000144 sockunion_free (su2);
145
paulfee0f4c2004-09-13 05:12:46 +0000146 if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
147 {
148 if (sockunion_same (su, &peer->su))
149 return RMAP_MATCH;
150
151 return RMAP_NOMATCH;
152 }
153 else
154 {
155 group = peer->group;
paul1eb8ef22005-04-07 07:30:20 +0000156 for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
paulfee0f4c2004-09-13 05:12:46 +0000157 {
158 if (sockunion_same (su, &peer->su))
159 return RMAP_MATCH;
paulfee0f4c2004-09-13 05:12:46 +0000160 }
Paul Jakma30a22312008-08-15 14:05:22 +0100161 return RMAP_NOMATCH;
paulfee0f4c2004-09-13 05:12:46 +0000162 }
163 }
164 return RMAP_NOMATCH;
165}
166
paul94f2b392005-06-28 12:44:16 +0000167static void *
paulfd79ac92004-10-13 05:06:08 +0000168route_match_peer_compile (const char *arg)
paulfee0f4c2004-09-13 05:12:46 +0000169{
170 union sockunion *su;
171 int ret;
172
173 su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion));
174
175 ret = str2sockunion ( (arg)? arg : "0.0.0.0", su);
176 if (ret < 0) {
177 XFREE (MTYPE_ROUTE_MAP_COMPILED, su);
178 return NULL;
179 }
180
181 return su;
182}
183
184/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000185static void
paulfee0f4c2004-09-13 05:12:46 +0000186route_match_peer_free (void *rule)
187{
188 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
189}
190
191/* Route map commands for ip address matching. */
192struct route_map_rule_cmd route_match_peer_cmd =
193{
194 "peer",
195 route_match_peer,
196 route_match_peer_compile,
197 route_match_peer_free
198};
199
paul718e3742002-12-13 20:15:29 +0000200/* `match ip address IP_ACCESS_LIST' */
201
202/* Match function should return 1 if match is success else return
203 zero. */
paul94f2b392005-06-28 12:44:16 +0000204static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000205route_match_ip_address (void *rule, struct prefix *prefix,
206 route_map_object_t type, void *object)
207{
208 struct access_list *alist;
209 /* struct prefix_ipv4 match; */
210
211 if (type == RMAP_BGP)
212 {
213 alist = access_list_lookup (AFI_IP, (char *) rule);
214 if (alist == NULL)
215 return RMAP_NOMATCH;
216
217 return (access_list_apply (alist, prefix) == FILTER_DENY ?
218 RMAP_NOMATCH : RMAP_MATCH);
219 }
220 return RMAP_NOMATCH;
221}
222
223/* Route map `ip address' match statement. `arg' should be
224 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000225static void *
paulfd79ac92004-10-13 05:06:08 +0000226route_match_ip_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000227{
228 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
229}
230
231/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000232static void
paul718e3742002-12-13 20:15:29 +0000233route_match_ip_address_free (void *rule)
234{
235 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
236}
237
238/* Route map commands for ip address matching. */
239struct route_map_rule_cmd route_match_ip_address_cmd =
240{
241 "ip address",
242 route_match_ip_address,
243 route_match_ip_address_compile,
244 route_match_ip_address_free
245};
246
247/* `match ip next-hop IP_ADDRESS' */
248
249/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000250static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000251route_match_ip_next_hop (void *rule, struct prefix *prefix,
252 route_map_object_t type, void *object)
253{
254 struct access_list *alist;
255 struct bgp_info *bgp_info;
256 struct prefix_ipv4 p;
257
258 if (type == RMAP_BGP)
259 {
260 bgp_info = object;
261 p.family = AF_INET;
262 p.prefix = bgp_info->attr->nexthop;
263 p.prefixlen = IPV4_MAX_BITLEN;
264
265 alist = access_list_lookup (AFI_IP, (char *) rule);
266 if (alist == NULL)
267 return RMAP_NOMATCH;
268
269 return (access_list_apply (alist, &p) == FILTER_DENY ?
270 RMAP_NOMATCH : RMAP_MATCH);
271 }
272 return RMAP_NOMATCH;
273}
274
275/* Route map `ip next-hop' match statement. `arg' is
276 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000277static void *
paulfd79ac92004-10-13 05:06:08 +0000278route_match_ip_next_hop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000279{
280 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
281}
282
283/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000284static void
paul718e3742002-12-13 20:15:29 +0000285route_match_ip_next_hop_free (void *rule)
286{
287 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
288}
289
290/* Route map commands for ip next-hop matching. */
291struct route_map_rule_cmd route_match_ip_next_hop_cmd =
292{
293 "ip next-hop",
294 route_match_ip_next_hop,
295 route_match_ip_next_hop_compile,
296 route_match_ip_next_hop_free
297};
298
hassoc1643bb2005-02-02 16:43:17 +0000299/* `match ip route-source ACCESS-LIST' */
300
301/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000302static route_map_result_t
hassoc1643bb2005-02-02 16:43:17 +0000303route_match_ip_route_source (void *rule, struct prefix *prefix,
304 route_map_object_t type, void *object)
305{
306 struct access_list *alist;
307 struct bgp_info *bgp_info;
308 struct peer *peer;
309 struct prefix_ipv4 p;
310
311 if (type == RMAP_BGP)
312 {
313 bgp_info = object;
314 peer = bgp_info->peer;
315
316 if (! peer || sockunion_family (&peer->su) != AF_INET)
317 return RMAP_NOMATCH;
318
319 p.family = AF_INET;
320 p.prefix = peer->su.sin.sin_addr;
321 p.prefixlen = IPV4_MAX_BITLEN;
322
323 alist = access_list_lookup (AFI_IP, (char *) rule);
324 if (alist == NULL)
325 return RMAP_NOMATCH;
326
327 return (access_list_apply (alist, &p) == FILTER_DENY ?
328 RMAP_NOMATCH : RMAP_MATCH);
329 }
330 return RMAP_NOMATCH;
331}
332
333/* Route map `ip route-source' match statement. `arg' is
334 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000335static void *
hassoc1643bb2005-02-02 16:43:17 +0000336route_match_ip_route_source_compile (const char *arg)
337{
338 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
339}
340
341/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000342static void
hassoc1643bb2005-02-02 16:43:17 +0000343route_match_ip_route_source_free (void *rule)
344{
345 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
346}
347
348/* Route map commands for ip route-source matching. */
349struct route_map_rule_cmd route_match_ip_route_source_cmd =
350{
351 "ip route-source",
352 route_match_ip_route_source,
353 route_match_ip_route_source_compile,
354 route_match_ip_route_source_free
355};
356
paul718e3742002-12-13 20:15:29 +0000357/* `match ip address prefix-list PREFIX_LIST' */
358
paul94f2b392005-06-28 12:44:16 +0000359static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000360route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
361 route_map_object_t type, void *object)
362{
363 struct prefix_list *plist;
364
365 if (type == RMAP_BGP)
366 {
367 plist = prefix_list_lookup (AFI_IP, (char *) rule);
368 if (plist == NULL)
369 return RMAP_NOMATCH;
370
371 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
372 RMAP_NOMATCH : RMAP_MATCH);
373 }
374 return RMAP_NOMATCH;
375}
376
paul94f2b392005-06-28 12:44:16 +0000377static void *
paulfd79ac92004-10-13 05:06:08 +0000378route_match_ip_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000379{
380 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
381}
382
paul94f2b392005-06-28 12:44:16 +0000383static void
paul718e3742002-12-13 20:15:29 +0000384route_match_ip_address_prefix_list_free (void *rule)
385{
386 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
387}
388
389struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
390{
391 "ip address prefix-list",
392 route_match_ip_address_prefix_list,
393 route_match_ip_address_prefix_list_compile,
394 route_match_ip_address_prefix_list_free
395};
396
397/* `match ip next-hop prefix-list PREFIX_LIST' */
398
paul94f2b392005-06-28 12:44:16 +0000399static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000400route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
401 route_map_object_t type, void *object)
402{
403 struct prefix_list *plist;
404 struct bgp_info *bgp_info;
405 struct prefix_ipv4 p;
406
407 if (type == RMAP_BGP)
408 {
409 bgp_info = object;
410 p.family = AF_INET;
411 p.prefix = bgp_info->attr->nexthop;
412 p.prefixlen = IPV4_MAX_BITLEN;
413
414 plist = prefix_list_lookup (AFI_IP, (char *) rule);
415 if (plist == NULL)
416 return RMAP_NOMATCH;
417
418 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
419 RMAP_NOMATCH : RMAP_MATCH);
420 }
421 return RMAP_NOMATCH;
422}
423
paul94f2b392005-06-28 12:44:16 +0000424static void *
paulfd79ac92004-10-13 05:06:08 +0000425route_match_ip_next_hop_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000426{
427 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
428}
429
paul94f2b392005-06-28 12:44:16 +0000430static void
paul718e3742002-12-13 20:15:29 +0000431route_match_ip_next_hop_prefix_list_free (void *rule)
432{
433 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
434}
435
436struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
437{
438 "ip next-hop prefix-list",
439 route_match_ip_next_hop_prefix_list,
440 route_match_ip_next_hop_prefix_list_compile,
441 route_match_ip_next_hop_prefix_list_free
442};
443
hassoc1643bb2005-02-02 16:43:17 +0000444/* `match ip route-source prefix-list PREFIX_LIST' */
445
paul94f2b392005-06-28 12:44:16 +0000446static route_map_result_t
hassoc1643bb2005-02-02 16:43:17 +0000447route_match_ip_route_source_prefix_list (void *rule, struct prefix *prefix,
448 route_map_object_t type, void *object)
449{
450 struct prefix_list *plist;
451 struct bgp_info *bgp_info;
452 struct peer *peer;
453 struct prefix_ipv4 p;
454
455 if (type == RMAP_BGP)
456 {
457 bgp_info = object;
458 peer = bgp_info->peer;
459
460 if (! peer || sockunion_family (&peer->su) != AF_INET)
461 return RMAP_NOMATCH;
462
463 p.family = AF_INET;
464 p.prefix = peer->su.sin.sin_addr;
465 p.prefixlen = IPV4_MAX_BITLEN;
466
467 plist = prefix_list_lookup (AFI_IP, (char *) rule);
468 if (plist == NULL)
469 return RMAP_NOMATCH;
470
471 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
472 RMAP_NOMATCH : RMAP_MATCH);
473 }
474 return RMAP_NOMATCH;
475}
476
paul94f2b392005-06-28 12:44:16 +0000477static void *
hassoc1643bb2005-02-02 16:43:17 +0000478route_match_ip_route_source_prefix_list_compile (const char *arg)
479{
480 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
481}
482
paul94f2b392005-06-28 12:44:16 +0000483static void
hassoc1643bb2005-02-02 16:43:17 +0000484route_match_ip_route_source_prefix_list_free (void *rule)
485{
486 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
487}
488
489struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd =
490{
491 "ip route-source prefix-list",
492 route_match_ip_route_source_prefix_list,
493 route_match_ip_route_source_prefix_list_compile,
494 route_match_ip_route_source_prefix_list_free
495};
496
paul718e3742002-12-13 20:15:29 +0000497/* `match metric METRIC' */
498
499/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000500static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000501route_match_metric (void *rule, struct prefix *prefix,
502 route_map_object_t type, void *object)
503{
504 u_int32_t *med;
505 struct bgp_info *bgp_info;
506
507 if (type == RMAP_BGP)
508 {
509 med = rule;
510 bgp_info = object;
511
512 if (bgp_info->attr->med == *med)
513 return RMAP_MATCH;
514 else
515 return RMAP_NOMATCH;
516 }
517 return RMAP_NOMATCH;
518}
519
520/* Route map `match metric' match statement. `arg' is MED value */
paul94f2b392005-06-28 12:44:16 +0000521static void *
paulfd79ac92004-10-13 05:06:08 +0000522route_match_metric_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000523{
524 u_int32_t *med;
525 char *endptr = NULL;
paul3b424972003-10-13 09:47:32 +0000526 unsigned long tmpval;
paul718e3742002-12-13 20:15:29 +0000527
Ulrich Weber830526a2011-12-21 02:24:11 +0400528 /* Metric value shoud be integer. */
529 if (! all_digit (arg))
530 return NULL;
531
532 errno = 0;
paul3b424972003-10-13 09:47:32 +0000533 tmpval = strtoul (arg, &endptr, 10);
Ulrich Weber830526a2011-12-21 02:24:11 +0400534 if (*endptr != '\0' || errno || tmpval > UINT32_MAX)
paul3b424972003-10-13 09:47:32 +0000535 return NULL;
paulfd79ac92004-10-13 05:06:08 +0000536
paul718e3742002-12-13 20:15:29 +0000537 med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
paulfd79ac92004-10-13 05:06:08 +0000538
539 if (!med)
540 return med;
541
paul3b424972003-10-13 09:47:32 +0000542 *med = tmpval;
paul718e3742002-12-13 20:15:29 +0000543 return med;
544}
545
546/* Free route map's compiled `match metric' value. */
paul94f2b392005-06-28 12:44:16 +0000547static void
paul718e3742002-12-13 20:15:29 +0000548route_match_metric_free (void *rule)
549{
550 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
551}
552
553/* Route map commands for metric matching. */
554struct route_map_rule_cmd route_match_metric_cmd =
555{
556 "metric",
557 route_match_metric,
558 route_match_metric_compile,
559 route_match_metric_free
560};
561
562/* `match as-path ASPATH' */
563
564/* Match function for as-path match. I assume given object is */
paul94f2b392005-06-28 12:44:16 +0000565static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000566route_match_aspath (void *rule, struct prefix *prefix,
567 route_map_object_t type, void *object)
568{
569
570 struct as_list *as_list;
571 struct bgp_info *bgp_info;
572
573 if (type == RMAP_BGP)
574 {
575 as_list = as_list_lookup ((char *) rule);
576 if (as_list == NULL)
577 return RMAP_NOMATCH;
578
579 bgp_info = object;
580
581 /* Perform match. */
582 return ((as_list_apply (as_list, bgp_info->attr->aspath) == AS_FILTER_DENY) ? RMAP_NOMATCH : RMAP_MATCH);
583 }
584 return RMAP_NOMATCH;
585}
586
587/* Compile function for as-path match. */
paul94f2b392005-06-28 12:44:16 +0000588static void *
paulfd79ac92004-10-13 05:06:08 +0000589route_match_aspath_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000590{
591 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
592}
593
594/* Compile function for as-path match. */
paul94f2b392005-06-28 12:44:16 +0000595static void
paul718e3742002-12-13 20:15:29 +0000596route_match_aspath_free (void *rule)
597{
598 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
599}
600
601/* Route map commands for aspath matching. */
602struct route_map_rule_cmd route_match_aspath_cmd =
603{
604 "as-path",
605 route_match_aspath,
606 route_match_aspath_compile,
607 route_match_aspath_free
608};
paul718e3742002-12-13 20:15:29 +0000609
610/* `match community COMMUNIY' */
611struct rmap_community
612{
613 char *name;
614 int exact;
615};
616
617/* Match function for community match. */
paul94f2b392005-06-28 12:44:16 +0000618static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000619route_match_community (void *rule, struct prefix *prefix,
620 route_map_object_t type, void *object)
621{
622 struct community_list *list;
623 struct bgp_info *bgp_info;
624 struct rmap_community *rcom;
625
626 if (type == RMAP_BGP)
627 {
628 bgp_info = object;
629 rcom = rule;
630
hassofee6e4e2005-02-02 16:29:31 +0000631 list = community_list_lookup (bgp_clist, rcom->name, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +0000632 if (! list)
633 return RMAP_NOMATCH;
634
635 if (rcom->exact)
636 {
637 if (community_list_exact_match (bgp_info->attr->community, list))
638 return RMAP_MATCH;
639 }
640 else
641 {
642 if (community_list_match (bgp_info->attr->community, list))
643 return RMAP_MATCH;
644 }
645 }
646 return RMAP_NOMATCH;
647}
648
649/* Compile function for community match. */
paul94f2b392005-06-28 12:44:16 +0000650static void *
paulfd79ac92004-10-13 05:06:08 +0000651route_match_community_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000652{
653 struct rmap_community *rcom;
654 int len;
655 char *p;
656
657 rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community));
658
659 p = strchr (arg, ' ');
660 if (p)
661 {
662 len = p - arg;
663 rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
664 memcpy (rcom->name, arg, len);
665 rcom->exact = 1;
666 }
667 else
668 {
669 rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
670 rcom->exact = 0;
671 }
672 return rcom;
673}
674
675/* Compile function for community match. */
paul94f2b392005-06-28 12:44:16 +0000676static void
paul718e3742002-12-13 20:15:29 +0000677route_match_community_free (void *rule)
678{
679 struct rmap_community *rcom = rule;
680
681 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name);
682 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom);
683}
684
685/* Route map commands for community matching. */
686struct route_map_rule_cmd route_match_community_cmd =
687{
688 "community",
689 route_match_community,
690 route_match_community_compile,
691 route_match_community_free
692};
693
paul73ffb252003-04-19 15:49:49 +0000694/* Match function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000695static route_map_result_t
paul73ffb252003-04-19 15:49:49 +0000696route_match_ecommunity (void *rule, struct prefix *prefix,
697 route_map_object_t type, void *object)
698{
699 struct community_list *list;
700 struct bgp_info *bgp_info;
701
702 if (type == RMAP_BGP)
703 {
704 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +0000705
706 if (!bgp_info->attr->extra)
707 return RMAP_NOMATCH;
708
paul73ffb252003-04-19 15:49:49 +0000709 list = community_list_lookup (bgp_clist, (char *) rule,
hassofee6e4e2005-02-02 16:29:31 +0000710 EXTCOMMUNITY_LIST_MASTER);
paul73ffb252003-04-19 15:49:49 +0000711 if (! list)
712 return RMAP_NOMATCH;
713
Paul Jakmafb982c22007-05-04 20:15:47 +0000714 if (ecommunity_list_match (bgp_info->attr->extra->ecommunity, list))
paul73ffb252003-04-19 15:49:49 +0000715 return RMAP_MATCH;
716 }
717 return RMAP_NOMATCH;
718}
719
720/* Compile function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000721static void *
paulfd79ac92004-10-13 05:06:08 +0000722route_match_ecommunity_compile (const char *arg)
paul73ffb252003-04-19 15:49:49 +0000723{
724 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
725}
726
727/* Compile function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000728static void
paul73ffb252003-04-19 15:49:49 +0000729route_match_ecommunity_free (void *rule)
730{
731 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
732}
733
734/* Route map commands for community matching. */
735struct route_map_rule_cmd route_match_ecommunity_cmd =
736{
737 "extcommunity",
738 route_match_ecommunity,
739 route_match_ecommunity_compile,
740 route_match_ecommunity_free
741};
742
paul718e3742002-12-13 20:15:29 +0000743/* `match nlri` and `set nlri` are replaced by `address-family ipv4`
744 and `address-family vpnv4'. */
745
746/* `match origin' */
paul94f2b392005-06-28 12:44:16 +0000747static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000748route_match_origin (void *rule, struct prefix *prefix,
749 route_map_object_t type, void *object)
750{
751 u_char *origin;
752 struct bgp_info *bgp_info;
753
754 if (type == RMAP_BGP)
755 {
756 origin = rule;
757 bgp_info = object;
758
759 if (bgp_info->attr->origin == *origin)
760 return RMAP_MATCH;
761 }
762
763 return RMAP_NOMATCH;
764}
765
paul94f2b392005-06-28 12:44:16 +0000766static void *
paulfd79ac92004-10-13 05:06:08 +0000767route_match_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000768{
769 u_char *origin;
770
771 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
772
773 if (strcmp (arg, "igp") == 0)
774 *origin = 0;
775 else if (strcmp (arg, "egp") == 0)
776 *origin = 1;
777 else
778 *origin = 2;
779
780 return origin;
781}
782
783/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000784static void
paul718e3742002-12-13 20:15:29 +0000785route_match_origin_free (void *rule)
786{
787 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
788}
789
790/* Route map commands for origin matching. */
791struct route_map_rule_cmd route_match_origin_cmd =
792{
793 "origin",
794 route_match_origin,
795 route_match_origin_compile,
796 route_match_origin_free
797};
Vyacheslav Trushkin1c8afb72011-11-22 20:15:10 +0400798
799/* match probability { */
800
801static route_map_result_t
802route_match_probability (void *rule, struct prefix *prefix,
803 route_map_object_t type, void *object)
804{
805 long r;
806#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
807 r = random();
808#else
809 r = (long) rand();
810#endif
811
812 switch (*(unsigned *) rule)
813 {
814 case 0: break;
815 case RAND_MAX: return RMAP_MATCH;
816 default:
817 if (r < *(unsigned *) rule)
818 {
819 return RMAP_MATCH;
820 }
821 }
822
823 return RMAP_NOMATCH;
824}
825
826static void *
827route_match_probability_compile (const char *arg)
828{
829 unsigned *lobule;
830 unsigned perc;
831
832#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
833 srandom (time (NULL));
834#else
835 srand (time (NULL));
836#endif
837
838 perc = atoi (arg);
839 lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned));
840
841 switch (perc)
842 {
843 case 0: *lobule = 0; break;
844 case 100: *lobule = RAND_MAX; break;
845 default: *lobule = RAND_MAX / 100 * perc;
846 }
847
848 return lobule;
849}
850
851static void
852route_match_probability_free (void *rule)
853{
854 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
855}
856
857struct route_map_rule_cmd route_match_probability_cmd =
858{
859 "probability",
860 route_match_probability,
861 route_match_probability_compile,
862 route_match_probability_free
863};
864
865/* } */
866
paul718e3742002-12-13 20:15:29 +0000867/* `set ip next-hop IP_ADDRESS' */
868
869/* Set nexthop to object. ojbect must be pointer to struct attr. */
paulac41b2a2003-08-12 05:32:27 +0000870struct rmap_ip_nexthop_set
871{
872 struct in_addr *address;
873 int peer_address;
874};
875
paul94f2b392005-06-28 12:44:16 +0000876static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000877route_set_ip_nexthop (void *rule, struct prefix *prefix,
878 route_map_object_t type, void *object)
879{
paulac41b2a2003-08-12 05:32:27 +0000880 struct rmap_ip_nexthop_set *rins = rule;
881 struct in_addr peer_address;
paul718e3742002-12-13 20:15:29 +0000882 struct bgp_info *bgp_info;
paulac41b2a2003-08-12 05:32:27 +0000883 struct peer *peer;
paul718e3742002-12-13 20:15:29 +0000884
885 if (type == RMAP_BGP)
886 {
paul718e3742002-12-13 20:15:29 +0000887 bgp_info = object;
paulac41b2a2003-08-12 05:32:27 +0000888 peer = bgp_info->peer;
889
890 if (rins->peer_address)
891 {
paulfee0f4c2004-09-13 05:12:46 +0000892 if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) ||
893 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
paulac41b2a2003-08-12 05:32:27 +0000894 && peer->su_remote
895 && sockunion_family (peer->su_remote) == AF_INET)
896 {
897 inet_aton (sockunion_su2str (peer->su_remote), &peer_address);
898 bgp_info->attr->nexthop = peer_address;
899 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
900 }
901 else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
902 && peer->su_local
903 && sockunion_family (peer->su_local) == AF_INET)
904 {
905 inet_aton (sockunion_su2str (peer->su_local), &peer_address);
906 bgp_info->attr->nexthop = peer_address;
907 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
908 }
909 }
910 else
911 {
912 /* Set next hop value. */
913 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
914 bgp_info->attr->nexthop = *rins->address;
915 }
paul718e3742002-12-13 20:15:29 +0000916 }
917
918 return RMAP_OKAY;
919}
920
921/* Route map `ip nexthop' compile function. Given string is converted
922 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +0000923static void *
paulfd79ac92004-10-13 05:06:08 +0000924route_set_ip_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000925{
paulac41b2a2003-08-12 05:32:27 +0000926 struct rmap_ip_nexthop_set *rins;
927 struct in_addr *address = NULL;
928 int peer_address = 0;
paul718e3742002-12-13 20:15:29 +0000929 int ret;
paul718e3742002-12-13 20:15:29 +0000930
paulac41b2a2003-08-12 05:32:27 +0000931 if (strcmp (arg, "peer-address") == 0)
932 peer_address = 1;
933 else
paul718e3742002-12-13 20:15:29 +0000934 {
paulac41b2a2003-08-12 05:32:27 +0000935 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
936 ret = inet_aton (arg, address);
937
938 if (ret == 0)
939 {
940 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
941 return NULL;
942 }
paul718e3742002-12-13 20:15:29 +0000943 }
944
Stephen Hemminger393deb92008-08-18 14:13:29 -0700945 rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set));
paulac41b2a2003-08-12 05:32:27 +0000946
947 rins->address = address;
948 rins->peer_address = peer_address;
949
950 return rins;
paul718e3742002-12-13 20:15:29 +0000951}
952
953/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +0000954static void
paul718e3742002-12-13 20:15:29 +0000955route_set_ip_nexthop_free (void *rule)
956{
paulac41b2a2003-08-12 05:32:27 +0000957 struct rmap_ip_nexthop_set *rins = rule;
958
959 if (rins->address)
960 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address);
961
962 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins);
paul718e3742002-12-13 20:15:29 +0000963}
964
965/* Route map commands for ip nexthop set. */
966struct route_map_rule_cmd route_set_ip_nexthop_cmd =
967{
968 "ip next-hop",
969 route_set_ip_nexthop,
970 route_set_ip_nexthop_compile,
971 route_set_ip_nexthop_free
972};
973
974/* `set local-preference LOCAL_PREF' */
975
976/* Set local preference. */
paul94f2b392005-06-28 12:44:16 +0000977static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000978route_set_local_pref (void *rule, struct prefix *prefix,
979 route_map_object_t type, void *object)
980{
981 u_int32_t *local_pref;
982 struct bgp_info *bgp_info;
983
984 if (type == RMAP_BGP)
985 {
986 /* Fetch routemap's rule information. */
987 local_pref = rule;
988 bgp_info = object;
989
990 /* Set local preference value. */
991 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
992 bgp_info->attr->local_pref = *local_pref;
993 }
994
995 return RMAP_OKAY;
996}
997
998/* set local preference compilation. */
paul94f2b392005-06-28 12:44:16 +0000999static void *
paulfd79ac92004-10-13 05:06:08 +00001000route_set_local_pref_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001001{
paulfd79ac92004-10-13 05:06:08 +00001002 unsigned long tmp;
paul718e3742002-12-13 20:15:29 +00001003 u_int32_t *local_pref;
1004 char *endptr = NULL;
1005
1006 /* Local preference value shoud be integer. */
1007 if (! all_digit (arg))
1008 return NULL;
paulfd79ac92004-10-13 05:06:08 +00001009
Ulrich Weber830526a2011-12-21 02:24:11 +04001010 errno = 0;
paulfd79ac92004-10-13 05:06:08 +00001011 tmp = strtoul (arg, &endptr, 10);
Ulrich Weber830526a2011-12-21 02:24:11 +04001012 if (*endptr != '\0' || errno || tmp > UINT32_MAX)
paulfd79ac92004-10-13 05:06:08 +00001013 return NULL;
1014
1015 local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
1016
1017 if (!local_pref)
1018 return local_pref;
1019
1020 *local_pref = tmp;
1021
paul718e3742002-12-13 20:15:29 +00001022 return local_pref;
1023}
1024
1025/* Free route map's local preference value. */
paul94f2b392005-06-28 12:44:16 +00001026static void
paul718e3742002-12-13 20:15:29 +00001027route_set_local_pref_free (void *rule)
1028{
1029 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1030}
1031
1032/* Set local preference rule structure. */
1033struct route_map_rule_cmd route_set_local_pref_cmd =
1034{
1035 "local-preference",
1036 route_set_local_pref,
1037 route_set_local_pref_compile,
1038 route_set_local_pref_free,
1039};
1040
1041/* `set weight WEIGHT' */
1042
1043/* Set weight. */
paul94f2b392005-06-28 12:44:16 +00001044static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001045route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type,
1046 void *object)
1047{
1048 u_int32_t *weight;
1049 struct bgp_info *bgp_info;
1050
1051 if (type == RMAP_BGP)
1052 {
1053 /* Fetch routemap's rule information. */
1054 weight = rule;
1055 bgp_info = object;
1056
1057 /* Set weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001058 if (*weight)
1059 (bgp_attr_extra_get (bgp_info->attr))->weight = *weight;
1060 else if (bgp_info->attr->extra)
1061 bgp_info->attr->extra->weight = 0;
paul718e3742002-12-13 20:15:29 +00001062 }
1063
1064 return RMAP_OKAY;
1065}
1066
1067/* set local preference compilation. */
paul94f2b392005-06-28 12:44:16 +00001068static void *
paulfd79ac92004-10-13 05:06:08 +00001069route_set_weight_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001070{
paulfd79ac92004-10-13 05:06:08 +00001071 unsigned long tmp;
paul718e3742002-12-13 20:15:29 +00001072 u_int32_t *weight;
1073 char *endptr = NULL;
1074
1075 /* Local preference value shoud be integer. */
1076 if (! all_digit (arg))
1077 return NULL;
1078
Ulrich Weber830526a2011-12-21 02:24:11 +04001079 errno = 0;
paulfd79ac92004-10-13 05:06:08 +00001080 tmp = strtoul (arg, &endptr, 10);
Ulrich Weber830526a2011-12-21 02:24:11 +04001081 if (*endptr != '\0' || errno || tmp > UINT32_MAX)
paulfd79ac92004-10-13 05:06:08 +00001082 return NULL;
1083
paul718e3742002-12-13 20:15:29 +00001084 weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
paulfd79ac92004-10-13 05:06:08 +00001085
1086 if (weight == NULL)
1087 return weight;
1088
1089 *weight = tmp;
1090
paul718e3742002-12-13 20:15:29 +00001091 return weight;
1092}
1093
1094/* Free route map's local preference value. */
paul94f2b392005-06-28 12:44:16 +00001095static void
paul718e3742002-12-13 20:15:29 +00001096route_set_weight_free (void *rule)
1097{
1098 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1099}
1100
1101/* Set local preference rule structure. */
1102struct route_map_rule_cmd route_set_weight_cmd =
1103{
1104 "weight",
1105 route_set_weight,
1106 route_set_weight_compile,
1107 route_set_weight_free,
1108};
1109
1110/* `set metric METRIC' */
1111
1112/* Set metric to attribute. */
paul94f2b392005-06-28 12:44:16 +00001113static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001114route_set_metric (void *rule, struct prefix *prefix,
1115 route_map_object_t type, void *object)
1116{
1117 char *metric;
1118 u_int32_t metric_val;
1119 struct bgp_info *bgp_info;
1120
1121 if (type == RMAP_BGP)
1122 {
1123 /* Fetch routemap's rule information. */
1124 metric = rule;
1125 bgp_info = object;
1126
1127 if (! (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
1128 bgp_info->attr->med = 0;
1129 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
1130
1131 if (all_digit (metric))
1132 {
1133 metric_val = strtoul (metric, (char **)NULL, 10);
1134 bgp_info->attr->med = metric_val;
1135 }
1136 else
1137 {
1138 metric_val = strtoul (metric+1, (char **)NULL, 10);
1139
1140 if (strncmp (metric, "+", 1) == 0)
1141 {
paul3b424972003-10-13 09:47:32 +00001142 if (bgp_info->attr->med/2 + metric_val/2 > BGP_MED_MAX/2)
1143 bgp_info->attr->med = BGP_MED_MAX - 1;
paul718e3742002-12-13 20:15:29 +00001144 else
paul537d8ea2003-08-27 06:45:32 +00001145 bgp_info->attr->med += metric_val;
paul718e3742002-12-13 20:15:29 +00001146 }
1147 else if (strncmp (metric, "-", 1) == 0)
1148 {
paul537d8ea2003-08-27 06:45:32 +00001149 if (bgp_info->attr->med <= metric_val)
1150 bgp_info->attr->med = 0;
paul718e3742002-12-13 20:15:29 +00001151 else
paul537d8ea2003-08-27 06:45:32 +00001152 bgp_info->attr->med -= metric_val;
paul718e3742002-12-13 20:15:29 +00001153 }
1154 }
1155 }
1156 return RMAP_OKAY;
1157}
1158
1159/* set metric compilation. */
paul94f2b392005-06-28 12:44:16 +00001160static void *
paulfd79ac92004-10-13 05:06:08 +00001161route_set_metric_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001162{
1163 u_int32_t metric;
paul94f2b392005-06-28 12:44:16 +00001164 unsigned long larg;
paul718e3742002-12-13 20:15:29 +00001165 char *endptr = NULL;
1166
1167 if (all_digit (arg))
1168 {
1169 /* set metric value check*/
Ulrich Weber830526a2011-12-21 02:24:11 +04001170 errno = 0;
paul94f2b392005-06-28 12:44:16 +00001171 larg = strtoul (arg, &endptr, 10);
Ulrich Weber830526a2011-12-21 02:24:11 +04001172 if (*endptr != '\0' || errno || larg > UINT32_MAX)
paul718e3742002-12-13 20:15:29 +00001173 return NULL;
paul94f2b392005-06-28 12:44:16 +00001174 metric = larg;
paul718e3742002-12-13 20:15:29 +00001175 }
1176 else
1177 {
1178 /* set metric +/-value check */
1179 if ((strncmp (arg, "+", 1) != 0
1180 && strncmp (arg, "-", 1) != 0)
1181 || (! all_digit (arg+1)))
1182 return NULL;
1183
Ulrich Weber830526a2011-12-21 02:24:11 +04001184 errno = 0;
paul94f2b392005-06-28 12:44:16 +00001185 larg = strtoul (arg+1, &endptr, 10);
Ulrich Weber830526a2011-12-21 02:24:11 +04001186 if (*endptr != '\0' || errno || larg > UINT32_MAX)
paul718e3742002-12-13 20:15:29 +00001187 return NULL;
paul94f2b392005-06-28 12:44:16 +00001188 metric = larg;
paul718e3742002-12-13 20:15:29 +00001189 }
1190
1191 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1192}
1193
1194/* Free route map's compiled `set metric' value. */
paul94f2b392005-06-28 12:44:16 +00001195static void
paul718e3742002-12-13 20:15:29 +00001196route_set_metric_free (void *rule)
1197{
1198 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1199}
1200
1201/* Set metric rule structure. */
1202struct route_map_rule_cmd route_set_metric_cmd =
1203{
1204 "metric",
1205 route_set_metric,
1206 route_set_metric_compile,
1207 route_set_metric_free,
1208};
1209
1210/* `set as-path prepend ASPATH' */
1211
1212/* For AS path prepend mechanism. */
paul94f2b392005-06-28 12:44:16 +00001213static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001214route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1215{
1216 struct aspath *aspath;
1217 struct aspath *new;
1218 struct bgp_info *binfo;
1219
1220 if (type == RMAP_BGP)
1221 {
1222 aspath = rule;
1223 binfo = object;
1224
1225 if (binfo->attr->aspath->refcnt)
1226 new = aspath_dup (binfo->attr->aspath);
1227 else
1228 new = binfo->attr->aspath;
1229
1230 aspath_prepend (aspath, new);
1231 binfo->attr->aspath = new;
1232 }
1233
1234 return RMAP_OKAY;
1235}
1236
1237/* Compile function for as-path prepend. */
paul94f2b392005-06-28 12:44:16 +00001238static void *
paulfd79ac92004-10-13 05:06:08 +00001239route_set_aspath_prepend_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001240{
1241 struct aspath *aspath;
1242
1243 aspath = aspath_str2aspath (arg);
1244 if (! aspath)
1245 return NULL;
1246 return aspath;
1247}
1248
1249/* Compile function for as-path prepend. */
paul94f2b392005-06-28 12:44:16 +00001250static void
paul718e3742002-12-13 20:15:29 +00001251route_set_aspath_prepend_free (void *rule)
1252{
1253 struct aspath *aspath = rule;
1254 aspath_free (aspath);
1255}
1256
1257/* Set metric rule structure. */
1258struct route_map_rule_cmd route_set_aspath_prepend_cmd =
1259{
1260 "as-path prepend",
1261 route_set_aspath_prepend,
1262 route_set_aspath_prepend_compile,
1263 route_set_aspath_prepend_free,
1264};
1265
Denis Ovsienko841f7a52008-04-10 11:47:45 +00001266/* `set as-path exclude ASn' */
1267
1268/* For ASN exclude mechanism.
1269 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1270 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1271 */
1272static route_map_result_t
1273route_set_aspath_exclude (void *rule, struct prefix *dummy, route_map_object_t type, void *object)
1274{
1275 struct aspath * new_path, * exclude_path;
1276 struct bgp_info *binfo;
1277
1278 if (type == RMAP_BGP)
1279 {
1280 exclude_path = rule;
1281 binfo = object;
1282 if (binfo->attr->aspath->refcnt)
1283 new_path = aspath_dup (binfo->attr->aspath);
1284 else
1285 new_path = binfo->attr->aspath;
1286 binfo->attr->aspath = aspath_filter_exclude (new_path, exclude_path);
1287 }
1288 return RMAP_OKAY;
1289}
1290
1291/* FIXME: consider using route_set_aspath_prepend_compile() and
1292 * route_set_aspath_prepend_free(), which two below function are
1293 * exact clones of.
1294 */
1295
1296/* Compile function for as-path exclude. */
1297static void *
1298route_set_aspath_exclude_compile (const char *arg)
1299{
1300 struct aspath *aspath;
1301
1302 aspath = aspath_str2aspath (arg);
1303 if (! aspath)
1304 return NULL;
1305 return aspath;
1306}
1307
1308static void
1309route_set_aspath_exclude_free (void *rule)
1310{
1311 struct aspath *aspath = rule;
1312 aspath_free (aspath);
1313}
1314
1315/* Set ASn exlude rule structure. */
1316struct route_map_rule_cmd route_set_aspath_exclude_cmd =
1317{
1318 "as-path exclude",
1319 route_set_aspath_exclude,
1320 route_set_aspath_exclude_compile,
1321 route_set_aspath_exclude_free,
1322};
1323
paul718e3742002-12-13 20:15:29 +00001324/* `set community COMMUNITY' */
1325struct rmap_com_set
1326{
1327 struct community *com;
1328 int additive;
1329 int none;
1330};
1331
1332/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001333static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001334route_set_community (void *rule, struct prefix *prefix,
1335 route_map_object_t type, void *object)
1336{
1337 struct rmap_com_set *rcs;
1338 struct bgp_info *binfo;
1339 struct attr *attr;
1340 struct community *new = NULL;
1341 struct community *old;
1342 struct community *merge;
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001343
paul718e3742002-12-13 20:15:29 +00001344 if (type == RMAP_BGP)
1345 {
1346 rcs = rule;
1347 binfo = object;
1348 attr = binfo->attr;
1349 old = attr->community;
1350
1351 /* "none" case. */
1352 if (rcs->none)
1353 {
1354 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES));
1355 attr->community = NULL;
1356 return RMAP_OKAY;
1357 }
1358
1359 /* "additive" case. */
1360 if (rcs->additive && old)
1361 {
1362 merge = community_merge (community_dup (old), rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001363
1364 /* HACK: if the old community is not intern'd,
1365 * we should free it here, or all reference to it may be lost.
1366 * Really need to cleanup attribute caching sometime.
1367 */
1368 if (old->refcnt == 0)
1369 community_free (old);
paul718e3742002-12-13 20:15:29 +00001370 new = community_uniq_sort (merge);
1371 community_free (merge);
1372 }
1373 else
1374 new = community_dup (rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001375
1376 /* will be interned by caller if required */
paul718e3742002-12-13 20:15:29 +00001377 attr->community = new;
hasso70601e02005-05-27 03:26:57 +00001378
paul718e3742002-12-13 20:15:29 +00001379 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1380 }
1381
1382 return RMAP_OKAY;
1383}
1384
1385/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001386static void *
paulfd79ac92004-10-13 05:06:08 +00001387route_set_community_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001388{
1389 struct rmap_com_set *rcs;
1390 struct community *com = NULL;
1391 char *sp;
1392 int additive = 0;
1393 int none = 0;
1394
1395 if (strcmp (arg, "none") == 0)
1396 none = 1;
1397 else
1398 {
1399 sp = strstr (arg, "additive");
1400
1401 if (sp && sp > arg)
1402 {
1403 /* "additive" keyworkd is included. */
1404 additive = 1;
1405 *(sp - 1) = '\0';
1406 }
1407
1408 com = community_str2com (arg);
1409
1410 if (additive)
1411 *(sp - 1) = ' ';
1412
1413 if (! com)
1414 return NULL;
1415 }
1416
Stephen Hemminger393deb92008-08-18 14:13:29 -07001417 rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
paul718e3742002-12-13 20:15:29 +00001418 rcs->com = com;
1419 rcs->additive = additive;
1420 rcs->none = none;
1421
1422 return rcs;
1423}
1424
1425/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001426static void
paul718e3742002-12-13 20:15:29 +00001427route_set_community_free (void *rule)
1428{
1429 struct rmap_com_set *rcs = rule;
1430
1431 if (rcs->com)
1432 community_free (rcs->com);
1433 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs);
1434}
1435
1436/* Set community rule structure. */
1437struct route_map_rule_cmd route_set_community_cmd =
1438{
1439 "community",
1440 route_set_community,
1441 route_set_community_compile,
1442 route_set_community_free,
1443};
1444
hassofee6e4e2005-02-02 16:29:31 +00001445/* `set comm-list (<1-99>|<100-500>|WORD) delete' */
paul718e3742002-12-13 20:15:29 +00001446
1447/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001448static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001449route_set_community_delete (void *rule, struct prefix *prefix,
1450 route_map_object_t type, void *object)
1451{
1452 struct community_list *list;
1453 struct community *merge;
1454 struct community *new;
1455 struct community *old;
1456 struct bgp_info *binfo;
1457
1458 if (type == RMAP_BGP)
1459 {
1460 if (! rule)
1461 return RMAP_OKAY;
1462
1463 binfo = object;
hassofee6e4e2005-02-02 16:29:31 +00001464 list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00001465 old = binfo->attr->community;
1466
1467 if (list && old)
1468 {
1469 merge = community_list_match_delete (community_dup (old), list);
1470 new = community_uniq_sort (merge);
1471 community_free (merge);
1472
1473 if (new->size == 0)
1474 {
1475 binfo->attr->community = NULL;
1476 binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1477 community_free (new);
1478 }
1479 else
1480 {
1481 binfo->attr->community = new;
1482 binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1483 }
1484 }
1485 }
1486
1487 return RMAP_OKAY;
1488}
1489
1490/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001491static void *
paulfd79ac92004-10-13 05:06:08 +00001492route_set_community_delete_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001493{
1494 char *p;
1495 char *str;
1496 int len;
1497
1498 p = strchr (arg, ' ');
1499 if (p)
1500 {
1501 len = p - arg;
1502 str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
1503 memcpy (str, arg, len);
1504 }
1505 else
1506 str = NULL;
1507
1508 return str;
1509}
1510
1511/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001512static void
paul718e3742002-12-13 20:15:29 +00001513route_set_community_delete_free (void *rule)
1514{
1515 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1516}
1517
1518/* Set community rule structure. */
1519struct route_map_rule_cmd route_set_community_delete_cmd =
1520{
1521 "comm-list",
1522 route_set_community_delete,
1523 route_set_community_delete_compile,
1524 route_set_community_delete_free,
1525};
1526
1527/* `set extcommunity rt COMMUNITY' */
1528
1529/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001530static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001531route_set_ecommunity_rt (void *rule, struct prefix *prefix,
1532 route_map_object_t type, void *object)
1533{
1534 struct ecommunity *ecom;
1535 struct ecommunity *new_ecom;
1536 struct ecommunity *old_ecom;
1537 struct bgp_info *bgp_info;
1538
1539 if (type == RMAP_BGP)
1540 {
1541 ecom = rule;
1542 bgp_info = object;
1543
1544 if (! ecom)
1545 return RMAP_OKAY;
1546
1547 /* We assume additive for Extended Community. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001548 old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
paul718e3742002-12-13 20:15:29 +00001549
1550 if (old_ecom)
1551 new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
1552 else
1553 new_ecom = ecommunity_dup (ecom);
1554
Paul Jakmafb982c22007-05-04 20:15:47 +00001555 bgp_info->attr->extra->ecommunity = new_ecom;
paul718e3742002-12-13 20:15:29 +00001556
hasso70601e02005-05-27 03:26:57 +00001557 if (old_ecom)
1558 ecommunity_free (old_ecom);
1559
paul718e3742002-12-13 20:15:29 +00001560 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
1561 }
1562 return RMAP_OKAY;
1563}
1564
1565/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001566static void *
paulfd79ac92004-10-13 05:06:08 +00001567route_set_ecommunity_rt_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001568{
1569 struct ecommunity *ecom;
1570
1571 ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0);
1572 if (! ecom)
1573 return NULL;
1574 return ecom;
1575}
1576
1577/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001578static void
paul718e3742002-12-13 20:15:29 +00001579route_set_ecommunity_rt_free (void *rule)
1580{
1581 struct ecommunity *ecom = rule;
1582 ecommunity_free (ecom);
1583}
1584
1585/* Set community rule structure. */
1586struct route_map_rule_cmd route_set_ecommunity_rt_cmd =
1587{
1588 "extcommunity rt",
1589 route_set_ecommunity_rt,
1590 route_set_ecommunity_rt_compile,
1591 route_set_ecommunity_rt_free,
1592};
1593
1594/* `set extcommunity soo COMMUNITY' */
1595
1596/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001597static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001598route_set_ecommunity_soo (void *rule, struct prefix *prefix,
1599 route_map_object_t type, void *object)
1600{
1601 struct ecommunity *ecom;
1602 struct bgp_info *bgp_info;
1603
1604 if (type == RMAP_BGP)
1605 {
1606 ecom = rule;
1607 bgp_info = object;
1608
1609 if (! ecom)
1610 return RMAP_OKAY;
1611
1612 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
Paul Jakmafb982c22007-05-04 20:15:47 +00001613 (bgp_attr_extra_get (bgp_info->attr))->ecommunity = ecommunity_dup (ecom);
paul718e3742002-12-13 20:15:29 +00001614 }
1615 return RMAP_OKAY;
1616}
1617
1618/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001619static void *
paulfd79ac92004-10-13 05:06:08 +00001620route_set_ecommunity_soo_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001621{
1622 struct ecommunity *ecom;
1623
1624 ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0);
1625 if (! ecom)
1626 return NULL;
1627
1628 return ecom;
1629}
1630
1631/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001632static void
paul718e3742002-12-13 20:15:29 +00001633route_set_ecommunity_soo_free (void *rule)
1634{
1635 struct ecommunity *ecom = rule;
1636 ecommunity_free (ecom);
1637}
1638
1639/* Set community rule structure. */
1640struct route_map_rule_cmd route_set_ecommunity_soo_cmd =
1641{
1642 "extcommunity soo",
1643 route_set_ecommunity_soo,
1644 route_set_ecommunity_soo_compile,
1645 route_set_ecommunity_soo_free,
1646};
1647
1648/* `set origin ORIGIN' */
1649
1650/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00001651static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001652route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1653{
1654 u_char *origin;
1655 struct bgp_info *bgp_info;
1656
1657 if (type == RMAP_BGP)
1658 {
1659 origin = rule;
1660 bgp_info = object;
1661
1662 bgp_info->attr->origin = *origin;
1663 }
1664
1665 return RMAP_OKAY;
1666}
1667
1668/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001669static void *
paulfd79ac92004-10-13 05:06:08 +00001670route_set_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001671{
1672 u_char *origin;
1673
1674 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
1675
1676 if (strcmp (arg, "igp") == 0)
1677 *origin = 0;
1678 else if (strcmp (arg, "egp") == 0)
1679 *origin = 1;
1680 else
1681 *origin = 2;
1682
1683 return origin;
1684}
1685
1686/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001687static void
paul718e3742002-12-13 20:15:29 +00001688route_set_origin_free (void *rule)
1689{
1690 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1691}
1692
1693/* Set metric rule structure. */
1694struct route_map_rule_cmd route_set_origin_cmd =
1695{
1696 "origin",
1697 route_set_origin,
1698 route_set_origin_compile,
1699 route_set_origin_free,
1700};
1701
1702/* `set atomic-aggregate' */
1703
1704/* For atomic aggregate set. */
paul94f2b392005-06-28 12:44:16 +00001705static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001706route_set_atomic_aggregate (void *rule, struct prefix *prefix,
1707 route_map_object_t type, void *object)
1708{
1709 struct bgp_info *bgp_info;
1710
1711 if (type == RMAP_BGP)
1712 {
1713 bgp_info = object;
1714 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
1715 }
1716
1717 return RMAP_OKAY;
1718}
1719
1720/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001721static void *
paulfd79ac92004-10-13 05:06:08 +00001722route_set_atomic_aggregate_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001723{
1724 return (void *)1;
1725}
1726
1727/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001728static void
paul718e3742002-12-13 20:15:29 +00001729route_set_atomic_aggregate_free (void *rule)
1730{
1731 return;
1732}
1733
1734/* Set atomic aggregate rule structure. */
1735struct route_map_rule_cmd route_set_atomic_aggregate_cmd =
1736{
1737 "atomic-aggregate",
1738 route_set_atomic_aggregate,
1739 route_set_atomic_aggregate_compile,
1740 route_set_atomic_aggregate_free,
1741};
1742
1743/* `set aggregator as AS A.B.C.D' */
1744struct aggregator
1745{
1746 as_t as;
1747 struct in_addr address;
1748};
1749
paul94f2b392005-06-28 12:44:16 +00001750static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001751route_set_aggregator_as (void *rule, struct prefix *prefix,
1752 route_map_object_t type, void *object)
1753{
1754 struct bgp_info *bgp_info;
1755 struct aggregator *aggregator;
Paul Jakmafb982c22007-05-04 20:15:47 +00001756 struct attr_extra *ae;
paul718e3742002-12-13 20:15:29 +00001757
1758 if (type == RMAP_BGP)
1759 {
1760 bgp_info = object;
1761 aggregator = rule;
Paul Jakmafb982c22007-05-04 20:15:47 +00001762 ae = bgp_attr_extra_get (bgp_info->attr);
1763
1764 ae->aggregator_as = aggregator->as;
1765 ae->aggregator_addr = aggregator->address;
paul718e3742002-12-13 20:15:29 +00001766 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
1767 }
1768
1769 return RMAP_OKAY;
1770}
1771
paul94f2b392005-06-28 12:44:16 +00001772static void *
paulfd79ac92004-10-13 05:06:08 +00001773route_set_aggregator_as_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001774{
1775 struct aggregator *aggregator;
1776 char as[10];
1777 char address[20];
1778
Stephen Hemminger393deb92008-08-18 14:13:29 -07001779 aggregator = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));
paul718e3742002-12-13 20:15:29 +00001780 sscanf (arg, "%s %s", as, address);
1781
1782 aggregator->as = strtoul (as, NULL, 10);
1783 inet_aton (address, &aggregator->address);
1784
1785 return aggregator;
1786}
1787
paul94f2b392005-06-28 12:44:16 +00001788static void
paul718e3742002-12-13 20:15:29 +00001789route_set_aggregator_as_free (void *rule)
1790{
1791 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1792}
1793
1794struct route_map_rule_cmd route_set_aggregator_as_cmd =
1795{
1796 "aggregator as",
1797 route_set_aggregator_as,
1798 route_set_aggregator_as_compile,
1799 route_set_aggregator_as_free,
1800};
1801
1802#ifdef HAVE_IPV6
1803/* `match ipv6 address IP_ACCESS_LIST' */
1804
paul94f2b392005-06-28 12:44:16 +00001805static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001806route_match_ipv6_address (void *rule, struct prefix *prefix,
1807 route_map_object_t type, void *object)
1808{
1809 struct access_list *alist;
1810
1811 if (type == RMAP_BGP)
1812 {
1813 alist = access_list_lookup (AFI_IP6, (char *) rule);
1814 if (alist == NULL)
1815 return RMAP_NOMATCH;
1816
1817 return (access_list_apply (alist, prefix) == FILTER_DENY ?
1818 RMAP_NOMATCH : RMAP_MATCH);
1819 }
1820 return RMAP_NOMATCH;
1821}
1822
paul94f2b392005-06-28 12:44:16 +00001823static void *
paulfd79ac92004-10-13 05:06:08 +00001824route_match_ipv6_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001825{
1826 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1827}
1828
paul94f2b392005-06-28 12:44:16 +00001829static void
paul718e3742002-12-13 20:15:29 +00001830route_match_ipv6_address_free (void *rule)
1831{
1832 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1833}
1834
1835/* Route map commands for ip address matching. */
1836struct route_map_rule_cmd route_match_ipv6_address_cmd =
1837{
1838 "ipv6 address",
1839 route_match_ipv6_address,
1840 route_match_ipv6_address_compile,
1841 route_match_ipv6_address_free
1842};
1843
1844/* `match ipv6 next-hop IP_ADDRESS' */
1845
paul94f2b392005-06-28 12:44:16 +00001846static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001847route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
1848 route_map_object_t type, void *object)
1849{
1850 struct in6_addr *addr;
1851 struct bgp_info *bgp_info;
1852
1853 if (type == RMAP_BGP)
1854 {
1855 addr = rule;
1856 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +00001857
1858 if (!bgp_info->attr->extra)
1859 return RMAP_NOMATCH;
1860
1861 if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, rule))
paul718e3742002-12-13 20:15:29 +00001862 return RMAP_MATCH;
1863
Paul Jakmafb982c22007-05-04 20:15:47 +00001864 if (bgp_info->attr->extra->mp_nexthop_len == 32 &&
1865 IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, rule))
paul718e3742002-12-13 20:15:29 +00001866 return RMAP_MATCH;
1867
1868 return RMAP_NOMATCH;
1869 }
1870
1871 return RMAP_NOMATCH;
1872}
1873
paul94f2b392005-06-28 12:44:16 +00001874static void *
paulfd79ac92004-10-13 05:06:08 +00001875route_match_ipv6_next_hop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001876{
1877 struct in6_addr *address;
1878 int ret;
1879
1880 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1881
1882 ret = inet_pton (AF_INET6, arg, address);
1883 if (!ret)
1884 {
1885 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1886 return NULL;
1887 }
1888
1889 return address;
1890}
1891
paul94f2b392005-06-28 12:44:16 +00001892static void
paul718e3742002-12-13 20:15:29 +00001893route_match_ipv6_next_hop_free (void *rule)
1894{
1895 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1896}
1897
1898struct route_map_rule_cmd route_match_ipv6_next_hop_cmd =
1899{
1900 "ipv6 next-hop",
1901 route_match_ipv6_next_hop,
1902 route_match_ipv6_next_hop_compile,
1903 route_match_ipv6_next_hop_free
1904};
1905
1906/* `match ipv6 address prefix-list PREFIX_LIST' */
1907
paul94f2b392005-06-28 12:44:16 +00001908static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001909route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix,
1910 route_map_object_t type, void *object)
1911{
1912 struct prefix_list *plist;
1913
1914 if (type == RMAP_BGP)
1915 {
1916 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
1917 if (plist == NULL)
1918 return RMAP_NOMATCH;
1919
1920 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
1921 RMAP_NOMATCH : RMAP_MATCH);
1922 }
1923 return RMAP_NOMATCH;
1924}
1925
paul94f2b392005-06-28 12:44:16 +00001926static void *
paulfd79ac92004-10-13 05:06:08 +00001927route_match_ipv6_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001928{
1929 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1930}
1931
paul94f2b392005-06-28 12:44:16 +00001932static void
paul718e3742002-12-13 20:15:29 +00001933route_match_ipv6_address_prefix_list_free (void *rule)
1934{
1935 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1936}
1937
1938struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
1939{
1940 "ipv6 address prefix-list",
1941 route_match_ipv6_address_prefix_list,
1942 route_match_ipv6_address_prefix_list_compile,
1943 route_match_ipv6_address_prefix_list_free
1944};
1945
1946/* `set ipv6 nexthop global IP_ADDRESS' */
1947
1948/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001949static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001950route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix,
1951 route_map_object_t type, void *object)
1952{
1953 struct in6_addr *address;
1954 struct bgp_info *bgp_info;
1955
1956 if (type == RMAP_BGP)
1957 {
1958 /* Fetch routemap's rule information. */
1959 address = rule;
1960 bgp_info = object;
1961
1962 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001963 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address;
paul718e3742002-12-13 20:15:29 +00001964
1965 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001966 if (bgp_info->attr->extra->mp_nexthop_len == 0)
1967 bgp_info->attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001968 }
1969
1970 return RMAP_OKAY;
1971}
1972
1973/* Route map `ip next-hop' compile function. Given string is converted
1974 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00001975static void *
paulfd79ac92004-10-13 05:06:08 +00001976route_set_ipv6_nexthop_global_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001977{
1978 int ret;
1979 struct in6_addr *address;
1980
1981 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1982
1983 ret = inet_pton (AF_INET6, arg, address);
1984
1985 if (ret == 0)
1986 {
1987 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1988 return NULL;
1989 }
1990
1991 return address;
1992}
1993
1994/* Free route map's compiled `ip next-hop' value. */
paul94f2b392005-06-28 12:44:16 +00001995static void
paul718e3742002-12-13 20:15:29 +00001996route_set_ipv6_nexthop_global_free (void *rule)
1997{
1998 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1999}
2000
2001/* Route map commands for ip nexthop set. */
2002struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd =
2003{
2004 "ipv6 next-hop global",
2005 route_set_ipv6_nexthop_global,
2006 route_set_ipv6_nexthop_global_compile,
2007 route_set_ipv6_nexthop_global_free
2008};
2009
2010/* `set ipv6 nexthop local IP_ADDRESS' */
2011
2012/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00002013static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002014route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
2015 route_map_object_t type, void *object)
2016{
2017 struct in6_addr *address;
2018 struct bgp_info *bgp_info;
2019
2020 if (type == RMAP_BGP)
2021 {
2022 /* Fetch routemap's rule information. */
2023 address = rule;
2024 bgp_info = object;
2025
2026 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002027 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address;
paul718e3742002-12-13 20:15:29 +00002028
2029 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002030 if (bgp_info->attr->extra->mp_nexthop_len != 32)
2031 bgp_info->attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002032 }
2033
2034 return RMAP_OKAY;
2035}
2036
2037/* Route map `ip nexthop' compile function. Given string is converted
2038 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00002039static void *
paulfd79ac92004-10-13 05:06:08 +00002040route_set_ipv6_nexthop_local_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002041{
2042 int ret;
2043 struct in6_addr *address;
2044
2045 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
2046
2047 ret = inet_pton (AF_INET6, arg, address);
2048
2049 if (ret == 0)
2050 {
2051 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2052 return NULL;
2053 }
2054
2055 return address;
2056}
2057
2058/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +00002059static void
paul718e3742002-12-13 20:15:29 +00002060route_set_ipv6_nexthop_local_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_local_cmd =
2067{
2068 "ipv6 next-hop local",
2069 route_set_ipv6_nexthop_local,
2070 route_set_ipv6_nexthop_local_compile,
2071 route_set_ipv6_nexthop_local_free
2072};
2073#endif /* HAVE_IPV6 */
2074
2075/* `set vpnv4 nexthop A.B.C.D' */
2076
paul94f2b392005-06-28 12:44:16 +00002077static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002078route_set_vpnv4_nexthop (void *rule, struct prefix *prefix,
2079 route_map_object_t type, void *object)
2080{
2081 struct in_addr *address;
2082 struct bgp_info *bgp_info;
2083
2084 if (type == RMAP_BGP)
2085 {
2086 /* Fetch routemap's rule information. */
2087 address = rule;
2088 bgp_info = object;
2089
2090 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002091 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address;
paul718e3742002-12-13 20:15:29 +00002092 }
2093
2094 return RMAP_OKAY;
2095}
2096
paul94f2b392005-06-28 12:44:16 +00002097static void *
paulfd79ac92004-10-13 05:06:08 +00002098route_set_vpnv4_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002099{
2100 int ret;
2101 struct in_addr *address;
2102
2103 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2104
2105 ret = inet_aton (arg, address);
2106
2107 if (ret == 0)
2108 {
2109 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2110 return NULL;
2111 }
2112
2113 return address;
2114}
2115
paul94f2b392005-06-28 12:44:16 +00002116static void
paul718e3742002-12-13 20:15:29 +00002117route_set_vpnv4_nexthop_free (void *rule)
2118{
2119 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2120}
2121
2122/* Route map commands for ip nexthop set. */
2123struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd =
2124{
2125 "vpnv4 next-hop",
2126 route_set_vpnv4_nexthop,
2127 route_set_vpnv4_nexthop_compile,
2128 route_set_vpnv4_nexthop_free
2129};
2130
2131/* `set originator-id' */
2132
2133/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00002134static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002135route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
2136{
2137 struct in_addr *address;
2138 struct bgp_info *bgp_info;
2139
2140 if (type == RMAP_BGP)
2141 {
2142 address = rule;
2143 bgp_info = object;
2144
2145 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);
Paul Jakmafb982c22007-05-04 20:15:47 +00002146 (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address;
paul718e3742002-12-13 20:15:29 +00002147 }
2148
2149 return RMAP_OKAY;
2150}
2151
2152/* Compile function for originator-id set. */
paul94f2b392005-06-28 12:44:16 +00002153static void *
paulfd79ac92004-10-13 05:06:08 +00002154route_set_originator_id_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002155{
2156 int ret;
2157 struct in_addr *address;
2158
2159 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2160
2161 ret = inet_aton (arg, address);
2162
2163 if (ret == 0)
2164 {
2165 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2166 return NULL;
2167 }
2168
2169 return address;
2170}
2171
2172/* Compile function for originator_id set. */
paul94f2b392005-06-28 12:44:16 +00002173static void
paul718e3742002-12-13 20:15:29 +00002174route_set_originator_id_free (void *rule)
2175{
2176 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2177}
2178
2179/* Set metric rule structure. */
2180struct route_map_rule_cmd route_set_originator_id_cmd =
2181{
2182 "originator-id",
2183 route_set_originator_id,
2184 route_set_originator_id_compile,
2185 route_set_originator_id_free,
2186};
2187
2188/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002189static int
paul718e3742002-12-13 20:15:29 +00002190bgp_route_match_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002191 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002192{
2193 int ret;
2194
2195 ret = route_map_add_match (index, command, arg);
2196 if (ret)
2197 {
2198 switch (ret)
2199 {
2200 case RMAP_RULE_MISSING:
2201 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2202 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002203 case RMAP_COMPILE_ERROR:
2204 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2205 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002206 }
2207 }
2208 return CMD_SUCCESS;
2209}
2210
2211/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002212static int
paul718e3742002-12-13 20:15:29 +00002213bgp_route_match_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002214 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002215{
2216 int ret;
2217
2218 ret = route_map_delete_match (index, command, arg);
2219 if (ret)
2220 {
2221 switch (ret)
2222 {
2223 case RMAP_RULE_MISSING:
2224 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2225 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002226 case RMAP_COMPILE_ERROR:
2227 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2228 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002229 }
2230 }
2231 return CMD_SUCCESS;
2232}
2233
2234/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002235static int
paul718e3742002-12-13 20:15:29 +00002236bgp_route_set_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002237 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002238{
2239 int ret;
2240
2241 ret = route_map_add_set (index, command, arg);
2242 if (ret)
2243 {
2244 switch (ret)
2245 {
2246 case RMAP_RULE_MISSING:
2247 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2248 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002249 case RMAP_COMPILE_ERROR:
2250 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2251 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002252 }
2253 }
2254 return CMD_SUCCESS;
2255}
2256
2257/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002258static int
paul718e3742002-12-13 20:15:29 +00002259bgp_route_set_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002260 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002261{
2262 int ret;
2263
2264 ret = route_map_delete_set (index, command, arg);
2265 if (ret)
2266 {
2267 switch (ret)
2268 {
2269 case RMAP_RULE_MISSING:
2270 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2271 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002272 case RMAP_COMPILE_ERROR:
2273 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2274 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002275 }
2276 }
2277 return CMD_SUCCESS;
2278}
2279
2280/* Hook function for updating route_map assignment. */
paul94f2b392005-06-28 12:44:16 +00002281static void
paulfd79ac92004-10-13 05:06:08 +00002282bgp_route_map_update (const char *unused)
paul718e3742002-12-13 20:15:29 +00002283{
2284 int i;
2285 afi_t afi;
2286 safi_t safi;
2287 int direct;
paul1eb8ef22005-04-07 07:30:20 +00002288 struct listnode *node, *nnode;
2289 struct listnode *mnode, *mnnode;
paul718e3742002-12-13 20:15:29 +00002290 struct bgp *bgp;
2291 struct peer *peer;
2292 struct peer_group *group;
2293 struct bgp_filter *filter;
2294 struct bgp_node *bn;
2295 struct bgp_static *bgp_static;
2296
2297 /* For neighbor route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002298 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002299 {
paul1eb8ef22005-04-07 07:30:20 +00002300 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002301 {
2302 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2303 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2304 {
2305 filter = &peer->filter[afi][safi];
2306
paulfee0f4c2004-09-13 05:12:46 +00002307 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002308 {
2309 if (filter->map[direct].name)
2310 filter->map[direct].map =
2311 route_map_lookup_by_name (filter->map[direct].name);
2312 else
2313 filter->map[direct].map = NULL;
2314 }
2315
2316 if (filter->usmap.name)
2317 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2318 else
2319 filter->usmap.map = NULL;
2320 }
2321 }
paul1eb8ef22005-04-07 07:30:20 +00002322 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
paul718e3742002-12-13 20:15:29 +00002323 {
2324 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2325 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2326 {
2327 filter = &group->conf->filter[afi][safi];
2328
paulfee0f4c2004-09-13 05:12:46 +00002329 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002330 {
2331 if (filter->map[direct].name)
2332 filter->map[direct].map =
2333 route_map_lookup_by_name (filter->map[direct].name);
2334 else
2335 filter->map[direct].map = NULL;
2336 }
2337
2338 if (filter->usmap.name)
2339 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2340 else
2341 filter->usmap.map = NULL;
2342 }
2343 }
2344 }
2345
2346 /* For default-originate route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002347 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002348 {
paul1eb8ef22005-04-07 07:30:20 +00002349 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002350 {
2351 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2352 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2353 {
2354 if (peer->default_rmap[afi][safi].name)
2355 peer->default_rmap[afi][safi].map =
2356 route_map_lookup_by_name (peer->default_rmap[afi][safi].name);
2357 else
2358 peer->default_rmap[afi][safi].map = NULL;
2359 }
2360 }
2361 }
2362
2363 /* For network route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002364 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002365 {
2366 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2367 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2368 for (bn = bgp_table_top (bgp->route[afi][safi]); bn;
2369 bn = bgp_route_next (bn))
2370 if ((bgp_static = bn->info) != NULL)
2371 {
2372 if (bgp_static->rmap.name)
2373 bgp_static->rmap.map =
2374 route_map_lookup_by_name (bgp_static->rmap.name);
2375 else
2376 bgp_static->rmap.map = NULL;
2377 }
2378 }
2379
2380 /* For redistribute route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002381 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002382 {
2383 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2384 {
2385 if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)
2386 bgp->rmap[ZEBRA_FAMILY_IPV4][i].map =
2387 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);
2388#ifdef HAVE_IPV6
2389 if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)
2390 bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =
2391 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);
2392#endif /* HAVE_IPV6 */
2393 }
2394 }
2395}
2396
paulfee0f4c2004-09-13 05:12:46 +00002397DEFUN (match_peer,
2398 match_peer_cmd,
2399 "match peer (A.B.C.D|X:X::X:X)",
2400 MATCH_STR
2401 "Match peer address\n"
2402 "IPv6 address of peer\n"
2403 "IP address of peer\n")
2404{
2405 return bgp_route_match_add (vty, vty->index, "peer", argv[0]);
2406}
2407
2408DEFUN (match_peer_local,
2409 match_peer_local_cmd,
2410 "match peer local",
2411 MATCH_STR
2412 "Match peer address\n"
2413 "Static or Redistributed routes\n")
2414{
2415 return bgp_route_match_add (vty, vty->index, "peer", NULL);
2416}
2417
2418DEFUN (no_match_peer,
2419 no_match_peer_cmd,
2420 "no match peer",
2421 NO_STR
2422 MATCH_STR
2423 "Match peer address\n")
2424{
2425 if (argc == 0)
2426 return bgp_route_match_delete (vty, vty->index, "peer", NULL);
2427
2428 return bgp_route_match_delete (vty, vty->index, "peer", argv[0]);
2429}
2430
2431ALIAS (no_match_peer,
2432 no_match_peer_val_cmd,
2433 "no match peer (A.B.C.D|X:X::X:X)",
2434 NO_STR
2435 MATCH_STR
2436 "Match peer address\n"
2437 "IPv6 address of peer\n"
2438 "IP address of peer\n")
2439
2440ALIAS (no_match_peer,
2441 no_match_peer_local_cmd,
2442 "no match peer local",
2443 NO_STR
2444 MATCH_STR
2445 "Match peer address\n"
2446 "Static or Redistributed routes\n")
2447
paul718e3742002-12-13 20:15:29 +00002448DEFUN (match_ip_address,
2449 match_ip_address_cmd,
2450 "match ip address (<1-199>|<1300-2699>|WORD)",
2451 MATCH_STR
2452 IP_STR
2453 "Match address of route\n"
2454 "IP access-list number\n"
2455 "IP access-list number (expanded range)\n"
2456 "IP Access-list name\n")
2457{
2458 return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);
2459}
2460
2461DEFUN (no_match_ip_address,
2462 no_match_ip_address_cmd,
2463 "no match ip address",
2464 NO_STR
2465 MATCH_STR
2466 IP_STR
2467 "Match address of route\n")
2468{
2469 if (argc == 0)
2470 return bgp_route_match_delete (vty, vty->index, "ip address", NULL);
2471
2472 return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);
2473}
2474
2475ALIAS (no_match_ip_address,
2476 no_match_ip_address_val_cmd,
2477 "no match ip address (<1-199>|<1300-2699>|WORD)",
2478 NO_STR
2479 MATCH_STR
2480 IP_STR
2481 "Match address of route\n"
2482 "IP access-list number\n"
2483 "IP access-list number (expanded range)\n"
2484 "IP Access-list name\n")
2485
2486DEFUN (match_ip_next_hop,
2487 match_ip_next_hop_cmd,
2488 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
2489 MATCH_STR
2490 IP_STR
2491 "Match next-hop address of route\n"
2492 "IP access-list number\n"
2493 "IP access-list number (expanded range)\n"
2494 "IP Access-list name\n")
2495{
2496 return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
2497}
2498
2499DEFUN (no_match_ip_next_hop,
2500 no_match_ip_next_hop_cmd,
2501 "no match ip next-hop",
2502 NO_STR
2503 MATCH_STR
2504 IP_STR
2505 "Match next-hop address of route\n")
2506{
2507 if (argc == 0)
2508 return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
2509
2510 return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
2511}
2512
2513ALIAS (no_match_ip_next_hop,
2514 no_match_ip_next_hop_val_cmd,
2515 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2516 NO_STR
2517 MATCH_STR
2518 IP_STR
2519 "Match next-hop address of route\n"
2520 "IP access-list number\n"
2521 "IP access-list number (expanded range)\n"
2522 "IP Access-list name\n")
2523
Vyacheslav Trushkin1c8afb72011-11-22 20:15:10 +04002524/* match probability { */
2525
2526DEFUN (match_probability,
2527 match_probability_cmd,
2528 "match probability <0-100>",
2529 MATCH_STR
2530 "Match portion of routes defined by percentage value\n"
2531 "Percentage of routes\n")
2532{
2533 return bgp_route_match_add (vty, vty->index, "probability", argv[0]);
2534}
2535
2536DEFUN (no_match_probability,
2537 no_match_probability_cmd,
2538 "no match probability",
2539 NO_STR
2540 MATCH_STR
2541 "Match portion of routes defined by percentage value\n")
2542{
2543 return bgp_route_match_delete (vty, vty->index, "probability", argc ? argv[0] : NULL);
2544}
2545
2546ALIAS (no_match_probability,
2547 no_match_probability_val_cmd,
2548 "no match probability <1-99>",
2549 NO_STR
2550 MATCH_STR
2551 "Match portion of routes defined by percentage value\n"
2552 "Percentage of routes\n")
2553
2554/* } */
2555
hassoc1643bb2005-02-02 16:43:17 +00002556DEFUN (match_ip_route_source,
2557 match_ip_route_source_cmd,
2558 "match ip route-source (<1-199>|<1300-2699>|WORD)",
2559 MATCH_STR
2560 IP_STR
2561 "Match advertising source address of route\n"
2562 "IP access-list number\n"
2563 "IP access-list number (expanded range)\n"
2564 "IP standard access-list name\n")
2565{
2566 return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]);
2567}
2568
2569DEFUN (no_match_ip_route_source,
2570 no_match_ip_route_source_cmd,
2571 "no match ip route-source",
2572 NO_STR
2573 MATCH_STR
2574 IP_STR
2575 "Match advertising source address of route\n")
2576{
2577 if (argc == 0)
2578 return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL);
2579
2580 return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]);
2581}
2582
2583ALIAS (no_match_ip_route_source,
2584 no_match_ip_route_source_val_cmd,
2585 "no match ip route-source (<1-199>|<1300-2699>|WORD)",
2586 NO_STR
2587 MATCH_STR
2588 IP_STR
2589 "Match advertising source address of route\n"
2590 "IP access-list number\n"
2591 "IP access-list number (expanded range)\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002592 "IP standard access-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002593
paul718e3742002-12-13 20:15:29 +00002594DEFUN (match_ip_address_prefix_list,
2595 match_ip_address_prefix_list_cmd,
2596 "match ip address prefix-list WORD",
2597 MATCH_STR
2598 IP_STR
2599 "Match address of route\n"
2600 "Match entries of prefix-lists\n"
2601 "IP prefix-list name\n")
2602{
2603 return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
2604}
2605
2606DEFUN (no_match_ip_address_prefix_list,
2607 no_match_ip_address_prefix_list_cmd,
2608 "no match ip address prefix-list",
2609 NO_STR
2610 MATCH_STR
2611 IP_STR
2612 "Match address of route\n"
2613 "Match entries of prefix-lists\n")
2614{
2615 if (argc == 0)
2616 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
2617
2618 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
2619}
2620
2621ALIAS (no_match_ip_address_prefix_list,
2622 no_match_ip_address_prefix_list_val_cmd,
2623 "no match ip address prefix-list WORD",
2624 NO_STR
2625 MATCH_STR
2626 IP_STR
2627 "Match address of route\n"
2628 "Match entries of prefix-lists\n"
2629 "IP prefix-list name\n")
2630
2631DEFUN (match_ip_next_hop_prefix_list,
2632 match_ip_next_hop_prefix_list_cmd,
2633 "match ip next-hop prefix-list WORD",
2634 MATCH_STR
2635 IP_STR
2636 "Match next-hop address of route\n"
2637 "Match entries of prefix-lists\n"
2638 "IP prefix-list name\n")
2639{
2640 return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2641}
2642
2643DEFUN (no_match_ip_next_hop_prefix_list,
2644 no_match_ip_next_hop_prefix_list_cmd,
2645 "no match ip next-hop prefix-list",
2646 NO_STR
2647 MATCH_STR
2648 IP_STR
2649 "Match next-hop address of route\n"
2650 "Match entries of prefix-lists\n")
2651{
2652 if (argc == 0)
2653 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
2654
2655 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2656}
2657
2658ALIAS (no_match_ip_next_hop_prefix_list,
2659 no_match_ip_next_hop_prefix_list_val_cmd,
2660 "no match ip next-hop prefix-list WORD",
2661 NO_STR
2662 MATCH_STR
2663 IP_STR
2664 "Match next-hop address of route\n"
2665 "Match entries of prefix-lists\n"
2666 "IP prefix-list name\n")
2667
hassoc1643bb2005-02-02 16:43:17 +00002668DEFUN (match_ip_route_source_prefix_list,
2669 match_ip_route_source_prefix_list_cmd,
2670 "match ip route-source prefix-list WORD",
2671 MATCH_STR
2672 IP_STR
2673 "Match advertising source address of route\n"
2674 "Match entries of prefix-lists\n"
2675 "IP prefix-list name\n")
2676{
2677 return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]);
2678}
2679
2680DEFUN (no_match_ip_route_source_prefix_list,
2681 no_match_ip_route_source_prefix_list_cmd,
2682 "no match ip route-source prefix-list",
2683 NO_STR
2684 MATCH_STR
2685 IP_STR
2686 "Match advertising source address of route\n"
2687 "Match entries of prefix-lists\n")
2688{
2689 if (argc == 0)
2690 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL);
2691
2692 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]);
2693}
2694
2695ALIAS (no_match_ip_route_source_prefix_list,
2696 no_match_ip_route_source_prefix_list_val_cmd,
2697 "no match ip route-source prefix-list WORD",
2698 NO_STR
2699 MATCH_STR
2700 IP_STR
2701 "Match advertising source address of route\n"
2702 "Match entries of prefix-lists\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002703 "IP prefix-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002704
paul718e3742002-12-13 20:15:29 +00002705DEFUN (match_metric,
2706 match_metric_cmd,
2707 "match metric <0-4294967295>",
2708 MATCH_STR
2709 "Match metric of route\n"
2710 "Metric value\n")
2711{
2712 return bgp_route_match_add (vty, vty->index, "metric", argv[0]);
2713}
2714
2715DEFUN (no_match_metric,
2716 no_match_metric_cmd,
2717 "no match metric",
2718 NO_STR
2719 MATCH_STR
2720 "Match metric of route\n")
2721{
2722 if (argc == 0)
2723 return bgp_route_match_delete (vty, vty->index, "metric", NULL);
2724
2725 return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);
2726}
2727
2728ALIAS (no_match_metric,
2729 no_match_metric_val_cmd,
2730 "no match metric <0-4294967295>",
2731 NO_STR
2732 MATCH_STR
2733 "Match metric of route\n"
2734 "Metric value\n")
2735
2736DEFUN (match_community,
2737 match_community_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002738 "match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002739 MATCH_STR
2740 "Match BGP community list\n"
2741 "Community-list number (standard)\n"
2742 "Community-list number (expanded)\n"
2743 "Community-list name\n")
2744{
2745 return bgp_route_match_add (vty, vty->index, "community", argv[0]);
2746}
2747
2748DEFUN (match_community_exact,
2749 match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002750 "match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002751 MATCH_STR
2752 "Match BGP community list\n"
2753 "Community-list number (standard)\n"
2754 "Community-list number (expanded)\n"
2755 "Community-list name\n"
2756 "Do exact matching of communities\n")
2757{
2758 int ret;
2759 char *argstr;
2760
2761 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
2762 strlen (argv[0]) + strlen ("exact-match") + 2);
2763
2764 sprintf (argstr, "%s exact-match", argv[0]);
2765
2766 ret = bgp_route_match_add (vty, vty->index, "community", argstr);
2767
2768 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
2769
2770 return ret;
2771}
2772
2773DEFUN (no_match_community,
2774 no_match_community_cmd,
2775 "no match community",
2776 NO_STR
2777 MATCH_STR
2778 "Match BGP community list\n")
2779{
2780 return bgp_route_match_delete (vty, vty->index, "community", NULL);
2781}
2782
2783ALIAS (no_match_community,
2784 no_match_community_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002785 "no match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002786 NO_STR
2787 MATCH_STR
2788 "Match BGP community list\n"
2789 "Community-list number (standard)\n"
2790 "Community-list number (expanded)\n"
2791 "Community-list name\n")
2792
2793ALIAS (no_match_community,
2794 no_match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002795 "no match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002796 NO_STR
2797 MATCH_STR
2798 "Match BGP community list\n"
2799 "Community-list number (standard)\n"
2800 "Community-list number (expanded)\n"
2801 "Community-list name\n"
2802 "Do exact matching of communities\n")
2803
paul73ffb252003-04-19 15:49:49 +00002804DEFUN (match_ecommunity,
2805 match_ecommunity_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002806 "match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002807 MATCH_STR
2808 "Match BGP/VPN extended community list\n"
2809 "Extended community-list number (standard)\n"
2810 "Extended community-list number (expanded)\n"
2811 "Extended community-list name\n")
2812{
2813 return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]);
2814}
2815
2816DEFUN (no_match_ecommunity,
2817 no_match_ecommunity_cmd,
2818 "no match extcommunity",
2819 NO_STR
2820 MATCH_STR
2821 "Match BGP/VPN extended community list\n")
2822{
2823 return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL);
2824}
2825
2826ALIAS (no_match_ecommunity,
2827 no_match_ecommunity_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002828 "no match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002829 NO_STR
2830 MATCH_STR
2831 "Match BGP/VPN extended community list\n"
2832 "Extended community-list number (standard)\n"
2833 "Extended community-list number (expanded)\n"
2834 "Extended community-list name\n")
2835
paul718e3742002-12-13 20:15:29 +00002836DEFUN (match_aspath,
2837 match_aspath_cmd,
2838 "match as-path WORD",
2839 MATCH_STR
2840 "Match BGP AS path list\n"
2841 "AS path access-list name\n")
2842{
2843 return bgp_route_match_add (vty, vty->index, "as-path", argv[0]);
2844}
2845
2846DEFUN (no_match_aspath,
2847 no_match_aspath_cmd,
2848 "no match as-path",
2849 NO_STR
2850 MATCH_STR
2851 "Match BGP AS path list\n")
2852{
2853 return bgp_route_match_delete (vty, vty->index, "as-path", NULL);
2854}
2855
2856ALIAS (no_match_aspath,
2857 no_match_aspath_val_cmd,
2858 "no match as-path WORD",
2859 NO_STR
2860 MATCH_STR
2861 "Match BGP AS path list\n"
2862 "AS path access-list name\n")
2863
2864DEFUN (match_origin,
2865 match_origin_cmd,
2866 "match origin (egp|igp|incomplete)",
2867 MATCH_STR
2868 "BGP origin code\n"
2869 "remote EGP\n"
2870 "local IGP\n"
2871 "unknown heritage\n")
2872{
2873 if (strncmp (argv[0], "igp", 2) == 0)
2874 return bgp_route_match_add (vty, vty->index, "origin", "igp");
2875 if (strncmp (argv[0], "egp", 1) == 0)
2876 return bgp_route_match_add (vty, vty->index, "origin", "egp");
2877 if (strncmp (argv[0], "incomplete", 2) == 0)
2878 return bgp_route_match_add (vty, vty->index, "origin", "incomplete");
2879
2880 return CMD_WARNING;
2881}
2882
2883DEFUN (no_match_origin,
2884 no_match_origin_cmd,
2885 "no match origin",
2886 NO_STR
2887 MATCH_STR
2888 "BGP origin code\n")
2889{
2890 return bgp_route_match_delete (vty, vty->index, "origin", NULL);
2891}
2892
2893ALIAS (no_match_origin,
2894 no_match_origin_val_cmd,
2895 "no match origin (egp|igp|incomplete)",
2896 NO_STR
2897 MATCH_STR
2898 "BGP origin code\n"
2899 "remote EGP\n"
2900 "local IGP\n"
2901 "unknown heritage\n")
2902
2903DEFUN (set_ip_nexthop,
2904 set_ip_nexthop_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002905 "set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002906 SET_STR
2907 IP_STR
2908 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002909 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002910{
2911 union sockunion su;
2912 int ret;
2913
2914 ret = str2sockunion (argv[0], &su);
2915 if (ret < 0)
2916 {
2917 vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
2918 return CMD_WARNING;
2919 }
2920
2921 return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
2922}
2923
paulaf5cd0a2003-11-02 07:24:40 +00002924DEFUN (set_ip_nexthop_peer,
2925 set_ip_nexthop_peer_cmd,
2926 "set ip next-hop peer-address",
2927 SET_STR
2928 IP_STR
2929 "Next hop address\n"
2930 "Use peer address (for BGP only)\n")
2931{
2932 return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address");
2933}
2934
paul94f2b392005-06-28 12:44:16 +00002935DEFUN_DEPRECATED (no_set_ip_nexthop_peer,
paulaf5cd0a2003-11-02 07:24:40 +00002936 no_set_ip_nexthop_peer_cmd,
2937 "no set ip next-hop peer-address",
2938 NO_STR
2939 SET_STR
2940 IP_STR
2941 "Next hop address\n"
2942 "Use peer address (for BGP only)\n")
2943{
2944 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2945}
2946
2947
paul718e3742002-12-13 20:15:29 +00002948DEFUN (no_set_ip_nexthop,
2949 no_set_ip_nexthop_cmd,
2950 "no set ip next-hop",
2951 NO_STR
2952 SET_STR
paul718e3742002-12-13 20:15:29 +00002953 "Next hop address\n")
2954{
paulaf5cd0a2003-11-02 07:24:40 +00002955 if (argc == 0)
paul718e3742002-12-13 20:15:29 +00002956 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2957
2958 return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
2959}
2960
2961ALIAS (no_set_ip_nexthop,
2962 no_set_ip_nexthop_val_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002963 "no set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002964 NO_STR
2965 SET_STR
2966 IP_STR
2967 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002968 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002969
2970DEFUN (set_metric,
2971 set_metric_cmd,
paul73ffb252003-04-19 15:49:49 +00002972 "set metric <0-4294967295>",
paul718e3742002-12-13 20:15:29 +00002973 SET_STR
2974 "Metric value for destination routing protocol\n"
paul73ffb252003-04-19 15:49:49 +00002975 "Metric value\n")
paul718e3742002-12-13 20:15:29 +00002976{
2977 return bgp_route_set_add (vty, vty->index, "metric", argv[0]);
2978}
2979
paul73ffb252003-04-19 15:49:49 +00002980ALIAS (set_metric,
2981 set_metric_addsub_cmd,
2982 "set metric <+/-metric>",
2983 SET_STR
2984 "Metric value for destination routing protocol\n"
hasso033e8612005-05-28 04:50:54 +00002985 "Add or subtract metric\n")
paul73ffb252003-04-19 15:49:49 +00002986
paul718e3742002-12-13 20:15:29 +00002987DEFUN (no_set_metric,
2988 no_set_metric_cmd,
2989 "no set metric",
2990 NO_STR
2991 SET_STR
2992 "Metric value for destination routing protocol\n")
2993{
2994 if (argc == 0)
2995 return bgp_route_set_delete (vty, vty->index, "metric", NULL);
2996
2997 return bgp_route_set_delete (vty, vty->index, "metric", argv[0]);
2998}
2999
3000ALIAS (no_set_metric,
3001 no_set_metric_val_cmd,
3002 "no set metric <0-4294967295>",
3003 NO_STR
3004 SET_STR
3005 "Metric value for destination routing protocol\n"
3006 "Metric value\n")
3007
3008DEFUN (set_local_pref,
3009 set_local_pref_cmd,
3010 "set local-preference <0-4294967295>",
3011 SET_STR
3012 "BGP local preference path attribute\n"
3013 "Preference value\n")
3014{
3015 return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]);
3016}
3017
3018DEFUN (no_set_local_pref,
3019 no_set_local_pref_cmd,
3020 "no set local-preference",
3021 NO_STR
3022 SET_STR
3023 "BGP local preference path attribute\n")
3024{
3025 if (argc == 0)
3026 return bgp_route_set_delete (vty, vty->index, "local-preference", NULL);
3027
3028 return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]);
3029}
3030
3031ALIAS (no_set_local_pref,
3032 no_set_local_pref_val_cmd,
3033 "no set local-preference <0-4294967295>",
3034 NO_STR
3035 SET_STR
3036 "BGP local preference path attribute\n"
3037 "Preference value\n")
3038
3039DEFUN (set_weight,
3040 set_weight_cmd,
3041 "set weight <0-4294967295>",
3042 SET_STR
3043 "BGP weight for routing table\n"
3044 "Weight value\n")
3045{
3046 return bgp_route_set_add (vty, vty->index, "weight", argv[0]);
3047}
3048
3049DEFUN (no_set_weight,
3050 no_set_weight_cmd,
3051 "no set weight",
3052 NO_STR
3053 SET_STR
3054 "BGP weight for routing table\n")
3055{
3056 if (argc == 0)
3057 return bgp_route_set_delete (vty, vty->index, "weight", NULL);
3058
3059 return bgp_route_set_delete (vty, vty->index, "weight", argv[0]);
3060}
3061
3062ALIAS (no_set_weight,
3063 no_set_weight_val_cmd,
3064 "no set weight <0-4294967295>",
3065 NO_STR
3066 SET_STR
3067 "BGP weight for routing table\n"
3068 "Weight value\n")
3069
3070DEFUN (set_aspath_prepend,
3071 set_aspath_prepend_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003072 "set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003073 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003074 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003075 "Prepend to the as-path\n"
3076 "AS number\n")
3077{
3078 int ret;
3079 char *str;
3080
3081 str = argv_concat (argv, argc, 0);
3082 ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str);
3083 XFREE (MTYPE_TMP, str);
3084
3085 return ret;
3086}
3087
3088DEFUN (no_set_aspath_prepend,
3089 no_set_aspath_prepend_cmd,
3090 "no set as-path prepend",
3091 NO_STR
3092 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003093 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003094 "Prepend to the as-path\n")
3095{
Denis Ovsienkoa7f93f32007-12-18 15:13:06 +00003096 int ret;
3097 char *str;
3098
3099 if (argc == 0)
3100 return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL);
3101
3102 str = argv_concat (argv, argc, 0);
3103 ret = bgp_route_set_delete (vty, vty->index, "as-path prepend", str);
3104 XFREE (MTYPE_TMP, str);
3105 return ret;
paul718e3742002-12-13 20:15:29 +00003106}
3107
3108ALIAS (no_set_aspath_prepend,
3109 no_set_aspath_prepend_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003110 "no set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003111 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 "AS number\n")
3116
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003117DEFUN (set_aspath_exclude,
3118 set_aspath_exclude_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003119 "set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003120 SET_STR
3121 "Transform BGP AS-path attribute\n"
3122 "Exclude from the as-path\n"
3123 "AS number\n")
3124{
3125 int ret;
3126 char *str;
3127
3128 str = argv_concat (argv, argc, 0);
3129 ret = bgp_route_set_add (vty, vty->index, "as-path exclude", str);
3130 XFREE (MTYPE_TMP, str);
3131 return ret;
3132}
3133
3134DEFUN (no_set_aspath_exclude,
3135 no_set_aspath_exclude_cmd,
3136 "no set as-path exclude",
3137 NO_STR
3138 SET_STR
3139 "Transform BGP AS_PATH attribute\n"
3140 "Exclude from the as-path\n")
3141{
3142 int ret;
3143 char *str;
3144
3145 if (argc == 0)
3146 return bgp_route_set_delete (vty, vty->index, "as-path exclude", NULL);
3147
3148 str = argv_concat (argv, argc, 0);
3149 ret = bgp_route_set_delete (vty, vty->index, "as-path exclude", str);
3150 XFREE (MTYPE_TMP, str);
3151 return ret;
3152}
3153
3154ALIAS (no_set_aspath_exclude,
3155 no_set_aspath_exclude_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003156 "no set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003157 NO_STR
3158 SET_STR
3159 "Transform BGP AS_PATH attribute\n"
3160 "Exclude from the as-path\n"
3161 "AS number\n")
3162
paul718e3742002-12-13 20:15:29 +00003163DEFUN (set_community,
3164 set_community_cmd,
3165 "set community .AA:NN",
3166 SET_STR
3167 "BGP community attribute\n"
3168 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3169{
3170 int i;
3171 int first = 0;
3172 int additive = 0;
3173 struct buffer *b;
3174 struct community *com = NULL;
3175 char *str;
3176 char *argstr;
3177 int ret;
3178
3179 b = buffer_new (1024);
3180
3181 for (i = 0; i < argc; i++)
3182 {
3183 if (strncmp (argv[i], "additive", strlen (argv[i])) == 0)
3184 {
3185 additive = 1;
3186 continue;
3187 }
3188
3189 if (first)
3190 buffer_putc (b, ' ');
3191 else
3192 first = 1;
3193
3194 if (strncmp (argv[i], "internet", strlen (argv[i])) == 0)
3195 {
3196 buffer_putstr (b, "internet");
3197 continue;
3198 }
3199 if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0)
3200 {
3201 buffer_putstr (b, "local-AS");
3202 continue;
3203 }
3204 if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0
3205 && strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0)
3206 {
3207 buffer_putstr (b, "no-advertise");
3208 continue;
3209 }
3210 if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0
3211 && strncmp (argv[i], "no-export", strlen (argv[i])) == 0)
3212 {
3213 buffer_putstr (b, "no-export");
3214 continue;
3215 }
3216 buffer_putstr (b, argv[i]);
3217 }
3218 buffer_putc (b, '\0');
3219
3220 /* Fetch result string then compile it to communities attribute. */
3221 str = buffer_getstr (b);
3222 buffer_free (b);
3223
3224 if (str)
3225 {
3226 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00003227 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00003228 }
3229
3230 /* Can't compile user input into communities attribute. */
3231 if (! com)
3232 {
3233 vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE);
3234 return CMD_WARNING;
3235 }
3236
3237 /* Set communites attribute string. */
3238 str = community_str (com);
3239
3240 if (additive)
3241 {
3242 argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1);
3243 strcpy (argstr, str);
3244 strcpy (argstr + strlen (str), " additive");
3245 ret = bgp_route_set_add (vty, vty->index, "community", argstr);
3246 XFREE (MTYPE_TMP, argstr);
3247 }
3248 else
3249 ret = bgp_route_set_add (vty, vty->index, "community", str);
3250
3251 community_free (com);
3252
3253 return ret;
3254}
3255
3256DEFUN (set_community_none,
3257 set_community_none_cmd,
3258 "set community none",
3259 SET_STR
3260 "BGP community attribute\n"
3261 "No community attribute\n")
3262{
3263 return bgp_route_set_add (vty, vty->index, "community", "none");
3264}
3265
3266DEFUN (no_set_community,
3267 no_set_community_cmd,
3268 "no set community",
3269 NO_STR
3270 SET_STR
3271 "BGP community attribute\n")
3272{
3273 return bgp_route_set_delete (vty, vty->index, "community", NULL);
3274}
3275
3276ALIAS (no_set_community,
3277 no_set_community_val_cmd,
3278 "no set community .AA:NN",
3279 NO_STR
3280 SET_STR
3281 "BGP community attribute\n"
3282 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3283
3284ALIAS (no_set_community,
3285 no_set_community_none_cmd,
3286 "no set community none",
3287 NO_STR
3288 SET_STR
3289 "BGP community attribute\n"
3290 "No community attribute\n")
3291
3292DEFUN (set_community_delete,
3293 set_community_delete_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003294 "set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003295 SET_STR
3296 "set BGP community list (for deletion)\n"
3297 "Community-list number (standard)\n"
3298 "Communitly-list number (expanded)\n"
3299 "Community-list name\n"
3300 "Delete matching communities\n")
3301{
3302 char *str;
3303
3304 str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1);
3305 strcpy (str, argv[0]);
3306 strcpy (str + strlen (argv[0]), " delete");
3307
3308 bgp_route_set_add (vty, vty->index, "comm-list", str);
3309
3310 XFREE (MTYPE_TMP, str);
3311 return CMD_SUCCESS;
3312}
3313
3314DEFUN (no_set_community_delete,
3315 no_set_community_delete_cmd,
3316 "no set comm-list",
3317 NO_STR
3318 SET_STR
3319 "set BGP community list (for deletion)\n")
3320{
3321 return bgp_route_set_delete (vty, vty->index, "comm-list", NULL);
3322}
3323
3324ALIAS (no_set_community_delete,
3325 no_set_community_delete_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003326 "no set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003327 NO_STR
3328 SET_STR
3329 "set BGP community list (for deletion)\n"
3330 "Community-list number (standard)\n"
3331 "Communitly-list number (expanded)\n"
3332 "Community-list name\n"
3333 "Delete matching communities\n")
3334
3335DEFUN (set_ecommunity_rt,
3336 set_ecommunity_rt_cmd,
3337 "set extcommunity rt .ASN:nn_or_IP-address:nn",
3338 SET_STR
3339 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003340 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003341 "VPN extended community\n")
3342{
3343 int ret;
3344 char *str;
3345
3346 str = argv_concat (argv, argc, 0);
3347 ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str);
3348 XFREE (MTYPE_TMP, str);
3349
3350 return ret;
3351}
3352
3353DEFUN (no_set_ecommunity_rt,
3354 no_set_ecommunity_rt_cmd,
3355 "no set extcommunity rt",
3356 NO_STR
3357 SET_STR
3358 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003359 "Route Target extended community\n")
paul718e3742002-12-13 20:15:29 +00003360{
3361 return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL);
3362}
3363
3364ALIAS (no_set_ecommunity_rt,
3365 no_set_ecommunity_rt_val_cmd,
3366 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
3367 NO_STR
3368 SET_STR
3369 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003370 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003371 "VPN extended community\n")
3372
3373DEFUN (set_ecommunity_soo,
3374 set_ecommunity_soo_cmd,
3375 "set extcommunity soo .ASN:nn_or_IP-address:nn",
3376 SET_STR
3377 "BGP extended community attribute\n"
3378 "Site-of-Origin extended community\n"
3379 "VPN extended community\n")
3380{
3381 int ret;
3382 char *str;
3383
3384 str = argv_concat (argv, argc, 0);
3385 ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str);
3386 XFREE (MTYPE_TMP, str);
3387 return ret;
3388}
3389
3390DEFUN (no_set_ecommunity_soo,
3391 no_set_ecommunity_soo_cmd,
3392 "no set extcommunity soo",
3393 NO_STR
3394 SET_STR
3395 "BGP extended community attribute\n"
3396 "Site-of-Origin extended community\n")
3397{
3398 return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL);
3399}
3400
3401ALIAS (no_set_ecommunity_soo,
3402 no_set_ecommunity_soo_val_cmd,
3403 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
3404 NO_STR
3405 SET_STR
3406 "BGP extended community attribute\n"
3407 "Site-of-Origin extended community\n"
3408 "VPN extended community\n")
3409
3410DEFUN (set_origin,
3411 set_origin_cmd,
3412 "set origin (egp|igp|incomplete)",
3413 SET_STR
3414 "BGP origin code\n"
3415 "remote EGP\n"
3416 "local IGP\n"
3417 "unknown heritage\n")
3418{
3419 if (strncmp (argv[0], "igp", 2) == 0)
3420 return bgp_route_set_add (vty, vty->index, "origin", "igp");
3421 if (strncmp (argv[0], "egp", 1) == 0)
3422 return bgp_route_set_add (vty, vty->index, "origin", "egp");
3423 if (strncmp (argv[0], "incomplete", 2) == 0)
3424 return bgp_route_set_add (vty, vty->index, "origin", "incomplete");
3425
3426 return CMD_WARNING;
3427}
3428
3429DEFUN (no_set_origin,
3430 no_set_origin_cmd,
3431 "no set origin",
3432 NO_STR
3433 SET_STR
3434 "BGP origin code\n")
3435{
3436 return bgp_route_set_delete (vty, vty->index, "origin", NULL);
3437}
3438
3439ALIAS (no_set_origin,
3440 no_set_origin_val_cmd,
3441 "no set origin (egp|igp|incomplete)",
3442 NO_STR
3443 SET_STR
3444 "BGP origin code\n"
3445 "remote EGP\n"
3446 "local IGP\n"
3447 "unknown heritage\n")
3448
3449DEFUN (set_atomic_aggregate,
3450 set_atomic_aggregate_cmd,
3451 "set atomic-aggregate",
3452 SET_STR
3453 "BGP atomic aggregate attribute\n" )
3454{
3455 return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL);
3456}
3457
3458DEFUN (no_set_atomic_aggregate,
3459 no_set_atomic_aggregate_cmd,
3460 "no set atomic-aggregate",
3461 NO_STR
3462 SET_STR
3463 "BGP atomic aggregate attribute\n" )
3464{
3465 return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL);
3466}
3467
3468DEFUN (set_aggregator_as,
3469 set_aggregator_as_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003470 "set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003471 SET_STR
3472 "BGP aggregator attribute\n"
3473 "AS number of aggregator\n"
3474 "AS number\n"
3475 "IP address of aggregator\n")
3476{
3477 int ret;
3478 as_t as;
3479 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003480 char *argstr;
3481
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003482 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paulfd79ac92004-10-13 05:06:08 +00003483
paul718e3742002-12-13 20:15:29 +00003484 ret = inet_aton (argv[1], &address);
3485 if (ret == 0)
3486 {
3487 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3488 return CMD_WARNING;
3489 }
3490
3491 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3492 strlen (argv[0]) + strlen (argv[1]) + 2);
3493
3494 sprintf (argstr, "%s %s", argv[0], argv[1]);
3495
3496 ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr);
3497
3498 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3499
3500 return ret;
3501}
3502
3503DEFUN (no_set_aggregator_as,
3504 no_set_aggregator_as_cmd,
3505 "no set aggregator as",
3506 NO_STR
3507 SET_STR
3508 "BGP aggregator attribute\n"
3509 "AS number of aggregator\n")
3510{
3511 int ret;
3512 as_t as;
3513 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003514 char *argstr;
3515
3516 if (argv == 0)
3517 return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL);
3518
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003519 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paul718e3742002-12-13 20:15:29 +00003520
3521 ret = inet_aton (argv[1], &address);
3522 if (ret == 0)
3523 {
3524 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3525 return CMD_WARNING;
3526 }
3527
3528 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3529 strlen (argv[0]) + strlen (argv[1]) + 2);
3530
3531 sprintf (argstr, "%s %s", argv[0], argv[1]);
3532
3533 ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr);
3534
3535 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3536
3537 return ret;
3538}
3539
3540ALIAS (no_set_aggregator_as,
3541 no_set_aggregator_as_val_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003542 "no set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003543 NO_STR
3544 SET_STR
3545 "BGP aggregator attribute\n"
3546 "AS number of aggregator\n"
3547 "AS number\n"
3548 "IP address of aggregator\n")
3549
3550
3551#ifdef HAVE_IPV6
3552DEFUN (match_ipv6_address,
3553 match_ipv6_address_cmd,
3554 "match ipv6 address WORD",
3555 MATCH_STR
3556 IPV6_STR
3557 "Match IPv6 address of route\n"
3558 "IPv6 access-list name\n")
3559{
3560 return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]);
3561}
3562
3563DEFUN (no_match_ipv6_address,
3564 no_match_ipv6_address_cmd,
3565 "no match ipv6 address WORD",
3566 NO_STR
3567 MATCH_STR
3568 IPV6_STR
3569 "Match IPv6 address of route\n"
3570 "IPv6 access-list name\n")
3571{
3572 return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]);
3573}
3574
3575DEFUN (match_ipv6_next_hop,
3576 match_ipv6_next_hop_cmd,
3577 "match ipv6 next-hop X:X::X:X",
3578 MATCH_STR
3579 IPV6_STR
3580 "Match IPv6 next-hop address of route\n"
3581 "IPv6 address of next hop\n")
3582{
3583 return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]);
3584}
3585
3586DEFUN (no_match_ipv6_next_hop,
3587 no_match_ipv6_next_hop_cmd,
3588 "no match ipv6 next-hop X:X::X:X",
3589 NO_STR
3590 MATCH_STR
3591 IPV6_STR
3592 "Match IPv6 next-hop address of route\n"
3593 "IPv6 address of next hop\n")
3594{
3595 return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
3596}
3597
3598DEFUN (match_ipv6_address_prefix_list,
3599 match_ipv6_address_prefix_list_cmd,
3600 "match ipv6 address prefix-list WORD",
3601 MATCH_STR
3602 IPV6_STR
3603 "Match address of route\n"
3604 "Match entries of prefix-lists\n"
3605 "IP prefix-list name\n")
3606{
3607 return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3608}
3609
3610DEFUN (no_match_ipv6_address_prefix_list,
3611 no_match_ipv6_address_prefix_list_cmd,
3612 "no match ipv6 address prefix-list WORD",
3613 NO_STR
3614 MATCH_STR
3615 IPV6_STR
3616 "Match address of route\n"
3617 "Match entries of prefix-lists\n"
3618 "IP prefix-list name\n")
3619{
3620 return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3621}
3622
3623DEFUN (set_ipv6_nexthop_global,
3624 set_ipv6_nexthop_global_cmd,
3625 "set ipv6 next-hop global X:X::X:X",
3626 SET_STR
3627 IPV6_STR
3628 "IPv6 next-hop address\n"
3629 "IPv6 global address\n"
3630 "IPv6 address of next hop\n")
3631{
3632 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]);
3633}
3634
3635DEFUN (no_set_ipv6_nexthop_global,
3636 no_set_ipv6_nexthop_global_cmd,
3637 "no set ipv6 next-hop global",
3638 NO_STR
3639 SET_STR
3640 IPV6_STR
3641 "IPv6 next-hop address\n"
3642 "IPv6 global address\n")
3643{
3644 if (argc == 0)
3645 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL);
3646
3647 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]);
3648}
3649
3650ALIAS (no_set_ipv6_nexthop_global,
3651 no_set_ipv6_nexthop_global_val_cmd,
3652 "no set ipv6 next-hop global X:X::X:X",
3653 NO_STR
3654 SET_STR
3655 IPV6_STR
3656 "IPv6 next-hop address\n"
3657 "IPv6 global address\n"
3658 "IPv6 address of next hop\n")
3659
3660DEFUN (set_ipv6_nexthop_local,
3661 set_ipv6_nexthop_local_cmd,
3662 "set ipv6 next-hop local X:X::X:X",
3663 SET_STR
3664 IPV6_STR
3665 "IPv6 next-hop address\n"
3666 "IPv6 local address\n"
3667 "IPv6 address of next hop\n")
3668{
3669 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
3670}
3671
3672DEFUN (no_set_ipv6_nexthop_local,
3673 no_set_ipv6_nexthop_local_cmd,
3674 "no set ipv6 next-hop local",
3675 NO_STR
3676 SET_STR
3677 IPV6_STR
3678 "IPv6 next-hop address\n"
3679 "IPv6 local address\n")
3680{
3681 if (argc == 0)
3682 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
3683
3684 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
3685}
3686
3687ALIAS (no_set_ipv6_nexthop_local,
3688 no_set_ipv6_nexthop_local_val_cmd,
3689 "no set ipv6 next-hop local X:X::X:X",
3690 NO_STR
3691 SET_STR
3692 IPV6_STR
3693 "IPv6 next-hop address\n"
3694 "IPv6 local address\n"
3695 "IPv6 address of next hop\n")
3696#endif /* HAVE_IPV6 */
3697
3698DEFUN (set_vpnv4_nexthop,
3699 set_vpnv4_nexthop_cmd,
3700 "set vpnv4 next-hop A.B.C.D",
3701 SET_STR
3702 "VPNv4 information\n"
3703 "VPNv4 next-hop address\n"
3704 "IP address of next hop\n")
3705{
3706 return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]);
3707}
3708
3709DEFUN (no_set_vpnv4_nexthop,
3710 no_set_vpnv4_nexthop_cmd,
3711 "no set vpnv4 next-hop",
3712 NO_STR
3713 SET_STR
3714 "VPNv4 information\n"
3715 "VPNv4 next-hop address\n")
3716{
3717 if (argc == 0)
3718 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL);
3719
3720 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]);
3721}
3722
3723ALIAS (no_set_vpnv4_nexthop,
3724 no_set_vpnv4_nexthop_val_cmd,
3725 "no set vpnv4 next-hop A.B.C.D",
3726 NO_STR
3727 SET_STR
3728 "VPNv4 information\n"
3729 "VPNv4 next-hop address\n"
3730 "IP address of next hop\n")
3731
3732DEFUN (set_originator_id,
3733 set_originator_id_cmd,
3734 "set originator-id A.B.C.D",
3735 SET_STR
3736 "BGP originator ID attribute\n"
3737 "IP address of originator\n")
3738{
3739 return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]);
3740}
3741
3742DEFUN (no_set_originator_id,
3743 no_set_originator_id_cmd,
3744 "no set originator-id",
3745 NO_STR
3746 SET_STR
3747 "BGP originator ID attribute\n")
3748{
3749 if (argc == 0)
3750 return bgp_route_set_delete (vty, vty->index, "originator-id", NULL);
3751
3752 return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]);
3753}
3754
3755ALIAS (no_set_originator_id,
3756 no_set_originator_id_val_cmd,
3757 "no set originator-id A.B.C.D",
3758 NO_STR
3759 SET_STR
3760 "BGP originator ID attribute\n"
3761 "IP address of originator\n")
3762
Paul Jakmae70e5752011-07-05 00:41:59 +04003763DEFUN_DEPRECATED (set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003764 set_pathlimit_ttl_cmd,
3765 "set pathlimit ttl <1-255>",
3766 SET_STR
3767 "BGP AS-Pathlimit attribute\n"
3768 "Set AS-Path Hop-count TTL\n")
3769{
Paul Jakmae70e5752011-07-05 00:41:59 +04003770 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003771}
3772
Paul Jakmae70e5752011-07-05 00:41:59 +04003773DEFUN_DEPRECATED (no_set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003774 no_set_pathlimit_ttl_cmd,
3775 "no set pathlimit ttl",
3776 NO_STR
3777 SET_STR
3778 "BGP AS-Pathlimit attribute\n"
3779 "Set AS-Path Hop-count TTL\n")
3780{
Paul Jakmae70e5752011-07-05 00:41:59 +04003781 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003782}
3783
3784ALIAS (no_set_pathlimit_ttl,
3785 no_set_pathlimit_ttl_val_cmd,
3786 "no set pathlimit ttl <1-255>",
3787 NO_STR
3788 MATCH_STR
3789 "BGP AS-Pathlimit attribute\n"
3790 "Set AS-Path Hop-count TTL\n")
3791
Paul Jakmae70e5752011-07-05 00:41:59 +04003792DEFUN_DEPRECATED (match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003793 match_pathlimit_as_cmd,
3794 "match pathlimit as <1-65535>",
3795 MATCH_STR
3796 "BGP AS-Pathlimit attribute\n"
3797 "Match Pathlimit AS number\n")
3798{
Paul Jakmae70e5752011-07-05 00:41:59 +04003799 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003800}
3801
Paul Jakmae70e5752011-07-05 00:41:59 +04003802DEFUN_DEPRECATED (no_match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003803 no_match_pathlimit_as_cmd,
3804 "no match pathlimit as",
3805 NO_STR
3806 MATCH_STR
3807 "BGP AS-Pathlimit attribute\n"
3808 "Match Pathlimit AS number\n")
3809{
Paul Jakmae70e5752011-07-05 00:41:59 +04003810 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003811}
3812
3813ALIAS (no_match_pathlimit_as,
3814 no_match_pathlimit_as_val_cmd,
3815 "no match pathlimit as <1-65535>",
3816 NO_STR
3817 MATCH_STR
3818 "BGP AS-Pathlimit attribute\n"
3819 "Match Pathlimit ASN\n")
3820
paul718e3742002-12-13 20:15:29 +00003821
3822/* Initialization of route map. */
3823void
paul94f2b392005-06-28 12:44:16 +00003824bgp_route_map_init (void)
paul718e3742002-12-13 20:15:29 +00003825{
3826 route_map_init ();
3827 route_map_init_vty ();
3828 route_map_add_hook (bgp_route_map_update);
3829 route_map_delete_hook (bgp_route_map_update);
3830
paulfee0f4c2004-09-13 05:12:46 +00003831 route_map_install_match (&route_match_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003832 route_map_install_match (&route_match_ip_address_cmd);
3833 route_map_install_match (&route_match_ip_next_hop_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003834 route_map_install_match (&route_match_ip_route_source_cmd);
paul718e3742002-12-13 20:15:29 +00003835 route_map_install_match (&route_match_ip_address_prefix_list_cmd);
3836 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003837 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +00003838 route_map_install_match (&route_match_aspath_cmd);
3839 route_map_install_match (&route_match_community_cmd);
paul73ffb252003-04-19 15:49:49 +00003840 route_map_install_match (&route_match_ecommunity_cmd);
paul718e3742002-12-13 20:15:29 +00003841 route_map_install_match (&route_match_metric_cmd);
3842 route_map_install_match (&route_match_origin_cmd);
Vyacheslav Trushkin1c8afb72011-11-22 20:15:10 +04003843 route_map_install_match (&route_match_probability_cmd);
paul718e3742002-12-13 20:15:29 +00003844
3845 route_map_install_set (&route_set_ip_nexthop_cmd);
3846 route_map_install_set (&route_set_local_pref_cmd);
3847 route_map_install_set (&route_set_weight_cmd);
3848 route_map_install_set (&route_set_metric_cmd);
3849 route_map_install_set (&route_set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003850 route_map_install_set (&route_set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003851 route_map_install_set (&route_set_origin_cmd);
3852 route_map_install_set (&route_set_atomic_aggregate_cmd);
3853 route_map_install_set (&route_set_aggregator_as_cmd);
3854 route_map_install_set (&route_set_community_cmd);
3855 route_map_install_set (&route_set_community_delete_cmd);
3856 route_map_install_set (&route_set_vpnv4_nexthop_cmd);
3857 route_map_install_set (&route_set_originator_id_cmd);
3858 route_map_install_set (&route_set_ecommunity_rt_cmd);
3859 route_map_install_set (&route_set_ecommunity_soo_cmd);
3860
paulfee0f4c2004-09-13 05:12:46 +00003861 install_element (RMAP_NODE, &match_peer_cmd);
3862 install_element (RMAP_NODE, &match_peer_local_cmd);
3863 install_element (RMAP_NODE, &no_match_peer_cmd);
3864 install_element (RMAP_NODE, &no_match_peer_val_cmd);
3865 install_element (RMAP_NODE, &no_match_peer_local_cmd);
paul718e3742002-12-13 20:15:29 +00003866 install_element (RMAP_NODE, &match_ip_address_cmd);
3867 install_element (RMAP_NODE, &no_match_ip_address_cmd);
3868 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
3869 install_element (RMAP_NODE, &match_ip_next_hop_cmd);
3870 install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
3871 install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003872 install_element (RMAP_NODE, &match_ip_route_source_cmd);
3873 install_element (RMAP_NODE, &no_match_ip_route_source_cmd);
3874 install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd);
paul718e3742002-12-13 20:15:29 +00003875 install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
3876 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
3877 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
3878 install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
3879 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
3880 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003881 install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
3882 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
3883 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd);
paul718e3742002-12-13 20:15:29 +00003884
3885 install_element (RMAP_NODE, &match_aspath_cmd);
3886 install_element (RMAP_NODE, &no_match_aspath_cmd);
3887 install_element (RMAP_NODE, &no_match_aspath_val_cmd);
3888 install_element (RMAP_NODE, &match_metric_cmd);
3889 install_element (RMAP_NODE, &no_match_metric_cmd);
3890 install_element (RMAP_NODE, &no_match_metric_val_cmd);
3891 install_element (RMAP_NODE, &match_community_cmd);
3892 install_element (RMAP_NODE, &match_community_exact_cmd);
3893 install_element (RMAP_NODE, &no_match_community_cmd);
3894 install_element (RMAP_NODE, &no_match_community_val_cmd);
3895 install_element (RMAP_NODE, &no_match_community_exact_cmd);
paul73ffb252003-04-19 15:49:49 +00003896 install_element (RMAP_NODE, &match_ecommunity_cmd);
3897 install_element (RMAP_NODE, &no_match_ecommunity_cmd);
3898 install_element (RMAP_NODE, &no_match_ecommunity_val_cmd);
paul718e3742002-12-13 20:15:29 +00003899 install_element (RMAP_NODE, &match_origin_cmd);
3900 install_element (RMAP_NODE, &no_match_origin_cmd);
3901 install_element (RMAP_NODE, &no_match_origin_val_cmd);
Vyacheslav Trushkin1c8afb72011-11-22 20:15:10 +04003902 install_element (RMAP_NODE, &match_probability_cmd);
3903 install_element (RMAP_NODE, &no_match_probability_cmd);
3904 install_element (RMAP_NODE, &no_match_probability_val_cmd);
paul718e3742002-12-13 20:15:29 +00003905
3906 install_element (RMAP_NODE, &set_ip_nexthop_cmd);
paulaf5cd0a2003-11-02 07:24:40 +00003907 install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003908 install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
3909 install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
3910 install_element (RMAP_NODE, &set_local_pref_cmd);
3911 install_element (RMAP_NODE, &no_set_local_pref_cmd);
3912 install_element (RMAP_NODE, &no_set_local_pref_val_cmd);
3913 install_element (RMAP_NODE, &set_weight_cmd);
3914 install_element (RMAP_NODE, &no_set_weight_cmd);
3915 install_element (RMAP_NODE, &no_set_weight_val_cmd);
3916 install_element (RMAP_NODE, &set_metric_cmd);
paul73ffb252003-04-19 15:49:49 +00003917 install_element (RMAP_NODE, &set_metric_addsub_cmd);
paul718e3742002-12-13 20:15:29 +00003918 install_element (RMAP_NODE, &no_set_metric_cmd);
3919 install_element (RMAP_NODE, &no_set_metric_val_cmd);
3920 install_element (RMAP_NODE, &set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003921 install_element (RMAP_NODE, &set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003922 install_element (RMAP_NODE, &no_set_aspath_prepend_cmd);
3923 install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003924 install_element (RMAP_NODE, &no_set_aspath_exclude_cmd);
3925 install_element (RMAP_NODE, &no_set_aspath_exclude_val_cmd);
paul718e3742002-12-13 20:15:29 +00003926 install_element (RMAP_NODE, &set_origin_cmd);
3927 install_element (RMAP_NODE, &no_set_origin_cmd);
3928 install_element (RMAP_NODE, &no_set_origin_val_cmd);
3929 install_element (RMAP_NODE, &set_atomic_aggregate_cmd);
3930 install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd);
3931 install_element (RMAP_NODE, &set_aggregator_as_cmd);
3932 install_element (RMAP_NODE, &no_set_aggregator_as_cmd);
3933 install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd);
3934 install_element (RMAP_NODE, &set_community_cmd);
3935 install_element (RMAP_NODE, &set_community_none_cmd);
3936 install_element (RMAP_NODE, &no_set_community_cmd);
3937 install_element (RMAP_NODE, &no_set_community_val_cmd);
3938 install_element (RMAP_NODE, &no_set_community_none_cmd);
3939 install_element (RMAP_NODE, &set_community_delete_cmd);
3940 install_element (RMAP_NODE, &no_set_community_delete_cmd);
3941 install_element (RMAP_NODE, &no_set_community_delete_val_cmd);
3942 install_element (RMAP_NODE, &set_ecommunity_rt_cmd);
3943 install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd);
3944 install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd);
3945 install_element (RMAP_NODE, &set_ecommunity_soo_cmd);
3946 install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd);
3947 install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd);
3948 install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd);
3949 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd);
3950 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd);
3951 install_element (RMAP_NODE, &set_originator_id_cmd);
3952 install_element (RMAP_NODE, &no_set_originator_id_cmd);
3953 install_element (RMAP_NODE, &no_set_originator_id_val_cmd);
3954
3955#ifdef HAVE_IPV6
3956 route_map_install_match (&route_match_ipv6_address_cmd);
3957 route_map_install_match (&route_match_ipv6_next_hop_cmd);
3958 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd);
3959 route_map_install_set (&route_set_ipv6_nexthop_global_cmd);
3960 route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
Paul Jakma41367172007-08-06 15:24:51 +00003961
paul718e3742002-12-13 20:15:29 +00003962 install_element (RMAP_NODE, &match_ipv6_address_cmd);
3963 install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
3964 install_element (RMAP_NODE, &match_ipv6_next_hop_cmd);
3965 install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd);
3966 install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
3967 install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
3968 install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd);
3969 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
3970 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd);
3971 install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
3972 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
3973 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
3974#endif /* HAVE_IPV6 */
Paul Jakma41367172007-08-06 15:24:51 +00003975
Paul Jakmae70e5752011-07-05 00:41:59 +04003976 /* AS-Pathlimit: functionality removed, commands kept for
3977 * compatibility.
3978 */
Paul Jakma41367172007-08-06 15:24:51 +00003979 install_element (RMAP_NODE, &set_pathlimit_ttl_cmd);
3980 install_element (RMAP_NODE, &no_set_pathlimit_ttl_cmd);
3981 install_element (RMAP_NODE, &no_set_pathlimit_ttl_val_cmd);
3982 install_element (RMAP_NODE, &match_pathlimit_as_cmd);
3983 install_element (RMAP_NODE, &no_match_pathlimit_as_cmd);
3984 install_element (RMAP_NODE, &no_match_pathlimit_as_val_cmd);
paul718e3742002-12-13 20:15:29 +00003985}