blob: 06b0859246d094fb2203bb48aaa543551ccbb981 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Route map function of bgpd.
2 Copyright (C) 1998, 1999 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "filter.h"
25#include "routemap.h"
26#include "command.h"
27#include "linklist.h"
28#include "plist.h"
29#include "memory.h"
30#include "log.h"
Jeremy Jackson25f45882009-01-12 16:06:12 -050031#ifdef HAVE_LIBPCREPOSIX
32# include <pcreposix.h>
paul718e3742002-12-13 20:15:29 +000033#else
Jeremy Jackson25f45882009-01-12 16:06:12 -050034# ifdef HAVE_GNU_REGEX
35# include <regex.h>
36# else
37# include "regex-gnu.h"
38# endif /* HAVE_GNU_REGEX */
39#endif /* HAVE_LIBPCREPOSIX */
paul718e3742002-12-13 20:15:29 +000040#include "buffer.h"
41#include "sockunion.h"
42
43#include "bgpd/bgpd.h"
44#include "bgpd/bgp_table.h"
45#include "bgpd/bgp_attr.h"
46#include "bgpd/bgp_aspath.h"
47#include "bgpd/bgp_route.h"
48#include "bgpd/bgp_regex.h"
49#include "bgpd/bgp_community.h"
50#include "bgpd/bgp_clist.h"
51#include "bgpd/bgp_filter.h"
52#include "bgpd/bgp_mplsvpn.h"
53#include "bgpd/bgp_ecommunity.h"
Paul Jakma320da872008-07-02 13:40:33 +000054#include "bgpd/bgp_vty.h"
paul718e3742002-12-13 20:15:29 +000055
56/* Memo of route-map commands.
57
58o Cisco route-map
59
60 match as-path : Done
61 community : Done
62 interface : Not yet
63 ip address : Done
64 ip next-hop : Done
hassoc1643bb2005-02-02 16:43:17 +000065 ip route-source : Done
paul718e3742002-12-13 20:15:29 +000066 ip prefix-list : Done
67 ipv6 address : Done
68 ipv6 next-hop : Done
69 ipv6 route-source: (This will not be implemented by bgpd)
70 ipv6 prefix-list : Done
71 length : (This will not be implemented by bgpd)
72 metric : Done
73 route-type : (This will not be implemented by bgpd)
74 tag : (This will not be implemented by bgpd)
75
76 set as-path prepend : Done
77 as-path tag : Not yet
78 automatic-tag : (This will not be implemented by bgpd)
79 community : Done
80 comm-list : Not yet
81 dampning : Not yet
82 default : (This will not be implemented by bgpd)
83 interface : (This will not be implemented by bgpd)
84 ip default : (This will not be implemented by bgpd)
85 ip next-hop : Done
86 ip precedence : (This will not be implemented by bgpd)
87 ip tos : (This will not be implemented by bgpd)
88 level : (This will not be implemented by bgpd)
89 local-preference : Done
90 metric : Done
91 metric-type : Not yet
92 origin : Done
93 tag : (This will not be implemented by bgpd)
94 weight : Done
95
Timo Teräs2aa640b2014-05-20 08:57:26 +030096o Local extensions
paul718e3742002-12-13 20:15:29 +000097
98 set ipv6 next-hop global: Done
99 set ipv6 next-hop local : Done
Denis Ovsienko841f7a52008-04-10 11:47:45 +0000100 set as-path exclude : Done
paul718e3742002-12-13 20:15:29 +0000101
102*/
David Lamparter6b0655a2014-06-04 06:53:35 +0200103
Timo Teräsb304dcb2014-05-20 09:04:49 +0300104 /* generic as path object to be shared in multiple rules */
105
106static void *
107route_aspath_compile (const char *arg)
108{
109 struct aspath *aspath;
110
111 aspath = aspath_str2aspath (arg);
112 if (! aspath)
113 return NULL;
114 return aspath;
115}
116
117static void
118route_aspath_free (void *rule)
119{
120 struct aspath *aspath = rule;
121 aspath_free (aspath);
122}
123
paulfee0f4c2004-09-13 05:12:46 +0000124 /* 'match peer (A.B.C.D|X:X::X:X)' */
125
126/* Compares the peer specified in the 'match peer' clause with the peer
127 received in bgp_info->peer. If it is the same, or if the peer structure
128 received is a peer_group containing it, returns RMAP_MATCH. */
paul94f2b392005-06-28 12:44:16 +0000129static route_map_result_t
paulfee0f4c2004-09-13 05:12:46 +0000130route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type,
131 void *object)
132{
133 union sockunion *su;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200134 union sockunion su_def = { .sa.sa_family = AF_INET,
135 .sin.sin_addr.s_addr = INADDR_ANY };
paulfee0f4c2004-09-13 05:12:46 +0000136 struct peer_group *group;
137 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +0000138 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +0000139
140 if (type == RMAP_BGP)
141 {
142 su = rule;
143 peer = ((struct bgp_info *) object)->peer;
144
145 if ( ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT) &&
146 ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_EXPORT) )
147 return RMAP_NOMATCH;
148
149 /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
150 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200151 if (sockunion_same (su, &su_def))
paulfee0f4c2004-09-13 05:12:46 +0000152 {
paul22db9de2005-05-19 01:50:11 +0000153 int ret;
paulfee0f4c2004-09-13 05:12:46 +0000154 if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) ||
155 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE) ||
156 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_DEFAULT))
paul22db9de2005-05-19 01:50:11 +0000157 ret = RMAP_MATCH;
paulfee0f4c2004-09-13 05:12:46 +0000158 else
paul22db9de2005-05-19 01:50:11 +0000159 ret = RMAP_NOMATCH;
paul22db9de2005-05-19 01:50:11 +0000160 return ret;
paulfee0f4c2004-09-13 05:12:46 +0000161 }
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200162
paulfee0f4c2004-09-13 05:12:46 +0000163 if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
164 {
165 if (sockunion_same (su, &peer->su))
166 return RMAP_MATCH;
167
168 return RMAP_NOMATCH;
169 }
170 else
171 {
172 group = peer->group;
paul1eb8ef22005-04-07 07:30:20 +0000173 for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
paulfee0f4c2004-09-13 05:12:46 +0000174 {
175 if (sockunion_same (su, &peer->su))
176 return RMAP_MATCH;
paulfee0f4c2004-09-13 05:12:46 +0000177 }
Paul Jakma30a22312008-08-15 14:05:22 +0100178 return RMAP_NOMATCH;
paulfee0f4c2004-09-13 05:12:46 +0000179 }
180 }
181 return RMAP_NOMATCH;
182}
183
paul94f2b392005-06-28 12:44:16 +0000184static void *
paulfd79ac92004-10-13 05:06:08 +0000185route_match_peer_compile (const char *arg)
paulfee0f4c2004-09-13 05:12:46 +0000186{
187 union sockunion *su;
188 int ret;
189
190 su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion));
191
Jorge Boncompte [DTI2]4fe080d2012-04-13 13:46:08 +0200192 ret = str2sockunion (strcmp(arg, "local") ? arg : "0.0.0.0", su);
paulfee0f4c2004-09-13 05:12:46 +0000193 if (ret < 0) {
194 XFREE (MTYPE_ROUTE_MAP_COMPILED, su);
195 return NULL;
196 }
197
198 return su;
199}
200
201/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000202static void
paulfee0f4c2004-09-13 05:12:46 +0000203route_match_peer_free (void *rule)
204{
205 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
206}
207
208/* Route map commands for ip address matching. */
209struct route_map_rule_cmd route_match_peer_cmd =
210{
211 "peer",
212 route_match_peer,
213 route_match_peer_compile,
214 route_match_peer_free
215};
216
paul718e3742002-12-13 20:15:29 +0000217/* `match ip address IP_ACCESS_LIST' */
218
219/* Match function should return 1 if match is success else return
220 zero. */
paul94f2b392005-06-28 12:44:16 +0000221static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000222route_match_ip_address (void *rule, struct prefix *prefix,
223 route_map_object_t type, void *object)
224{
225 struct access_list *alist;
226 /* struct prefix_ipv4 match; */
227
228 if (type == RMAP_BGP)
229 {
230 alist = access_list_lookup (AFI_IP, (char *) rule);
231 if (alist == NULL)
232 return RMAP_NOMATCH;
233
234 return (access_list_apply (alist, prefix) == FILTER_DENY ?
235 RMAP_NOMATCH : RMAP_MATCH);
236 }
237 return RMAP_NOMATCH;
238}
239
240/* Route map `ip address' match statement. `arg' should be
241 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000242static void *
paulfd79ac92004-10-13 05:06:08 +0000243route_match_ip_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000244{
245 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
246}
247
248/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000249static void
paul718e3742002-12-13 20:15:29 +0000250route_match_ip_address_free (void *rule)
251{
252 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
253}
254
255/* Route map commands for ip address matching. */
256struct route_map_rule_cmd route_match_ip_address_cmd =
257{
258 "ip address",
259 route_match_ip_address,
260 route_match_ip_address_compile,
261 route_match_ip_address_free
262};
David Lamparter6b0655a2014-06-04 06:53:35 +0200263
paul718e3742002-12-13 20:15:29 +0000264/* `match ip next-hop IP_ADDRESS' */
265
266/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000267static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000268route_match_ip_next_hop (void *rule, struct prefix *prefix,
269 route_map_object_t type, void *object)
270{
271 struct access_list *alist;
272 struct bgp_info *bgp_info;
273 struct prefix_ipv4 p;
274
275 if (type == RMAP_BGP)
276 {
277 bgp_info = object;
278 p.family = AF_INET;
279 p.prefix = bgp_info->attr->nexthop;
280 p.prefixlen = IPV4_MAX_BITLEN;
281
282 alist = access_list_lookup (AFI_IP, (char *) rule);
283 if (alist == NULL)
284 return RMAP_NOMATCH;
285
286 return (access_list_apply (alist, &p) == FILTER_DENY ?
287 RMAP_NOMATCH : RMAP_MATCH);
288 }
289 return RMAP_NOMATCH;
290}
291
292/* Route map `ip next-hop' match statement. `arg' is
293 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000294static void *
paulfd79ac92004-10-13 05:06:08 +0000295route_match_ip_next_hop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000296{
297 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
298}
299
300/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000301static void
paul718e3742002-12-13 20:15:29 +0000302route_match_ip_next_hop_free (void *rule)
303{
304 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
305}
306
307/* Route map commands for ip next-hop matching. */
308struct route_map_rule_cmd route_match_ip_next_hop_cmd =
309{
310 "ip next-hop",
311 route_match_ip_next_hop,
312 route_match_ip_next_hop_compile,
313 route_match_ip_next_hop_free
314};
David Lamparter6b0655a2014-06-04 06:53:35 +0200315
hassoc1643bb2005-02-02 16:43:17 +0000316/* `match ip route-source ACCESS-LIST' */
317
318/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000319static route_map_result_t
hassoc1643bb2005-02-02 16:43:17 +0000320route_match_ip_route_source (void *rule, struct prefix *prefix,
321 route_map_object_t type, void *object)
322{
323 struct access_list *alist;
324 struct bgp_info *bgp_info;
325 struct peer *peer;
326 struct prefix_ipv4 p;
327
328 if (type == RMAP_BGP)
329 {
330 bgp_info = object;
331 peer = bgp_info->peer;
332
333 if (! peer || sockunion_family (&peer->su) != AF_INET)
334 return RMAP_NOMATCH;
335
336 p.family = AF_INET;
337 p.prefix = peer->su.sin.sin_addr;
338 p.prefixlen = IPV4_MAX_BITLEN;
339
340 alist = access_list_lookup (AFI_IP, (char *) rule);
341 if (alist == NULL)
342 return RMAP_NOMATCH;
343
344 return (access_list_apply (alist, &p) == FILTER_DENY ?
345 RMAP_NOMATCH : RMAP_MATCH);
346 }
347 return RMAP_NOMATCH;
348}
349
350/* Route map `ip route-source' match statement. `arg' is
351 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000352static void *
hassoc1643bb2005-02-02 16:43:17 +0000353route_match_ip_route_source_compile (const char *arg)
354{
355 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
356}
357
358/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000359static void
hassoc1643bb2005-02-02 16:43:17 +0000360route_match_ip_route_source_free (void *rule)
361{
362 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
363}
364
365/* Route map commands for ip route-source matching. */
366struct route_map_rule_cmd route_match_ip_route_source_cmd =
367{
368 "ip route-source",
369 route_match_ip_route_source,
370 route_match_ip_route_source_compile,
371 route_match_ip_route_source_free
372};
David Lamparter6b0655a2014-06-04 06:53:35 +0200373
paul718e3742002-12-13 20:15:29 +0000374/* `match ip address prefix-list PREFIX_LIST' */
375
paul94f2b392005-06-28 12:44:16 +0000376static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000377route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
378 route_map_object_t type, void *object)
379{
380 struct prefix_list *plist;
381
382 if (type == RMAP_BGP)
383 {
384 plist = prefix_list_lookup (AFI_IP, (char *) rule);
385 if (plist == NULL)
386 return RMAP_NOMATCH;
387
388 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
389 RMAP_NOMATCH : RMAP_MATCH);
390 }
391 return RMAP_NOMATCH;
392}
393
paul94f2b392005-06-28 12:44:16 +0000394static void *
paulfd79ac92004-10-13 05:06:08 +0000395route_match_ip_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000396{
397 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
398}
399
paul94f2b392005-06-28 12:44:16 +0000400static void
paul718e3742002-12-13 20:15:29 +0000401route_match_ip_address_prefix_list_free (void *rule)
402{
403 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
404}
405
406struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
407{
408 "ip address prefix-list",
409 route_match_ip_address_prefix_list,
410 route_match_ip_address_prefix_list_compile,
411 route_match_ip_address_prefix_list_free
412};
David Lamparter6b0655a2014-06-04 06:53:35 +0200413
paul718e3742002-12-13 20:15:29 +0000414/* `match ip next-hop prefix-list PREFIX_LIST' */
415
paul94f2b392005-06-28 12:44:16 +0000416static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000417route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
418 route_map_object_t type, void *object)
419{
420 struct prefix_list *plist;
421 struct bgp_info *bgp_info;
422 struct prefix_ipv4 p;
423
424 if (type == RMAP_BGP)
425 {
426 bgp_info = object;
427 p.family = AF_INET;
428 p.prefix = bgp_info->attr->nexthop;
429 p.prefixlen = IPV4_MAX_BITLEN;
430
431 plist = prefix_list_lookup (AFI_IP, (char *) rule);
432 if (plist == NULL)
433 return RMAP_NOMATCH;
434
435 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
436 RMAP_NOMATCH : RMAP_MATCH);
437 }
438 return RMAP_NOMATCH;
439}
440
paul94f2b392005-06-28 12:44:16 +0000441static void *
paulfd79ac92004-10-13 05:06:08 +0000442route_match_ip_next_hop_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000443{
444 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
445}
446
paul94f2b392005-06-28 12:44:16 +0000447static void
paul718e3742002-12-13 20:15:29 +0000448route_match_ip_next_hop_prefix_list_free (void *rule)
449{
450 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
451}
452
453struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
454{
455 "ip next-hop prefix-list",
456 route_match_ip_next_hop_prefix_list,
457 route_match_ip_next_hop_prefix_list_compile,
458 route_match_ip_next_hop_prefix_list_free
459};
David Lamparter6b0655a2014-06-04 06:53:35 +0200460
hassoc1643bb2005-02-02 16:43:17 +0000461/* `match ip route-source prefix-list PREFIX_LIST' */
462
paul94f2b392005-06-28 12:44:16 +0000463static route_map_result_t
hassoc1643bb2005-02-02 16:43:17 +0000464route_match_ip_route_source_prefix_list (void *rule, struct prefix *prefix,
465 route_map_object_t type, void *object)
466{
467 struct prefix_list *plist;
468 struct bgp_info *bgp_info;
469 struct peer *peer;
470 struct prefix_ipv4 p;
471
472 if (type == RMAP_BGP)
473 {
474 bgp_info = object;
475 peer = bgp_info->peer;
476
477 if (! peer || sockunion_family (&peer->su) != AF_INET)
478 return RMAP_NOMATCH;
479
480 p.family = AF_INET;
481 p.prefix = peer->su.sin.sin_addr;
482 p.prefixlen = IPV4_MAX_BITLEN;
483
484 plist = prefix_list_lookup (AFI_IP, (char *) rule);
485 if (plist == NULL)
486 return RMAP_NOMATCH;
487
488 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
489 RMAP_NOMATCH : RMAP_MATCH);
490 }
491 return RMAP_NOMATCH;
492}
493
paul94f2b392005-06-28 12:44:16 +0000494static void *
hassoc1643bb2005-02-02 16:43:17 +0000495route_match_ip_route_source_prefix_list_compile (const char *arg)
496{
497 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
498}
499
paul94f2b392005-06-28 12:44:16 +0000500static void
hassoc1643bb2005-02-02 16:43:17 +0000501route_match_ip_route_source_prefix_list_free (void *rule)
502{
503 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
504}
505
506struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd =
507{
508 "ip route-source prefix-list",
509 route_match_ip_route_source_prefix_list,
510 route_match_ip_route_source_prefix_list_compile,
511 route_match_ip_route_source_prefix_list_free
512};
David Lamparter6b0655a2014-06-04 06:53:35 +0200513
paul718e3742002-12-13 20:15:29 +0000514/* `match metric METRIC' */
515
516/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000517static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000518route_match_metric (void *rule, struct prefix *prefix,
519 route_map_object_t type, void *object)
520{
521 u_int32_t *med;
522 struct bgp_info *bgp_info;
523
524 if (type == RMAP_BGP)
525 {
526 med = rule;
527 bgp_info = object;
528
529 if (bgp_info->attr->med == *med)
530 return RMAP_MATCH;
531 else
532 return RMAP_NOMATCH;
533 }
534 return RMAP_NOMATCH;
535}
536
537/* Route map `match metric' match statement. `arg' is MED value */
paul94f2b392005-06-28 12:44:16 +0000538static void *
paulfd79ac92004-10-13 05:06:08 +0000539route_match_metric_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000540{
541 u_int32_t *med;
542 char *endptr = NULL;
paul3b424972003-10-13 09:47:32 +0000543 unsigned long tmpval;
paul718e3742002-12-13 20:15:29 +0000544
Ulrich Weber664711c2011-12-21 02:24:11 +0400545 /* Metric value shoud be integer. */
546 if (! all_digit (arg))
547 return NULL;
548
549 errno = 0;
paul3b424972003-10-13 09:47:32 +0000550 tmpval = strtoul (arg, &endptr, 10);
Ulrich Weber664711c2011-12-21 02:24:11 +0400551 if (*endptr != '\0' || errno || tmpval > UINT32_MAX)
paul3b424972003-10-13 09:47:32 +0000552 return NULL;
paulfd79ac92004-10-13 05:06:08 +0000553
paul718e3742002-12-13 20:15:29 +0000554 med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
paulfd79ac92004-10-13 05:06:08 +0000555
556 if (!med)
557 return med;
558
paul3b424972003-10-13 09:47:32 +0000559 *med = tmpval;
paul718e3742002-12-13 20:15:29 +0000560 return med;
561}
562
563/* Free route map's compiled `match metric' value. */
paul94f2b392005-06-28 12:44:16 +0000564static void
paul718e3742002-12-13 20:15:29 +0000565route_match_metric_free (void *rule)
566{
567 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
568}
569
570/* Route map commands for metric matching. */
571struct route_map_rule_cmd route_match_metric_cmd =
572{
573 "metric",
574 route_match_metric,
575 route_match_metric_compile,
576 route_match_metric_free
577};
David Lamparter6b0655a2014-06-04 06:53:35 +0200578
paul718e3742002-12-13 20:15:29 +0000579/* `match as-path ASPATH' */
580
581/* Match function for as-path match. I assume given object is */
paul94f2b392005-06-28 12:44:16 +0000582static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000583route_match_aspath (void *rule, struct prefix *prefix,
584 route_map_object_t type, void *object)
585{
586
587 struct as_list *as_list;
588 struct bgp_info *bgp_info;
589
590 if (type == RMAP_BGP)
591 {
592 as_list = as_list_lookup ((char *) rule);
593 if (as_list == NULL)
594 return RMAP_NOMATCH;
595
596 bgp_info = object;
597
598 /* Perform match. */
599 return ((as_list_apply (as_list, bgp_info->attr->aspath) == AS_FILTER_DENY) ? RMAP_NOMATCH : RMAP_MATCH);
600 }
601 return RMAP_NOMATCH;
602}
603
604/* Compile function for as-path match. */
paul94f2b392005-06-28 12:44:16 +0000605static void *
paulfd79ac92004-10-13 05:06:08 +0000606route_match_aspath_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000607{
608 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
609}
610
611/* Compile function for as-path match. */
paul94f2b392005-06-28 12:44:16 +0000612static void
paul718e3742002-12-13 20:15:29 +0000613route_match_aspath_free (void *rule)
614{
615 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
616}
617
618/* Route map commands for aspath matching. */
619struct route_map_rule_cmd route_match_aspath_cmd =
620{
621 "as-path",
622 route_match_aspath,
623 route_match_aspath_compile,
624 route_match_aspath_free
625};
David Lamparter6b0655a2014-06-04 06:53:35 +0200626
paul718e3742002-12-13 20:15:29 +0000627/* `match community COMMUNIY' */
628struct rmap_community
629{
630 char *name;
631 int exact;
632};
633
634/* Match function for community match. */
paul94f2b392005-06-28 12:44:16 +0000635static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000636route_match_community (void *rule, struct prefix *prefix,
637 route_map_object_t type, void *object)
638{
639 struct community_list *list;
640 struct bgp_info *bgp_info;
641 struct rmap_community *rcom;
642
643 if (type == RMAP_BGP)
644 {
645 bgp_info = object;
646 rcom = rule;
647
hassofee6e4e2005-02-02 16:29:31 +0000648 list = community_list_lookup (bgp_clist, rcom->name, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +0000649 if (! list)
650 return RMAP_NOMATCH;
651
652 if (rcom->exact)
653 {
654 if (community_list_exact_match (bgp_info->attr->community, list))
655 return RMAP_MATCH;
656 }
657 else
658 {
659 if (community_list_match (bgp_info->attr->community, list))
660 return RMAP_MATCH;
661 }
662 }
663 return RMAP_NOMATCH;
664}
665
666/* Compile function for community match. */
paul94f2b392005-06-28 12:44:16 +0000667static void *
paulfd79ac92004-10-13 05:06:08 +0000668route_match_community_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000669{
670 struct rmap_community *rcom;
671 int len;
672 char *p;
673
674 rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community));
675
676 p = strchr (arg, ' ');
677 if (p)
678 {
679 len = p - arg;
680 rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
681 memcpy (rcom->name, arg, len);
682 rcom->exact = 1;
683 }
684 else
685 {
686 rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
687 rcom->exact = 0;
688 }
689 return rcom;
690}
691
692/* Compile function for community match. */
paul94f2b392005-06-28 12:44:16 +0000693static void
paul718e3742002-12-13 20:15:29 +0000694route_match_community_free (void *rule)
695{
696 struct rmap_community *rcom = rule;
697
698 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name);
699 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom);
700}
701
702/* Route map commands for community matching. */
703struct route_map_rule_cmd route_match_community_cmd =
704{
705 "community",
706 route_match_community,
707 route_match_community_compile,
708 route_match_community_free
709};
David Lamparter6b0655a2014-06-04 06:53:35 +0200710
paul73ffb252003-04-19 15:49:49 +0000711/* Match function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000712static route_map_result_t
paul73ffb252003-04-19 15:49:49 +0000713route_match_ecommunity (void *rule, struct prefix *prefix,
714 route_map_object_t type, void *object)
715{
716 struct community_list *list;
717 struct bgp_info *bgp_info;
718
719 if (type == RMAP_BGP)
720 {
721 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +0000722
723 if (!bgp_info->attr->extra)
724 return RMAP_NOMATCH;
725
paul73ffb252003-04-19 15:49:49 +0000726 list = community_list_lookup (bgp_clist, (char *) rule,
hassofee6e4e2005-02-02 16:29:31 +0000727 EXTCOMMUNITY_LIST_MASTER);
paul73ffb252003-04-19 15:49:49 +0000728 if (! list)
729 return RMAP_NOMATCH;
730
Paul Jakmafb982c22007-05-04 20:15:47 +0000731 if (ecommunity_list_match (bgp_info->attr->extra->ecommunity, list))
paul73ffb252003-04-19 15:49:49 +0000732 return RMAP_MATCH;
733 }
734 return RMAP_NOMATCH;
735}
736
737/* Compile function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000738static void *
paulfd79ac92004-10-13 05:06:08 +0000739route_match_ecommunity_compile (const char *arg)
paul73ffb252003-04-19 15:49:49 +0000740{
741 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
742}
743
744/* Compile function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000745static void
paul73ffb252003-04-19 15:49:49 +0000746route_match_ecommunity_free (void *rule)
747{
748 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
749}
750
751/* Route map commands for community matching. */
752struct route_map_rule_cmd route_match_ecommunity_cmd =
753{
754 "extcommunity",
755 route_match_ecommunity,
756 route_match_ecommunity_compile,
757 route_match_ecommunity_free
758};
David Lamparter6b0655a2014-06-04 06:53:35 +0200759
paul718e3742002-12-13 20:15:29 +0000760/* `match nlri` and `set nlri` are replaced by `address-family ipv4`
761 and `address-family vpnv4'. */
David Lamparter6b0655a2014-06-04 06:53:35 +0200762
paul718e3742002-12-13 20:15:29 +0000763/* `match origin' */
paul94f2b392005-06-28 12:44:16 +0000764static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000765route_match_origin (void *rule, struct prefix *prefix,
766 route_map_object_t type, void *object)
767{
768 u_char *origin;
769 struct bgp_info *bgp_info;
770
771 if (type == RMAP_BGP)
772 {
773 origin = rule;
774 bgp_info = object;
775
776 if (bgp_info->attr->origin == *origin)
777 return RMAP_MATCH;
778 }
779
780 return RMAP_NOMATCH;
781}
782
paul94f2b392005-06-28 12:44:16 +0000783static void *
paulfd79ac92004-10-13 05:06:08 +0000784route_match_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000785{
786 u_char *origin;
787
788 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
789
790 if (strcmp (arg, "igp") == 0)
791 *origin = 0;
792 else if (strcmp (arg, "egp") == 0)
793 *origin = 1;
794 else
795 *origin = 2;
796
797 return origin;
798}
799
800/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000801static void
paul718e3742002-12-13 20:15:29 +0000802route_match_origin_free (void *rule)
803{
804 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
805}
806
807/* Route map commands for origin matching. */
808struct route_map_rule_cmd route_match_origin_cmd =
809{
810 "origin",
811 route_match_origin,
812 route_match_origin_compile,
813 route_match_origin_free
814};
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +0400815
816/* match probability { */
817
818static route_map_result_t
819route_match_probability (void *rule, struct prefix *prefix,
820 route_map_object_t type, void *object)
821{
822 long r;
823#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
824 r = random();
825#else
826 r = (long) rand();
827#endif
828
829 switch (*(unsigned *) rule)
830 {
831 case 0: break;
832 case RAND_MAX: return RMAP_MATCH;
833 default:
834 if (r < *(unsigned *) rule)
835 {
836 return RMAP_MATCH;
837 }
838 }
839
840 return RMAP_NOMATCH;
841}
842
843static void *
844route_match_probability_compile (const char *arg)
845{
846 unsigned *lobule;
847 unsigned perc;
848
849#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
850 srandom (time (NULL));
851#else
852 srand (time (NULL));
853#endif
854
855 perc = atoi (arg);
856 lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned));
857
858 switch (perc)
859 {
860 case 0: *lobule = 0; break;
861 case 100: *lobule = RAND_MAX; break;
862 default: *lobule = RAND_MAX / 100 * perc;
863 }
864
865 return lobule;
866}
867
868static void
869route_match_probability_free (void *rule)
870{
871 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
872}
873
874struct route_map_rule_cmd route_match_probability_cmd =
875{
876 "probability",
877 route_match_probability,
878 route_match_probability_compile,
879 route_match_probability_free
880};
881
882/* } */
883
paul718e3742002-12-13 20:15:29 +0000884/* `set ip next-hop IP_ADDRESS' */
885
886/* Set nexthop to object. ojbect must be pointer to struct attr. */
paulac41b2a2003-08-12 05:32:27 +0000887struct rmap_ip_nexthop_set
888{
889 struct in_addr *address;
890 int peer_address;
891};
892
paul94f2b392005-06-28 12:44:16 +0000893static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000894route_set_ip_nexthop (void *rule, struct prefix *prefix,
895 route_map_object_t type, void *object)
896{
paulac41b2a2003-08-12 05:32:27 +0000897 struct rmap_ip_nexthop_set *rins = rule;
paul718e3742002-12-13 20:15:29 +0000898 struct bgp_info *bgp_info;
paulac41b2a2003-08-12 05:32:27 +0000899 struct peer *peer;
paul718e3742002-12-13 20:15:29 +0000900
901 if (type == RMAP_BGP)
902 {
paul718e3742002-12-13 20:15:29 +0000903 bgp_info = object;
paulac41b2a2003-08-12 05:32:27 +0000904 peer = bgp_info->peer;
905
906 if (rins->peer_address)
907 {
paulfee0f4c2004-09-13 05:12:46 +0000908 if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) ||
909 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
paulac41b2a2003-08-12 05:32:27 +0000910 && peer->su_remote
911 && sockunion_family (peer->su_remote) == AF_INET)
912 {
Jorge Boncompte [DTI2]0c5ed3e2012-04-10 16:57:22 +0200913 bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_remote);
paulac41b2a2003-08-12 05:32:27 +0000914 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
915 }
916 else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
917 && peer->su_local
918 && sockunion_family (peer->su_local) == AF_INET)
919 {
Jorge Boncompte [DTI2]0c5ed3e2012-04-10 16:57:22 +0200920 bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_local);
paulac41b2a2003-08-12 05:32:27 +0000921 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
922 }
923 }
924 else
925 {
926 /* Set next hop value. */
927 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
928 bgp_info->attr->nexthop = *rins->address;
929 }
paul718e3742002-12-13 20:15:29 +0000930 }
931
932 return RMAP_OKAY;
933}
934
935/* Route map `ip nexthop' compile function. Given string is converted
936 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +0000937static void *
paulfd79ac92004-10-13 05:06:08 +0000938route_set_ip_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000939{
paulac41b2a2003-08-12 05:32:27 +0000940 struct rmap_ip_nexthop_set *rins;
941 struct in_addr *address = NULL;
942 int peer_address = 0;
paul718e3742002-12-13 20:15:29 +0000943 int ret;
paul718e3742002-12-13 20:15:29 +0000944
paulac41b2a2003-08-12 05:32:27 +0000945 if (strcmp (arg, "peer-address") == 0)
946 peer_address = 1;
947 else
paul718e3742002-12-13 20:15:29 +0000948 {
paulac41b2a2003-08-12 05:32:27 +0000949 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
950 ret = inet_aton (arg, address);
951
952 if (ret == 0)
953 {
954 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
955 return NULL;
956 }
paul718e3742002-12-13 20:15:29 +0000957 }
958
Stephen Hemminger393deb92008-08-18 14:13:29 -0700959 rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set));
paulac41b2a2003-08-12 05:32:27 +0000960
961 rins->address = address;
962 rins->peer_address = peer_address;
963
964 return rins;
paul718e3742002-12-13 20:15:29 +0000965}
966
967/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +0000968static void
paul718e3742002-12-13 20:15:29 +0000969route_set_ip_nexthop_free (void *rule)
970{
paulac41b2a2003-08-12 05:32:27 +0000971 struct rmap_ip_nexthop_set *rins = rule;
972
973 if (rins->address)
974 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address);
975
976 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins);
paul718e3742002-12-13 20:15:29 +0000977}
978
979/* Route map commands for ip nexthop set. */
980struct route_map_rule_cmd route_set_ip_nexthop_cmd =
981{
982 "ip next-hop",
983 route_set_ip_nexthop,
984 route_set_ip_nexthop_compile,
985 route_set_ip_nexthop_free
986};
David Lamparter6b0655a2014-06-04 06:53:35 +0200987
paul718e3742002-12-13 20:15:29 +0000988/* `set local-preference LOCAL_PREF' */
989
990/* Set local preference. */
paul94f2b392005-06-28 12:44:16 +0000991static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000992route_set_local_pref (void *rule, struct prefix *prefix,
993 route_map_object_t type, void *object)
994{
995 u_int32_t *local_pref;
996 struct bgp_info *bgp_info;
997
998 if (type == RMAP_BGP)
999 {
1000 /* Fetch routemap's rule information. */
1001 local_pref = rule;
1002 bgp_info = object;
1003
1004 /* Set local preference value. */
1005 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1006 bgp_info->attr->local_pref = *local_pref;
1007 }
1008
1009 return RMAP_OKAY;
1010}
1011
1012/* set local preference compilation. */
paul94f2b392005-06-28 12:44:16 +00001013static void *
paulfd79ac92004-10-13 05:06:08 +00001014route_set_local_pref_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001015{
paulfd79ac92004-10-13 05:06:08 +00001016 unsigned long tmp;
paul718e3742002-12-13 20:15:29 +00001017 u_int32_t *local_pref;
1018 char *endptr = NULL;
1019
1020 /* Local preference value shoud be integer. */
1021 if (! all_digit (arg))
1022 return NULL;
paulfd79ac92004-10-13 05:06:08 +00001023
Ulrich Weber664711c2011-12-21 02:24:11 +04001024 errno = 0;
paulfd79ac92004-10-13 05:06:08 +00001025 tmp = strtoul (arg, &endptr, 10);
Ulrich Weber664711c2011-12-21 02:24:11 +04001026 if (*endptr != '\0' || errno || tmp > UINT32_MAX)
paulfd79ac92004-10-13 05:06:08 +00001027 return NULL;
1028
1029 local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
1030
1031 if (!local_pref)
1032 return local_pref;
1033
1034 *local_pref = tmp;
1035
paul718e3742002-12-13 20:15:29 +00001036 return local_pref;
1037}
1038
1039/* Free route map's local preference value. */
paul94f2b392005-06-28 12:44:16 +00001040static void
paul718e3742002-12-13 20:15:29 +00001041route_set_local_pref_free (void *rule)
1042{
1043 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1044}
1045
1046/* Set local preference rule structure. */
1047struct route_map_rule_cmd route_set_local_pref_cmd =
1048{
1049 "local-preference",
1050 route_set_local_pref,
1051 route_set_local_pref_compile,
1052 route_set_local_pref_free,
1053};
David Lamparter6b0655a2014-06-04 06:53:35 +02001054
paul718e3742002-12-13 20:15:29 +00001055/* `set weight WEIGHT' */
1056
1057/* Set weight. */
paul94f2b392005-06-28 12:44:16 +00001058static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001059route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type,
1060 void *object)
1061{
1062 u_int32_t *weight;
1063 struct bgp_info *bgp_info;
1064
1065 if (type == RMAP_BGP)
1066 {
1067 /* Fetch routemap's rule information. */
1068 weight = rule;
1069 bgp_info = object;
1070
1071 /* Set weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001072 if (*weight)
1073 (bgp_attr_extra_get (bgp_info->attr))->weight = *weight;
1074 else if (bgp_info->attr->extra)
1075 bgp_info->attr->extra->weight = 0;
paul718e3742002-12-13 20:15:29 +00001076 }
1077
1078 return RMAP_OKAY;
1079}
1080
1081/* set local preference compilation. */
paul94f2b392005-06-28 12:44:16 +00001082static void *
paulfd79ac92004-10-13 05:06:08 +00001083route_set_weight_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001084{
paulfd79ac92004-10-13 05:06:08 +00001085 unsigned long tmp;
paul718e3742002-12-13 20:15:29 +00001086 u_int32_t *weight;
1087 char *endptr = NULL;
1088
1089 /* Local preference value shoud be integer. */
1090 if (! all_digit (arg))
1091 return NULL;
1092
Ulrich Weber664711c2011-12-21 02:24:11 +04001093 errno = 0;
paulfd79ac92004-10-13 05:06:08 +00001094 tmp = strtoul (arg, &endptr, 10);
Ulrich Weber664711c2011-12-21 02:24:11 +04001095 if (*endptr != '\0' || errno || tmp > UINT32_MAX)
paulfd79ac92004-10-13 05:06:08 +00001096 return NULL;
1097
paul718e3742002-12-13 20:15:29 +00001098 weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
paulfd79ac92004-10-13 05:06:08 +00001099
1100 if (weight == NULL)
1101 return weight;
1102
1103 *weight = tmp;
1104
paul718e3742002-12-13 20:15:29 +00001105 return weight;
1106}
1107
1108/* Free route map's local preference value. */
paul94f2b392005-06-28 12:44:16 +00001109static void
paul718e3742002-12-13 20:15:29 +00001110route_set_weight_free (void *rule)
1111{
1112 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1113}
1114
1115/* Set local preference rule structure. */
1116struct route_map_rule_cmd route_set_weight_cmd =
1117{
1118 "weight",
1119 route_set_weight,
1120 route_set_weight_compile,
1121 route_set_weight_free,
1122};
David Lamparter6b0655a2014-06-04 06:53:35 +02001123
paul718e3742002-12-13 20:15:29 +00001124/* `set metric METRIC' */
1125
1126/* Set metric to attribute. */
paul94f2b392005-06-28 12:44:16 +00001127static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001128route_set_metric (void *rule, struct prefix *prefix,
1129 route_map_object_t type, void *object)
1130{
1131 char *metric;
1132 u_int32_t metric_val;
1133 struct bgp_info *bgp_info;
1134
1135 if (type == RMAP_BGP)
1136 {
1137 /* Fetch routemap's rule information. */
1138 metric = rule;
1139 bgp_info = object;
1140
1141 if (! (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
1142 bgp_info->attr->med = 0;
1143 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
1144
1145 if (all_digit (metric))
1146 {
1147 metric_val = strtoul (metric, (char **)NULL, 10);
1148 bgp_info->attr->med = metric_val;
1149 }
1150 else
1151 {
1152 metric_val = strtoul (metric+1, (char **)NULL, 10);
1153
1154 if (strncmp (metric, "+", 1) == 0)
1155 {
paul3b424972003-10-13 09:47:32 +00001156 if (bgp_info->attr->med/2 + metric_val/2 > BGP_MED_MAX/2)
1157 bgp_info->attr->med = BGP_MED_MAX - 1;
paul718e3742002-12-13 20:15:29 +00001158 else
paul537d8ea2003-08-27 06:45:32 +00001159 bgp_info->attr->med += metric_val;
paul718e3742002-12-13 20:15:29 +00001160 }
1161 else if (strncmp (metric, "-", 1) == 0)
1162 {
paul537d8ea2003-08-27 06:45:32 +00001163 if (bgp_info->attr->med <= metric_val)
1164 bgp_info->attr->med = 0;
paul718e3742002-12-13 20:15:29 +00001165 else
paul537d8ea2003-08-27 06:45:32 +00001166 bgp_info->attr->med -= metric_val;
paul718e3742002-12-13 20:15:29 +00001167 }
1168 }
1169 }
1170 return RMAP_OKAY;
1171}
1172
1173/* set metric compilation. */
paul94f2b392005-06-28 12:44:16 +00001174static void *
paulfd79ac92004-10-13 05:06:08 +00001175route_set_metric_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001176{
paul94f2b392005-06-28 12:44:16 +00001177 unsigned long larg;
paul718e3742002-12-13 20:15:29 +00001178 char *endptr = NULL;
1179
1180 if (all_digit (arg))
1181 {
1182 /* set metric value check*/
Ulrich Weber664711c2011-12-21 02:24:11 +04001183 errno = 0;
paul94f2b392005-06-28 12:44:16 +00001184 larg = strtoul (arg, &endptr, 10);
Ulrich Weber664711c2011-12-21 02:24:11 +04001185 if (*endptr != '\0' || errno || larg > UINT32_MAX)
paul718e3742002-12-13 20:15:29 +00001186 return NULL;
1187 }
1188 else
1189 {
1190 /* set metric +/-value check */
1191 if ((strncmp (arg, "+", 1) != 0
1192 && strncmp (arg, "-", 1) != 0)
1193 || (! all_digit (arg+1)))
1194 return NULL;
1195
Ulrich Weber664711c2011-12-21 02:24:11 +04001196 errno = 0;
paul94f2b392005-06-28 12:44:16 +00001197 larg = strtoul (arg+1, &endptr, 10);
Ulrich Weber664711c2011-12-21 02:24:11 +04001198 if (*endptr != '\0' || errno || larg > UINT32_MAX)
paul718e3742002-12-13 20:15:29 +00001199 return NULL;
1200 }
1201
1202 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1203}
1204
1205/* Free route map's compiled `set metric' value. */
paul94f2b392005-06-28 12:44:16 +00001206static void
paul718e3742002-12-13 20:15:29 +00001207route_set_metric_free (void *rule)
1208{
1209 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1210}
1211
1212/* Set metric rule structure. */
1213struct route_map_rule_cmd route_set_metric_cmd =
1214{
1215 "metric",
1216 route_set_metric,
1217 route_set_metric_compile,
1218 route_set_metric_free,
1219};
David Lamparter6b0655a2014-06-04 06:53:35 +02001220
paul718e3742002-12-13 20:15:29 +00001221/* `set as-path prepend ASPATH' */
1222
1223/* For AS path prepend mechanism. */
paul94f2b392005-06-28 12:44:16 +00001224static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001225route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1226{
1227 struct aspath *aspath;
1228 struct aspath *new;
1229 struct bgp_info *binfo;
1230
1231 if (type == RMAP_BGP)
1232 {
1233 aspath = rule;
1234 binfo = object;
1235
1236 if (binfo->attr->aspath->refcnt)
1237 new = aspath_dup (binfo->attr->aspath);
1238 else
1239 new = binfo->attr->aspath;
1240
1241 aspath_prepend (aspath, new);
1242 binfo->attr->aspath = new;
1243 }
1244
1245 return RMAP_OKAY;
1246}
1247
Timo Teräs2aa640b2014-05-20 08:57:26 +03001248/* Set as-path prepend rule structure. */
paul718e3742002-12-13 20:15:29 +00001249struct route_map_rule_cmd route_set_aspath_prepend_cmd =
1250{
1251 "as-path prepend",
1252 route_set_aspath_prepend,
Timo Teräsb304dcb2014-05-20 09:04:49 +03001253 route_aspath_compile,
1254 route_aspath_free,
paul718e3742002-12-13 20:15:29 +00001255};
David Lamparter6b0655a2014-06-04 06:53:35 +02001256
Denis Ovsienko841f7a52008-04-10 11:47:45 +00001257/* `set as-path exclude ASn' */
1258
1259/* For ASN exclude mechanism.
1260 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1261 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1262 */
1263static route_map_result_t
1264route_set_aspath_exclude (void *rule, struct prefix *dummy, route_map_object_t type, void *object)
1265{
1266 struct aspath * new_path, * exclude_path;
1267 struct bgp_info *binfo;
1268
1269 if (type == RMAP_BGP)
1270 {
1271 exclude_path = rule;
1272 binfo = object;
1273 if (binfo->attr->aspath->refcnt)
1274 new_path = aspath_dup (binfo->attr->aspath);
1275 else
1276 new_path = binfo->attr->aspath;
1277 binfo->attr->aspath = aspath_filter_exclude (new_path, exclude_path);
1278 }
1279 return RMAP_OKAY;
1280}
1281
Denis Ovsienko841f7a52008-04-10 11:47:45 +00001282/* Set ASn exlude rule structure. */
1283struct route_map_rule_cmd route_set_aspath_exclude_cmd =
1284{
1285 "as-path exclude",
1286 route_set_aspath_exclude,
Timo Teräsb304dcb2014-05-20 09:04:49 +03001287 route_aspath_compile,
1288 route_aspath_free,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00001289};
David Lamparter6b0655a2014-06-04 06:53:35 +02001290
paul718e3742002-12-13 20:15:29 +00001291/* `set community COMMUNITY' */
1292struct rmap_com_set
1293{
1294 struct community *com;
1295 int additive;
1296 int none;
1297};
1298
1299/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001300static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001301route_set_community (void *rule, struct prefix *prefix,
1302 route_map_object_t type, void *object)
1303{
1304 struct rmap_com_set *rcs;
1305 struct bgp_info *binfo;
1306 struct attr *attr;
1307 struct community *new = NULL;
1308 struct community *old;
1309 struct community *merge;
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001310
paul718e3742002-12-13 20:15:29 +00001311 if (type == RMAP_BGP)
1312 {
1313 rcs = rule;
1314 binfo = object;
1315 attr = binfo->attr;
1316 old = attr->community;
1317
1318 /* "none" case. */
1319 if (rcs->none)
1320 {
1321 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES));
1322 attr->community = NULL;
Christian Frankeb06b35f2012-12-07 14:26:09 +00001323 /* See the longer comment down below. */
1324 if (old && old->refcnt == 0)
1325 community_free(old);
paul718e3742002-12-13 20:15:29 +00001326 return RMAP_OKAY;
1327 }
1328
1329 /* "additive" case. */
1330 if (rcs->additive && old)
1331 {
1332 merge = community_merge (community_dup (old), rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001333
1334 /* HACK: if the old community is not intern'd,
1335 * we should free it here, or all reference to it may be lost.
1336 * Really need to cleanup attribute caching sometime.
1337 */
1338 if (old->refcnt == 0)
1339 community_free (old);
paul718e3742002-12-13 20:15:29 +00001340 new = community_uniq_sort (merge);
1341 community_free (merge);
1342 }
1343 else
1344 new = community_dup (rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001345
1346 /* will be interned by caller if required */
Paul Jakma4a2035f2011-04-01 15:58:27 +01001347 attr->community = new;
hasso70601e02005-05-27 03:26:57 +00001348
paul718e3742002-12-13 20:15:29 +00001349 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1350 }
1351
1352 return RMAP_OKAY;
1353}
1354
1355/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001356static void *
paulfd79ac92004-10-13 05:06:08 +00001357route_set_community_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001358{
1359 struct rmap_com_set *rcs;
1360 struct community *com = NULL;
1361 char *sp;
1362 int additive = 0;
1363 int none = 0;
1364
1365 if (strcmp (arg, "none") == 0)
1366 none = 1;
1367 else
1368 {
1369 sp = strstr (arg, "additive");
1370
1371 if (sp && sp > arg)
1372 {
1373 /* "additive" keyworkd is included. */
1374 additive = 1;
1375 *(sp - 1) = '\0';
1376 }
1377
1378 com = community_str2com (arg);
1379
1380 if (additive)
1381 *(sp - 1) = ' ';
1382
1383 if (! com)
1384 return NULL;
1385 }
1386
Stephen Hemminger393deb92008-08-18 14:13:29 -07001387 rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
Paul Jakma4a2035f2011-04-01 15:58:27 +01001388 rcs->com = com;
paul718e3742002-12-13 20:15:29 +00001389 rcs->additive = additive;
1390 rcs->none = none;
1391
1392 return rcs;
1393}
1394
1395/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001396static void
paul718e3742002-12-13 20:15:29 +00001397route_set_community_free (void *rule)
1398{
1399 struct rmap_com_set *rcs = rule;
1400
1401 if (rcs->com)
1402 community_free (rcs->com);
1403 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs);
1404}
1405
1406/* Set community rule structure. */
1407struct route_map_rule_cmd route_set_community_cmd =
1408{
1409 "community",
1410 route_set_community,
1411 route_set_community_compile,
1412 route_set_community_free,
1413};
David Lamparter6b0655a2014-06-04 06:53:35 +02001414
hassofee6e4e2005-02-02 16:29:31 +00001415/* `set comm-list (<1-99>|<100-500>|WORD) delete' */
paul718e3742002-12-13 20:15:29 +00001416
1417/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001418static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001419route_set_community_delete (void *rule, struct prefix *prefix,
1420 route_map_object_t type, void *object)
1421{
1422 struct community_list *list;
1423 struct community *merge;
1424 struct community *new;
1425 struct community *old;
1426 struct bgp_info *binfo;
1427
1428 if (type == RMAP_BGP)
1429 {
1430 if (! rule)
1431 return RMAP_OKAY;
1432
1433 binfo = object;
hassofee6e4e2005-02-02 16:29:31 +00001434 list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00001435 old = binfo->attr->community;
1436
1437 if (list && old)
1438 {
1439 merge = community_list_match_delete (community_dup (old), list);
1440 new = community_uniq_sort (merge);
1441 community_free (merge);
1442
Michael Lambert604a9b42010-09-13 11:48:11 -04001443 /* HACK: if the old community is not intern'd,
1444 * we should free it here, or all reference to it may be lost.
1445 * Really need to cleanup attribute caching sometime.
1446 */
1447 if (old->refcnt == 0)
1448 community_free (old);
1449
paul718e3742002-12-13 20:15:29 +00001450 if (new->size == 0)
1451 {
1452 binfo->attr->community = NULL;
1453 binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1454 community_free (new);
1455 }
1456 else
1457 {
Paul Jakma4a2035f2011-04-01 15:58:27 +01001458 binfo->attr->community = new;
paul718e3742002-12-13 20:15:29 +00001459 binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1460 }
1461 }
1462 }
1463
1464 return RMAP_OKAY;
1465}
1466
1467/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001468static void *
paulfd79ac92004-10-13 05:06:08 +00001469route_set_community_delete_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001470{
1471 char *p;
1472 char *str;
1473 int len;
1474
1475 p = strchr (arg, ' ');
1476 if (p)
1477 {
1478 len = p - arg;
1479 str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
1480 memcpy (str, arg, len);
1481 }
1482 else
1483 str = NULL;
1484
1485 return str;
1486}
1487
1488/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001489static void
paul718e3742002-12-13 20:15:29 +00001490route_set_community_delete_free (void *rule)
1491{
1492 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1493}
1494
1495/* Set community rule structure. */
1496struct route_map_rule_cmd route_set_community_delete_cmd =
1497{
1498 "comm-list",
1499 route_set_community_delete,
1500 route_set_community_delete_compile,
1501 route_set_community_delete_free,
1502};
David Lamparter6b0655a2014-06-04 06:53:35 +02001503
paul718e3742002-12-13 20:15:29 +00001504/* `set extcommunity rt COMMUNITY' */
1505
David Lamparter73d78ea2014-06-04 00:58:47 +02001506/* For community set mechanism. Used by _rt and _soo. */
paul94f2b392005-06-28 12:44:16 +00001507static route_map_result_t
David Lamparter73d78ea2014-06-04 00:58:47 +02001508route_set_ecommunity (void *rule, struct prefix *prefix,
1509 route_map_object_t type, void *object)
paul718e3742002-12-13 20:15:29 +00001510{
1511 struct ecommunity *ecom;
1512 struct ecommunity *new_ecom;
1513 struct ecommunity *old_ecom;
1514 struct bgp_info *bgp_info;
1515
1516 if (type == RMAP_BGP)
1517 {
1518 ecom = rule;
1519 bgp_info = object;
1520
1521 if (! ecom)
1522 return RMAP_OKAY;
1523
1524 /* We assume additive for Extended Community. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001525 old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
paul718e3742002-12-13 20:15:29 +00001526
1527 if (old_ecom)
David Lamparter27bf90a2014-06-04 00:59:01 +02001528 {
1529 new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
1530
1531 /* old_ecom->refcnt = 1 => owned elsewhere, e.g. bgp_update_receive()
1532 * ->refcnt = 0 => set by a previous route-map statement */
1533 if (!old_ecom->refcnt)
1534 ecommunity_free (&old_ecom);
1535 }
paul718e3742002-12-13 20:15:29 +00001536 else
1537 new_ecom = ecommunity_dup (ecom);
1538
David Lamparter27bf90a2014-06-04 00:59:01 +02001539 /* will be intern()'d or attr_flush()'d by bgp_update_main() */
1540 bgp_info->attr->extra->ecommunity = new_ecom;
hasso70601e02005-05-27 03:26:57 +00001541
paul718e3742002-12-13 20:15:29 +00001542 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
1543 }
1544 return RMAP_OKAY;
1545}
1546
1547/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001548static void *
paulfd79ac92004-10-13 05:06:08 +00001549route_set_ecommunity_rt_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001550{
1551 struct ecommunity *ecom;
1552
1553 ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0);
1554 if (! ecom)
1555 return NULL;
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001556 return ecommunity_intern (ecom);
paul718e3742002-12-13 20:15:29 +00001557}
1558
David Lamparter73d78ea2014-06-04 00:58:47 +02001559/* Free function for set community. Used by _rt and _soo */
paul94f2b392005-06-28 12:44:16 +00001560static void
David Lamparter73d78ea2014-06-04 00:58:47 +02001561route_set_ecommunity_free (void *rule)
paul718e3742002-12-13 20:15:29 +00001562{
1563 struct ecommunity *ecom = rule;
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001564 ecommunity_unintern (&ecom);
paul718e3742002-12-13 20:15:29 +00001565}
1566
1567/* Set community rule structure. */
1568struct route_map_rule_cmd route_set_ecommunity_rt_cmd =
1569{
1570 "extcommunity rt",
David Lamparter73d78ea2014-06-04 00:58:47 +02001571 route_set_ecommunity,
paul718e3742002-12-13 20:15:29 +00001572 route_set_ecommunity_rt_compile,
David Lamparter73d78ea2014-06-04 00:58:47 +02001573 route_set_ecommunity_free,
paul718e3742002-12-13 20:15:29 +00001574};
1575
1576/* `set extcommunity soo COMMUNITY' */
1577
paul718e3742002-12-13 20:15:29 +00001578/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001579static void *
paulfd79ac92004-10-13 05:06:08 +00001580route_set_ecommunity_soo_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001581{
1582 struct ecommunity *ecom;
1583
1584 ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0);
1585 if (! ecom)
1586 return NULL;
1587
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001588 return ecommunity_intern (ecom);
paul718e3742002-12-13 20:15:29 +00001589}
1590
paul718e3742002-12-13 20:15:29 +00001591/* Set community rule structure. */
1592struct route_map_rule_cmd route_set_ecommunity_soo_cmd =
1593{
1594 "extcommunity soo",
David Lamparter73d78ea2014-06-04 00:58:47 +02001595 route_set_ecommunity,
paul718e3742002-12-13 20:15:29 +00001596 route_set_ecommunity_soo_compile,
David Lamparter73d78ea2014-06-04 00:58:47 +02001597 route_set_ecommunity_free,
paul718e3742002-12-13 20:15:29 +00001598};
David Lamparter6b0655a2014-06-04 06:53:35 +02001599
paul718e3742002-12-13 20:15:29 +00001600/* `set origin ORIGIN' */
1601
1602/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00001603static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001604route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1605{
1606 u_char *origin;
1607 struct bgp_info *bgp_info;
1608
1609 if (type == RMAP_BGP)
1610 {
1611 origin = rule;
1612 bgp_info = object;
1613
1614 bgp_info->attr->origin = *origin;
1615 }
1616
1617 return RMAP_OKAY;
1618}
1619
1620/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001621static void *
paulfd79ac92004-10-13 05:06:08 +00001622route_set_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001623{
1624 u_char *origin;
1625
1626 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
1627
1628 if (strcmp (arg, "igp") == 0)
1629 *origin = 0;
1630 else if (strcmp (arg, "egp") == 0)
1631 *origin = 1;
1632 else
1633 *origin = 2;
1634
1635 return origin;
1636}
1637
1638/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001639static void
paul718e3742002-12-13 20:15:29 +00001640route_set_origin_free (void *rule)
1641{
1642 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1643}
1644
Timo Teräs2aa640b2014-05-20 08:57:26 +03001645/* Set origin rule structure. */
paul718e3742002-12-13 20:15:29 +00001646struct route_map_rule_cmd route_set_origin_cmd =
1647{
1648 "origin",
1649 route_set_origin,
1650 route_set_origin_compile,
1651 route_set_origin_free,
1652};
David Lamparter6b0655a2014-06-04 06:53:35 +02001653
paul718e3742002-12-13 20:15:29 +00001654/* `set atomic-aggregate' */
1655
1656/* For atomic aggregate set. */
paul94f2b392005-06-28 12:44:16 +00001657static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001658route_set_atomic_aggregate (void *rule, struct prefix *prefix,
1659 route_map_object_t type, void *object)
1660{
1661 struct bgp_info *bgp_info;
1662
1663 if (type == RMAP_BGP)
1664 {
1665 bgp_info = object;
1666 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
1667 }
1668
1669 return RMAP_OKAY;
1670}
1671
1672/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001673static void *
paulfd79ac92004-10-13 05:06:08 +00001674route_set_atomic_aggregate_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001675{
1676 return (void *)1;
1677}
1678
1679/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001680static void
paul718e3742002-12-13 20:15:29 +00001681route_set_atomic_aggregate_free (void *rule)
1682{
1683 return;
1684}
1685
1686/* Set atomic aggregate rule structure. */
1687struct route_map_rule_cmd route_set_atomic_aggregate_cmd =
1688{
1689 "atomic-aggregate",
1690 route_set_atomic_aggregate,
1691 route_set_atomic_aggregate_compile,
1692 route_set_atomic_aggregate_free,
1693};
David Lamparter6b0655a2014-06-04 06:53:35 +02001694
paul718e3742002-12-13 20:15:29 +00001695/* `set aggregator as AS A.B.C.D' */
1696struct aggregator
1697{
1698 as_t as;
1699 struct in_addr address;
1700};
1701
paul94f2b392005-06-28 12:44:16 +00001702static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001703route_set_aggregator_as (void *rule, struct prefix *prefix,
1704 route_map_object_t type, void *object)
1705{
1706 struct bgp_info *bgp_info;
1707 struct aggregator *aggregator;
Paul Jakmafb982c22007-05-04 20:15:47 +00001708 struct attr_extra *ae;
paul718e3742002-12-13 20:15:29 +00001709
1710 if (type == RMAP_BGP)
1711 {
1712 bgp_info = object;
1713 aggregator = rule;
Paul Jakmafb982c22007-05-04 20:15:47 +00001714 ae = bgp_attr_extra_get (bgp_info->attr);
1715
1716 ae->aggregator_as = aggregator->as;
1717 ae->aggregator_addr = aggregator->address;
paul718e3742002-12-13 20:15:29 +00001718 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
1719 }
1720
1721 return RMAP_OKAY;
1722}
1723
paul94f2b392005-06-28 12:44:16 +00001724static void *
paulfd79ac92004-10-13 05:06:08 +00001725route_set_aggregator_as_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001726{
1727 struct aggregator *aggregator;
1728 char as[10];
1729 char address[20];
1730
Stephen Hemminger393deb92008-08-18 14:13:29 -07001731 aggregator = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));
paul718e3742002-12-13 20:15:29 +00001732 sscanf (arg, "%s %s", as, address);
1733
1734 aggregator->as = strtoul (as, NULL, 10);
1735 inet_aton (address, &aggregator->address);
1736
1737 return aggregator;
1738}
1739
paul94f2b392005-06-28 12:44:16 +00001740static void
paul718e3742002-12-13 20:15:29 +00001741route_set_aggregator_as_free (void *rule)
1742{
1743 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1744}
1745
1746struct route_map_rule_cmd route_set_aggregator_as_cmd =
1747{
1748 "aggregator as",
1749 route_set_aggregator_as,
1750 route_set_aggregator_as_compile,
1751 route_set_aggregator_as_free,
1752};
David Lamparter6b0655a2014-06-04 06:53:35 +02001753
paul718e3742002-12-13 20:15:29 +00001754#ifdef HAVE_IPV6
1755/* `match ipv6 address IP_ACCESS_LIST' */
1756
paul94f2b392005-06-28 12:44:16 +00001757static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001758route_match_ipv6_address (void *rule, struct prefix *prefix,
1759 route_map_object_t type, void *object)
1760{
1761 struct access_list *alist;
1762
1763 if (type == RMAP_BGP)
1764 {
1765 alist = access_list_lookup (AFI_IP6, (char *) rule);
1766 if (alist == NULL)
1767 return RMAP_NOMATCH;
1768
1769 return (access_list_apply (alist, prefix) == FILTER_DENY ?
1770 RMAP_NOMATCH : RMAP_MATCH);
1771 }
1772 return RMAP_NOMATCH;
1773}
1774
paul94f2b392005-06-28 12:44:16 +00001775static void *
paulfd79ac92004-10-13 05:06:08 +00001776route_match_ipv6_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001777{
1778 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1779}
1780
paul94f2b392005-06-28 12:44:16 +00001781static void
paul718e3742002-12-13 20:15:29 +00001782route_match_ipv6_address_free (void *rule)
1783{
1784 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1785}
1786
1787/* Route map commands for ip address matching. */
1788struct route_map_rule_cmd route_match_ipv6_address_cmd =
1789{
1790 "ipv6 address",
1791 route_match_ipv6_address,
1792 route_match_ipv6_address_compile,
1793 route_match_ipv6_address_free
1794};
David Lamparter6b0655a2014-06-04 06:53:35 +02001795
paul718e3742002-12-13 20:15:29 +00001796/* `match ipv6 next-hop IP_ADDRESS' */
1797
paul94f2b392005-06-28 12:44:16 +00001798static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001799route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
1800 route_map_object_t type, void *object)
1801{
Paul Jakma7aa9dce2014-09-19 14:42:23 +01001802 struct in6_addr *addr = rule;
paul718e3742002-12-13 20:15:29 +00001803 struct bgp_info *bgp_info;
1804
1805 if (type == RMAP_BGP)
1806 {
paul718e3742002-12-13 20:15:29 +00001807 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +00001808
1809 if (!bgp_info->attr->extra)
1810 return RMAP_NOMATCH;
1811
Paul Jakma7aa9dce2014-09-19 14:42:23 +01001812 if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, addr))
paul718e3742002-12-13 20:15:29 +00001813 return RMAP_MATCH;
1814
Paul Jakmafb982c22007-05-04 20:15:47 +00001815 if (bgp_info->attr->extra->mp_nexthop_len == 32 &&
Paul Jakma7aa9dce2014-09-19 14:42:23 +01001816 IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, addr))
paul718e3742002-12-13 20:15:29 +00001817 return RMAP_MATCH;
1818
1819 return RMAP_NOMATCH;
1820 }
1821
1822 return RMAP_NOMATCH;
1823}
1824
paul94f2b392005-06-28 12:44:16 +00001825static void *
paulfd79ac92004-10-13 05:06:08 +00001826route_match_ipv6_next_hop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001827{
1828 struct in6_addr *address;
1829 int ret;
1830
1831 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1832
1833 ret = inet_pton (AF_INET6, arg, address);
1834 if (!ret)
1835 {
1836 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1837 return NULL;
1838 }
1839
1840 return address;
1841}
1842
paul94f2b392005-06-28 12:44:16 +00001843static void
paul718e3742002-12-13 20:15:29 +00001844route_match_ipv6_next_hop_free (void *rule)
1845{
1846 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1847}
1848
1849struct route_map_rule_cmd route_match_ipv6_next_hop_cmd =
1850{
1851 "ipv6 next-hop",
1852 route_match_ipv6_next_hop,
1853 route_match_ipv6_next_hop_compile,
1854 route_match_ipv6_next_hop_free
1855};
David Lamparter6b0655a2014-06-04 06:53:35 +02001856
paul718e3742002-12-13 20:15:29 +00001857/* `match ipv6 address prefix-list PREFIX_LIST' */
1858
paul94f2b392005-06-28 12:44:16 +00001859static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001860route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix,
1861 route_map_object_t type, void *object)
1862{
1863 struct prefix_list *plist;
1864
1865 if (type == RMAP_BGP)
1866 {
1867 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
1868 if (plist == NULL)
1869 return RMAP_NOMATCH;
1870
1871 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
1872 RMAP_NOMATCH : RMAP_MATCH);
1873 }
1874 return RMAP_NOMATCH;
1875}
1876
paul94f2b392005-06-28 12:44:16 +00001877static void *
paulfd79ac92004-10-13 05:06:08 +00001878route_match_ipv6_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001879{
1880 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1881}
1882
paul94f2b392005-06-28 12:44:16 +00001883static void
paul718e3742002-12-13 20:15:29 +00001884route_match_ipv6_address_prefix_list_free (void *rule)
1885{
1886 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1887}
1888
1889struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
1890{
1891 "ipv6 address prefix-list",
1892 route_match_ipv6_address_prefix_list,
1893 route_match_ipv6_address_prefix_list_compile,
1894 route_match_ipv6_address_prefix_list_free
1895};
David Lamparter6b0655a2014-06-04 06:53:35 +02001896
paul718e3742002-12-13 20:15:29 +00001897/* `set ipv6 nexthop global IP_ADDRESS' */
1898
1899/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001900static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001901route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix,
1902 route_map_object_t type, void *object)
1903{
1904 struct in6_addr *address;
1905 struct bgp_info *bgp_info;
1906
1907 if (type == RMAP_BGP)
1908 {
1909 /* Fetch routemap's rule information. */
1910 address = rule;
1911 bgp_info = object;
1912
1913 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001914 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address;
paul718e3742002-12-13 20:15:29 +00001915
1916 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001917 if (bgp_info->attr->extra->mp_nexthop_len == 0)
1918 bgp_info->attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001919 }
1920
1921 return RMAP_OKAY;
1922}
1923
1924/* Route map `ip next-hop' compile function. Given string is converted
1925 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00001926static void *
paulfd79ac92004-10-13 05:06:08 +00001927route_set_ipv6_nexthop_global_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001928{
1929 int ret;
1930 struct in6_addr *address;
1931
1932 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1933
1934 ret = inet_pton (AF_INET6, arg, address);
1935
1936 if (ret == 0)
1937 {
1938 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1939 return NULL;
1940 }
1941
1942 return address;
1943}
1944
1945/* Free route map's compiled `ip next-hop' value. */
paul94f2b392005-06-28 12:44:16 +00001946static void
paul718e3742002-12-13 20:15:29 +00001947route_set_ipv6_nexthop_global_free (void *rule)
1948{
1949 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1950}
1951
1952/* Route map commands for ip nexthop set. */
1953struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd =
1954{
1955 "ipv6 next-hop global",
1956 route_set_ipv6_nexthop_global,
1957 route_set_ipv6_nexthop_global_compile,
1958 route_set_ipv6_nexthop_global_free
1959};
David Lamparter6b0655a2014-06-04 06:53:35 +02001960
paul718e3742002-12-13 20:15:29 +00001961/* `set ipv6 nexthop local IP_ADDRESS' */
1962
1963/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001964static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001965route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
1966 route_map_object_t type, void *object)
1967{
1968 struct in6_addr *address;
1969 struct bgp_info *bgp_info;
1970
1971 if (type == RMAP_BGP)
1972 {
1973 /* Fetch routemap's rule information. */
1974 address = rule;
1975 bgp_info = object;
1976
1977 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001978 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address;
paul718e3742002-12-13 20:15:29 +00001979
1980 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001981 if (bgp_info->attr->extra->mp_nexthop_len != 32)
1982 bgp_info->attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001983 }
1984
1985 return RMAP_OKAY;
1986}
1987
1988/* Route map `ip nexthop' compile function. Given string is converted
1989 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00001990static void *
paulfd79ac92004-10-13 05:06:08 +00001991route_set_ipv6_nexthop_local_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001992{
1993 int ret;
1994 struct in6_addr *address;
1995
1996 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1997
1998 ret = inet_pton (AF_INET6, arg, address);
1999
2000 if (ret == 0)
2001 {
2002 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2003 return NULL;
2004 }
2005
2006 return address;
2007}
2008
2009/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +00002010static void
paul718e3742002-12-13 20:15:29 +00002011route_set_ipv6_nexthop_local_free (void *rule)
2012{
2013 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2014}
2015
2016/* Route map commands for ip nexthop set. */
2017struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd =
2018{
2019 "ipv6 next-hop local",
2020 route_set_ipv6_nexthop_local,
2021 route_set_ipv6_nexthop_local_compile,
2022 route_set_ipv6_nexthop_local_free
2023};
2024#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02002025
paul718e3742002-12-13 20:15:29 +00002026/* `set vpnv4 nexthop A.B.C.D' */
2027
paul94f2b392005-06-28 12:44:16 +00002028static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002029route_set_vpnv4_nexthop (void *rule, struct prefix *prefix,
2030 route_map_object_t type, void *object)
2031{
2032 struct in_addr *address;
2033 struct bgp_info *bgp_info;
2034
2035 if (type == RMAP_BGP)
2036 {
2037 /* Fetch routemap's rule information. */
2038 address = rule;
2039 bgp_info = object;
2040
2041 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002042 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address;
paul718e3742002-12-13 20:15:29 +00002043 }
2044
2045 return RMAP_OKAY;
2046}
2047
paul94f2b392005-06-28 12:44:16 +00002048static void *
paulfd79ac92004-10-13 05:06:08 +00002049route_set_vpnv4_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002050{
2051 int ret;
2052 struct in_addr *address;
2053
2054 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2055
2056 ret = inet_aton (arg, address);
2057
2058 if (ret == 0)
2059 {
2060 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2061 return NULL;
2062 }
2063
2064 return address;
2065}
2066
paul94f2b392005-06-28 12:44:16 +00002067static void
paul718e3742002-12-13 20:15:29 +00002068route_set_vpnv4_nexthop_free (void *rule)
2069{
2070 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2071}
2072
2073/* Route map commands for ip nexthop set. */
2074struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd =
2075{
2076 "vpnv4 next-hop",
2077 route_set_vpnv4_nexthop,
2078 route_set_vpnv4_nexthop_compile,
2079 route_set_vpnv4_nexthop_free
2080};
David Lamparter6b0655a2014-06-04 06:53:35 +02002081
paul718e3742002-12-13 20:15:29 +00002082/* `set originator-id' */
2083
2084/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00002085static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002086route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
2087{
2088 struct in_addr *address;
2089 struct bgp_info *bgp_info;
2090
2091 if (type == RMAP_BGP)
2092 {
2093 address = rule;
2094 bgp_info = object;
2095
2096 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);
Paul Jakmafb982c22007-05-04 20:15:47 +00002097 (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address;
paul718e3742002-12-13 20:15:29 +00002098 }
2099
2100 return RMAP_OKAY;
2101}
2102
2103/* Compile function for originator-id set. */
paul94f2b392005-06-28 12:44:16 +00002104static void *
paulfd79ac92004-10-13 05:06:08 +00002105route_set_originator_id_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002106{
2107 int ret;
2108 struct in_addr *address;
2109
2110 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2111
2112 ret = inet_aton (arg, address);
2113
2114 if (ret == 0)
2115 {
2116 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2117 return NULL;
2118 }
2119
2120 return address;
2121}
2122
2123/* Compile function for originator_id set. */
paul94f2b392005-06-28 12:44:16 +00002124static void
paul718e3742002-12-13 20:15:29 +00002125route_set_originator_id_free (void *rule)
2126{
2127 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2128}
2129
Timo Teräs2aa640b2014-05-20 08:57:26 +03002130/* Set originator-id rule structure. */
paul718e3742002-12-13 20:15:29 +00002131struct route_map_rule_cmd route_set_originator_id_cmd =
2132{
2133 "originator-id",
2134 route_set_originator_id,
2135 route_set_originator_id_compile,
2136 route_set_originator_id_free,
2137};
David Lamparter6b0655a2014-06-04 06:53:35 +02002138
paul718e3742002-12-13 20:15:29 +00002139/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002140static int
paul718e3742002-12-13 20:15:29 +00002141bgp_route_match_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002142 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002143{
2144 int ret;
2145
2146 ret = route_map_add_match (index, command, arg);
2147 if (ret)
2148 {
2149 switch (ret)
2150 {
2151 case RMAP_RULE_MISSING:
2152 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2153 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002154 case RMAP_COMPILE_ERROR:
2155 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2156 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002157 }
2158 }
2159 return CMD_SUCCESS;
2160}
2161
2162/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002163static int
paul718e3742002-12-13 20:15:29 +00002164bgp_route_match_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002165 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002166{
2167 int ret;
2168
2169 ret = route_map_delete_match (index, command, arg);
2170 if (ret)
2171 {
2172 switch (ret)
2173 {
2174 case RMAP_RULE_MISSING:
2175 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2176 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002177 case RMAP_COMPILE_ERROR:
2178 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2179 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002180 }
2181 }
2182 return CMD_SUCCESS;
2183}
2184
2185/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002186static int
paul718e3742002-12-13 20:15:29 +00002187bgp_route_set_add (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002188 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002189{
2190 int ret;
2191
2192 ret = route_map_add_set (index, command, arg);
2193 if (ret)
2194 {
2195 switch (ret)
2196 {
2197 case RMAP_RULE_MISSING:
2198 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2199 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002200 case RMAP_COMPILE_ERROR:
2201 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2202 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002203 }
2204 }
2205 return CMD_SUCCESS;
2206}
2207
2208/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002209static int
paul718e3742002-12-13 20:15:29 +00002210bgp_route_set_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002211 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002212{
2213 int ret;
2214
2215 ret = route_map_delete_set (index, command, arg);
2216 if (ret)
2217 {
2218 switch (ret)
2219 {
2220 case RMAP_RULE_MISSING:
2221 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2222 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002223 case RMAP_COMPILE_ERROR:
2224 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2225 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002226 }
2227 }
2228 return CMD_SUCCESS;
2229}
2230
2231/* Hook function for updating route_map assignment. */
paul94f2b392005-06-28 12:44:16 +00002232static void
paulfd79ac92004-10-13 05:06:08 +00002233bgp_route_map_update (const char *unused)
paul718e3742002-12-13 20:15:29 +00002234{
2235 int i;
2236 afi_t afi;
2237 safi_t safi;
2238 int direct;
paul1eb8ef22005-04-07 07:30:20 +00002239 struct listnode *node, *nnode;
2240 struct listnode *mnode, *mnnode;
paul718e3742002-12-13 20:15:29 +00002241 struct bgp *bgp;
2242 struct peer *peer;
2243 struct peer_group *group;
2244 struct bgp_filter *filter;
2245 struct bgp_node *bn;
2246 struct bgp_static *bgp_static;
2247
2248 /* For neighbor route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002249 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002250 {
paul1eb8ef22005-04-07 07:30:20 +00002251 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002252 {
2253 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2254 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2255 {
2256 filter = &peer->filter[afi][safi];
2257
paulfee0f4c2004-09-13 05:12:46 +00002258 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002259 {
2260 if (filter->map[direct].name)
2261 filter->map[direct].map =
2262 route_map_lookup_by_name (filter->map[direct].name);
2263 else
2264 filter->map[direct].map = NULL;
2265 }
2266
2267 if (filter->usmap.name)
2268 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2269 else
2270 filter->usmap.map = NULL;
2271 }
2272 }
paul1eb8ef22005-04-07 07:30:20 +00002273 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
paul718e3742002-12-13 20:15:29 +00002274 {
2275 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2276 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2277 {
2278 filter = &group->conf->filter[afi][safi];
2279
paulfee0f4c2004-09-13 05:12:46 +00002280 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002281 {
2282 if (filter->map[direct].name)
2283 filter->map[direct].map =
2284 route_map_lookup_by_name (filter->map[direct].name);
2285 else
2286 filter->map[direct].map = NULL;
2287 }
2288
2289 if (filter->usmap.name)
2290 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2291 else
2292 filter->usmap.map = NULL;
2293 }
2294 }
2295 }
2296
2297 /* For default-originate route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002298 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002299 {
paul1eb8ef22005-04-07 07:30:20 +00002300 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002301 {
2302 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2303 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2304 {
2305 if (peer->default_rmap[afi][safi].name)
2306 peer->default_rmap[afi][safi].map =
2307 route_map_lookup_by_name (peer->default_rmap[afi][safi].name);
2308 else
2309 peer->default_rmap[afi][safi].map = NULL;
2310 }
2311 }
2312 }
2313
2314 /* For network route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002315 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002316 {
2317 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2318 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2319 for (bn = bgp_table_top (bgp->route[afi][safi]); bn;
2320 bn = bgp_route_next (bn))
2321 if ((bgp_static = bn->info) != NULL)
2322 {
2323 if (bgp_static->rmap.name)
2324 bgp_static->rmap.map =
2325 route_map_lookup_by_name (bgp_static->rmap.name);
2326 else
2327 bgp_static->rmap.map = NULL;
2328 }
2329 }
2330
2331 /* For redistribute route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002332 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002333 {
2334 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2335 {
2336 if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)
2337 bgp->rmap[ZEBRA_FAMILY_IPV4][i].map =
2338 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);
2339#ifdef HAVE_IPV6
2340 if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)
2341 bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =
2342 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);
2343#endif /* HAVE_IPV6 */
2344 }
2345 }
2346}
David Lamparter6b0655a2014-06-04 06:53:35 +02002347
paulfee0f4c2004-09-13 05:12:46 +00002348DEFUN (match_peer,
2349 match_peer_cmd,
2350 "match peer (A.B.C.D|X:X::X:X)",
2351 MATCH_STR
2352 "Match peer address\n"
2353 "IPv6 address of peer\n"
2354 "IP address of peer\n")
2355{
2356 return bgp_route_match_add (vty, vty->index, "peer", argv[0]);
2357}
2358
2359DEFUN (match_peer_local,
2360 match_peer_local_cmd,
2361 "match peer local",
2362 MATCH_STR
2363 "Match peer address\n"
2364 "Static or Redistributed routes\n")
2365{
Jorge Boncompte [DTI2]4fe080d2012-04-13 13:46:08 +02002366 return bgp_route_match_add (vty, vty->index, "peer", "local");
paulfee0f4c2004-09-13 05:12:46 +00002367}
2368
2369DEFUN (no_match_peer,
2370 no_match_peer_cmd,
2371 "no match peer",
2372 NO_STR
2373 MATCH_STR
2374 "Match peer address\n")
2375{
2376 if (argc == 0)
2377 return bgp_route_match_delete (vty, vty->index, "peer", NULL);
2378
2379 return bgp_route_match_delete (vty, vty->index, "peer", argv[0]);
2380}
2381
2382ALIAS (no_match_peer,
2383 no_match_peer_val_cmd,
2384 "no match peer (A.B.C.D|X:X::X:X)",
2385 NO_STR
2386 MATCH_STR
2387 "Match peer address\n"
2388 "IPv6 address of peer\n"
2389 "IP address of peer\n")
2390
2391ALIAS (no_match_peer,
2392 no_match_peer_local_cmd,
2393 "no match peer local",
2394 NO_STR
2395 MATCH_STR
2396 "Match peer address\n"
2397 "Static or Redistributed routes\n")
2398
paul718e3742002-12-13 20:15:29 +00002399DEFUN (match_ip_address,
2400 match_ip_address_cmd,
2401 "match ip address (<1-199>|<1300-2699>|WORD)",
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{
2409 return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);
2410}
2411
2412DEFUN (no_match_ip_address,
2413 no_match_ip_address_cmd,
2414 "no match ip address",
2415 NO_STR
2416 MATCH_STR
2417 IP_STR
2418 "Match address of route\n")
2419{
2420 if (argc == 0)
2421 return bgp_route_match_delete (vty, vty->index, "ip address", NULL);
2422
2423 return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);
2424}
2425
2426ALIAS (no_match_ip_address,
2427 no_match_ip_address_val_cmd,
2428 "no match ip address (<1-199>|<1300-2699>|WORD)",
2429 NO_STR
2430 MATCH_STR
2431 IP_STR
2432 "Match address of route\n"
2433 "IP access-list number\n"
2434 "IP access-list number (expanded range)\n"
2435 "IP Access-list name\n")
2436
2437DEFUN (match_ip_next_hop,
2438 match_ip_next_hop_cmd,
2439 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
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{
2447 return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
2448}
2449
2450DEFUN (no_match_ip_next_hop,
2451 no_match_ip_next_hop_cmd,
2452 "no match ip next-hop",
2453 NO_STR
2454 MATCH_STR
2455 IP_STR
2456 "Match next-hop address of route\n")
2457{
2458 if (argc == 0)
2459 return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
2460
2461 return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
2462}
2463
2464ALIAS (no_match_ip_next_hop,
2465 no_match_ip_next_hop_val_cmd,
2466 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2467 NO_STR
2468 MATCH_STR
2469 IP_STR
2470 "Match next-hop address of route\n"
2471 "IP access-list number\n"
2472 "IP access-list number (expanded range)\n"
2473 "IP Access-list name\n")
2474
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +04002475/* match probability { */
2476
2477DEFUN (match_probability,
2478 match_probability_cmd,
2479 "match probability <0-100>",
2480 MATCH_STR
2481 "Match portion of routes defined by percentage value\n"
2482 "Percentage of routes\n")
2483{
2484 return bgp_route_match_add (vty, vty->index, "probability", argv[0]);
2485}
2486
2487DEFUN (no_match_probability,
2488 no_match_probability_cmd,
2489 "no match probability",
2490 NO_STR
2491 MATCH_STR
2492 "Match portion of routes defined by percentage value\n")
2493{
2494 return bgp_route_match_delete (vty, vty->index, "probability", argc ? argv[0] : NULL);
2495}
2496
2497ALIAS (no_match_probability,
2498 no_match_probability_val_cmd,
2499 "no match probability <1-99>",
2500 NO_STR
2501 MATCH_STR
2502 "Match portion of routes defined by percentage value\n"
2503 "Percentage of routes\n")
2504
2505/* } */
2506
hassoc1643bb2005-02-02 16:43:17 +00002507DEFUN (match_ip_route_source,
2508 match_ip_route_source_cmd,
2509 "match ip route-source (<1-199>|<1300-2699>|WORD)",
2510 MATCH_STR
2511 IP_STR
2512 "Match advertising source address of route\n"
2513 "IP access-list number\n"
2514 "IP access-list number (expanded range)\n"
2515 "IP standard access-list name\n")
2516{
2517 return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]);
2518}
2519
2520DEFUN (no_match_ip_route_source,
2521 no_match_ip_route_source_cmd,
2522 "no match ip route-source",
2523 NO_STR
2524 MATCH_STR
2525 IP_STR
2526 "Match advertising source address of route\n")
2527{
2528 if (argc == 0)
2529 return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL);
2530
2531 return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]);
2532}
2533
2534ALIAS (no_match_ip_route_source,
2535 no_match_ip_route_source_val_cmd,
2536 "no match ip route-source (<1-199>|<1300-2699>|WORD)",
2537 NO_STR
2538 MATCH_STR
2539 IP_STR
2540 "Match advertising source address of route\n"
2541 "IP access-list number\n"
2542 "IP access-list number (expanded range)\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002543 "IP standard access-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002544
paul718e3742002-12-13 20:15:29 +00002545DEFUN (match_ip_address_prefix_list,
2546 match_ip_address_prefix_list_cmd,
2547 "match ip address prefix-list WORD",
2548 MATCH_STR
2549 IP_STR
2550 "Match address of route\n"
2551 "Match entries of prefix-lists\n"
2552 "IP prefix-list name\n")
2553{
2554 return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
2555}
2556
2557DEFUN (no_match_ip_address_prefix_list,
2558 no_match_ip_address_prefix_list_cmd,
2559 "no match ip address prefix-list",
2560 NO_STR
2561 MATCH_STR
2562 IP_STR
2563 "Match address of route\n"
2564 "Match entries of prefix-lists\n")
2565{
2566 if (argc == 0)
2567 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
2568
2569 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
2570}
2571
2572ALIAS (no_match_ip_address_prefix_list,
2573 no_match_ip_address_prefix_list_val_cmd,
2574 "no match ip address prefix-list WORD",
2575 NO_STR
2576 MATCH_STR
2577 IP_STR
2578 "Match address of route\n"
2579 "Match entries of prefix-lists\n"
2580 "IP prefix-list name\n")
2581
2582DEFUN (match_ip_next_hop_prefix_list,
2583 match_ip_next_hop_prefix_list_cmd,
2584 "match ip next-hop prefix-list WORD",
2585 MATCH_STR
2586 IP_STR
2587 "Match next-hop address of route\n"
2588 "Match entries of prefix-lists\n"
2589 "IP prefix-list name\n")
2590{
2591 return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2592}
2593
2594DEFUN (no_match_ip_next_hop_prefix_list,
2595 no_match_ip_next_hop_prefix_list_cmd,
2596 "no match ip next-hop prefix-list",
2597 NO_STR
2598 MATCH_STR
2599 IP_STR
2600 "Match next-hop address of route\n"
2601 "Match entries of prefix-lists\n")
2602{
2603 if (argc == 0)
2604 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
2605
2606 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2607}
2608
2609ALIAS (no_match_ip_next_hop_prefix_list,
2610 no_match_ip_next_hop_prefix_list_val_cmd,
2611 "no match ip next-hop prefix-list WORD",
2612 NO_STR
2613 MATCH_STR
2614 IP_STR
2615 "Match next-hop address of route\n"
2616 "Match entries of prefix-lists\n"
2617 "IP prefix-list name\n")
2618
hassoc1643bb2005-02-02 16:43:17 +00002619DEFUN (match_ip_route_source_prefix_list,
2620 match_ip_route_source_prefix_list_cmd,
2621 "match ip route-source prefix-list WORD",
2622 MATCH_STR
2623 IP_STR
2624 "Match advertising source address of route\n"
2625 "Match entries of prefix-lists\n"
2626 "IP prefix-list name\n")
2627{
2628 return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]);
2629}
2630
2631DEFUN (no_match_ip_route_source_prefix_list,
2632 no_match_ip_route_source_prefix_list_cmd,
2633 "no match ip route-source prefix-list",
2634 NO_STR
2635 MATCH_STR
2636 IP_STR
2637 "Match advertising source address of route\n"
2638 "Match entries of prefix-lists\n")
2639{
2640 if (argc == 0)
2641 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL);
2642
2643 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]);
2644}
2645
2646ALIAS (no_match_ip_route_source_prefix_list,
2647 no_match_ip_route_source_prefix_list_val_cmd,
2648 "no match ip route-source prefix-list WORD",
2649 NO_STR
2650 MATCH_STR
2651 IP_STR
2652 "Match advertising source address of route\n"
2653 "Match entries of prefix-lists\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002654 "IP prefix-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002655
paul718e3742002-12-13 20:15:29 +00002656DEFUN (match_metric,
2657 match_metric_cmd,
2658 "match metric <0-4294967295>",
2659 MATCH_STR
2660 "Match metric of route\n"
2661 "Metric value\n")
2662{
2663 return bgp_route_match_add (vty, vty->index, "metric", argv[0]);
2664}
2665
2666DEFUN (no_match_metric,
2667 no_match_metric_cmd,
2668 "no match metric",
2669 NO_STR
2670 MATCH_STR
2671 "Match metric of route\n")
2672{
2673 if (argc == 0)
2674 return bgp_route_match_delete (vty, vty->index, "metric", NULL);
2675
2676 return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);
2677}
2678
2679ALIAS (no_match_metric,
2680 no_match_metric_val_cmd,
2681 "no match metric <0-4294967295>",
2682 NO_STR
2683 MATCH_STR
2684 "Match metric of route\n"
2685 "Metric value\n")
2686
2687DEFUN (match_community,
2688 match_community_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002689 "match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002690 MATCH_STR
2691 "Match BGP community list\n"
2692 "Community-list number (standard)\n"
2693 "Community-list number (expanded)\n"
2694 "Community-list name\n")
2695{
2696 return bgp_route_match_add (vty, vty->index, "community", argv[0]);
2697}
2698
2699DEFUN (match_community_exact,
2700 match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002701 "match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002702 MATCH_STR
2703 "Match BGP community list\n"
2704 "Community-list number (standard)\n"
2705 "Community-list number (expanded)\n"
2706 "Community-list name\n"
2707 "Do exact matching of communities\n")
2708{
2709 int ret;
2710 char *argstr;
2711
2712 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
2713 strlen (argv[0]) + strlen ("exact-match") + 2);
2714
2715 sprintf (argstr, "%s exact-match", argv[0]);
2716
2717 ret = bgp_route_match_add (vty, vty->index, "community", argstr);
2718
2719 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
2720
2721 return ret;
2722}
2723
2724DEFUN (no_match_community,
2725 no_match_community_cmd,
2726 "no match community",
2727 NO_STR
2728 MATCH_STR
2729 "Match BGP community list\n")
2730{
2731 return bgp_route_match_delete (vty, vty->index, "community", NULL);
2732}
2733
2734ALIAS (no_match_community,
2735 no_match_community_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002736 "no match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002737 NO_STR
2738 MATCH_STR
2739 "Match BGP community list\n"
2740 "Community-list number (standard)\n"
2741 "Community-list number (expanded)\n"
2742 "Community-list name\n")
2743
2744ALIAS (no_match_community,
2745 no_match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002746 "no match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002747 NO_STR
2748 MATCH_STR
2749 "Match BGP community list\n"
2750 "Community-list number (standard)\n"
2751 "Community-list number (expanded)\n"
2752 "Community-list name\n"
2753 "Do exact matching of communities\n")
2754
paul73ffb252003-04-19 15:49:49 +00002755DEFUN (match_ecommunity,
2756 match_ecommunity_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002757 "match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002758 MATCH_STR
2759 "Match BGP/VPN extended community list\n"
2760 "Extended community-list number (standard)\n"
2761 "Extended community-list number (expanded)\n"
2762 "Extended community-list name\n")
2763{
2764 return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]);
2765}
2766
2767DEFUN (no_match_ecommunity,
2768 no_match_ecommunity_cmd,
2769 "no match extcommunity",
2770 NO_STR
2771 MATCH_STR
2772 "Match BGP/VPN extended community list\n")
2773{
2774 return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL);
2775}
2776
2777ALIAS (no_match_ecommunity,
2778 no_match_ecommunity_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002779 "no match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002780 NO_STR
2781 MATCH_STR
2782 "Match BGP/VPN extended community list\n"
2783 "Extended community-list number (standard)\n"
2784 "Extended community-list number (expanded)\n"
2785 "Extended community-list name\n")
2786
paul718e3742002-12-13 20:15:29 +00002787DEFUN (match_aspath,
2788 match_aspath_cmd,
2789 "match as-path WORD",
2790 MATCH_STR
2791 "Match BGP AS path list\n"
2792 "AS path access-list name\n")
2793{
2794 return bgp_route_match_add (vty, vty->index, "as-path", argv[0]);
2795}
2796
2797DEFUN (no_match_aspath,
2798 no_match_aspath_cmd,
2799 "no match as-path",
2800 NO_STR
2801 MATCH_STR
2802 "Match BGP AS path list\n")
2803{
2804 return bgp_route_match_delete (vty, vty->index, "as-path", NULL);
2805}
2806
2807ALIAS (no_match_aspath,
2808 no_match_aspath_val_cmd,
2809 "no match as-path WORD",
2810 NO_STR
2811 MATCH_STR
2812 "Match BGP AS path list\n"
2813 "AS path access-list name\n")
2814
2815DEFUN (match_origin,
2816 match_origin_cmd,
2817 "match origin (egp|igp|incomplete)",
2818 MATCH_STR
2819 "BGP origin code\n"
2820 "remote EGP\n"
2821 "local IGP\n"
2822 "unknown heritage\n")
2823{
2824 if (strncmp (argv[0], "igp", 2) == 0)
2825 return bgp_route_match_add (vty, vty->index, "origin", "igp");
2826 if (strncmp (argv[0], "egp", 1) == 0)
2827 return bgp_route_match_add (vty, vty->index, "origin", "egp");
2828 if (strncmp (argv[0], "incomplete", 2) == 0)
2829 return bgp_route_match_add (vty, vty->index, "origin", "incomplete");
2830
2831 return CMD_WARNING;
2832}
2833
2834DEFUN (no_match_origin,
2835 no_match_origin_cmd,
2836 "no match origin",
2837 NO_STR
2838 MATCH_STR
2839 "BGP origin code\n")
2840{
2841 return bgp_route_match_delete (vty, vty->index, "origin", NULL);
2842}
2843
2844ALIAS (no_match_origin,
2845 no_match_origin_val_cmd,
2846 "no match origin (egp|igp|incomplete)",
2847 NO_STR
2848 MATCH_STR
2849 "BGP origin code\n"
2850 "remote EGP\n"
2851 "local IGP\n"
2852 "unknown heritage\n")
2853
2854DEFUN (set_ip_nexthop,
2855 set_ip_nexthop_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002856 "set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002857 SET_STR
2858 IP_STR
2859 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002860 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002861{
2862 union sockunion su;
2863 int ret;
2864
2865 ret = str2sockunion (argv[0], &su);
2866 if (ret < 0)
2867 {
2868 vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
2869 return CMD_WARNING;
2870 }
2871
2872 return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
2873}
2874
paulaf5cd0a2003-11-02 07:24:40 +00002875DEFUN (set_ip_nexthop_peer,
2876 set_ip_nexthop_peer_cmd,
2877 "set ip next-hop peer-address",
2878 SET_STR
2879 IP_STR
2880 "Next hop address\n"
2881 "Use peer address (for BGP only)\n")
2882{
2883 return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address");
2884}
2885
paul94f2b392005-06-28 12:44:16 +00002886DEFUN_DEPRECATED (no_set_ip_nexthop_peer,
paulaf5cd0a2003-11-02 07:24:40 +00002887 no_set_ip_nexthop_peer_cmd,
2888 "no set ip next-hop peer-address",
2889 NO_STR
2890 SET_STR
2891 IP_STR
2892 "Next hop address\n"
2893 "Use peer address (for BGP only)\n")
2894{
2895 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2896}
2897
2898
paul718e3742002-12-13 20:15:29 +00002899DEFUN (no_set_ip_nexthop,
2900 no_set_ip_nexthop_cmd,
2901 "no set ip next-hop",
2902 NO_STR
2903 SET_STR
paul718e3742002-12-13 20:15:29 +00002904 "Next hop address\n")
2905{
paulaf5cd0a2003-11-02 07:24:40 +00002906 if (argc == 0)
paul718e3742002-12-13 20:15:29 +00002907 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2908
2909 return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
2910}
2911
2912ALIAS (no_set_ip_nexthop,
2913 no_set_ip_nexthop_val_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002914 "no set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002915 NO_STR
2916 SET_STR
2917 IP_STR
2918 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002919 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002920
2921DEFUN (set_metric,
2922 set_metric_cmd,
paul73ffb252003-04-19 15:49:49 +00002923 "set metric <0-4294967295>",
paul718e3742002-12-13 20:15:29 +00002924 SET_STR
2925 "Metric value for destination routing protocol\n"
paul73ffb252003-04-19 15:49:49 +00002926 "Metric value\n")
paul718e3742002-12-13 20:15:29 +00002927{
2928 return bgp_route_set_add (vty, vty->index, "metric", argv[0]);
2929}
2930
paul73ffb252003-04-19 15:49:49 +00002931ALIAS (set_metric,
2932 set_metric_addsub_cmd,
2933 "set metric <+/-metric>",
2934 SET_STR
2935 "Metric value for destination routing protocol\n"
hasso033e8612005-05-28 04:50:54 +00002936 "Add or subtract metric\n")
paul73ffb252003-04-19 15:49:49 +00002937
paul718e3742002-12-13 20:15:29 +00002938DEFUN (no_set_metric,
2939 no_set_metric_cmd,
2940 "no set metric",
2941 NO_STR
2942 SET_STR
2943 "Metric value for destination routing protocol\n")
2944{
2945 if (argc == 0)
2946 return bgp_route_set_delete (vty, vty->index, "metric", NULL);
2947
2948 return bgp_route_set_delete (vty, vty->index, "metric", argv[0]);
2949}
2950
2951ALIAS (no_set_metric,
2952 no_set_metric_val_cmd,
2953 "no set metric <0-4294967295>",
2954 NO_STR
2955 SET_STR
2956 "Metric value for destination routing protocol\n"
2957 "Metric value\n")
2958
2959DEFUN (set_local_pref,
2960 set_local_pref_cmd,
2961 "set local-preference <0-4294967295>",
2962 SET_STR
2963 "BGP local preference path attribute\n"
2964 "Preference value\n")
2965{
2966 return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]);
2967}
2968
2969DEFUN (no_set_local_pref,
2970 no_set_local_pref_cmd,
2971 "no set local-preference",
2972 NO_STR
2973 SET_STR
2974 "BGP local preference path attribute\n")
2975{
2976 if (argc == 0)
2977 return bgp_route_set_delete (vty, vty->index, "local-preference", NULL);
2978
2979 return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]);
2980}
2981
2982ALIAS (no_set_local_pref,
2983 no_set_local_pref_val_cmd,
2984 "no set local-preference <0-4294967295>",
2985 NO_STR
2986 SET_STR
2987 "BGP local preference path attribute\n"
2988 "Preference value\n")
2989
2990DEFUN (set_weight,
2991 set_weight_cmd,
2992 "set weight <0-4294967295>",
2993 SET_STR
2994 "BGP weight for routing table\n"
2995 "Weight value\n")
2996{
2997 return bgp_route_set_add (vty, vty->index, "weight", argv[0]);
2998}
2999
3000DEFUN (no_set_weight,
3001 no_set_weight_cmd,
3002 "no set weight",
3003 NO_STR
3004 SET_STR
3005 "BGP weight for routing table\n")
3006{
3007 if (argc == 0)
3008 return bgp_route_set_delete (vty, vty->index, "weight", NULL);
3009
3010 return bgp_route_set_delete (vty, vty->index, "weight", argv[0]);
3011}
3012
3013ALIAS (no_set_weight,
3014 no_set_weight_val_cmd,
3015 "no set weight <0-4294967295>",
3016 NO_STR
3017 SET_STR
3018 "BGP weight for routing table\n"
3019 "Weight value\n")
3020
3021DEFUN (set_aspath_prepend,
3022 set_aspath_prepend_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003023 "set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003024 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003025 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003026 "Prepend to the as-path\n"
3027 "AS number\n")
3028{
3029 int ret;
3030 char *str;
3031
3032 str = argv_concat (argv, argc, 0);
3033 ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str);
3034 XFREE (MTYPE_TMP, str);
3035
3036 return ret;
3037}
3038
3039DEFUN (no_set_aspath_prepend,
3040 no_set_aspath_prepend_cmd,
3041 "no set as-path prepend",
3042 NO_STR
3043 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003044 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003045 "Prepend to the as-path\n")
3046{
Denis Ovsienkoa7f93f32007-12-18 15:13:06 +00003047 int ret;
3048 char *str;
3049
3050 if (argc == 0)
3051 return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL);
3052
3053 str = argv_concat (argv, argc, 0);
3054 ret = bgp_route_set_delete (vty, vty->index, "as-path prepend", str);
3055 XFREE (MTYPE_TMP, str);
3056 return ret;
paul718e3742002-12-13 20:15:29 +00003057}
3058
3059ALIAS (no_set_aspath_prepend,
3060 no_set_aspath_prepend_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003061 "no set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003062 NO_STR
3063 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003064 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003065 "Prepend to the as-path\n"
3066 "AS number\n")
3067
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003068DEFUN (set_aspath_exclude,
3069 set_aspath_exclude_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003070 "set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003071 SET_STR
3072 "Transform BGP AS-path attribute\n"
3073 "Exclude from the as-path\n"
3074 "AS number\n")
3075{
3076 int ret;
3077 char *str;
3078
3079 str = argv_concat (argv, argc, 0);
3080 ret = bgp_route_set_add (vty, vty->index, "as-path exclude", str);
3081 XFREE (MTYPE_TMP, str);
3082 return ret;
3083}
3084
3085DEFUN (no_set_aspath_exclude,
3086 no_set_aspath_exclude_cmd,
3087 "no set as-path exclude",
3088 NO_STR
3089 SET_STR
3090 "Transform BGP AS_PATH attribute\n"
3091 "Exclude from the as-path\n")
3092{
3093 int ret;
3094 char *str;
3095
3096 if (argc == 0)
3097 return bgp_route_set_delete (vty, vty->index, "as-path exclude", NULL);
3098
3099 str = argv_concat (argv, argc, 0);
3100 ret = bgp_route_set_delete (vty, vty->index, "as-path exclude", str);
3101 XFREE (MTYPE_TMP, str);
3102 return ret;
3103}
3104
3105ALIAS (no_set_aspath_exclude,
3106 no_set_aspath_exclude_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003107 "no set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003108 NO_STR
3109 SET_STR
3110 "Transform BGP AS_PATH attribute\n"
3111 "Exclude from the as-path\n"
3112 "AS number\n")
3113
paul718e3742002-12-13 20:15:29 +00003114DEFUN (set_community,
3115 set_community_cmd,
3116 "set community .AA:NN",
3117 SET_STR
3118 "BGP community attribute\n"
3119 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3120{
3121 int i;
3122 int first = 0;
3123 int additive = 0;
3124 struct buffer *b;
3125 struct community *com = NULL;
3126 char *str;
3127 char *argstr;
3128 int ret;
3129
3130 b = buffer_new (1024);
3131
3132 for (i = 0; i < argc; i++)
3133 {
3134 if (strncmp (argv[i], "additive", strlen (argv[i])) == 0)
3135 {
3136 additive = 1;
3137 continue;
3138 }
3139
3140 if (first)
3141 buffer_putc (b, ' ');
3142 else
3143 first = 1;
3144
3145 if (strncmp (argv[i], "internet", strlen (argv[i])) == 0)
3146 {
3147 buffer_putstr (b, "internet");
3148 continue;
3149 }
3150 if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0)
3151 {
3152 buffer_putstr (b, "local-AS");
3153 continue;
3154 }
3155 if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0
3156 && strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0)
3157 {
3158 buffer_putstr (b, "no-advertise");
3159 continue;
3160 }
3161 if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0
3162 && strncmp (argv[i], "no-export", strlen (argv[i])) == 0)
3163 {
3164 buffer_putstr (b, "no-export");
3165 continue;
3166 }
3167 buffer_putstr (b, argv[i]);
3168 }
3169 buffer_putc (b, '\0');
3170
3171 /* Fetch result string then compile it to communities attribute. */
3172 str = buffer_getstr (b);
3173 buffer_free (b);
3174
3175 if (str)
3176 {
3177 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00003178 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00003179 }
3180
3181 /* Can't compile user input into communities attribute. */
3182 if (! com)
3183 {
3184 vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE);
3185 return CMD_WARNING;
3186 }
3187
3188 /* Set communites attribute string. */
3189 str = community_str (com);
3190
3191 if (additive)
3192 {
3193 argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1);
3194 strcpy (argstr, str);
3195 strcpy (argstr + strlen (str), " additive");
3196 ret = bgp_route_set_add (vty, vty->index, "community", argstr);
3197 XFREE (MTYPE_TMP, argstr);
3198 }
3199 else
3200 ret = bgp_route_set_add (vty, vty->index, "community", str);
3201
3202 community_free (com);
3203
3204 return ret;
3205}
3206
3207DEFUN (set_community_none,
3208 set_community_none_cmd,
3209 "set community none",
3210 SET_STR
3211 "BGP community attribute\n"
3212 "No community attribute\n")
3213{
3214 return bgp_route_set_add (vty, vty->index, "community", "none");
3215}
3216
3217DEFUN (no_set_community,
3218 no_set_community_cmd,
3219 "no set community",
3220 NO_STR
3221 SET_STR
3222 "BGP community attribute\n")
3223{
3224 return bgp_route_set_delete (vty, vty->index, "community", NULL);
3225}
3226
3227ALIAS (no_set_community,
3228 no_set_community_val_cmd,
3229 "no set community .AA:NN",
3230 NO_STR
3231 SET_STR
3232 "BGP community attribute\n"
3233 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3234
3235ALIAS (no_set_community,
3236 no_set_community_none_cmd,
3237 "no set community none",
3238 NO_STR
3239 SET_STR
3240 "BGP community attribute\n"
3241 "No community attribute\n")
3242
3243DEFUN (set_community_delete,
3244 set_community_delete_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003245 "set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003246 SET_STR
3247 "set BGP community list (for deletion)\n"
3248 "Community-list number (standard)\n"
3249 "Communitly-list number (expanded)\n"
3250 "Community-list name\n"
3251 "Delete matching communities\n")
3252{
3253 char *str;
3254
3255 str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1);
3256 strcpy (str, argv[0]);
3257 strcpy (str + strlen (argv[0]), " delete");
3258
3259 bgp_route_set_add (vty, vty->index, "comm-list", str);
3260
3261 XFREE (MTYPE_TMP, str);
3262 return CMD_SUCCESS;
3263}
3264
3265DEFUN (no_set_community_delete,
3266 no_set_community_delete_cmd,
3267 "no set comm-list",
3268 NO_STR
3269 SET_STR
3270 "set BGP community list (for deletion)\n")
3271{
3272 return bgp_route_set_delete (vty, vty->index, "comm-list", NULL);
3273}
3274
3275ALIAS (no_set_community_delete,
3276 no_set_community_delete_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003277 "no set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003278 NO_STR
3279 SET_STR
3280 "set BGP community list (for deletion)\n"
3281 "Community-list number (standard)\n"
3282 "Communitly-list number (expanded)\n"
3283 "Community-list name\n"
3284 "Delete matching communities\n")
3285
3286DEFUN (set_ecommunity_rt,
3287 set_ecommunity_rt_cmd,
3288 "set extcommunity rt .ASN:nn_or_IP-address:nn",
3289 SET_STR
3290 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003291 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003292 "VPN extended community\n")
3293{
3294 int ret;
3295 char *str;
3296
3297 str = argv_concat (argv, argc, 0);
3298 ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str);
3299 XFREE (MTYPE_TMP, str);
3300
3301 return ret;
3302}
3303
3304DEFUN (no_set_ecommunity_rt,
3305 no_set_ecommunity_rt_cmd,
3306 "no set extcommunity rt",
3307 NO_STR
3308 SET_STR
3309 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003310 "Route Target extended community\n")
paul718e3742002-12-13 20:15:29 +00003311{
3312 return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL);
3313}
3314
3315ALIAS (no_set_ecommunity_rt,
3316 no_set_ecommunity_rt_val_cmd,
3317 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
3318 NO_STR
3319 SET_STR
3320 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003321 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003322 "VPN extended community\n")
3323
3324DEFUN (set_ecommunity_soo,
3325 set_ecommunity_soo_cmd,
3326 "set extcommunity soo .ASN:nn_or_IP-address:nn",
3327 SET_STR
3328 "BGP extended community attribute\n"
3329 "Site-of-Origin extended community\n"
3330 "VPN extended community\n")
3331{
3332 int ret;
3333 char *str;
3334
3335 str = argv_concat (argv, argc, 0);
3336 ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str);
3337 XFREE (MTYPE_TMP, str);
3338 return ret;
3339}
3340
3341DEFUN (no_set_ecommunity_soo,
3342 no_set_ecommunity_soo_cmd,
3343 "no set extcommunity soo",
3344 NO_STR
3345 SET_STR
3346 "BGP extended community attribute\n"
3347 "Site-of-Origin extended community\n")
3348{
3349 return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL);
3350}
3351
3352ALIAS (no_set_ecommunity_soo,
3353 no_set_ecommunity_soo_val_cmd,
3354 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
3355 NO_STR
3356 SET_STR
3357 "BGP extended community attribute\n"
3358 "Site-of-Origin extended community\n"
3359 "VPN extended community\n")
3360
3361DEFUN (set_origin,
3362 set_origin_cmd,
3363 "set origin (egp|igp|incomplete)",
3364 SET_STR
3365 "BGP origin code\n"
3366 "remote EGP\n"
3367 "local IGP\n"
3368 "unknown heritage\n")
3369{
3370 if (strncmp (argv[0], "igp", 2) == 0)
3371 return bgp_route_set_add (vty, vty->index, "origin", "igp");
3372 if (strncmp (argv[0], "egp", 1) == 0)
3373 return bgp_route_set_add (vty, vty->index, "origin", "egp");
3374 if (strncmp (argv[0], "incomplete", 2) == 0)
3375 return bgp_route_set_add (vty, vty->index, "origin", "incomplete");
3376
3377 return CMD_WARNING;
3378}
3379
3380DEFUN (no_set_origin,
3381 no_set_origin_cmd,
3382 "no set origin",
3383 NO_STR
3384 SET_STR
3385 "BGP origin code\n")
3386{
3387 return bgp_route_set_delete (vty, vty->index, "origin", NULL);
3388}
3389
3390ALIAS (no_set_origin,
3391 no_set_origin_val_cmd,
3392 "no set origin (egp|igp|incomplete)",
3393 NO_STR
3394 SET_STR
3395 "BGP origin code\n"
3396 "remote EGP\n"
3397 "local IGP\n"
3398 "unknown heritage\n")
3399
3400DEFUN (set_atomic_aggregate,
3401 set_atomic_aggregate_cmd,
3402 "set atomic-aggregate",
3403 SET_STR
3404 "BGP atomic aggregate attribute\n" )
3405{
3406 return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL);
3407}
3408
3409DEFUN (no_set_atomic_aggregate,
3410 no_set_atomic_aggregate_cmd,
3411 "no set atomic-aggregate",
3412 NO_STR
3413 SET_STR
3414 "BGP atomic aggregate attribute\n" )
3415{
3416 return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL);
3417}
3418
3419DEFUN (set_aggregator_as,
3420 set_aggregator_as_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003421 "set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003422 SET_STR
3423 "BGP aggregator attribute\n"
3424 "AS number of aggregator\n"
3425 "AS number\n"
3426 "IP address of aggregator\n")
3427{
3428 int ret;
Paul Jakma7aa9dce2014-09-19 14:42:23 +01003429 as_t as __attribute__((unused)); /* dummy for VTY_GET_INTEGER_RANGE */
paul718e3742002-12-13 20:15:29 +00003430 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003431 char *argstr;
3432
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003433 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paulfd79ac92004-10-13 05:06:08 +00003434
paul718e3742002-12-13 20:15:29 +00003435 ret = inet_aton (argv[1], &address);
3436 if (ret == 0)
3437 {
3438 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3439 return CMD_WARNING;
3440 }
3441
3442 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3443 strlen (argv[0]) + strlen (argv[1]) + 2);
3444
3445 sprintf (argstr, "%s %s", argv[0], argv[1]);
3446
3447 ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr);
3448
3449 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3450
3451 return ret;
3452}
3453
3454DEFUN (no_set_aggregator_as,
3455 no_set_aggregator_as_cmd,
3456 "no set aggregator as",
3457 NO_STR
3458 SET_STR
3459 "BGP aggregator attribute\n"
3460 "AS number of aggregator\n")
3461{
3462 int ret;
Paul Jakma7aa9dce2014-09-19 14:42:23 +01003463 as_t as __attribute__((unused)); /* dummy for VTY_GET_INTEGER_RANGE */
paul718e3742002-12-13 20:15:29 +00003464 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003465 char *argstr;
3466
3467 if (argv == 0)
3468 return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL);
3469
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003470 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paul718e3742002-12-13 20:15:29 +00003471
3472 ret = inet_aton (argv[1], &address);
3473 if (ret == 0)
3474 {
3475 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3476 return CMD_WARNING;
3477 }
3478
3479 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3480 strlen (argv[0]) + strlen (argv[1]) + 2);
3481
3482 sprintf (argstr, "%s %s", argv[0], argv[1]);
3483
3484 ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr);
3485
3486 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3487
3488 return ret;
3489}
3490
3491ALIAS (no_set_aggregator_as,
3492 no_set_aggregator_as_val_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003493 "no set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003494 NO_STR
3495 SET_STR
3496 "BGP aggregator attribute\n"
3497 "AS number of aggregator\n"
3498 "AS number\n"
3499 "IP address of aggregator\n")
3500
David Lamparter6b0655a2014-06-04 06:53:35 +02003501
paul718e3742002-12-13 20:15:29 +00003502#ifdef HAVE_IPV6
3503DEFUN (match_ipv6_address,
3504 match_ipv6_address_cmd,
3505 "match ipv6 address WORD",
3506 MATCH_STR
3507 IPV6_STR
3508 "Match IPv6 address of route\n"
3509 "IPv6 access-list name\n")
3510{
3511 return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]);
3512}
3513
3514DEFUN (no_match_ipv6_address,
3515 no_match_ipv6_address_cmd,
3516 "no match ipv6 address WORD",
3517 NO_STR
3518 MATCH_STR
3519 IPV6_STR
3520 "Match IPv6 address of route\n"
3521 "IPv6 access-list name\n")
3522{
3523 return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]);
3524}
3525
3526DEFUN (match_ipv6_next_hop,
3527 match_ipv6_next_hop_cmd,
3528 "match ipv6 next-hop X:X::X:X",
3529 MATCH_STR
3530 IPV6_STR
3531 "Match IPv6 next-hop address of route\n"
3532 "IPv6 address of next hop\n")
3533{
3534 return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]);
3535}
3536
3537DEFUN (no_match_ipv6_next_hop,
3538 no_match_ipv6_next_hop_cmd,
3539 "no match ipv6 next-hop X:X::X:X",
3540 NO_STR
3541 MATCH_STR
3542 IPV6_STR
3543 "Match IPv6 next-hop address of route\n"
3544 "IPv6 address of next hop\n")
3545{
3546 return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
3547}
3548
3549DEFUN (match_ipv6_address_prefix_list,
3550 match_ipv6_address_prefix_list_cmd,
3551 "match ipv6 address prefix-list WORD",
3552 MATCH_STR
3553 IPV6_STR
3554 "Match address of route\n"
3555 "Match entries of prefix-lists\n"
3556 "IP prefix-list name\n")
3557{
3558 return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3559}
3560
3561DEFUN (no_match_ipv6_address_prefix_list,
3562 no_match_ipv6_address_prefix_list_cmd,
3563 "no match ipv6 address prefix-list WORD",
3564 NO_STR
3565 MATCH_STR
3566 IPV6_STR
3567 "Match address of route\n"
3568 "Match entries of prefix-lists\n"
3569 "IP prefix-list name\n")
3570{
3571 return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3572}
3573
3574DEFUN (set_ipv6_nexthop_global,
3575 set_ipv6_nexthop_global_cmd,
3576 "set ipv6 next-hop global X:X::X:X",
3577 SET_STR
3578 IPV6_STR
3579 "IPv6 next-hop address\n"
3580 "IPv6 global address\n"
3581 "IPv6 address of next hop\n")
3582{
3583 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]);
3584}
3585
3586DEFUN (no_set_ipv6_nexthop_global,
3587 no_set_ipv6_nexthop_global_cmd,
3588 "no set ipv6 next-hop global",
3589 NO_STR
3590 SET_STR
3591 IPV6_STR
3592 "IPv6 next-hop address\n"
3593 "IPv6 global address\n")
3594{
3595 if (argc == 0)
3596 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL);
3597
3598 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]);
3599}
3600
3601ALIAS (no_set_ipv6_nexthop_global,
3602 no_set_ipv6_nexthop_global_val_cmd,
3603 "no set ipv6 next-hop global X:X::X:X",
3604 NO_STR
3605 SET_STR
3606 IPV6_STR
3607 "IPv6 next-hop address\n"
3608 "IPv6 global address\n"
3609 "IPv6 address of next hop\n")
3610
3611DEFUN (set_ipv6_nexthop_local,
3612 set_ipv6_nexthop_local_cmd,
3613 "set ipv6 next-hop local X:X::X:X",
3614 SET_STR
3615 IPV6_STR
3616 "IPv6 next-hop address\n"
3617 "IPv6 local address\n"
3618 "IPv6 address of next hop\n")
3619{
3620 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
3621}
3622
3623DEFUN (no_set_ipv6_nexthop_local,
3624 no_set_ipv6_nexthop_local_cmd,
3625 "no set ipv6 next-hop local",
3626 NO_STR
3627 SET_STR
3628 IPV6_STR
3629 "IPv6 next-hop address\n"
3630 "IPv6 local address\n")
3631{
3632 if (argc == 0)
3633 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
3634
3635 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
3636}
3637
3638ALIAS (no_set_ipv6_nexthop_local,
3639 no_set_ipv6_nexthop_local_val_cmd,
3640 "no set ipv6 next-hop local X:X::X:X",
3641 NO_STR
3642 SET_STR
3643 IPV6_STR
3644 "IPv6 next-hop address\n"
3645 "IPv6 local address\n"
3646 "IPv6 address of next hop\n")
3647#endif /* HAVE_IPV6 */
3648
3649DEFUN (set_vpnv4_nexthop,
3650 set_vpnv4_nexthop_cmd,
3651 "set vpnv4 next-hop A.B.C.D",
3652 SET_STR
3653 "VPNv4 information\n"
3654 "VPNv4 next-hop address\n"
3655 "IP address of next hop\n")
3656{
3657 return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]);
3658}
3659
3660DEFUN (no_set_vpnv4_nexthop,
3661 no_set_vpnv4_nexthop_cmd,
3662 "no set vpnv4 next-hop",
3663 NO_STR
3664 SET_STR
3665 "VPNv4 information\n"
3666 "VPNv4 next-hop address\n")
3667{
3668 if (argc == 0)
3669 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL);
3670
3671 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]);
3672}
3673
3674ALIAS (no_set_vpnv4_nexthop,
3675 no_set_vpnv4_nexthop_val_cmd,
3676 "no set vpnv4 next-hop A.B.C.D",
3677 NO_STR
3678 SET_STR
3679 "VPNv4 information\n"
3680 "VPNv4 next-hop address\n"
3681 "IP address of next hop\n")
3682
3683DEFUN (set_originator_id,
3684 set_originator_id_cmd,
3685 "set originator-id A.B.C.D",
3686 SET_STR
3687 "BGP originator ID attribute\n"
3688 "IP address of originator\n")
3689{
3690 return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]);
3691}
3692
3693DEFUN (no_set_originator_id,
3694 no_set_originator_id_cmd,
3695 "no set originator-id",
3696 NO_STR
3697 SET_STR
3698 "BGP originator ID attribute\n")
3699{
3700 if (argc == 0)
3701 return bgp_route_set_delete (vty, vty->index, "originator-id", NULL);
3702
3703 return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]);
3704}
3705
3706ALIAS (no_set_originator_id,
3707 no_set_originator_id_val_cmd,
3708 "no set originator-id A.B.C.D",
3709 NO_STR
3710 SET_STR
3711 "BGP originator ID attribute\n"
3712 "IP address of originator\n")
3713
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003714DEFUN_DEPRECATED (set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003715 set_pathlimit_ttl_cmd,
3716 "set pathlimit ttl <1-255>",
3717 SET_STR
3718 "BGP AS-Pathlimit attribute\n"
3719 "Set AS-Path Hop-count TTL\n")
3720{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003721 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003722}
3723
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003724DEFUN_DEPRECATED (no_set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003725 no_set_pathlimit_ttl_cmd,
3726 "no set pathlimit ttl",
3727 NO_STR
3728 SET_STR
3729 "BGP AS-Pathlimit attribute\n"
3730 "Set AS-Path Hop-count TTL\n")
3731{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003732 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003733}
3734
3735ALIAS (no_set_pathlimit_ttl,
3736 no_set_pathlimit_ttl_val_cmd,
3737 "no set pathlimit ttl <1-255>",
3738 NO_STR
3739 MATCH_STR
3740 "BGP AS-Pathlimit attribute\n"
3741 "Set AS-Path Hop-count TTL\n")
3742
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003743DEFUN_DEPRECATED (match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003744 match_pathlimit_as_cmd,
3745 "match pathlimit as <1-65535>",
3746 MATCH_STR
3747 "BGP AS-Pathlimit attribute\n"
3748 "Match Pathlimit AS number\n")
3749{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003750 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003751}
3752
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003753DEFUN_DEPRECATED (no_match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003754 no_match_pathlimit_as_cmd,
3755 "no match pathlimit as",
3756 NO_STR
3757 MATCH_STR
3758 "BGP AS-Pathlimit attribute\n"
3759 "Match Pathlimit AS number\n")
3760{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003761 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003762}
3763
3764ALIAS (no_match_pathlimit_as,
3765 no_match_pathlimit_as_val_cmd,
3766 "no match pathlimit as <1-65535>",
3767 NO_STR
3768 MATCH_STR
3769 "BGP AS-Pathlimit attribute\n"
3770 "Match Pathlimit ASN\n")
3771
David Lamparter6b0655a2014-06-04 06:53:35 +02003772
paul718e3742002-12-13 20:15:29 +00003773/* Initialization of route map. */
3774void
paul94f2b392005-06-28 12:44:16 +00003775bgp_route_map_init (void)
paul718e3742002-12-13 20:15:29 +00003776{
3777 route_map_init ();
3778 route_map_init_vty ();
3779 route_map_add_hook (bgp_route_map_update);
3780 route_map_delete_hook (bgp_route_map_update);
3781
paulfee0f4c2004-09-13 05:12:46 +00003782 route_map_install_match (&route_match_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003783 route_map_install_match (&route_match_ip_address_cmd);
3784 route_map_install_match (&route_match_ip_next_hop_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003785 route_map_install_match (&route_match_ip_route_source_cmd);
paul718e3742002-12-13 20:15:29 +00003786 route_map_install_match (&route_match_ip_address_prefix_list_cmd);
3787 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003788 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +00003789 route_map_install_match (&route_match_aspath_cmd);
3790 route_map_install_match (&route_match_community_cmd);
paul73ffb252003-04-19 15:49:49 +00003791 route_map_install_match (&route_match_ecommunity_cmd);
paul718e3742002-12-13 20:15:29 +00003792 route_map_install_match (&route_match_metric_cmd);
3793 route_map_install_match (&route_match_origin_cmd);
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +04003794 route_map_install_match (&route_match_probability_cmd);
paul718e3742002-12-13 20:15:29 +00003795
3796 route_map_install_set (&route_set_ip_nexthop_cmd);
3797 route_map_install_set (&route_set_local_pref_cmd);
3798 route_map_install_set (&route_set_weight_cmd);
3799 route_map_install_set (&route_set_metric_cmd);
3800 route_map_install_set (&route_set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003801 route_map_install_set (&route_set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003802 route_map_install_set (&route_set_origin_cmd);
3803 route_map_install_set (&route_set_atomic_aggregate_cmd);
3804 route_map_install_set (&route_set_aggregator_as_cmd);
3805 route_map_install_set (&route_set_community_cmd);
3806 route_map_install_set (&route_set_community_delete_cmd);
3807 route_map_install_set (&route_set_vpnv4_nexthop_cmd);
3808 route_map_install_set (&route_set_originator_id_cmd);
3809 route_map_install_set (&route_set_ecommunity_rt_cmd);
3810 route_map_install_set (&route_set_ecommunity_soo_cmd);
3811
paulfee0f4c2004-09-13 05:12:46 +00003812 install_element (RMAP_NODE, &match_peer_cmd);
3813 install_element (RMAP_NODE, &match_peer_local_cmd);
3814 install_element (RMAP_NODE, &no_match_peer_cmd);
3815 install_element (RMAP_NODE, &no_match_peer_val_cmd);
3816 install_element (RMAP_NODE, &no_match_peer_local_cmd);
paul718e3742002-12-13 20:15:29 +00003817 install_element (RMAP_NODE, &match_ip_address_cmd);
3818 install_element (RMAP_NODE, &no_match_ip_address_cmd);
3819 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
3820 install_element (RMAP_NODE, &match_ip_next_hop_cmd);
3821 install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
3822 install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003823 install_element (RMAP_NODE, &match_ip_route_source_cmd);
3824 install_element (RMAP_NODE, &no_match_ip_route_source_cmd);
3825 install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd);
paul718e3742002-12-13 20:15:29 +00003826 install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
3827 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
3828 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
3829 install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
3830 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
3831 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003832 install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
3833 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
3834 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd);
paul718e3742002-12-13 20:15:29 +00003835
3836 install_element (RMAP_NODE, &match_aspath_cmd);
3837 install_element (RMAP_NODE, &no_match_aspath_cmd);
3838 install_element (RMAP_NODE, &no_match_aspath_val_cmd);
3839 install_element (RMAP_NODE, &match_metric_cmd);
3840 install_element (RMAP_NODE, &no_match_metric_cmd);
3841 install_element (RMAP_NODE, &no_match_metric_val_cmd);
3842 install_element (RMAP_NODE, &match_community_cmd);
3843 install_element (RMAP_NODE, &match_community_exact_cmd);
3844 install_element (RMAP_NODE, &no_match_community_cmd);
3845 install_element (RMAP_NODE, &no_match_community_val_cmd);
3846 install_element (RMAP_NODE, &no_match_community_exact_cmd);
paul73ffb252003-04-19 15:49:49 +00003847 install_element (RMAP_NODE, &match_ecommunity_cmd);
3848 install_element (RMAP_NODE, &no_match_ecommunity_cmd);
3849 install_element (RMAP_NODE, &no_match_ecommunity_val_cmd);
paul718e3742002-12-13 20:15:29 +00003850 install_element (RMAP_NODE, &match_origin_cmd);
3851 install_element (RMAP_NODE, &no_match_origin_cmd);
3852 install_element (RMAP_NODE, &no_match_origin_val_cmd);
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +04003853 install_element (RMAP_NODE, &match_probability_cmd);
3854 install_element (RMAP_NODE, &no_match_probability_cmd);
3855 install_element (RMAP_NODE, &no_match_probability_val_cmd);
paul718e3742002-12-13 20:15:29 +00003856
3857 install_element (RMAP_NODE, &set_ip_nexthop_cmd);
paulaf5cd0a2003-11-02 07:24:40 +00003858 install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003859 install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
3860 install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
3861 install_element (RMAP_NODE, &set_local_pref_cmd);
3862 install_element (RMAP_NODE, &no_set_local_pref_cmd);
3863 install_element (RMAP_NODE, &no_set_local_pref_val_cmd);
3864 install_element (RMAP_NODE, &set_weight_cmd);
3865 install_element (RMAP_NODE, &no_set_weight_cmd);
3866 install_element (RMAP_NODE, &no_set_weight_val_cmd);
3867 install_element (RMAP_NODE, &set_metric_cmd);
paul73ffb252003-04-19 15:49:49 +00003868 install_element (RMAP_NODE, &set_metric_addsub_cmd);
paul718e3742002-12-13 20:15:29 +00003869 install_element (RMAP_NODE, &no_set_metric_cmd);
3870 install_element (RMAP_NODE, &no_set_metric_val_cmd);
3871 install_element (RMAP_NODE, &set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003872 install_element (RMAP_NODE, &set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003873 install_element (RMAP_NODE, &no_set_aspath_prepend_cmd);
3874 install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003875 install_element (RMAP_NODE, &no_set_aspath_exclude_cmd);
3876 install_element (RMAP_NODE, &no_set_aspath_exclude_val_cmd);
paul718e3742002-12-13 20:15:29 +00003877 install_element (RMAP_NODE, &set_origin_cmd);
3878 install_element (RMAP_NODE, &no_set_origin_cmd);
3879 install_element (RMAP_NODE, &no_set_origin_val_cmd);
3880 install_element (RMAP_NODE, &set_atomic_aggregate_cmd);
3881 install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd);
3882 install_element (RMAP_NODE, &set_aggregator_as_cmd);
3883 install_element (RMAP_NODE, &no_set_aggregator_as_cmd);
3884 install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd);
3885 install_element (RMAP_NODE, &set_community_cmd);
3886 install_element (RMAP_NODE, &set_community_none_cmd);
3887 install_element (RMAP_NODE, &no_set_community_cmd);
3888 install_element (RMAP_NODE, &no_set_community_val_cmd);
3889 install_element (RMAP_NODE, &no_set_community_none_cmd);
3890 install_element (RMAP_NODE, &set_community_delete_cmd);
3891 install_element (RMAP_NODE, &no_set_community_delete_cmd);
3892 install_element (RMAP_NODE, &no_set_community_delete_val_cmd);
3893 install_element (RMAP_NODE, &set_ecommunity_rt_cmd);
3894 install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd);
3895 install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd);
3896 install_element (RMAP_NODE, &set_ecommunity_soo_cmd);
3897 install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd);
3898 install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd);
3899 install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd);
3900 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd);
3901 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd);
3902 install_element (RMAP_NODE, &set_originator_id_cmd);
3903 install_element (RMAP_NODE, &no_set_originator_id_cmd);
3904 install_element (RMAP_NODE, &no_set_originator_id_val_cmd);
3905
3906#ifdef HAVE_IPV6
3907 route_map_install_match (&route_match_ipv6_address_cmd);
3908 route_map_install_match (&route_match_ipv6_next_hop_cmd);
3909 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd);
3910 route_map_install_set (&route_set_ipv6_nexthop_global_cmd);
3911 route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
Paul Jakma41367172007-08-06 15:24:51 +00003912
paul718e3742002-12-13 20:15:29 +00003913 install_element (RMAP_NODE, &match_ipv6_address_cmd);
3914 install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
3915 install_element (RMAP_NODE, &match_ipv6_next_hop_cmd);
3916 install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd);
3917 install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
3918 install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
3919 install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd);
3920 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
3921 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd);
3922 install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
3923 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
3924 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
3925#endif /* HAVE_IPV6 */
Paul Jakma41367172007-08-06 15:24:51 +00003926
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003927 /* AS-Pathlimit: functionality removed, commands kept for
3928 * compatibility.
3929 */
Paul Jakma41367172007-08-06 15:24:51 +00003930 install_element (RMAP_NODE, &set_pathlimit_ttl_cmd);
3931 install_element (RMAP_NODE, &no_set_pathlimit_ttl_cmd);
3932 install_element (RMAP_NODE, &no_set_pathlimit_ttl_val_cmd);
3933 install_element (RMAP_NODE, &match_pathlimit_as_cmd);
3934 install_element (RMAP_NODE, &no_match_pathlimit_as_cmd);
3935 install_element (RMAP_NODE, &no_match_pathlimit_as_val_cmd);
paul718e3742002-12-13 20:15:29 +00003936}