blob: 173bf93b14877c0e9f52c141f18e2f8893b07640 [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
paul3b424972003-10-13 09:47:32 +0000528 tmpval = strtoul (arg, &endptr, 10);
paulfd79ac92004-10-13 05:06:08 +0000529 if (*endptr != '\0' || tmpval == ULONG_MAX || tmpval > UINT32_MAX)
paul3b424972003-10-13 09:47:32 +0000530 return NULL;
paulfd79ac92004-10-13 05:06:08 +0000531
paul718e3742002-12-13 20:15:29 +0000532 med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
paulfd79ac92004-10-13 05:06:08 +0000533
534 if (!med)
535 return med;
536
paul3b424972003-10-13 09:47:32 +0000537 *med = tmpval;
paul718e3742002-12-13 20:15:29 +0000538 return med;
539}
540
541/* Free route map's compiled `match metric' value. */
paul94f2b392005-06-28 12:44:16 +0000542static void
paul718e3742002-12-13 20:15:29 +0000543route_match_metric_free (void *rule)
544{
545 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
546}
547
548/* Route map commands for metric matching. */
549struct route_map_rule_cmd route_match_metric_cmd =
550{
551 "metric",
552 route_match_metric,
553 route_match_metric_compile,
554 route_match_metric_free
555};
556
557/* `match as-path ASPATH' */
558
559/* Match function for as-path match. I assume given object is */
paul94f2b392005-06-28 12:44:16 +0000560static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000561route_match_aspath (void *rule, struct prefix *prefix,
562 route_map_object_t type, void *object)
563{
564
565 struct as_list *as_list;
566 struct bgp_info *bgp_info;
567
568 if (type == RMAP_BGP)
569 {
570 as_list = as_list_lookup ((char *) rule);
571 if (as_list == NULL)
572 return RMAP_NOMATCH;
573
574 bgp_info = object;
575
576 /* Perform match. */
577 return ((as_list_apply (as_list, bgp_info->attr->aspath) == AS_FILTER_DENY) ? RMAP_NOMATCH : RMAP_MATCH);
578 }
579 return RMAP_NOMATCH;
580}
581
582/* Compile function for as-path match. */
paul94f2b392005-06-28 12:44:16 +0000583static void *
paulfd79ac92004-10-13 05:06:08 +0000584route_match_aspath_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000585{
586 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
587}
588
589/* Compile function for as-path match. */
paul94f2b392005-06-28 12:44:16 +0000590static void
paul718e3742002-12-13 20:15:29 +0000591route_match_aspath_free (void *rule)
592{
593 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
594}
595
596/* Route map commands for aspath matching. */
597struct route_map_rule_cmd route_match_aspath_cmd =
598{
599 "as-path",
600 route_match_aspath,
601 route_match_aspath_compile,
602 route_match_aspath_free
603};
paul718e3742002-12-13 20:15:29 +0000604
605/* `match community COMMUNIY' */
606struct rmap_community
607{
608 char *name;
609 int exact;
610};
611
612/* Match function for community match. */
paul94f2b392005-06-28 12:44:16 +0000613static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000614route_match_community (void *rule, struct prefix *prefix,
615 route_map_object_t type, void *object)
616{
617 struct community_list *list;
618 struct bgp_info *bgp_info;
619 struct rmap_community *rcom;
620
621 if (type == RMAP_BGP)
622 {
623 bgp_info = object;
624 rcom = rule;
625
hassofee6e4e2005-02-02 16:29:31 +0000626 list = community_list_lookup (bgp_clist, rcom->name, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +0000627 if (! list)
628 return RMAP_NOMATCH;
629
630 if (rcom->exact)
631 {
632 if (community_list_exact_match (bgp_info->attr->community, list))
633 return RMAP_MATCH;
634 }
635 else
636 {
637 if (community_list_match (bgp_info->attr->community, list))
638 return RMAP_MATCH;
639 }
640 }
641 return RMAP_NOMATCH;
642}
643
644/* Compile function for community match. */
paul94f2b392005-06-28 12:44:16 +0000645static void *
paulfd79ac92004-10-13 05:06:08 +0000646route_match_community_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000647{
648 struct rmap_community *rcom;
649 int len;
650 char *p;
651
652 rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community));
653
654 p = strchr (arg, ' ');
655 if (p)
656 {
657 len = p - arg;
658 rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
659 memcpy (rcom->name, arg, len);
660 rcom->exact = 1;
661 }
662 else
663 {
664 rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
665 rcom->exact = 0;
666 }
667 return rcom;
668}
669
670/* Compile function for community match. */
paul94f2b392005-06-28 12:44:16 +0000671static void
paul718e3742002-12-13 20:15:29 +0000672route_match_community_free (void *rule)
673{
674 struct rmap_community *rcom = rule;
675
676 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name);
677 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom);
678}
679
680/* Route map commands for community matching. */
681struct route_map_rule_cmd route_match_community_cmd =
682{
683 "community",
684 route_match_community,
685 route_match_community_compile,
686 route_match_community_free
687};
688
paul73ffb252003-04-19 15:49:49 +0000689/* Match function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000690static route_map_result_t
paul73ffb252003-04-19 15:49:49 +0000691route_match_ecommunity (void *rule, struct prefix *prefix,
692 route_map_object_t type, void *object)
693{
694 struct community_list *list;
695 struct bgp_info *bgp_info;
696
697 if (type == RMAP_BGP)
698 {
699 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +0000700
701 if (!bgp_info->attr->extra)
702 return RMAP_NOMATCH;
703
paul73ffb252003-04-19 15:49:49 +0000704 list = community_list_lookup (bgp_clist, (char *) rule,
hassofee6e4e2005-02-02 16:29:31 +0000705 EXTCOMMUNITY_LIST_MASTER);
paul73ffb252003-04-19 15:49:49 +0000706 if (! list)
707 return RMAP_NOMATCH;
708
Paul Jakmafb982c22007-05-04 20:15:47 +0000709 if (ecommunity_list_match (bgp_info->attr->extra->ecommunity, list))
paul73ffb252003-04-19 15:49:49 +0000710 return RMAP_MATCH;
711 }
712 return RMAP_NOMATCH;
713}
714
715/* Compile function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000716static void *
paulfd79ac92004-10-13 05:06:08 +0000717route_match_ecommunity_compile (const char *arg)
paul73ffb252003-04-19 15:49:49 +0000718{
719 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
720}
721
722/* Compile function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000723static void
paul73ffb252003-04-19 15:49:49 +0000724route_match_ecommunity_free (void *rule)
725{
726 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
727}
728
729/* Route map commands for community matching. */
730struct route_map_rule_cmd route_match_ecommunity_cmd =
731{
732 "extcommunity",
733 route_match_ecommunity,
734 route_match_ecommunity_compile,
735 route_match_ecommunity_free
736};
737
paul718e3742002-12-13 20:15:29 +0000738/* `match nlri` and `set nlri` are replaced by `address-family ipv4`
739 and `address-family vpnv4'. */
740
741/* `match origin' */
paul94f2b392005-06-28 12:44:16 +0000742static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000743route_match_origin (void *rule, struct prefix *prefix,
744 route_map_object_t type, void *object)
745{
746 u_char *origin;
747 struct bgp_info *bgp_info;
748
749 if (type == RMAP_BGP)
750 {
751 origin = rule;
752 bgp_info = object;
753
754 if (bgp_info->attr->origin == *origin)
755 return RMAP_MATCH;
756 }
757
758 return RMAP_NOMATCH;
759}
760
paul94f2b392005-06-28 12:44:16 +0000761static void *
paulfd79ac92004-10-13 05:06:08 +0000762route_match_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000763{
764 u_char *origin;
765
766 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
767
768 if (strcmp (arg, "igp") == 0)
769 *origin = 0;
770 else if (strcmp (arg, "egp") == 0)
771 *origin = 1;
772 else
773 *origin = 2;
774
775 return origin;
776}
777
778/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000779static void
paul718e3742002-12-13 20:15:29 +0000780route_match_origin_free (void *rule)
781{
782 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
783}
784
785/* Route map commands for origin matching. */
786struct route_map_rule_cmd route_match_origin_cmd =
787{
788 "origin",
789 route_match_origin,
790 route_match_origin_compile,
791 route_match_origin_free
792};
Vyacheslav Trushkin1c8afb72011-11-22 20:15:10 +0400793
794/* match probability { */
795
796static route_map_result_t
797route_match_probability (void *rule, struct prefix *prefix,
798 route_map_object_t type, void *object)
799{
800 long r;
801#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
802 r = random();
803#else
804 r = (long) rand();
805#endif
806
807 switch (*(unsigned *) rule)
808 {
809 case 0: break;
810 case RAND_MAX: return RMAP_MATCH;
811 default:
812 if (r < *(unsigned *) rule)
813 {
814 return RMAP_MATCH;
815 }
816 }
817
818 return RMAP_NOMATCH;
819}
820
821static void *
822route_match_probability_compile (const char *arg)
823{
824 unsigned *lobule;
825 unsigned perc;
826
827#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
828 srandom (time (NULL));
829#else
830 srand (time (NULL));
831#endif
832
833 perc = atoi (arg);
834 lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned));
835
836 switch (perc)
837 {
838 case 0: *lobule = 0; break;
839 case 100: *lobule = RAND_MAX; break;
840 default: *lobule = RAND_MAX / 100 * perc;
841 }
842
843 return lobule;
844}
845
846static void
847route_match_probability_free (void *rule)
848{
849 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
850}
851
852struct route_map_rule_cmd route_match_probability_cmd =
853{
854 "probability",
855 route_match_probability,
856 route_match_probability_compile,
857 route_match_probability_free
858};
859
860/* } */
861
paul718e3742002-12-13 20:15:29 +0000862/* `set ip next-hop IP_ADDRESS' */
863
864/* Set nexthop to object. ojbect must be pointer to struct attr. */
paulac41b2a2003-08-12 05:32:27 +0000865struct rmap_ip_nexthop_set
866{
867 struct in_addr *address;
868 int peer_address;
869};
870
paul94f2b392005-06-28 12:44:16 +0000871static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000872route_set_ip_nexthop (void *rule, struct prefix *prefix,
873 route_map_object_t type, void *object)
874{
paulac41b2a2003-08-12 05:32:27 +0000875 struct rmap_ip_nexthop_set *rins = rule;
876 struct in_addr peer_address;
paul718e3742002-12-13 20:15:29 +0000877 struct bgp_info *bgp_info;
paulac41b2a2003-08-12 05:32:27 +0000878 struct peer *peer;
paul718e3742002-12-13 20:15:29 +0000879
880 if (type == RMAP_BGP)
881 {
paul718e3742002-12-13 20:15:29 +0000882 bgp_info = object;
paulac41b2a2003-08-12 05:32:27 +0000883 peer = bgp_info->peer;
884
885 if (rins->peer_address)
886 {
paulfee0f4c2004-09-13 05:12:46 +0000887 if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) ||
888 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
paulac41b2a2003-08-12 05:32:27 +0000889 && peer->su_remote
890 && sockunion_family (peer->su_remote) == AF_INET)
891 {
892 inet_aton (sockunion_su2str (peer->su_remote), &peer_address);
893 bgp_info->attr->nexthop = peer_address;
894 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
895 }
896 else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
897 && peer->su_local
898 && sockunion_family (peer->su_local) == AF_INET)
899 {
900 inet_aton (sockunion_su2str (peer->su_local), &peer_address);
901 bgp_info->attr->nexthop = peer_address;
902 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
903 }
904 }
905 else
906 {
907 /* Set next hop value. */
908 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
909 bgp_info->attr->nexthop = *rins->address;
910 }
paul718e3742002-12-13 20:15:29 +0000911 }
912
913 return RMAP_OKAY;
914}
915
916/* Route map `ip nexthop' compile function. Given string is converted
917 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +0000918static void *
paulfd79ac92004-10-13 05:06:08 +0000919route_set_ip_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000920{
paulac41b2a2003-08-12 05:32:27 +0000921 struct rmap_ip_nexthop_set *rins;
922 struct in_addr *address = NULL;
923 int peer_address = 0;
paul718e3742002-12-13 20:15:29 +0000924 int ret;
paul718e3742002-12-13 20:15:29 +0000925
paulac41b2a2003-08-12 05:32:27 +0000926 if (strcmp (arg, "peer-address") == 0)
927 peer_address = 1;
928 else
paul718e3742002-12-13 20:15:29 +0000929 {
paulac41b2a2003-08-12 05:32:27 +0000930 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
931 ret = inet_aton (arg, address);
932
933 if (ret == 0)
934 {
935 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
936 return NULL;
937 }
paul718e3742002-12-13 20:15:29 +0000938 }
939
Stephen Hemminger393deb92008-08-18 14:13:29 -0700940 rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set));
paulac41b2a2003-08-12 05:32:27 +0000941
942 rins->address = address;
943 rins->peer_address = peer_address;
944
945 return rins;
paul718e3742002-12-13 20:15:29 +0000946}
947
948/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +0000949static void
paul718e3742002-12-13 20:15:29 +0000950route_set_ip_nexthop_free (void *rule)
951{
paulac41b2a2003-08-12 05:32:27 +0000952 struct rmap_ip_nexthop_set *rins = rule;
953
954 if (rins->address)
955 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address);
956
957 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins);
paul718e3742002-12-13 20:15:29 +0000958}
959
960/* Route map commands for ip nexthop set. */
961struct route_map_rule_cmd route_set_ip_nexthop_cmd =
962{
963 "ip next-hop",
964 route_set_ip_nexthop,
965 route_set_ip_nexthop_compile,
966 route_set_ip_nexthop_free
967};
968
969/* `set local-preference LOCAL_PREF' */
970
971/* Set local preference. */
paul94f2b392005-06-28 12:44:16 +0000972static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000973route_set_local_pref (void *rule, struct prefix *prefix,
974 route_map_object_t type, void *object)
975{
976 u_int32_t *local_pref;
977 struct bgp_info *bgp_info;
978
979 if (type == RMAP_BGP)
980 {
981 /* Fetch routemap's rule information. */
982 local_pref = rule;
983 bgp_info = object;
984
985 /* Set local preference value. */
986 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
987 bgp_info->attr->local_pref = *local_pref;
988 }
989
990 return RMAP_OKAY;
991}
992
993/* set local preference compilation. */
paul94f2b392005-06-28 12:44:16 +0000994static void *
paulfd79ac92004-10-13 05:06:08 +0000995route_set_local_pref_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000996{
paulfd79ac92004-10-13 05:06:08 +0000997 unsigned long tmp;
paul718e3742002-12-13 20:15:29 +0000998 u_int32_t *local_pref;
999 char *endptr = NULL;
1000
1001 /* Local preference value shoud be integer. */
1002 if (! all_digit (arg))
1003 return NULL;
paulfd79ac92004-10-13 05:06:08 +00001004
1005 tmp = strtoul (arg, &endptr, 10);
1006 if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX)
1007 return NULL;
1008
1009 local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
1010
1011 if (!local_pref)
1012 return local_pref;
1013
1014 *local_pref = tmp;
1015
paul718e3742002-12-13 20:15:29 +00001016 return local_pref;
1017}
1018
1019/* Free route map's local preference value. */
paul94f2b392005-06-28 12:44:16 +00001020static void
paul718e3742002-12-13 20:15:29 +00001021route_set_local_pref_free (void *rule)
1022{
1023 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1024}
1025
1026/* Set local preference rule structure. */
1027struct route_map_rule_cmd route_set_local_pref_cmd =
1028{
1029 "local-preference",
1030 route_set_local_pref,
1031 route_set_local_pref_compile,
1032 route_set_local_pref_free,
1033};
1034
1035/* `set weight WEIGHT' */
1036
1037/* Set weight. */
paul94f2b392005-06-28 12:44:16 +00001038static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001039route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type,
1040 void *object)
1041{
1042 u_int32_t *weight;
1043 struct bgp_info *bgp_info;
1044
1045 if (type == RMAP_BGP)
1046 {
1047 /* Fetch routemap's rule information. */
1048 weight = rule;
1049 bgp_info = object;
1050
1051 /* Set weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 if (*weight)
1053 (bgp_attr_extra_get (bgp_info->attr))->weight = *weight;
1054 else if (bgp_info->attr->extra)
1055 bgp_info->attr->extra->weight = 0;
paul718e3742002-12-13 20:15:29 +00001056 }
1057
1058 return RMAP_OKAY;
1059}
1060
1061/* set local preference compilation. */
paul94f2b392005-06-28 12:44:16 +00001062static void *
paulfd79ac92004-10-13 05:06:08 +00001063route_set_weight_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001064{
paulfd79ac92004-10-13 05:06:08 +00001065 unsigned long tmp;
paul718e3742002-12-13 20:15:29 +00001066 u_int32_t *weight;
1067 char *endptr = NULL;
1068
1069 /* Local preference value shoud be integer. */
1070 if (! all_digit (arg))
1071 return NULL;
1072
paulfd79ac92004-10-13 05:06:08 +00001073
1074 tmp = strtoul (arg, &endptr, 10);
1075 if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX)
1076 return NULL;
1077
paul718e3742002-12-13 20:15:29 +00001078 weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
paulfd79ac92004-10-13 05:06:08 +00001079
1080 if (weight == NULL)
1081 return weight;
1082
1083 *weight = tmp;
1084
paul718e3742002-12-13 20:15:29 +00001085 return weight;
1086}
1087
1088/* Free route map's local preference value. */
paul94f2b392005-06-28 12:44:16 +00001089static void
paul718e3742002-12-13 20:15:29 +00001090route_set_weight_free (void *rule)
1091{
1092 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1093}
1094
1095/* Set local preference rule structure. */
1096struct route_map_rule_cmd route_set_weight_cmd =
1097{
1098 "weight",
1099 route_set_weight,
1100 route_set_weight_compile,
1101 route_set_weight_free,
1102};
1103
1104/* `set metric METRIC' */
1105
1106/* Set metric to attribute. */
paul94f2b392005-06-28 12:44:16 +00001107static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001108route_set_metric (void *rule, struct prefix *prefix,
1109 route_map_object_t type, void *object)
1110{
1111 char *metric;
1112 u_int32_t metric_val;
1113 struct bgp_info *bgp_info;
1114
1115 if (type == RMAP_BGP)
1116 {
1117 /* Fetch routemap's rule information. */
1118 metric = rule;
1119 bgp_info = object;
1120
1121 if (! (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
1122 bgp_info->attr->med = 0;
1123 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
1124
1125 if (all_digit (metric))
1126 {
1127 metric_val = strtoul (metric, (char **)NULL, 10);
1128 bgp_info->attr->med = metric_val;
1129 }
1130 else
1131 {
1132 metric_val = strtoul (metric+1, (char **)NULL, 10);
1133
1134 if (strncmp (metric, "+", 1) == 0)
1135 {
paul3b424972003-10-13 09:47:32 +00001136 if (bgp_info->attr->med/2 + metric_val/2 > BGP_MED_MAX/2)
1137 bgp_info->attr->med = BGP_MED_MAX - 1;
paul718e3742002-12-13 20:15:29 +00001138 else
paul537d8ea2003-08-27 06:45:32 +00001139 bgp_info->attr->med += metric_val;
paul718e3742002-12-13 20:15:29 +00001140 }
1141 else if (strncmp (metric, "-", 1) == 0)
1142 {
paul537d8ea2003-08-27 06:45:32 +00001143 if (bgp_info->attr->med <= metric_val)
1144 bgp_info->attr->med = 0;
paul718e3742002-12-13 20:15:29 +00001145 else
paul537d8ea2003-08-27 06:45:32 +00001146 bgp_info->attr->med -= metric_val;
paul718e3742002-12-13 20:15:29 +00001147 }
1148 }
1149 }
1150 return RMAP_OKAY;
1151}
1152
1153/* set metric compilation. */
paul94f2b392005-06-28 12:44:16 +00001154static void *
paulfd79ac92004-10-13 05:06:08 +00001155route_set_metric_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001156{
1157 u_int32_t metric;
paul94f2b392005-06-28 12:44:16 +00001158 unsigned long larg;
paul718e3742002-12-13 20:15:29 +00001159 char *endptr = NULL;
1160
1161 if (all_digit (arg))
1162 {
1163 /* set metric value check*/
paul94f2b392005-06-28 12:44:16 +00001164 larg = strtoul (arg, &endptr, 10);
1165 if (*endptr != '\0' || larg == ULONG_MAX || larg > UINT32_MAX)
paul718e3742002-12-13 20:15:29 +00001166 return NULL;
paul94f2b392005-06-28 12:44:16 +00001167 metric = larg;
paul718e3742002-12-13 20:15:29 +00001168 }
1169 else
1170 {
1171 /* set metric +/-value check */
1172 if ((strncmp (arg, "+", 1) != 0
1173 && strncmp (arg, "-", 1) != 0)
1174 || (! all_digit (arg+1)))
1175 return NULL;
1176
paul94f2b392005-06-28 12:44:16 +00001177 larg = strtoul (arg+1, &endptr, 10);
1178 if (*endptr != '\0' || larg == ULONG_MAX || larg > UINT32_MAX)
paul718e3742002-12-13 20:15:29 +00001179 return NULL;
paul94f2b392005-06-28 12:44:16 +00001180 metric = larg;
paul718e3742002-12-13 20:15:29 +00001181 }
1182
1183 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1184}
1185
1186/* Free route map's compiled `set metric' value. */
paul94f2b392005-06-28 12:44:16 +00001187static void
paul718e3742002-12-13 20:15:29 +00001188route_set_metric_free (void *rule)
1189{
1190 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1191}
1192
1193/* Set metric rule structure. */
1194struct route_map_rule_cmd route_set_metric_cmd =
1195{
1196 "metric",
1197 route_set_metric,
1198 route_set_metric_compile,
1199 route_set_metric_free,
1200};
1201
1202/* `set as-path prepend ASPATH' */
1203
1204/* For AS path prepend mechanism. */
paul94f2b392005-06-28 12:44:16 +00001205static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001206route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1207{
1208 struct aspath *aspath;
1209 struct aspath *new;
1210 struct bgp_info *binfo;
1211
1212 if (type == RMAP_BGP)
1213 {
1214 aspath = rule;
1215 binfo = object;
1216
1217 if (binfo->attr->aspath->refcnt)
1218 new = aspath_dup (binfo->attr->aspath);
1219 else
1220 new = binfo->attr->aspath;
1221
1222 aspath_prepend (aspath, new);
1223 binfo->attr->aspath = new;
1224 }
1225
1226 return RMAP_OKAY;
1227}
1228
1229/* Compile function for as-path prepend. */
paul94f2b392005-06-28 12:44:16 +00001230static void *
paulfd79ac92004-10-13 05:06:08 +00001231route_set_aspath_prepend_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001232{
1233 struct aspath *aspath;
1234
1235 aspath = aspath_str2aspath (arg);
1236 if (! aspath)
1237 return NULL;
1238 return aspath;
1239}
1240
1241/* Compile function for as-path prepend. */
paul94f2b392005-06-28 12:44:16 +00001242static void
paul718e3742002-12-13 20:15:29 +00001243route_set_aspath_prepend_free (void *rule)
1244{
1245 struct aspath *aspath = rule;
1246 aspath_free (aspath);
1247}
1248
1249/* Set metric rule structure. */
1250struct route_map_rule_cmd route_set_aspath_prepend_cmd =
1251{
1252 "as-path prepend",
1253 route_set_aspath_prepend,
1254 route_set_aspath_prepend_compile,
1255 route_set_aspath_prepend_free,
1256};
1257
Denis Ovsienko841f7a52008-04-10 11:47:45 +00001258/* `set as-path exclude ASn' */
1259
1260/* For ASN exclude mechanism.
1261 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1262 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1263 */
1264static route_map_result_t
1265route_set_aspath_exclude (void *rule, struct prefix *dummy, route_map_object_t type, void *object)
1266{
1267 struct aspath * new_path, * exclude_path;
1268 struct bgp_info *binfo;
1269
1270 if (type == RMAP_BGP)
1271 {
1272 exclude_path = rule;
1273 binfo = object;
1274 if (binfo->attr->aspath->refcnt)
1275 new_path = aspath_dup (binfo->attr->aspath);
1276 else
1277 new_path = binfo->attr->aspath;
1278 binfo->attr->aspath = aspath_filter_exclude (new_path, exclude_path);
1279 }
1280 return RMAP_OKAY;
1281}
1282
1283/* FIXME: consider using route_set_aspath_prepend_compile() and
1284 * route_set_aspath_prepend_free(), which two below function are
1285 * exact clones of.
1286 */
1287
1288/* Compile function for as-path exclude. */
1289static void *
1290route_set_aspath_exclude_compile (const char *arg)
1291{
1292 struct aspath *aspath;
1293
1294 aspath = aspath_str2aspath (arg);
1295 if (! aspath)
1296 return NULL;
1297 return aspath;
1298}
1299
1300static void
1301route_set_aspath_exclude_free (void *rule)
1302{
1303 struct aspath *aspath = rule;
1304 aspath_free (aspath);
1305}
1306
1307/* Set ASn exlude rule structure. */
1308struct route_map_rule_cmd route_set_aspath_exclude_cmd =
1309{
1310 "as-path exclude",
1311 route_set_aspath_exclude,
1312 route_set_aspath_exclude_compile,
1313 route_set_aspath_exclude_free,
1314};
1315
paul718e3742002-12-13 20:15:29 +00001316/* `set community COMMUNITY' */
1317struct rmap_com_set
1318{
1319 struct community *com;
1320 int additive;
1321 int none;
1322};
1323
1324/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001325static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001326route_set_community (void *rule, struct prefix *prefix,
1327 route_map_object_t type, void *object)
1328{
1329 struct rmap_com_set *rcs;
1330 struct bgp_info *binfo;
1331 struct attr *attr;
1332 struct community *new = NULL;
1333 struct community *old;
1334 struct community *merge;
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001335
paul718e3742002-12-13 20:15:29 +00001336 if (type == RMAP_BGP)
1337 {
1338 rcs = rule;
1339 binfo = object;
1340 attr = binfo->attr;
1341 old = attr->community;
1342
1343 /* "none" case. */
1344 if (rcs->none)
1345 {
1346 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES));
1347 attr->community = NULL;
1348 return RMAP_OKAY;
1349 }
1350
1351 /* "additive" case. */
1352 if (rcs->additive && old)
1353 {
1354 merge = community_merge (community_dup (old), rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001355
1356 /* HACK: if the old community is not intern'd,
1357 * we should free it here, or all reference to it may be lost.
1358 * Really need to cleanup attribute caching sometime.
1359 */
1360 if (old->refcnt == 0)
1361 community_free (old);
paul718e3742002-12-13 20:15:29 +00001362 new = community_uniq_sort (merge);
1363 community_free (merge);
1364 }
1365 else
1366 new = community_dup (rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001367
1368 /* will be interned by caller if required */
paul718e3742002-12-13 20:15:29 +00001369 attr->community = new;
hasso70601e02005-05-27 03:26:57 +00001370
paul718e3742002-12-13 20:15:29 +00001371 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1372 }
1373
1374 return RMAP_OKAY;
1375}
1376
1377/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001378static void *
paulfd79ac92004-10-13 05:06:08 +00001379route_set_community_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001380{
1381 struct rmap_com_set *rcs;
1382 struct community *com = NULL;
1383 char *sp;
1384 int additive = 0;
1385 int none = 0;
1386
1387 if (strcmp (arg, "none") == 0)
1388 none = 1;
1389 else
1390 {
1391 sp = strstr (arg, "additive");
1392
1393 if (sp && sp > arg)
1394 {
1395 /* "additive" keyworkd is included. */
1396 additive = 1;
1397 *(sp - 1) = '\0';
1398 }
1399
1400 com = community_str2com (arg);
1401
1402 if (additive)
1403 *(sp - 1) = ' ';
1404
1405 if (! com)
1406 return NULL;
1407 }
1408
Stephen Hemminger393deb92008-08-18 14:13:29 -07001409 rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
paul718e3742002-12-13 20:15:29 +00001410 rcs->com = com;
1411 rcs->additive = additive;
1412 rcs->none = none;
1413
1414 return rcs;
1415}
1416
1417/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001418static void
paul718e3742002-12-13 20:15:29 +00001419route_set_community_free (void *rule)
1420{
1421 struct rmap_com_set *rcs = rule;
1422
1423 if (rcs->com)
1424 community_free (rcs->com);
1425 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs);
1426}
1427
1428/* Set community rule structure. */
1429struct route_map_rule_cmd route_set_community_cmd =
1430{
1431 "community",
1432 route_set_community,
1433 route_set_community_compile,
1434 route_set_community_free,
1435};
1436
hassofee6e4e2005-02-02 16:29:31 +00001437/* `set comm-list (<1-99>|<100-500>|WORD) delete' */
paul718e3742002-12-13 20:15:29 +00001438
1439/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001440static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001441route_set_community_delete (void *rule, struct prefix *prefix,
1442 route_map_object_t type, void *object)
1443{
1444 struct community_list *list;
1445 struct community *merge;
1446 struct community *new;
1447 struct community *old;
1448 struct bgp_info *binfo;
1449
1450 if (type == RMAP_BGP)
1451 {
1452 if (! rule)
1453 return RMAP_OKAY;
1454
1455 binfo = object;
hassofee6e4e2005-02-02 16:29:31 +00001456 list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00001457 old = binfo->attr->community;
1458
1459 if (list && old)
1460 {
1461 merge = community_list_match_delete (community_dup (old), list);
1462 new = community_uniq_sort (merge);
1463 community_free (merge);
1464
1465 if (new->size == 0)
1466 {
1467 binfo->attr->community = NULL;
1468 binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1469 community_free (new);
1470 }
1471 else
1472 {
1473 binfo->attr->community = new;
1474 binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1475 }
1476 }
1477 }
1478
1479 return RMAP_OKAY;
1480}
1481
1482/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001483static void *
paulfd79ac92004-10-13 05:06:08 +00001484route_set_community_delete_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001485{
1486 char *p;
1487 char *str;
1488 int len;
1489
1490 p = strchr (arg, ' ');
1491 if (p)
1492 {
1493 len = p - arg;
1494 str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
1495 memcpy (str, arg, len);
1496 }
1497 else
1498 str = NULL;
1499
1500 return str;
1501}
1502
1503/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001504static void
paul718e3742002-12-13 20:15:29 +00001505route_set_community_delete_free (void *rule)
1506{
1507 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1508}
1509
1510/* Set community rule structure. */
1511struct route_map_rule_cmd route_set_community_delete_cmd =
1512{
1513 "comm-list",
1514 route_set_community_delete,
1515 route_set_community_delete_compile,
1516 route_set_community_delete_free,
1517};
1518
1519/* `set extcommunity rt COMMUNITY' */
1520
1521/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001522static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001523route_set_ecommunity_rt (void *rule, struct prefix *prefix,
1524 route_map_object_t type, void *object)
1525{
1526 struct ecommunity *ecom;
1527 struct ecommunity *new_ecom;
1528 struct ecommunity *old_ecom;
1529 struct bgp_info *bgp_info;
1530
1531 if (type == RMAP_BGP)
1532 {
1533 ecom = rule;
1534 bgp_info = object;
1535
1536 if (! ecom)
1537 return RMAP_OKAY;
1538
1539 /* We assume additive for Extended Community. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001540 old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
paul718e3742002-12-13 20:15:29 +00001541
1542 if (old_ecom)
1543 new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
1544 else
1545 new_ecom = ecommunity_dup (ecom);
1546
Paul Jakmafb982c22007-05-04 20:15:47 +00001547 bgp_info->attr->extra->ecommunity = new_ecom;
paul718e3742002-12-13 20:15:29 +00001548
hasso70601e02005-05-27 03:26:57 +00001549 if (old_ecom)
1550 ecommunity_free (old_ecom);
1551
paul718e3742002-12-13 20:15:29 +00001552 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
1553 }
1554 return RMAP_OKAY;
1555}
1556
1557/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001558static void *
paulfd79ac92004-10-13 05:06:08 +00001559route_set_ecommunity_rt_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001560{
1561 struct ecommunity *ecom;
1562
1563 ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0);
1564 if (! ecom)
1565 return NULL;
1566 return ecom;
1567}
1568
1569/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001570static void
paul718e3742002-12-13 20:15:29 +00001571route_set_ecommunity_rt_free (void *rule)
1572{
1573 struct ecommunity *ecom = rule;
1574 ecommunity_free (ecom);
1575}
1576
1577/* Set community rule structure. */
1578struct route_map_rule_cmd route_set_ecommunity_rt_cmd =
1579{
1580 "extcommunity rt",
1581 route_set_ecommunity_rt,
1582 route_set_ecommunity_rt_compile,
1583 route_set_ecommunity_rt_free,
1584};
1585
1586/* `set extcommunity soo COMMUNITY' */
1587
1588/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001589static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001590route_set_ecommunity_soo (void *rule, struct prefix *prefix,
1591 route_map_object_t type, void *object)
1592{
1593 struct ecommunity *ecom;
1594 struct bgp_info *bgp_info;
1595
1596 if (type == RMAP_BGP)
1597 {
1598 ecom = rule;
1599 bgp_info = object;
1600
1601 if (! ecom)
1602 return RMAP_OKAY;
1603
1604 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
Paul Jakmafb982c22007-05-04 20:15:47 +00001605 (bgp_attr_extra_get (bgp_info->attr))->ecommunity = ecommunity_dup (ecom);
paul718e3742002-12-13 20:15:29 +00001606 }
1607 return RMAP_OKAY;
1608}
1609
1610/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001611static void *
paulfd79ac92004-10-13 05:06:08 +00001612route_set_ecommunity_soo_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001613{
1614 struct ecommunity *ecom;
1615
1616 ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0);
1617 if (! ecom)
1618 return NULL;
1619
1620 return ecom;
1621}
1622
1623/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001624static void
paul718e3742002-12-13 20:15:29 +00001625route_set_ecommunity_soo_free (void *rule)
1626{
1627 struct ecommunity *ecom = rule;
1628 ecommunity_free (ecom);
1629}
1630
1631/* Set community rule structure. */
1632struct route_map_rule_cmd route_set_ecommunity_soo_cmd =
1633{
1634 "extcommunity soo",
1635 route_set_ecommunity_soo,
1636 route_set_ecommunity_soo_compile,
1637 route_set_ecommunity_soo_free,
1638};
1639
1640/* `set origin ORIGIN' */
1641
1642/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00001643static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001644route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1645{
1646 u_char *origin;
1647 struct bgp_info *bgp_info;
1648
1649 if (type == RMAP_BGP)
1650 {
1651 origin = rule;
1652 bgp_info = object;
1653
1654 bgp_info->attr->origin = *origin;
1655 }
1656
1657 return RMAP_OKAY;
1658}
1659
1660/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001661static void *
paulfd79ac92004-10-13 05:06:08 +00001662route_set_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001663{
1664 u_char *origin;
1665
1666 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
1667
1668 if (strcmp (arg, "igp") == 0)
1669 *origin = 0;
1670 else if (strcmp (arg, "egp") == 0)
1671 *origin = 1;
1672 else
1673 *origin = 2;
1674
1675 return origin;
1676}
1677
1678/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001679static void
paul718e3742002-12-13 20:15:29 +00001680route_set_origin_free (void *rule)
1681{
1682 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1683}
1684
1685/* Set metric rule structure. */
1686struct route_map_rule_cmd route_set_origin_cmd =
1687{
1688 "origin",
1689 route_set_origin,
1690 route_set_origin_compile,
1691 route_set_origin_free,
1692};
1693
1694/* `set atomic-aggregate' */
1695
1696/* For atomic aggregate set. */
paul94f2b392005-06-28 12:44:16 +00001697static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001698route_set_atomic_aggregate (void *rule, struct prefix *prefix,
1699 route_map_object_t type, void *object)
1700{
1701 struct bgp_info *bgp_info;
1702
1703 if (type == RMAP_BGP)
1704 {
1705 bgp_info = object;
1706 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
1707 }
1708
1709 return RMAP_OKAY;
1710}
1711
1712/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001713static void *
paulfd79ac92004-10-13 05:06:08 +00001714route_set_atomic_aggregate_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001715{
1716 return (void *)1;
1717}
1718
1719/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001720static void
paul718e3742002-12-13 20:15:29 +00001721route_set_atomic_aggregate_free (void *rule)
1722{
1723 return;
1724}
1725
1726/* Set atomic aggregate rule structure. */
1727struct route_map_rule_cmd route_set_atomic_aggregate_cmd =
1728{
1729 "atomic-aggregate",
1730 route_set_atomic_aggregate,
1731 route_set_atomic_aggregate_compile,
1732 route_set_atomic_aggregate_free,
1733};
1734
1735/* `set aggregator as AS A.B.C.D' */
1736struct aggregator
1737{
1738 as_t as;
1739 struct in_addr address;
1740};
1741
paul94f2b392005-06-28 12:44:16 +00001742static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001743route_set_aggregator_as (void *rule, struct prefix *prefix,
1744 route_map_object_t type, void *object)
1745{
1746 struct bgp_info *bgp_info;
1747 struct aggregator *aggregator;
Paul Jakmafb982c22007-05-04 20:15:47 +00001748 struct attr_extra *ae;
paul718e3742002-12-13 20:15:29 +00001749
1750 if (type == RMAP_BGP)
1751 {
1752 bgp_info = object;
1753 aggregator = rule;
Paul Jakmafb982c22007-05-04 20:15:47 +00001754 ae = bgp_attr_extra_get (bgp_info->attr);
1755
1756 ae->aggregator_as = aggregator->as;
1757 ae->aggregator_addr = aggregator->address;
paul718e3742002-12-13 20:15:29 +00001758 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
1759 }
1760
1761 return RMAP_OKAY;
1762}
1763
paul94f2b392005-06-28 12:44:16 +00001764static void *
paulfd79ac92004-10-13 05:06:08 +00001765route_set_aggregator_as_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001766{
1767 struct aggregator *aggregator;
1768 char as[10];
1769 char address[20];
1770
Stephen Hemminger393deb92008-08-18 14:13:29 -07001771 aggregator = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));
paul718e3742002-12-13 20:15:29 +00001772 sscanf (arg, "%s %s", as, address);
1773
1774 aggregator->as = strtoul (as, NULL, 10);
1775 inet_aton (address, &aggregator->address);
1776
1777 return aggregator;
1778}
1779
paul94f2b392005-06-28 12:44:16 +00001780static void
paul718e3742002-12-13 20:15:29 +00001781route_set_aggregator_as_free (void *rule)
1782{
1783 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1784}
1785
1786struct route_map_rule_cmd route_set_aggregator_as_cmd =
1787{
1788 "aggregator as",
1789 route_set_aggregator_as,
1790 route_set_aggregator_as_compile,
1791 route_set_aggregator_as_free,
1792};
1793
1794#ifdef HAVE_IPV6
1795/* `match ipv6 address IP_ACCESS_LIST' */
1796
paul94f2b392005-06-28 12:44:16 +00001797static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001798route_match_ipv6_address (void *rule, struct prefix *prefix,
1799 route_map_object_t type, void *object)
1800{
1801 struct access_list *alist;
1802
1803 if (type == RMAP_BGP)
1804 {
1805 alist = access_list_lookup (AFI_IP6, (char *) rule);
1806 if (alist == NULL)
1807 return RMAP_NOMATCH;
1808
1809 return (access_list_apply (alist, prefix) == FILTER_DENY ?
1810 RMAP_NOMATCH : RMAP_MATCH);
1811 }
1812 return RMAP_NOMATCH;
1813}
1814
paul94f2b392005-06-28 12:44:16 +00001815static void *
paulfd79ac92004-10-13 05:06:08 +00001816route_match_ipv6_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001817{
1818 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1819}
1820
paul94f2b392005-06-28 12:44:16 +00001821static void
paul718e3742002-12-13 20:15:29 +00001822route_match_ipv6_address_free (void *rule)
1823{
1824 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1825}
1826
1827/* Route map commands for ip address matching. */
1828struct route_map_rule_cmd route_match_ipv6_address_cmd =
1829{
1830 "ipv6 address",
1831 route_match_ipv6_address,
1832 route_match_ipv6_address_compile,
1833 route_match_ipv6_address_free
1834};
1835
1836/* `match ipv6 next-hop IP_ADDRESS' */
1837
paul94f2b392005-06-28 12:44:16 +00001838static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001839route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
1840 route_map_object_t type, void *object)
1841{
1842 struct in6_addr *addr;
1843 struct bgp_info *bgp_info;
1844
1845 if (type == RMAP_BGP)
1846 {
1847 addr = rule;
1848 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +00001849
1850 if (!bgp_info->attr->extra)
1851 return RMAP_NOMATCH;
1852
1853 if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, rule))
paul718e3742002-12-13 20:15:29 +00001854 return RMAP_MATCH;
1855
Paul Jakmafb982c22007-05-04 20:15:47 +00001856 if (bgp_info->attr->extra->mp_nexthop_len == 32 &&
1857 IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, rule))
paul718e3742002-12-13 20:15:29 +00001858 return RMAP_MATCH;
1859
1860 return RMAP_NOMATCH;
1861 }
1862
1863 return RMAP_NOMATCH;
1864}
1865
paul94f2b392005-06-28 12:44:16 +00001866static void *
paulfd79ac92004-10-13 05:06:08 +00001867route_match_ipv6_next_hop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001868{
1869 struct in6_addr *address;
1870 int ret;
1871
1872 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1873
1874 ret = inet_pton (AF_INET6, arg, address);
1875 if (!ret)
1876 {
1877 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1878 return NULL;
1879 }
1880
1881 return address;
1882}
1883
paul94f2b392005-06-28 12:44:16 +00001884static void
paul718e3742002-12-13 20:15:29 +00001885route_match_ipv6_next_hop_free (void *rule)
1886{
1887 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1888}
1889
1890struct route_map_rule_cmd route_match_ipv6_next_hop_cmd =
1891{
1892 "ipv6 next-hop",
1893 route_match_ipv6_next_hop,
1894 route_match_ipv6_next_hop_compile,
1895 route_match_ipv6_next_hop_free
1896};
1897
1898/* `match ipv6 address prefix-list PREFIX_LIST' */
1899
paul94f2b392005-06-28 12:44:16 +00001900static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001901route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix,
1902 route_map_object_t type, void *object)
1903{
1904 struct prefix_list *plist;
1905
1906 if (type == RMAP_BGP)
1907 {
1908 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
1909 if (plist == NULL)
1910 return RMAP_NOMATCH;
1911
1912 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
1913 RMAP_NOMATCH : RMAP_MATCH);
1914 }
1915 return RMAP_NOMATCH;
1916}
1917
paul94f2b392005-06-28 12:44:16 +00001918static void *
paulfd79ac92004-10-13 05:06:08 +00001919route_match_ipv6_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001920{
1921 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1922}
1923
paul94f2b392005-06-28 12:44:16 +00001924static void
paul718e3742002-12-13 20:15:29 +00001925route_match_ipv6_address_prefix_list_free (void *rule)
1926{
1927 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1928}
1929
1930struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
1931{
1932 "ipv6 address prefix-list",
1933 route_match_ipv6_address_prefix_list,
1934 route_match_ipv6_address_prefix_list_compile,
1935 route_match_ipv6_address_prefix_list_free
1936};
1937
1938/* `set ipv6 nexthop global IP_ADDRESS' */
1939
1940/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001941static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001942route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix,
1943 route_map_object_t type, void *object)
1944{
1945 struct in6_addr *address;
1946 struct bgp_info *bgp_info;
1947
1948 if (type == RMAP_BGP)
1949 {
1950 /* Fetch routemap's rule information. */
1951 address = rule;
1952 bgp_info = object;
1953
1954 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001955 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address;
paul718e3742002-12-13 20:15:29 +00001956
1957 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001958 if (bgp_info->attr->extra->mp_nexthop_len == 0)
1959 bgp_info->attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001960 }
1961
1962 return RMAP_OKAY;
1963}
1964
1965/* Route map `ip next-hop' compile function. Given string is converted
1966 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00001967static void *
paulfd79ac92004-10-13 05:06:08 +00001968route_set_ipv6_nexthop_global_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001969{
1970 int ret;
1971 struct in6_addr *address;
1972
1973 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1974
1975 ret = inet_pton (AF_INET6, arg, address);
1976
1977 if (ret == 0)
1978 {
1979 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1980 return NULL;
1981 }
1982
1983 return address;
1984}
1985
1986/* Free route map's compiled `ip next-hop' value. */
paul94f2b392005-06-28 12:44:16 +00001987static void
paul718e3742002-12-13 20:15:29 +00001988route_set_ipv6_nexthop_global_free (void *rule)
1989{
1990 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1991}
1992
1993/* Route map commands for ip nexthop set. */
1994struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd =
1995{
1996 "ipv6 next-hop global",
1997 route_set_ipv6_nexthop_global,
1998 route_set_ipv6_nexthop_global_compile,
1999 route_set_ipv6_nexthop_global_free
2000};
2001
2002/* `set ipv6 nexthop local IP_ADDRESS' */
2003
2004/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00002005static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002006route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
2007 route_map_object_t type, void *object)
2008{
2009 struct in6_addr *address;
2010 struct bgp_info *bgp_info;
2011
2012 if (type == RMAP_BGP)
2013 {
2014 /* Fetch routemap's rule information. */
2015 address = rule;
2016 bgp_info = object;
2017
2018 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002019 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address;
paul718e3742002-12-13 20:15:29 +00002020
2021 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002022 if (bgp_info->attr->extra->mp_nexthop_len != 32)
2023 bgp_info->attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002024 }
2025
2026 return RMAP_OKAY;
2027}
2028
2029/* Route map `ip nexthop' compile function. Given string is converted
2030 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00002031static void *
paulfd79ac92004-10-13 05:06:08 +00002032route_set_ipv6_nexthop_local_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002033{
2034 int ret;
2035 struct in6_addr *address;
2036
2037 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
2038
2039 ret = inet_pton (AF_INET6, arg, address);
2040
2041 if (ret == 0)
2042 {
2043 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2044 return NULL;
2045 }
2046
2047 return address;
2048}
2049
2050/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +00002051static void
paul718e3742002-12-13 20:15:29 +00002052route_set_ipv6_nexthop_local_free (void *rule)
2053{
2054 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2055}
2056
2057/* Route map commands for ip nexthop set. */
2058struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd =
2059{
2060 "ipv6 next-hop local",
2061 route_set_ipv6_nexthop_local,
2062 route_set_ipv6_nexthop_local_compile,
2063 route_set_ipv6_nexthop_local_free
2064};
2065#endif /* HAVE_IPV6 */
2066
2067/* `set vpnv4 nexthop A.B.C.D' */
2068
paul94f2b392005-06-28 12:44:16 +00002069static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002070route_set_vpnv4_nexthop (void *rule, struct prefix *prefix,
2071 route_map_object_t type, void *object)
2072{
2073 struct in_addr *address;
2074 struct bgp_info *bgp_info;
2075
2076 if (type == RMAP_BGP)
2077 {
2078 /* Fetch routemap's rule information. */
2079 address = rule;
2080 bgp_info = object;
2081
2082 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002083 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address;
paul718e3742002-12-13 20:15:29 +00002084 }
2085
2086 return RMAP_OKAY;
2087}
2088
paul94f2b392005-06-28 12:44:16 +00002089static void *
paulfd79ac92004-10-13 05:06:08 +00002090route_set_vpnv4_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002091{
2092 int ret;
2093 struct in_addr *address;
2094
2095 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2096
2097 ret = inet_aton (arg, address);
2098
2099 if (ret == 0)
2100 {
2101 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2102 return NULL;
2103 }
2104
2105 return address;
2106}
2107
paul94f2b392005-06-28 12:44:16 +00002108static void
paul718e3742002-12-13 20:15:29 +00002109route_set_vpnv4_nexthop_free (void *rule)
2110{
2111 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2112}
2113
2114/* Route map commands for ip nexthop set. */
2115struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd =
2116{
2117 "vpnv4 next-hop",
2118 route_set_vpnv4_nexthop,
2119 route_set_vpnv4_nexthop_compile,
2120 route_set_vpnv4_nexthop_free
2121};
2122
2123/* `set originator-id' */
2124
2125/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00002126static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002127route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
2128{
2129 struct in_addr *address;
2130 struct bgp_info *bgp_info;
2131
2132 if (type == RMAP_BGP)
2133 {
2134 address = rule;
2135 bgp_info = object;
2136
2137 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);
Paul Jakmafb982c22007-05-04 20:15:47 +00002138 (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address;
paul718e3742002-12-13 20:15:29 +00002139 }
2140
2141 return RMAP_OKAY;
2142}
2143
2144/* Compile function for originator-id set. */
paul94f2b392005-06-28 12:44:16 +00002145static void *
paulfd79ac92004-10-13 05:06:08 +00002146route_set_originator_id_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002147{
2148 int ret;
2149 struct in_addr *address;
2150
2151 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2152
2153 ret = inet_aton (arg, address);
2154
2155 if (ret == 0)
2156 {
2157 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2158 return NULL;
2159 }
2160
2161 return address;
2162}
2163
2164/* Compile function for originator_id set. */
paul94f2b392005-06-28 12:44:16 +00002165static void
paul718e3742002-12-13 20:15:29 +00002166route_set_originator_id_free (void *rule)
2167{
2168 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2169}
2170
2171/* Set metric rule structure. */
2172struct route_map_rule_cmd route_set_originator_id_cmd =
2173{
2174 "originator-id",
2175 route_set_originator_id,
2176 route_set_originator_id_compile,
2177 route_set_originator_id_free,
2178};
2179
2180/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002181static int
paul718e3742002-12-13 20:15:29 +00002182bgp_route_match_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002183 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002184{
2185 int ret;
2186
2187 ret = route_map_add_match (index, command, arg);
2188 if (ret)
2189 {
2190 switch (ret)
2191 {
2192 case RMAP_RULE_MISSING:
2193 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2194 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002195 case RMAP_COMPILE_ERROR:
2196 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2197 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002198 }
2199 }
2200 return CMD_SUCCESS;
2201}
2202
2203/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002204static int
paul718e3742002-12-13 20:15:29 +00002205bgp_route_match_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002206 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002207{
2208 int ret;
2209
2210 ret = route_map_delete_match (index, command, arg);
2211 if (ret)
2212 {
2213 switch (ret)
2214 {
2215 case RMAP_RULE_MISSING:
2216 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2217 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002218 case RMAP_COMPILE_ERROR:
2219 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2220 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002221 }
2222 }
2223 return CMD_SUCCESS;
2224}
2225
2226/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002227static int
paul718e3742002-12-13 20:15:29 +00002228bgp_route_set_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002229 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002230{
2231 int ret;
2232
2233 ret = route_map_add_set (index, command, arg);
2234 if (ret)
2235 {
2236 switch (ret)
2237 {
2238 case RMAP_RULE_MISSING:
2239 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2240 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002241 case RMAP_COMPILE_ERROR:
2242 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2243 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002244 }
2245 }
2246 return CMD_SUCCESS;
2247}
2248
2249/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002250static int
paul718e3742002-12-13 20:15:29 +00002251bgp_route_set_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002252 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002253{
2254 int ret;
2255
2256 ret = route_map_delete_set (index, command, arg);
2257 if (ret)
2258 {
2259 switch (ret)
2260 {
2261 case RMAP_RULE_MISSING:
2262 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2263 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002264 case RMAP_COMPILE_ERROR:
2265 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2266 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002267 }
2268 }
2269 return CMD_SUCCESS;
2270}
2271
2272/* Hook function for updating route_map assignment. */
paul94f2b392005-06-28 12:44:16 +00002273static void
paulfd79ac92004-10-13 05:06:08 +00002274bgp_route_map_update (const char *unused)
paul718e3742002-12-13 20:15:29 +00002275{
2276 int i;
2277 afi_t afi;
2278 safi_t safi;
2279 int direct;
paul1eb8ef22005-04-07 07:30:20 +00002280 struct listnode *node, *nnode;
2281 struct listnode *mnode, *mnnode;
paul718e3742002-12-13 20:15:29 +00002282 struct bgp *bgp;
2283 struct peer *peer;
2284 struct peer_group *group;
2285 struct bgp_filter *filter;
2286 struct bgp_node *bn;
2287 struct bgp_static *bgp_static;
2288
2289 /* For neighbor route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002290 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002291 {
paul1eb8ef22005-04-07 07:30:20 +00002292 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002293 {
2294 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2295 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2296 {
2297 filter = &peer->filter[afi][safi];
2298
paulfee0f4c2004-09-13 05:12:46 +00002299 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002300 {
2301 if (filter->map[direct].name)
2302 filter->map[direct].map =
2303 route_map_lookup_by_name (filter->map[direct].name);
2304 else
2305 filter->map[direct].map = NULL;
2306 }
2307
2308 if (filter->usmap.name)
2309 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2310 else
2311 filter->usmap.map = NULL;
2312 }
2313 }
paul1eb8ef22005-04-07 07:30:20 +00002314 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
paul718e3742002-12-13 20:15:29 +00002315 {
2316 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2317 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2318 {
2319 filter = &group->conf->filter[afi][safi];
2320
paulfee0f4c2004-09-13 05:12:46 +00002321 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002322 {
2323 if (filter->map[direct].name)
2324 filter->map[direct].map =
2325 route_map_lookup_by_name (filter->map[direct].name);
2326 else
2327 filter->map[direct].map = NULL;
2328 }
2329
2330 if (filter->usmap.name)
2331 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2332 else
2333 filter->usmap.map = NULL;
2334 }
2335 }
2336 }
2337
2338 /* For default-originate route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002339 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002340 {
paul1eb8ef22005-04-07 07:30:20 +00002341 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002342 {
2343 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2344 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2345 {
2346 if (peer->default_rmap[afi][safi].name)
2347 peer->default_rmap[afi][safi].map =
2348 route_map_lookup_by_name (peer->default_rmap[afi][safi].name);
2349 else
2350 peer->default_rmap[afi][safi].map = NULL;
2351 }
2352 }
2353 }
2354
2355 /* For network route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002356 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002357 {
2358 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2359 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2360 for (bn = bgp_table_top (bgp->route[afi][safi]); bn;
2361 bn = bgp_route_next (bn))
2362 if ((bgp_static = bn->info) != NULL)
2363 {
2364 if (bgp_static->rmap.name)
2365 bgp_static->rmap.map =
2366 route_map_lookup_by_name (bgp_static->rmap.name);
2367 else
2368 bgp_static->rmap.map = NULL;
2369 }
2370 }
2371
2372 /* For redistribute route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002373 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002374 {
2375 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2376 {
2377 if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)
2378 bgp->rmap[ZEBRA_FAMILY_IPV4][i].map =
2379 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);
2380#ifdef HAVE_IPV6
2381 if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)
2382 bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =
2383 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);
2384#endif /* HAVE_IPV6 */
2385 }
2386 }
2387}
2388
paulfee0f4c2004-09-13 05:12:46 +00002389DEFUN (match_peer,
2390 match_peer_cmd,
2391 "match peer (A.B.C.D|X:X::X:X)",
2392 MATCH_STR
2393 "Match peer address\n"
2394 "IPv6 address of peer\n"
2395 "IP address of peer\n")
2396{
2397 return bgp_route_match_add (vty, vty->index, "peer", argv[0]);
2398}
2399
2400DEFUN (match_peer_local,
2401 match_peer_local_cmd,
2402 "match peer local",
2403 MATCH_STR
2404 "Match peer address\n"
2405 "Static or Redistributed routes\n")
2406{
2407 return bgp_route_match_add (vty, vty->index, "peer", NULL);
2408}
2409
2410DEFUN (no_match_peer,
2411 no_match_peer_cmd,
2412 "no match peer",
2413 NO_STR
2414 MATCH_STR
2415 "Match peer address\n")
2416{
2417 if (argc == 0)
2418 return bgp_route_match_delete (vty, vty->index, "peer", NULL);
2419
2420 return bgp_route_match_delete (vty, vty->index, "peer", argv[0]);
2421}
2422
2423ALIAS (no_match_peer,
2424 no_match_peer_val_cmd,
2425 "no match peer (A.B.C.D|X:X::X:X)",
2426 NO_STR
2427 MATCH_STR
2428 "Match peer address\n"
2429 "IPv6 address of peer\n"
2430 "IP address of peer\n")
2431
2432ALIAS (no_match_peer,
2433 no_match_peer_local_cmd,
2434 "no match peer local",
2435 NO_STR
2436 MATCH_STR
2437 "Match peer address\n"
2438 "Static or Redistributed routes\n")
2439
paul718e3742002-12-13 20:15:29 +00002440DEFUN (match_ip_address,
2441 match_ip_address_cmd,
2442 "match ip address (<1-199>|<1300-2699>|WORD)",
2443 MATCH_STR
2444 IP_STR
2445 "Match address of route\n"
2446 "IP access-list number\n"
2447 "IP access-list number (expanded range)\n"
2448 "IP Access-list name\n")
2449{
2450 return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);
2451}
2452
2453DEFUN (no_match_ip_address,
2454 no_match_ip_address_cmd,
2455 "no match ip address",
2456 NO_STR
2457 MATCH_STR
2458 IP_STR
2459 "Match address of route\n")
2460{
2461 if (argc == 0)
2462 return bgp_route_match_delete (vty, vty->index, "ip address", NULL);
2463
2464 return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);
2465}
2466
2467ALIAS (no_match_ip_address,
2468 no_match_ip_address_val_cmd,
2469 "no match ip address (<1-199>|<1300-2699>|WORD)",
2470 NO_STR
2471 MATCH_STR
2472 IP_STR
2473 "Match address of route\n"
2474 "IP access-list number\n"
2475 "IP access-list number (expanded range)\n"
2476 "IP Access-list name\n")
2477
2478DEFUN (match_ip_next_hop,
2479 match_ip_next_hop_cmd,
2480 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
2481 MATCH_STR
2482 IP_STR
2483 "Match next-hop address of route\n"
2484 "IP access-list number\n"
2485 "IP access-list number (expanded range)\n"
2486 "IP Access-list name\n")
2487{
2488 return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
2489}
2490
2491DEFUN (no_match_ip_next_hop,
2492 no_match_ip_next_hop_cmd,
2493 "no match ip next-hop",
2494 NO_STR
2495 MATCH_STR
2496 IP_STR
2497 "Match next-hop address of route\n")
2498{
2499 if (argc == 0)
2500 return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
2501
2502 return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
2503}
2504
2505ALIAS (no_match_ip_next_hop,
2506 no_match_ip_next_hop_val_cmd,
2507 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2508 NO_STR
2509 MATCH_STR
2510 IP_STR
2511 "Match next-hop address of route\n"
2512 "IP access-list number\n"
2513 "IP access-list number (expanded range)\n"
2514 "IP Access-list name\n")
2515
Vyacheslav Trushkin1c8afb72011-11-22 20:15:10 +04002516/* match probability { */
2517
2518DEFUN (match_probability,
2519 match_probability_cmd,
2520 "match probability <0-100>",
2521 MATCH_STR
2522 "Match portion of routes defined by percentage value\n"
2523 "Percentage of routes\n")
2524{
2525 return bgp_route_match_add (vty, vty->index, "probability", argv[0]);
2526}
2527
2528DEFUN (no_match_probability,
2529 no_match_probability_cmd,
2530 "no match probability",
2531 NO_STR
2532 MATCH_STR
2533 "Match portion of routes defined by percentage value\n")
2534{
2535 return bgp_route_match_delete (vty, vty->index, "probability", argc ? argv[0] : NULL);
2536}
2537
2538ALIAS (no_match_probability,
2539 no_match_probability_val_cmd,
2540 "no match probability <1-99>",
2541 NO_STR
2542 MATCH_STR
2543 "Match portion of routes defined by percentage value\n"
2544 "Percentage of routes\n")
2545
2546/* } */
2547
hassoc1643bb2005-02-02 16:43:17 +00002548DEFUN (match_ip_route_source,
2549 match_ip_route_source_cmd,
2550 "match ip route-source (<1-199>|<1300-2699>|WORD)",
2551 MATCH_STR
2552 IP_STR
2553 "Match advertising source address of route\n"
2554 "IP access-list number\n"
2555 "IP access-list number (expanded range)\n"
2556 "IP standard access-list name\n")
2557{
2558 return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]);
2559}
2560
2561DEFUN (no_match_ip_route_source,
2562 no_match_ip_route_source_cmd,
2563 "no match ip route-source",
2564 NO_STR
2565 MATCH_STR
2566 IP_STR
2567 "Match advertising source address of route\n")
2568{
2569 if (argc == 0)
2570 return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL);
2571
2572 return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]);
2573}
2574
2575ALIAS (no_match_ip_route_source,
2576 no_match_ip_route_source_val_cmd,
2577 "no match ip route-source (<1-199>|<1300-2699>|WORD)",
2578 NO_STR
2579 MATCH_STR
2580 IP_STR
2581 "Match advertising source address of route\n"
2582 "IP access-list number\n"
2583 "IP access-list number (expanded range)\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002584 "IP standard access-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002585
paul718e3742002-12-13 20:15:29 +00002586DEFUN (match_ip_address_prefix_list,
2587 match_ip_address_prefix_list_cmd,
2588 "match ip address prefix-list WORD",
2589 MATCH_STR
2590 IP_STR
2591 "Match address of route\n"
2592 "Match entries of prefix-lists\n"
2593 "IP prefix-list name\n")
2594{
2595 return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
2596}
2597
2598DEFUN (no_match_ip_address_prefix_list,
2599 no_match_ip_address_prefix_list_cmd,
2600 "no match ip address prefix-list",
2601 NO_STR
2602 MATCH_STR
2603 IP_STR
2604 "Match address of route\n"
2605 "Match entries of prefix-lists\n")
2606{
2607 if (argc == 0)
2608 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
2609
2610 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
2611}
2612
2613ALIAS (no_match_ip_address_prefix_list,
2614 no_match_ip_address_prefix_list_val_cmd,
2615 "no match ip address prefix-list WORD",
2616 NO_STR
2617 MATCH_STR
2618 IP_STR
2619 "Match address of route\n"
2620 "Match entries of prefix-lists\n"
2621 "IP prefix-list name\n")
2622
2623DEFUN (match_ip_next_hop_prefix_list,
2624 match_ip_next_hop_prefix_list_cmd,
2625 "match ip next-hop prefix-list WORD",
2626 MATCH_STR
2627 IP_STR
2628 "Match next-hop address of route\n"
2629 "Match entries of prefix-lists\n"
2630 "IP prefix-list name\n")
2631{
2632 return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2633}
2634
2635DEFUN (no_match_ip_next_hop_prefix_list,
2636 no_match_ip_next_hop_prefix_list_cmd,
2637 "no match ip next-hop prefix-list",
2638 NO_STR
2639 MATCH_STR
2640 IP_STR
2641 "Match next-hop address of route\n"
2642 "Match entries of prefix-lists\n")
2643{
2644 if (argc == 0)
2645 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
2646
2647 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2648}
2649
2650ALIAS (no_match_ip_next_hop_prefix_list,
2651 no_match_ip_next_hop_prefix_list_val_cmd,
2652 "no match ip next-hop prefix-list WORD",
2653 NO_STR
2654 MATCH_STR
2655 IP_STR
2656 "Match next-hop address of route\n"
2657 "Match entries of prefix-lists\n"
2658 "IP prefix-list name\n")
2659
hassoc1643bb2005-02-02 16:43:17 +00002660DEFUN (match_ip_route_source_prefix_list,
2661 match_ip_route_source_prefix_list_cmd,
2662 "match ip route-source prefix-list WORD",
2663 MATCH_STR
2664 IP_STR
2665 "Match advertising source address of route\n"
2666 "Match entries of prefix-lists\n"
2667 "IP prefix-list name\n")
2668{
2669 return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]);
2670}
2671
2672DEFUN (no_match_ip_route_source_prefix_list,
2673 no_match_ip_route_source_prefix_list_cmd,
2674 "no match ip route-source prefix-list",
2675 NO_STR
2676 MATCH_STR
2677 IP_STR
2678 "Match advertising source address of route\n"
2679 "Match entries of prefix-lists\n")
2680{
2681 if (argc == 0)
2682 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL);
2683
2684 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]);
2685}
2686
2687ALIAS (no_match_ip_route_source_prefix_list,
2688 no_match_ip_route_source_prefix_list_val_cmd,
2689 "no match ip route-source prefix-list WORD",
2690 NO_STR
2691 MATCH_STR
2692 IP_STR
2693 "Match advertising source address of route\n"
2694 "Match entries of prefix-lists\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002695 "IP prefix-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002696
paul718e3742002-12-13 20:15:29 +00002697DEFUN (match_metric,
2698 match_metric_cmd,
2699 "match metric <0-4294967295>",
2700 MATCH_STR
2701 "Match metric of route\n"
2702 "Metric value\n")
2703{
2704 return bgp_route_match_add (vty, vty->index, "metric", argv[0]);
2705}
2706
2707DEFUN (no_match_metric,
2708 no_match_metric_cmd,
2709 "no match metric",
2710 NO_STR
2711 MATCH_STR
2712 "Match metric of route\n")
2713{
2714 if (argc == 0)
2715 return bgp_route_match_delete (vty, vty->index, "metric", NULL);
2716
2717 return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);
2718}
2719
2720ALIAS (no_match_metric,
2721 no_match_metric_val_cmd,
2722 "no match metric <0-4294967295>",
2723 NO_STR
2724 MATCH_STR
2725 "Match metric of route\n"
2726 "Metric value\n")
2727
2728DEFUN (match_community,
2729 match_community_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002730 "match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002731 MATCH_STR
2732 "Match BGP community list\n"
2733 "Community-list number (standard)\n"
2734 "Community-list number (expanded)\n"
2735 "Community-list name\n")
2736{
2737 return bgp_route_match_add (vty, vty->index, "community", argv[0]);
2738}
2739
2740DEFUN (match_community_exact,
2741 match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002742 "match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002743 MATCH_STR
2744 "Match BGP community list\n"
2745 "Community-list number (standard)\n"
2746 "Community-list number (expanded)\n"
2747 "Community-list name\n"
2748 "Do exact matching of communities\n")
2749{
2750 int ret;
2751 char *argstr;
2752
2753 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
2754 strlen (argv[0]) + strlen ("exact-match") + 2);
2755
2756 sprintf (argstr, "%s exact-match", argv[0]);
2757
2758 ret = bgp_route_match_add (vty, vty->index, "community", argstr);
2759
2760 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
2761
2762 return ret;
2763}
2764
2765DEFUN (no_match_community,
2766 no_match_community_cmd,
2767 "no match community",
2768 NO_STR
2769 MATCH_STR
2770 "Match BGP community list\n")
2771{
2772 return bgp_route_match_delete (vty, vty->index, "community", NULL);
2773}
2774
2775ALIAS (no_match_community,
2776 no_match_community_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002777 "no match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002778 NO_STR
2779 MATCH_STR
2780 "Match BGP community list\n"
2781 "Community-list number (standard)\n"
2782 "Community-list number (expanded)\n"
2783 "Community-list name\n")
2784
2785ALIAS (no_match_community,
2786 no_match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002787 "no match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002788 NO_STR
2789 MATCH_STR
2790 "Match BGP community list\n"
2791 "Community-list number (standard)\n"
2792 "Community-list number (expanded)\n"
2793 "Community-list name\n"
2794 "Do exact matching of communities\n")
2795
paul73ffb252003-04-19 15:49:49 +00002796DEFUN (match_ecommunity,
2797 match_ecommunity_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002798 "match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002799 MATCH_STR
2800 "Match BGP/VPN extended community list\n"
2801 "Extended community-list number (standard)\n"
2802 "Extended community-list number (expanded)\n"
2803 "Extended community-list name\n")
2804{
2805 return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]);
2806}
2807
2808DEFUN (no_match_ecommunity,
2809 no_match_ecommunity_cmd,
2810 "no match extcommunity",
2811 NO_STR
2812 MATCH_STR
2813 "Match BGP/VPN extended community list\n")
2814{
2815 return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL);
2816}
2817
2818ALIAS (no_match_ecommunity,
2819 no_match_ecommunity_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002820 "no match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002821 NO_STR
2822 MATCH_STR
2823 "Match BGP/VPN extended community list\n"
2824 "Extended community-list number (standard)\n"
2825 "Extended community-list number (expanded)\n"
2826 "Extended community-list name\n")
2827
paul718e3742002-12-13 20:15:29 +00002828DEFUN (match_aspath,
2829 match_aspath_cmd,
2830 "match as-path WORD",
2831 MATCH_STR
2832 "Match BGP AS path list\n"
2833 "AS path access-list name\n")
2834{
2835 return bgp_route_match_add (vty, vty->index, "as-path", argv[0]);
2836}
2837
2838DEFUN (no_match_aspath,
2839 no_match_aspath_cmd,
2840 "no match as-path",
2841 NO_STR
2842 MATCH_STR
2843 "Match BGP AS path list\n")
2844{
2845 return bgp_route_match_delete (vty, vty->index, "as-path", NULL);
2846}
2847
2848ALIAS (no_match_aspath,
2849 no_match_aspath_val_cmd,
2850 "no match as-path WORD",
2851 NO_STR
2852 MATCH_STR
2853 "Match BGP AS path list\n"
2854 "AS path access-list name\n")
2855
2856DEFUN (match_origin,
2857 match_origin_cmd,
2858 "match origin (egp|igp|incomplete)",
2859 MATCH_STR
2860 "BGP origin code\n"
2861 "remote EGP\n"
2862 "local IGP\n"
2863 "unknown heritage\n")
2864{
2865 if (strncmp (argv[0], "igp", 2) == 0)
2866 return bgp_route_match_add (vty, vty->index, "origin", "igp");
2867 if (strncmp (argv[0], "egp", 1) == 0)
2868 return bgp_route_match_add (vty, vty->index, "origin", "egp");
2869 if (strncmp (argv[0], "incomplete", 2) == 0)
2870 return bgp_route_match_add (vty, vty->index, "origin", "incomplete");
2871
2872 return CMD_WARNING;
2873}
2874
2875DEFUN (no_match_origin,
2876 no_match_origin_cmd,
2877 "no match origin",
2878 NO_STR
2879 MATCH_STR
2880 "BGP origin code\n")
2881{
2882 return bgp_route_match_delete (vty, vty->index, "origin", NULL);
2883}
2884
2885ALIAS (no_match_origin,
2886 no_match_origin_val_cmd,
2887 "no match origin (egp|igp|incomplete)",
2888 NO_STR
2889 MATCH_STR
2890 "BGP origin code\n"
2891 "remote EGP\n"
2892 "local IGP\n"
2893 "unknown heritage\n")
2894
2895DEFUN (set_ip_nexthop,
2896 set_ip_nexthop_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002897 "set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002898 SET_STR
2899 IP_STR
2900 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002901 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002902{
2903 union sockunion su;
2904 int ret;
2905
2906 ret = str2sockunion (argv[0], &su);
2907 if (ret < 0)
2908 {
2909 vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
2910 return CMD_WARNING;
2911 }
2912
2913 return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
2914}
2915
paulaf5cd0a2003-11-02 07:24:40 +00002916DEFUN (set_ip_nexthop_peer,
2917 set_ip_nexthop_peer_cmd,
2918 "set ip next-hop peer-address",
2919 SET_STR
2920 IP_STR
2921 "Next hop address\n"
2922 "Use peer address (for BGP only)\n")
2923{
2924 return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address");
2925}
2926
paul94f2b392005-06-28 12:44:16 +00002927DEFUN_DEPRECATED (no_set_ip_nexthop_peer,
paulaf5cd0a2003-11-02 07:24:40 +00002928 no_set_ip_nexthop_peer_cmd,
2929 "no set ip next-hop peer-address",
2930 NO_STR
2931 SET_STR
2932 IP_STR
2933 "Next hop address\n"
2934 "Use peer address (for BGP only)\n")
2935{
2936 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2937}
2938
2939
paul718e3742002-12-13 20:15:29 +00002940DEFUN (no_set_ip_nexthop,
2941 no_set_ip_nexthop_cmd,
2942 "no set ip next-hop",
2943 NO_STR
2944 SET_STR
paul718e3742002-12-13 20:15:29 +00002945 "Next hop address\n")
2946{
paulaf5cd0a2003-11-02 07:24:40 +00002947 if (argc == 0)
paul718e3742002-12-13 20:15:29 +00002948 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2949
2950 return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
2951}
2952
2953ALIAS (no_set_ip_nexthop,
2954 no_set_ip_nexthop_val_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002955 "no set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002956 NO_STR
2957 SET_STR
2958 IP_STR
2959 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002960 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002961
2962DEFUN (set_metric,
2963 set_metric_cmd,
paul73ffb252003-04-19 15:49:49 +00002964 "set metric <0-4294967295>",
paul718e3742002-12-13 20:15:29 +00002965 SET_STR
2966 "Metric value for destination routing protocol\n"
paul73ffb252003-04-19 15:49:49 +00002967 "Metric value\n")
paul718e3742002-12-13 20:15:29 +00002968{
2969 return bgp_route_set_add (vty, vty->index, "metric", argv[0]);
2970}
2971
paul73ffb252003-04-19 15:49:49 +00002972ALIAS (set_metric,
2973 set_metric_addsub_cmd,
2974 "set metric <+/-metric>",
2975 SET_STR
2976 "Metric value for destination routing protocol\n"
hasso033e8612005-05-28 04:50:54 +00002977 "Add or subtract metric\n")
paul73ffb252003-04-19 15:49:49 +00002978
paul718e3742002-12-13 20:15:29 +00002979DEFUN (no_set_metric,
2980 no_set_metric_cmd,
2981 "no set metric",
2982 NO_STR
2983 SET_STR
2984 "Metric value for destination routing protocol\n")
2985{
2986 if (argc == 0)
2987 return bgp_route_set_delete (vty, vty->index, "metric", NULL);
2988
2989 return bgp_route_set_delete (vty, vty->index, "metric", argv[0]);
2990}
2991
2992ALIAS (no_set_metric,
2993 no_set_metric_val_cmd,
2994 "no set metric <0-4294967295>",
2995 NO_STR
2996 SET_STR
2997 "Metric value for destination routing protocol\n"
2998 "Metric value\n")
2999
3000DEFUN (set_local_pref,
3001 set_local_pref_cmd,
3002 "set local-preference <0-4294967295>",
3003 SET_STR
3004 "BGP local preference path attribute\n"
3005 "Preference value\n")
3006{
3007 return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]);
3008}
3009
3010DEFUN (no_set_local_pref,
3011 no_set_local_pref_cmd,
3012 "no set local-preference",
3013 NO_STR
3014 SET_STR
3015 "BGP local preference path attribute\n")
3016{
3017 if (argc == 0)
3018 return bgp_route_set_delete (vty, vty->index, "local-preference", NULL);
3019
3020 return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]);
3021}
3022
3023ALIAS (no_set_local_pref,
3024 no_set_local_pref_val_cmd,
3025 "no set local-preference <0-4294967295>",
3026 NO_STR
3027 SET_STR
3028 "BGP local preference path attribute\n"
3029 "Preference value\n")
3030
3031DEFUN (set_weight,
3032 set_weight_cmd,
3033 "set weight <0-4294967295>",
3034 SET_STR
3035 "BGP weight for routing table\n"
3036 "Weight value\n")
3037{
3038 return bgp_route_set_add (vty, vty->index, "weight", argv[0]);
3039}
3040
3041DEFUN (no_set_weight,
3042 no_set_weight_cmd,
3043 "no set weight",
3044 NO_STR
3045 SET_STR
3046 "BGP weight for routing table\n")
3047{
3048 if (argc == 0)
3049 return bgp_route_set_delete (vty, vty->index, "weight", NULL);
3050
3051 return bgp_route_set_delete (vty, vty->index, "weight", argv[0]);
3052}
3053
3054ALIAS (no_set_weight,
3055 no_set_weight_val_cmd,
3056 "no set weight <0-4294967295>",
3057 NO_STR
3058 SET_STR
3059 "BGP weight for routing table\n"
3060 "Weight value\n")
3061
3062DEFUN (set_aspath_prepend,
3063 set_aspath_prepend_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003064 "set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003065 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003066 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003067 "Prepend to the as-path\n"
3068 "AS number\n")
3069{
3070 int ret;
3071 char *str;
3072
3073 str = argv_concat (argv, argc, 0);
3074 ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str);
3075 XFREE (MTYPE_TMP, str);
3076
3077 return ret;
3078}
3079
3080DEFUN (no_set_aspath_prepend,
3081 no_set_aspath_prepend_cmd,
3082 "no set as-path prepend",
3083 NO_STR
3084 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003085 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003086 "Prepend to the as-path\n")
3087{
Denis Ovsienkoa7f93f32007-12-18 15:13:06 +00003088 int ret;
3089 char *str;
3090
3091 if (argc == 0)
3092 return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL);
3093
3094 str = argv_concat (argv, argc, 0);
3095 ret = bgp_route_set_delete (vty, vty->index, "as-path prepend", str);
3096 XFREE (MTYPE_TMP, str);
3097 return ret;
paul718e3742002-12-13 20:15:29 +00003098}
3099
3100ALIAS (no_set_aspath_prepend,
3101 no_set_aspath_prepend_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003102 "no set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003103 NO_STR
3104 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003105 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003106 "Prepend to the as-path\n"
3107 "AS number\n")
3108
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003109DEFUN (set_aspath_exclude,
3110 set_aspath_exclude_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003111 "set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003112 SET_STR
3113 "Transform BGP AS-path attribute\n"
3114 "Exclude from the as-path\n"
3115 "AS number\n")
3116{
3117 int ret;
3118 char *str;
3119
3120 str = argv_concat (argv, argc, 0);
3121 ret = bgp_route_set_add (vty, vty->index, "as-path exclude", str);
3122 XFREE (MTYPE_TMP, str);
3123 return ret;
3124}
3125
3126DEFUN (no_set_aspath_exclude,
3127 no_set_aspath_exclude_cmd,
3128 "no set as-path exclude",
3129 NO_STR
3130 SET_STR
3131 "Transform BGP AS_PATH attribute\n"
3132 "Exclude from the as-path\n")
3133{
3134 int ret;
3135 char *str;
3136
3137 if (argc == 0)
3138 return bgp_route_set_delete (vty, vty->index, "as-path exclude", NULL);
3139
3140 str = argv_concat (argv, argc, 0);
3141 ret = bgp_route_set_delete (vty, vty->index, "as-path exclude", str);
3142 XFREE (MTYPE_TMP, str);
3143 return ret;
3144}
3145
3146ALIAS (no_set_aspath_exclude,
3147 no_set_aspath_exclude_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003148 "no set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003149 NO_STR
3150 SET_STR
3151 "Transform BGP AS_PATH attribute\n"
3152 "Exclude from the as-path\n"
3153 "AS number\n")
3154
paul718e3742002-12-13 20:15:29 +00003155DEFUN (set_community,
3156 set_community_cmd,
3157 "set community .AA:NN",
3158 SET_STR
3159 "BGP community attribute\n"
3160 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3161{
3162 int i;
3163 int first = 0;
3164 int additive = 0;
3165 struct buffer *b;
3166 struct community *com = NULL;
3167 char *str;
3168 char *argstr;
3169 int ret;
3170
3171 b = buffer_new (1024);
3172
3173 for (i = 0; i < argc; i++)
3174 {
3175 if (strncmp (argv[i], "additive", strlen (argv[i])) == 0)
3176 {
3177 additive = 1;
3178 continue;
3179 }
3180
3181 if (first)
3182 buffer_putc (b, ' ');
3183 else
3184 first = 1;
3185
3186 if (strncmp (argv[i], "internet", strlen (argv[i])) == 0)
3187 {
3188 buffer_putstr (b, "internet");
3189 continue;
3190 }
3191 if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0)
3192 {
3193 buffer_putstr (b, "local-AS");
3194 continue;
3195 }
3196 if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0
3197 && strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0)
3198 {
3199 buffer_putstr (b, "no-advertise");
3200 continue;
3201 }
3202 if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0
3203 && strncmp (argv[i], "no-export", strlen (argv[i])) == 0)
3204 {
3205 buffer_putstr (b, "no-export");
3206 continue;
3207 }
3208 buffer_putstr (b, argv[i]);
3209 }
3210 buffer_putc (b, '\0');
3211
3212 /* Fetch result string then compile it to communities attribute. */
3213 str = buffer_getstr (b);
3214 buffer_free (b);
3215
3216 if (str)
3217 {
3218 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00003219 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00003220 }
3221
3222 /* Can't compile user input into communities attribute. */
3223 if (! com)
3224 {
3225 vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE);
3226 return CMD_WARNING;
3227 }
3228
3229 /* Set communites attribute string. */
3230 str = community_str (com);
3231
3232 if (additive)
3233 {
3234 argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1);
3235 strcpy (argstr, str);
3236 strcpy (argstr + strlen (str), " additive");
3237 ret = bgp_route_set_add (vty, vty->index, "community", argstr);
3238 XFREE (MTYPE_TMP, argstr);
3239 }
3240 else
3241 ret = bgp_route_set_add (vty, vty->index, "community", str);
3242
3243 community_free (com);
3244
3245 return ret;
3246}
3247
3248DEFUN (set_community_none,
3249 set_community_none_cmd,
3250 "set community none",
3251 SET_STR
3252 "BGP community attribute\n"
3253 "No community attribute\n")
3254{
3255 return bgp_route_set_add (vty, vty->index, "community", "none");
3256}
3257
3258DEFUN (no_set_community,
3259 no_set_community_cmd,
3260 "no set community",
3261 NO_STR
3262 SET_STR
3263 "BGP community attribute\n")
3264{
3265 return bgp_route_set_delete (vty, vty->index, "community", NULL);
3266}
3267
3268ALIAS (no_set_community,
3269 no_set_community_val_cmd,
3270 "no set community .AA:NN",
3271 NO_STR
3272 SET_STR
3273 "BGP community attribute\n"
3274 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3275
3276ALIAS (no_set_community,
3277 no_set_community_none_cmd,
3278 "no set community none",
3279 NO_STR
3280 SET_STR
3281 "BGP community attribute\n"
3282 "No community attribute\n")
3283
3284DEFUN (set_community_delete,
3285 set_community_delete_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003286 "set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003287 SET_STR
3288 "set BGP community list (for deletion)\n"
3289 "Community-list number (standard)\n"
3290 "Communitly-list number (expanded)\n"
3291 "Community-list name\n"
3292 "Delete matching communities\n")
3293{
3294 char *str;
3295
3296 str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1);
3297 strcpy (str, argv[0]);
3298 strcpy (str + strlen (argv[0]), " delete");
3299
3300 bgp_route_set_add (vty, vty->index, "comm-list", str);
3301
3302 XFREE (MTYPE_TMP, str);
3303 return CMD_SUCCESS;
3304}
3305
3306DEFUN (no_set_community_delete,
3307 no_set_community_delete_cmd,
3308 "no set comm-list",
3309 NO_STR
3310 SET_STR
3311 "set BGP community list (for deletion)\n")
3312{
3313 return bgp_route_set_delete (vty, vty->index, "comm-list", NULL);
3314}
3315
3316ALIAS (no_set_community_delete,
3317 no_set_community_delete_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003318 "no set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003319 NO_STR
3320 SET_STR
3321 "set BGP community list (for deletion)\n"
3322 "Community-list number (standard)\n"
3323 "Communitly-list number (expanded)\n"
3324 "Community-list name\n"
3325 "Delete matching communities\n")
3326
3327DEFUN (set_ecommunity_rt,
3328 set_ecommunity_rt_cmd,
3329 "set extcommunity rt .ASN:nn_or_IP-address:nn",
3330 SET_STR
3331 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003332 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003333 "VPN extended community\n")
3334{
3335 int ret;
3336 char *str;
3337
3338 str = argv_concat (argv, argc, 0);
3339 ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str);
3340 XFREE (MTYPE_TMP, str);
3341
3342 return ret;
3343}
3344
3345DEFUN (no_set_ecommunity_rt,
3346 no_set_ecommunity_rt_cmd,
3347 "no set extcommunity rt",
3348 NO_STR
3349 SET_STR
3350 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003351 "Route Target extended community\n")
paul718e3742002-12-13 20:15:29 +00003352{
3353 return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL);
3354}
3355
3356ALIAS (no_set_ecommunity_rt,
3357 no_set_ecommunity_rt_val_cmd,
3358 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
3359 NO_STR
3360 SET_STR
3361 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003362 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003363 "VPN extended community\n")
3364
3365DEFUN (set_ecommunity_soo,
3366 set_ecommunity_soo_cmd,
3367 "set extcommunity soo .ASN:nn_or_IP-address:nn",
3368 SET_STR
3369 "BGP extended community attribute\n"
3370 "Site-of-Origin extended community\n"
3371 "VPN extended community\n")
3372{
3373 int ret;
3374 char *str;
3375
3376 str = argv_concat (argv, argc, 0);
3377 ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str);
3378 XFREE (MTYPE_TMP, str);
3379 return ret;
3380}
3381
3382DEFUN (no_set_ecommunity_soo,
3383 no_set_ecommunity_soo_cmd,
3384 "no set extcommunity soo",
3385 NO_STR
3386 SET_STR
3387 "BGP extended community attribute\n"
3388 "Site-of-Origin extended community\n")
3389{
3390 return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL);
3391}
3392
3393ALIAS (no_set_ecommunity_soo,
3394 no_set_ecommunity_soo_val_cmd,
3395 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
3396 NO_STR
3397 SET_STR
3398 "BGP extended community attribute\n"
3399 "Site-of-Origin extended community\n"
3400 "VPN extended community\n")
3401
3402DEFUN (set_origin,
3403 set_origin_cmd,
3404 "set origin (egp|igp|incomplete)",
3405 SET_STR
3406 "BGP origin code\n"
3407 "remote EGP\n"
3408 "local IGP\n"
3409 "unknown heritage\n")
3410{
3411 if (strncmp (argv[0], "igp", 2) == 0)
3412 return bgp_route_set_add (vty, vty->index, "origin", "igp");
3413 if (strncmp (argv[0], "egp", 1) == 0)
3414 return bgp_route_set_add (vty, vty->index, "origin", "egp");
3415 if (strncmp (argv[0], "incomplete", 2) == 0)
3416 return bgp_route_set_add (vty, vty->index, "origin", "incomplete");
3417
3418 return CMD_WARNING;
3419}
3420
3421DEFUN (no_set_origin,
3422 no_set_origin_cmd,
3423 "no set origin",
3424 NO_STR
3425 SET_STR
3426 "BGP origin code\n")
3427{
3428 return bgp_route_set_delete (vty, vty->index, "origin", NULL);
3429}
3430
3431ALIAS (no_set_origin,
3432 no_set_origin_val_cmd,
3433 "no set origin (egp|igp|incomplete)",
3434 NO_STR
3435 SET_STR
3436 "BGP origin code\n"
3437 "remote EGP\n"
3438 "local IGP\n"
3439 "unknown heritage\n")
3440
3441DEFUN (set_atomic_aggregate,
3442 set_atomic_aggregate_cmd,
3443 "set atomic-aggregate",
3444 SET_STR
3445 "BGP atomic aggregate attribute\n" )
3446{
3447 return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL);
3448}
3449
3450DEFUN (no_set_atomic_aggregate,
3451 no_set_atomic_aggregate_cmd,
3452 "no set atomic-aggregate",
3453 NO_STR
3454 SET_STR
3455 "BGP atomic aggregate attribute\n" )
3456{
3457 return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL);
3458}
3459
3460DEFUN (set_aggregator_as,
3461 set_aggregator_as_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003462 "set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003463 SET_STR
3464 "BGP aggregator attribute\n"
3465 "AS number of aggregator\n"
3466 "AS number\n"
3467 "IP address of aggregator\n")
3468{
3469 int ret;
3470 as_t as;
3471 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003472 char *argstr;
3473
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003474 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paulfd79ac92004-10-13 05:06:08 +00003475
paul718e3742002-12-13 20:15:29 +00003476 ret = inet_aton (argv[1], &address);
3477 if (ret == 0)
3478 {
3479 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3480 return CMD_WARNING;
3481 }
3482
3483 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3484 strlen (argv[0]) + strlen (argv[1]) + 2);
3485
3486 sprintf (argstr, "%s %s", argv[0], argv[1]);
3487
3488 ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr);
3489
3490 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3491
3492 return ret;
3493}
3494
3495DEFUN (no_set_aggregator_as,
3496 no_set_aggregator_as_cmd,
3497 "no set aggregator as",
3498 NO_STR
3499 SET_STR
3500 "BGP aggregator attribute\n"
3501 "AS number of aggregator\n")
3502{
3503 int ret;
3504 as_t as;
3505 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003506 char *argstr;
3507
3508 if (argv == 0)
3509 return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL);
3510
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003511 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paul718e3742002-12-13 20:15:29 +00003512
3513 ret = inet_aton (argv[1], &address);
3514 if (ret == 0)
3515 {
3516 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3517 return CMD_WARNING;
3518 }
3519
3520 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3521 strlen (argv[0]) + strlen (argv[1]) + 2);
3522
3523 sprintf (argstr, "%s %s", argv[0], argv[1]);
3524
3525 ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr);
3526
3527 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3528
3529 return ret;
3530}
3531
3532ALIAS (no_set_aggregator_as,
3533 no_set_aggregator_as_val_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003534 "no set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003535 NO_STR
3536 SET_STR
3537 "BGP aggregator attribute\n"
3538 "AS number of aggregator\n"
3539 "AS number\n"
3540 "IP address of aggregator\n")
3541
3542
3543#ifdef HAVE_IPV6
3544DEFUN (match_ipv6_address,
3545 match_ipv6_address_cmd,
3546 "match ipv6 address WORD",
3547 MATCH_STR
3548 IPV6_STR
3549 "Match IPv6 address of route\n"
3550 "IPv6 access-list name\n")
3551{
3552 return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]);
3553}
3554
3555DEFUN (no_match_ipv6_address,
3556 no_match_ipv6_address_cmd,
3557 "no match ipv6 address WORD",
3558 NO_STR
3559 MATCH_STR
3560 IPV6_STR
3561 "Match IPv6 address of route\n"
3562 "IPv6 access-list name\n")
3563{
3564 return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]);
3565}
3566
3567DEFUN (match_ipv6_next_hop,
3568 match_ipv6_next_hop_cmd,
3569 "match ipv6 next-hop X:X::X:X",
3570 MATCH_STR
3571 IPV6_STR
3572 "Match IPv6 next-hop address of route\n"
3573 "IPv6 address of next hop\n")
3574{
3575 return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]);
3576}
3577
3578DEFUN (no_match_ipv6_next_hop,
3579 no_match_ipv6_next_hop_cmd,
3580 "no match ipv6 next-hop X:X::X:X",
3581 NO_STR
3582 MATCH_STR
3583 IPV6_STR
3584 "Match IPv6 next-hop address of route\n"
3585 "IPv6 address of next hop\n")
3586{
3587 return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
3588}
3589
3590DEFUN (match_ipv6_address_prefix_list,
3591 match_ipv6_address_prefix_list_cmd,
3592 "match ipv6 address prefix-list WORD",
3593 MATCH_STR
3594 IPV6_STR
3595 "Match address of route\n"
3596 "Match entries of prefix-lists\n"
3597 "IP prefix-list name\n")
3598{
3599 return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3600}
3601
3602DEFUN (no_match_ipv6_address_prefix_list,
3603 no_match_ipv6_address_prefix_list_cmd,
3604 "no match ipv6 address prefix-list WORD",
3605 NO_STR
3606 MATCH_STR
3607 IPV6_STR
3608 "Match address of route\n"
3609 "Match entries of prefix-lists\n"
3610 "IP prefix-list name\n")
3611{
3612 return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3613}
3614
3615DEFUN (set_ipv6_nexthop_global,
3616 set_ipv6_nexthop_global_cmd,
3617 "set ipv6 next-hop global X:X::X:X",
3618 SET_STR
3619 IPV6_STR
3620 "IPv6 next-hop address\n"
3621 "IPv6 global address\n"
3622 "IPv6 address of next hop\n")
3623{
3624 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]);
3625}
3626
3627DEFUN (no_set_ipv6_nexthop_global,
3628 no_set_ipv6_nexthop_global_cmd,
3629 "no set ipv6 next-hop global",
3630 NO_STR
3631 SET_STR
3632 IPV6_STR
3633 "IPv6 next-hop address\n"
3634 "IPv6 global address\n")
3635{
3636 if (argc == 0)
3637 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL);
3638
3639 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]);
3640}
3641
3642ALIAS (no_set_ipv6_nexthop_global,
3643 no_set_ipv6_nexthop_global_val_cmd,
3644 "no set ipv6 next-hop global X:X::X:X",
3645 NO_STR
3646 SET_STR
3647 IPV6_STR
3648 "IPv6 next-hop address\n"
3649 "IPv6 global address\n"
3650 "IPv6 address of next hop\n")
3651
3652DEFUN (set_ipv6_nexthop_local,
3653 set_ipv6_nexthop_local_cmd,
3654 "set ipv6 next-hop local X:X::X:X",
3655 SET_STR
3656 IPV6_STR
3657 "IPv6 next-hop address\n"
3658 "IPv6 local address\n"
3659 "IPv6 address of next hop\n")
3660{
3661 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
3662}
3663
3664DEFUN (no_set_ipv6_nexthop_local,
3665 no_set_ipv6_nexthop_local_cmd,
3666 "no set ipv6 next-hop local",
3667 NO_STR
3668 SET_STR
3669 IPV6_STR
3670 "IPv6 next-hop address\n"
3671 "IPv6 local address\n")
3672{
3673 if (argc == 0)
3674 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
3675
3676 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
3677}
3678
3679ALIAS (no_set_ipv6_nexthop_local,
3680 no_set_ipv6_nexthop_local_val_cmd,
3681 "no set ipv6 next-hop local X:X::X:X",
3682 NO_STR
3683 SET_STR
3684 IPV6_STR
3685 "IPv6 next-hop address\n"
3686 "IPv6 local address\n"
3687 "IPv6 address of next hop\n")
3688#endif /* HAVE_IPV6 */
3689
3690DEFUN (set_vpnv4_nexthop,
3691 set_vpnv4_nexthop_cmd,
3692 "set vpnv4 next-hop A.B.C.D",
3693 SET_STR
3694 "VPNv4 information\n"
3695 "VPNv4 next-hop address\n"
3696 "IP address of next hop\n")
3697{
3698 return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]);
3699}
3700
3701DEFUN (no_set_vpnv4_nexthop,
3702 no_set_vpnv4_nexthop_cmd,
3703 "no set vpnv4 next-hop",
3704 NO_STR
3705 SET_STR
3706 "VPNv4 information\n"
3707 "VPNv4 next-hop address\n")
3708{
3709 if (argc == 0)
3710 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL);
3711
3712 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]);
3713}
3714
3715ALIAS (no_set_vpnv4_nexthop,
3716 no_set_vpnv4_nexthop_val_cmd,
3717 "no set vpnv4 next-hop A.B.C.D",
3718 NO_STR
3719 SET_STR
3720 "VPNv4 information\n"
3721 "VPNv4 next-hop address\n"
3722 "IP address of next hop\n")
3723
3724DEFUN (set_originator_id,
3725 set_originator_id_cmd,
3726 "set originator-id A.B.C.D",
3727 SET_STR
3728 "BGP originator ID attribute\n"
3729 "IP address of originator\n")
3730{
3731 return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]);
3732}
3733
3734DEFUN (no_set_originator_id,
3735 no_set_originator_id_cmd,
3736 "no set originator-id",
3737 NO_STR
3738 SET_STR
3739 "BGP originator ID attribute\n")
3740{
3741 if (argc == 0)
3742 return bgp_route_set_delete (vty, vty->index, "originator-id", NULL);
3743
3744 return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]);
3745}
3746
3747ALIAS (no_set_originator_id,
3748 no_set_originator_id_val_cmd,
3749 "no set originator-id A.B.C.D",
3750 NO_STR
3751 SET_STR
3752 "BGP originator ID attribute\n"
3753 "IP address of originator\n")
3754
Paul Jakmae70e5752011-07-05 00:41:59 +04003755DEFUN_DEPRECATED (set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003756 set_pathlimit_ttl_cmd,
3757 "set pathlimit ttl <1-255>",
3758 SET_STR
3759 "BGP AS-Pathlimit attribute\n"
3760 "Set AS-Path Hop-count TTL\n")
3761{
Paul Jakmae70e5752011-07-05 00:41:59 +04003762 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003763}
3764
Paul Jakmae70e5752011-07-05 00:41:59 +04003765DEFUN_DEPRECATED (no_set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003766 no_set_pathlimit_ttl_cmd,
3767 "no set pathlimit ttl",
3768 NO_STR
3769 SET_STR
3770 "BGP AS-Pathlimit attribute\n"
3771 "Set AS-Path Hop-count TTL\n")
3772{
Paul Jakmae70e5752011-07-05 00:41:59 +04003773 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003774}
3775
3776ALIAS (no_set_pathlimit_ttl,
3777 no_set_pathlimit_ttl_val_cmd,
3778 "no set pathlimit ttl <1-255>",
3779 NO_STR
3780 MATCH_STR
3781 "BGP AS-Pathlimit attribute\n"
3782 "Set AS-Path Hop-count TTL\n")
3783
Paul Jakmae70e5752011-07-05 00:41:59 +04003784DEFUN_DEPRECATED (match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003785 match_pathlimit_as_cmd,
3786 "match pathlimit as <1-65535>",
3787 MATCH_STR
3788 "BGP AS-Pathlimit attribute\n"
3789 "Match Pathlimit AS number\n")
3790{
Paul Jakmae70e5752011-07-05 00:41:59 +04003791 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003792}
3793
Paul Jakmae70e5752011-07-05 00:41:59 +04003794DEFUN_DEPRECATED (no_match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003795 no_match_pathlimit_as_cmd,
3796 "no match pathlimit as",
3797 NO_STR
3798 MATCH_STR
3799 "BGP AS-Pathlimit attribute\n"
3800 "Match Pathlimit AS number\n")
3801{
Paul Jakmae70e5752011-07-05 00:41:59 +04003802 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003803}
3804
3805ALIAS (no_match_pathlimit_as,
3806 no_match_pathlimit_as_val_cmd,
3807 "no match pathlimit as <1-65535>",
3808 NO_STR
3809 MATCH_STR
3810 "BGP AS-Pathlimit attribute\n"
3811 "Match Pathlimit ASN\n")
3812
paul718e3742002-12-13 20:15:29 +00003813
3814/* Initialization of route map. */
3815void
paul94f2b392005-06-28 12:44:16 +00003816bgp_route_map_init (void)
paul718e3742002-12-13 20:15:29 +00003817{
3818 route_map_init ();
3819 route_map_init_vty ();
3820 route_map_add_hook (bgp_route_map_update);
3821 route_map_delete_hook (bgp_route_map_update);
3822
paulfee0f4c2004-09-13 05:12:46 +00003823 route_map_install_match (&route_match_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003824 route_map_install_match (&route_match_ip_address_cmd);
3825 route_map_install_match (&route_match_ip_next_hop_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003826 route_map_install_match (&route_match_ip_route_source_cmd);
paul718e3742002-12-13 20:15:29 +00003827 route_map_install_match (&route_match_ip_address_prefix_list_cmd);
3828 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003829 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +00003830 route_map_install_match (&route_match_aspath_cmd);
3831 route_map_install_match (&route_match_community_cmd);
paul73ffb252003-04-19 15:49:49 +00003832 route_map_install_match (&route_match_ecommunity_cmd);
paul718e3742002-12-13 20:15:29 +00003833 route_map_install_match (&route_match_metric_cmd);
3834 route_map_install_match (&route_match_origin_cmd);
Vyacheslav Trushkin1c8afb72011-11-22 20:15:10 +04003835 route_map_install_match (&route_match_probability_cmd);
paul718e3742002-12-13 20:15:29 +00003836
3837 route_map_install_set (&route_set_ip_nexthop_cmd);
3838 route_map_install_set (&route_set_local_pref_cmd);
3839 route_map_install_set (&route_set_weight_cmd);
3840 route_map_install_set (&route_set_metric_cmd);
3841 route_map_install_set (&route_set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003842 route_map_install_set (&route_set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003843 route_map_install_set (&route_set_origin_cmd);
3844 route_map_install_set (&route_set_atomic_aggregate_cmd);
3845 route_map_install_set (&route_set_aggregator_as_cmd);
3846 route_map_install_set (&route_set_community_cmd);
3847 route_map_install_set (&route_set_community_delete_cmd);
3848 route_map_install_set (&route_set_vpnv4_nexthop_cmd);
3849 route_map_install_set (&route_set_originator_id_cmd);
3850 route_map_install_set (&route_set_ecommunity_rt_cmd);
3851 route_map_install_set (&route_set_ecommunity_soo_cmd);
3852
paulfee0f4c2004-09-13 05:12:46 +00003853 install_element (RMAP_NODE, &match_peer_cmd);
3854 install_element (RMAP_NODE, &match_peer_local_cmd);
3855 install_element (RMAP_NODE, &no_match_peer_cmd);
3856 install_element (RMAP_NODE, &no_match_peer_val_cmd);
3857 install_element (RMAP_NODE, &no_match_peer_local_cmd);
paul718e3742002-12-13 20:15:29 +00003858 install_element (RMAP_NODE, &match_ip_address_cmd);
3859 install_element (RMAP_NODE, &no_match_ip_address_cmd);
3860 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
3861 install_element (RMAP_NODE, &match_ip_next_hop_cmd);
3862 install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
3863 install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003864 install_element (RMAP_NODE, &match_ip_route_source_cmd);
3865 install_element (RMAP_NODE, &no_match_ip_route_source_cmd);
3866 install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd);
paul718e3742002-12-13 20:15:29 +00003867 install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
3868 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
3869 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
3870 install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
3871 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
3872 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003873 install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
3874 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
3875 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd);
paul718e3742002-12-13 20:15:29 +00003876
3877 install_element (RMAP_NODE, &match_aspath_cmd);
3878 install_element (RMAP_NODE, &no_match_aspath_cmd);
3879 install_element (RMAP_NODE, &no_match_aspath_val_cmd);
3880 install_element (RMAP_NODE, &match_metric_cmd);
3881 install_element (RMAP_NODE, &no_match_metric_cmd);
3882 install_element (RMAP_NODE, &no_match_metric_val_cmd);
3883 install_element (RMAP_NODE, &match_community_cmd);
3884 install_element (RMAP_NODE, &match_community_exact_cmd);
3885 install_element (RMAP_NODE, &no_match_community_cmd);
3886 install_element (RMAP_NODE, &no_match_community_val_cmd);
3887 install_element (RMAP_NODE, &no_match_community_exact_cmd);
paul73ffb252003-04-19 15:49:49 +00003888 install_element (RMAP_NODE, &match_ecommunity_cmd);
3889 install_element (RMAP_NODE, &no_match_ecommunity_cmd);
3890 install_element (RMAP_NODE, &no_match_ecommunity_val_cmd);
paul718e3742002-12-13 20:15:29 +00003891 install_element (RMAP_NODE, &match_origin_cmd);
3892 install_element (RMAP_NODE, &no_match_origin_cmd);
3893 install_element (RMAP_NODE, &no_match_origin_val_cmd);
Vyacheslav Trushkin1c8afb72011-11-22 20:15:10 +04003894 install_element (RMAP_NODE, &match_probability_cmd);
3895 install_element (RMAP_NODE, &no_match_probability_cmd);
3896 install_element (RMAP_NODE, &no_match_probability_val_cmd);
paul718e3742002-12-13 20:15:29 +00003897
3898 install_element (RMAP_NODE, &set_ip_nexthop_cmd);
paulaf5cd0a2003-11-02 07:24:40 +00003899 install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003900 install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
3901 install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
3902 install_element (RMAP_NODE, &set_local_pref_cmd);
3903 install_element (RMAP_NODE, &no_set_local_pref_cmd);
3904 install_element (RMAP_NODE, &no_set_local_pref_val_cmd);
3905 install_element (RMAP_NODE, &set_weight_cmd);
3906 install_element (RMAP_NODE, &no_set_weight_cmd);
3907 install_element (RMAP_NODE, &no_set_weight_val_cmd);
3908 install_element (RMAP_NODE, &set_metric_cmd);
paul73ffb252003-04-19 15:49:49 +00003909 install_element (RMAP_NODE, &set_metric_addsub_cmd);
paul718e3742002-12-13 20:15:29 +00003910 install_element (RMAP_NODE, &no_set_metric_cmd);
3911 install_element (RMAP_NODE, &no_set_metric_val_cmd);
3912 install_element (RMAP_NODE, &set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003913 install_element (RMAP_NODE, &set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003914 install_element (RMAP_NODE, &no_set_aspath_prepend_cmd);
3915 install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003916 install_element (RMAP_NODE, &no_set_aspath_exclude_cmd);
3917 install_element (RMAP_NODE, &no_set_aspath_exclude_val_cmd);
paul718e3742002-12-13 20:15:29 +00003918 install_element (RMAP_NODE, &set_origin_cmd);
3919 install_element (RMAP_NODE, &no_set_origin_cmd);
3920 install_element (RMAP_NODE, &no_set_origin_val_cmd);
3921 install_element (RMAP_NODE, &set_atomic_aggregate_cmd);
3922 install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd);
3923 install_element (RMAP_NODE, &set_aggregator_as_cmd);
3924 install_element (RMAP_NODE, &no_set_aggregator_as_cmd);
3925 install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd);
3926 install_element (RMAP_NODE, &set_community_cmd);
3927 install_element (RMAP_NODE, &set_community_none_cmd);
3928 install_element (RMAP_NODE, &no_set_community_cmd);
3929 install_element (RMAP_NODE, &no_set_community_val_cmd);
3930 install_element (RMAP_NODE, &no_set_community_none_cmd);
3931 install_element (RMAP_NODE, &set_community_delete_cmd);
3932 install_element (RMAP_NODE, &no_set_community_delete_cmd);
3933 install_element (RMAP_NODE, &no_set_community_delete_val_cmd);
3934 install_element (RMAP_NODE, &set_ecommunity_rt_cmd);
3935 install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd);
3936 install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd);
3937 install_element (RMAP_NODE, &set_ecommunity_soo_cmd);
3938 install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd);
3939 install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd);
3940 install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd);
3941 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd);
3942 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd);
3943 install_element (RMAP_NODE, &set_originator_id_cmd);
3944 install_element (RMAP_NODE, &no_set_originator_id_cmd);
3945 install_element (RMAP_NODE, &no_set_originator_id_val_cmd);
3946
3947#ifdef HAVE_IPV6
3948 route_map_install_match (&route_match_ipv6_address_cmd);
3949 route_map_install_match (&route_match_ipv6_next_hop_cmd);
3950 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd);
3951 route_map_install_set (&route_set_ipv6_nexthop_global_cmd);
3952 route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
Paul Jakma41367172007-08-06 15:24:51 +00003953
paul718e3742002-12-13 20:15:29 +00003954 install_element (RMAP_NODE, &match_ipv6_address_cmd);
3955 install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
3956 install_element (RMAP_NODE, &match_ipv6_next_hop_cmd);
3957 install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd);
3958 install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
3959 install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
3960 install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd);
3961 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
3962 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd);
3963 install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
3964 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
3965 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
3966#endif /* HAVE_IPV6 */
Paul Jakma41367172007-08-06 15:24:51 +00003967
Paul Jakmae70e5752011-07-05 00:41:59 +04003968 /* AS-Pathlimit: functionality removed, commands kept for
3969 * compatibility.
3970 */
Paul Jakma41367172007-08-06 15:24:51 +00003971 install_element (RMAP_NODE, &set_pathlimit_ttl_cmd);
3972 install_element (RMAP_NODE, &no_set_pathlimit_ttl_cmd);
3973 install_element (RMAP_NODE, &no_set_pathlimit_ttl_val_cmd);
3974 install_element (RMAP_NODE, &match_pathlimit_as_cmd);
3975 install_element (RMAP_NODE, &no_match_pathlimit_as_cmd);
3976 install_element (RMAP_NODE, &no_match_pathlimit_as_val_cmd);
paul718e3742002-12-13 20:15:29 +00003977}