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