blob: eb5e80f83e9c73d81b6de8baf8fb7e2bf64a36aa [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Route map function of bgpd.
2 Copyright (C) 1998, 1999 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "filter.h"
25#include "routemap.h"
26#include "command.h"
27#include "linklist.h"
28#include "plist.h"
29#include "memory.h"
30#include "log.h"
Jeremy Jackson25f45882009-01-12 16:06:12 -050031#ifdef HAVE_LIBPCREPOSIX
32# include <pcreposix.h>
paul718e3742002-12-13 20:15:29 +000033#else
Jeremy Jackson25f45882009-01-12 16:06:12 -050034# ifdef HAVE_GNU_REGEX
35# include <regex.h>
36# else
37# include "regex-gnu.h"
38# endif /* HAVE_GNU_REGEX */
39#endif /* HAVE_LIBPCREPOSIX */
paul718e3742002-12-13 20:15:29 +000040#include "buffer.h"
41#include "sockunion.h"
42
43#include "bgpd/bgpd.h"
44#include "bgpd/bgp_table.h"
45#include "bgpd/bgp_attr.h"
46#include "bgpd/bgp_aspath.h"
47#include "bgpd/bgp_route.h"
48#include "bgpd/bgp_regex.h"
49#include "bgpd/bgp_community.h"
50#include "bgpd/bgp_clist.h"
51#include "bgpd/bgp_filter.h"
52#include "bgpd/bgp_mplsvpn.h"
53#include "bgpd/bgp_ecommunity.h"
Paul Jakma320da872008-07-02 13:40:33 +000054#include "bgpd/bgp_vty.h"
paul718e3742002-12-13 20:15:29 +000055
56/* Memo of route-map commands.
57
58o Cisco route-map
59
60 match as-path : Done
61 community : Done
62 interface : Not yet
63 ip address : Done
64 ip next-hop : Done
hassoc1643bb2005-02-02 16:43:17 +000065 ip route-source : Done
paul718e3742002-12-13 20:15:29 +000066 ip prefix-list : Done
67 ipv6 address : Done
68 ipv6 next-hop : Done
69 ipv6 route-source: (This will not be implemented by bgpd)
70 ipv6 prefix-list : Done
71 length : (This will not be implemented by bgpd)
72 metric : Done
73 route-type : (This will not be implemented by bgpd)
74 tag : (This will not be implemented by bgpd)
75
76 set as-path prepend : Done
77 as-path tag : Not yet
78 automatic-tag : (This will not be implemented by bgpd)
79 community : Done
80 comm-list : Not yet
81 dampning : Not yet
82 default : (This will not be implemented by bgpd)
83 interface : (This will not be implemented by bgpd)
84 ip default : (This will not be implemented by bgpd)
85 ip next-hop : Done
86 ip precedence : (This will not be implemented by bgpd)
87 ip tos : (This will not be implemented by bgpd)
88 level : (This will not be implemented by bgpd)
89 local-preference : Done
90 metric : Done
91 metric-type : Not yet
92 origin : Done
93 tag : (This will not be implemented by bgpd)
94 weight : Done
95
96o Local extention
97
98 set ipv6 next-hop global: Done
99 set ipv6 next-hop local : Done
Denis Ovsienko841f7a52008-04-10 11:47:45 +0000100 set as-path exclude : Done
paul718e3742002-12-13 20:15:29 +0000101
102*/
David Lamparter6b0655a2014-06-04 06:53:35 +0200103
paulfee0f4c2004-09-13 05:12:46 +0000104 /* 'match peer (A.B.C.D|X:X::X:X)' */
105
106/* Compares the peer specified in the 'match peer' clause with the peer
107 received in bgp_info->peer. If it is the same, or if the peer structure
108 received is a peer_group containing it, returns RMAP_MATCH. */
paul94f2b392005-06-28 12:44:16 +0000109static route_map_result_t
paulfee0f4c2004-09-13 05:12:46 +0000110route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type,
111 void *object)
112{
113 union sockunion *su;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200114 union sockunion su_def = { .sa.sa_family = AF_INET,
115 .sin.sin_addr.s_addr = INADDR_ANY };
paulfee0f4c2004-09-13 05:12:46 +0000116 struct peer_group *group;
117 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +0000118 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +0000119
120 if (type == RMAP_BGP)
121 {
122 su = rule;
123 peer = ((struct bgp_info *) object)->peer;
124
125 if ( ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT) &&
126 ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_EXPORT) )
127 return RMAP_NOMATCH;
128
129 /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
130 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200131 if (sockunion_same (su, &su_def))
paulfee0f4c2004-09-13 05:12:46 +0000132 {
paul22db9de2005-05-19 01:50:11 +0000133 int ret;
paulfee0f4c2004-09-13 05:12:46 +0000134 if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) ||
135 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE) ||
136 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_DEFAULT))
paul22db9de2005-05-19 01:50:11 +0000137 ret = RMAP_MATCH;
paulfee0f4c2004-09-13 05:12:46 +0000138 else
paul22db9de2005-05-19 01:50:11 +0000139 ret = RMAP_NOMATCH;
paul22db9de2005-05-19 01:50:11 +0000140 return ret;
paulfee0f4c2004-09-13 05:12:46 +0000141 }
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +0200142
paulfee0f4c2004-09-13 05:12:46 +0000143 if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
144 {
145 if (sockunion_same (su, &peer->su))
146 return RMAP_MATCH;
147
148 return RMAP_NOMATCH;
149 }
150 else
151 {
152 group = peer->group;
paul1eb8ef22005-04-07 07:30:20 +0000153 for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
paulfee0f4c2004-09-13 05:12:46 +0000154 {
155 if (sockunion_same (su, &peer->su))
156 return RMAP_MATCH;
paulfee0f4c2004-09-13 05:12:46 +0000157 }
Paul Jakma30a22312008-08-15 14:05:22 +0100158 return RMAP_NOMATCH;
paulfee0f4c2004-09-13 05:12:46 +0000159 }
160 }
161 return RMAP_NOMATCH;
162}
163
paul94f2b392005-06-28 12:44:16 +0000164static void *
paulfd79ac92004-10-13 05:06:08 +0000165route_match_peer_compile (const char *arg)
paulfee0f4c2004-09-13 05:12:46 +0000166{
167 union sockunion *su;
168 int ret;
169
170 su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion));
171
Jorge Boncompte [DTI2]4fe080d2012-04-13 13:46:08 +0200172 ret = str2sockunion (strcmp(arg, "local") ? arg : "0.0.0.0", su);
paulfee0f4c2004-09-13 05:12:46 +0000173 if (ret < 0) {
174 XFREE (MTYPE_ROUTE_MAP_COMPILED, su);
175 return NULL;
176 }
177
178 return su;
179}
180
181/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000182static void
paulfee0f4c2004-09-13 05:12:46 +0000183route_match_peer_free (void *rule)
184{
185 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
186}
187
188/* Route map commands for ip address matching. */
189struct route_map_rule_cmd route_match_peer_cmd =
190{
191 "peer",
192 route_match_peer,
193 route_match_peer_compile,
194 route_match_peer_free
195};
196
paul718e3742002-12-13 20:15:29 +0000197/* `match ip address IP_ACCESS_LIST' */
198
199/* Match function should return 1 if match is success else return
200 zero. */
paul94f2b392005-06-28 12:44:16 +0000201static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000202route_match_ip_address (void *rule, struct prefix *prefix,
203 route_map_object_t type, void *object)
204{
205 struct access_list *alist;
206 /* struct prefix_ipv4 match; */
207
208 if (type == RMAP_BGP)
209 {
210 alist = access_list_lookup (AFI_IP, (char *) rule);
211 if (alist == NULL)
212 return RMAP_NOMATCH;
213
214 return (access_list_apply (alist, prefix) == FILTER_DENY ?
215 RMAP_NOMATCH : RMAP_MATCH);
216 }
217 return RMAP_NOMATCH;
218}
219
220/* Route map `ip address' match statement. `arg' should be
221 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000222static void *
paulfd79ac92004-10-13 05:06:08 +0000223route_match_ip_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000224{
225 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
226}
227
228/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000229static void
paul718e3742002-12-13 20:15:29 +0000230route_match_ip_address_free (void *rule)
231{
232 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
233}
234
235/* Route map commands for ip address matching. */
236struct route_map_rule_cmd route_match_ip_address_cmd =
237{
238 "ip address",
239 route_match_ip_address,
240 route_match_ip_address_compile,
241 route_match_ip_address_free
242};
David Lamparter6b0655a2014-06-04 06:53:35 +0200243
paul718e3742002-12-13 20:15:29 +0000244/* `match ip next-hop IP_ADDRESS' */
245
246/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000247static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000248route_match_ip_next_hop (void *rule, struct prefix *prefix,
249 route_map_object_t type, void *object)
250{
251 struct access_list *alist;
252 struct bgp_info *bgp_info;
253 struct prefix_ipv4 p;
254
255 if (type == RMAP_BGP)
256 {
257 bgp_info = object;
258 p.family = AF_INET;
259 p.prefix = bgp_info->attr->nexthop;
260 p.prefixlen = IPV4_MAX_BITLEN;
261
262 alist = access_list_lookup (AFI_IP, (char *) rule);
263 if (alist == NULL)
264 return RMAP_NOMATCH;
265
266 return (access_list_apply (alist, &p) == FILTER_DENY ?
267 RMAP_NOMATCH : RMAP_MATCH);
268 }
269 return RMAP_NOMATCH;
270}
271
272/* Route map `ip next-hop' match statement. `arg' is
273 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000274static void *
paulfd79ac92004-10-13 05:06:08 +0000275route_match_ip_next_hop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000276{
277 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
278}
279
280/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000281static void
paul718e3742002-12-13 20:15:29 +0000282route_match_ip_next_hop_free (void *rule)
283{
284 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
285}
286
287/* Route map commands for ip next-hop matching. */
288struct route_map_rule_cmd route_match_ip_next_hop_cmd =
289{
290 "ip next-hop",
291 route_match_ip_next_hop,
292 route_match_ip_next_hop_compile,
293 route_match_ip_next_hop_free
294};
David Lamparter6b0655a2014-06-04 06:53:35 +0200295
hassoc1643bb2005-02-02 16:43:17 +0000296/* `match ip route-source ACCESS-LIST' */
297
298/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000299static route_map_result_t
hassoc1643bb2005-02-02 16:43:17 +0000300route_match_ip_route_source (void *rule, struct prefix *prefix,
301 route_map_object_t type, void *object)
302{
303 struct access_list *alist;
304 struct bgp_info *bgp_info;
305 struct peer *peer;
306 struct prefix_ipv4 p;
307
308 if (type == RMAP_BGP)
309 {
310 bgp_info = object;
311 peer = bgp_info->peer;
312
313 if (! peer || sockunion_family (&peer->su) != AF_INET)
314 return RMAP_NOMATCH;
315
316 p.family = AF_INET;
317 p.prefix = peer->su.sin.sin_addr;
318 p.prefixlen = IPV4_MAX_BITLEN;
319
320 alist = access_list_lookup (AFI_IP, (char *) rule);
321 if (alist == NULL)
322 return RMAP_NOMATCH;
323
324 return (access_list_apply (alist, &p) == FILTER_DENY ?
325 RMAP_NOMATCH : RMAP_MATCH);
326 }
327 return RMAP_NOMATCH;
328}
329
330/* Route map `ip route-source' match statement. `arg' is
331 access-list name. */
paul94f2b392005-06-28 12:44:16 +0000332static void *
hassoc1643bb2005-02-02 16:43:17 +0000333route_match_ip_route_source_compile (const char *arg)
334{
335 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
336}
337
338/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000339static void
hassoc1643bb2005-02-02 16:43:17 +0000340route_match_ip_route_source_free (void *rule)
341{
342 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
343}
344
345/* Route map commands for ip route-source matching. */
346struct route_map_rule_cmd route_match_ip_route_source_cmd =
347{
348 "ip route-source",
349 route_match_ip_route_source,
350 route_match_ip_route_source_compile,
351 route_match_ip_route_source_free
352};
David Lamparter6b0655a2014-06-04 06:53:35 +0200353
paul718e3742002-12-13 20:15:29 +0000354/* `match ip address prefix-list PREFIX_LIST' */
355
paul94f2b392005-06-28 12:44:16 +0000356static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000357route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
358 route_map_object_t type, void *object)
359{
360 struct prefix_list *plist;
361
362 if (type == RMAP_BGP)
363 {
364 plist = prefix_list_lookup (AFI_IP, (char *) rule);
365 if (plist == NULL)
366 return RMAP_NOMATCH;
367
368 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
369 RMAP_NOMATCH : RMAP_MATCH);
370 }
371 return RMAP_NOMATCH;
372}
373
paul94f2b392005-06-28 12:44:16 +0000374static void *
paulfd79ac92004-10-13 05:06:08 +0000375route_match_ip_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000376{
377 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
378}
379
paul94f2b392005-06-28 12:44:16 +0000380static void
paul718e3742002-12-13 20:15:29 +0000381route_match_ip_address_prefix_list_free (void *rule)
382{
383 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
384}
385
386struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
387{
388 "ip address prefix-list",
389 route_match_ip_address_prefix_list,
390 route_match_ip_address_prefix_list_compile,
391 route_match_ip_address_prefix_list_free
392};
David Lamparter6b0655a2014-06-04 06:53:35 +0200393
paul718e3742002-12-13 20:15:29 +0000394/* `match ip next-hop prefix-list PREFIX_LIST' */
395
paul94f2b392005-06-28 12:44:16 +0000396static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000397route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
398 route_map_object_t type, void *object)
399{
400 struct prefix_list *plist;
401 struct bgp_info *bgp_info;
402 struct prefix_ipv4 p;
403
404 if (type == RMAP_BGP)
405 {
406 bgp_info = object;
407 p.family = AF_INET;
408 p.prefix = bgp_info->attr->nexthop;
409 p.prefixlen = IPV4_MAX_BITLEN;
410
411 plist = prefix_list_lookup (AFI_IP, (char *) rule);
412 if (plist == NULL)
413 return RMAP_NOMATCH;
414
415 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
416 RMAP_NOMATCH : RMAP_MATCH);
417 }
418 return RMAP_NOMATCH;
419}
420
paul94f2b392005-06-28 12:44:16 +0000421static void *
paulfd79ac92004-10-13 05:06:08 +0000422route_match_ip_next_hop_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000423{
424 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
425}
426
paul94f2b392005-06-28 12:44:16 +0000427static void
paul718e3742002-12-13 20:15:29 +0000428route_match_ip_next_hop_prefix_list_free (void *rule)
429{
430 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
431}
432
433struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
434{
435 "ip next-hop prefix-list",
436 route_match_ip_next_hop_prefix_list,
437 route_match_ip_next_hop_prefix_list_compile,
438 route_match_ip_next_hop_prefix_list_free
439};
David Lamparter6b0655a2014-06-04 06:53:35 +0200440
hassoc1643bb2005-02-02 16:43:17 +0000441/* `match ip route-source prefix-list PREFIX_LIST' */
442
paul94f2b392005-06-28 12:44:16 +0000443static route_map_result_t
hassoc1643bb2005-02-02 16:43:17 +0000444route_match_ip_route_source_prefix_list (void *rule, struct prefix *prefix,
445 route_map_object_t type, void *object)
446{
447 struct prefix_list *plist;
448 struct bgp_info *bgp_info;
449 struct peer *peer;
450 struct prefix_ipv4 p;
451
452 if (type == RMAP_BGP)
453 {
454 bgp_info = object;
455 peer = bgp_info->peer;
456
457 if (! peer || sockunion_family (&peer->su) != AF_INET)
458 return RMAP_NOMATCH;
459
460 p.family = AF_INET;
461 p.prefix = peer->su.sin.sin_addr;
462 p.prefixlen = IPV4_MAX_BITLEN;
463
464 plist = prefix_list_lookup (AFI_IP, (char *) rule);
465 if (plist == NULL)
466 return RMAP_NOMATCH;
467
468 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
469 RMAP_NOMATCH : RMAP_MATCH);
470 }
471 return RMAP_NOMATCH;
472}
473
paul94f2b392005-06-28 12:44:16 +0000474static void *
hassoc1643bb2005-02-02 16:43:17 +0000475route_match_ip_route_source_prefix_list_compile (const char *arg)
476{
477 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
478}
479
paul94f2b392005-06-28 12:44:16 +0000480static void
hassoc1643bb2005-02-02 16:43:17 +0000481route_match_ip_route_source_prefix_list_free (void *rule)
482{
483 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
484}
485
486struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd =
487{
488 "ip route-source prefix-list",
489 route_match_ip_route_source_prefix_list,
490 route_match_ip_route_source_prefix_list_compile,
491 route_match_ip_route_source_prefix_list_free
492};
David Lamparter6b0655a2014-06-04 06:53:35 +0200493
paul718e3742002-12-13 20:15:29 +0000494/* `match metric METRIC' */
495
496/* Match function return 1 if match is success else return zero. */
paul94f2b392005-06-28 12:44:16 +0000497static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000498route_match_metric (void *rule, struct prefix *prefix,
499 route_map_object_t type, void *object)
500{
501 u_int32_t *med;
502 struct bgp_info *bgp_info;
503
504 if (type == RMAP_BGP)
505 {
506 med = rule;
507 bgp_info = object;
508
509 if (bgp_info->attr->med == *med)
510 return RMAP_MATCH;
511 else
512 return RMAP_NOMATCH;
513 }
514 return RMAP_NOMATCH;
515}
516
517/* Route map `match metric' match statement. `arg' is MED value */
paul94f2b392005-06-28 12:44:16 +0000518static void *
paulfd79ac92004-10-13 05:06:08 +0000519route_match_metric_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000520{
521 u_int32_t *med;
522 char *endptr = NULL;
paul3b424972003-10-13 09:47:32 +0000523 unsigned long tmpval;
paul718e3742002-12-13 20:15:29 +0000524
Ulrich Weber664711c2011-12-21 02:24:11 +0400525 /* Metric value shoud be integer. */
526 if (! all_digit (arg))
527 return NULL;
528
529 errno = 0;
paul3b424972003-10-13 09:47:32 +0000530 tmpval = strtoul (arg, &endptr, 10);
Ulrich Weber664711c2011-12-21 02:24:11 +0400531 if (*endptr != '\0' || errno || tmpval > UINT32_MAX)
paul3b424972003-10-13 09:47:32 +0000532 return NULL;
paulfd79ac92004-10-13 05:06:08 +0000533
paul718e3742002-12-13 20:15:29 +0000534 med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
paulfd79ac92004-10-13 05:06:08 +0000535
536 if (!med)
537 return med;
538
paul3b424972003-10-13 09:47:32 +0000539 *med = tmpval;
paul718e3742002-12-13 20:15:29 +0000540 return med;
541}
542
543/* Free route map's compiled `match metric' value. */
paul94f2b392005-06-28 12:44:16 +0000544static void
paul718e3742002-12-13 20:15:29 +0000545route_match_metric_free (void *rule)
546{
547 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
548}
549
550/* Route map commands for metric matching. */
551struct route_map_rule_cmd route_match_metric_cmd =
552{
553 "metric",
554 route_match_metric,
555 route_match_metric_compile,
556 route_match_metric_free
557};
David Lamparter6b0655a2014-06-04 06:53:35 +0200558
paul718e3742002-12-13 20:15:29 +0000559/* `match as-path ASPATH' */
560
561/* Match function for as-path match. I assume given object is */
paul94f2b392005-06-28 12:44:16 +0000562static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000563route_match_aspath (void *rule, struct prefix *prefix,
564 route_map_object_t type, void *object)
565{
566
567 struct as_list *as_list;
568 struct bgp_info *bgp_info;
569
570 if (type == RMAP_BGP)
571 {
572 as_list = as_list_lookup ((char *) rule);
573 if (as_list == NULL)
574 return RMAP_NOMATCH;
575
576 bgp_info = object;
577
578 /* Perform match. */
579 return ((as_list_apply (as_list, bgp_info->attr->aspath) == AS_FILTER_DENY) ? RMAP_NOMATCH : RMAP_MATCH);
580 }
581 return RMAP_NOMATCH;
582}
583
584/* Compile function for as-path match. */
paul94f2b392005-06-28 12:44:16 +0000585static void *
paulfd79ac92004-10-13 05:06:08 +0000586route_match_aspath_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000587{
588 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
589}
590
591/* Compile function for as-path match. */
paul94f2b392005-06-28 12:44:16 +0000592static void
paul718e3742002-12-13 20:15:29 +0000593route_match_aspath_free (void *rule)
594{
595 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
596}
597
598/* Route map commands for aspath matching. */
599struct route_map_rule_cmd route_match_aspath_cmd =
600{
601 "as-path",
602 route_match_aspath,
603 route_match_aspath_compile,
604 route_match_aspath_free
605};
David Lamparter6b0655a2014-06-04 06:53:35 +0200606
paul718e3742002-12-13 20:15:29 +0000607/* `match community COMMUNIY' */
608struct rmap_community
609{
610 char *name;
611 int exact;
612};
613
614/* Match function for community match. */
paul94f2b392005-06-28 12:44:16 +0000615static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000616route_match_community (void *rule, struct prefix *prefix,
617 route_map_object_t type, void *object)
618{
619 struct community_list *list;
620 struct bgp_info *bgp_info;
621 struct rmap_community *rcom;
622
623 if (type == RMAP_BGP)
624 {
625 bgp_info = object;
626 rcom = rule;
627
hassofee6e4e2005-02-02 16:29:31 +0000628 list = community_list_lookup (bgp_clist, rcom->name, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +0000629 if (! list)
630 return RMAP_NOMATCH;
631
632 if (rcom->exact)
633 {
634 if (community_list_exact_match (bgp_info->attr->community, list))
635 return RMAP_MATCH;
636 }
637 else
638 {
639 if (community_list_match (bgp_info->attr->community, list))
640 return RMAP_MATCH;
641 }
642 }
643 return RMAP_NOMATCH;
644}
645
646/* Compile function for community match. */
paul94f2b392005-06-28 12:44:16 +0000647static void *
paulfd79ac92004-10-13 05:06:08 +0000648route_match_community_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000649{
650 struct rmap_community *rcom;
651 int len;
652 char *p;
653
654 rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community));
655
656 p = strchr (arg, ' ');
657 if (p)
658 {
659 len = p - arg;
660 rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
661 memcpy (rcom->name, arg, len);
662 rcom->exact = 1;
663 }
664 else
665 {
666 rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
667 rcom->exact = 0;
668 }
669 return rcom;
670}
671
672/* Compile function for community match. */
paul94f2b392005-06-28 12:44:16 +0000673static void
paul718e3742002-12-13 20:15:29 +0000674route_match_community_free (void *rule)
675{
676 struct rmap_community *rcom = rule;
677
678 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name);
679 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom);
680}
681
682/* Route map commands for community matching. */
683struct route_map_rule_cmd route_match_community_cmd =
684{
685 "community",
686 route_match_community,
687 route_match_community_compile,
688 route_match_community_free
689};
David Lamparter6b0655a2014-06-04 06:53:35 +0200690
paul73ffb252003-04-19 15:49:49 +0000691/* Match function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000692static route_map_result_t
paul73ffb252003-04-19 15:49:49 +0000693route_match_ecommunity (void *rule, struct prefix *prefix,
694 route_map_object_t type, void *object)
695{
696 struct community_list *list;
697 struct bgp_info *bgp_info;
698
699 if (type == RMAP_BGP)
700 {
701 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +0000702
703 if (!bgp_info->attr->extra)
704 return RMAP_NOMATCH;
705
paul73ffb252003-04-19 15:49:49 +0000706 list = community_list_lookup (bgp_clist, (char *) rule,
hassofee6e4e2005-02-02 16:29:31 +0000707 EXTCOMMUNITY_LIST_MASTER);
paul73ffb252003-04-19 15:49:49 +0000708 if (! list)
709 return RMAP_NOMATCH;
710
Paul Jakmafb982c22007-05-04 20:15:47 +0000711 if (ecommunity_list_match (bgp_info->attr->extra->ecommunity, list))
paul73ffb252003-04-19 15:49:49 +0000712 return RMAP_MATCH;
713 }
714 return RMAP_NOMATCH;
715}
716
717/* Compile function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000718static void *
paulfd79ac92004-10-13 05:06:08 +0000719route_match_ecommunity_compile (const char *arg)
paul73ffb252003-04-19 15:49:49 +0000720{
721 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
722}
723
724/* Compile function for extcommunity match. */
paul94f2b392005-06-28 12:44:16 +0000725static void
paul73ffb252003-04-19 15:49:49 +0000726route_match_ecommunity_free (void *rule)
727{
728 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
729}
730
731/* Route map commands for community matching. */
732struct route_map_rule_cmd route_match_ecommunity_cmd =
733{
734 "extcommunity",
735 route_match_ecommunity,
736 route_match_ecommunity_compile,
737 route_match_ecommunity_free
738};
David Lamparter6b0655a2014-06-04 06:53:35 +0200739
paul718e3742002-12-13 20:15:29 +0000740/* `match nlri` and `set nlri` are replaced by `address-family ipv4`
741 and `address-family vpnv4'. */
David Lamparter6b0655a2014-06-04 06:53:35 +0200742
paul718e3742002-12-13 20:15:29 +0000743/* `match origin' */
paul94f2b392005-06-28 12:44:16 +0000744static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000745route_match_origin (void *rule, struct prefix *prefix,
746 route_map_object_t type, void *object)
747{
748 u_char *origin;
749 struct bgp_info *bgp_info;
750
751 if (type == RMAP_BGP)
752 {
753 origin = rule;
754 bgp_info = object;
755
756 if (bgp_info->attr->origin == *origin)
757 return RMAP_MATCH;
758 }
759
760 return RMAP_NOMATCH;
761}
762
paul94f2b392005-06-28 12:44:16 +0000763static void *
paulfd79ac92004-10-13 05:06:08 +0000764route_match_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000765{
766 u_char *origin;
767
768 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
769
770 if (strcmp (arg, "igp") == 0)
771 *origin = 0;
772 else if (strcmp (arg, "egp") == 0)
773 *origin = 1;
774 else
775 *origin = 2;
776
777 return origin;
778}
779
780/* Free route map's compiled `ip address' value. */
paul94f2b392005-06-28 12:44:16 +0000781static void
paul718e3742002-12-13 20:15:29 +0000782route_match_origin_free (void *rule)
783{
784 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
785}
786
787/* Route map commands for origin matching. */
788struct route_map_rule_cmd route_match_origin_cmd =
789{
790 "origin",
791 route_match_origin,
792 route_match_origin_compile,
793 route_match_origin_free
794};
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +0400795
796/* match probability { */
797
798static route_map_result_t
799route_match_probability (void *rule, struct prefix *prefix,
800 route_map_object_t type, void *object)
801{
802 long r;
803#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
804 r = random();
805#else
806 r = (long) rand();
807#endif
808
809 switch (*(unsigned *) rule)
810 {
811 case 0: break;
812 case RAND_MAX: return RMAP_MATCH;
813 default:
814 if (r < *(unsigned *) rule)
815 {
816 return RMAP_MATCH;
817 }
818 }
819
820 return RMAP_NOMATCH;
821}
822
823static void *
824route_match_probability_compile (const char *arg)
825{
826 unsigned *lobule;
827 unsigned perc;
828
829#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
830 srandom (time (NULL));
831#else
832 srand (time (NULL));
833#endif
834
835 perc = atoi (arg);
836 lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned));
837
838 switch (perc)
839 {
840 case 0: *lobule = 0; break;
841 case 100: *lobule = RAND_MAX; break;
842 default: *lobule = RAND_MAX / 100 * perc;
843 }
844
845 return lobule;
846}
847
848static void
849route_match_probability_free (void *rule)
850{
851 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
852}
853
854struct route_map_rule_cmd route_match_probability_cmd =
855{
856 "probability",
857 route_match_probability,
858 route_match_probability_compile,
859 route_match_probability_free
860};
861
862/* } */
863
paul718e3742002-12-13 20:15:29 +0000864/* `set ip next-hop IP_ADDRESS' */
865
866/* Set nexthop to object. ojbect must be pointer to struct attr. */
paulac41b2a2003-08-12 05:32:27 +0000867struct rmap_ip_nexthop_set
868{
869 struct in_addr *address;
870 int peer_address;
871};
872
paul94f2b392005-06-28 12:44:16 +0000873static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000874route_set_ip_nexthop (void *rule, struct prefix *prefix,
875 route_map_object_t type, void *object)
876{
paulac41b2a2003-08-12 05:32:27 +0000877 struct rmap_ip_nexthop_set *rins = rule;
paul718e3742002-12-13 20:15:29 +0000878 struct bgp_info *bgp_info;
paulac41b2a2003-08-12 05:32:27 +0000879 struct peer *peer;
paul718e3742002-12-13 20:15:29 +0000880
881 if (type == RMAP_BGP)
882 {
paul718e3742002-12-13 20:15:29 +0000883 bgp_info = object;
paulac41b2a2003-08-12 05:32:27 +0000884 peer = bgp_info->peer;
885
886 if (rins->peer_address)
887 {
paulfee0f4c2004-09-13 05:12:46 +0000888 if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) ||
889 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
paulac41b2a2003-08-12 05:32:27 +0000890 && peer->su_remote
891 && sockunion_family (peer->su_remote) == AF_INET)
892 {
Jorge Boncompte [DTI2]0c5ed3e2012-04-10 16:57:22 +0200893 bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_remote);
paulac41b2a2003-08-12 05:32:27 +0000894 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
895 }
896 else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
897 && peer->su_local
898 && sockunion_family (peer->su_local) == AF_INET)
899 {
Jorge Boncompte [DTI2]0c5ed3e2012-04-10 16:57:22 +0200900 bgp_info->attr->nexthop.s_addr = sockunion2ip (peer->su_local);
paulac41b2a2003-08-12 05:32:27 +0000901 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
902 }
903 }
904 else
905 {
906 /* Set next hop value. */
907 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
908 bgp_info->attr->nexthop = *rins->address;
909 }
paul718e3742002-12-13 20:15:29 +0000910 }
911
912 return RMAP_OKAY;
913}
914
915/* Route map `ip nexthop' compile function. Given string is converted
916 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +0000917static void *
paulfd79ac92004-10-13 05:06:08 +0000918route_set_ip_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000919{
paulac41b2a2003-08-12 05:32:27 +0000920 struct rmap_ip_nexthop_set *rins;
921 struct in_addr *address = NULL;
922 int peer_address = 0;
paul718e3742002-12-13 20:15:29 +0000923 int ret;
paul718e3742002-12-13 20:15:29 +0000924
paulac41b2a2003-08-12 05:32:27 +0000925 if (strcmp (arg, "peer-address") == 0)
926 peer_address = 1;
927 else
paul718e3742002-12-13 20:15:29 +0000928 {
paulac41b2a2003-08-12 05:32:27 +0000929 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
930 ret = inet_aton (arg, address);
931
932 if (ret == 0)
933 {
934 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
935 return NULL;
936 }
paul718e3742002-12-13 20:15:29 +0000937 }
938
Stephen Hemminger393deb92008-08-18 14:13:29 -0700939 rins = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set));
paulac41b2a2003-08-12 05:32:27 +0000940
941 rins->address = address;
942 rins->peer_address = peer_address;
943
944 return rins;
paul718e3742002-12-13 20:15:29 +0000945}
946
947/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +0000948static void
paul718e3742002-12-13 20:15:29 +0000949route_set_ip_nexthop_free (void *rule)
950{
paulac41b2a2003-08-12 05:32:27 +0000951 struct rmap_ip_nexthop_set *rins = rule;
952
953 if (rins->address)
954 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address);
955
956 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins);
paul718e3742002-12-13 20:15:29 +0000957}
958
959/* Route map commands for ip nexthop set. */
960struct route_map_rule_cmd route_set_ip_nexthop_cmd =
961{
962 "ip next-hop",
963 route_set_ip_nexthop,
964 route_set_ip_nexthop_compile,
965 route_set_ip_nexthop_free
966};
David Lamparter6b0655a2014-06-04 06:53:35 +0200967
paul718e3742002-12-13 20:15:29 +0000968/* `set local-preference LOCAL_PREF' */
969
970/* Set local preference. */
paul94f2b392005-06-28 12:44:16 +0000971static route_map_result_t
paul718e3742002-12-13 20:15:29 +0000972route_set_local_pref (void *rule, struct prefix *prefix,
973 route_map_object_t type, void *object)
974{
975 u_int32_t *local_pref;
976 struct bgp_info *bgp_info;
977
978 if (type == RMAP_BGP)
979 {
980 /* Fetch routemap's rule information. */
981 local_pref = rule;
982 bgp_info = object;
983
984 /* Set local preference value. */
985 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
986 bgp_info->attr->local_pref = *local_pref;
987 }
988
989 return RMAP_OKAY;
990}
991
992/* set local preference compilation. */
paul94f2b392005-06-28 12:44:16 +0000993static void *
paulfd79ac92004-10-13 05:06:08 +0000994route_set_local_pref_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000995{
paulfd79ac92004-10-13 05:06:08 +0000996 unsigned long tmp;
paul718e3742002-12-13 20:15:29 +0000997 u_int32_t *local_pref;
998 char *endptr = NULL;
999
1000 /* Local preference value shoud be integer. */
1001 if (! all_digit (arg))
1002 return NULL;
paulfd79ac92004-10-13 05:06:08 +00001003
Ulrich Weber664711c2011-12-21 02:24:11 +04001004 errno = 0;
paulfd79ac92004-10-13 05:06:08 +00001005 tmp = strtoul (arg, &endptr, 10);
Ulrich Weber664711c2011-12-21 02:24:11 +04001006 if (*endptr != '\0' || errno || tmp > UINT32_MAX)
paulfd79ac92004-10-13 05:06:08 +00001007 return NULL;
1008
1009 local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
1010
1011 if (!local_pref)
1012 return local_pref;
1013
1014 *local_pref = tmp;
1015
paul718e3742002-12-13 20:15:29 +00001016 return local_pref;
1017}
1018
1019/* Free route map's local preference value. */
paul94f2b392005-06-28 12:44:16 +00001020static void
paul718e3742002-12-13 20:15:29 +00001021route_set_local_pref_free (void *rule)
1022{
1023 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1024}
1025
1026/* Set local preference rule structure. */
1027struct route_map_rule_cmd route_set_local_pref_cmd =
1028{
1029 "local-preference",
1030 route_set_local_pref,
1031 route_set_local_pref_compile,
1032 route_set_local_pref_free,
1033};
David Lamparter6b0655a2014-06-04 06:53:35 +02001034
paul718e3742002-12-13 20:15:29 +00001035/* `set weight WEIGHT' */
1036
1037/* Set weight. */
paul94f2b392005-06-28 12:44:16 +00001038static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001039route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type,
1040 void *object)
1041{
1042 u_int32_t *weight;
1043 struct bgp_info *bgp_info;
1044
1045 if (type == RMAP_BGP)
1046 {
1047 /* Fetch routemap's rule information. */
1048 weight = rule;
1049 bgp_info = object;
1050
1051 /* Set weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 if (*weight)
1053 (bgp_attr_extra_get (bgp_info->attr))->weight = *weight;
1054 else if (bgp_info->attr->extra)
1055 bgp_info->attr->extra->weight = 0;
paul718e3742002-12-13 20:15:29 +00001056 }
1057
1058 return RMAP_OKAY;
1059}
1060
1061/* set local preference compilation. */
paul94f2b392005-06-28 12:44:16 +00001062static void *
paulfd79ac92004-10-13 05:06:08 +00001063route_set_weight_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001064{
paulfd79ac92004-10-13 05:06:08 +00001065 unsigned long tmp;
paul718e3742002-12-13 20:15:29 +00001066 u_int32_t *weight;
1067 char *endptr = NULL;
1068
1069 /* Local preference value shoud be integer. */
1070 if (! all_digit (arg))
1071 return NULL;
1072
Ulrich Weber664711c2011-12-21 02:24:11 +04001073 errno = 0;
paulfd79ac92004-10-13 05:06:08 +00001074 tmp = strtoul (arg, &endptr, 10);
Ulrich Weber664711c2011-12-21 02:24:11 +04001075 if (*endptr != '\0' || errno || tmp > UINT32_MAX)
paulfd79ac92004-10-13 05:06:08 +00001076 return NULL;
1077
paul718e3742002-12-13 20:15:29 +00001078 weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
paulfd79ac92004-10-13 05:06:08 +00001079
1080 if (weight == NULL)
1081 return weight;
1082
1083 *weight = tmp;
1084
paul718e3742002-12-13 20:15:29 +00001085 return weight;
1086}
1087
1088/* Free route map's local preference value. */
paul94f2b392005-06-28 12:44:16 +00001089static void
paul718e3742002-12-13 20:15:29 +00001090route_set_weight_free (void *rule)
1091{
1092 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1093}
1094
1095/* Set local preference rule structure. */
1096struct route_map_rule_cmd route_set_weight_cmd =
1097{
1098 "weight",
1099 route_set_weight,
1100 route_set_weight_compile,
1101 route_set_weight_free,
1102};
David Lamparter6b0655a2014-06-04 06:53:35 +02001103
paul718e3742002-12-13 20:15:29 +00001104/* `set metric METRIC' */
1105
1106/* Set metric to attribute. */
paul94f2b392005-06-28 12:44:16 +00001107static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001108route_set_metric (void *rule, struct prefix *prefix,
1109 route_map_object_t type, void *object)
1110{
1111 char *metric;
1112 u_int32_t metric_val;
1113 struct bgp_info *bgp_info;
1114
1115 if (type == RMAP_BGP)
1116 {
1117 /* Fetch routemap's rule information. */
1118 metric = rule;
1119 bgp_info = object;
1120
1121 if (! (bgp_info->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC)))
1122 bgp_info->attr->med = 0;
1123 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
1124
1125 if (all_digit (metric))
1126 {
1127 metric_val = strtoul (metric, (char **)NULL, 10);
1128 bgp_info->attr->med = metric_val;
1129 }
1130 else
1131 {
1132 metric_val = strtoul (metric+1, (char **)NULL, 10);
1133
1134 if (strncmp (metric, "+", 1) == 0)
1135 {
paul3b424972003-10-13 09:47:32 +00001136 if (bgp_info->attr->med/2 + metric_val/2 > BGP_MED_MAX/2)
1137 bgp_info->attr->med = BGP_MED_MAX - 1;
paul718e3742002-12-13 20:15:29 +00001138 else
paul537d8ea2003-08-27 06:45:32 +00001139 bgp_info->attr->med += metric_val;
paul718e3742002-12-13 20:15:29 +00001140 }
1141 else if (strncmp (metric, "-", 1) == 0)
1142 {
paul537d8ea2003-08-27 06:45:32 +00001143 if (bgp_info->attr->med <= metric_val)
1144 bgp_info->attr->med = 0;
paul718e3742002-12-13 20:15:29 +00001145 else
paul537d8ea2003-08-27 06:45:32 +00001146 bgp_info->attr->med -= metric_val;
paul718e3742002-12-13 20:15:29 +00001147 }
1148 }
1149 }
1150 return RMAP_OKAY;
1151}
1152
1153/* set metric compilation. */
paul94f2b392005-06-28 12:44:16 +00001154static void *
paulfd79ac92004-10-13 05:06:08 +00001155route_set_metric_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001156{
1157 u_int32_t metric;
paul94f2b392005-06-28 12:44:16 +00001158 unsigned long larg;
paul718e3742002-12-13 20:15:29 +00001159 char *endptr = NULL;
1160
1161 if (all_digit (arg))
1162 {
1163 /* set metric value check*/
Ulrich Weber664711c2011-12-21 02:24:11 +04001164 errno = 0;
paul94f2b392005-06-28 12:44:16 +00001165 larg = strtoul (arg, &endptr, 10);
Ulrich Weber664711c2011-12-21 02:24:11 +04001166 if (*endptr != '\0' || errno || larg > UINT32_MAX)
paul718e3742002-12-13 20:15:29 +00001167 return NULL;
paul94f2b392005-06-28 12:44:16 +00001168 metric = larg;
paul718e3742002-12-13 20:15:29 +00001169 }
1170 else
1171 {
1172 /* set metric +/-value check */
1173 if ((strncmp (arg, "+", 1) != 0
1174 && strncmp (arg, "-", 1) != 0)
1175 || (! all_digit (arg+1)))
1176 return NULL;
1177
Ulrich Weber664711c2011-12-21 02:24:11 +04001178 errno = 0;
paul94f2b392005-06-28 12:44:16 +00001179 larg = strtoul (arg+1, &endptr, 10);
Ulrich Weber664711c2011-12-21 02:24:11 +04001180 if (*endptr != '\0' || errno || larg > UINT32_MAX)
paul718e3742002-12-13 20:15:29 +00001181 return NULL;
paul94f2b392005-06-28 12:44:16 +00001182 metric = larg;
paul718e3742002-12-13 20:15:29 +00001183 }
1184
1185 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1186}
1187
1188/* Free route map's compiled `set metric' value. */
paul94f2b392005-06-28 12:44:16 +00001189static void
paul718e3742002-12-13 20:15:29 +00001190route_set_metric_free (void *rule)
1191{
1192 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1193}
1194
1195/* Set metric rule structure. */
1196struct route_map_rule_cmd route_set_metric_cmd =
1197{
1198 "metric",
1199 route_set_metric,
1200 route_set_metric_compile,
1201 route_set_metric_free,
1202};
David Lamparter6b0655a2014-06-04 06:53:35 +02001203
paul718e3742002-12-13 20:15:29 +00001204/* `set as-path prepend ASPATH' */
1205
1206/* For AS path prepend mechanism. */
paul94f2b392005-06-28 12:44:16 +00001207static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001208route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1209{
1210 struct aspath *aspath;
1211 struct aspath *new;
1212 struct bgp_info *binfo;
1213
1214 if (type == RMAP_BGP)
1215 {
1216 aspath = rule;
1217 binfo = object;
1218
1219 if (binfo->attr->aspath->refcnt)
1220 new = aspath_dup (binfo->attr->aspath);
1221 else
1222 new = binfo->attr->aspath;
1223
1224 aspath_prepend (aspath, new);
1225 binfo->attr->aspath = new;
1226 }
1227
1228 return RMAP_OKAY;
1229}
1230
1231/* Compile function for as-path prepend. */
paul94f2b392005-06-28 12:44:16 +00001232static void *
paulfd79ac92004-10-13 05:06:08 +00001233route_set_aspath_prepend_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001234{
1235 struct aspath *aspath;
1236
1237 aspath = aspath_str2aspath (arg);
1238 if (! aspath)
1239 return NULL;
1240 return aspath;
1241}
1242
1243/* Compile function for as-path prepend. */
paul94f2b392005-06-28 12:44:16 +00001244static void
paul718e3742002-12-13 20:15:29 +00001245route_set_aspath_prepend_free (void *rule)
1246{
1247 struct aspath *aspath = rule;
1248 aspath_free (aspath);
1249}
1250
1251/* Set metric rule structure. */
1252struct route_map_rule_cmd route_set_aspath_prepend_cmd =
1253{
1254 "as-path prepend",
1255 route_set_aspath_prepend,
1256 route_set_aspath_prepend_compile,
1257 route_set_aspath_prepend_free,
1258};
David Lamparter6b0655a2014-06-04 06:53:35 +02001259
Denis Ovsienko841f7a52008-04-10 11:47:45 +00001260/* `set as-path exclude ASn' */
1261
1262/* For ASN exclude mechanism.
1263 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1264 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1265 */
1266static route_map_result_t
1267route_set_aspath_exclude (void *rule, struct prefix *dummy, route_map_object_t type, void *object)
1268{
1269 struct aspath * new_path, * exclude_path;
1270 struct bgp_info *binfo;
1271
1272 if (type == RMAP_BGP)
1273 {
1274 exclude_path = rule;
1275 binfo = object;
1276 if (binfo->attr->aspath->refcnt)
1277 new_path = aspath_dup (binfo->attr->aspath);
1278 else
1279 new_path = binfo->attr->aspath;
1280 binfo->attr->aspath = aspath_filter_exclude (new_path, exclude_path);
1281 }
1282 return RMAP_OKAY;
1283}
1284
1285/* FIXME: consider using route_set_aspath_prepend_compile() and
1286 * route_set_aspath_prepend_free(), which two below function are
1287 * exact clones of.
1288 */
1289
1290/* Compile function for as-path exclude. */
1291static void *
1292route_set_aspath_exclude_compile (const char *arg)
1293{
1294 struct aspath *aspath;
1295
1296 aspath = aspath_str2aspath (arg);
1297 if (! aspath)
1298 return NULL;
1299 return aspath;
1300}
1301
1302static void
1303route_set_aspath_exclude_free (void *rule)
1304{
1305 struct aspath *aspath = rule;
1306 aspath_free (aspath);
1307}
1308
1309/* Set ASn exlude rule structure. */
1310struct route_map_rule_cmd route_set_aspath_exclude_cmd =
1311{
1312 "as-path exclude",
1313 route_set_aspath_exclude,
1314 route_set_aspath_exclude_compile,
1315 route_set_aspath_exclude_free,
1316};
David Lamparter6b0655a2014-06-04 06:53:35 +02001317
paul718e3742002-12-13 20:15:29 +00001318/* `set community COMMUNITY' */
1319struct rmap_com_set
1320{
1321 struct community *com;
1322 int additive;
1323 int none;
1324};
1325
1326/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001327static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001328route_set_community (void *rule, struct prefix *prefix,
1329 route_map_object_t type, void *object)
1330{
1331 struct rmap_com_set *rcs;
1332 struct bgp_info *binfo;
1333 struct attr *attr;
1334 struct community *new = NULL;
1335 struct community *old;
1336 struct community *merge;
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001337
paul718e3742002-12-13 20:15:29 +00001338 if (type == RMAP_BGP)
1339 {
1340 rcs = rule;
1341 binfo = object;
1342 attr = binfo->attr;
1343 old = attr->community;
1344
1345 /* "none" case. */
1346 if (rcs->none)
1347 {
1348 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES));
1349 attr->community = NULL;
Christian Frankeb06b35f2012-12-07 14:26:09 +00001350 /* See the longer comment down below. */
1351 if (old && old->refcnt == 0)
1352 community_free(old);
paul718e3742002-12-13 20:15:29 +00001353 return RMAP_OKAY;
1354 }
1355
1356 /* "additive" case. */
1357 if (rcs->additive && old)
1358 {
1359 merge = community_merge (community_dup (old), rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001360
1361 /* HACK: if the old community is not intern'd,
1362 * we should free it here, or all reference to it may be lost.
1363 * Really need to cleanup attribute caching sometime.
1364 */
1365 if (old->refcnt == 0)
1366 community_free (old);
paul718e3742002-12-13 20:15:29 +00001367 new = community_uniq_sort (merge);
1368 community_free (merge);
1369 }
1370 else
1371 new = community_dup (rcs->com);
Paul Jakmaaa94ca82006-02-18 10:49:04 +00001372
1373 /* will be interned by caller if required */
Paul Jakma4a2035f2011-04-01 15:58:27 +01001374 attr->community = new;
hasso70601e02005-05-27 03:26:57 +00001375
paul718e3742002-12-13 20:15:29 +00001376 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1377 }
1378
1379 return RMAP_OKAY;
1380}
1381
1382/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001383static void *
paulfd79ac92004-10-13 05:06:08 +00001384route_set_community_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001385{
1386 struct rmap_com_set *rcs;
1387 struct community *com = NULL;
1388 char *sp;
1389 int additive = 0;
1390 int none = 0;
1391
1392 if (strcmp (arg, "none") == 0)
1393 none = 1;
1394 else
1395 {
1396 sp = strstr (arg, "additive");
1397
1398 if (sp && sp > arg)
1399 {
1400 /* "additive" keyworkd is included. */
1401 additive = 1;
1402 *(sp - 1) = '\0';
1403 }
1404
1405 com = community_str2com (arg);
1406
1407 if (additive)
1408 *(sp - 1) = ' ';
1409
1410 if (! com)
1411 return NULL;
1412 }
1413
Stephen Hemminger393deb92008-08-18 14:13:29 -07001414 rcs = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
Paul Jakma4a2035f2011-04-01 15:58:27 +01001415 rcs->com = com;
paul718e3742002-12-13 20:15:29 +00001416 rcs->additive = additive;
1417 rcs->none = none;
1418
1419 return rcs;
1420}
1421
1422/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001423static void
paul718e3742002-12-13 20:15:29 +00001424route_set_community_free (void *rule)
1425{
1426 struct rmap_com_set *rcs = rule;
1427
1428 if (rcs->com)
1429 community_free (rcs->com);
1430 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs);
1431}
1432
1433/* Set community rule structure. */
1434struct route_map_rule_cmd route_set_community_cmd =
1435{
1436 "community",
1437 route_set_community,
1438 route_set_community_compile,
1439 route_set_community_free,
1440};
David Lamparter6b0655a2014-06-04 06:53:35 +02001441
hassofee6e4e2005-02-02 16:29:31 +00001442/* `set comm-list (<1-99>|<100-500>|WORD) delete' */
paul718e3742002-12-13 20:15:29 +00001443
1444/* For community set mechanism. */
paul94f2b392005-06-28 12:44:16 +00001445static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001446route_set_community_delete (void *rule, struct prefix *prefix,
1447 route_map_object_t type, void *object)
1448{
1449 struct community_list *list;
1450 struct community *merge;
1451 struct community *new;
1452 struct community *old;
1453 struct bgp_info *binfo;
1454
1455 if (type == RMAP_BGP)
1456 {
1457 if (! rule)
1458 return RMAP_OKAY;
1459
1460 binfo = object;
hassofee6e4e2005-02-02 16:29:31 +00001461 list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00001462 old = binfo->attr->community;
1463
1464 if (list && old)
1465 {
1466 merge = community_list_match_delete (community_dup (old), list);
1467 new = community_uniq_sort (merge);
1468 community_free (merge);
1469
Michael Lambert604a9b42010-09-13 11:48:11 -04001470 /* HACK: if the old community is not intern'd,
1471 * we should free it here, or all reference to it may be lost.
1472 * Really need to cleanup attribute caching sometime.
1473 */
1474 if (old->refcnt == 0)
1475 community_free (old);
1476
paul718e3742002-12-13 20:15:29 +00001477 if (new->size == 0)
1478 {
1479 binfo->attr->community = NULL;
1480 binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1481 community_free (new);
1482 }
1483 else
1484 {
Paul Jakma4a2035f2011-04-01 15:58:27 +01001485 binfo->attr->community = new;
paul718e3742002-12-13 20:15:29 +00001486 binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1487 }
1488 }
1489 }
1490
1491 return RMAP_OKAY;
1492}
1493
1494/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001495static void *
paulfd79ac92004-10-13 05:06:08 +00001496route_set_community_delete_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001497{
1498 char *p;
1499 char *str;
1500 int len;
1501
1502 p = strchr (arg, ' ');
1503 if (p)
1504 {
1505 len = p - arg;
1506 str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
1507 memcpy (str, arg, len);
1508 }
1509 else
1510 str = NULL;
1511
1512 return str;
1513}
1514
1515/* Free function for set community. */
paul94f2b392005-06-28 12:44:16 +00001516static void
paul718e3742002-12-13 20:15:29 +00001517route_set_community_delete_free (void *rule)
1518{
1519 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1520}
1521
1522/* Set community rule structure. */
1523struct route_map_rule_cmd route_set_community_delete_cmd =
1524{
1525 "comm-list",
1526 route_set_community_delete,
1527 route_set_community_delete_compile,
1528 route_set_community_delete_free,
1529};
David Lamparter6b0655a2014-06-04 06:53:35 +02001530
paul718e3742002-12-13 20:15:29 +00001531/* `set extcommunity rt COMMUNITY' */
1532
David Lamparter73d78ea2014-06-04 00:58:47 +02001533/* For community set mechanism. Used by _rt and _soo. */
paul94f2b392005-06-28 12:44:16 +00001534static route_map_result_t
David Lamparter73d78ea2014-06-04 00:58:47 +02001535route_set_ecommunity (void *rule, struct prefix *prefix,
1536 route_map_object_t type, void *object)
paul718e3742002-12-13 20:15:29 +00001537{
1538 struct ecommunity *ecom;
1539 struct ecommunity *new_ecom;
1540 struct ecommunity *old_ecom;
1541 struct bgp_info *bgp_info;
1542
1543 if (type == RMAP_BGP)
1544 {
1545 ecom = rule;
1546 bgp_info = object;
1547
1548 if (! ecom)
1549 return RMAP_OKAY;
1550
1551 /* We assume additive for Extended Community. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001552 old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
paul718e3742002-12-13 20:15:29 +00001553
1554 if (old_ecom)
1555 new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
1556 else
1557 new_ecom = ecommunity_dup (ecom);
1558
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001559 bgp_info->attr->extra->ecommunity = ecommunity_intern (new_ecom);
paul718e3742002-12-13 20:15:29 +00001560
hasso70601e02005-05-27 03:26:57 +00001561 if (old_ecom)
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001562 ecommunity_unintern (&old_ecom);
hasso70601e02005-05-27 03:26:57 +00001563
paul718e3742002-12-13 20:15:29 +00001564 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
1565 }
1566 return RMAP_OKAY;
1567}
1568
1569/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001570static void *
paulfd79ac92004-10-13 05:06:08 +00001571route_set_ecommunity_rt_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001572{
1573 struct ecommunity *ecom;
1574
1575 ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0);
1576 if (! ecom)
1577 return NULL;
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001578 return ecommunity_intern (ecom);
paul718e3742002-12-13 20:15:29 +00001579}
1580
David Lamparter73d78ea2014-06-04 00:58:47 +02001581/* Free function for set community. Used by _rt and _soo */
paul94f2b392005-06-28 12:44:16 +00001582static void
David Lamparter73d78ea2014-06-04 00:58:47 +02001583route_set_ecommunity_free (void *rule)
paul718e3742002-12-13 20:15:29 +00001584{
1585 struct ecommunity *ecom = rule;
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001586 ecommunity_unintern (&ecom);
paul718e3742002-12-13 20:15:29 +00001587}
1588
1589/* Set community rule structure. */
1590struct route_map_rule_cmd route_set_ecommunity_rt_cmd =
1591{
1592 "extcommunity rt",
David Lamparter73d78ea2014-06-04 00:58:47 +02001593 route_set_ecommunity,
paul718e3742002-12-13 20:15:29 +00001594 route_set_ecommunity_rt_compile,
David Lamparter73d78ea2014-06-04 00:58:47 +02001595 route_set_ecommunity_free,
paul718e3742002-12-13 20:15:29 +00001596};
1597
1598/* `set extcommunity soo COMMUNITY' */
1599
paul718e3742002-12-13 20:15:29 +00001600/* Compile function for set community. */
paul94f2b392005-06-28 12:44:16 +00001601static void *
paulfd79ac92004-10-13 05:06:08 +00001602route_set_ecommunity_soo_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001603{
1604 struct ecommunity *ecom;
1605
1606 ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0);
1607 if (! ecom)
1608 return NULL;
1609
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001610 return ecommunity_intern (ecom);
paul718e3742002-12-13 20:15:29 +00001611}
1612
paul718e3742002-12-13 20:15:29 +00001613/* Set community rule structure. */
1614struct route_map_rule_cmd route_set_ecommunity_soo_cmd =
1615{
1616 "extcommunity soo",
David Lamparter73d78ea2014-06-04 00:58:47 +02001617 route_set_ecommunity,
paul718e3742002-12-13 20:15:29 +00001618 route_set_ecommunity_soo_compile,
David Lamparter73d78ea2014-06-04 00:58:47 +02001619 route_set_ecommunity_free,
paul718e3742002-12-13 20:15:29 +00001620};
David Lamparter6b0655a2014-06-04 06:53:35 +02001621
paul718e3742002-12-13 20:15:29 +00001622/* `set origin ORIGIN' */
1623
1624/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00001625static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001626route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1627{
1628 u_char *origin;
1629 struct bgp_info *bgp_info;
1630
1631 if (type == RMAP_BGP)
1632 {
1633 origin = rule;
1634 bgp_info = object;
1635
1636 bgp_info->attr->origin = *origin;
1637 }
1638
1639 return RMAP_OKAY;
1640}
1641
1642/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001643static void *
paulfd79ac92004-10-13 05:06:08 +00001644route_set_origin_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001645{
1646 u_char *origin;
1647
1648 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
1649
1650 if (strcmp (arg, "igp") == 0)
1651 *origin = 0;
1652 else if (strcmp (arg, "egp") == 0)
1653 *origin = 1;
1654 else
1655 *origin = 2;
1656
1657 return origin;
1658}
1659
1660/* Compile function for origin set. */
paul94f2b392005-06-28 12:44:16 +00001661static void
paul718e3742002-12-13 20:15:29 +00001662route_set_origin_free (void *rule)
1663{
1664 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1665}
1666
1667/* Set metric rule structure. */
1668struct route_map_rule_cmd route_set_origin_cmd =
1669{
1670 "origin",
1671 route_set_origin,
1672 route_set_origin_compile,
1673 route_set_origin_free,
1674};
David Lamparter6b0655a2014-06-04 06:53:35 +02001675
paul718e3742002-12-13 20:15:29 +00001676/* `set atomic-aggregate' */
1677
1678/* For atomic aggregate set. */
paul94f2b392005-06-28 12:44:16 +00001679static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001680route_set_atomic_aggregate (void *rule, struct prefix *prefix,
1681 route_map_object_t type, void *object)
1682{
1683 struct bgp_info *bgp_info;
1684
1685 if (type == RMAP_BGP)
1686 {
1687 bgp_info = object;
1688 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
1689 }
1690
1691 return RMAP_OKAY;
1692}
1693
1694/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001695static void *
paulfd79ac92004-10-13 05:06:08 +00001696route_set_atomic_aggregate_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001697{
1698 return (void *)1;
1699}
1700
1701/* Compile function for atomic aggregate. */
paul94f2b392005-06-28 12:44:16 +00001702static void
paul718e3742002-12-13 20:15:29 +00001703route_set_atomic_aggregate_free (void *rule)
1704{
1705 return;
1706}
1707
1708/* Set atomic aggregate rule structure. */
1709struct route_map_rule_cmd route_set_atomic_aggregate_cmd =
1710{
1711 "atomic-aggregate",
1712 route_set_atomic_aggregate,
1713 route_set_atomic_aggregate_compile,
1714 route_set_atomic_aggregate_free,
1715};
David Lamparter6b0655a2014-06-04 06:53:35 +02001716
paul718e3742002-12-13 20:15:29 +00001717/* `set aggregator as AS A.B.C.D' */
1718struct aggregator
1719{
1720 as_t as;
1721 struct in_addr address;
1722};
1723
paul94f2b392005-06-28 12:44:16 +00001724static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001725route_set_aggregator_as (void *rule, struct prefix *prefix,
1726 route_map_object_t type, void *object)
1727{
1728 struct bgp_info *bgp_info;
1729 struct aggregator *aggregator;
Paul Jakmafb982c22007-05-04 20:15:47 +00001730 struct attr_extra *ae;
paul718e3742002-12-13 20:15:29 +00001731
1732 if (type == RMAP_BGP)
1733 {
1734 bgp_info = object;
1735 aggregator = rule;
Paul Jakmafb982c22007-05-04 20:15:47 +00001736 ae = bgp_attr_extra_get (bgp_info->attr);
1737
1738 ae->aggregator_as = aggregator->as;
1739 ae->aggregator_addr = aggregator->address;
paul718e3742002-12-13 20:15:29 +00001740 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
1741 }
1742
1743 return RMAP_OKAY;
1744}
1745
paul94f2b392005-06-28 12:44:16 +00001746static void *
paulfd79ac92004-10-13 05:06:08 +00001747route_set_aggregator_as_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001748{
1749 struct aggregator *aggregator;
1750 char as[10];
1751 char address[20];
1752
Stephen Hemminger393deb92008-08-18 14:13:29 -07001753 aggregator = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));
paul718e3742002-12-13 20:15:29 +00001754 sscanf (arg, "%s %s", as, address);
1755
1756 aggregator->as = strtoul (as, NULL, 10);
1757 inet_aton (address, &aggregator->address);
1758
1759 return aggregator;
1760}
1761
paul94f2b392005-06-28 12:44:16 +00001762static void
paul718e3742002-12-13 20:15:29 +00001763route_set_aggregator_as_free (void *rule)
1764{
1765 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1766}
1767
1768struct route_map_rule_cmd route_set_aggregator_as_cmd =
1769{
1770 "aggregator as",
1771 route_set_aggregator_as,
1772 route_set_aggregator_as_compile,
1773 route_set_aggregator_as_free,
1774};
David Lamparter6b0655a2014-06-04 06:53:35 +02001775
paul718e3742002-12-13 20:15:29 +00001776#ifdef HAVE_IPV6
1777/* `match ipv6 address IP_ACCESS_LIST' */
1778
paul94f2b392005-06-28 12:44:16 +00001779static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001780route_match_ipv6_address (void *rule, struct prefix *prefix,
1781 route_map_object_t type, void *object)
1782{
1783 struct access_list *alist;
1784
1785 if (type == RMAP_BGP)
1786 {
1787 alist = access_list_lookup (AFI_IP6, (char *) rule);
1788 if (alist == NULL)
1789 return RMAP_NOMATCH;
1790
1791 return (access_list_apply (alist, prefix) == FILTER_DENY ?
1792 RMAP_NOMATCH : RMAP_MATCH);
1793 }
1794 return RMAP_NOMATCH;
1795}
1796
paul94f2b392005-06-28 12:44:16 +00001797static void *
paulfd79ac92004-10-13 05:06:08 +00001798route_match_ipv6_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001799{
1800 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1801}
1802
paul94f2b392005-06-28 12:44:16 +00001803static void
paul718e3742002-12-13 20:15:29 +00001804route_match_ipv6_address_free (void *rule)
1805{
1806 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1807}
1808
1809/* Route map commands for ip address matching. */
1810struct route_map_rule_cmd route_match_ipv6_address_cmd =
1811{
1812 "ipv6 address",
1813 route_match_ipv6_address,
1814 route_match_ipv6_address_compile,
1815 route_match_ipv6_address_free
1816};
David Lamparter6b0655a2014-06-04 06:53:35 +02001817
paul718e3742002-12-13 20:15:29 +00001818/* `match ipv6 next-hop IP_ADDRESS' */
1819
paul94f2b392005-06-28 12:44:16 +00001820static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001821route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
1822 route_map_object_t type, void *object)
1823{
1824 struct in6_addr *addr;
1825 struct bgp_info *bgp_info;
1826
1827 if (type == RMAP_BGP)
1828 {
1829 addr = rule;
1830 bgp_info = object;
Paul Jakmafb982c22007-05-04 20:15:47 +00001831
1832 if (!bgp_info->attr->extra)
1833 return RMAP_NOMATCH;
1834
1835 if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, rule))
paul718e3742002-12-13 20:15:29 +00001836 return RMAP_MATCH;
1837
Paul Jakmafb982c22007-05-04 20:15:47 +00001838 if (bgp_info->attr->extra->mp_nexthop_len == 32 &&
1839 IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, rule))
paul718e3742002-12-13 20:15:29 +00001840 return RMAP_MATCH;
1841
1842 return RMAP_NOMATCH;
1843 }
1844
1845 return RMAP_NOMATCH;
1846}
1847
paul94f2b392005-06-28 12:44:16 +00001848static void *
paulfd79ac92004-10-13 05:06:08 +00001849route_match_ipv6_next_hop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001850{
1851 struct in6_addr *address;
1852 int ret;
1853
1854 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1855
1856 ret = inet_pton (AF_INET6, arg, address);
1857 if (!ret)
1858 {
1859 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1860 return NULL;
1861 }
1862
1863 return address;
1864}
1865
paul94f2b392005-06-28 12:44:16 +00001866static void
paul718e3742002-12-13 20:15:29 +00001867route_match_ipv6_next_hop_free (void *rule)
1868{
1869 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1870}
1871
1872struct route_map_rule_cmd route_match_ipv6_next_hop_cmd =
1873{
1874 "ipv6 next-hop",
1875 route_match_ipv6_next_hop,
1876 route_match_ipv6_next_hop_compile,
1877 route_match_ipv6_next_hop_free
1878};
David Lamparter6b0655a2014-06-04 06:53:35 +02001879
paul718e3742002-12-13 20:15:29 +00001880/* `match ipv6 address prefix-list PREFIX_LIST' */
1881
paul94f2b392005-06-28 12:44:16 +00001882static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001883route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix,
1884 route_map_object_t type, void *object)
1885{
1886 struct prefix_list *plist;
1887
1888 if (type == RMAP_BGP)
1889 {
1890 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
1891 if (plist == NULL)
1892 return RMAP_NOMATCH;
1893
1894 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
1895 RMAP_NOMATCH : RMAP_MATCH);
1896 }
1897 return RMAP_NOMATCH;
1898}
1899
paul94f2b392005-06-28 12:44:16 +00001900static void *
paulfd79ac92004-10-13 05:06:08 +00001901route_match_ipv6_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001902{
1903 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1904}
1905
paul94f2b392005-06-28 12:44:16 +00001906static void
paul718e3742002-12-13 20:15:29 +00001907route_match_ipv6_address_prefix_list_free (void *rule)
1908{
1909 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1910}
1911
1912struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
1913{
1914 "ipv6 address prefix-list",
1915 route_match_ipv6_address_prefix_list,
1916 route_match_ipv6_address_prefix_list_compile,
1917 route_match_ipv6_address_prefix_list_free
1918};
David Lamparter6b0655a2014-06-04 06:53:35 +02001919
paul718e3742002-12-13 20:15:29 +00001920/* `set ipv6 nexthop global IP_ADDRESS' */
1921
1922/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001923static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001924route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix,
1925 route_map_object_t type, void *object)
1926{
1927 struct in6_addr *address;
1928 struct bgp_info *bgp_info;
1929
1930 if (type == RMAP_BGP)
1931 {
1932 /* Fetch routemap's rule information. */
1933 address = rule;
1934 bgp_info = object;
1935
1936 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001937 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address;
paul718e3742002-12-13 20:15:29 +00001938
1939 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001940 if (bgp_info->attr->extra->mp_nexthop_len == 0)
1941 bgp_info->attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001942 }
1943
1944 return RMAP_OKAY;
1945}
1946
1947/* Route map `ip next-hop' compile function. Given string is converted
1948 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00001949static void *
paulfd79ac92004-10-13 05:06:08 +00001950route_set_ipv6_nexthop_global_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00001951{
1952 int ret;
1953 struct in6_addr *address;
1954
1955 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1956
1957 ret = inet_pton (AF_INET6, arg, address);
1958
1959 if (ret == 0)
1960 {
1961 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1962 return NULL;
1963 }
1964
1965 return address;
1966}
1967
1968/* Free route map's compiled `ip next-hop' value. */
paul94f2b392005-06-28 12:44:16 +00001969static void
paul718e3742002-12-13 20:15:29 +00001970route_set_ipv6_nexthop_global_free (void *rule)
1971{
1972 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1973}
1974
1975/* Route map commands for ip nexthop set. */
1976struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd =
1977{
1978 "ipv6 next-hop global",
1979 route_set_ipv6_nexthop_global,
1980 route_set_ipv6_nexthop_global_compile,
1981 route_set_ipv6_nexthop_global_free
1982};
David Lamparter6b0655a2014-06-04 06:53:35 +02001983
paul718e3742002-12-13 20:15:29 +00001984/* `set ipv6 nexthop local IP_ADDRESS' */
1985
1986/* Set nexthop to object. ojbect must be pointer to struct attr. */
paul94f2b392005-06-28 12:44:16 +00001987static route_map_result_t
paul718e3742002-12-13 20:15:29 +00001988route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
1989 route_map_object_t type, void *object)
1990{
1991 struct in6_addr *address;
1992 struct bgp_info *bgp_info;
1993
1994 if (type == RMAP_BGP)
1995 {
1996 /* Fetch routemap's rule information. */
1997 address = rule;
1998 bgp_info = object;
1999
2000 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002001 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address;
paul718e3742002-12-13 20:15:29 +00002002
2003 /* Set nexthop length. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002004 if (bgp_info->attr->extra->mp_nexthop_len != 32)
2005 bgp_info->attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002006 }
2007
2008 return RMAP_OKAY;
2009}
2010
2011/* Route map `ip nexthop' compile function. Given string is converted
2012 to struct in_addr structure. */
paul94f2b392005-06-28 12:44:16 +00002013static void *
paulfd79ac92004-10-13 05:06:08 +00002014route_set_ipv6_nexthop_local_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002015{
2016 int ret;
2017 struct in6_addr *address;
2018
2019 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
2020
2021 ret = inet_pton (AF_INET6, arg, address);
2022
2023 if (ret == 0)
2024 {
2025 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2026 return NULL;
2027 }
2028
2029 return address;
2030}
2031
2032/* Free route map's compiled `ip nexthop' value. */
paul94f2b392005-06-28 12:44:16 +00002033static void
paul718e3742002-12-13 20:15:29 +00002034route_set_ipv6_nexthop_local_free (void *rule)
2035{
2036 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2037}
2038
2039/* Route map commands for ip nexthop set. */
2040struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd =
2041{
2042 "ipv6 next-hop local",
2043 route_set_ipv6_nexthop_local,
2044 route_set_ipv6_nexthop_local_compile,
2045 route_set_ipv6_nexthop_local_free
2046};
2047#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02002048
paul718e3742002-12-13 20:15:29 +00002049/* `set vpnv4 nexthop A.B.C.D' */
2050
paul94f2b392005-06-28 12:44:16 +00002051static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002052route_set_vpnv4_nexthop (void *rule, struct prefix *prefix,
2053 route_map_object_t type, void *object)
2054{
2055 struct in_addr *address;
2056 struct bgp_info *bgp_info;
2057
2058 if (type == RMAP_BGP)
2059 {
2060 /* Fetch routemap's rule information. */
2061 address = rule;
2062 bgp_info = object;
2063
2064 /* Set next hop value. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002065 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address;
paul718e3742002-12-13 20:15:29 +00002066 }
2067
2068 return RMAP_OKAY;
2069}
2070
paul94f2b392005-06-28 12:44:16 +00002071static void *
paulfd79ac92004-10-13 05:06:08 +00002072route_set_vpnv4_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002073{
2074 int ret;
2075 struct in_addr *address;
2076
2077 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2078
2079 ret = inet_aton (arg, address);
2080
2081 if (ret == 0)
2082 {
2083 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2084 return NULL;
2085 }
2086
2087 return address;
2088}
2089
paul94f2b392005-06-28 12:44:16 +00002090static void
paul718e3742002-12-13 20:15:29 +00002091route_set_vpnv4_nexthop_free (void *rule)
2092{
2093 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2094}
2095
2096/* Route map commands for ip nexthop set. */
2097struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd =
2098{
2099 "vpnv4 next-hop",
2100 route_set_vpnv4_nexthop,
2101 route_set_vpnv4_nexthop_compile,
2102 route_set_vpnv4_nexthop_free
2103};
David Lamparter6b0655a2014-06-04 06:53:35 +02002104
paul718e3742002-12-13 20:15:29 +00002105/* `set originator-id' */
2106
2107/* For origin set. */
paul94f2b392005-06-28 12:44:16 +00002108static route_map_result_t
paul718e3742002-12-13 20:15:29 +00002109route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
2110{
2111 struct in_addr *address;
2112 struct bgp_info *bgp_info;
2113
2114 if (type == RMAP_BGP)
2115 {
2116 address = rule;
2117 bgp_info = object;
2118
2119 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);
Paul Jakmafb982c22007-05-04 20:15:47 +00002120 (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address;
paul718e3742002-12-13 20:15:29 +00002121 }
2122
2123 return RMAP_OKAY;
2124}
2125
2126/* Compile function for originator-id set. */
paul94f2b392005-06-28 12:44:16 +00002127static void *
paulfd79ac92004-10-13 05:06:08 +00002128route_set_originator_id_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +00002129{
2130 int ret;
2131 struct in_addr *address;
2132
2133 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2134
2135 ret = inet_aton (arg, address);
2136
2137 if (ret == 0)
2138 {
2139 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2140 return NULL;
2141 }
2142
2143 return address;
2144}
2145
2146/* Compile function for originator_id set. */
paul94f2b392005-06-28 12:44:16 +00002147static void
paul718e3742002-12-13 20:15:29 +00002148route_set_originator_id_free (void *rule)
2149{
2150 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2151}
2152
2153/* Set metric rule structure. */
2154struct route_map_rule_cmd route_set_originator_id_cmd =
2155{
2156 "originator-id",
2157 route_set_originator_id,
2158 route_set_originator_id_compile,
2159 route_set_originator_id_free,
2160};
David Lamparter6b0655a2014-06-04 06:53:35 +02002161
paul718e3742002-12-13 20:15:29 +00002162/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002163static int
paul718e3742002-12-13 20:15:29 +00002164bgp_route_match_add (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_add_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/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002186static int
paul718e3742002-12-13 20:15:29 +00002187bgp_route_match_delete (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_delete_match (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/* Add bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002209static int
paul718e3742002-12-13 20:15:29 +00002210bgp_route_set_add (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_add_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/* Delete bgp route map rule. */
paul94f2b392005-06-28 12:44:16 +00002232static int
paul718e3742002-12-13 20:15:29 +00002233bgp_route_set_delete (struct vty *vty, struct route_map_index *index,
paulfd79ac92004-10-13 05:06:08 +00002234 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +00002235{
2236 int ret;
2237
2238 ret = route_map_delete_set (index, command, arg);
2239 if (ret)
2240 {
2241 switch (ret)
2242 {
2243 case RMAP_RULE_MISSING:
2244 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2245 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002246 case RMAP_COMPILE_ERROR:
2247 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2248 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00002249 }
2250 }
2251 return CMD_SUCCESS;
2252}
2253
2254/* Hook function for updating route_map assignment. */
paul94f2b392005-06-28 12:44:16 +00002255static void
paulfd79ac92004-10-13 05:06:08 +00002256bgp_route_map_update (const char *unused)
paul718e3742002-12-13 20:15:29 +00002257{
2258 int i;
2259 afi_t afi;
2260 safi_t safi;
2261 int direct;
paul1eb8ef22005-04-07 07:30:20 +00002262 struct listnode *node, *nnode;
2263 struct listnode *mnode, *mnnode;
paul718e3742002-12-13 20:15:29 +00002264 struct bgp *bgp;
2265 struct peer *peer;
2266 struct peer_group *group;
2267 struct bgp_filter *filter;
2268 struct bgp_node *bn;
2269 struct bgp_static *bgp_static;
2270
2271 /* For neighbor route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002272 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002273 {
paul1eb8ef22005-04-07 07:30:20 +00002274 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002275 {
2276 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2277 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2278 {
2279 filter = &peer->filter[afi][safi];
2280
paulfee0f4c2004-09-13 05:12:46 +00002281 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002282 {
2283 if (filter->map[direct].name)
2284 filter->map[direct].map =
2285 route_map_lookup_by_name (filter->map[direct].name);
2286 else
2287 filter->map[direct].map = NULL;
2288 }
2289
2290 if (filter->usmap.name)
2291 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2292 else
2293 filter->usmap.map = NULL;
2294 }
2295 }
paul1eb8ef22005-04-07 07:30:20 +00002296 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
paul718e3742002-12-13 20:15:29 +00002297 {
2298 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2299 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2300 {
2301 filter = &group->conf->filter[afi][safi];
2302
paulfee0f4c2004-09-13 05:12:46 +00002303 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
paul718e3742002-12-13 20:15:29 +00002304 {
2305 if (filter->map[direct].name)
2306 filter->map[direct].map =
2307 route_map_lookup_by_name (filter->map[direct].name);
2308 else
2309 filter->map[direct].map = NULL;
2310 }
2311
2312 if (filter->usmap.name)
2313 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2314 else
2315 filter->usmap.map = NULL;
2316 }
2317 }
2318 }
2319
2320 /* For default-originate route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002321 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002322 {
paul1eb8ef22005-04-07 07:30:20 +00002323 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00002324 {
2325 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2326 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2327 {
2328 if (peer->default_rmap[afi][safi].name)
2329 peer->default_rmap[afi][safi].map =
2330 route_map_lookup_by_name (peer->default_rmap[afi][safi].name);
2331 else
2332 peer->default_rmap[afi][safi].map = NULL;
2333 }
2334 }
2335 }
2336
2337 /* For network route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002338 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002339 {
2340 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2341 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2342 for (bn = bgp_table_top (bgp->route[afi][safi]); bn;
2343 bn = bgp_route_next (bn))
2344 if ((bgp_static = bn->info) != NULL)
2345 {
2346 if (bgp_static->rmap.name)
2347 bgp_static->rmap.map =
2348 route_map_lookup_by_name (bgp_static->rmap.name);
2349 else
2350 bgp_static->rmap.map = NULL;
2351 }
2352 }
2353
2354 /* For redistribute route-map updates. */
paul1eb8ef22005-04-07 07:30:20 +00002355 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
paul718e3742002-12-13 20:15:29 +00002356 {
2357 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2358 {
2359 if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)
2360 bgp->rmap[ZEBRA_FAMILY_IPV4][i].map =
2361 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);
2362#ifdef HAVE_IPV6
2363 if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)
2364 bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =
2365 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);
2366#endif /* HAVE_IPV6 */
2367 }
2368 }
2369}
David Lamparter6b0655a2014-06-04 06:53:35 +02002370
paulfee0f4c2004-09-13 05:12:46 +00002371DEFUN (match_peer,
2372 match_peer_cmd,
2373 "match peer (A.B.C.D|X:X::X:X)",
2374 MATCH_STR
2375 "Match peer address\n"
2376 "IPv6 address of peer\n"
2377 "IP address of peer\n")
2378{
2379 return bgp_route_match_add (vty, vty->index, "peer", argv[0]);
2380}
2381
2382DEFUN (match_peer_local,
2383 match_peer_local_cmd,
2384 "match peer local",
2385 MATCH_STR
2386 "Match peer address\n"
2387 "Static or Redistributed routes\n")
2388{
Jorge Boncompte [DTI2]4fe080d2012-04-13 13:46:08 +02002389 return bgp_route_match_add (vty, vty->index, "peer", "local");
paulfee0f4c2004-09-13 05:12:46 +00002390}
2391
2392DEFUN (no_match_peer,
2393 no_match_peer_cmd,
2394 "no match peer",
2395 NO_STR
2396 MATCH_STR
2397 "Match peer address\n")
2398{
2399 if (argc == 0)
2400 return bgp_route_match_delete (vty, vty->index, "peer", NULL);
2401
2402 return bgp_route_match_delete (vty, vty->index, "peer", argv[0]);
2403}
2404
2405ALIAS (no_match_peer,
2406 no_match_peer_val_cmd,
2407 "no match peer (A.B.C.D|X:X::X:X)",
2408 NO_STR
2409 MATCH_STR
2410 "Match peer address\n"
2411 "IPv6 address of peer\n"
2412 "IP address of peer\n")
2413
2414ALIAS (no_match_peer,
2415 no_match_peer_local_cmd,
2416 "no match peer local",
2417 NO_STR
2418 MATCH_STR
2419 "Match peer address\n"
2420 "Static or Redistributed routes\n")
2421
paul718e3742002-12-13 20:15:29 +00002422DEFUN (match_ip_address,
2423 match_ip_address_cmd,
2424 "match ip address (<1-199>|<1300-2699>|WORD)",
2425 MATCH_STR
2426 IP_STR
2427 "Match address of route\n"
2428 "IP access-list number\n"
2429 "IP access-list number (expanded range)\n"
2430 "IP Access-list name\n")
2431{
2432 return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);
2433}
2434
2435DEFUN (no_match_ip_address,
2436 no_match_ip_address_cmd,
2437 "no match ip address",
2438 NO_STR
2439 MATCH_STR
2440 IP_STR
2441 "Match address of route\n")
2442{
2443 if (argc == 0)
2444 return bgp_route_match_delete (vty, vty->index, "ip address", NULL);
2445
2446 return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);
2447}
2448
2449ALIAS (no_match_ip_address,
2450 no_match_ip_address_val_cmd,
2451 "no match ip address (<1-199>|<1300-2699>|WORD)",
2452 NO_STR
2453 MATCH_STR
2454 IP_STR
2455 "Match address of route\n"
2456 "IP access-list number\n"
2457 "IP access-list number (expanded range)\n"
2458 "IP Access-list name\n")
2459
2460DEFUN (match_ip_next_hop,
2461 match_ip_next_hop_cmd,
2462 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
2463 MATCH_STR
2464 IP_STR
2465 "Match next-hop address of route\n"
2466 "IP access-list number\n"
2467 "IP access-list number (expanded range)\n"
2468 "IP Access-list name\n")
2469{
2470 return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
2471}
2472
2473DEFUN (no_match_ip_next_hop,
2474 no_match_ip_next_hop_cmd,
2475 "no match ip next-hop",
2476 NO_STR
2477 MATCH_STR
2478 IP_STR
2479 "Match next-hop address of route\n")
2480{
2481 if (argc == 0)
2482 return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
2483
2484 return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
2485}
2486
2487ALIAS (no_match_ip_next_hop,
2488 no_match_ip_next_hop_val_cmd,
2489 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2490 NO_STR
2491 MATCH_STR
2492 IP_STR
2493 "Match next-hop address of route\n"
2494 "IP access-list number\n"
2495 "IP access-list number (expanded range)\n"
2496 "IP Access-list name\n")
2497
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +04002498/* match probability { */
2499
2500DEFUN (match_probability,
2501 match_probability_cmd,
2502 "match probability <0-100>",
2503 MATCH_STR
2504 "Match portion of routes defined by percentage value\n"
2505 "Percentage of routes\n")
2506{
2507 return bgp_route_match_add (vty, vty->index, "probability", argv[0]);
2508}
2509
2510DEFUN (no_match_probability,
2511 no_match_probability_cmd,
2512 "no match probability",
2513 NO_STR
2514 MATCH_STR
2515 "Match portion of routes defined by percentage value\n")
2516{
2517 return bgp_route_match_delete (vty, vty->index, "probability", argc ? argv[0] : NULL);
2518}
2519
2520ALIAS (no_match_probability,
2521 no_match_probability_val_cmd,
2522 "no match probability <1-99>",
2523 NO_STR
2524 MATCH_STR
2525 "Match portion of routes defined by percentage value\n"
2526 "Percentage of routes\n")
2527
2528/* } */
2529
hassoc1643bb2005-02-02 16:43:17 +00002530DEFUN (match_ip_route_source,
2531 match_ip_route_source_cmd,
2532 "match ip route-source (<1-199>|<1300-2699>|WORD)",
2533 MATCH_STR
2534 IP_STR
2535 "Match advertising source address of route\n"
2536 "IP access-list number\n"
2537 "IP access-list number (expanded range)\n"
2538 "IP standard access-list name\n")
2539{
2540 return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]);
2541}
2542
2543DEFUN (no_match_ip_route_source,
2544 no_match_ip_route_source_cmd,
2545 "no match ip route-source",
2546 NO_STR
2547 MATCH_STR
2548 IP_STR
2549 "Match advertising source address of route\n")
2550{
2551 if (argc == 0)
2552 return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL);
2553
2554 return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]);
2555}
2556
2557ALIAS (no_match_ip_route_source,
2558 no_match_ip_route_source_val_cmd,
2559 "no match ip route-source (<1-199>|<1300-2699>|WORD)",
2560 NO_STR
2561 MATCH_STR
2562 IP_STR
2563 "Match advertising source address of route\n"
2564 "IP access-list number\n"
2565 "IP access-list number (expanded range)\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002566 "IP standard access-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002567
paul718e3742002-12-13 20:15:29 +00002568DEFUN (match_ip_address_prefix_list,
2569 match_ip_address_prefix_list_cmd,
2570 "match ip address prefix-list WORD",
2571 MATCH_STR
2572 IP_STR
2573 "Match address of route\n"
2574 "Match entries of prefix-lists\n"
2575 "IP prefix-list name\n")
2576{
2577 return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
2578}
2579
2580DEFUN (no_match_ip_address_prefix_list,
2581 no_match_ip_address_prefix_list_cmd,
2582 "no match ip address prefix-list",
2583 NO_STR
2584 MATCH_STR
2585 IP_STR
2586 "Match address of route\n"
2587 "Match entries of prefix-lists\n")
2588{
2589 if (argc == 0)
2590 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
2591
2592 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
2593}
2594
2595ALIAS (no_match_ip_address_prefix_list,
2596 no_match_ip_address_prefix_list_val_cmd,
2597 "no match ip address prefix-list WORD",
2598 NO_STR
2599 MATCH_STR
2600 IP_STR
2601 "Match address of route\n"
2602 "Match entries of prefix-lists\n"
2603 "IP prefix-list name\n")
2604
2605DEFUN (match_ip_next_hop_prefix_list,
2606 match_ip_next_hop_prefix_list_cmd,
2607 "match ip next-hop prefix-list WORD",
2608 MATCH_STR
2609 IP_STR
2610 "Match next-hop address of route\n"
2611 "Match entries of prefix-lists\n"
2612 "IP prefix-list name\n")
2613{
2614 return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2615}
2616
2617DEFUN (no_match_ip_next_hop_prefix_list,
2618 no_match_ip_next_hop_prefix_list_cmd,
2619 "no match ip next-hop prefix-list",
2620 NO_STR
2621 MATCH_STR
2622 IP_STR
2623 "Match next-hop address of route\n"
2624 "Match entries of prefix-lists\n")
2625{
2626 if (argc == 0)
2627 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
2628
2629 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2630}
2631
2632ALIAS (no_match_ip_next_hop_prefix_list,
2633 no_match_ip_next_hop_prefix_list_val_cmd,
2634 "no match ip next-hop prefix-list WORD",
2635 NO_STR
2636 MATCH_STR
2637 IP_STR
2638 "Match next-hop address of route\n"
2639 "Match entries of prefix-lists\n"
2640 "IP prefix-list name\n")
2641
hassoc1643bb2005-02-02 16:43:17 +00002642DEFUN (match_ip_route_source_prefix_list,
2643 match_ip_route_source_prefix_list_cmd,
2644 "match ip route-source prefix-list WORD",
2645 MATCH_STR
2646 IP_STR
2647 "Match advertising source address of route\n"
2648 "Match entries of prefix-lists\n"
2649 "IP prefix-list name\n")
2650{
2651 return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]);
2652}
2653
2654DEFUN (no_match_ip_route_source_prefix_list,
2655 no_match_ip_route_source_prefix_list_cmd,
2656 "no match ip route-source prefix-list",
2657 NO_STR
2658 MATCH_STR
2659 IP_STR
2660 "Match advertising source address of route\n"
2661 "Match entries of prefix-lists\n")
2662{
2663 if (argc == 0)
2664 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL);
2665
2666 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]);
2667}
2668
2669ALIAS (no_match_ip_route_source_prefix_list,
2670 no_match_ip_route_source_prefix_list_val_cmd,
2671 "no match ip route-source prefix-list WORD",
2672 NO_STR
2673 MATCH_STR
2674 IP_STR
2675 "Match advertising source address of route\n"
2676 "Match entries of prefix-lists\n"
Paul Jakma30a22312008-08-15 14:05:22 +01002677 "IP prefix-list name\n")
hassoc1643bb2005-02-02 16:43:17 +00002678
paul718e3742002-12-13 20:15:29 +00002679DEFUN (match_metric,
2680 match_metric_cmd,
2681 "match metric <0-4294967295>",
2682 MATCH_STR
2683 "Match metric of route\n"
2684 "Metric value\n")
2685{
2686 return bgp_route_match_add (vty, vty->index, "metric", argv[0]);
2687}
2688
2689DEFUN (no_match_metric,
2690 no_match_metric_cmd,
2691 "no match metric",
2692 NO_STR
2693 MATCH_STR
2694 "Match metric of route\n")
2695{
2696 if (argc == 0)
2697 return bgp_route_match_delete (vty, vty->index, "metric", NULL);
2698
2699 return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);
2700}
2701
2702ALIAS (no_match_metric,
2703 no_match_metric_val_cmd,
2704 "no match metric <0-4294967295>",
2705 NO_STR
2706 MATCH_STR
2707 "Match metric of route\n"
2708 "Metric value\n")
2709
2710DEFUN (match_community,
2711 match_community_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002712 "match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002713 MATCH_STR
2714 "Match BGP community list\n"
2715 "Community-list number (standard)\n"
2716 "Community-list number (expanded)\n"
2717 "Community-list name\n")
2718{
2719 return bgp_route_match_add (vty, vty->index, "community", argv[0]);
2720}
2721
2722DEFUN (match_community_exact,
2723 match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002724 "match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002725 MATCH_STR
2726 "Match BGP community list\n"
2727 "Community-list number (standard)\n"
2728 "Community-list number (expanded)\n"
2729 "Community-list name\n"
2730 "Do exact matching of communities\n")
2731{
2732 int ret;
2733 char *argstr;
2734
2735 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
2736 strlen (argv[0]) + strlen ("exact-match") + 2);
2737
2738 sprintf (argstr, "%s exact-match", argv[0]);
2739
2740 ret = bgp_route_match_add (vty, vty->index, "community", argstr);
2741
2742 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
2743
2744 return ret;
2745}
2746
2747DEFUN (no_match_community,
2748 no_match_community_cmd,
2749 "no match community",
2750 NO_STR
2751 MATCH_STR
2752 "Match BGP community list\n")
2753{
2754 return bgp_route_match_delete (vty, vty->index, "community", NULL);
2755}
2756
2757ALIAS (no_match_community,
2758 no_match_community_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002759 "no match community (<1-99>|<100-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00002760 NO_STR
2761 MATCH_STR
2762 "Match BGP community list\n"
2763 "Community-list number (standard)\n"
2764 "Community-list number (expanded)\n"
2765 "Community-list name\n")
2766
2767ALIAS (no_match_community,
2768 no_match_community_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002769 "no match community (<1-99>|<100-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00002770 NO_STR
2771 MATCH_STR
2772 "Match BGP community list\n"
2773 "Community-list number (standard)\n"
2774 "Community-list number (expanded)\n"
2775 "Community-list name\n"
2776 "Do exact matching of communities\n")
2777
paul73ffb252003-04-19 15:49:49 +00002778DEFUN (match_ecommunity,
2779 match_ecommunity_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002780 "match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002781 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{
2787 return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]);
2788}
2789
2790DEFUN (no_match_ecommunity,
2791 no_match_ecommunity_cmd,
2792 "no match extcommunity",
2793 NO_STR
2794 MATCH_STR
2795 "Match BGP/VPN extended community list\n")
2796{
2797 return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL);
2798}
2799
2800ALIAS (no_match_ecommunity,
2801 no_match_ecommunity_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00002802 "no match extcommunity (<1-99>|<100-500>|WORD)",
paul73ffb252003-04-19 15:49:49 +00002803 NO_STR
2804 MATCH_STR
2805 "Match BGP/VPN extended community list\n"
2806 "Extended community-list number (standard)\n"
2807 "Extended community-list number (expanded)\n"
2808 "Extended community-list name\n")
2809
paul718e3742002-12-13 20:15:29 +00002810DEFUN (match_aspath,
2811 match_aspath_cmd,
2812 "match as-path WORD",
2813 MATCH_STR
2814 "Match BGP AS path list\n"
2815 "AS path access-list name\n")
2816{
2817 return bgp_route_match_add (vty, vty->index, "as-path", argv[0]);
2818}
2819
2820DEFUN (no_match_aspath,
2821 no_match_aspath_cmd,
2822 "no match as-path",
2823 NO_STR
2824 MATCH_STR
2825 "Match BGP AS path list\n")
2826{
2827 return bgp_route_match_delete (vty, vty->index, "as-path", NULL);
2828}
2829
2830ALIAS (no_match_aspath,
2831 no_match_aspath_val_cmd,
2832 "no match as-path WORD",
2833 NO_STR
2834 MATCH_STR
2835 "Match BGP AS path list\n"
2836 "AS path access-list name\n")
2837
2838DEFUN (match_origin,
2839 match_origin_cmd,
2840 "match origin (egp|igp|incomplete)",
2841 MATCH_STR
2842 "BGP origin code\n"
2843 "remote EGP\n"
2844 "local IGP\n"
2845 "unknown heritage\n")
2846{
2847 if (strncmp (argv[0], "igp", 2) == 0)
2848 return bgp_route_match_add (vty, vty->index, "origin", "igp");
2849 if (strncmp (argv[0], "egp", 1) == 0)
2850 return bgp_route_match_add (vty, vty->index, "origin", "egp");
2851 if (strncmp (argv[0], "incomplete", 2) == 0)
2852 return bgp_route_match_add (vty, vty->index, "origin", "incomplete");
2853
2854 return CMD_WARNING;
2855}
2856
2857DEFUN (no_match_origin,
2858 no_match_origin_cmd,
2859 "no match origin",
2860 NO_STR
2861 MATCH_STR
2862 "BGP origin code\n")
2863{
2864 return bgp_route_match_delete (vty, vty->index, "origin", NULL);
2865}
2866
2867ALIAS (no_match_origin,
2868 no_match_origin_val_cmd,
2869 "no match origin (egp|igp|incomplete)",
2870 NO_STR
2871 MATCH_STR
2872 "BGP origin code\n"
2873 "remote EGP\n"
2874 "local IGP\n"
2875 "unknown heritage\n")
2876
2877DEFUN (set_ip_nexthop,
2878 set_ip_nexthop_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002879 "set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002880 SET_STR
2881 IP_STR
2882 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002883 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002884{
2885 union sockunion su;
2886 int ret;
2887
2888 ret = str2sockunion (argv[0], &su);
2889 if (ret < 0)
2890 {
2891 vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
2892 return CMD_WARNING;
2893 }
2894
2895 return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
2896}
2897
paulaf5cd0a2003-11-02 07:24:40 +00002898DEFUN (set_ip_nexthop_peer,
2899 set_ip_nexthop_peer_cmd,
2900 "set ip next-hop peer-address",
2901 SET_STR
2902 IP_STR
2903 "Next hop address\n"
2904 "Use peer address (for BGP only)\n")
2905{
2906 return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address");
2907}
2908
paul94f2b392005-06-28 12:44:16 +00002909DEFUN_DEPRECATED (no_set_ip_nexthop_peer,
paulaf5cd0a2003-11-02 07:24:40 +00002910 no_set_ip_nexthop_peer_cmd,
2911 "no set ip next-hop peer-address",
2912 NO_STR
2913 SET_STR
2914 IP_STR
2915 "Next hop address\n"
2916 "Use peer address (for BGP only)\n")
2917{
2918 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2919}
2920
2921
paul718e3742002-12-13 20:15:29 +00002922DEFUN (no_set_ip_nexthop,
2923 no_set_ip_nexthop_cmd,
2924 "no set ip next-hop",
2925 NO_STR
2926 SET_STR
paul718e3742002-12-13 20:15:29 +00002927 "Next hop address\n")
2928{
paulaf5cd0a2003-11-02 07:24:40 +00002929 if (argc == 0)
paul718e3742002-12-13 20:15:29 +00002930 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2931
2932 return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
2933}
2934
2935ALIAS (no_set_ip_nexthop,
2936 no_set_ip_nexthop_val_cmd,
paulaf5cd0a2003-11-02 07:24:40 +00002937 "no set ip next-hop A.B.C.D",
paul718e3742002-12-13 20:15:29 +00002938 NO_STR
2939 SET_STR
2940 IP_STR
2941 "Next hop address\n"
paulaf5cd0a2003-11-02 07:24:40 +00002942 "IP address of next hop\n")
paul718e3742002-12-13 20:15:29 +00002943
2944DEFUN (set_metric,
2945 set_metric_cmd,
paul73ffb252003-04-19 15:49:49 +00002946 "set metric <0-4294967295>",
paul718e3742002-12-13 20:15:29 +00002947 SET_STR
2948 "Metric value for destination routing protocol\n"
paul73ffb252003-04-19 15:49:49 +00002949 "Metric value\n")
paul718e3742002-12-13 20:15:29 +00002950{
2951 return bgp_route_set_add (vty, vty->index, "metric", argv[0]);
2952}
2953
paul73ffb252003-04-19 15:49:49 +00002954ALIAS (set_metric,
2955 set_metric_addsub_cmd,
2956 "set metric <+/-metric>",
2957 SET_STR
2958 "Metric value for destination routing protocol\n"
hasso033e8612005-05-28 04:50:54 +00002959 "Add or subtract metric\n")
paul73ffb252003-04-19 15:49:49 +00002960
paul718e3742002-12-13 20:15:29 +00002961DEFUN (no_set_metric,
2962 no_set_metric_cmd,
2963 "no set metric",
2964 NO_STR
2965 SET_STR
2966 "Metric value for destination routing protocol\n")
2967{
2968 if (argc == 0)
2969 return bgp_route_set_delete (vty, vty->index, "metric", NULL);
2970
2971 return bgp_route_set_delete (vty, vty->index, "metric", argv[0]);
2972}
2973
2974ALIAS (no_set_metric,
2975 no_set_metric_val_cmd,
2976 "no set metric <0-4294967295>",
2977 NO_STR
2978 SET_STR
2979 "Metric value for destination routing protocol\n"
2980 "Metric value\n")
2981
2982DEFUN (set_local_pref,
2983 set_local_pref_cmd,
2984 "set local-preference <0-4294967295>",
2985 SET_STR
2986 "BGP local preference path attribute\n"
2987 "Preference value\n")
2988{
2989 return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]);
2990}
2991
2992DEFUN (no_set_local_pref,
2993 no_set_local_pref_cmd,
2994 "no set local-preference",
2995 NO_STR
2996 SET_STR
2997 "BGP local preference path attribute\n")
2998{
2999 if (argc == 0)
3000 return bgp_route_set_delete (vty, vty->index, "local-preference", NULL);
3001
3002 return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]);
3003}
3004
3005ALIAS (no_set_local_pref,
3006 no_set_local_pref_val_cmd,
3007 "no set local-preference <0-4294967295>",
3008 NO_STR
3009 SET_STR
3010 "BGP local preference path attribute\n"
3011 "Preference value\n")
3012
3013DEFUN (set_weight,
3014 set_weight_cmd,
3015 "set weight <0-4294967295>",
3016 SET_STR
3017 "BGP weight for routing table\n"
3018 "Weight value\n")
3019{
3020 return bgp_route_set_add (vty, vty->index, "weight", argv[0]);
3021}
3022
3023DEFUN (no_set_weight,
3024 no_set_weight_cmd,
3025 "no set weight",
3026 NO_STR
3027 SET_STR
3028 "BGP weight for routing table\n")
3029{
3030 if (argc == 0)
3031 return bgp_route_set_delete (vty, vty->index, "weight", NULL);
3032
3033 return bgp_route_set_delete (vty, vty->index, "weight", argv[0]);
3034}
3035
3036ALIAS (no_set_weight,
3037 no_set_weight_val_cmd,
3038 "no set weight <0-4294967295>",
3039 NO_STR
3040 SET_STR
3041 "BGP weight for routing table\n"
3042 "Weight value\n")
3043
3044DEFUN (set_aspath_prepend,
3045 set_aspath_prepend_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003046 "set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003047 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003048 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003049 "Prepend to the as-path\n"
3050 "AS number\n")
3051{
3052 int ret;
3053 char *str;
3054
3055 str = argv_concat (argv, argc, 0);
3056 ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str);
3057 XFREE (MTYPE_TMP, str);
3058
3059 return ret;
3060}
3061
3062DEFUN (no_set_aspath_prepend,
3063 no_set_aspath_prepend_cmd,
3064 "no set as-path prepend",
3065 NO_STR
3066 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003067 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003068 "Prepend to the as-path\n")
3069{
Denis Ovsienkoa7f93f32007-12-18 15:13:06 +00003070 int ret;
3071 char *str;
3072
3073 if (argc == 0)
3074 return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL);
3075
3076 str = argv_concat (argv, argc, 0);
3077 ret = bgp_route_set_delete (vty, vty->index, "as-path prepend", str);
3078 XFREE (MTYPE_TMP, str);
3079 return ret;
paul718e3742002-12-13 20:15:29 +00003080}
3081
3082ALIAS (no_set_aspath_prepend,
3083 no_set_aspath_prepend_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003084 "no set as-path prepend ." CMD_AS_RANGE,
paul718e3742002-12-13 20:15:29 +00003085 NO_STR
3086 SET_STR
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003087 "Transform BGP AS_PATH attribute\n"
paul718e3742002-12-13 20:15:29 +00003088 "Prepend to the as-path\n"
3089 "AS number\n")
3090
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003091DEFUN (set_aspath_exclude,
3092 set_aspath_exclude_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003093 "set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003094 SET_STR
3095 "Transform BGP AS-path attribute\n"
3096 "Exclude from the as-path\n"
3097 "AS number\n")
3098{
3099 int ret;
3100 char *str;
3101
3102 str = argv_concat (argv, argc, 0);
3103 ret = bgp_route_set_add (vty, vty->index, "as-path exclude", str);
3104 XFREE (MTYPE_TMP, str);
3105 return ret;
3106}
3107
3108DEFUN (no_set_aspath_exclude,
3109 no_set_aspath_exclude_cmd,
3110 "no set as-path exclude",
3111 NO_STR
3112 SET_STR
3113 "Transform BGP AS_PATH attribute\n"
3114 "Exclude from the as-path\n")
3115{
3116 int ret;
3117 char *str;
3118
3119 if (argc == 0)
3120 return bgp_route_set_delete (vty, vty->index, "as-path exclude", NULL);
3121
3122 str = argv_concat (argv, argc, 0);
3123 ret = bgp_route_set_delete (vty, vty->index, "as-path exclude", str);
3124 XFREE (MTYPE_TMP, str);
3125 return ret;
3126}
3127
3128ALIAS (no_set_aspath_exclude,
3129 no_set_aspath_exclude_val_cmd,
Denis Ovsienko10819ec2009-06-09 15:15:33 +04003130 "no set as-path exclude ." CMD_AS_RANGE,
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003131 NO_STR
3132 SET_STR
3133 "Transform BGP AS_PATH attribute\n"
3134 "Exclude from the as-path\n"
3135 "AS number\n")
3136
paul718e3742002-12-13 20:15:29 +00003137DEFUN (set_community,
3138 set_community_cmd,
3139 "set community .AA:NN",
3140 SET_STR
3141 "BGP community attribute\n"
3142 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3143{
3144 int i;
3145 int first = 0;
3146 int additive = 0;
3147 struct buffer *b;
3148 struct community *com = NULL;
3149 char *str;
3150 char *argstr;
3151 int ret;
3152
3153 b = buffer_new (1024);
3154
3155 for (i = 0; i < argc; i++)
3156 {
3157 if (strncmp (argv[i], "additive", strlen (argv[i])) == 0)
3158 {
3159 additive = 1;
3160 continue;
3161 }
3162
3163 if (first)
3164 buffer_putc (b, ' ');
3165 else
3166 first = 1;
3167
3168 if (strncmp (argv[i], "internet", strlen (argv[i])) == 0)
3169 {
3170 buffer_putstr (b, "internet");
3171 continue;
3172 }
3173 if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0)
3174 {
3175 buffer_putstr (b, "local-AS");
3176 continue;
3177 }
3178 if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0
3179 && strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0)
3180 {
3181 buffer_putstr (b, "no-advertise");
3182 continue;
3183 }
3184 if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0
3185 && strncmp (argv[i], "no-export", strlen (argv[i])) == 0)
3186 {
3187 buffer_putstr (b, "no-export");
3188 continue;
3189 }
3190 buffer_putstr (b, argv[i]);
3191 }
3192 buffer_putc (b, '\0');
3193
3194 /* Fetch result string then compile it to communities attribute. */
3195 str = buffer_getstr (b);
3196 buffer_free (b);
3197
3198 if (str)
3199 {
3200 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00003201 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00003202 }
3203
3204 /* Can't compile user input into communities attribute. */
3205 if (! com)
3206 {
3207 vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE);
3208 return CMD_WARNING;
3209 }
3210
3211 /* Set communites attribute string. */
3212 str = community_str (com);
3213
3214 if (additive)
3215 {
3216 argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1);
3217 strcpy (argstr, str);
3218 strcpy (argstr + strlen (str), " additive");
3219 ret = bgp_route_set_add (vty, vty->index, "community", argstr);
3220 XFREE (MTYPE_TMP, argstr);
3221 }
3222 else
3223 ret = bgp_route_set_add (vty, vty->index, "community", str);
3224
3225 community_free (com);
3226
3227 return ret;
3228}
3229
3230DEFUN (set_community_none,
3231 set_community_none_cmd,
3232 "set community none",
3233 SET_STR
3234 "BGP community attribute\n"
3235 "No community attribute\n")
3236{
3237 return bgp_route_set_add (vty, vty->index, "community", "none");
3238}
3239
3240DEFUN (no_set_community,
3241 no_set_community_cmd,
3242 "no set community",
3243 NO_STR
3244 SET_STR
3245 "BGP community attribute\n")
3246{
3247 return bgp_route_set_delete (vty, vty->index, "community", NULL);
3248}
3249
3250ALIAS (no_set_community,
3251 no_set_community_val_cmd,
3252 "no set community .AA:NN",
3253 NO_STR
3254 SET_STR
3255 "BGP community attribute\n"
3256 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3257
3258ALIAS (no_set_community,
3259 no_set_community_none_cmd,
3260 "no set community none",
3261 NO_STR
3262 SET_STR
3263 "BGP community attribute\n"
3264 "No community attribute\n")
3265
3266DEFUN (set_community_delete,
3267 set_community_delete_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003268 "set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003269 SET_STR
3270 "set BGP community list (for deletion)\n"
3271 "Community-list number (standard)\n"
3272 "Communitly-list number (expanded)\n"
3273 "Community-list name\n"
3274 "Delete matching communities\n")
3275{
3276 char *str;
3277
3278 str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1);
3279 strcpy (str, argv[0]);
3280 strcpy (str + strlen (argv[0]), " delete");
3281
3282 bgp_route_set_add (vty, vty->index, "comm-list", str);
3283
3284 XFREE (MTYPE_TMP, str);
3285 return CMD_SUCCESS;
3286}
3287
3288DEFUN (no_set_community_delete,
3289 no_set_community_delete_cmd,
3290 "no set comm-list",
3291 NO_STR
3292 SET_STR
3293 "set BGP community list (for deletion)\n")
3294{
3295 return bgp_route_set_delete (vty, vty->index, "comm-list", NULL);
3296}
3297
3298ALIAS (no_set_community_delete,
3299 no_set_community_delete_val_cmd,
hassofee6e4e2005-02-02 16:29:31 +00003300 "no set comm-list (<1-99>|<100-500>|WORD) delete",
paul718e3742002-12-13 20:15:29 +00003301 NO_STR
3302 SET_STR
3303 "set BGP community list (for deletion)\n"
3304 "Community-list number (standard)\n"
3305 "Communitly-list number (expanded)\n"
3306 "Community-list name\n"
3307 "Delete matching communities\n")
3308
3309DEFUN (set_ecommunity_rt,
3310 set_ecommunity_rt_cmd,
3311 "set extcommunity rt .ASN:nn_or_IP-address:nn",
3312 SET_STR
3313 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003314 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003315 "VPN extended community\n")
3316{
3317 int ret;
3318 char *str;
3319
3320 str = argv_concat (argv, argc, 0);
3321 ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str);
3322 XFREE (MTYPE_TMP, str);
3323
3324 return ret;
3325}
3326
3327DEFUN (no_set_ecommunity_rt,
3328 no_set_ecommunity_rt_cmd,
3329 "no set extcommunity rt",
3330 NO_STR
3331 SET_STR
3332 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003333 "Route Target extended community\n")
paul718e3742002-12-13 20:15:29 +00003334{
3335 return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL);
3336}
3337
3338ALIAS (no_set_ecommunity_rt,
3339 no_set_ecommunity_rt_val_cmd,
3340 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
3341 NO_STR
3342 SET_STR
3343 "BGP extended community attribute\n"
Denis Ovsienkoe6b6a562009-06-01 20:20:36 +04003344 "Route Target extended community\n"
paul718e3742002-12-13 20:15:29 +00003345 "VPN extended community\n")
3346
3347DEFUN (set_ecommunity_soo,
3348 set_ecommunity_soo_cmd,
3349 "set extcommunity soo .ASN:nn_or_IP-address:nn",
3350 SET_STR
3351 "BGP extended community attribute\n"
3352 "Site-of-Origin extended community\n"
3353 "VPN extended community\n")
3354{
3355 int ret;
3356 char *str;
3357
3358 str = argv_concat (argv, argc, 0);
3359 ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str);
3360 XFREE (MTYPE_TMP, str);
3361 return ret;
3362}
3363
3364DEFUN (no_set_ecommunity_soo,
3365 no_set_ecommunity_soo_cmd,
3366 "no set extcommunity soo",
3367 NO_STR
3368 SET_STR
3369 "BGP extended community attribute\n"
3370 "Site-of-Origin extended community\n")
3371{
3372 return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL);
3373}
3374
3375ALIAS (no_set_ecommunity_soo,
3376 no_set_ecommunity_soo_val_cmd,
3377 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
3378 NO_STR
3379 SET_STR
3380 "BGP extended community attribute\n"
3381 "Site-of-Origin extended community\n"
3382 "VPN extended community\n")
3383
3384DEFUN (set_origin,
3385 set_origin_cmd,
3386 "set origin (egp|igp|incomplete)",
3387 SET_STR
3388 "BGP origin code\n"
3389 "remote EGP\n"
3390 "local IGP\n"
3391 "unknown heritage\n")
3392{
3393 if (strncmp (argv[0], "igp", 2) == 0)
3394 return bgp_route_set_add (vty, vty->index, "origin", "igp");
3395 if (strncmp (argv[0], "egp", 1) == 0)
3396 return bgp_route_set_add (vty, vty->index, "origin", "egp");
3397 if (strncmp (argv[0], "incomplete", 2) == 0)
3398 return bgp_route_set_add (vty, vty->index, "origin", "incomplete");
3399
3400 return CMD_WARNING;
3401}
3402
3403DEFUN (no_set_origin,
3404 no_set_origin_cmd,
3405 "no set origin",
3406 NO_STR
3407 SET_STR
3408 "BGP origin code\n")
3409{
3410 return bgp_route_set_delete (vty, vty->index, "origin", NULL);
3411}
3412
3413ALIAS (no_set_origin,
3414 no_set_origin_val_cmd,
3415 "no set origin (egp|igp|incomplete)",
3416 NO_STR
3417 SET_STR
3418 "BGP origin code\n"
3419 "remote EGP\n"
3420 "local IGP\n"
3421 "unknown heritage\n")
3422
3423DEFUN (set_atomic_aggregate,
3424 set_atomic_aggregate_cmd,
3425 "set atomic-aggregate",
3426 SET_STR
3427 "BGP atomic aggregate attribute\n" )
3428{
3429 return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL);
3430}
3431
3432DEFUN (no_set_atomic_aggregate,
3433 no_set_atomic_aggregate_cmd,
3434 "no set atomic-aggregate",
3435 NO_STR
3436 SET_STR
3437 "BGP atomic aggregate attribute\n" )
3438{
3439 return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL);
3440}
3441
3442DEFUN (set_aggregator_as,
3443 set_aggregator_as_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003444 "set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003445 SET_STR
3446 "BGP aggregator attribute\n"
3447 "AS number of aggregator\n"
3448 "AS number\n"
3449 "IP address of aggregator\n")
3450{
3451 int ret;
3452 as_t as;
3453 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003454 char *argstr;
3455
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003456 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paulfd79ac92004-10-13 05:06:08 +00003457
paul718e3742002-12-13 20:15:29 +00003458 ret = inet_aton (argv[1], &address);
3459 if (ret == 0)
3460 {
3461 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3462 return CMD_WARNING;
3463 }
3464
3465 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3466 strlen (argv[0]) + strlen (argv[1]) + 2);
3467
3468 sprintf (argstr, "%s %s", argv[0], argv[1]);
3469
3470 ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr);
3471
3472 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3473
3474 return ret;
3475}
3476
3477DEFUN (no_set_aggregator_as,
3478 no_set_aggregator_as_cmd,
3479 "no set aggregator as",
3480 NO_STR
3481 SET_STR
3482 "BGP aggregator attribute\n"
3483 "AS number of aggregator\n")
3484{
3485 int ret;
3486 as_t as;
3487 struct in_addr address;
paul718e3742002-12-13 20:15:29 +00003488 char *argstr;
3489
3490 if (argv == 0)
3491 return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL);
3492
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00003493 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
paul718e3742002-12-13 20:15:29 +00003494
3495 ret = inet_aton (argv[1], &address);
3496 if (ret == 0)
3497 {
3498 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3499 return CMD_WARNING;
3500 }
3501
3502 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3503 strlen (argv[0]) + strlen (argv[1]) + 2);
3504
3505 sprintf (argstr, "%s %s", argv[0], argv[1]);
3506
3507 ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr);
3508
3509 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3510
3511 return ret;
3512}
3513
3514ALIAS (no_set_aggregator_as,
3515 no_set_aggregator_as_val_cmd,
Paul Jakma320da872008-07-02 13:40:33 +00003516 "no set aggregator as " CMD_AS_RANGE " A.B.C.D",
paul718e3742002-12-13 20:15:29 +00003517 NO_STR
3518 SET_STR
3519 "BGP aggregator attribute\n"
3520 "AS number of aggregator\n"
3521 "AS number\n"
3522 "IP address of aggregator\n")
3523
David Lamparter6b0655a2014-06-04 06:53:35 +02003524
paul718e3742002-12-13 20:15:29 +00003525#ifdef HAVE_IPV6
3526DEFUN (match_ipv6_address,
3527 match_ipv6_address_cmd,
3528 "match ipv6 address WORD",
3529 MATCH_STR
3530 IPV6_STR
3531 "Match IPv6 address of route\n"
3532 "IPv6 access-list name\n")
3533{
3534 return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]);
3535}
3536
3537DEFUN (no_match_ipv6_address,
3538 no_match_ipv6_address_cmd,
3539 "no match ipv6 address WORD",
3540 NO_STR
3541 MATCH_STR
3542 IPV6_STR
3543 "Match IPv6 address of route\n"
3544 "IPv6 access-list name\n")
3545{
3546 return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]);
3547}
3548
3549DEFUN (match_ipv6_next_hop,
3550 match_ipv6_next_hop_cmd,
3551 "match ipv6 next-hop X:X::X:X",
3552 MATCH_STR
3553 IPV6_STR
3554 "Match IPv6 next-hop address of route\n"
3555 "IPv6 address of next hop\n")
3556{
3557 return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]);
3558}
3559
3560DEFUN (no_match_ipv6_next_hop,
3561 no_match_ipv6_next_hop_cmd,
3562 "no match ipv6 next-hop X:X::X:X",
3563 NO_STR
3564 MATCH_STR
3565 IPV6_STR
3566 "Match IPv6 next-hop address of route\n"
3567 "IPv6 address of next hop\n")
3568{
3569 return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
3570}
3571
3572DEFUN (match_ipv6_address_prefix_list,
3573 match_ipv6_address_prefix_list_cmd,
3574 "match ipv6 address prefix-list WORD",
3575 MATCH_STR
3576 IPV6_STR
3577 "Match address of route\n"
3578 "Match entries of prefix-lists\n"
3579 "IP prefix-list name\n")
3580{
3581 return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3582}
3583
3584DEFUN (no_match_ipv6_address_prefix_list,
3585 no_match_ipv6_address_prefix_list_cmd,
3586 "no match ipv6 address prefix-list WORD",
3587 NO_STR
3588 MATCH_STR
3589 IPV6_STR
3590 "Match address of route\n"
3591 "Match entries of prefix-lists\n"
3592 "IP prefix-list name\n")
3593{
3594 return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3595}
3596
3597DEFUN (set_ipv6_nexthop_global,
3598 set_ipv6_nexthop_global_cmd,
3599 "set ipv6 next-hop global X:X::X:X",
3600 SET_STR
3601 IPV6_STR
3602 "IPv6 next-hop address\n"
3603 "IPv6 global address\n"
3604 "IPv6 address of next hop\n")
3605{
3606 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]);
3607}
3608
3609DEFUN (no_set_ipv6_nexthop_global,
3610 no_set_ipv6_nexthop_global_cmd,
3611 "no set ipv6 next-hop global",
3612 NO_STR
3613 SET_STR
3614 IPV6_STR
3615 "IPv6 next-hop address\n"
3616 "IPv6 global address\n")
3617{
3618 if (argc == 0)
3619 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL);
3620
3621 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]);
3622}
3623
3624ALIAS (no_set_ipv6_nexthop_global,
3625 no_set_ipv6_nexthop_global_val_cmd,
3626 "no set ipv6 next-hop global X:X::X:X",
3627 NO_STR
3628 SET_STR
3629 IPV6_STR
3630 "IPv6 next-hop address\n"
3631 "IPv6 global address\n"
3632 "IPv6 address of next hop\n")
3633
3634DEFUN (set_ipv6_nexthop_local,
3635 set_ipv6_nexthop_local_cmd,
3636 "set ipv6 next-hop local X:X::X:X",
3637 SET_STR
3638 IPV6_STR
3639 "IPv6 next-hop address\n"
3640 "IPv6 local address\n"
3641 "IPv6 address of next hop\n")
3642{
3643 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
3644}
3645
3646DEFUN (no_set_ipv6_nexthop_local,
3647 no_set_ipv6_nexthop_local_cmd,
3648 "no set ipv6 next-hop local",
3649 NO_STR
3650 SET_STR
3651 IPV6_STR
3652 "IPv6 next-hop address\n"
3653 "IPv6 local address\n")
3654{
3655 if (argc == 0)
3656 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
3657
3658 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
3659}
3660
3661ALIAS (no_set_ipv6_nexthop_local,
3662 no_set_ipv6_nexthop_local_val_cmd,
3663 "no set ipv6 next-hop local X:X::X:X",
3664 NO_STR
3665 SET_STR
3666 IPV6_STR
3667 "IPv6 next-hop address\n"
3668 "IPv6 local address\n"
3669 "IPv6 address of next hop\n")
3670#endif /* HAVE_IPV6 */
3671
3672DEFUN (set_vpnv4_nexthop,
3673 set_vpnv4_nexthop_cmd,
3674 "set vpnv4 next-hop A.B.C.D",
3675 SET_STR
3676 "VPNv4 information\n"
3677 "VPNv4 next-hop address\n"
3678 "IP address of next hop\n")
3679{
3680 return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]);
3681}
3682
3683DEFUN (no_set_vpnv4_nexthop,
3684 no_set_vpnv4_nexthop_cmd,
3685 "no set vpnv4 next-hop",
3686 NO_STR
3687 SET_STR
3688 "VPNv4 information\n"
3689 "VPNv4 next-hop address\n")
3690{
3691 if (argc == 0)
3692 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL);
3693
3694 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]);
3695}
3696
3697ALIAS (no_set_vpnv4_nexthop,
3698 no_set_vpnv4_nexthop_val_cmd,
3699 "no set vpnv4 next-hop A.B.C.D",
3700 NO_STR
3701 SET_STR
3702 "VPNv4 information\n"
3703 "VPNv4 next-hop address\n"
3704 "IP address of next hop\n")
3705
3706DEFUN (set_originator_id,
3707 set_originator_id_cmd,
3708 "set originator-id A.B.C.D",
3709 SET_STR
3710 "BGP originator ID attribute\n"
3711 "IP address of originator\n")
3712{
3713 return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]);
3714}
3715
3716DEFUN (no_set_originator_id,
3717 no_set_originator_id_cmd,
3718 "no set originator-id",
3719 NO_STR
3720 SET_STR
3721 "BGP originator ID attribute\n")
3722{
3723 if (argc == 0)
3724 return bgp_route_set_delete (vty, vty->index, "originator-id", NULL);
3725
3726 return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]);
3727}
3728
3729ALIAS (no_set_originator_id,
3730 no_set_originator_id_val_cmd,
3731 "no set originator-id A.B.C.D",
3732 NO_STR
3733 SET_STR
3734 "BGP originator ID attribute\n"
3735 "IP address of originator\n")
3736
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003737DEFUN_DEPRECATED (set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003738 set_pathlimit_ttl_cmd,
3739 "set pathlimit ttl <1-255>",
3740 SET_STR
3741 "BGP AS-Pathlimit attribute\n"
3742 "Set AS-Path Hop-count TTL\n")
3743{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003744 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003745}
3746
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003747DEFUN_DEPRECATED (no_set_pathlimit_ttl,
Paul Jakma41367172007-08-06 15:24:51 +00003748 no_set_pathlimit_ttl_cmd,
3749 "no set pathlimit ttl",
3750 NO_STR
3751 SET_STR
3752 "BGP AS-Pathlimit attribute\n"
3753 "Set AS-Path Hop-count TTL\n")
3754{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003755 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003756}
3757
3758ALIAS (no_set_pathlimit_ttl,
3759 no_set_pathlimit_ttl_val_cmd,
3760 "no set pathlimit ttl <1-255>",
3761 NO_STR
3762 MATCH_STR
3763 "BGP AS-Pathlimit attribute\n"
3764 "Set AS-Path Hop-count TTL\n")
3765
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003766DEFUN_DEPRECATED (match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003767 match_pathlimit_as_cmd,
3768 "match pathlimit as <1-65535>",
3769 MATCH_STR
3770 "BGP AS-Pathlimit attribute\n"
3771 "Match Pathlimit AS number\n")
3772{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003773 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003774}
3775
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003776DEFUN_DEPRECATED (no_match_pathlimit_as,
Paul Jakma41367172007-08-06 15:24:51 +00003777 no_match_pathlimit_as_cmd,
3778 "no match pathlimit as",
3779 NO_STR
3780 MATCH_STR
3781 "BGP AS-Pathlimit attribute\n"
3782 "Match Pathlimit AS number\n")
3783{
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003784 return CMD_SUCCESS;
Paul Jakma41367172007-08-06 15:24:51 +00003785}
3786
3787ALIAS (no_match_pathlimit_as,
3788 no_match_pathlimit_as_val_cmd,
3789 "no match pathlimit as <1-65535>",
3790 NO_STR
3791 MATCH_STR
3792 "BGP AS-Pathlimit attribute\n"
3793 "Match Pathlimit ASN\n")
3794
David Lamparter6b0655a2014-06-04 06:53:35 +02003795
paul718e3742002-12-13 20:15:29 +00003796/* Initialization of route map. */
3797void
paul94f2b392005-06-28 12:44:16 +00003798bgp_route_map_init (void)
paul718e3742002-12-13 20:15:29 +00003799{
3800 route_map_init ();
3801 route_map_init_vty ();
3802 route_map_add_hook (bgp_route_map_update);
3803 route_map_delete_hook (bgp_route_map_update);
3804
paulfee0f4c2004-09-13 05:12:46 +00003805 route_map_install_match (&route_match_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003806 route_map_install_match (&route_match_ip_address_cmd);
3807 route_map_install_match (&route_match_ip_next_hop_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003808 route_map_install_match (&route_match_ip_route_source_cmd);
paul718e3742002-12-13 20:15:29 +00003809 route_map_install_match (&route_match_ip_address_prefix_list_cmd);
3810 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003811 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +00003812 route_map_install_match (&route_match_aspath_cmd);
3813 route_map_install_match (&route_match_community_cmd);
paul73ffb252003-04-19 15:49:49 +00003814 route_map_install_match (&route_match_ecommunity_cmd);
paul718e3742002-12-13 20:15:29 +00003815 route_map_install_match (&route_match_metric_cmd);
3816 route_map_install_match (&route_match_origin_cmd);
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +04003817 route_map_install_match (&route_match_probability_cmd);
paul718e3742002-12-13 20:15:29 +00003818
3819 route_map_install_set (&route_set_ip_nexthop_cmd);
3820 route_map_install_set (&route_set_local_pref_cmd);
3821 route_map_install_set (&route_set_weight_cmd);
3822 route_map_install_set (&route_set_metric_cmd);
3823 route_map_install_set (&route_set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003824 route_map_install_set (&route_set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003825 route_map_install_set (&route_set_origin_cmd);
3826 route_map_install_set (&route_set_atomic_aggregate_cmd);
3827 route_map_install_set (&route_set_aggregator_as_cmd);
3828 route_map_install_set (&route_set_community_cmd);
3829 route_map_install_set (&route_set_community_delete_cmd);
3830 route_map_install_set (&route_set_vpnv4_nexthop_cmd);
3831 route_map_install_set (&route_set_originator_id_cmd);
3832 route_map_install_set (&route_set_ecommunity_rt_cmd);
3833 route_map_install_set (&route_set_ecommunity_soo_cmd);
3834
paulfee0f4c2004-09-13 05:12:46 +00003835 install_element (RMAP_NODE, &match_peer_cmd);
3836 install_element (RMAP_NODE, &match_peer_local_cmd);
3837 install_element (RMAP_NODE, &no_match_peer_cmd);
3838 install_element (RMAP_NODE, &no_match_peer_val_cmd);
3839 install_element (RMAP_NODE, &no_match_peer_local_cmd);
paul718e3742002-12-13 20:15:29 +00003840 install_element (RMAP_NODE, &match_ip_address_cmd);
3841 install_element (RMAP_NODE, &no_match_ip_address_cmd);
3842 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
3843 install_element (RMAP_NODE, &match_ip_next_hop_cmd);
3844 install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
3845 install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003846 install_element (RMAP_NODE, &match_ip_route_source_cmd);
3847 install_element (RMAP_NODE, &no_match_ip_route_source_cmd);
3848 install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd);
paul718e3742002-12-13 20:15:29 +00003849 install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
3850 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
3851 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
3852 install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
3853 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
3854 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
hassoc1643bb2005-02-02 16:43:17 +00003855 install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
3856 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
3857 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd);
paul718e3742002-12-13 20:15:29 +00003858
3859 install_element (RMAP_NODE, &match_aspath_cmd);
3860 install_element (RMAP_NODE, &no_match_aspath_cmd);
3861 install_element (RMAP_NODE, &no_match_aspath_val_cmd);
3862 install_element (RMAP_NODE, &match_metric_cmd);
3863 install_element (RMAP_NODE, &no_match_metric_cmd);
3864 install_element (RMAP_NODE, &no_match_metric_val_cmd);
3865 install_element (RMAP_NODE, &match_community_cmd);
3866 install_element (RMAP_NODE, &match_community_exact_cmd);
3867 install_element (RMAP_NODE, &no_match_community_cmd);
3868 install_element (RMAP_NODE, &no_match_community_val_cmd);
3869 install_element (RMAP_NODE, &no_match_community_exact_cmd);
paul73ffb252003-04-19 15:49:49 +00003870 install_element (RMAP_NODE, &match_ecommunity_cmd);
3871 install_element (RMAP_NODE, &no_match_ecommunity_cmd);
3872 install_element (RMAP_NODE, &no_match_ecommunity_val_cmd);
paul718e3742002-12-13 20:15:29 +00003873 install_element (RMAP_NODE, &match_origin_cmd);
3874 install_element (RMAP_NODE, &no_match_origin_cmd);
3875 install_element (RMAP_NODE, &no_match_origin_val_cmd);
Vyacheslav Trushkin1add1152011-11-22 20:15:10 +04003876 install_element (RMAP_NODE, &match_probability_cmd);
3877 install_element (RMAP_NODE, &no_match_probability_cmd);
3878 install_element (RMAP_NODE, &no_match_probability_val_cmd);
paul718e3742002-12-13 20:15:29 +00003879
3880 install_element (RMAP_NODE, &set_ip_nexthop_cmd);
paulaf5cd0a2003-11-02 07:24:40 +00003881 install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd);
paul718e3742002-12-13 20:15:29 +00003882 install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
3883 install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
3884 install_element (RMAP_NODE, &set_local_pref_cmd);
3885 install_element (RMAP_NODE, &no_set_local_pref_cmd);
3886 install_element (RMAP_NODE, &no_set_local_pref_val_cmd);
3887 install_element (RMAP_NODE, &set_weight_cmd);
3888 install_element (RMAP_NODE, &no_set_weight_cmd);
3889 install_element (RMAP_NODE, &no_set_weight_val_cmd);
3890 install_element (RMAP_NODE, &set_metric_cmd);
paul73ffb252003-04-19 15:49:49 +00003891 install_element (RMAP_NODE, &set_metric_addsub_cmd);
paul718e3742002-12-13 20:15:29 +00003892 install_element (RMAP_NODE, &no_set_metric_cmd);
3893 install_element (RMAP_NODE, &no_set_metric_val_cmd);
3894 install_element (RMAP_NODE, &set_aspath_prepend_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003895 install_element (RMAP_NODE, &set_aspath_exclude_cmd);
paul718e3742002-12-13 20:15:29 +00003896 install_element (RMAP_NODE, &no_set_aspath_prepend_cmd);
3897 install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd);
Denis Ovsienko841f7a52008-04-10 11:47:45 +00003898 install_element (RMAP_NODE, &no_set_aspath_exclude_cmd);
3899 install_element (RMAP_NODE, &no_set_aspath_exclude_val_cmd);
paul718e3742002-12-13 20:15:29 +00003900 install_element (RMAP_NODE, &set_origin_cmd);
3901 install_element (RMAP_NODE, &no_set_origin_cmd);
3902 install_element (RMAP_NODE, &no_set_origin_val_cmd);
3903 install_element (RMAP_NODE, &set_atomic_aggregate_cmd);
3904 install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd);
3905 install_element (RMAP_NODE, &set_aggregator_as_cmd);
3906 install_element (RMAP_NODE, &no_set_aggregator_as_cmd);
3907 install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd);
3908 install_element (RMAP_NODE, &set_community_cmd);
3909 install_element (RMAP_NODE, &set_community_none_cmd);
3910 install_element (RMAP_NODE, &no_set_community_cmd);
3911 install_element (RMAP_NODE, &no_set_community_val_cmd);
3912 install_element (RMAP_NODE, &no_set_community_none_cmd);
3913 install_element (RMAP_NODE, &set_community_delete_cmd);
3914 install_element (RMAP_NODE, &no_set_community_delete_cmd);
3915 install_element (RMAP_NODE, &no_set_community_delete_val_cmd);
3916 install_element (RMAP_NODE, &set_ecommunity_rt_cmd);
3917 install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd);
3918 install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd);
3919 install_element (RMAP_NODE, &set_ecommunity_soo_cmd);
3920 install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd);
3921 install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd);
3922 install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd);
3923 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd);
3924 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd);
3925 install_element (RMAP_NODE, &set_originator_id_cmd);
3926 install_element (RMAP_NODE, &no_set_originator_id_cmd);
3927 install_element (RMAP_NODE, &no_set_originator_id_val_cmd);
3928
3929#ifdef HAVE_IPV6
3930 route_map_install_match (&route_match_ipv6_address_cmd);
3931 route_map_install_match (&route_match_ipv6_next_hop_cmd);
3932 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd);
3933 route_map_install_set (&route_set_ipv6_nexthop_global_cmd);
3934 route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
Paul Jakma41367172007-08-06 15:24:51 +00003935
paul718e3742002-12-13 20:15:29 +00003936 install_element (RMAP_NODE, &match_ipv6_address_cmd);
3937 install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
3938 install_element (RMAP_NODE, &match_ipv6_next_hop_cmd);
3939 install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd);
3940 install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
3941 install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
3942 install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd);
3943 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
3944 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd);
3945 install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
3946 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
3947 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
3948#endif /* HAVE_IPV6 */
Paul Jakma41367172007-08-06 15:24:51 +00003949
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003950 /* AS-Pathlimit: functionality removed, commands kept for
3951 * compatibility.
3952 */
Paul Jakma41367172007-08-06 15:24:51 +00003953 install_element (RMAP_NODE, &set_pathlimit_ttl_cmd);
3954 install_element (RMAP_NODE, &no_set_pathlimit_ttl_cmd);
3955 install_element (RMAP_NODE, &no_set_pathlimit_ttl_val_cmd);
3956 install_element (RMAP_NODE, &match_pathlimit_as_cmd);
3957 install_element (RMAP_NODE, &no_match_pathlimit_as_cmd);
3958 install_element (RMAP_NODE, &no_match_pathlimit_as_val_cmd);
paul718e3742002-12-13 20:15:29 +00003959}