blob: 178af603e919ad27503d98f2c1eedc9f351a1615 [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};
793/* `set ip next-hop IP_ADDRESS' */
794
795/* Set nexthop to object. ojbect must be pointer to struct attr. */
paulac41b2a2003-08-12 05:32:27 +0000796struct rmap_ip_nexthop_set
797{
798 struct in_addr *address;
799 int peer_address;
800};
801
paul94f2b392005-06-28 12:44:16 +0000802static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000803route_set_ip_nexthop (void *rule, struct prefix *prefix,
804 route_map_object_t type, void *object)
805{
paulac41b2a2003-08-12 05:32:27 +0000806 struct rmap_ip_nexthop_set *rins = rule;
807 struct in_addr peer_address;
paul718e3742002-12-13 20:15:29 +0000808 struct bgp_info *bgp_info;
paulac41b2a2003-08-12 05:32:27 +0000809 struct peer *peer;
paul718e3742002-12-13 20:15:29 +0000810
811 if (type == RMAP_BGP)
812 {
paul718e3742002-12-13 20:15:29 +0000813 bgp_info = object;
paulac41b2a2003-08-12 05:32:27 +0000814 peer = bgp_info->peer;
815
816 if (rins->peer_address)
817 {
paulfee0f4c2004-09-13 05:12:46 +0000818 if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) ||
819 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
paulac41b2a2003-08-12 05:32:27 +0000820 && peer->su_remote
821 && sockunion_family (peer->su_remote) == AF_INET)
822 {
823 inet_aton (sockunion_su2str (peer->su_remote), &peer_address);
824 bgp_info->attr->nexthop = peer_address;
825 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
826 }
827 else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
828 && peer->su_local
829 && sockunion_family (peer->su_local) == AF_INET)
830 {
831 inet_aton (sockunion_su2str (peer->su_local), &peer_address);
832 bgp_info->attr->nexthop = peer_address;
833 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
834 }
835 }
836 else
837 {
838 /* Set next hop value. */
839 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
840 bgp_info->attr->nexthop = *rins->address;
841 }
paul718e3742002-12-13 20:15:29 +0000842 }
843
844 return RMAP_OKAY;
845}
846
847/* Route map `ip nexthop' compile function. Given string is converted
848 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +0000849static void *
paulfd79ac92004-10-13 05:06:08 +0000850route_set_ip_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000851{
paulac41b2a2003-08-12 05:32:27 +0000852 struct rmap_ip_nexthop_set *rins;
853 struct in_addr *address = NULL;
854 int peer_address = 0;
paul718e3742002-12-13 20:15:29 +0000855 int ret;
paul718e3742002-12-13 20:15:29 +0000856
paulac41b2a2003-08-12 05:32:27 +0000857 if (strcmp (arg, "peer-address") == 0)
858 peer_address = 1;
859 else
paul718e3742002-12-13 20:15:29 +0000860 {
paulac41b2a2003-08-12 05:32:27 +0000861 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
862 ret = inet_aton (arg, address);
863
864 if (ret == 0)
865 {
866 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
867 return NULL;
868 }
paul718e3742002-12-13 20:15:29 +0000869 }
870
Stephen Hemminger393deb92008-08-18 14:13:29 -0700871 rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set));
paulac41b2a2003-08-12 05:32:27 +0000872
873 rins->address = address;
874 rins->peer_address = peer_address;
875
876 return rins;
paul718e3742002-12-13 20:15:29 +0000877}
878
879/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +0000880static void
paul718e3742002-12-13 20:15:29 +0000881route_set_ip_nexthop_free (void *rule)
882{
paulac41b2a2003-08-12 05:32:27 +0000883 struct rmap_ip_nexthop_set *rins = rule;
884
885 if (rins->address)
886 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address);
887
888 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins);
paul718e3742002-12-13 20:15:29 +0000889}
890
891/* Route map commands for ip nexthop set. */
892struct route_map_rule_cmd route_set_ip_nexthop_cmd =
893{
894 "ip next-hop",
895 route_set_ip_nexthop,
896 route_set_ip_nexthop_compile,
897 route_set_ip_nexthop_free
898};
899
900/* `set local-preference LOCAL_PREF' */
901
902/* Set local preference. */
paul94f2b392005-06-28 12:44:16 +0000903static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000904route_set_local_pref (void *rule, struct prefix *prefix,
905 route_map_object_t type, void *object)
906{
907 u_int32_t *local_pref;
908 struct bgp_info *bgp_info;
909
910 if (type == RMAP_BGP)
911 {
912 /* Fetch routemap's rule information. */
913 local_pref = rule;
914 bgp_info = object;
915
916 /* Set local preference value. */
917 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
918 bgp_info->attr->local_pref = *local_pref;
919 }
920
921 return RMAP_OKAY;
922}
923
924/* set local preference compilation. */
paul94f2b392005-06-28 12:44:16 +0000925static void *
paulfd79ac92004-10-13 05:06:08 +0000926route_set_local_pref_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000927{
paulfd79ac92004-10-13 05:06:08 +0000928 unsigned long tmp;
paul718e3742002-12-13 20:15:29 +0000929 u_int32_t *local_pref;
930 char *endptr = NULL;
931
932 /* Local preference value shoud be integer. */
933 if (! all_digit (arg))
934 return NULL;
paulfd79ac92004-10-13 05:06:08 +0000935
936 tmp = strtoul (arg, &endptr, 10);
937 if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX)
938 return NULL;
939
940 local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
941
942 if (!local_pref)
943 return local_pref;
944
945 *local_pref = tmp;
946
paul718e3742002-12-13 20:15:29 +0000947 return local_pref;
948}
949
950/* Free route map's local preference value. */
paul94f2b392005-06-28 12:44:16 +0000951static void
paul718e3742002-12-13 20:15:29 +0000952route_set_local_pref_free (void *rule)
953{
954 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
955}
956
957/* Set local preference rule structure. */
958struct route_map_rule_cmd route_set_local_pref_cmd =
959{
960 "local-preference",
961 route_set_local_pref,
962 route_set_local_pref_compile,
963 route_set_local_pref_free,
964};
965
966/* `set weight WEIGHT' */
967
968/* Set weight. */
paul94f2b392005-06-28 12:44:16 +0000969static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000970route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type,
971 void *object)
972{
973 u_int32_t *weight;
974 struct bgp_info *bgp_info;
975
976 if (type == RMAP_BGP)
977 {
978 /* Fetch routemap's rule information. */
979 weight = rule;
980 bgp_info = object;
981
982 /* Set weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000983 if (*weight)
984 (bgp_attr_extra_get (bgp_info->attr))->weight = *weight;
985 else if (bgp_info->attr->extra)
986 bgp_info->attr->extra->weight = 0;
paul718e3742002-12-13 20:15:29 +0000987 }
988
989 return RMAP_OKAY;
990}
991
992/* set local preference compilation. */
paul94f2b392005-06-28 12:44:16 +0000993static void *
paulfd79ac92004-10-13 05:06:08 +0000994route_set_weight_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000995{
paulfd79ac92004-10-13 05:06:08 +0000996 unsigned long tmp;
paul718e3742002-12-13 20:15:29 +0000997 u_int32_t *weight;
998 char *endptr = NULL;
999
1000 /* Local preference value shoud be integer. */
1001 if (! all_digit (arg))
1002 return NULL;
1003
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
paul718e3742002-12-13 20:15:29 +00001009 weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
paulfd79ac92004-10-13 05:06:08 +00001010
1011 if (weight == NULL)
1012 return weight;
1013
1014 *weight = tmp;
1015
paul718e3742002-12-13 20:15:29 +00001016 return weight;
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_weight_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_weight_cmd =
1028{
1029 "weight",
1030 route_set_weight,
1031 route_set_weight_compile,
1032 route_set_weight_free,
1033};
1034
1035/* `set metric METRIC' */
1036
1037/* Set metric to attribute. */
paul94f2b392005-06-28 12:44:16 +00001038static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001039route_set_metric (void *rule, struct prefix *prefix,
1040 route_map_object_t type, void *object)
1041{
1042 char *metric;
1043 u_int32_t metric_val;
1044 struct bgp_info *bgp_info;
1045
1046 if (type == RMAP_BGP)
1047 {
1048 /* Fetch routemap's rule information. */
1049 metric = rule;
1050 bgp_info = object;
1051
1052 if (! (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
1053 bgp_info->attr->med = 0;
1054 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
1055
1056 if (all_digit (metric))
1057 {
1058 metric_val = strtoul (metric, (char **)NULL, 10);
1059 bgp_info->attr->med = metric_val;
1060 }
1061 else
1062 {
1063 metric_val = strtoul (metric+1, (char **)NULL, 10);
1064
1065 if (strncmp (metric, "+", 1) == 0)
1066 {
paul3b424972003-10-13 09:47:32 +00001067 if (bgp_info->attr->med/2 + metric_val/2 > BGP_MED_MAX/2)
1068 bgp_info->attr->med = BGP_MED_MAX - 1;
paul718e3742002-12-13 20:15:29 +00001069 else
paul537d8ea2003-08-27 06:45:32 +00001070 bgp_info->attr->med += metric_val;
paul718e3742002-12-13 20:15:29 +00001071 }
1072 else if (strncmp (metric, "-", 1) == 0)
1073 {
paul537d8ea2003-08-27 06:45:32 +00001074 if (bgp_info->attr->med <= metric_val)
1075 bgp_info->attr->med = 0;
paul718e3742002-12-13 20:15:29 +00001076 else
paul537d8ea2003-08-27 06:45:32 +00001077 bgp_info->attr->med -= metric_val;
paul718e3742002-12-13 20:15:29 +00001078 }
1079 }
1080 }
1081 return RMAP_OKAY;
1082}
1083
1084/* set metric compilation. */
paul94f2b392005-06-28 12:44:16 +00001085static void *
paulfd79ac92004-10-13 05:06:08 +00001086route_set_metric_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001087{
1088 u_int32_t metric;
paul94f2b392005-06-28 12:44:16 +00001089 unsigned long larg;
paul718e3742002-12-13 20:15:29 +00001090 char *endptr = NULL;
1091
1092 if (all_digit (arg))
1093 {
1094 /* set metric value check*/
paul94f2b392005-06-28 12:44:16 +00001095 larg = strtoul (arg, &endptr, 10);
1096 if (*endptr != '\0' || larg == ULONG_MAX || larg > UINT32_MAX)
paul718e3742002-12-13 20:15:29 +00001097 return NULL;
paul94f2b392005-06-28 12:44:16 +00001098 metric = larg;
paul718e3742002-12-13 20:15:29 +00001099 }
1100 else
1101 {
1102 /* set metric +/-value check */
1103 if ((strncmp (arg, "+", 1) != 0
1104 && strncmp (arg, "-", 1) != 0)
1105 || (! all_digit (arg+1)))
1106 return NULL;
1107
paul94f2b392005-06-28 12:44:16 +00001108 larg = strtoul (arg+1, &endptr, 10);
1109 if (*endptr != '\0' || larg == ULONG_MAX || larg > UINT32_MAX)
paul718e3742002-12-13 20:15:29 +00001110 return NULL;
paul94f2b392005-06-28 12:44:16 +00001111 metric = larg;
paul718e3742002-12-13 20:15:29 +00001112 }
1113
1114 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1115}
1116
1117/* Free route map's compiled `set metric' value. */
paul94f2b392005-06-28 12:44:16 +00001118static void
paul718e3742002-12-13 20:15:29 +00001119route_set_metric_free (void *rule)
1120{
1121 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1122}
1123
1124/* Set metric rule structure. */
1125struct route_map_rule_cmd route_set_metric_cmd =
1126{
1127 "metric",
1128 route_set_metric,
1129 route_set_metric_compile,
1130 route_set_metric_free,
1131};
1132
1133/* `set as-path prepend ASPATH' */
1134
1135/* For AS path prepend mechanism. */
paul94f2b392005-06-28 12:44:16 +00001136static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001137route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1138{
1139 struct aspath *aspath;
1140 struct aspath *new;
1141 struct bgp_info *binfo;
1142
1143 if (type == RMAP_BGP)
1144 {
1145 aspath = rule;
1146 binfo = object;
1147
1148 if (binfo->attr->aspath->refcnt)
1149 new = aspath_dup (binfo->attr->aspath);
1150 else
1151 new = binfo->attr->aspath;
1152
1153 aspath_prepend (aspath, new);
1154 binfo->attr->aspath = new;
1155 }
1156
1157 return RMAP_OKAY;
1158}
1159
1160/* Compile function for as-path prepend. */
paul94f2b392005-06-28 12:44:16 +00001161static void *
paulfd79ac92004-10-13 05:06:08 +00001162route_set_aspath_prepend_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001163{
1164 struct aspath *aspath;
1165
1166 aspath = aspath_str2aspath (arg);
1167 if (! aspath)
1168 return NULL;
1169 return aspath;
1170}
1171
1172/* Compile function for as-path prepend. */
paul94f2b392005-06-28 12:44:16 +00001173static void
paul718e3742002-12-13 20:15:29 +00001174route_set_aspath_prepend_free (void *rule)
1175{
1176 struct aspath *aspath = rule;
1177 aspath_free (aspath);
1178}
1179
1180/* Set metric rule structure. */
1181struct route_map_rule_cmd route_set_aspath_prepend_cmd =
1182{
1183 "as-path prepend",
1184 route_set_aspath_prepend,
1185 route_set_aspath_prepend_compile,
1186 route_set_aspath_prepend_free,
1187};
1188
Denis Ovsienko841f7a52008-04-10 11:47:45 +00001189/* `set as-path exclude ASn' */
1190
1191/* For ASN exclude mechanism.
1192 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1193 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1194 */
1195static route_map_result_t
1196route_set_aspath_exclude (void *rule, struct prefix *dummy, route_map_object_t type, void *object)
1197{
1198 struct aspath * new_path, * exclude_path;
1199 struct bgp_info *binfo;
1200
1201 if (type == RMAP_BGP)
1202 {
1203 exclude_path = rule;
1204 binfo = object;
1205 if (binfo->attr->aspath->refcnt)
1206 new_path = aspath_dup (binfo->attr->aspath);
1207 else
1208 new_path = binfo->attr->aspath;
1209 binfo->attr->aspath = aspath_filter_exclude (new_path, exclude_path);
1210 }
1211 return RMAP_OKAY;
1212}
1213
1214/* FIXME: consider using route_set_aspath_prepend_compile() and
1215 * route_set_aspath_prepend_free(), which two below function are
1216 * exact clones of.
1217 */
1218
1219/* Compile function for as-path exclude. */
1220static void *
1221route_set_aspath_exclude_compile (const char *arg)
1222{
1223 struct aspath *aspath;
1224
1225 aspath = aspath_str2aspath (arg);
1226 if (! aspath)
1227 return NULL;
1228 return aspath;
1229}
1230
1231static void
1232route_set_aspath_exclude_free (void *rule)
1233{
1234 struct aspath *aspath = rule;
1235 aspath_free (aspath);
1236}
1237
1238/* Set ASn exlude rule structure. */
1239struct route_map_rule_cmd route_set_aspath_exclude_cmd =
1240{
1241 "as-path exclude",
1242 route_set_aspath_exclude,
1243 route_set_aspath_exclude_compile,
1244 route_set_aspath_exclude_free,
1245};
1246
paul718e3742002-12-13 20:15:29 +00001247/* `set community COMMUNITY' */
1248struct rmap_com_set
1249{
1250 struct community *com;
1251 int additive;
1252 int none;
1253};
1254
1255/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001256static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001257route_set_community (void *rule, struct prefix *prefix,
1258 route_map_object_t type, void *object)
1259{
1260 struct rmap_com_set *rcs;
1261 struct bgp_info *binfo;
1262 struct attr *attr;
1263 struct community *new = NULL;
1264 struct community *old;
1265 struct community *merge;
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001266
paul718e3742002-12-13 20:15:29 +00001267 if (type == RMAP_BGP)
1268 {
1269 rcs = rule;
1270 binfo = object;
1271 attr = binfo->attr;
1272 old = attr->community;
1273
1274 /* "none" case. */
1275 if (rcs->none)
1276 {
1277 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES));
1278 attr->community = NULL;
1279 return RMAP_OKAY;
1280 }
1281
1282 /* "additive" case. */
1283 if (rcs->additive && old)
1284 {
1285 merge = community_merge (community_dup (old), rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001286
1287 /* HACK: if the old community is not intern'd,
1288 * we should free it here, or all reference to it may be lost.
1289 * Really need to cleanup attribute caching sometime.
1290 */
1291 if (old->refcnt == 0)
1292 community_free (old);
paul718e3742002-12-13 20:15:29 +00001293 new = community_uniq_sort (merge);
1294 community_free (merge);
1295 }
1296 else
1297 new = community_dup (rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001298
1299 /* will be interned by caller if required */
Paul Jakma4a2035f2011-04-01 15:58:27 +01001300 attr->community = new;
hasso70601e02005-05-27 03:26:57 +00001301
paul718e3742002-12-13 20:15:29 +00001302 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1303 }
1304
1305 return RMAP_OKAY;
1306}
1307
1308/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001309static void *
paulfd79ac92004-10-13 05:06:08 +00001310route_set_community_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001311{
1312 struct rmap_com_set *rcs;
1313 struct community *com = NULL;
1314 char *sp;
1315 int additive = 0;
1316 int none = 0;
1317
1318 if (strcmp (arg, "none") == 0)
1319 none = 1;
1320 else
1321 {
1322 sp = strstr (arg, "additive");
1323
1324 if (sp && sp > arg)
1325 {
1326 /* "additive" keyworkd is included. */
1327 additive = 1;
1328 *(sp - 1) = '\0';
1329 }
1330
1331 com = community_str2com (arg);
1332
1333 if (additive)
1334 *(sp - 1) = ' ';
1335
1336 if (! com)
1337 return NULL;
1338 }
1339
Stephen Hemminger393deb92008-08-18 14:13:29 -07001340 rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
Paul Jakma4a2035f2011-04-01 15:58:27 +01001341 rcs->com = com;
paul718e3742002-12-13 20:15:29 +00001342 rcs->additive = additive;
1343 rcs->none = none;
1344
1345 return rcs;
1346}
1347
1348/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001349static void
paul718e3742002-12-13 20:15:29 +00001350route_set_community_free (void *rule)
1351{
1352 struct rmap_com_set *rcs = rule;
1353
1354 if (rcs->com)
1355 community_free (rcs->com);
1356 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs);
1357}
1358
1359/* Set community rule structure. */
1360struct route_map_rule_cmd route_set_community_cmd =
1361{
1362 "community",
1363 route_set_community,
1364 route_set_community_compile,
1365 route_set_community_free,
1366};
1367
hassofee6e4e2005-02-02 16:29:31 +00001368/* `set comm-list (<1-99>|<100-500>|WORD) delete' */
paul718e3742002-12-13 20:15:29 +00001369
1370/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001371static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001372route_set_community_delete (void *rule, struct prefix *prefix,
1373 route_map_object_t type, void *object)
1374{
1375 struct community_list *list;
1376 struct community *merge;
1377 struct community *new;
1378 struct community *old;
1379 struct bgp_info *binfo;
1380
1381 if (type == RMAP_BGP)
1382 {
1383 if (! rule)
1384 return RMAP_OKAY;
1385
1386 binfo = object;
hassofee6e4e2005-02-02 16:29:31 +00001387 list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00001388 old = binfo->attr->community;
1389
1390 if (list && old)
1391 {
1392 merge = community_list_match_delete (community_dup (old), list);
1393 new = community_uniq_sort (merge);
1394 community_free (merge);
1395
Michael Lambert604a9b42010-09-13 11:48:11 -04001396 /* HACK: if the old community is not intern'd,
1397 * we should free it here, or all reference to it may be lost.
1398 * Really need to cleanup attribute caching sometime.
1399 */
1400 if (old->refcnt == 0)
1401 community_free (old);
1402
paul718e3742002-12-13 20:15:29 +00001403 if (new->size == 0)
1404 {
1405 binfo->attr->community = NULL;
1406 binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1407 community_free (new);
1408 }
1409 else
1410 {
Paul Jakma4a2035f2011-04-01 15:58:27 +01001411 binfo->attr->community = new;
paul718e3742002-12-13 20:15:29 +00001412 binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1413 }
1414 }
1415 }
1416
1417 return RMAP_OKAY;
1418}
1419
1420/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001421static void *
paulfd79ac92004-10-13 05:06:08 +00001422route_set_community_delete_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001423{
1424 char *p;
1425 char *str;
1426 int len;
1427
1428 p = strchr (arg, ' ');
1429 if (p)
1430 {
1431 len = p - arg;
1432 str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
1433 memcpy (str, arg, len);
1434 }
1435 else
1436 str = NULL;
1437
1438 return str;
1439}
1440
1441/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001442static void
paul718e3742002-12-13 20:15:29 +00001443route_set_community_delete_free (void *rule)
1444{
1445 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1446}
1447
1448/* Set community rule structure. */
1449struct route_map_rule_cmd route_set_community_delete_cmd =
1450{
1451 "comm-list",
1452 route_set_community_delete,
1453 route_set_community_delete_compile,
1454 route_set_community_delete_free,
1455};
1456
1457/* `set extcommunity rt COMMUNITY' */
1458
1459/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001460static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001461route_set_ecommunity_rt (void *rule, struct prefix *prefix,
1462 route_map_object_t type, void *object)
1463{
1464 struct ecommunity *ecom;
1465 struct ecommunity *new_ecom;
1466 struct ecommunity *old_ecom;
1467 struct bgp_info *bgp_info;
1468
1469 if (type == RMAP_BGP)
1470 {
1471 ecom = rule;
1472 bgp_info = object;
1473
1474 if (! ecom)
1475 return RMAP_OKAY;
1476
1477 /* We assume additive for Extended Community. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001478 old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
paul718e3742002-12-13 20:15:29 +00001479
1480 if (old_ecom)
1481 new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
1482 else
1483 new_ecom = ecommunity_dup (ecom);
1484
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001485 bgp_info->attr->extra->ecommunity = ecommunity_intern (new_ecom);
paul718e3742002-12-13 20:15:29 +00001486
hasso70601e02005-05-27 03:26:57 +00001487 if (old_ecom)
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001488 ecommunity_unintern (&old_ecom);
hasso70601e02005-05-27 03:26:57 +00001489
paul718e3742002-12-13 20:15:29 +00001490 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
1491 }
1492 return RMAP_OKAY;
1493}
1494
1495/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001496static void *
paulfd79ac92004-10-13 05:06:08 +00001497route_set_ecommunity_rt_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001498{
1499 struct ecommunity *ecom;
1500
1501 ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0);
1502 if (! ecom)
1503 return NULL;
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001504 return ecommunity_intern (ecom);
paul718e3742002-12-13 20:15:29 +00001505}
1506
1507/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001508static void
paul718e3742002-12-13 20:15:29 +00001509route_set_ecommunity_rt_free (void *rule)
1510{
1511 struct ecommunity *ecom = rule;
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001512 ecommunity_unintern (&ecom);
paul718e3742002-12-13 20:15:29 +00001513}
1514
1515/* Set community rule structure. */
1516struct route_map_rule_cmd route_set_ecommunity_rt_cmd =
1517{
1518 "extcommunity rt",
1519 route_set_ecommunity_rt,
1520 route_set_ecommunity_rt_compile,
1521 route_set_ecommunity_rt_free,
1522};
1523
1524/* `set extcommunity soo COMMUNITY' */
1525
1526/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001527static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001528route_set_ecommunity_soo (void *rule, struct prefix *prefix,
1529 route_map_object_t type, void *object)
1530{
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001531 struct ecommunity *ecom, *old_ecom, *new_ecom;
paul718e3742002-12-13 20:15:29 +00001532 struct bgp_info *bgp_info;
1533
1534 if (type == RMAP_BGP)
1535 {
1536 ecom = rule;
1537 bgp_info = object;
1538
1539 if (! ecom)
1540 return RMAP_OKAY;
1541
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001542 old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
1543
1544 if (old_ecom)
1545 new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
1546 else
1547 new_ecom = ecommunity_dup (ecom);
1548
1549 bgp_info->attr->extra->ecommunity = ecommunity_intern (new_ecom);
1550
1551 if (old_ecom)
1552 ecommunity_unintern (&old_ecom);
1553
paul718e3742002-12-13 20:15:29 +00001554 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
paul718e3742002-12-13 20:15:29 +00001555 }
1556 return RMAP_OKAY;
1557}
1558
1559/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001560static void *
paulfd79ac92004-10-13 05:06:08 +00001561route_set_ecommunity_soo_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001562{
1563 struct ecommunity *ecom;
1564
1565 ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0);
1566 if (! ecom)
1567 return NULL;
1568
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001569 return ecommunity_intern (ecom);
paul718e3742002-12-13 20:15:29 +00001570}
1571
1572/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001573static void
paul718e3742002-12-13 20:15:29 +00001574route_set_ecommunity_soo_free (void *rule)
1575{
1576 struct ecommunity *ecom = rule;
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001577 ecommunity_unintern (&ecom);
paul718e3742002-12-13 20:15:29 +00001578}
1579
1580/* Set community rule structure. */
1581struct route_map_rule_cmd route_set_ecommunity_soo_cmd =
1582{
1583 "extcommunity soo",
1584 route_set_ecommunity_soo,
1585 route_set_ecommunity_soo_compile,
1586 route_set_ecommunity_soo_free,
1587};
1588
1589/* `set origin ORIGIN' */
1590
1591/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00001592static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001593route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1594{
1595 u_char *origin;
1596 struct bgp_info *bgp_info;
1597
1598 if (type == RMAP_BGP)
1599 {
1600 origin = rule;
1601 bgp_info = object;
1602
1603 bgp_info->attr->origin = *origin;
1604 }
1605
1606 return RMAP_OKAY;
1607}
1608
1609/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001610static void *
paulfd79ac92004-10-13 05:06:08 +00001611route_set_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001612{
1613 u_char *origin;
1614
1615 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
1616
1617 if (strcmp (arg, "igp") == 0)
1618 *origin = 0;
1619 else if (strcmp (arg, "egp") == 0)
1620 *origin = 1;
1621 else
1622 *origin = 2;
1623
1624 return origin;
1625}
1626
1627/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001628static void
paul718e3742002-12-13 20:15:29 +00001629route_set_origin_free (void *rule)
1630{
1631 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1632}
1633
1634/* Set metric rule structure. */
1635struct route_map_rule_cmd route_set_origin_cmd =
1636{
1637 "origin",
1638 route_set_origin,
1639 route_set_origin_compile,
1640 route_set_origin_free,
1641};
1642
1643/* `set atomic-aggregate' */
1644
1645/* For atomic aggregate set. */
paul94f2b392005-06-28 12:44:16 +00001646static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001647route_set_atomic_aggregate (void *rule, struct prefix *prefix,
1648 route_map_object_t type, void *object)
1649{
1650 struct bgp_info *bgp_info;
1651
1652 if (type == RMAP_BGP)
1653 {
1654 bgp_info = object;
1655 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
1656 }
1657
1658 return RMAP_OKAY;
1659}
1660
1661/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001662static void *
paulfd79ac92004-10-13 05:06:08 +00001663route_set_atomic_aggregate_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001664{
1665 return (void *)1;
1666}
1667
1668/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001669static void
paul718e3742002-12-13 20:15:29 +00001670route_set_atomic_aggregate_free (void *rule)
1671{
1672 return;
1673}
1674
1675/* Set atomic aggregate rule structure. */
1676struct route_map_rule_cmd route_set_atomic_aggregate_cmd =
1677{
1678 "atomic-aggregate",
1679 route_set_atomic_aggregate,
1680 route_set_atomic_aggregate_compile,
1681 route_set_atomic_aggregate_free,
1682};
1683
1684/* `set aggregator as AS A.B.C.D' */
1685struct aggregator
1686{
1687 as_t as;
1688 struct in_addr address;
1689};
1690
paul94f2b392005-06-28 12:44:16 +00001691static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001692route_set_aggregator_as (void *rule, struct prefix *prefix,
1693 route_map_object_t type, void *object)
1694{
1695 struct bgp_info *bgp_info;
1696 struct aggregator *aggregator;
Paul Jakmafb982c22007-05-04 20:15:47 +00001697 struct attr_extra *ae;
paul718e3742002-12-13 20:15:29 +00001698
1699 if (type == RMAP_BGP)
1700 {
1701 bgp_info = object;
1702 aggregator = rule;
Paul Jakmafb982c22007-05-04 20:15:47 +00001703 ae = bgp_attr_extra_get (bgp_info->attr);
1704
1705 ae->aggregator_as = aggregator->as;
1706 ae->aggregator_addr = aggregator->address;
paul718e3742002-12-13 20:15:29 +00001707 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
1708 }
1709
1710 return RMAP_OKAY;
1711}
1712
paul94f2b392005-06-28 12:44:16 +00001713static void *
paulfd79ac92004-10-13 05:06:08 +00001714route_set_aggregator_as_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001715{
1716 struct aggregator *aggregator;
1717 char as[10];
1718 char address[20];
1719
Stephen Hemminger393deb92008-08-18 14:13:29 -07001720 aggregator = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));
paul718e3742002-12-13 20:15:29 +00001721 sscanf (arg, "%s %s", as, address);
1722
1723 aggregator->as = strtoul (as, NULL, 10);
1724 inet_aton (address, &aggregator->address);
1725
1726 return aggregator;
1727}
1728
paul94f2b392005-06-28 12:44:16 +00001729static void
paul718e3742002-12-13 20:15:29 +00001730route_set_aggregator_as_free (void *rule)
1731{
1732 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1733}
1734
1735struct route_map_rule_cmd route_set_aggregator_as_cmd =
1736{
1737 "aggregator as",
1738 route_set_aggregator_as,
1739 route_set_aggregator_as_compile,
1740 route_set_aggregator_as_free,
1741};
1742
1743#ifdef HAVE_IPV6
1744/* `match ipv6 address IP_ACCESS_LIST' */
1745
paul94f2b392005-06-28 12:44:16 +00001746static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001747route_match_ipv6_address (void *rule, struct prefix *prefix,
1748 route_map_object_t type, void *object)
1749{
1750 struct access_list *alist;
1751
1752 if (type == RMAP_BGP)
1753 {
1754 alist = access_list_lookup (AFI_IP6, (char *) rule);
1755 if (alist == NULL)
1756 return RMAP_NOMATCH;
1757
1758 return (access_list_apply (alist, prefix) == FILTER_DENY ?
1759 RMAP_NOMATCH : RMAP_MATCH);
1760 }
1761 return RMAP_NOMATCH;
1762}
1763
paul94f2b392005-06-28 12:44:16 +00001764static void *
paulfd79ac92004-10-13 05:06:08 +00001765route_match_ipv6_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001766{
1767 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1768}
1769
paul94f2b392005-06-28 12:44:16 +00001770static void
paul718e3742002-12-13 20:15:29 +00001771route_match_ipv6_address_free (void *rule)
1772{
1773 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1774}
1775
1776/* Route map commands for ip address matching. */
1777struct route_map_rule_cmd route_match_ipv6_address_cmd =
1778{
1779 "ipv6 address",
1780 route_match_ipv6_address,
1781 route_match_ipv6_address_compile,
1782 route_match_ipv6_address_free
1783};
1784
1785/* `match ipv6 next-hop IP_ADDRESS' */
1786
paul94f2b392005-06-28 12:44:16 +00001787static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001788route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
1789 route_map_object_t type, void *object)
1790{
1791 struct in6_addr *addr;
1792 struct bgp_info *bgp_info;
1793
1794 if (type == RMAP_BGP)
1795 {
1796 addr = rule;
1797 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +00001798
1799 if (!bgp_info->attr->extra)
1800 return RMAP_NOMATCH;
1801
1802 if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, rule))
paul718e3742002-12-13 20:15:29 +00001803 return RMAP_MATCH;
1804
Paul Jakmafb982c22007-05-04 20:15:47 +00001805 if (bgp_info->attr->extra->mp_nexthop_len == 32 &&
1806 IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, rule))
paul718e3742002-12-13 20:15:29 +00001807 return RMAP_MATCH;
1808
1809 return RMAP_NOMATCH;
1810 }
1811
1812 return RMAP_NOMATCH;
1813}
1814
paul94f2b392005-06-28 12:44:16 +00001815static void *
paulfd79ac92004-10-13 05:06:08 +00001816route_match_ipv6_next_hop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001817{
1818 struct in6_addr *address;
1819 int ret;
1820
1821 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1822
1823 ret = inet_pton (AF_INET6, arg, address);
1824 if (!ret)
1825 {
1826 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1827 return NULL;
1828 }
1829
1830 return address;
1831}
1832
paul94f2b392005-06-28 12:44:16 +00001833static void
paul718e3742002-12-13 20:15:29 +00001834route_match_ipv6_next_hop_free (void *rule)
1835{
1836 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1837}
1838
1839struct route_map_rule_cmd route_match_ipv6_next_hop_cmd =
1840{
1841 "ipv6 next-hop",
1842 route_match_ipv6_next_hop,
1843 route_match_ipv6_next_hop_compile,
1844 route_match_ipv6_next_hop_free
1845};
1846
1847/* `match ipv6 address prefix-list PREFIX_LIST' */
1848
paul94f2b392005-06-28 12:44:16 +00001849static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001850route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix,
1851 route_map_object_t type, void *object)
1852{
1853 struct prefix_list *plist;
1854
1855 if (type == RMAP_BGP)
1856 {
1857 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
1858 if (plist == NULL)
1859 return RMAP_NOMATCH;
1860
1861 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
1862 RMAP_NOMATCH : RMAP_MATCH);
1863 }
1864 return RMAP_NOMATCH;
1865}
1866
paul94f2b392005-06-28 12:44:16 +00001867static void *
paulfd79ac92004-10-13 05:06:08 +00001868route_match_ipv6_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001869{
1870 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1871}
1872
paul94f2b392005-06-28 12:44:16 +00001873static void
paul718e3742002-12-13 20:15:29 +00001874route_match_ipv6_address_prefix_list_free (void *rule)
1875{
1876 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1877}
1878
1879struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
1880{
1881 "ipv6 address prefix-list",
1882 route_match_ipv6_address_prefix_list,
1883 route_match_ipv6_address_prefix_list_compile,
1884 route_match_ipv6_address_prefix_list_free
1885};
1886
1887/* `set ipv6 nexthop global IP_ADDRESS' */
1888
1889/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001890static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001891route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix,
1892 route_map_object_t type, void *object)
1893{
1894 struct in6_addr *address;
1895 struct bgp_info *bgp_info;
1896
1897 if (type == RMAP_BGP)
1898 {
1899 /* Fetch routemap's rule information. */
1900 address = rule;
1901 bgp_info = object;
1902
1903 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001904 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address;
paul718e3742002-12-13 20:15:29 +00001905
1906 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001907 if (bgp_info->attr->extra->mp_nexthop_len == 0)
1908 bgp_info->attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001909 }
1910
1911 return RMAP_OKAY;
1912}
1913
1914/* Route map `ip next-hop' compile function. Given string is converted
1915 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00001916static void *
paulfd79ac92004-10-13 05:06:08 +00001917route_set_ipv6_nexthop_global_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001918{
1919 int ret;
1920 struct in6_addr *address;
1921
1922 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1923
1924 ret = inet_pton (AF_INET6, arg, address);
1925
1926 if (ret == 0)
1927 {
1928 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1929 return NULL;
1930 }
1931
1932 return address;
1933}
1934
1935/* Free route map's compiled `ip next-hop' value. */
paul94f2b392005-06-28 12:44:16 +00001936static void
paul718e3742002-12-13 20:15:29 +00001937route_set_ipv6_nexthop_global_free (void *rule)
1938{
1939 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1940}
1941
1942/* Route map commands for ip nexthop set. */
1943struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd =
1944{
1945 "ipv6 next-hop global",
1946 route_set_ipv6_nexthop_global,
1947 route_set_ipv6_nexthop_global_compile,
1948 route_set_ipv6_nexthop_global_free
1949};
1950
1951/* `set ipv6 nexthop local IP_ADDRESS' */
1952
1953/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001954static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001955route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
1956 route_map_object_t type, void *object)
1957{
1958 struct in6_addr *address;
1959 struct bgp_info *bgp_info;
1960
1961 if (type == RMAP_BGP)
1962 {
1963 /* Fetch routemap's rule information. */
1964 address = rule;
1965 bgp_info = object;
1966
1967 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001968 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address;
paul718e3742002-12-13 20:15:29 +00001969
1970 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001971 if (bgp_info->attr->extra->mp_nexthop_len != 32)
1972 bgp_info->attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001973 }
1974
1975 return RMAP_OKAY;
1976}
1977
1978/* Route map `ip nexthop' compile function. Given string is converted
1979 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00001980static void *
paulfd79ac92004-10-13 05:06:08 +00001981route_set_ipv6_nexthop_local_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001982{
1983 int ret;
1984 struct in6_addr *address;
1985
1986 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1987
1988 ret = inet_pton (AF_INET6, arg, address);
1989
1990 if (ret == 0)
1991 {
1992 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1993 return NULL;
1994 }
1995
1996 return address;
1997}
1998
1999/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +00002000static void
paul718e3742002-12-13 20:15:29 +00002001route_set_ipv6_nexthop_local_free (void *rule)
2002{
2003 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2004}
2005
2006/* Route map commands for ip nexthop set. */
2007struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd =
2008{
2009 "ipv6 next-hop local",
2010 route_set_ipv6_nexthop_local,
2011 route_set_ipv6_nexthop_local_compile,
2012 route_set_ipv6_nexthop_local_free
2013};
2014#endif /* HAVE_IPV6 */
2015
2016/* `set vpnv4 nexthop A.B.C.D' */
2017
paul94f2b392005-06-28 12:44:16 +00002018static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002019route_set_vpnv4_nexthop (void *rule, struct prefix *prefix,
2020 route_map_object_t type, void *object)
2021{
2022 struct in_addr *address;
2023 struct bgp_info *bgp_info;
2024
2025 if (type == RMAP_BGP)
2026 {
2027 /* Fetch routemap's rule information. */
2028 address = rule;
2029 bgp_info = object;
2030
2031 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002032 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address;
paul718e3742002-12-13 20:15:29 +00002033 }
2034
2035 return RMAP_OKAY;
2036}
2037
paul94f2b392005-06-28 12:44:16 +00002038static void *
paulfd79ac92004-10-13 05:06:08 +00002039route_set_vpnv4_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002040{
2041 int ret;
2042 struct in_addr *address;
2043
2044 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2045
2046 ret = inet_aton (arg, address);
2047
2048 if (ret == 0)
2049 {
2050 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2051 return NULL;
2052 }
2053
2054 return address;
2055}
2056
paul94f2b392005-06-28 12:44:16 +00002057static void
paul718e3742002-12-13 20:15:29 +00002058route_set_vpnv4_nexthop_free (void *rule)
2059{
2060 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2061}
2062
2063/* Route map commands for ip nexthop set. */
2064struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd =
2065{
2066 "vpnv4 next-hop",
2067 route_set_vpnv4_nexthop,
2068 route_set_vpnv4_nexthop_compile,
2069 route_set_vpnv4_nexthop_free
2070};
2071
2072/* `set originator-id' */
2073
2074/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00002075static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002076route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
2077{
2078 struct in_addr *address;
2079 struct bgp_info *bgp_info;
2080
2081 if (type == RMAP_BGP)
2082 {
2083 address = rule;
2084 bgp_info = object;
2085
2086 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);
Paul Jakmafb982c22007-05-04 20:15:47 +00002087 (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address;
paul718e3742002-12-13 20:15:29 +00002088 }
2089
2090 return RMAP_OKAY;
2091}
2092
2093/* Compile function for originator-id set. */
paul94f2b392005-06-28 12:44:16 +00002094static void *
paulfd79ac92004-10-13 05:06:08 +00002095route_set_originator_id_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002096{
2097 int ret;
2098 struct in_addr *address;
2099
2100 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2101
2102 ret = inet_aton (arg, address);
2103
2104 if (ret == 0)
2105 {
2106 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2107 return NULL;
2108 }
2109
2110 return address;
2111}
2112
2113/* Compile function for originator_id set. */
paul94f2b392005-06-28 12:44:16 +00002114static void
paul718e3742002-12-13 20:15:29 +00002115route_set_originator_id_free (void *rule)
2116{
2117 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2118}
2119
2120/* Set metric rule structure. */
2121struct route_map_rule_cmd route_set_originator_id_cmd =
2122{
2123 "originator-id",
2124 route_set_originator_id,
2125 route_set_originator_id_compile,
2126 route_set_originator_id_free,
2127};
2128
2129/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002130static int
paul718e3742002-12-13 20:15:29 +00002131bgp_route_match_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002132 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002133{
2134 int ret;
2135
2136 ret = route_map_add_match (index, command, arg);
2137 if (ret)
2138 {
2139 switch (ret)
2140 {
2141 case RMAP_RULE_MISSING:
2142 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2143 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002144 case RMAP_COMPILE_ERROR:
2145 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2146 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002147 }
2148 }
2149 return CMD_SUCCESS;
2150}
2151
2152/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002153static int
paul718e3742002-12-13 20:15:29 +00002154bgp_route_match_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002155 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002156{
2157 int ret;
2158
2159 ret = route_map_delete_match (index, command, arg);
2160 if (ret)
2161 {
2162 switch (ret)
2163 {
2164 case RMAP_RULE_MISSING:
2165 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2166 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002167 case RMAP_COMPILE_ERROR:
2168 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2169 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002170 }
2171 }
2172 return CMD_SUCCESS;
2173}
2174
2175/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002176static int
paul718e3742002-12-13 20:15:29 +00002177bgp_route_set_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002178 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002179{
2180 int ret;
2181
2182 ret = route_map_add_set (index, command, arg);
2183 if (ret)
2184 {
2185 switch (ret)
2186 {
2187 case RMAP_RULE_MISSING:
2188 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2189 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002190 case RMAP_COMPILE_ERROR:
2191 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2192 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002193 }
2194 }
2195 return CMD_SUCCESS;
2196}
2197
2198/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002199static int
paul718e3742002-12-13 20:15:29 +00002200bgp_route_set_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002201 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002202{
2203 int ret;
2204
2205 ret = route_map_delete_set (index, command, arg);
2206 if (ret)
2207 {
2208 switch (ret)
2209 {
2210 case RMAP_RULE_MISSING:
2211 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2212 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002213 case RMAP_COMPILE_ERROR:
2214 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2215 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002216 }
2217 }
2218 return CMD_SUCCESS;
2219}
2220
2221/* Hook function for updating route_map assignment. */
paul94f2b392005-06-28 12:44:16 +00002222static void
paulfd79ac92004-10-13 05:06:08 +00002223bgp_route_map_update (const char *unused)
paul718e3742002-12-13 20:15:29 +00002224{
2225 int i;
2226 afi_t afi;
2227 safi_t safi;
2228 int direct;
paul1eb8ef22005-04-07 07:30:20 +00002229 struct listnode *node, *nnode;
2230 struct listnode *mnode, *mnnode;
paul718e3742002-12-13 20:15:29 +00002231 struct bgp *bgp;
2232 struct peer *peer;
2233 struct peer_group *group;
2234 struct bgp_filter *filter;
2235 struct bgp_node *bn;
2236 struct bgp_static *bgp_static;
2237
2238 /* For neighbor route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002239 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002240 {
paul1eb8ef22005-04-07 07:30:20 +00002241 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002242 {
2243 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2244 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2245 {
2246 filter = &peer->filter[afi][safi];
2247
paulfee0f4c2004-09-13 05:12:46 +00002248 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002249 {
2250 if (filter->map[direct].name)
2251 filter->map[direct].map =
2252 route_map_lookup_by_name (filter->map[direct].name);
2253 else
2254 filter->map[direct].map = NULL;
2255 }
2256
2257 if (filter->usmap.name)
2258 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2259 else
2260 filter->usmap.map = NULL;
2261 }
2262 }
paul1eb8ef22005-04-07 07:30:20 +00002263 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
paul718e3742002-12-13 20:15:29 +00002264 {
2265 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2266 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2267 {
2268 filter = &group->conf->filter[afi][safi];
2269
paulfee0f4c2004-09-13 05:12:46 +00002270 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002271 {
2272 if (filter->map[direct].name)
2273 filter->map[direct].map =
2274 route_map_lookup_by_name (filter->map[direct].name);
2275 else
2276 filter->map[direct].map = NULL;
2277 }
2278
2279 if (filter->usmap.name)
2280 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2281 else
2282 filter->usmap.map = NULL;
2283 }
2284 }
2285 }
2286
2287 /* For default-originate route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002288 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002289 {
paul1eb8ef22005-04-07 07:30:20 +00002290 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002291 {
2292 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2293 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2294 {
2295 if (peer->default_rmap[afi][safi].name)
2296 peer->default_rmap[afi][safi].map =
2297 route_map_lookup_by_name (peer->default_rmap[afi][safi].name);
2298 else
2299 peer->default_rmap[afi][safi].map = NULL;
2300 }
2301 }
2302 }
2303
2304 /* For network route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002305 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002306 {
2307 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2308 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2309 for (bn = bgp_table_top (bgp->route[afi][safi]); bn;
2310 bn = bgp_route_next (bn))
2311 if ((bgp_static = bn->info) != NULL)
2312 {
2313 if (bgp_static->rmap.name)
2314 bgp_static->rmap.map =
2315 route_map_lookup_by_name (bgp_static->rmap.name);
2316 else
2317 bgp_static->rmap.map = NULL;
2318 }
2319 }
2320
2321 /* For redistribute route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002322 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002323 {
2324 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2325 {
2326 if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)
2327 bgp->rmap[ZEBRA_FAMILY_IPV4][i].map =
2328 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);
2329#ifdef HAVE_IPV6
2330 if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)
2331 bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =
2332 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);
2333#endif /* HAVE_IPV6 */
2334 }
2335 }
2336}
2337
paulfee0f4c2004-09-13 05:12:46 +00002338DEFUN (match_peer,
2339 match_peer_cmd,
2340 "match peer (A.B.C.D|X:X::X:X)",
2341 MATCH_STR
2342 "Match peer address\n"
2343 "IPv6 address of peer\n"
2344 "IP address of peer\n")
2345{
2346 return bgp_route_match_add (vty, vty->index, "peer", argv[0]);
2347}
2348
2349DEFUN (match_peer_local,
2350 match_peer_local_cmd,
2351 "match peer local",
2352 MATCH_STR
2353 "Match peer address\n"
2354 "Static or Redistributed routes\n")
2355{
2356 return bgp_route_match_add (vty, vty->index, "peer", NULL);
2357}
2358
2359DEFUN (no_match_peer,
2360 no_match_peer_cmd,
2361 "no match peer",
2362 NO_STR
2363 MATCH_STR
2364 "Match peer address\n")
2365{
2366 if (argc == 0)
2367 return bgp_route_match_delete (vty, vty->index, "peer", NULL);
2368
2369 return bgp_route_match_delete (vty, vty->index, "peer", argv[0]);
2370}
2371
2372ALIAS (no_match_peer,
2373 no_match_peer_val_cmd,
2374 "no match peer (A.B.C.D|X:X::X:X)",
2375 NO_STR
2376 MATCH_STR
2377 "Match peer address\n"
2378 "IPv6 address of peer\n"
2379 "IP address of peer\n")
2380
2381ALIAS (no_match_peer,
2382 no_match_peer_local_cmd,
2383 "no match peer local",
2384 NO_STR
2385 MATCH_STR
2386 "Match peer address\n"
2387 "Static or Redistributed routes\n")
2388
paul718e3742002-12-13 20:15:29 +00002389DEFUN (match_ip_address,
2390 match_ip_address_cmd,
2391 "match ip address (<1-199>|<1300-2699>|WORD)",
2392 MATCH_STR
2393 IP_STR
2394 "Match address of route\n"
2395 "IP access-list number\n"
2396 "IP access-list number (expanded range)\n"
2397 "IP Access-list name\n")
2398{
2399 return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);
2400}
2401
2402DEFUN (no_match_ip_address,
2403 no_match_ip_address_cmd,
2404 "no match ip address",
2405 NO_STR
2406 MATCH_STR
2407 IP_STR
2408 "Match address of route\n")
2409{
2410 if (argc == 0)
2411 return bgp_route_match_delete (vty, vty->index, "ip address", NULL);
2412
2413 return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);
2414}
2415
2416ALIAS (no_match_ip_address,
2417 no_match_ip_address_val_cmd,
2418 "no match ip address (<1-199>|<1300-2699>|WORD)",
2419 NO_STR
2420 MATCH_STR
2421 IP_STR
2422 "Match address of route\n"
2423 "IP access-list number\n"
2424 "IP access-list number (expanded range)\n"
2425 "IP Access-list name\n")
2426
2427DEFUN (match_ip_next_hop,
2428 match_ip_next_hop_cmd,
2429 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
2430 MATCH_STR
2431 IP_STR
2432 "Match next-hop address of route\n"
2433 "IP access-list number\n"
2434 "IP access-list number (expanded range)\n"
2435 "IP Access-list name\n")
2436{
2437 return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
2438}
2439
2440DEFUN (no_match_ip_next_hop,
2441 no_match_ip_next_hop_cmd,
2442 "no match ip next-hop",
2443 NO_STR
2444 MATCH_STR
2445 IP_STR
2446 "Match next-hop address of route\n")
2447{
2448 if (argc == 0)
2449 return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
2450
2451 return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
2452}
2453
2454ALIAS (no_match_ip_next_hop,
2455 no_match_ip_next_hop_val_cmd,
2456 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2457 NO_STR
2458 MATCH_STR
2459 IP_STR
2460 "Match next-hop address of route\n"
2461 "IP access-list number\n"
2462 "IP access-list number (expanded range)\n"
2463 "IP Access-list name\n")
2464
hassoc1643bb2005-02-02 16:43:17 +00002465DEFUN (match_ip_route_source,
2466 match_ip_route_source_cmd,
2467 "match ip route-source (<1-199>|<1300-2699>|WORD)",
2468 MATCH_STR
2469 IP_STR
2470 "Match advertising source address of route\n"
2471 "IP access-list number\n"
2472 "IP access-list number (expanded range)\n"
2473 "IP standard access-list name\n")
2474{
2475 return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]);
2476}
2477
2478DEFUN (no_match_ip_route_source,
2479 no_match_ip_route_source_cmd,
2480 "no match ip route-source",
2481 NO_STR
2482 MATCH_STR
2483 IP_STR
2484 "Match advertising source address of route\n")
2485{
2486 if (argc == 0)
2487 return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL);
2488
2489 return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]);
2490}
2491
2492ALIAS (no_match_ip_route_source,
2493 no_match_ip_route_source_val_cmd,
2494 "no match ip route-source (<1-199>|<1300-2699>|WORD)",
2495 NO_STR
2496 MATCH_STR
2497 IP_STR
2498 "Match advertising source address of route\n"
2499 "IP access-list number\n"
2500 "IP access-list number (expanded range)\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002501 "IP standard access-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002502
paul718e3742002-12-13 20:15:29 +00002503DEFUN (match_ip_address_prefix_list,
2504 match_ip_address_prefix_list_cmd,
2505 "match ip address prefix-list WORD",
2506 MATCH_STR
2507 IP_STR
2508 "Match address of route\n"
2509 "Match entries of prefix-lists\n"
2510 "IP prefix-list name\n")
2511{
2512 return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
2513}
2514
2515DEFUN (no_match_ip_address_prefix_list,
2516 no_match_ip_address_prefix_list_cmd,
2517 "no match ip address prefix-list",
2518 NO_STR
2519 MATCH_STR
2520 IP_STR
2521 "Match address of route\n"
2522 "Match entries of prefix-lists\n")
2523{
2524 if (argc == 0)
2525 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
2526
2527 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
2528}
2529
2530ALIAS (no_match_ip_address_prefix_list,
2531 no_match_ip_address_prefix_list_val_cmd,
2532 "no match ip address prefix-list WORD",
2533 NO_STR
2534 MATCH_STR
2535 IP_STR
2536 "Match address of route\n"
2537 "Match entries of prefix-lists\n"
2538 "IP prefix-list name\n")
2539
2540DEFUN (match_ip_next_hop_prefix_list,
2541 match_ip_next_hop_prefix_list_cmd,
2542 "match ip next-hop prefix-list WORD",
2543 MATCH_STR
2544 IP_STR
2545 "Match next-hop address of route\n"
2546 "Match entries of prefix-lists\n"
2547 "IP prefix-list name\n")
2548{
2549 return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2550}
2551
2552DEFUN (no_match_ip_next_hop_prefix_list,
2553 no_match_ip_next_hop_prefix_list_cmd,
2554 "no match ip next-hop prefix-list",
2555 NO_STR
2556 MATCH_STR
2557 IP_STR
2558 "Match next-hop address of route\n"
2559 "Match entries of prefix-lists\n")
2560{
2561 if (argc == 0)
2562 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
2563
2564 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2565}
2566
2567ALIAS (no_match_ip_next_hop_prefix_list,
2568 no_match_ip_next_hop_prefix_list_val_cmd,
2569 "no match ip next-hop prefix-list WORD",
2570 NO_STR
2571 MATCH_STR
2572 IP_STR
2573 "Match next-hop address of route\n"
2574 "Match entries of prefix-lists\n"
2575 "IP prefix-list name\n")
2576
hassoc1643bb2005-02-02 16:43:17 +00002577DEFUN (match_ip_route_source_prefix_list,
2578 match_ip_route_source_prefix_list_cmd,
2579 "match ip route-source prefix-list WORD",
2580 MATCH_STR
2581 IP_STR
2582 "Match advertising source address of route\n"
2583 "Match entries of prefix-lists\n"
2584 "IP prefix-list name\n")
2585{
2586 return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]);
2587}
2588
2589DEFUN (no_match_ip_route_source_prefix_list,
2590 no_match_ip_route_source_prefix_list_cmd,
2591 "no match ip route-source prefix-list",
2592 NO_STR
2593 MATCH_STR
2594 IP_STR
2595 "Match advertising source address of route\n"
2596 "Match entries of prefix-lists\n")
2597{
2598 if (argc == 0)
2599 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL);
2600
2601 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]);
2602}
2603
2604ALIAS (no_match_ip_route_source_prefix_list,
2605 no_match_ip_route_source_prefix_list_val_cmd,
2606 "no match ip route-source prefix-list WORD",
2607 NO_STR
2608 MATCH_STR
2609 IP_STR
2610 "Match advertising source address of route\n"
2611 "Match entries of prefix-lists\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002612 "IP prefix-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002613
paul718e3742002-12-13 20:15:29 +00002614DEFUN (match_metric,
2615 match_metric_cmd,
2616 "match metric <0-4294967295>",
2617 MATCH_STR
2618 "Match metric of route\n"
2619 "Metric value\n")
2620{
2621 return bgp_route_match_add (vty, vty->index, "metric", argv[0]);
2622}
2623
2624DEFUN (no_match_metric,
2625 no_match_metric_cmd,
2626 "no match metric",
2627 NO_STR
2628 MATCH_STR
2629 "Match metric of route\n")
2630{
2631 if (argc == 0)
2632 return bgp_route_match_delete (vty, vty->index, "metric", NULL);
2633
2634 return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);
2635}
2636
2637ALIAS (no_match_metric,
2638 no_match_metric_val_cmd,
2639 "no match metric <0-4294967295>",
2640 NO_STR
2641 MATCH_STR
2642 "Match metric of route\n"
2643 "Metric value\n")
2644
2645DEFUN (match_community,
2646 match_community_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002647 "match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002648 MATCH_STR
2649 "Match BGP community list\n"
2650 "Community-list number (standard)\n"
2651 "Community-list number (expanded)\n"
2652 "Community-list name\n")
2653{
2654 return bgp_route_match_add (vty, vty->index, "community", argv[0]);
2655}
2656
2657DEFUN (match_community_exact,
2658 match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002659 "match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002660 MATCH_STR
2661 "Match BGP community list\n"
2662 "Community-list number (standard)\n"
2663 "Community-list number (expanded)\n"
2664 "Community-list name\n"
2665 "Do exact matching of communities\n")
2666{
2667 int ret;
2668 char *argstr;
2669
2670 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
2671 strlen (argv[0]) + strlen ("exact-match") + 2);
2672
2673 sprintf (argstr, "%s exact-match", argv[0]);
2674
2675 ret = bgp_route_match_add (vty, vty->index, "community", argstr);
2676
2677 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
2678
2679 return ret;
2680}
2681
2682DEFUN (no_match_community,
2683 no_match_community_cmd,
2684 "no match community",
2685 NO_STR
2686 MATCH_STR
2687 "Match BGP community list\n")
2688{
2689 return bgp_route_match_delete (vty, vty->index, "community", NULL);
2690}
2691
2692ALIAS (no_match_community,
2693 no_match_community_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002694 "no match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002695 NO_STR
2696 MATCH_STR
2697 "Match BGP community list\n"
2698 "Community-list number (standard)\n"
2699 "Community-list number (expanded)\n"
2700 "Community-list name\n")
2701
2702ALIAS (no_match_community,
2703 no_match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002704 "no match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002705 NO_STR
2706 MATCH_STR
2707 "Match BGP community list\n"
2708 "Community-list number (standard)\n"
2709 "Community-list number (expanded)\n"
2710 "Community-list name\n"
2711 "Do exact matching of communities\n")
2712
paul73ffb252003-04-19 15:49:49 +00002713DEFUN (match_ecommunity,
2714 match_ecommunity_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002715 "match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002716 MATCH_STR
2717 "Match BGP/VPN extended community list\n"
2718 "Extended community-list number (standard)\n"
2719 "Extended community-list number (expanded)\n"
2720 "Extended community-list name\n")
2721{
2722 return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]);
2723}
2724
2725DEFUN (no_match_ecommunity,
2726 no_match_ecommunity_cmd,
2727 "no match extcommunity",
2728 NO_STR
2729 MATCH_STR
2730 "Match BGP/VPN extended community list\n")
2731{
2732 return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL);
2733}
2734
2735ALIAS (no_match_ecommunity,
2736 no_match_ecommunity_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002737 "no match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002738 NO_STR
2739 MATCH_STR
2740 "Match BGP/VPN extended community list\n"
2741 "Extended community-list number (standard)\n"
2742 "Extended community-list number (expanded)\n"
2743 "Extended community-list name\n")
2744
paul718e3742002-12-13 20:15:29 +00002745DEFUN (match_aspath,
2746 match_aspath_cmd,
2747 "match as-path WORD",
2748 MATCH_STR
2749 "Match BGP AS path list\n"
2750 "AS path access-list name\n")
2751{
2752 return bgp_route_match_add (vty, vty->index, "as-path", argv[0]);
2753}
2754
2755DEFUN (no_match_aspath,
2756 no_match_aspath_cmd,
2757 "no match as-path",
2758 NO_STR
2759 MATCH_STR
2760 "Match BGP AS path list\n")
2761{
2762 return bgp_route_match_delete (vty, vty->index, "as-path", NULL);
2763}
2764
2765ALIAS (no_match_aspath,
2766 no_match_aspath_val_cmd,
2767 "no match as-path WORD",
2768 NO_STR
2769 MATCH_STR
2770 "Match BGP AS path list\n"
2771 "AS path access-list name\n")
2772
2773DEFUN (match_origin,
2774 match_origin_cmd,
2775 "match origin (egp|igp|incomplete)",
2776 MATCH_STR
2777 "BGP origin code\n"
2778 "remote EGP\n"
2779 "local IGP\n"
2780 "unknown heritage\n")
2781{
2782 if (strncmp (argv[0], "igp", 2) == 0)
2783 return bgp_route_match_add (vty, vty->index, "origin", "igp");
2784 if (strncmp (argv[0], "egp", 1) == 0)
2785 return bgp_route_match_add (vty, vty->index, "origin", "egp");
2786 if (strncmp (argv[0], "incomplete", 2) == 0)
2787 return bgp_route_match_add (vty, vty->index, "origin", "incomplete");
2788
2789 return CMD_WARNING;
2790}
2791
2792DEFUN (no_match_origin,
2793 no_match_origin_cmd,
2794 "no match origin",
2795 NO_STR
2796 MATCH_STR
2797 "BGP origin code\n")
2798{
2799 return bgp_route_match_delete (vty, vty->index, "origin", NULL);
2800}
2801
2802ALIAS (no_match_origin,
2803 no_match_origin_val_cmd,
2804 "no match origin (egp|igp|incomplete)",
2805 NO_STR
2806 MATCH_STR
2807 "BGP origin code\n"
2808 "remote EGP\n"
2809 "local IGP\n"
2810 "unknown heritage\n")
2811
2812DEFUN (set_ip_nexthop,
2813 set_ip_nexthop_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002814 "set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002815 SET_STR
2816 IP_STR
2817 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002818 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002819{
2820 union sockunion su;
2821 int ret;
2822
2823 ret = str2sockunion (argv[0], &su);
2824 if (ret < 0)
2825 {
2826 vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
2827 return CMD_WARNING;
2828 }
2829
2830 return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
2831}
2832
paulaf5cd0a2003-11-02 07:24:40 +00002833DEFUN (set_ip_nexthop_peer,
2834 set_ip_nexthop_peer_cmd,
2835 "set ip next-hop peer-address",
2836 SET_STR
2837 IP_STR
2838 "Next hop address\n"
2839 "Use peer address (for BGP only)\n")
2840{
2841 return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address");
2842}
2843
paul94f2b392005-06-28 12:44:16 +00002844DEFUN_DEPRECATED (no_set_ip_nexthop_peer,
paulaf5cd0a2003-11-02 07:24:40 +00002845 no_set_ip_nexthop_peer_cmd,
2846 "no set ip next-hop peer-address",
2847 NO_STR
2848 SET_STR
2849 IP_STR
2850 "Next hop address\n"
2851 "Use peer address (for BGP only)\n")
2852{
2853 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2854}
2855
2856
paul718e3742002-12-13 20:15:29 +00002857DEFUN (no_set_ip_nexthop,
2858 no_set_ip_nexthop_cmd,
2859 "no set ip next-hop",
2860 NO_STR
2861 SET_STR
paul718e3742002-12-13 20:15:29 +00002862 "Next hop address\n")
2863{
paulaf5cd0a2003-11-02 07:24:40 +00002864 if (argc == 0)
paul718e3742002-12-13 20:15:29 +00002865 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2866
2867 return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
2868}
2869
2870ALIAS (no_set_ip_nexthop,
2871 no_set_ip_nexthop_val_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002872 "no set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002873 NO_STR
2874 SET_STR
2875 IP_STR
2876 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002877 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002878
2879DEFUN (set_metric,
2880 set_metric_cmd,
paul73ffb252003-04-19 15:49:49 +00002881 "set metric <0-4294967295>",
paul718e3742002-12-13 20:15:29 +00002882 SET_STR
2883 "Metric value for destination routing protocol\n"
paul73ffb252003-04-19 15:49:49 +00002884 "Metric value\n")
paul718e3742002-12-13 20:15:29 +00002885{
2886 return bgp_route_set_add (vty, vty->index, "metric", argv[0]);
2887}
2888
paul73ffb252003-04-19 15:49:49 +00002889ALIAS (set_metric,
2890 set_metric_addsub_cmd,
2891 "set metric <+/-metric>",
2892 SET_STR
2893 "Metric value for destination routing protocol\n"
hasso033e8612005-05-28 04:50:54 +00002894 "Add or subtract metric\n")
paul73ffb252003-04-19 15:49:49 +00002895
paul718e3742002-12-13 20:15:29 +00002896DEFUN (no_set_metric,
2897 no_set_metric_cmd,
2898 "no set metric",
2899 NO_STR
2900 SET_STR
2901 "Metric value for destination routing protocol\n")
2902{
2903 if (argc == 0)
2904 return bgp_route_set_delete (vty, vty->index, "metric", NULL);
2905
2906 return bgp_route_set_delete (vty, vty->index, "metric", argv[0]);
2907}
2908
2909ALIAS (no_set_metric,
2910 no_set_metric_val_cmd,
2911 "no set metric <0-4294967295>",
2912 NO_STR
2913 SET_STR
2914 "Metric value for destination routing protocol\n"
2915 "Metric value\n")
2916
2917DEFUN (set_local_pref,
2918 set_local_pref_cmd,
2919 "set local-preference <0-4294967295>",
2920 SET_STR
2921 "BGP local preference path attribute\n"
2922 "Preference value\n")
2923{
2924 return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]);
2925}
2926
2927DEFUN (no_set_local_pref,
2928 no_set_local_pref_cmd,
2929 "no set local-preference",
2930 NO_STR
2931 SET_STR
2932 "BGP local preference path attribute\n")
2933{
2934 if (argc == 0)
2935 return bgp_route_set_delete (vty, vty->index, "local-preference", NULL);
2936
2937 return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]);
2938}
2939
2940ALIAS (no_set_local_pref,
2941 no_set_local_pref_val_cmd,
2942 "no set local-preference <0-4294967295>",
2943 NO_STR
2944 SET_STR
2945 "BGP local preference path attribute\n"
2946 "Preference value\n")
2947
2948DEFUN (set_weight,
2949 set_weight_cmd,
2950 "set weight <0-4294967295>",
2951 SET_STR
2952 "BGP weight for routing table\n"
2953 "Weight value\n")
2954{
2955 return bgp_route_set_add (vty, vty->index, "weight", argv[0]);
2956}
2957
2958DEFUN (no_set_weight,
2959 no_set_weight_cmd,
2960 "no set weight",
2961 NO_STR
2962 SET_STR
2963 "BGP weight for routing table\n")
2964{
2965 if (argc == 0)
2966 return bgp_route_set_delete (vty, vty->index, "weight", NULL);
2967
2968 return bgp_route_set_delete (vty, vty->index, "weight", argv[0]);
2969}
2970
2971ALIAS (no_set_weight,
2972 no_set_weight_val_cmd,
2973 "no set weight <0-4294967295>",
2974 NO_STR
2975 SET_STR
2976 "BGP weight for routing table\n"
2977 "Weight value\n")
2978
2979DEFUN (set_aspath_prepend,
2980 set_aspath_prepend_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04002981 "set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00002982 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00002983 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00002984 "Prepend to the as-path\n"
2985 "AS number\n")
2986{
2987 int ret;
2988 char *str;
2989
2990 str = argv_concat (argv, argc, 0);
2991 ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str);
2992 XFREE (MTYPE_TMP, str);
2993
2994 return ret;
2995}
2996
2997DEFUN (no_set_aspath_prepend,
2998 no_set_aspath_prepend_cmd,
2999 "no set as-path prepend",
3000 NO_STR
3001 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003002 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003003 "Prepend to the as-path\n")
3004{
Denis Ovsienkoa7f93f32007-12-18 15:13:06 +00003005 int ret;
3006 char *str;
3007
3008 if (argc == 0)
3009 return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL);
3010
3011 str = argv_concat (argv, argc, 0);
3012 ret = bgp_route_set_delete (vty, vty->index, "as-path prepend", str);
3013 XFREE (MTYPE_TMP, str);
3014 return ret;
paul718e3742002-12-13 20:15:29 +00003015}
3016
3017ALIAS (no_set_aspath_prepend,
3018 no_set_aspath_prepend_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003019 "no set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003020 NO_STR
3021 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003022 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003023 "Prepend to the as-path\n"
3024 "AS number\n")
3025
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003026DEFUN (set_aspath_exclude,
3027 set_aspath_exclude_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003028 "set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003029 SET_STR
3030 "Transform BGP AS-path attribute\n"
3031 "Exclude from the as-path\n"
3032 "AS number\n")
3033{
3034 int ret;
3035 char *str;
3036
3037 str = argv_concat (argv, argc, 0);
3038 ret = bgp_route_set_add (vty, vty->index, "as-path exclude", str);
3039 XFREE (MTYPE_TMP, str);
3040 return ret;
3041}
3042
3043DEFUN (no_set_aspath_exclude,
3044 no_set_aspath_exclude_cmd,
3045 "no set as-path exclude",
3046 NO_STR
3047 SET_STR
3048 "Transform BGP AS_PATH attribute\n"
3049 "Exclude from the as-path\n")
3050{
3051 int ret;
3052 char *str;
3053
3054 if (argc == 0)
3055 return bgp_route_set_delete (vty, vty->index, "as-path exclude", NULL);
3056
3057 str = argv_concat (argv, argc, 0);
3058 ret = bgp_route_set_delete (vty, vty->index, "as-path exclude", str);
3059 XFREE (MTYPE_TMP, str);
3060 return ret;
3061}
3062
3063ALIAS (no_set_aspath_exclude,
3064 no_set_aspath_exclude_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003065 "no set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003066 NO_STR
3067 SET_STR
3068 "Transform BGP AS_PATH attribute\n"
3069 "Exclude from the as-path\n"
3070 "AS number\n")
3071
paul718e3742002-12-13 20:15:29 +00003072DEFUN (set_community,
3073 set_community_cmd,
3074 "set community .AA:NN",
3075 SET_STR
3076 "BGP community attribute\n"
3077 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3078{
3079 int i;
3080 int first = 0;
3081 int additive = 0;
3082 struct buffer *b;
3083 struct community *com = NULL;
3084 char *str;
3085 char *argstr;
3086 int ret;
3087
3088 b = buffer_new (1024);
3089
3090 for (i = 0; i < argc; i++)
3091 {
3092 if (strncmp (argv[i], "additive", strlen (argv[i])) == 0)
3093 {
3094 additive = 1;
3095 continue;
3096 }
3097
3098 if (first)
3099 buffer_putc (b, ' ');
3100 else
3101 first = 1;
3102
3103 if (strncmp (argv[i], "internet", strlen (argv[i])) == 0)
3104 {
3105 buffer_putstr (b, "internet");
3106 continue;
3107 }
3108 if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0)
3109 {
3110 buffer_putstr (b, "local-AS");
3111 continue;
3112 }
3113 if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0
3114 && strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0)
3115 {
3116 buffer_putstr (b, "no-advertise");
3117 continue;
3118 }
3119 if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0
3120 && strncmp (argv[i], "no-export", strlen (argv[i])) == 0)
3121 {
3122 buffer_putstr (b, "no-export");
3123 continue;
3124 }
3125 buffer_putstr (b, argv[i]);
3126 }
3127 buffer_putc (b, '\0');
3128
3129 /* Fetch result string then compile it to communities attribute. */
3130 str = buffer_getstr (b);
3131 buffer_free (b);
3132
3133 if (str)
3134 {
3135 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00003136 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00003137 }
3138
3139 /* Can't compile user input into communities attribute. */
3140 if (! com)
3141 {
3142 vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE);
3143 return CMD_WARNING;
3144 }
3145
3146 /* Set communites attribute string. */
3147 str = community_str (com);
3148
3149 if (additive)
3150 {
3151 argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1);
3152 strcpy (argstr, str);
3153 strcpy (argstr + strlen (str), " additive");
3154 ret = bgp_route_set_add (vty, vty->index, "community", argstr);
3155 XFREE (MTYPE_TMP, argstr);
3156 }
3157 else
3158 ret = bgp_route_set_add (vty, vty->index, "community", str);
3159
3160 community_free (com);
3161
3162 return ret;
3163}
3164
3165DEFUN (set_community_none,
3166 set_community_none_cmd,
3167 "set community none",
3168 SET_STR
3169 "BGP community attribute\n"
3170 "No community attribute\n")
3171{
3172 return bgp_route_set_add (vty, vty->index, "community", "none");
3173}
3174
3175DEFUN (no_set_community,
3176 no_set_community_cmd,
3177 "no set community",
3178 NO_STR
3179 SET_STR
3180 "BGP community attribute\n")
3181{
3182 return bgp_route_set_delete (vty, vty->index, "community", NULL);
3183}
3184
3185ALIAS (no_set_community,
3186 no_set_community_val_cmd,
3187 "no set community .AA:NN",
3188 NO_STR
3189 SET_STR
3190 "BGP community attribute\n"
3191 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3192
3193ALIAS (no_set_community,
3194 no_set_community_none_cmd,
3195 "no set community none",
3196 NO_STR
3197 SET_STR
3198 "BGP community attribute\n"
3199 "No community attribute\n")
3200
3201DEFUN (set_community_delete,
3202 set_community_delete_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003203 "set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003204 SET_STR
3205 "set BGP community list (for deletion)\n"
3206 "Community-list number (standard)\n"
3207 "Communitly-list number (expanded)\n"
3208 "Community-list name\n"
3209 "Delete matching communities\n")
3210{
3211 char *str;
3212
3213 str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1);
3214 strcpy (str, argv[0]);
3215 strcpy (str + strlen (argv[0]), " delete");
3216
3217 bgp_route_set_add (vty, vty->index, "comm-list", str);
3218
3219 XFREE (MTYPE_TMP, str);
3220 return CMD_SUCCESS;
3221}
3222
3223DEFUN (no_set_community_delete,
3224 no_set_community_delete_cmd,
3225 "no set comm-list",
3226 NO_STR
3227 SET_STR
3228 "set BGP community list (for deletion)\n")
3229{
3230 return bgp_route_set_delete (vty, vty->index, "comm-list", NULL);
3231}
3232
3233ALIAS (no_set_community_delete,
3234 no_set_community_delete_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003235 "no set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003236 NO_STR
3237 SET_STR
3238 "set BGP community list (for deletion)\n"
3239 "Community-list number (standard)\n"
3240 "Communitly-list number (expanded)\n"
3241 "Community-list name\n"
3242 "Delete matching communities\n")
3243
3244DEFUN (set_ecommunity_rt,
3245 set_ecommunity_rt_cmd,
3246 "set extcommunity rt .ASN:nn_or_IP-address:nn",
3247 SET_STR
3248 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003249 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003250 "VPN extended community\n")
3251{
3252 int ret;
3253 char *str;
3254
3255 str = argv_concat (argv, argc, 0);
3256 ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str);
3257 XFREE (MTYPE_TMP, str);
3258
3259 return ret;
3260}
3261
3262DEFUN (no_set_ecommunity_rt,
3263 no_set_ecommunity_rt_cmd,
3264 "no set extcommunity rt",
3265 NO_STR
3266 SET_STR
3267 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003268 "Route Target extended community\n")
paul718e3742002-12-13 20:15:29 +00003269{
3270 return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL);
3271}
3272
3273ALIAS (no_set_ecommunity_rt,
3274 no_set_ecommunity_rt_val_cmd,
3275 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
3276 NO_STR
3277 SET_STR
3278 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003279 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003280 "VPN extended community\n")
3281
3282DEFUN (set_ecommunity_soo,
3283 set_ecommunity_soo_cmd,
3284 "set extcommunity soo .ASN:nn_or_IP-address:nn",
3285 SET_STR
3286 "BGP extended community attribute\n"
3287 "Site-of-Origin extended community\n"
3288 "VPN extended community\n")
3289{
3290 int ret;
3291 char *str;
3292
3293 str = argv_concat (argv, argc, 0);
3294 ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str);
3295 XFREE (MTYPE_TMP, str);
3296 return ret;
3297}
3298
3299DEFUN (no_set_ecommunity_soo,
3300 no_set_ecommunity_soo_cmd,
3301 "no set extcommunity soo",
3302 NO_STR
3303 SET_STR
3304 "BGP extended community attribute\n"
3305 "Site-of-Origin extended community\n")
3306{
3307 return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL);
3308}
3309
3310ALIAS (no_set_ecommunity_soo,
3311 no_set_ecommunity_soo_val_cmd,
3312 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
3313 NO_STR
3314 SET_STR
3315 "BGP extended community attribute\n"
3316 "Site-of-Origin extended community\n"
3317 "VPN extended community\n")
3318
3319DEFUN (set_origin,
3320 set_origin_cmd,
3321 "set origin (egp|igp|incomplete)",
3322 SET_STR
3323 "BGP origin code\n"
3324 "remote EGP\n"
3325 "local IGP\n"
3326 "unknown heritage\n")
3327{
3328 if (strncmp (argv[0], "igp", 2) == 0)
3329 return bgp_route_set_add (vty, vty->index, "origin", "igp");
3330 if (strncmp (argv[0], "egp", 1) == 0)
3331 return bgp_route_set_add (vty, vty->index, "origin", "egp");
3332 if (strncmp (argv[0], "incomplete", 2) == 0)
3333 return bgp_route_set_add (vty, vty->index, "origin", "incomplete");
3334
3335 return CMD_WARNING;
3336}
3337
3338DEFUN (no_set_origin,
3339 no_set_origin_cmd,
3340 "no set origin",
3341 NO_STR
3342 SET_STR
3343 "BGP origin code\n")
3344{
3345 return bgp_route_set_delete (vty, vty->index, "origin", NULL);
3346}
3347
3348ALIAS (no_set_origin,
3349 no_set_origin_val_cmd,
3350 "no set origin (egp|igp|incomplete)",
3351 NO_STR
3352 SET_STR
3353 "BGP origin code\n"
3354 "remote EGP\n"
3355 "local IGP\n"
3356 "unknown heritage\n")
3357
3358DEFUN (set_atomic_aggregate,
3359 set_atomic_aggregate_cmd,
3360 "set atomic-aggregate",
3361 SET_STR
3362 "BGP atomic aggregate attribute\n" )
3363{
3364 return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL);
3365}
3366
3367DEFUN (no_set_atomic_aggregate,
3368 no_set_atomic_aggregate_cmd,
3369 "no set atomic-aggregate",
3370 NO_STR
3371 SET_STR
3372 "BGP atomic aggregate attribute\n" )
3373{
3374 return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL);
3375}
3376
3377DEFUN (set_aggregator_as,
3378 set_aggregator_as_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003379 "set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003380 SET_STR
3381 "BGP aggregator attribute\n"
3382 "AS number of aggregator\n"
3383 "AS number\n"
3384 "IP address of aggregator\n")
3385{
3386 int ret;
3387 as_t as;
3388 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003389 char *argstr;
3390
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003391 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paulfd79ac92004-10-13 05:06:08 +00003392
paul718e3742002-12-13 20:15:29 +00003393 ret = inet_aton (argv[1], &address);
3394 if (ret == 0)
3395 {
3396 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3397 return CMD_WARNING;
3398 }
3399
3400 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3401 strlen (argv[0]) + strlen (argv[1]) + 2);
3402
3403 sprintf (argstr, "%s %s", argv[0], argv[1]);
3404
3405 ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr);
3406
3407 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3408
3409 return ret;
3410}
3411
3412DEFUN (no_set_aggregator_as,
3413 no_set_aggregator_as_cmd,
3414 "no set aggregator as",
3415 NO_STR
3416 SET_STR
3417 "BGP aggregator attribute\n"
3418 "AS number of aggregator\n")
3419{
3420 int ret;
3421 as_t as;
3422 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003423 char *argstr;
3424
3425 if (argv == 0)
3426 return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL);
3427
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003428 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paul718e3742002-12-13 20:15:29 +00003429
3430 ret = inet_aton (argv[1], &address);
3431 if (ret == 0)
3432 {
3433 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3434 return CMD_WARNING;
3435 }
3436
3437 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3438 strlen (argv[0]) + strlen (argv[1]) + 2);
3439
3440 sprintf (argstr, "%s %s", argv[0], argv[1]);
3441
3442 ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr);
3443
3444 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3445
3446 return ret;
3447}
3448
3449ALIAS (no_set_aggregator_as,
3450 no_set_aggregator_as_val_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003451 "no set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003452 NO_STR
3453 SET_STR
3454 "BGP aggregator attribute\n"
3455 "AS number of aggregator\n"
3456 "AS number\n"
3457 "IP address of aggregator\n")
3458
3459
3460#ifdef HAVE_IPV6
3461DEFUN (match_ipv6_address,
3462 match_ipv6_address_cmd,
3463 "match ipv6 address WORD",
3464 MATCH_STR
3465 IPV6_STR
3466 "Match IPv6 address of route\n"
3467 "IPv6 access-list name\n")
3468{
3469 return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]);
3470}
3471
3472DEFUN (no_match_ipv6_address,
3473 no_match_ipv6_address_cmd,
3474 "no match ipv6 address WORD",
3475 NO_STR
3476 MATCH_STR
3477 IPV6_STR
3478 "Match IPv6 address of route\n"
3479 "IPv6 access-list name\n")
3480{
3481 return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]);
3482}
3483
3484DEFUN (match_ipv6_next_hop,
3485 match_ipv6_next_hop_cmd,
3486 "match ipv6 next-hop X:X::X:X",
3487 MATCH_STR
3488 IPV6_STR
3489 "Match IPv6 next-hop address of route\n"
3490 "IPv6 address of next hop\n")
3491{
3492 return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]);
3493}
3494
3495DEFUN (no_match_ipv6_next_hop,
3496 no_match_ipv6_next_hop_cmd,
3497 "no match ipv6 next-hop X:X::X:X",
3498 NO_STR
3499 MATCH_STR
3500 IPV6_STR
3501 "Match IPv6 next-hop address of route\n"
3502 "IPv6 address of next hop\n")
3503{
3504 return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
3505}
3506
3507DEFUN (match_ipv6_address_prefix_list,
3508 match_ipv6_address_prefix_list_cmd,
3509 "match ipv6 address prefix-list WORD",
3510 MATCH_STR
3511 IPV6_STR
3512 "Match address of route\n"
3513 "Match entries of prefix-lists\n"
3514 "IP prefix-list name\n")
3515{
3516 return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3517}
3518
3519DEFUN (no_match_ipv6_address_prefix_list,
3520 no_match_ipv6_address_prefix_list_cmd,
3521 "no match ipv6 address prefix-list WORD",
3522 NO_STR
3523 MATCH_STR
3524 IPV6_STR
3525 "Match address of route\n"
3526 "Match entries of prefix-lists\n"
3527 "IP prefix-list name\n")
3528{
3529 return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3530}
3531
3532DEFUN (set_ipv6_nexthop_global,
3533 set_ipv6_nexthop_global_cmd,
3534 "set ipv6 next-hop global X:X::X:X",
3535 SET_STR
3536 IPV6_STR
3537 "IPv6 next-hop address\n"
3538 "IPv6 global address\n"
3539 "IPv6 address of next hop\n")
3540{
3541 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]);
3542}
3543
3544DEFUN (no_set_ipv6_nexthop_global,
3545 no_set_ipv6_nexthop_global_cmd,
3546 "no set ipv6 next-hop global",
3547 NO_STR
3548 SET_STR
3549 IPV6_STR
3550 "IPv6 next-hop address\n"
3551 "IPv6 global address\n")
3552{
3553 if (argc == 0)
3554 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL);
3555
3556 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]);
3557}
3558
3559ALIAS (no_set_ipv6_nexthop_global,
3560 no_set_ipv6_nexthop_global_val_cmd,
3561 "no set ipv6 next-hop global X:X::X:X",
3562 NO_STR
3563 SET_STR
3564 IPV6_STR
3565 "IPv6 next-hop address\n"
3566 "IPv6 global address\n"
3567 "IPv6 address of next hop\n")
3568
3569DEFUN (set_ipv6_nexthop_local,
3570 set_ipv6_nexthop_local_cmd,
3571 "set ipv6 next-hop local X:X::X:X",
3572 SET_STR
3573 IPV6_STR
3574 "IPv6 next-hop address\n"
3575 "IPv6 local address\n"
3576 "IPv6 address of next hop\n")
3577{
3578 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
3579}
3580
3581DEFUN (no_set_ipv6_nexthop_local,
3582 no_set_ipv6_nexthop_local_cmd,
3583 "no set ipv6 next-hop local",
3584 NO_STR
3585 SET_STR
3586 IPV6_STR
3587 "IPv6 next-hop address\n"
3588 "IPv6 local address\n")
3589{
3590 if (argc == 0)
3591 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
3592
3593 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
3594}
3595
3596ALIAS (no_set_ipv6_nexthop_local,
3597 no_set_ipv6_nexthop_local_val_cmd,
3598 "no set ipv6 next-hop local X:X::X:X",
3599 NO_STR
3600 SET_STR
3601 IPV6_STR
3602 "IPv6 next-hop address\n"
3603 "IPv6 local address\n"
3604 "IPv6 address of next hop\n")
3605#endif /* HAVE_IPV6 */
3606
3607DEFUN (set_vpnv4_nexthop,
3608 set_vpnv4_nexthop_cmd,
3609 "set vpnv4 next-hop A.B.C.D",
3610 SET_STR
3611 "VPNv4 information\n"
3612 "VPNv4 next-hop address\n"
3613 "IP address of next hop\n")
3614{
3615 return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]);
3616}
3617
3618DEFUN (no_set_vpnv4_nexthop,
3619 no_set_vpnv4_nexthop_cmd,
3620 "no set vpnv4 next-hop",
3621 NO_STR
3622 SET_STR
3623 "VPNv4 information\n"
3624 "VPNv4 next-hop address\n")
3625{
3626 if (argc == 0)
3627 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL);
3628
3629 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]);
3630}
3631
3632ALIAS (no_set_vpnv4_nexthop,
3633 no_set_vpnv4_nexthop_val_cmd,
3634 "no set vpnv4 next-hop A.B.C.D",
3635 NO_STR
3636 SET_STR
3637 "VPNv4 information\n"
3638 "VPNv4 next-hop address\n"
3639 "IP address of next hop\n")
3640
3641DEFUN (set_originator_id,
3642 set_originator_id_cmd,
3643 "set originator-id A.B.C.D",
3644 SET_STR
3645 "BGP originator ID attribute\n"
3646 "IP address of originator\n")
3647{
3648 return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]);
3649}
3650
3651DEFUN (no_set_originator_id,
3652 no_set_originator_id_cmd,
3653 "no set originator-id",
3654 NO_STR
3655 SET_STR
3656 "BGP originator ID attribute\n")
3657{
3658 if (argc == 0)
3659 return bgp_route_set_delete (vty, vty->index, "originator-id", NULL);
3660
3661 return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]);
3662}
3663
3664ALIAS (no_set_originator_id,
3665 no_set_originator_id_val_cmd,
3666 "no set originator-id A.B.C.D",
3667 NO_STR
3668 SET_STR
3669 "BGP originator ID attribute\n"
3670 "IP address of originator\n")
3671
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003672DEFUN_DEPRECATED (set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003673 set_pathlimit_ttl_cmd,
3674 "set pathlimit ttl <1-255>",
3675 SET_STR
3676 "BGP AS-Pathlimit attribute\n"
3677 "Set AS-Path Hop-count TTL\n")
3678{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003679 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003680}
3681
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003682DEFUN_DEPRECATED (no_set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003683 no_set_pathlimit_ttl_cmd,
3684 "no set pathlimit ttl",
3685 NO_STR
3686 SET_STR
3687 "BGP AS-Pathlimit attribute\n"
3688 "Set AS-Path Hop-count TTL\n")
3689{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003690 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003691}
3692
3693ALIAS (no_set_pathlimit_ttl,
3694 no_set_pathlimit_ttl_val_cmd,
3695 "no set pathlimit ttl <1-255>",
3696 NO_STR
3697 MATCH_STR
3698 "BGP AS-Pathlimit attribute\n"
3699 "Set AS-Path Hop-count TTL\n")
3700
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003701DEFUN_DEPRECATED (match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003702 match_pathlimit_as_cmd,
3703 "match pathlimit as <1-65535>",
3704 MATCH_STR
3705 "BGP AS-Pathlimit attribute\n"
3706 "Match Pathlimit AS number\n")
3707{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003708 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003709}
3710
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003711DEFUN_DEPRECATED (no_match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003712 no_match_pathlimit_as_cmd,
3713 "no match pathlimit as",
3714 NO_STR
3715 MATCH_STR
3716 "BGP AS-Pathlimit attribute\n"
3717 "Match Pathlimit AS number\n")
3718{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003719 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003720}
3721
3722ALIAS (no_match_pathlimit_as,
3723 no_match_pathlimit_as_val_cmd,
3724 "no match pathlimit as <1-65535>",
3725 NO_STR
3726 MATCH_STR
3727 "BGP AS-Pathlimit attribute\n"
3728 "Match Pathlimit ASN\n")
3729
paul718e3742002-12-13 20:15:29 +00003730
3731/* Initialization of route map. */
3732void
paul94f2b392005-06-28 12:44:16 +00003733bgp_route_map_init (void)
paul718e3742002-12-13 20:15:29 +00003734{
3735 route_map_init ();
3736 route_map_init_vty ();
3737 route_map_add_hook (bgp_route_map_update);
3738 route_map_delete_hook (bgp_route_map_update);
3739
paulfee0f4c2004-09-13 05:12:46 +00003740 route_map_install_match (&route_match_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003741 route_map_install_match (&route_match_ip_address_cmd);
3742 route_map_install_match (&route_match_ip_next_hop_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003743 route_map_install_match (&route_match_ip_route_source_cmd);
paul718e3742002-12-13 20:15:29 +00003744 route_map_install_match (&route_match_ip_address_prefix_list_cmd);
3745 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003746 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +00003747 route_map_install_match (&route_match_aspath_cmd);
3748 route_map_install_match (&route_match_community_cmd);
paul73ffb252003-04-19 15:49:49 +00003749 route_map_install_match (&route_match_ecommunity_cmd);
paul718e3742002-12-13 20:15:29 +00003750 route_map_install_match (&route_match_metric_cmd);
3751 route_map_install_match (&route_match_origin_cmd);
3752
3753 route_map_install_set (&route_set_ip_nexthop_cmd);
3754 route_map_install_set (&route_set_local_pref_cmd);
3755 route_map_install_set (&route_set_weight_cmd);
3756 route_map_install_set (&route_set_metric_cmd);
3757 route_map_install_set (&route_set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003758 route_map_install_set (&route_set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003759 route_map_install_set (&route_set_origin_cmd);
3760 route_map_install_set (&route_set_atomic_aggregate_cmd);
3761 route_map_install_set (&route_set_aggregator_as_cmd);
3762 route_map_install_set (&route_set_community_cmd);
3763 route_map_install_set (&route_set_community_delete_cmd);
3764 route_map_install_set (&route_set_vpnv4_nexthop_cmd);
3765 route_map_install_set (&route_set_originator_id_cmd);
3766 route_map_install_set (&route_set_ecommunity_rt_cmd);
3767 route_map_install_set (&route_set_ecommunity_soo_cmd);
3768
paulfee0f4c2004-09-13 05:12:46 +00003769 install_element (RMAP_NODE, &match_peer_cmd);
3770 install_element (RMAP_NODE, &match_peer_local_cmd);
3771 install_element (RMAP_NODE, &no_match_peer_cmd);
3772 install_element (RMAP_NODE, &no_match_peer_val_cmd);
3773 install_element (RMAP_NODE, &no_match_peer_local_cmd);
paul718e3742002-12-13 20:15:29 +00003774 install_element (RMAP_NODE, &match_ip_address_cmd);
3775 install_element (RMAP_NODE, &no_match_ip_address_cmd);
3776 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
3777 install_element (RMAP_NODE, &match_ip_next_hop_cmd);
3778 install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
3779 install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003780 install_element (RMAP_NODE, &match_ip_route_source_cmd);
3781 install_element (RMAP_NODE, &no_match_ip_route_source_cmd);
3782 install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd);
paul718e3742002-12-13 20:15:29 +00003783
3784 install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
3785 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
3786 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
3787 install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
3788 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
3789 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003790 install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
3791 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
3792 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd);
paul718e3742002-12-13 20:15:29 +00003793
3794 install_element (RMAP_NODE, &match_aspath_cmd);
3795 install_element (RMAP_NODE, &no_match_aspath_cmd);
3796 install_element (RMAP_NODE, &no_match_aspath_val_cmd);
3797 install_element (RMAP_NODE, &match_metric_cmd);
3798 install_element (RMAP_NODE, &no_match_metric_cmd);
3799 install_element (RMAP_NODE, &no_match_metric_val_cmd);
3800 install_element (RMAP_NODE, &match_community_cmd);
3801 install_element (RMAP_NODE, &match_community_exact_cmd);
3802 install_element (RMAP_NODE, &no_match_community_cmd);
3803 install_element (RMAP_NODE, &no_match_community_val_cmd);
3804 install_element (RMAP_NODE, &no_match_community_exact_cmd);
paul73ffb252003-04-19 15:49:49 +00003805 install_element (RMAP_NODE, &match_ecommunity_cmd);
3806 install_element (RMAP_NODE, &no_match_ecommunity_cmd);
3807 install_element (RMAP_NODE, &no_match_ecommunity_val_cmd);
paul718e3742002-12-13 20:15:29 +00003808 install_element (RMAP_NODE, &match_origin_cmd);
3809 install_element (RMAP_NODE, &no_match_origin_cmd);
3810 install_element (RMAP_NODE, &no_match_origin_val_cmd);
3811
3812 install_element (RMAP_NODE, &set_ip_nexthop_cmd);
paulaf5cd0a2003-11-02 07:24:40 +00003813 install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003814 install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
3815 install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
3816 install_element (RMAP_NODE, &set_local_pref_cmd);
3817 install_element (RMAP_NODE, &no_set_local_pref_cmd);
3818 install_element (RMAP_NODE, &no_set_local_pref_val_cmd);
3819 install_element (RMAP_NODE, &set_weight_cmd);
3820 install_element (RMAP_NODE, &no_set_weight_cmd);
3821 install_element (RMAP_NODE, &no_set_weight_val_cmd);
3822 install_element (RMAP_NODE, &set_metric_cmd);
paul73ffb252003-04-19 15:49:49 +00003823 install_element (RMAP_NODE, &set_metric_addsub_cmd);
paul718e3742002-12-13 20:15:29 +00003824 install_element (RMAP_NODE, &no_set_metric_cmd);
3825 install_element (RMAP_NODE, &no_set_metric_val_cmd);
3826 install_element (RMAP_NODE, &set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003827 install_element (RMAP_NODE, &set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003828 install_element (RMAP_NODE, &no_set_aspath_prepend_cmd);
3829 install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003830 install_element (RMAP_NODE, &no_set_aspath_exclude_cmd);
3831 install_element (RMAP_NODE, &no_set_aspath_exclude_val_cmd);
paul718e3742002-12-13 20:15:29 +00003832 install_element (RMAP_NODE, &set_origin_cmd);
3833 install_element (RMAP_NODE, &no_set_origin_cmd);
3834 install_element (RMAP_NODE, &no_set_origin_val_cmd);
3835 install_element (RMAP_NODE, &set_atomic_aggregate_cmd);
3836 install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd);
3837 install_element (RMAP_NODE, &set_aggregator_as_cmd);
3838 install_element (RMAP_NODE, &no_set_aggregator_as_cmd);
3839 install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd);
3840 install_element (RMAP_NODE, &set_community_cmd);
3841 install_element (RMAP_NODE, &set_community_none_cmd);
3842 install_element (RMAP_NODE, &no_set_community_cmd);
3843 install_element (RMAP_NODE, &no_set_community_val_cmd);
3844 install_element (RMAP_NODE, &no_set_community_none_cmd);
3845 install_element (RMAP_NODE, &set_community_delete_cmd);
3846 install_element (RMAP_NODE, &no_set_community_delete_cmd);
3847 install_element (RMAP_NODE, &no_set_community_delete_val_cmd);
3848 install_element (RMAP_NODE, &set_ecommunity_rt_cmd);
3849 install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd);
3850 install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd);
3851 install_element (RMAP_NODE, &set_ecommunity_soo_cmd);
3852 install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd);
3853 install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd);
3854 install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd);
3855 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd);
3856 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd);
3857 install_element (RMAP_NODE, &set_originator_id_cmd);
3858 install_element (RMAP_NODE, &no_set_originator_id_cmd);
3859 install_element (RMAP_NODE, &no_set_originator_id_val_cmd);
3860
3861#ifdef HAVE_IPV6
3862 route_map_install_match (&route_match_ipv6_address_cmd);
3863 route_map_install_match (&route_match_ipv6_next_hop_cmd);
3864 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd);
3865 route_map_install_set (&route_set_ipv6_nexthop_global_cmd);
3866 route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
Paul Jakma41367172007-08-06 15:24:51 +00003867
paul718e3742002-12-13 20:15:29 +00003868 install_element (RMAP_NODE, &match_ipv6_address_cmd);
3869 install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
3870 install_element (RMAP_NODE, &match_ipv6_next_hop_cmd);
3871 install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd);
3872 install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
3873 install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
3874 install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd);
3875 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
3876 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd);
3877 install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
3878 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
3879 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
3880#endif /* HAVE_IPV6 */
Paul Jakma41367172007-08-06 15:24:51 +00003881
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003882 /* AS-Pathlimit: functionality removed, commands kept for
3883 * compatibility.
3884 */
Paul Jakma41367172007-08-06 15:24:51 +00003885 install_element (RMAP_NODE, &set_pathlimit_ttl_cmd);
3886 install_element (RMAP_NODE, &no_set_pathlimit_ttl_cmd);
3887 install_element (RMAP_NODE, &no_set_pathlimit_ttl_val_cmd);
3888 install_element (RMAP_NODE, &match_pathlimit_as_cmd);
3889 install_element (RMAP_NODE, &no_match_pathlimit_as_cmd);
3890 install_element (RMAP_NODE, &no_match_pathlimit_as_val_cmd);
paul718e3742002-12-13 20:15:29 +00003891}