blob: 81ff48dbd6cb5278568b371a95c6292c4926d4f9 [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 */
paul718e3742002-12-13 20:15:29 +00001300 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));
paul718e3742002-12-13 20:15:29 +00001341 rcs->com = com;
1342 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
1396 if (new->size == 0)
1397 {
1398 binfo->attr->community = NULL;
1399 binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1400 community_free (new);
1401 }
1402 else
1403 {
1404 binfo->attr->community = new;
1405 binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1406 }
1407 }
1408 }
1409
1410 return RMAP_OKAY;
1411}
1412
1413/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001414static void *
paulfd79ac92004-10-13 05:06:08 +00001415route_set_community_delete_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001416{
1417 char *p;
1418 char *str;
1419 int len;
1420
1421 p = strchr (arg, ' ');
1422 if (p)
1423 {
1424 len = p - arg;
1425 str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
1426 memcpy (str, arg, len);
1427 }
1428 else
1429 str = NULL;
1430
1431 return str;
1432}
1433
1434/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001435static void
paul718e3742002-12-13 20:15:29 +00001436route_set_community_delete_free (void *rule)
1437{
1438 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1439}
1440
1441/* Set community rule structure. */
1442struct route_map_rule_cmd route_set_community_delete_cmd =
1443{
1444 "comm-list",
1445 route_set_community_delete,
1446 route_set_community_delete_compile,
1447 route_set_community_delete_free,
1448};
1449
1450/* `set extcommunity rt COMMUNITY' */
1451
1452/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001453static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001454route_set_ecommunity_rt (void *rule, struct prefix *prefix,
1455 route_map_object_t type, void *object)
1456{
1457 struct ecommunity *ecom;
1458 struct ecommunity *new_ecom;
1459 struct ecommunity *old_ecom;
1460 struct bgp_info *bgp_info;
1461
1462 if (type == RMAP_BGP)
1463 {
1464 ecom = rule;
1465 bgp_info = object;
1466
1467 if (! ecom)
1468 return RMAP_OKAY;
1469
1470 /* We assume additive for Extended Community. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001471 old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
paul718e3742002-12-13 20:15:29 +00001472
1473 if (old_ecom)
1474 new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
1475 else
1476 new_ecom = ecommunity_dup (ecom);
1477
Paul Jakmafb982c22007-05-04 20:15:47 +00001478 bgp_info->attr->extra->ecommunity = new_ecom;
paul718e3742002-12-13 20:15:29 +00001479
hasso70601e02005-05-27 03:26:57 +00001480 if (old_ecom)
1481 ecommunity_free (old_ecom);
1482
paul718e3742002-12-13 20:15:29 +00001483 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
1484 }
1485 return RMAP_OKAY;
1486}
1487
1488/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001489static void *
paulfd79ac92004-10-13 05:06:08 +00001490route_set_ecommunity_rt_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001491{
1492 struct ecommunity *ecom;
1493
1494 ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0);
1495 if (! ecom)
1496 return NULL;
1497 return ecom;
1498}
1499
1500/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001501static void
paul718e3742002-12-13 20:15:29 +00001502route_set_ecommunity_rt_free (void *rule)
1503{
1504 struct ecommunity *ecom = rule;
1505 ecommunity_free (ecom);
1506}
1507
1508/* Set community rule structure. */
1509struct route_map_rule_cmd route_set_ecommunity_rt_cmd =
1510{
1511 "extcommunity rt",
1512 route_set_ecommunity_rt,
1513 route_set_ecommunity_rt_compile,
1514 route_set_ecommunity_rt_free,
1515};
1516
1517/* `set extcommunity soo COMMUNITY' */
1518
1519/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001520static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001521route_set_ecommunity_soo (void *rule, struct prefix *prefix,
1522 route_map_object_t type, void *object)
1523{
1524 struct ecommunity *ecom;
1525 struct bgp_info *bgp_info;
1526
1527 if (type == RMAP_BGP)
1528 {
1529 ecom = rule;
1530 bgp_info = object;
1531
1532 if (! ecom)
1533 return RMAP_OKAY;
1534
1535 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
Paul Jakmafb982c22007-05-04 20:15:47 +00001536 (bgp_attr_extra_get (bgp_info->attr))->ecommunity = ecommunity_dup (ecom);
paul718e3742002-12-13 20:15:29 +00001537 }
1538 return RMAP_OKAY;
1539}
1540
1541/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001542static void *
paulfd79ac92004-10-13 05:06:08 +00001543route_set_ecommunity_soo_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001544{
1545 struct ecommunity *ecom;
1546
1547 ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0);
1548 if (! ecom)
1549 return NULL;
1550
1551 return ecom;
1552}
1553
1554/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001555static void
paul718e3742002-12-13 20:15:29 +00001556route_set_ecommunity_soo_free (void *rule)
1557{
1558 struct ecommunity *ecom = rule;
1559 ecommunity_free (ecom);
1560}
1561
1562/* Set community rule structure. */
1563struct route_map_rule_cmd route_set_ecommunity_soo_cmd =
1564{
1565 "extcommunity soo",
1566 route_set_ecommunity_soo,
1567 route_set_ecommunity_soo_compile,
1568 route_set_ecommunity_soo_free,
1569};
1570
1571/* `set origin ORIGIN' */
1572
1573/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00001574static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001575route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1576{
1577 u_char *origin;
1578 struct bgp_info *bgp_info;
1579
1580 if (type == RMAP_BGP)
1581 {
1582 origin = rule;
1583 bgp_info = object;
1584
1585 bgp_info->attr->origin = *origin;
1586 }
1587
1588 return RMAP_OKAY;
1589}
1590
1591/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001592static void *
paulfd79ac92004-10-13 05:06:08 +00001593route_set_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001594{
1595 u_char *origin;
1596
1597 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
1598
1599 if (strcmp (arg, "igp") == 0)
1600 *origin = 0;
1601 else if (strcmp (arg, "egp") == 0)
1602 *origin = 1;
1603 else
1604 *origin = 2;
1605
1606 return origin;
1607}
1608
1609/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001610static void
paul718e3742002-12-13 20:15:29 +00001611route_set_origin_free (void *rule)
1612{
1613 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1614}
1615
1616/* Set metric rule structure. */
1617struct route_map_rule_cmd route_set_origin_cmd =
1618{
1619 "origin",
1620 route_set_origin,
1621 route_set_origin_compile,
1622 route_set_origin_free,
1623};
1624
1625/* `set atomic-aggregate' */
1626
1627/* For atomic aggregate set. */
paul94f2b392005-06-28 12:44:16 +00001628static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001629route_set_atomic_aggregate (void *rule, struct prefix *prefix,
1630 route_map_object_t type, void *object)
1631{
1632 struct bgp_info *bgp_info;
1633
1634 if (type == RMAP_BGP)
1635 {
1636 bgp_info = object;
1637 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
1638 }
1639
1640 return RMAP_OKAY;
1641}
1642
1643/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001644static void *
paulfd79ac92004-10-13 05:06:08 +00001645route_set_atomic_aggregate_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001646{
1647 return (void *)1;
1648}
1649
1650/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001651static void
paul718e3742002-12-13 20:15:29 +00001652route_set_atomic_aggregate_free (void *rule)
1653{
1654 return;
1655}
1656
1657/* Set atomic aggregate rule structure. */
1658struct route_map_rule_cmd route_set_atomic_aggregate_cmd =
1659{
1660 "atomic-aggregate",
1661 route_set_atomic_aggregate,
1662 route_set_atomic_aggregate_compile,
1663 route_set_atomic_aggregate_free,
1664};
1665
1666/* `set aggregator as AS A.B.C.D' */
1667struct aggregator
1668{
1669 as_t as;
1670 struct in_addr address;
1671};
1672
paul94f2b392005-06-28 12:44:16 +00001673static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001674route_set_aggregator_as (void *rule, struct prefix *prefix,
1675 route_map_object_t type, void *object)
1676{
1677 struct bgp_info *bgp_info;
1678 struct aggregator *aggregator;
Paul Jakmafb982c22007-05-04 20:15:47 +00001679 struct attr_extra *ae;
paul718e3742002-12-13 20:15:29 +00001680
1681 if (type == RMAP_BGP)
1682 {
1683 bgp_info = object;
1684 aggregator = rule;
Paul Jakmafb982c22007-05-04 20:15:47 +00001685 ae = bgp_attr_extra_get (bgp_info->attr);
1686
1687 ae->aggregator_as = aggregator->as;
1688 ae->aggregator_addr = aggregator->address;
paul718e3742002-12-13 20:15:29 +00001689 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
1690 }
1691
1692 return RMAP_OKAY;
1693}
1694
paul94f2b392005-06-28 12:44:16 +00001695static void *
paulfd79ac92004-10-13 05:06:08 +00001696route_set_aggregator_as_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001697{
1698 struct aggregator *aggregator;
1699 char as[10];
1700 char address[20];
1701
Stephen Hemminger393deb92008-08-18 14:13:29 -07001702 aggregator = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));
paul718e3742002-12-13 20:15:29 +00001703 sscanf (arg, "%s %s", as, address);
1704
1705 aggregator->as = strtoul (as, NULL, 10);
1706 inet_aton (address, &aggregator->address);
1707
1708 return aggregator;
1709}
1710
paul94f2b392005-06-28 12:44:16 +00001711static void
paul718e3742002-12-13 20:15:29 +00001712route_set_aggregator_as_free (void *rule)
1713{
1714 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1715}
1716
1717struct route_map_rule_cmd route_set_aggregator_as_cmd =
1718{
1719 "aggregator as",
1720 route_set_aggregator_as,
1721 route_set_aggregator_as_compile,
1722 route_set_aggregator_as_free,
1723};
1724
1725#ifdef HAVE_IPV6
1726/* `match ipv6 address IP_ACCESS_LIST' */
1727
paul94f2b392005-06-28 12:44:16 +00001728static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001729route_match_ipv6_address (void *rule, struct prefix *prefix,
1730 route_map_object_t type, void *object)
1731{
1732 struct access_list *alist;
1733
1734 if (type == RMAP_BGP)
1735 {
1736 alist = access_list_lookup (AFI_IP6, (char *) rule);
1737 if (alist == NULL)
1738 return RMAP_NOMATCH;
1739
1740 return (access_list_apply (alist, prefix) == FILTER_DENY ?
1741 RMAP_NOMATCH : RMAP_MATCH);
1742 }
1743 return RMAP_NOMATCH;
1744}
1745
paul94f2b392005-06-28 12:44:16 +00001746static void *
paulfd79ac92004-10-13 05:06:08 +00001747route_match_ipv6_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001748{
1749 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1750}
1751
paul94f2b392005-06-28 12:44:16 +00001752static void
paul718e3742002-12-13 20:15:29 +00001753route_match_ipv6_address_free (void *rule)
1754{
1755 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1756}
1757
1758/* Route map commands for ip address matching. */
1759struct route_map_rule_cmd route_match_ipv6_address_cmd =
1760{
1761 "ipv6 address",
1762 route_match_ipv6_address,
1763 route_match_ipv6_address_compile,
1764 route_match_ipv6_address_free
1765};
1766
1767/* `match ipv6 next-hop IP_ADDRESS' */
1768
paul94f2b392005-06-28 12:44:16 +00001769static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001770route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
1771 route_map_object_t type, void *object)
1772{
1773 struct in6_addr *addr;
1774 struct bgp_info *bgp_info;
1775
1776 if (type == RMAP_BGP)
1777 {
1778 addr = rule;
1779 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +00001780
1781 if (!bgp_info->attr->extra)
1782 return RMAP_NOMATCH;
1783
1784 if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, rule))
paul718e3742002-12-13 20:15:29 +00001785 return RMAP_MATCH;
1786
Paul Jakmafb982c22007-05-04 20:15:47 +00001787 if (bgp_info->attr->extra->mp_nexthop_len == 32 &&
1788 IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, rule))
paul718e3742002-12-13 20:15:29 +00001789 return RMAP_MATCH;
1790
1791 return RMAP_NOMATCH;
1792 }
1793
1794 return RMAP_NOMATCH;
1795}
1796
paul94f2b392005-06-28 12:44:16 +00001797static void *
paulfd79ac92004-10-13 05:06:08 +00001798route_match_ipv6_next_hop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001799{
1800 struct in6_addr *address;
1801 int ret;
1802
1803 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1804
1805 ret = inet_pton (AF_INET6, arg, address);
1806 if (!ret)
1807 {
1808 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1809 return NULL;
1810 }
1811
1812 return address;
1813}
1814
paul94f2b392005-06-28 12:44:16 +00001815static void
paul718e3742002-12-13 20:15:29 +00001816route_match_ipv6_next_hop_free (void *rule)
1817{
1818 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1819}
1820
1821struct route_map_rule_cmd route_match_ipv6_next_hop_cmd =
1822{
1823 "ipv6 next-hop",
1824 route_match_ipv6_next_hop,
1825 route_match_ipv6_next_hop_compile,
1826 route_match_ipv6_next_hop_free
1827};
1828
1829/* `match ipv6 address prefix-list PREFIX_LIST' */
1830
paul94f2b392005-06-28 12:44:16 +00001831static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001832route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix,
1833 route_map_object_t type, void *object)
1834{
1835 struct prefix_list *plist;
1836
1837 if (type == RMAP_BGP)
1838 {
1839 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
1840 if (plist == NULL)
1841 return RMAP_NOMATCH;
1842
1843 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
1844 RMAP_NOMATCH : RMAP_MATCH);
1845 }
1846 return RMAP_NOMATCH;
1847}
1848
paul94f2b392005-06-28 12:44:16 +00001849static void *
paulfd79ac92004-10-13 05:06:08 +00001850route_match_ipv6_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001851{
1852 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1853}
1854
paul94f2b392005-06-28 12:44:16 +00001855static void
paul718e3742002-12-13 20:15:29 +00001856route_match_ipv6_address_prefix_list_free (void *rule)
1857{
1858 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1859}
1860
1861struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
1862{
1863 "ipv6 address prefix-list",
1864 route_match_ipv6_address_prefix_list,
1865 route_match_ipv6_address_prefix_list_compile,
1866 route_match_ipv6_address_prefix_list_free
1867};
1868
1869/* `set ipv6 nexthop global IP_ADDRESS' */
1870
1871/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001872static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001873route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix,
1874 route_map_object_t type, void *object)
1875{
1876 struct in6_addr *address;
1877 struct bgp_info *bgp_info;
1878
1879 if (type == RMAP_BGP)
1880 {
1881 /* Fetch routemap's rule information. */
1882 address = rule;
1883 bgp_info = object;
1884
1885 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001886 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address;
paul718e3742002-12-13 20:15:29 +00001887
1888 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001889 if (bgp_info->attr->extra->mp_nexthop_len == 0)
1890 bgp_info->attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001891 }
1892
1893 return RMAP_OKAY;
1894}
1895
1896/* Route map `ip next-hop' compile function. Given string is converted
1897 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00001898static void *
paulfd79ac92004-10-13 05:06:08 +00001899route_set_ipv6_nexthop_global_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001900{
1901 int ret;
1902 struct in6_addr *address;
1903
1904 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1905
1906 ret = inet_pton (AF_INET6, arg, address);
1907
1908 if (ret == 0)
1909 {
1910 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1911 return NULL;
1912 }
1913
1914 return address;
1915}
1916
1917/* Free route map's compiled `ip next-hop' value. */
paul94f2b392005-06-28 12:44:16 +00001918static void
paul718e3742002-12-13 20:15:29 +00001919route_set_ipv6_nexthop_global_free (void *rule)
1920{
1921 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1922}
1923
1924/* Route map commands for ip nexthop set. */
1925struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd =
1926{
1927 "ipv6 next-hop global",
1928 route_set_ipv6_nexthop_global,
1929 route_set_ipv6_nexthop_global_compile,
1930 route_set_ipv6_nexthop_global_free
1931};
1932
1933/* `set ipv6 nexthop local IP_ADDRESS' */
1934
1935/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001936static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001937route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
1938 route_map_object_t type, void *object)
1939{
1940 struct in6_addr *address;
1941 struct bgp_info *bgp_info;
1942
1943 if (type == RMAP_BGP)
1944 {
1945 /* Fetch routemap's rule information. */
1946 address = rule;
1947 bgp_info = object;
1948
1949 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001950 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address;
paul718e3742002-12-13 20:15:29 +00001951
1952 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001953 if (bgp_info->attr->extra->mp_nexthop_len != 32)
1954 bgp_info->attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001955 }
1956
1957 return RMAP_OKAY;
1958}
1959
1960/* Route map `ip nexthop' compile function. Given string is converted
1961 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00001962static void *
paulfd79ac92004-10-13 05:06:08 +00001963route_set_ipv6_nexthop_local_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001964{
1965 int ret;
1966 struct in6_addr *address;
1967
1968 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1969
1970 ret = inet_pton (AF_INET6, arg, address);
1971
1972 if (ret == 0)
1973 {
1974 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1975 return NULL;
1976 }
1977
1978 return address;
1979}
1980
1981/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +00001982static void
paul718e3742002-12-13 20:15:29 +00001983route_set_ipv6_nexthop_local_free (void *rule)
1984{
1985 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1986}
1987
1988/* Route map commands for ip nexthop set. */
1989struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd =
1990{
1991 "ipv6 next-hop local",
1992 route_set_ipv6_nexthop_local,
1993 route_set_ipv6_nexthop_local_compile,
1994 route_set_ipv6_nexthop_local_free
1995};
1996#endif /* HAVE_IPV6 */
1997
1998/* `set vpnv4 nexthop A.B.C.D' */
1999
paul94f2b392005-06-28 12:44:16 +00002000static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002001route_set_vpnv4_nexthop (void *rule, struct prefix *prefix,
2002 route_map_object_t type, void *object)
2003{
2004 struct in_addr *address;
2005 struct bgp_info *bgp_info;
2006
2007 if (type == RMAP_BGP)
2008 {
2009 /* Fetch routemap's rule information. */
2010 address = rule;
2011 bgp_info = object;
2012
2013 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002014 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address;
paul718e3742002-12-13 20:15:29 +00002015 }
2016
2017 return RMAP_OKAY;
2018}
2019
paul94f2b392005-06-28 12:44:16 +00002020static void *
paulfd79ac92004-10-13 05:06:08 +00002021route_set_vpnv4_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002022{
2023 int ret;
2024 struct in_addr *address;
2025
2026 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2027
2028 ret = inet_aton (arg, address);
2029
2030 if (ret == 0)
2031 {
2032 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2033 return NULL;
2034 }
2035
2036 return address;
2037}
2038
paul94f2b392005-06-28 12:44:16 +00002039static void
paul718e3742002-12-13 20:15:29 +00002040route_set_vpnv4_nexthop_free (void *rule)
2041{
2042 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2043}
2044
2045/* Route map commands for ip nexthop set. */
2046struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd =
2047{
2048 "vpnv4 next-hop",
2049 route_set_vpnv4_nexthop,
2050 route_set_vpnv4_nexthop_compile,
2051 route_set_vpnv4_nexthop_free
2052};
2053
2054/* `set originator-id' */
2055
2056/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00002057static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002058route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
2059{
2060 struct in_addr *address;
2061 struct bgp_info *bgp_info;
2062
2063 if (type == RMAP_BGP)
2064 {
2065 address = rule;
2066 bgp_info = object;
2067
2068 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);
Paul Jakmafb982c22007-05-04 20:15:47 +00002069 (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address;
paul718e3742002-12-13 20:15:29 +00002070 }
2071
2072 return RMAP_OKAY;
2073}
2074
2075/* Compile function for originator-id set. */
paul94f2b392005-06-28 12:44:16 +00002076static void *
paulfd79ac92004-10-13 05:06:08 +00002077route_set_originator_id_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002078{
2079 int ret;
2080 struct in_addr *address;
2081
2082 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2083
2084 ret = inet_aton (arg, address);
2085
2086 if (ret == 0)
2087 {
2088 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2089 return NULL;
2090 }
2091
2092 return address;
2093}
2094
2095/* Compile function for originator_id set. */
paul94f2b392005-06-28 12:44:16 +00002096static void
paul718e3742002-12-13 20:15:29 +00002097route_set_originator_id_free (void *rule)
2098{
2099 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2100}
2101
2102/* Set metric rule structure. */
2103struct route_map_rule_cmd route_set_originator_id_cmd =
2104{
2105 "originator-id",
2106 route_set_originator_id,
2107 route_set_originator_id_compile,
2108 route_set_originator_id_free,
2109};
2110
2111/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002112static int
paul718e3742002-12-13 20:15:29 +00002113bgp_route_match_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002114 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002115{
2116 int ret;
2117
2118 ret = route_map_add_match (index, command, arg);
2119 if (ret)
2120 {
2121 switch (ret)
2122 {
2123 case RMAP_RULE_MISSING:
2124 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2125 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002126 case RMAP_COMPILE_ERROR:
2127 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2128 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002129 }
2130 }
2131 return CMD_SUCCESS;
2132}
2133
2134/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002135static int
paul718e3742002-12-13 20:15:29 +00002136bgp_route_match_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002137 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002138{
2139 int ret;
2140
2141 ret = route_map_delete_match (index, command, arg);
2142 if (ret)
2143 {
2144 switch (ret)
2145 {
2146 case RMAP_RULE_MISSING:
2147 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2148 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002149 case RMAP_COMPILE_ERROR:
2150 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2151 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002152 }
2153 }
2154 return CMD_SUCCESS;
2155}
2156
2157/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002158static int
paul718e3742002-12-13 20:15:29 +00002159bgp_route_set_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002160 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002161{
2162 int ret;
2163
2164 ret = route_map_add_set (index, command, arg);
2165 if (ret)
2166 {
2167 switch (ret)
2168 {
2169 case RMAP_RULE_MISSING:
2170 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2171 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002172 case RMAP_COMPILE_ERROR:
2173 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2174 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002175 }
2176 }
2177 return CMD_SUCCESS;
2178}
2179
2180/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002181static int
paul718e3742002-12-13 20:15:29 +00002182bgp_route_set_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002183 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002184{
2185 int ret;
2186
2187 ret = route_map_delete_set (index, command, arg);
2188 if (ret)
2189 {
2190 switch (ret)
2191 {
2192 case RMAP_RULE_MISSING:
2193 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2194 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002195 case RMAP_COMPILE_ERROR:
2196 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2197 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002198 }
2199 }
2200 return CMD_SUCCESS;
2201}
2202
2203/* Hook function for updating route_map assignment. */
paul94f2b392005-06-28 12:44:16 +00002204static void
paulfd79ac92004-10-13 05:06:08 +00002205bgp_route_map_update (const char *unused)
paul718e3742002-12-13 20:15:29 +00002206{
2207 int i;
2208 afi_t afi;
2209 safi_t safi;
2210 int direct;
paul1eb8ef22005-04-07 07:30:20 +00002211 struct listnode *node, *nnode;
2212 struct listnode *mnode, *mnnode;
paul718e3742002-12-13 20:15:29 +00002213 struct bgp *bgp;
2214 struct peer *peer;
2215 struct peer_group *group;
2216 struct bgp_filter *filter;
2217 struct bgp_node *bn;
2218 struct bgp_static *bgp_static;
2219
2220 /* For neighbor route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002221 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002222 {
paul1eb8ef22005-04-07 07:30:20 +00002223 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002224 {
2225 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2226 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2227 {
2228 filter = &peer->filter[afi][safi];
2229
paulfee0f4c2004-09-13 05:12:46 +00002230 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002231 {
2232 if (filter->map[direct].name)
2233 filter->map[direct].map =
2234 route_map_lookup_by_name (filter->map[direct].name);
2235 else
2236 filter->map[direct].map = NULL;
2237 }
2238
2239 if (filter->usmap.name)
2240 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2241 else
2242 filter->usmap.map = NULL;
2243 }
2244 }
paul1eb8ef22005-04-07 07:30:20 +00002245 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
paul718e3742002-12-13 20:15:29 +00002246 {
2247 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2248 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2249 {
2250 filter = &group->conf->filter[afi][safi];
2251
paulfee0f4c2004-09-13 05:12:46 +00002252 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002253 {
2254 if (filter->map[direct].name)
2255 filter->map[direct].map =
2256 route_map_lookup_by_name (filter->map[direct].name);
2257 else
2258 filter->map[direct].map = NULL;
2259 }
2260
2261 if (filter->usmap.name)
2262 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2263 else
2264 filter->usmap.map = NULL;
2265 }
2266 }
2267 }
2268
2269 /* For default-originate route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002270 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002271 {
paul1eb8ef22005-04-07 07:30:20 +00002272 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002273 {
2274 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2275 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2276 {
2277 if (peer->default_rmap[afi][safi].name)
2278 peer->default_rmap[afi][safi].map =
2279 route_map_lookup_by_name (peer->default_rmap[afi][safi].name);
2280 else
2281 peer->default_rmap[afi][safi].map = NULL;
2282 }
2283 }
2284 }
2285
2286 /* For network route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002287 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002288 {
2289 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2290 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2291 for (bn = bgp_table_top (bgp->route[afi][safi]); bn;
2292 bn = bgp_route_next (bn))
2293 if ((bgp_static = bn->info) != NULL)
2294 {
2295 if (bgp_static->rmap.name)
2296 bgp_static->rmap.map =
2297 route_map_lookup_by_name (bgp_static->rmap.name);
2298 else
2299 bgp_static->rmap.map = NULL;
2300 }
2301 }
2302
2303 /* For redistribute route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002304 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002305 {
2306 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2307 {
2308 if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)
2309 bgp->rmap[ZEBRA_FAMILY_IPV4][i].map =
2310 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);
2311#ifdef HAVE_IPV6
2312 if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)
2313 bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =
2314 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);
2315#endif /* HAVE_IPV6 */
2316 }
2317 }
2318}
2319
paulfee0f4c2004-09-13 05:12:46 +00002320DEFUN (match_peer,
2321 match_peer_cmd,
2322 "match peer (A.B.C.D|X:X::X:X)",
2323 MATCH_STR
2324 "Match peer address\n"
2325 "IPv6 address of peer\n"
2326 "IP address of peer\n")
2327{
2328 return bgp_route_match_add (vty, vty->index, "peer", argv[0]);
2329}
2330
2331DEFUN (match_peer_local,
2332 match_peer_local_cmd,
2333 "match peer local",
2334 MATCH_STR
2335 "Match peer address\n"
2336 "Static or Redistributed routes\n")
2337{
2338 return bgp_route_match_add (vty, vty->index, "peer", NULL);
2339}
2340
2341DEFUN (no_match_peer,
2342 no_match_peer_cmd,
2343 "no match peer",
2344 NO_STR
2345 MATCH_STR
2346 "Match peer address\n")
2347{
2348 if (argc == 0)
2349 return bgp_route_match_delete (vty, vty->index, "peer", NULL);
2350
2351 return bgp_route_match_delete (vty, vty->index, "peer", argv[0]);
2352}
2353
2354ALIAS (no_match_peer,
2355 no_match_peer_val_cmd,
2356 "no match peer (A.B.C.D|X:X::X:X)",
2357 NO_STR
2358 MATCH_STR
2359 "Match peer address\n"
2360 "IPv6 address of peer\n"
2361 "IP address of peer\n")
2362
2363ALIAS (no_match_peer,
2364 no_match_peer_local_cmd,
2365 "no match peer local",
2366 NO_STR
2367 MATCH_STR
2368 "Match peer address\n"
2369 "Static or Redistributed routes\n")
2370
paul718e3742002-12-13 20:15:29 +00002371DEFUN (match_ip_address,
2372 match_ip_address_cmd,
2373 "match ip address (<1-199>|<1300-2699>|WORD)",
2374 MATCH_STR
2375 IP_STR
2376 "Match address of route\n"
2377 "IP access-list number\n"
2378 "IP access-list number (expanded range)\n"
2379 "IP Access-list name\n")
2380{
2381 return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);
2382}
2383
2384DEFUN (no_match_ip_address,
2385 no_match_ip_address_cmd,
2386 "no match ip address",
2387 NO_STR
2388 MATCH_STR
2389 IP_STR
2390 "Match address of route\n")
2391{
2392 if (argc == 0)
2393 return bgp_route_match_delete (vty, vty->index, "ip address", NULL);
2394
2395 return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);
2396}
2397
2398ALIAS (no_match_ip_address,
2399 no_match_ip_address_val_cmd,
2400 "no match ip address (<1-199>|<1300-2699>|WORD)",
2401 NO_STR
2402 MATCH_STR
2403 IP_STR
2404 "Match address of route\n"
2405 "IP access-list number\n"
2406 "IP access-list number (expanded range)\n"
2407 "IP Access-list name\n")
2408
2409DEFUN (match_ip_next_hop,
2410 match_ip_next_hop_cmd,
2411 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
2412 MATCH_STR
2413 IP_STR
2414 "Match next-hop address of route\n"
2415 "IP access-list number\n"
2416 "IP access-list number (expanded range)\n"
2417 "IP Access-list name\n")
2418{
2419 return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
2420}
2421
2422DEFUN (no_match_ip_next_hop,
2423 no_match_ip_next_hop_cmd,
2424 "no match ip next-hop",
2425 NO_STR
2426 MATCH_STR
2427 IP_STR
2428 "Match next-hop address of route\n")
2429{
2430 if (argc == 0)
2431 return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
2432
2433 return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
2434}
2435
2436ALIAS (no_match_ip_next_hop,
2437 no_match_ip_next_hop_val_cmd,
2438 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2439 NO_STR
2440 MATCH_STR
2441 IP_STR
2442 "Match next-hop address of route\n"
2443 "IP access-list number\n"
2444 "IP access-list number (expanded range)\n"
2445 "IP Access-list name\n")
2446
hassoc1643bb2005-02-02 16:43:17 +00002447DEFUN (match_ip_route_source,
2448 match_ip_route_source_cmd,
2449 "match ip route-source (<1-199>|<1300-2699>|WORD)",
2450 MATCH_STR
2451 IP_STR
2452 "Match advertising source address of route\n"
2453 "IP access-list number\n"
2454 "IP access-list number (expanded range)\n"
2455 "IP standard access-list name\n")
2456{
2457 return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]);
2458}
2459
2460DEFUN (no_match_ip_route_source,
2461 no_match_ip_route_source_cmd,
2462 "no match ip route-source",
2463 NO_STR
2464 MATCH_STR
2465 IP_STR
2466 "Match advertising source address of route\n")
2467{
2468 if (argc == 0)
2469 return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL);
2470
2471 return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]);
2472}
2473
2474ALIAS (no_match_ip_route_source,
2475 no_match_ip_route_source_val_cmd,
2476 "no match ip route-source (<1-199>|<1300-2699>|WORD)",
2477 NO_STR
2478 MATCH_STR
2479 IP_STR
2480 "Match advertising source address of route\n"
2481 "IP access-list number\n"
2482 "IP access-list number (expanded range)\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002483 "IP standard access-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002484
paul718e3742002-12-13 20:15:29 +00002485DEFUN (match_ip_address_prefix_list,
2486 match_ip_address_prefix_list_cmd,
2487 "match ip address prefix-list WORD",
2488 MATCH_STR
2489 IP_STR
2490 "Match address of route\n"
2491 "Match entries of prefix-lists\n"
2492 "IP prefix-list name\n")
2493{
2494 return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
2495}
2496
2497DEFUN (no_match_ip_address_prefix_list,
2498 no_match_ip_address_prefix_list_cmd,
2499 "no match ip address prefix-list",
2500 NO_STR
2501 MATCH_STR
2502 IP_STR
2503 "Match address of route\n"
2504 "Match entries of prefix-lists\n")
2505{
2506 if (argc == 0)
2507 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
2508
2509 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
2510}
2511
2512ALIAS (no_match_ip_address_prefix_list,
2513 no_match_ip_address_prefix_list_val_cmd,
2514 "no match ip address prefix-list WORD",
2515 NO_STR
2516 MATCH_STR
2517 IP_STR
2518 "Match address of route\n"
2519 "Match entries of prefix-lists\n"
2520 "IP prefix-list name\n")
2521
2522DEFUN (match_ip_next_hop_prefix_list,
2523 match_ip_next_hop_prefix_list_cmd,
2524 "match ip next-hop prefix-list WORD",
2525 MATCH_STR
2526 IP_STR
2527 "Match next-hop address of route\n"
2528 "Match entries of prefix-lists\n"
2529 "IP prefix-list name\n")
2530{
2531 return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2532}
2533
2534DEFUN (no_match_ip_next_hop_prefix_list,
2535 no_match_ip_next_hop_prefix_list_cmd,
2536 "no match ip next-hop prefix-list",
2537 NO_STR
2538 MATCH_STR
2539 IP_STR
2540 "Match next-hop address of route\n"
2541 "Match entries of prefix-lists\n")
2542{
2543 if (argc == 0)
2544 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
2545
2546 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2547}
2548
2549ALIAS (no_match_ip_next_hop_prefix_list,
2550 no_match_ip_next_hop_prefix_list_val_cmd,
2551 "no match ip next-hop prefix-list WORD",
2552 NO_STR
2553 MATCH_STR
2554 IP_STR
2555 "Match next-hop address of route\n"
2556 "Match entries of prefix-lists\n"
2557 "IP prefix-list name\n")
2558
hassoc1643bb2005-02-02 16:43:17 +00002559DEFUN (match_ip_route_source_prefix_list,
2560 match_ip_route_source_prefix_list_cmd,
2561 "match ip route-source prefix-list WORD",
2562 MATCH_STR
2563 IP_STR
2564 "Match advertising source address of route\n"
2565 "Match entries of prefix-lists\n"
2566 "IP prefix-list name\n")
2567{
2568 return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]);
2569}
2570
2571DEFUN (no_match_ip_route_source_prefix_list,
2572 no_match_ip_route_source_prefix_list_cmd,
2573 "no match ip route-source prefix-list",
2574 NO_STR
2575 MATCH_STR
2576 IP_STR
2577 "Match advertising source address of route\n"
2578 "Match entries of prefix-lists\n")
2579{
2580 if (argc == 0)
2581 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL);
2582
2583 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]);
2584}
2585
2586ALIAS (no_match_ip_route_source_prefix_list,
2587 no_match_ip_route_source_prefix_list_val_cmd,
2588 "no match ip route-source prefix-list WORD",
2589 NO_STR
2590 MATCH_STR
2591 IP_STR
2592 "Match advertising source address of route\n"
2593 "Match entries of prefix-lists\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002594 "IP prefix-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002595
paul718e3742002-12-13 20:15:29 +00002596DEFUN (match_metric,
2597 match_metric_cmd,
2598 "match metric <0-4294967295>",
2599 MATCH_STR
2600 "Match metric of route\n"
2601 "Metric value\n")
2602{
2603 return bgp_route_match_add (vty, vty->index, "metric", argv[0]);
2604}
2605
2606DEFUN (no_match_metric,
2607 no_match_metric_cmd,
2608 "no match metric",
2609 NO_STR
2610 MATCH_STR
2611 "Match metric of route\n")
2612{
2613 if (argc == 0)
2614 return bgp_route_match_delete (vty, vty->index, "metric", NULL);
2615
2616 return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);
2617}
2618
2619ALIAS (no_match_metric,
2620 no_match_metric_val_cmd,
2621 "no match metric <0-4294967295>",
2622 NO_STR
2623 MATCH_STR
2624 "Match metric of route\n"
2625 "Metric value\n")
2626
2627DEFUN (match_community,
2628 match_community_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002629 "match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002630 MATCH_STR
2631 "Match BGP community list\n"
2632 "Community-list number (standard)\n"
2633 "Community-list number (expanded)\n"
2634 "Community-list name\n")
2635{
2636 return bgp_route_match_add (vty, vty->index, "community", argv[0]);
2637}
2638
2639DEFUN (match_community_exact,
2640 match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002641 "match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002642 MATCH_STR
2643 "Match BGP community list\n"
2644 "Community-list number (standard)\n"
2645 "Community-list number (expanded)\n"
2646 "Community-list name\n"
2647 "Do exact matching of communities\n")
2648{
2649 int ret;
2650 char *argstr;
2651
2652 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
2653 strlen (argv[0]) + strlen ("exact-match") + 2);
2654
2655 sprintf (argstr, "%s exact-match", argv[0]);
2656
2657 ret = bgp_route_match_add (vty, vty->index, "community", argstr);
2658
2659 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
2660
2661 return ret;
2662}
2663
2664DEFUN (no_match_community,
2665 no_match_community_cmd,
2666 "no match community",
2667 NO_STR
2668 MATCH_STR
2669 "Match BGP community list\n")
2670{
2671 return bgp_route_match_delete (vty, vty->index, "community", NULL);
2672}
2673
2674ALIAS (no_match_community,
2675 no_match_community_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002676 "no match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002677 NO_STR
2678 MATCH_STR
2679 "Match BGP community list\n"
2680 "Community-list number (standard)\n"
2681 "Community-list number (expanded)\n"
2682 "Community-list name\n")
2683
2684ALIAS (no_match_community,
2685 no_match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002686 "no match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002687 NO_STR
2688 MATCH_STR
2689 "Match BGP community list\n"
2690 "Community-list number (standard)\n"
2691 "Community-list number (expanded)\n"
2692 "Community-list name\n"
2693 "Do exact matching of communities\n")
2694
paul73ffb252003-04-19 15:49:49 +00002695DEFUN (match_ecommunity,
2696 match_ecommunity_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002697 "match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002698 MATCH_STR
2699 "Match BGP/VPN extended community list\n"
2700 "Extended community-list number (standard)\n"
2701 "Extended community-list number (expanded)\n"
2702 "Extended community-list name\n")
2703{
2704 return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]);
2705}
2706
2707DEFUN (no_match_ecommunity,
2708 no_match_ecommunity_cmd,
2709 "no match extcommunity",
2710 NO_STR
2711 MATCH_STR
2712 "Match BGP/VPN extended community list\n")
2713{
2714 return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL);
2715}
2716
2717ALIAS (no_match_ecommunity,
2718 no_match_ecommunity_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002719 "no match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002720 NO_STR
2721 MATCH_STR
2722 "Match BGP/VPN extended community list\n"
2723 "Extended community-list number (standard)\n"
2724 "Extended community-list number (expanded)\n"
2725 "Extended community-list name\n")
2726
paul718e3742002-12-13 20:15:29 +00002727DEFUN (match_aspath,
2728 match_aspath_cmd,
2729 "match as-path WORD",
2730 MATCH_STR
2731 "Match BGP AS path list\n"
2732 "AS path access-list name\n")
2733{
2734 return bgp_route_match_add (vty, vty->index, "as-path", argv[0]);
2735}
2736
2737DEFUN (no_match_aspath,
2738 no_match_aspath_cmd,
2739 "no match as-path",
2740 NO_STR
2741 MATCH_STR
2742 "Match BGP AS path list\n")
2743{
2744 return bgp_route_match_delete (vty, vty->index, "as-path", NULL);
2745}
2746
2747ALIAS (no_match_aspath,
2748 no_match_aspath_val_cmd,
2749 "no match as-path WORD",
2750 NO_STR
2751 MATCH_STR
2752 "Match BGP AS path list\n"
2753 "AS path access-list name\n")
2754
2755DEFUN (match_origin,
2756 match_origin_cmd,
2757 "match origin (egp|igp|incomplete)",
2758 MATCH_STR
2759 "BGP origin code\n"
2760 "remote EGP\n"
2761 "local IGP\n"
2762 "unknown heritage\n")
2763{
2764 if (strncmp (argv[0], "igp", 2) == 0)
2765 return bgp_route_match_add (vty, vty->index, "origin", "igp");
2766 if (strncmp (argv[0], "egp", 1) == 0)
2767 return bgp_route_match_add (vty, vty->index, "origin", "egp");
2768 if (strncmp (argv[0], "incomplete", 2) == 0)
2769 return bgp_route_match_add (vty, vty->index, "origin", "incomplete");
2770
2771 return CMD_WARNING;
2772}
2773
2774DEFUN (no_match_origin,
2775 no_match_origin_cmd,
2776 "no match origin",
2777 NO_STR
2778 MATCH_STR
2779 "BGP origin code\n")
2780{
2781 return bgp_route_match_delete (vty, vty->index, "origin", NULL);
2782}
2783
2784ALIAS (no_match_origin,
2785 no_match_origin_val_cmd,
2786 "no match origin (egp|igp|incomplete)",
2787 NO_STR
2788 MATCH_STR
2789 "BGP origin code\n"
2790 "remote EGP\n"
2791 "local IGP\n"
2792 "unknown heritage\n")
2793
2794DEFUN (set_ip_nexthop,
2795 set_ip_nexthop_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002796 "set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002797 SET_STR
2798 IP_STR
2799 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002800 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002801{
2802 union sockunion su;
2803 int ret;
2804
2805 ret = str2sockunion (argv[0], &su);
2806 if (ret < 0)
2807 {
2808 vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
2809 return CMD_WARNING;
2810 }
2811
2812 return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
2813}
2814
paulaf5cd0a2003-11-02 07:24:40 +00002815DEFUN (set_ip_nexthop_peer,
2816 set_ip_nexthop_peer_cmd,
2817 "set ip next-hop peer-address",
2818 SET_STR
2819 IP_STR
2820 "Next hop address\n"
2821 "Use peer address (for BGP only)\n")
2822{
2823 return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address");
2824}
2825
paul94f2b392005-06-28 12:44:16 +00002826DEFUN_DEPRECATED (no_set_ip_nexthop_peer,
paulaf5cd0a2003-11-02 07:24:40 +00002827 no_set_ip_nexthop_peer_cmd,
2828 "no set ip next-hop peer-address",
2829 NO_STR
2830 SET_STR
2831 IP_STR
2832 "Next hop address\n"
2833 "Use peer address (for BGP only)\n")
2834{
2835 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2836}
2837
2838
paul718e3742002-12-13 20:15:29 +00002839DEFUN (no_set_ip_nexthop,
2840 no_set_ip_nexthop_cmd,
2841 "no set ip next-hop",
2842 NO_STR
2843 SET_STR
paul718e3742002-12-13 20:15:29 +00002844 "Next hop address\n")
2845{
paulaf5cd0a2003-11-02 07:24:40 +00002846 if (argc == 0)
paul718e3742002-12-13 20:15:29 +00002847 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2848
2849 return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
2850}
2851
2852ALIAS (no_set_ip_nexthop,
2853 no_set_ip_nexthop_val_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002854 "no set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002855 NO_STR
2856 SET_STR
2857 IP_STR
2858 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002859 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002860
2861DEFUN (set_metric,
2862 set_metric_cmd,
paul73ffb252003-04-19 15:49:49 +00002863 "set metric <0-4294967295>",
paul718e3742002-12-13 20:15:29 +00002864 SET_STR
2865 "Metric value for destination routing protocol\n"
paul73ffb252003-04-19 15:49:49 +00002866 "Metric value\n")
paul718e3742002-12-13 20:15:29 +00002867{
2868 return bgp_route_set_add (vty, vty->index, "metric", argv[0]);
2869}
2870
paul73ffb252003-04-19 15:49:49 +00002871ALIAS (set_metric,
2872 set_metric_addsub_cmd,
2873 "set metric <+/-metric>",
2874 SET_STR
2875 "Metric value for destination routing protocol\n"
hasso033e8612005-05-28 04:50:54 +00002876 "Add or subtract metric\n")
paul73ffb252003-04-19 15:49:49 +00002877
paul718e3742002-12-13 20:15:29 +00002878DEFUN (no_set_metric,
2879 no_set_metric_cmd,
2880 "no set metric",
2881 NO_STR
2882 SET_STR
2883 "Metric value for destination routing protocol\n")
2884{
2885 if (argc == 0)
2886 return bgp_route_set_delete (vty, vty->index, "metric", NULL);
2887
2888 return bgp_route_set_delete (vty, vty->index, "metric", argv[0]);
2889}
2890
2891ALIAS (no_set_metric,
2892 no_set_metric_val_cmd,
2893 "no set metric <0-4294967295>",
2894 NO_STR
2895 SET_STR
2896 "Metric value for destination routing protocol\n"
2897 "Metric value\n")
2898
2899DEFUN (set_local_pref,
2900 set_local_pref_cmd,
2901 "set local-preference <0-4294967295>",
2902 SET_STR
2903 "BGP local preference path attribute\n"
2904 "Preference value\n")
2905{
2906 return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]);
2907}
2908
2909DEFUN (no_set_local_pref,
2910 no_set_local_pref_cmd,
2911 "no set local-preference",
2912 NO_STR
2913 SET_STR
2914 "BGP local preference path attribute\n")
2915{
2916 if (argc == 0)
2917 return bgp_route_set_delete (vty, vty->index, "local-preference", NULL);
2918
2919 return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]);
2920}
2921
2922ALIAS (no_set_local_pref,
2923 no_set_local_pref_val_cmd,
2924 "no set local-preference <0-4294967295>",
2925 NO_STR
2926 SET_STR
2927 "BGP local preference path attribute\n"
2928 "Preference value\n")
2929
2930DEFUN (set_weight,
2931 set_weight_cmd,
2932 "set weight <0-4294967295>",
2933 SET_STR
2934 "BGP weight for routing table\n"
2935 "Weight value\n")
2936{
2937 return bgp_route_set_add (vty, vty->index, "weight", argv[0]);
2938}
2939
2940DEFUN (no_set_weight,
2941 no_set_weight_cmd,
2942 "no set weight",
2943 NO_STR
2944 SET_STR
2945 "BGP weight for routing table\n")
2946{
2947 if (argc == 0)
2948 return bgp_route_set_delete (vty, vty->index, "weight", NULL);
2949
2950 return bgp_route_set_delete (vty, vty->index, "weight", argv[0]);
2951}
2952
2953ALIAS (no_set_weight,
2954 no_set_weight_val_cmd,
2955 "no set weight <0-4294967295>",
2956 NO_STR
2957 SET_STR
2958 "BGP weight for routing table\n"
2959 "Weight value\n")
2960
2961DEFUN (set_aspath_prepend,
2962 set_aspath_prepend_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04002963 "set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00002964 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00002965 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00002966 "Prepend to the as-path\n"
2967 "AS number\n")
2968{
2969 int ret;
2970 char *str;
2971
2972 str = argv_concat (argv, argc, 0);
2973 ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str);
2974 XFREE (MTYPE_TMP, str);
2975
2976 return ret;
2977}
2978
2979DEFUN (no_set_aspath_prepend,
2980 no_set_aspath_prepend_cmd,
2981 "no set as-path prepend",
2982 NO_STR
2983 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00002984 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00002985 "Prepend to the as-path\n")
2986{
Denis Ovsienkoa7f93f32007-12-18 15:13:06 +00002987 int ret;
2988 char *str;
2989
2990 if (argc == 0)
2991 return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL);
2992
2993 str = argv_concat (argv, argc, 0);
2994 ret = bgp_route_set_delete (vty, vty->index, "as-path prepend", str);
2995 XFREE (MTYPE_TMP, str);
2996 return ret;
paul718e3742002-12-13 20:15:29 +00002997}
2998
2999ALIAS (no_set_aspath_prepend,
3000 no_set_aspath_prepend_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003001 "no set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003002 NO_STR
3003 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003004 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003005 "Prepend to the as-path\n"
3006 "AS number\n")
3007
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003008DEFUN (set_aspath_exclude,
3009 set_aspath_exclude_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003010 "set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003011 SET_STR
3012 "Transform BGP AS-path attribute\n"
3013 "Exclude from the as-path\n"
3014 "AS number\n")
3015{
3016 int ret;
3017 char *str;
3018
3019 str = argv_concat (argv, argc, 0);
3020 ret = bgp_route_set_add (vty, vty->index, "as-path exclude", str);
3021 XFREE (MTYPE_TMP, str);
3022 return ret;
3023}
3024
3025DEFUN (no_set_aspath_exclude,
3026 no_set_aspath_exclude_cmd,
3027 "no set as-path exclude",
3028 NO_STR
3029 SET_STR
3030 "Transform BGP AS_PATH attribute\n"
3031 "Exclude from the as-path\n")
3032{
3033 int ret;
3034 char *str;
3035
3036 if (argc == 0)
3037 return bgp_route_set_delete (vty, vty->index, "as-path exclude", NULL);
3038
3039 str = argv_concat (argv, argc, 0);
3040 ret = bgp_route_set_delete (vty, vty->index, "as-path exclude", str);
3041 XFREE (MTYPE_TMP, str);
3042 return ret;
3043}
3044
3045ALIAS (no_set_aspath_exclude,
3046 no_set_aspath_exclude_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003047 "no set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003048 NO_STR
3049 SET_STR
3050 "Transform BGP AS_PATH attribute\n"
3051 "Exclude from the as-path\n"
3052 "AS number\n")
3053
paul718e3742002-12-13 20:15:29 +00003054DEFUN (set_community,
3055 set_community_cmd,
3056 "set community .AA:NN",
3057 SET_STR
3058 "BGP community attribute\n"
3059 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3060{
3061 int i;
3062 int first = 0;
3063 int additive = 0;
3064 struct buffer *b;
3065 struct community *com = NULL;
3066 char *str;
3067 char *argstr;
3068 int ret;
3069
3070 b = buffer_new (1024);
3071
3072 for (i = 0; i < argc; i++)
3073 {
3074 if (strncmp (argv[i], "additive", strlen (argv[i])) == 0)
3075 {
3076 additive = 1;
3077 continue;
3078 }
3079
3080 if (first)
3081 buffer_putc (b, ' ');
3082 else
3083 first = 1;
3084
3085 if (strncmp (argv[i], "internet", strlen (argv[i])) == 0)
3086 {
3087 buffer_putstr (b, "internet");
3088 continue;
3089 }
3090 if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0)
3091 {
3092 buffer_putstr (b, "local-AS");
3093 continue;
3094 }
3095 if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0
3096 && strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0)
3097 {
3098 buffer_putstr (b, "no-advertise");
3099 continue;
3100 }
3101 if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0
3102 && strncmp (argv[i], "no-export", strlen (argv[i])) == 0)
3103 {
3104 buffer_putstr (b, "no-export");
3105 continue;
3106 }
3107 buffer_putstr (b, argv[i]);
3108 }
3109 buffer_putc (b, '\0');
3110
3111 /* Fetch result string then compile it to communities attribute. */
3112 str = buffer_getstr (b);
3113 buffer_free (b);
3114
3115 if (str)
3116 {
3117 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00003118 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00003119 }
3120
3121 /* Can't compile user input into communities attribute. */
3122 if (! com)
3123 {
3124 vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE);
3125 return CMD_WARNING;
3126 }
3127
3128 /* Set communites attribute string. */
3129 str = community_str (com);
3130
3131 if (additive)
3132 {
3133 argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1);
3134 strcpy (argstr, str);
3135 strcpy (argstr + strlen (str), " additive");
3136 ret = bgp_route_set_add (vty, vty->index, "community", argstr);
3137 XFREE (MTYPE_TMP, argstr);
3138 }
3139 else
3140 ret = bgp_route_set_add (vty, vty->index, "community", str);
3141
3142 community_free (com);
3143
3144 return ret;
3145}
3146
3147DEFUN (set_community_none,
3148 set_community_none_cmd,
3149 "set community none",
3150 SET_STR
3151 "BGP community attribute\n"
3152 "No community attribute\n")
3153{
3154 return bgp_route_set_add (vty, vty->index, "community", "none");
3155}
3156
3157DEFUN (no_set_community,
3158 no_set_community_cmd,
3159 "no set community",
3160 NO_STR
3161 SET_STR
3162 "BGP community attribute\n")
3163{
3164 return bgp_route_set_delete (vty, vty->index, "community", NULL);
3165}
3166
3167ALIAS (no_set_community,
3168 no_set_community_val_cmd,
3169 "no set community .AA:NN",
3170 NO_STR
3171 SET_STR
3172 "BGP community attribute\n"
3173 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3174
3175ALIAS (no_set_community,
3176 no_set_community_none_cmd,
3177 "no set community none",
3178 NO_STR
3179 SET_STR
3180 "BGP community attribute\n"
3181 "No community attribute\n")
3182
3183DEFUN (set_community_delete,
3184 set_community_delete_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003185 "set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003186 SET_STR
3187 "set BGP community list (for deletion)\n"
3188 "Community-list number (standard)\n"
3189 "Communitly-list number (expanded)\n"
3190 "Community-list name\n"
3191 "Delete matching communities\n")
3192{
3193 char *str;
3194
3195 str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1);
3196 strcpy (str, argv[0]);
3197 strcpy (str + strlen (argv[0]), " delete");
3198
3199 bgp_route_set_add (vty, vty->index, "comm-list", str);
3200
3201 XFREE (MTYPE_TMP, str);
3202 return CMD_SUCCESS;
3203}
3204
3205DEFUN (no_set_community_delete,
3206 no_set_community_delete_cmd,
3207 "no set comm-list",
3208 NO_STR
3209 SET_STR
3210 "set BGP community list (for deletion)\n")
3211{
3212 return bgp_route_set_delete (vty, vty->index, "comm-list", NULL);
3213}
3214
3215ALIAS (no_set_community_delete,
3216 no_set_community_delete_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003217 "no set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003218 NO_STR
3219 SET_STR
3220 "set BGP community list (for deletion)\n"
3221 "Community-list number (standard)\n"
3222 "Communitly-list number (expanded)\n"
3223 "Community-list name\n"
3224 "Delete matching communities\n")
3225
3226DEFUN (set_ecommunity_rt,
3227 set_ecommunity_rt_cmd,
3228 "set extcommunity rt .ASN:nn_or_IP-address:nn",
3229 SET_STR
3230 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003231 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003232 "VPN extended community\n")
3233{
3234 int ret;
3235 char *str;
3236
3237 str = argv_concat (argv, argc, 0);
3238 ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str);
3239 XFREE (MTYPE_TMP, str);
3240
3241 return ret;
3242}
3243
3244DEFUN (no_set_ecommunity_rt,
3245 no_set_ecommunity_rt_cmd,
3246 "no set extcommunity rt",
3247 NO_STR
3248 SET_STR
3249 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003250 "Route Target extended community\n")
paul718e3742002-12-13 20:15:29 +00003251{
3252 return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL);
3253}
3254
3255ALIAS (no_set_ecommunity_rt,
3256 no_set_ecommunity_rt_val_cmd,
3257 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
3258 NO_STR
3259 SET_STR
3260 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003261 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003262 "VPN extended community\n")
3263
3264DEFUN (set_ecommunity_soo,
3265 set_ecommunity_soo_cmd,
3266 "set extcommunity soo .ASN:nn_or_IP-address:nn",
3267 SET_STR
3268 "BGP extended community attribute\n"
3269 "Site-of-Origin extended community\n"
3270 "VPN extended community\n")
3271{
3272 int ret;
3273 char *str;
3274
3275 str = argv_concat (argv, argc, 0);
3276 ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str);
3277 XFREE (MTYPE_TMP, str);
3278 return ret;
3279}
3280
3281DEFUN (no_set_ecommunity_soo,
3282 no_set_ecommunity_soo_cmd,
3283 "no set extcommunity soo",
3284 NO_STR
3285 SET_STR
3286 "BGP extended community attribute\n"
3287 "Site-of-Origin extended community\n")
3288{
3289 return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL);
3290}
3291
3292ALIAS (no_set_ecommunity_soo,
3293 no_set_ecommunity_soo_val_cmd,
3294 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
3295 NO_STR
3296 SET_STR
3297 "BGP extended community attribute\n"
3298 "Site-of-Origin extended community\n"
3299 "VPN extended community\n")
3300
3301DEFUN (set_origin,
3302 set_origin_cmd,
3303 "set origin (egp|igp|incomplete)",
3304 SET_STR
3305 "BGP origin code\n"
3306 "remote EGP\n"
3307 "local IGP\n"
3308 "unknown heritage\n")
3309{
3310 if (strncmp (argv[0], "igp", 2) == 0)
3311 return bgp_route_set_add (vty, vty->index, "origin", "igp");
3312 if (strncmp (argv[0], "egp", 1) == 0)
3313 return bgp_route_set_add (vty, vty->index, "origin", "egp");
3314 if (strncmp (argv[0], "incomplete", 2) == 0)
3315 return bgp_route_set_add (vty, vty->index, "origin", "incomplete");
3316
3317 return CMD_WARNING;
3318}
3319
3320DEFUN (no_set_origin,
3321 no_set_origin_cmd,
3322 "no set origin",
3323 NO_STR
3324 SET_STR
3325 "BGP origin code\n")
3326{
3327 return bgp_route_set_delete (vty, vty->index, "origin", NULL);
3328}
3329
3330ALIAS (no_set_origin,
3331 no_set_origin_val_cmd,
3332 "no set origin (egp|igp|incomplete)",
3333 NO_STR
3334 SET_STR
3335 "BGP origin code\n"
3336 "remote EGP\n"
3337 "local IGP\n"
3338 "unknown heritage\n")
3339
3340DEFUN (set_atomic_aggregate,
3341 set_atomic_aggregate_cmd,
3342 "set atomic-aggregate",
3343 SET_STR
3344 "BGP atomic aggregate attribute\n" )
3345{
3346 return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL);
3347}
3348
3349DEFUN (no_set_atomic_aggregate,
3350 no_set_atomic_aggregate_cmd,
3351 "no set atomic-aggregate",
3352 NO_STR
3353 SET_STR
3354 "BGP atomic aggregate attribute\n" )
3355{
3356 return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL);
3357}
3358
3359DEFUN (set_aggregator_as,
3360 set_aggregator_as_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003361 "set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003362 SET_STR
3363 "BGP aggregator attribute\n"
3364 "AS number of aggregator\n"
3365 "AS number\n"
3366 "IP address of aggregator\n")
3367{
3368 int ret;
3369 as_t as;
3370 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003371 char *argstr;
3372
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003373 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paulfd79ac92004-10-13 05:06:08 +00003374
paul718e3742002-12-13 20:15:29 +00003375 ret = inet_aton (argv[1], &address);
3376 if (ret == 0)
3377 {
3378 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3379 return CMD_WARNING;
3380 }
3381
3382 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3383 strlen (argv[0]) + strlen (argv[1]) + 2);
3384
3385 sprintf (argstr, "%s %s", argv[0], argv[1]);
3386
3387 ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr);
3388
3389 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3390
3391 return ret;
3392}
3393
3394DEFUN (no_set_aggregator_as,
3395 no_set_aggregator_as_cmd,
3396 "no set aggregator as",
3397 NO_STR
3398 SET_STR
3399 "BGP aggregator attribute\n"
3400 "AS number of aggregator\n")
3401{
3402 int ret;
3403 as_t as;
3404 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003405 char *argstr;
3406
3407 if (argv == 0)
3408 return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL);
3409
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003410 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paul718e3742002-12-13 20:15:29 +00003411
3412 ret = inet_aton (argv[1], &address);
3413 if (ret == 0)
3414 {
3415 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3416 return CMD_WARNING;
3417 }
3418
3419 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3420 strlen (argv[0]) + strlen (argv[1]) + 2);
3421
3422 sprintf (argstr, "%s %s", argv[0], argv[1]);
3423
3424 ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr);
3425
3426 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3427
3428 return ret;
3429}
3430
3431ALIAS (no_set_aggregator_as,
3432 no_set_aggregator_as_val_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003433 "no set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003434 NO_STR
3435 SET_STR
3436 "BGP aggregator attribute\n"
3437 "AS number of aggregator\n"
3438 "AS number\n"
3439 "IP address of aggregator\n")
3440
3441
3442#ifdef HAVE_IPV6
3443DEFUN (match_ipv6_address,
3444 match_ipv6_address_cmd,
3445 "match ipv6 address WORD",
3446 MATCH_STR
3447 IPV6_STR
3448 "Match IPv6 address of route\n"
3449 "IPv6 access-list name\n")
3450{
3451 return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]);
3452}
3453
3454DEFUN (no_match_ipv6_address,
3455 no_match_ipv6_address_cmd,
3456 "no match ipv6 address WORD",
3457 NO_STR
3458 MATCH_STR
3459 IPV6_STR
3460 "Match IPv6 address of route\n"
3461 "IPv6 access-list name\n")
3462{
3463 return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]);
3464}
3465
3466DEFUN (match_ipv6_next_hop,
3467 match_ipv6_next_hop_cmd,
3468 "match ipv6 next-hop X:X::X:X",
3469 MATCH_STR
3470 IPV6_STR
3471 "Match IPv6 next-hop address of route\n"
3472 "IPv6 address of next hop\n")
3473{
3474 return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]);
3475}
3476
3477DEFUN (no_match_ipv6_next_hop,
3478 no_match_ipv6_next_hop_cmd,
3479 "no match ipv6 next-hop X:X::X:X",
3480 NO_STR
3481 MATCH_STR
3482 IPV6_STR
3483 "Match IPv6 next-hop address of route\n"
3484 "IPv6 address of next hop\n")
3485{
3486 return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
3487}
3488
3489DEFUN (match_ipv6_address_prefix_list,
3490 match_ipv6_address_prefix_list_cmd,
3491 "match ipv6 address prefix-list WORD",
3492 MATCH_STR
3493 IPV6_STR
3494 "Match address of route\n"
3495 "Match entries of prefix-lists\n"
3496 "IP prefix-list name\n")
3497{
3498 return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3499}
3500
3501DEFUN (no_match_ipv6_address_prefix_list,
3502 no_match_ipv6_address_prefix_list_cmd,
3503 "no match ipv6 address prefix-list WORD",
3504 NO_STR
3505 MATCH_STR
3506 IPV6_STR
3507 "Match address of route\n"
3508 "Match entries of prefix-lists\n"
3509 "IP prefix-list name\n")
3510{
3511 return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3512}
3513
3514DEFUN (set_ipv6_nexthop_global,
3515 set_ipv6_nexthop_global_cmd,
3516 "set ipv6 next-hop global X:X::X:X",
3517 SET_STR
3518 IPV6_STR
3519 "IPv6 next-hop address\n"
3520 "IPv6 global address\n"
3521 "IPv6 address of next hop\n")
3522{
3523 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]);
3524}
3525
3526DEFUN (no_set_ipv6_nexthop_global,
3527 no_set_ipv6_nexthop_global_cmd,
3528 "no set ipv6 next-hop global",
3529 NO_STR
3530 SET_STR
3531 IPV6_STR
3532 "IPv6 next-hop address\n"
3533 "IPv6 global address\n")
3534{
3535 if (argc == 0)
3536 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL);
3537
3538 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]);
3539}
3540
3541ALIAS (no_set_ipv6_nexthop_global,
3542 no_set_ipv6_nexthop_global_val_cmd,
3543 "no set ipv6 next-hop global X:X::X:X",
3544 NO_STR
3545 SET_STR
3546 IPV6_STR
3547 "IPv6 next-hop address\n"
3548 "IPv6 global address\n"
3549 "IPv6 address of next hop\n")
3550
3551DEFUN (set_ipv6_nexthop_local,
3552 set_ipv6_nexthop_local_cmd,
3553 "set ipv6 next-hop local X:X::X:X",
3554 SET_STR
3555 IPV6_STR
3556 "IPv6 next-hop address\n"
3557 "IPv6 local address\n"
3558 "IPv6 address of next hop\n")
3559{
3560 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
3561}
3562
3563DEFUN (no_set_ipv6_nexthop_local,
3564 no_set_ipv6_nexthop_local_cmd,
3565 "no set ipv6 next-hop local",
3566 NO_STR
3567 SET_STR
3568 IPV6_STR
3569 "IPv6 next-hop address\n"
3570 "IPv6 local address\n")
3571{
3572 if (argc == 0)
3573 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
3574
3575 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
3576}
3577
3578ALIAS (no_set_ipv6_nexthop_local,
3579 no_set_ipv6_nexthop_local_val_cmd,
3580 "no set ipv6 next-hop local X:X::X:X",
3581 NO_STR
3582 SET_STR
3583 IPV6_STR
3584 "IPv6 next-hop address\n"
3585 "IPv6 local address\n"
3586 "IPv6 address of next hop\n")
3587#endif /* HAVE_IPV6 */
3588
3589DEFUN (set_vpnv4_nexthop,
3590 set_vpnv4_nexthop_cmd,
3591 "set vpnv4 next-hop A.B.C.D",
3592 SET_STR
3593 "VPNv4 information\n"
3594 "VPNv4 next-hop address\n"
3595 "IP address of next hop\n")
3596{
3597 return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]);
3598}
3599
3600DEFUN (no_set_vpnv4_nexthop,
3601 no_set_vpnv4_nexthop_cmd,
3602 "no set vpnv4 next-hop",
3603 NO_STR
3604 SET_STR
3605 "VPNv4 information\n"
3606 "VPNv4 next-hop address\n")
3607{
3608 if (argc == 0)
3609 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL);
3610
3611 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]);
3612}
3613
3614ALIAS (no_set_vpnv4_nexthop,
3615 no_set_vpnv4_nexthop_val_cmd,
3616 "no set vpnv4 next-hop A.B.C.D",
3617 NO_STR
3618 SET_STR
3619 "VPNv4 information\n"
3620 "VPNv4 next-hop address\n"
3621 "IP address of next hop\n")
3622
3623DEFUN (set_originator_id,
3624 set_originator_id_cmd,
3625 "set originator-id A.B.C.D",
3626 SET_STR
3627 "BGP originator ID attribute\n"
3628 "IP address of originator\n")
3629{
3630 return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]);
3631}
3632
3633DEFUN (no_set_originator_id,
3634 no_set_originator_id_cmd,
3635 "no set originator-id",
3636 NO_STR
3637 SET_STR
3638 "BGP originator ID attribute\n")
3639{
3640 if (argc == 0)
3641 return bgp_route_set_delete (vty, vty->index, "originator-id", NULL);
3642
3643 return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]);
3644}
3645
3646ALIAS (no_set_originator_id,
3647 no_set_originator_id_val_cmd,
3648 "no set originator-id A.B.C.D",
3649 NO_STR
3650 SET_STR
3651 "BGP originator ID attribute\n"
3652 "IP address of originator\n")
3653
Paul Jakmae70e5752011-07-05 00:41:59 +04003654DEFUN_DEPRECATED (set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003655 set_pathlimit_ttl_cmd,
3656 "set pathlimit ttl <1-255>",
3657 SET_STR
3658 "BGP AS-Pathlimit attribute\n"
3659 "Set AS-Path Hop-count TTL\n")
3660{
Paul Jakmae70e5752011-07-05 00:41:59 +04003661 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003662}
3663
Paul Jakmae70e5752011-07-05 00:41:59 +04003664DEFUN_DEPRECATED (no_set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003665 no_set_pathlimit_ttl_cmd,
3666 "no set pathlimit ttl",
3667 NO_STR
3668 SET_STR
3669 "BGP AS-Pathlimit attribute\n"
3670 "Set AS-Path Hop-count TTL\n")
3671{
Paul Jakmae70e5752011-07-05 00:41:59 +04003672 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003673}
3674
3675ALIAS (no_set_pathlimit_ttl,
3676 no_set_pathlimit_ttl_val_cmd,
3677 "no set pathlimit ttl <1-255>",
3678 NO_STR
3679 MATCH_STR
3680 "BGP AS-Pathlimit attribute\n"
3681 "Set AS-Path Hop-count TTL\n")
3682
Paul Jakmae70e5752011-07-05 00:41:59 +04003683DEFUN_DEPRECATED (match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003684 match_pathlimit_as_cmd,
3685 "match pathlimit as <1-65535>",
3686 MATCH_STR
3687 "BGP AS-Pathlimit attribute\n"
3688 "Match Pathlimit AS number\n")
3689{
Paul Jakmae70e5752011-07-05 00:41:59 +04003690 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003691}
3692
Paul Jakmae70e5752011-07-05 00:41:59 +04003693DEFUN_DEPRECATED (no_match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003694 no_match_pathlimit_as_cmd,
3695 "no match pathlimit as",
3696 NO_STR
3697 MATCH_STR
3698 "BGP AS-Pathlimit attribute\n"
3699 "Match Pathlimit AS number\n")
3700{
Paul Jakmae70e5752011-07-05 00:41:59 +04003701 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003702}
3703
3704ALIAS (no_match_pathlimit_as,
3705 no_match_pathlimit_as_val_cmd,
3706 "no match pathlimit as <1-65535>",
3707 NO_STR
3708 MATCH_STR
3709 "BGP AS-Pathlimit attribute\n"
3710 "Match Pathlimit ASN\n")
3711
paul718e3742002-12-13 20:15:29 +00003712
3713/* Initialization of route map. */
3714void
paul94f2b392005-06-28 12:44:16 +00003715bgp_route_map_init (void)
paul718e3742002-12-13 20:15:29 +00003716{
3717 route_map_init ();
3718 route_map_init_vty ();
3719 route_map_add_hook (bgp_route_map_update);
3720 route_map_delete_hook (bgp_route_map_update);
3721
paulfee0f4c2004-09-13 05:12:46 +00003722 route_map_install_match (&route_match_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003723 route_map_install_match (&route_match_ip_address_cmd);
3724 route_map_install_match (&route_match_ip_next_hop_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003725 route_map_install_match (&route_match_ip_route_source_cmd);
paul718e3742002-12-13 20:15:29 +00003726 route_map_install_match (&route_match_ip_address_prefix_list_cmd);
3727 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003728 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +00003729 route_map_install_match (&route_match_aspath_cmd);
3730 route_map_install_match (&route_match_community_cmd);
paul73ffb252003-04-19 15:49:49 +00003731 route_map_install_match (&route_match_ecommunity_cmd);
paul718e3742002-12-13 20:15:29 +00003732 route_map_install_match (&route_match_metric_cmd);
3733 route_map_install_match (&route_match_origin_cmd);
3734
3735 route_map_install_set (&route_set_ip_nexthop_cmd);
3736 route_map_install_set (&route_set_local_pref_cmd);
3737 route_map_install_set (&route_set_weight_cmd);
3738 route_map_install_set (&route_set_metric_cmd);
3739 route_map_install_set (&route_set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003740 route_map_install_set (&route_set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003741 route_map_install_set (&route_set_origin_cmd);
3742 route_map_install_set (&route_set_atomic_aggregate_cmd);
3743 route_map_install_set (&route_set_aggregator_as_cmd);
3744 route_map_install_set (&route_set_community_cmd);
3745 route_map_install_set (&route_set_community_delete_cmd);
3746 route_map_install_set (&route_set_vpnv4_nexthop_cmd);
3747 route_map_install_set (&route_set_originator_id_cmd);
3748 route_map_install_set (&route_set_ecommunity_rt_cmd);
3749 route_map_install_set (&route_set_ecommunity_soo_cmd);
3750
paulfee0f4c2004-09-13 05:12:46 +00003751 install_element (RMAP_NODE, &match_peer_cmd);
3752 install_element (RMAP_NODE, &match_peer_local_cmd);
3753 install_element (RMAP_NODE, &no_match_peer_cmd);
3754 install_element (RMAP_NODE, &no_match_peer_val_cmd);
3755 install_element (RMAP_NODE, &no_match_peer_local_cmd);
paul718e3742002-12-13 20:15:29 +00003756 install_element (RMAP_NODE, &match_ip_address_cmd);
3757 install_element (RMAP_NODE, &no_match_ip_address_cmd);
3758 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
3759 install_element (RMAP_NODE, &match_ip_next_hop_cmd);
3760 install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
3761 install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003762 install_element (RMAP_NODE, &match_ip_route_source_cmd);
3763 install_element (RMAP_NODE, &no_match_ip_route_source_cmd);
3764 install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd);
paul718e3742002-12-13 20:15:29 +00003765
3766 install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
3767 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
3768 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
3769 install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
3770 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
3771 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003772 install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
3773 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
3774 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd);
paul718e3742002-12-13 20:15:29 +00003775
3776 install_element (RMAP_NODE, &match_aspath_cmd);
3777 install_element (RMAP_NODE, &no_match_aspath_cmd);
3778 install_element (RMAP_NODE, &no_match_aspath_val_cmd);
3779 install_element (RMAP_NODE, &match_metric_cmd);
3780 install_element (RMAP_NODE, &no_match_metric_cmd);
3781 install_element (RMAP_NODE, &no_match_metric_val_cmd);
3782 install_element (RMAP_NODE, &match_community_cmd);
3783 install_element (RMAP_NODE, &match_community_exact_cmd);
3784 install_element (RMAP_NODE, &no_match_community_cmd);
3785 install_element (RMAP_NODE, &no_match_community_val_cmd);
3786 install_element (RMAP_NODE, &no_match_community_exact_cmd);
paul73ffb252003-04-19 15:49:49 +00003787 install_element (RMAP_NODE, &match_ecommunity_cmd);
3788 install_element (RMAP_NODE, &no_match_ecommunity_cmd);
3789 install_element (RMAP_NODE, &no_match_ecommunity_val_cmd);
paul718e3742002-12-13 20:15:29 +00003790 install_element (RMAP_NODE, &match_origin_cmd);
3791 install_element (RMAP_NODE, &no_match_origin_cmd);
3792 install_element (RMAP_NODE, &no_match_origin_val_cmd);
3793
3794 install_element (RMAP_NODE, &set_ip_nexthop_cmd);
paulaf5cd0a2003-11-02 07:24:40 +00003795 install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003796 install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
3797 install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
3798 install_element (RMAP_NODE, &set_local_pref_cmd);
3799 install_element (RMAP_NODE, &no_set_local_pref_cmd);
3800 install_element (RMAP_NODE, &no_set_local_pref_val_cmd);
3801 install_element (RMAP_NODE, &set_weight_cmd);
3802 install_element (RMAP_NODE, &no_set_weight_cmd);
3803 install_element (RMAP_NODE, &no_set_weight_val_cmd);
3804 install_element (RMAP_NODE, &set_metric_cmd);
paul73ffb252003-04-19 15:49:49 +00003805 install_element (RMAP_NODE, &set_metric_addsub_cmd);
paul718e3742002-12-13 20:15:29 +00003806 install_element (RMAP_NODE, &no_set_metric_cmd);
3807 install_element (RMAP_NODE, &no_set_metric_val_cmd);
3808 install_element (RMAP_NODE, &set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003809 install_element (RMAP_NODE, &set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003810 install_element (RMAP_NODE, &no_set_aspath_prepend_cmd);
3811 install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003812 install_element (RMAP_NODE, &no_set_aspath_exclude_cmd);
3813 install_element (RMAP_NODE, &no_set_aspath_exclude_val_cmd);
paul718e3742002-12-13 20:15:29 +00003814 install_element (RMAP_NODE, &set_origin_cmd);
3815 install_element (RMAP_NODE, &no_set_origin_cmd);
3816 install_element (RMAP_NODE, &no_set_origin_val_cmd);
3817 install_element (RMAP_NODE, &set_atomic_aggregate_cmd);
3818 install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd);
3819 install_element (RMAP_NODE, &set_aggregator_as_cmd);
3820 install_element (RMAP_NODE, &no_set_aggregator_as_cmd);
3821 install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd);
3822 install_element (RMAP_NODE, &set_community_cmd);
3823 install_element (RMAP_NODE, &set_community_none_cmd);
3824 install_element (RMAP_NODE, &no_set_community_cmd);
3825 install_element (RMAP_NODE, &no_set_community_val_cmd);
3826 install_element (RMAP_NODE, &no_set_community_none_cmd);
3827 install_element (RMAP_NODE, &set_community_delete_cmd);
3828 install_element (RMAP_NODE, &no_set_community_delete_cmd);
3829 install_element (RMAP_NODE, &no_set_community_delete_val_cmd);
3830 install_element (RMAP_NODE, &set_ecommunity_rt_cmd);
3831 install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd);
3832 install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd);
3833 install_element (RMAP_NODE, &set_ecommunity_soo_cmd);
3834 install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd);
3835 install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd);
3836 install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd);
3837 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd);
3838 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd);
3839 install_element (RMAP_NODE, &set_originator_id_cmd);
3840 install_element (RMAP_NODE, &no_set_originator_id_cmd);
3841 install_element (RMAP_NODE, &no_set_originator_id_val_cmd);
3842
3843#ifdef HAVE_IPV6
3844 route_map_install_match (&route_match_ipv6_address_cmd);
3845 route_map_install_match (&route_match_ipv6_next_hop_cmd);
3846 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd);
3847 route_map_install_set (&route_set_ipv6_nexthop_global_cmd);
3848 route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
Paul Jakma41367172007-08-06 15:24:51 +00003849
paul718e3742002-12-13 20:15:29 +00003850 install_element (RMAP_NODE, &match_ipv6_address_cmd);
3851 install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
3852 install_element (RMAP_NODE, &match_ipv6_next_hop_cmd);
3853 install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd);
3854 install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
3855 install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
3856 install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd);
3857 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
3858 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd);
3859 install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
3860 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
3861 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
3862#endif /* HAVE_IPV6 */
Paul Jakma41367172007-08-06 15:24:51 +00003863
Paul Jakmae70e5752011-07-05 00:41:59 +04003864 /* AS-Pathlimit: functionality removed, commands kept for
3865 * compatibility.
3866 */
Paul Jakma41367172007-08-06 15:24:51 +00003867 install_element (RMAP_NODE, &set_pathlimit_ttl_cmd);
3868 install_element (RMAP_NODE, &no_set_pathlimit_ttl_cmd);
3869 install_element (RMAP_NODE, &no_set_pathlimit_ttl_val_cmd);
3870 install_element (RMAP_NODE, &match_pathlimit_as_cmd);
3871 install_element (RMAP_NODE, &no_match_pathlimit_as_cmd);
3872 install_element (RMAP_NODE, &no_match_pathlimit_as_val_cmd);
paul718e3742002-12-13 20:15:29 +00003873}