Dmitry Tejblum <tejblum@yandex-team.ru>
[jleu-quagga.git] / bgpd / bgp_routemap.c
blob2d4a863006fa942c045e17de32c4704d0ba7e8e7
1 /* Route map function of bgpd.
2 Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
21 #include <zebra.h>
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"
31 #ifdef HAVE_GNU_REGEX
32 #include <regex.h>
33 #else
34 #include "regex-gnu.h"
35 #endif /* HAVE_GNU_REGEX */
36 #include "buffer.h"
37 #include "sockunion.h"
39 #include "bgpd/bgpd.h"
40 #include "bgpd/bgp_table.h"
41 #include "bgpd/bgp_attr.h"
42 #include "bgpd/bgp_aspath.h"
43 #include "bgpd/bgp_route.h"
44 #include "bgpd/bgp_regex.h"
45 #include "bgpd/bgp_community.h"
46 #include "bgpd/bgp_clist.h"
47 #include "bgpd/bgp_filter.h"
48 #include "bgpd/bgp_mplsvpn.h"
49 #include "bgpd/bgp_ecommunity.h"
50 #include "bgpd/bgp_vty.h"
52 /* Memo of route-map commands.
54 o Cisco route-map
56 match as-path : Done
57 community : Done
58 interface : Not yet
59 ip address : Done
60 ip next-hop : Done
61 ip route-source : Done
62 ip prefix-list : Done
63 ipv6 address : Done
64 ipv6 next-hop : Done
65 ipv6 route-source: (This will not be implemented by bgpd)
66 ipv6 prefix-list : Done
67 length : (This will not be implemented by bgpd)
68 metric : Done
69 route-type : (This will not be implemented by bgpd)
70 tag : (This will not be implemented by bgpd)
72 set as-path prepend : Done
73 as-path tag : Not yet
74 automatic-tag : (This will not be implemented by bgpd)
75 community : Done
76 comm-list : Not yet
77 dampning : Not yet
78 default : (This will not be implemented by bgpd)
79 interface : (This will not be implemented by bgpd)
80 ip default : (This will not be implemented by bgpd)
81 ip next-hop : Done
82 ip precedence : (This will not be implemented by bgpd)
83 ip tos : (This will not be implemented by bgpd)
84 level : (This will not be implemented by bgpd)
85 local-preference : Done
86 metric : Done
87 metric-type : Not yet
88 origin : Done
89 tag : (This will not be implemented by bgpd)
90 weight : Done
91 pathlimit : Done
93 o Local extention
95 set ipv6 next-hop global: Done
96 set ipv6 next-hop local : Done
97 set pathlimit ttl : Done
98 set as-path exclude : Done
99 match pathlimit as : Done
103 /* Compiles either AS or TTL argument. It is amused the VTY code
104 * has already range-checked the values to be suitable as TTL or ASN
106 static void *
107 route_pathlimit_compile (const char *arg)
109 unsigned long tmp;
110 u_int32_t *val;
111 char *endptr = NULL;
113 /* TTL or AS value shoud be integer. */
114 if (! all_digit (arg))
115 return NULL;
117 tmp = strtoul (arg, &endptr, 10);
118 if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX)
119 return NULL;
121 if (!(val = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t))))
122 return NULL;
124 *val = tmp;
126 return val;
129 static void
130 route_pathlimit_free (void *rule)
132 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
135 static route_map_result_t
136 route_match_pathlimit_as (void *rule, struct prefix *prefix, route_map_object_t type,
137 void *object)
139 struct bgp_info *info = object;
140 struct attr *attr = info->attr;
141 uint32_t as = *(uint32_t *)rule;
143 if (type != RMAP_BGP)
144 return RMAP_NOMATCH;
146 if (!attr->pathlimit.as)
147 return RMAP_NOMATCH;
149 if (as == attr->pathlimit.as)
150 return RMAP_MATCH;
152 return RMAP_NOMATCH;
155 /* 'match pathlimit as' */
156 struct route_map_rule_cmd route_match_pathlimit_as_cmd =
158 "pathlimit as",
159 route_match_pathlimit_as,
160 route_pathlimit_compile,
161 route_pathlimit_free
164 /* Set pathlimit TTL. */
165 static route_map_result_t
166 route_set_pathlimit_ttl (void *rule, struct prefix *prefix,
167 route_map_object_t type, void *object)
169 struct bgp_info *info = object;
170 struct attr *attr = info->attr;
171 u_char ttl = *(uint32_t *)rule;
173 if (type == RMAP_BGP)
175 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
176 attr->pathlimit.ttl = ttl;
177 attr->pathlimit.as = 0;
180 return RMAP_OKAY;
183 /* Set local preference rule structure. */
184 struct route_map_rule_cmd route_set_pathlimit_ttl_cmd =
186 "pathlimit ttl",
187 route_set_pathlimit_ttl,
188 route_pathlimit_compile,
189 route_pathlimit_free,
192 /* 'match peer (A.B.C.D|X:X::X:X)' */
194 /* Compares the peer specified in the 'match peer' clause with the peer
195 received in bgp_info->peer. If it is the same, or if the peer structure
196 received is a peer_group containing it, returns RMAP_MATCH. */
197 static route_map_result_t
198 route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type,
199 void *object)
201 union sockunion *su;
202 union sockunion *su2;
203 struct peer_group *group;
204 struct peer *peer;
205 struct listnode *node, *nnode;
207 if (type == RMAP_BGP)
209 su = rule;
210 peer = ((struct bgp_info *) object)->peer;
212 if ( ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT) &&
213 ! CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_EXPORT) )
214 return RMAP_NOMATCH;
216 /* If su='0.0.0.0' (command 'match peer local'), and it's a NETWORK,
217 REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH */
218 su2 = sockunion_str2su ("0.0.0.0");
219 if ( sockunion_same (su, su2) )
221 int ret;
222 if ( CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_NETWORK) ||
223 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE) ||
224 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_DEFAULT))
225 ret = RMAP_MATCH;
226 else
227 ret = RMAP_NOMATCH;
229 sockunion_free (su2);
230 return ret;
232 sockunion_free (su2);
234 if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
236 if (sockunion_same (su, &peer->su))
237 return RMAP_MATCH;
239 return RMAP_NOMATCH;
241 else
243 group = peer->group;
244 for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer))
246 if (sockunion_same (su, &peer->su))
247 return RMAP_MATCH;
249 return RMAP_NOMATCH;
252 return RMAP_NOMATCH;
255 static void *
256 route_match_peer_compile (const char *arg)
258 union sockunion *su;
259 int ret;
261 su = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (union sockunion));
263 ret = str2sockunion ( (arg)? arg : "0.0.0.0", su);
264 if (ret < 0) {
265 XFREE (MTYPE_ROUTE_MAP_COMPILED, su);
266 return NULL;
269 return su;
272 /* Free route map's compiled `ip address' value. */
273 static void
274 route_match_peer_free (void *rule)
276 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
279 /* Route map commands for ip address matching. */
280 struct route_map_rule_cmd route_match_peer_cmd =
282 "peer",
283 route_match_peer,
284 route_match_peer_compile,
285 route_match_peer_free
288 /* `match ip address IP_ACCESS_LIST' */
290 /* Match function should return 1 if match is success else return
291 zero. */
292 static route_map_result_t
293 route_match_ip_address (void *rule, struct prefix *prefix,
294 route_map_object_t type, void *object)
296 struct access_list *alist;
297 /* struct prefix_ipv4 match; */
299 if (type == RMAP_BGP)
301 alist = access_list_lookup (AFI_IP, (char *) rule);
302 if (alist == NULL)
303 return RMAP_NOMATCH;
305 return (access_list_apply (alist, prefix) == FILTER_DENY ?
306 RMAP_NOMATCH : RMAP_MATCH);
308 return RMAP_NOMATCH;
311 /* Route map `ip address' match statement. `arg' should be
312 access-list name. */
313 static void *
314 route_match_ip_address_compile (const char *arg)
316 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
319 /* Free route map's compiled `ip address' value. */
320 static void
321 route_match_ip_address_free (void *rule)
323 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
326 /* Route map commands for ip address matching. */
327 struct route_map_rule_cmd route_match_ip_address_cmd =
329 "ip address",
330 route_match_ip_address,
331 route_match_ip_address_compile,
332 route_match_ip_address_free
335 /* `match ip next-hop IP_ADDRESS' */
337 /* Match function return 1 if match is success else return zero. */
338 static route_map_result_t
339 route_match_ip_next_hop (void *rule, struct prefix *prefix,
340 route_map_object_t type, void *object)
342 struct access_list *alist;
343 struct bgp_info *bgp_info;
344 struct prefix_ipv4 p;
346 if (type == RMAP_BGP)
348 bgp_info = object;
349 p.family = AF_INET;
350 p.prefix = bgp_info->attr->nexthop;
351 p.prefixlen = IPV4_MAX_BITLEN;
353 alist = access_list_lookup (AFI_IP, (char *) rule);
354 if (alist == NULL)
355 return RMAP_NOMATCH;
357 return (access_list_apply (alist, &p) == FILTER_DENY ?
358 RMAP_NOMATCH : RMAP_MATCH);
360 return RMAP_NOMATCH;
363 /* Route map `ip next-hop' match statement. `arg' is
364 access-list name. */
365 static void *
366 route_match_ip_next_hop_compile (const char *arg)
368 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
371 /* Free route map's compiled `ip address' value. */
372 static void
373 route_match_ip_next_hop_free (void *rule)
375 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
378 /* Route map commands for ip next-hop matching. */
379 struct route_map_rule_cmd route_match_ip_next_hop_cmd =
381 "ip next-hop",
382 route_match_ip_next_hop,
383 route_match_ip_next_hop_compile,
384 route_match_ip_next_hop_free
387 /* `match ip route-source ACCESS-LIST' */
389 /* Match function return 1 if match is success else return zero. */
390 static route_map_result_t
391 route_match_ip_route_source (void *rule, struct prefix *prefix,
392 route_map_object_t type, void *object)
394 struct access_list *alist;
395 struct bgp_info *bgp_info;
396 struct peer *peer;
397 struct prefix_ipv4 p;
399 if (type == RMAP_BGP)
401 bgp_info = object;
402 peer = bgp_info->peer;
404 if (! peer || sockunion_family (&peer->su) != AF_INET)
405 return RMAP_NOMATCH;
407 p.family = AF_INET;
408 p.prefix = peer->su.sin.sin_addr;
409 p.prefixlen = IPV4_MAX_BITLEN;
411 alist = access_list_lookup (AFI_IP, (char *) rule);
412 if (alist == NULL)
413 return RMAP_NOMATCH;
415 return (access_list_apply (alist, &p) == FILTER_DENY ?
416 RMAP_NOMATCH : RMAP_MATCH);
418 return RMAP_NOMATCH;
421 /* Route map `ip route-source' match statement. `arg' is
422 access-list name. */
423 static void *
424 route_match_ip_route_source_compile (const char *arg)
426 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
429 /* Free route map's compiled `ip address' value. */
430 static void
431 route_match_ip_route_source_free (void *rule)
433 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
436 /* Route map commands for ip route-source matching. */
437 struct route_map_rule_cmd route_match_ip_route_source_cmd =
439 "ip route-source",
440 route_match_ip_route_source,
441 route_match_ip_route_source_compile,
442 route_match_ip_route_source_free
445 /* `match ip address prefix-list PREFIX_LIST' */
447 static route_map_result_t
448 route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
449 route_map_object_t type, void *object)
451 struct prefix_list *plist;
453 if (type == RMAP_BGP)
455 plist = prefix_list_lookup (AFI_IP, (char *) rule);
456 if (plist == NULL)
457 return RMAP_NOMATCH;
459 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
460 RMAP_NOMATCH : RMAP_MATCH);
462 return RMAP_NOMATCH;
465 static void *
466 route_match_ip_address_prefix_list_compile (const char *arg)
468 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
471 static void
472 route_match_ip_address_prefix_list_free (void *rule)
474 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
477 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
479 "ip address prefix-list",
480 route_match_ip_address_prefix_list,
481 route_match_ip_address_prefix_list_compile,
482 route_match_ip_address_prefix_list_free
485 /* `match ip next-hop prefix-list PREFIX_LIST' */
487 static route_map_result_t
488 route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
489 route_map_object_t type, void *object)
491 struct prefix_list *plist;
492 struct bgp_info *bgp_info;
493 struct prefix_ipv4 p;
495 if (type == RMAP_BGP)
497 bgp_info = object;
498 p.family = AF_INET;
499 p.prefix = bgp_info->attr->nexthop;
500 p.prefixlen = IPV4_MAX_BITLEN;
502 plist = prefix_list_lookup (AFI_IP, (char *) rule);
503 if (plist == NULL)
504 return RMAP_NOMATCH;
506 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
507 RMAP_NOMATCH : RMAP_MATCH);
509 return RMAP_NOMATCH;
512 static void *
513 route_match_ip_next_hop_prefix_list_compile (const char *arg)
515 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
518 static void
519 route_match_ip_next_hop_prefix_list_free (void *rule)
521 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
524 struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
526 "ip next-hop prefix-list",
527 route_match_ip_next_hop_prefix_list,
528 route_match_ip_next_hop_prefix_list_compile,
529 route_match_ip_next_hop_prefix_list_free
532 /* `match ip route-source prefix-list PREFIX_LIST' */
534 static route_map_result_t
535 route_match_ip_route_source_prefix_list (void *rule, struct prefix *prefix,
536 route_map_object_t type, void *object)
538 struct prefix_list *plist;
539 struct bgp_info *bgp_info;
540 struct peer *peer;
541 struct prefix_ipv4 p;
543 if (type == RMAP_BGP)
545 bgp_info = object;
546 peer = bgp_info->peer;
548 if (! peer || sockunion_family (&peer->su) != AF_INET)
549 return RMAP_NOMATCH;
551 p.family = AF_INET;
552 p.prefix = peer->su.sin.sin_addr;
553 p.prefixlen = IPV4_MAX_BITLEN;
555 plist = prefix_list_lookup (AFI_IP, (char *) rule);
556 if (plist == NULL)
557 return RMAP_NOMATCH;
559 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
560 RMAP_NOMATCH : RMAP_MATCH);
562 return RMAP_NOMATCH;
565 static void *
566 route_match_ip_route_source_prefix_list_compile (const char *arg)
568 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
571 static void
572 route_match_ip_route_source_prefix_list_free (void *rule)
574 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
577 struct route_map_rule_cmd route_match_ip_route_source_prefix_list_cmd =
579 "ip route-source prefix-list",
580 route_match_ip_route_source_prefix_list,
581 route_match_ip_route_source_prefix_list_compile,
582 route_match_ip_route_source_prefix_list_free
585 /* `match metric METRIC' */
587 /* Match function return 1 if match is success else return zero. */
588 static route_map_result_t
589 route_match_metric (void *rule, struct prefix *prefix,
590 route_map_object_t type, void *object)
592 u_int32_t *med;
593 struct bgp_info *bgp_info;
595 if (type == RMAP_BGP)
597 med = rule;
598 bgp_info = object;
600 if (bgp_info->attr->med == *med)
601 return RMAP_MATCH;
602 else
603 return RMAP_NOMATCH;
605 return RMAP_NOMATCH;
608 /* Route map `match metric' match statement. `arg' is MED value */
609 static void *
610 route_match_metric_compile (const char *arg)
612 u_int32_t *med;
613 char *endptr = NULL;
614 unsigned long tmpval;
616 tmpval = strtoul (arg, &endptr, 10);
617 if (*endptr != '\0' || tmpval == ULONG_MAX || tmpval > UINT32_MAX)
618 return NULL;
620 med = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
622 if (!med)
623 return med;
625 *med = tmpval;
626 return med;
629 /* Free route map's compiled `match metric' value. */
630 static void
631 route_match_metric_free (void *rule)
633 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
636 /* Route map commands for metric matching. */
637 struct route_map_rule_cmd route_match_metric_cmd =
639 "metric",
640 route_match_metric,
641 route_match_metric_compile,
642 route_match_metric_free
645 /* `match as-path ASPATH' */
647 /* Match function for as-path match. I assume given object is */
648 static route_map_result_t
649 route_match_aspath (void *rule, struct prefix *prefix,
650 route_map_object_t type, void *object)
653 struct as_list *as_list;
654 struct bgp_info *bgp_info;
656 if (type == RMAP_BGP)
658 as_list = as_list_lookup ((char *) rule);
659 if (as_list == NULL)
660 return RMAP_NOMATCH;
662 bgp_info = object;
664 /* Perform match. */
665 return ((as_list_apply (as_list, bgp_info->attr->aspath) == AS_FILTER_DENY) ? RMAP_NOMATCH : RMAP_MATCH);
667 return RMAP_NOMATCH;
670 /* Compile function for as-path match. */
671 static void *
672 route_match_aspath_compile (const char *arg)
674 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
677 /* Compile function for as-path match. */
678 static void
679 route_match_aspath_free (void *rule)
681 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
684 /* Route map commands for aspath matching. */
685 struct route_map_rule_cmd route_match_aspath_cmd =
687 "as-path",
688 route_match_aspath,
689 route_match_aspath_compile,
690 route_match_aspath_free
693 /* `match community COMMUNIY' */
694 struct rmap_community
696 char *name;
697 int exact;
700 /* Match function for community match. */
701 static route_map_result_t
702 route_match_community (void *rule, struct prefix *prefix,
703 route_map_object_t type, void *object)
705 struct community_list *list;
706 struct bgp_info *bgp_info;
707 struct rmap_community *rcom;
709 if (type == RMAP_BGP)
711 bgp_info = object;
712 rcom = rule;
714 list = community_list_lookup (bgp_clist, rcom->name, COMMUNITY_LIST_MASTER);
715 if (! list)
716 return RMAP_NOMATCH;
718 if (rcom->exact)
720 if (community_list_exact_match (bgp_info->attr->community, list))
721 return RMAP_MATCH;
723 else
725 if (community_list_match (bgp_info->attr->community, list))
726 return RMAP_MATCH;
729 return RMAP_NOMATCH;
732 /* Compile function for community match. */
733 static void *
734 route_match_community_compile (const char *arg)
736 struct rmap_community *rcom;
737 int len;
738 char *p;
740 rcom = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_community));
742 p = strchr (arg, ' ');
743 if (p)
745 len = p - arg;
746 rcom->name = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
747 memcpy (rcom->name, arg, len);
748 rcom->exact = 1;
750 else
752 rcom->name = XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
753 rcom->exact = 0;
755 return rcom;
758 /* Compile function for community match. */
759 static void
760 route_match_community_free (void *rule)
762 struct rmap_community *rcom = rule;
764 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom->name);
765 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcom);
768 /* Route map commands for community matching. */
769 struct route_map_rule_cmd route_match_community_cmd =
771 "community",
772 route_match_community,
773 route_match_community_compile,
774 route_match_community_free
777 /* Match function for extcommunity match. */
778 static route_map_result_t
779 route_match_ecommunity (void *rule, struct prefix *prefix,
780 route_map_object_t type, void *object)
782 struct community_list *list;
783 struct bgp_info *bgp_info;
785 if (type == RMAP_BGP)
787 bgp_info = object;
789 if (!bgp_info->attr->extra)
790 return RMAP_NOMATCH;
792 list = community_list_lookup (bgp_clist, (char *) rule,
793 EXTCOMMUNITY_LIST_MASTER);
794 if (! list)
795 return RMAP_NOMATCH;
797 if (ecommunity_list_match (bgp_info->attr->extra->ecommunity, list))
798 return RMAP_MATCH;
800 return RMAP_NOMATCH;
803 /* Compile function for extcommunity match. */
804 static void *
805 route_match_ecommunity_compile (const char *arg)
807 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
810 /* Compile function for extcommunity match. */
811 static void
812 route_match_ecommunity_free (void *rule)
814 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
817 /* Route map commands for community matching. */
818 struct route_map_rule_cmd route_match_ecommunity_cmd =
820 "extcommunity",
821 route_match_ecommunity,
822 route_match_ecommunity_compile,
823 route_match_ecommunity_free
826 /* `match nlri` and `set nlri` are replaced by `address-family ipv4`
827 and `address-family vpnv4'. */
829 /* `match origin' */
830 static route_map_result_t
831 route_match_origin (void *rule, struct prefix *prefix,
832 route_map_object_t type, void *object)
834 u_char *origin;
835 struct bgp_info *bgp_info;
837 if (type == RMAP_BGP)
839 origin = rule;
840 bgp_info = object;
842 if (bgp_info->attr->origin == *origin)
843 return RMAP_MATCH;
846 return RMAP_NOMATCH;
849 static void *
850 route_match_origin_compile (const char *arg)
852 u_char *origin;
854 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
856 if (strcmp (arg, "igp") == 0)
857 *origin = 0;
858 else if (strcmp (arg, "egp") == 0)
859 *origin = 1;
860 else
861 *origin = 2;
863 return origin;
866 /* Free route map's compiled `ip address' value. */
867 static void
868 route_match_origin_free (void *rule)
870 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
873 /* Route map commands for origin matching. */
874 struct route_map_rule_cmd route_match_origin_cmd =
876 "origin",
877 route_match_origin,
878 route_match_origin_compile,
879 route_match_origin_free
881 /* `set ip next-hop IP_ADDRESS' */
883 /* Set nexthop to object. ojbect must be pointer to struct attr. */
884 struct rmap_ip_nexthop_set
886 struct in_addr *address;
887 int peer_address;
890 static route_map_result_t
891 route_set_ip_nexthop (void *rule, struct prefix *prefix,
892 route_map_object_t type, void *object)
894 struct rmap_ip_nexthop_set *rins = rule;
895 struct in_addr peer_address;
896 struct bgp_info *bgp_info;
897 struct peer *peer;
899 if (type == RMAP_BGP)
901 bgp_info = object;
902 peer = bgp_info->peer;
904 if (rins->peer_address)
906 if ((CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN) ||
907 CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
908 && peer->su_remote
909 && sockunion_family (peer->su_remote) == AF_INET)
911 inet_aton (sockunion_su2str (peer->su_remote), &peer_address);
912 bgp_info->attr->nexthop = peer_address;
913 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
915 else if (CHECK_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT)
916 && peer->su_local
917 && sockunion_family (peer->su_local) == AF_INET)
919 inet_aton (sockunion_su2str (peer->su_local), &peer_address);
920 bgp_info->attr->nexthop = peer_address;
921 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
924 else
926 /* Set next hop value. */
927 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP);
928 bgp_info->attr->nexthop = *rins->address;
932 return RMAP_OKAY;
935 /* Route map `ip nexthop' compile function. Given string is converted
936 to struct in_addr structure. */
937 static void *
938 route_set_ip_nexthop_compile (const char *arg)
940 struct rmap_ip_nexthop_set *rins;
941 struct in_addr *address = NULL;
942 int peer_address = 0;
943 int ret;
945 if (strcmp (arg, "peer-address") == 0)
946 peer_address = 1;
947 else
949 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
950 ret = inet_aton (arg, address);
952 if (ret == 0)
954 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
955 return NULL;
959 rins = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_ip_nexthop_set));
960 memset (rins, 0, sizeof (struct rmap_ip_nexthop_set));
962 rins->address = address;
963 rins->peer_address = peer_address;
965 return rins;
968 /* Free route map's compiled `ip nexthop' value. */
969 static void
970 route_set_ip_nexthop_free (void *rule)
972 struct rmap_ip_nexthop_set *rins = rule;
974 if (rins->address)
975 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins->address);
977 XFREE (MTYPE_ROUTE_MAP_COMPILED, rins);
980 /* Route map commands for ip nexthop set. */
981 struct route_map_rule_cmd route_set_ip_nexthop_cmd =
983 "ip next-hop",
984 route_set_ip_nexthop,
985 route_set_ip_nexthop_compile,
986 route_set_ip_nexthop_free
989 /* `set local-preference LOCAL_PREF' */
991 /* Set local preference. */
992 static route_map_result_t
993 route_set_local_pref (void *rule, struct prefix *prefix,
994 route_map_object_t type, void *object)
996 u_int32_t *local_pref;
997 struct bgp_info *bgp_info;
999 if (type == RMAP_BGP)
1001 /* Fetch routemap's rule information. */
1002 local_pref = rule;
1003 bgp_info = object;
1005 /* Set local preference value. */
1006 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
1007 bgp_info->attr->local_pref = *local_pref;
1010 return RMAP_OKAY;
1013 /* set local preference compilation. */
1014 static void *
1015 route_set_local_pref_compile (const char *arg)
1017 unsigned long tmp;
1018 u_int32_t *local_pref;
1019 char *endptr = NULL;
1021 /* Local preference value shoud be integer. */
1022 if (! all_digit (arg))
1023 return NULL;
1025 tmp = strtoul (arg, &endptr, 10);
1026 if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX)
1027 return NULL;
1029 local_pref = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
1031 if (!local_pref)
1032 return local_pref;
1034 *local_pref = tmp;
1036 return local_pref;
1039 /* Free route map's local preference value. */
1040 static void
1041 route_set_local_pref_free (void *rule)
1043 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1046 /* Set local preference rule structure. */
1047 struct route_map_rule_cmd route_set_local_pref_cmd =
1049 "local-preference",
1050 route_set_local_pref,
1051 route_set_local_pref_compile,
1052 route_set_local_pref_free,
1055 /* `set weight WEIGHT' */
1057 /* Set weight. */
1058 static route_map_result_t
1059 route_set_weight (void *rule, struct prefix *prefix, route_map_object_t type,
1060 void *object)
1062 u_int32_t *weight;
1063 struct bgp_info *bgp_info;
1065 if (type == RMAP_BGP)
1067 /* Fetch routemap's rule information. */
1068 weight = rule;
1069 bgp_info = object;
1071 /* Set weight value. */
1072 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;
1078 return RMAP_OKAY;
1081 /* set local preference compilation. */
1082 static void *
1083 route_set_weight_compile (const char *arg)
1085 unsigned long tmp;
1086 u_int32_t *weight;
1087 char *endptr = NULL;
1089 /* Local preference value shoud be integer. */
1090 if (! all_digit (arg))
1091 return NULL;
1094 tmp = strtoul (arg, &endptr, 10);
1095 if (*endptr != '\0' || tmp == ULONG_MAX || tmp > UINT32_MAX)
1096 return NULL;
1098 weight = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
1100 if (weight == NULL)
1101 return weight;
1103 *weight = tmp;
1105 return weight;
1108 /* Free route map's local preference value. */
1109 static void
1110 route_set_weight_free (void *rule)
1112 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1115 /* Set local preference rule structure. */
1116 struct route_map_rule_cmd route_set_weight_cmd =
1118 "weight",
1119 route_set_weight,
1120 route_set_weight_compile,
1121 route_set_weight_free,
1124 /* `set metric METRIC' */
1126 /* Set metric to attribute. */
1127 static route_map_result_t
1128 route_set_metric (void *rule, struct prefix *prefix,
1129 route_map_object_t type, void *object)
1131 char *metric;
1132 u_int32_t metric_val;
1133 struct bgp_info *bgp_info;
1135 if (type == RMAP_BGP)
1137 /* Fetch routemap's rule information. */
1138 metric = rule;
1139 bgp_info = object;
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);
1145 if (all_digit (metric))
1147 metric_val = strtoul (metric, (char **)NULL, 10);
1148 bgp_info->attr->med = metric_val;
1150 else
1152 metric_val = strtoul (metric+1, (char **)NULL, 10);
1154 if (strncmp (metric, "+", 1) == 0)
1156 if (bgp_info->attr->med/2 + metric_val/2 > BGP_MED_MAX/2)
1157 bgp_info->attr->med = BGP_MED_MAX - 1;
1158 else
1159 bgp_info->attr->med += metric_val;
1161 else if (strncmp (metric, "-", 1) == 0)
1163 if (bgp_info->attr->med <= metric_val)
1164 bgp_info->attr->med = 0;
1165 else
1166 bgp_info->attr->med -= metric_val;
1170 return RMAP_OKAY;
1173 /* set metric compilation. */
1174 static void *
1175 route_set_metric_compile (const char *arg)
1177 u_int32_t metric;
1178 unsigned long larg;
1179 char *endptr = NULL;
1181 if (all_digit (arg))
1183 /* set metric value check*/
1184 larg = strtoul (arg, &endptr, 10);
1185 if (*endptr != '\0' || larg == ULONG_MAX || larg > UINT32_MAX)
1186 return NULL;
1187 metric = larg;
1189 else
1191 /* set metric +/-value check */
1192 if ((strncmp (arg, "+", 1) != 0
1193 && strncmp (arg, "-", 1) != 0)
1194 || (! all_digit (arg+1)))
1195 return NULL;
1197 larg = strtoul (arg+1, &endptr, 10);
1198 if (*endptr != '\0' || larg == ULONG_MAX || larg > UINT32_MAX)
1199 return NULL;
1200 metric = larg;
1203 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1206 /* Free route map's compiled `set metric' value. */
1207 static void
1208 route_set_metric_free (void *rule)
1210 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1213 /* Set metric rule structure. */
1214 struct route_map_rule_cmd route_set_metric_cmd =
1216 "metric",
1217 route_set_metric,
1218 route_set_metric_compile,
1219 route_set_metric_free,
1222 /* `set as-path prepend ASPATH' */
1224 /* For AS path prepend mechanism. */
1225 static route_map_result_t
1226 route_set_aspath_prepend (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1228 struct aspath *aspath;
1229 struct aspath *new;
1230 struct bgp_info *binfo;
1232 if (type == RMAP_BGP)
1234 aspath = rule;
1235 binfo = object;
1237 if (binfo->attr->aspath->refcnt)
1238 new = aspath_dup (binfo->attr->aspath);
1239 else
1240 new = binfo->attr->aspath;
1242 aspath_prepend (aspath, new);
1243 binfo->attr->aspath = new;
1246 return RMAP_OKAY;
1249 /* Compile function for as-path prepend. */
1250 static void *
1251 route_set_aspath_prepend_compile (const char *arg)
1253 struct aspath *aspath;
1255 aspath = aspath_str2aspath (arg);
1256 if (! aspath)
1257 return NULL;
1258 return aspath;
1261 /* Compile function for as-path prepend. */
1262 static void
1263 route_set_aspath_prepend_free (void *rule)
1265 struct aspath *aspath = rule;
1266 aspath_free (aspath);
1269 /* Set metric rule structure. */
1270 struct route_map_rule_cmd route_set_aspath_prepend_cmd =
1272 "as-path prepend",
1273 route_set_aspath_prepend,
1274 route_set_aspath_prepend_compile,
1275 route_set_aspath_prepend_free,
1278 /* `set as-path exclude ASn' */
1280 /* For ASN exclude mechanism.
1281 * Iterate over ASns requested and filter them from the given AS_PATH one by one.
1282 * Make a deep copy of existing AS_PATH, but for the first ASn only.
1284 static route_map_result_t
1285 route_set_aspath_exclude (void *rule, struct prefix *dummy, route_map_object_t type, void *object)
1287 struct aspath * new_path, * exclude_path;
1288 struct bgp_info *binfo;
1290 if (type == RMAP_BGP)
1292 exclude_path = rule;
1293 binfo = object;
1294 if (binfo->attr->aspath->refcnt)
1295 new_path = aspath_dup (binfo->attr->aspath);
1296 else
1297 new_path = binfo->attr->aspath;
1298 binfo->attr->aspath = aspath_filter_exclude (new_path, exclude_path);
1300 return RMAP_OKAY;
1303 /* FIXME: consider using route_set_aspath_prepend_compile() and
1304 * route_set_aspath_prepend_free(), which two below function are
1305 * exact clones of.
1308 /* Compile function for as-path exclude. */
1309 static void *
1310 route_set_aspath_exclude_compile (const char *arg)
1312 struct aspath *aspath;
1314 aspath = aspath_str2aspath (arg);
1315 if (! aspath)
1316 return NULL;
1317 return aspath;
1320 static void
1321 route_set_aspath_exclude_free (void *rule)
1323 struct aspath *aspath = rule;
1324 aspath_free (aspath);
1327 /* Set ASn exlude rule structure. */
1328 struct route_map_rule_cmd route_set_aspath_exclude_cmd =
1330 "as-path exclude",
1331 route_set_aspath_exclude,
1332 route_set_aspath_exclude_compile,
1333 route_set_aspath_exclude_free,
1336 /* `set community COMMUNITY' */
1337 struct rmap_com_set
1339 struct community *com;
1340 int additive;
1341 int none;
1344 /* For community set mechanism. */
1345 static route_map_result_t
1346 route_set_community (void *rule, struct prefix *prefix,
1347 route_map_object_t type, void *object)
1349 struct rmap_com_set *rcs;
1350 struct bgp_info *binfo;
1351 struct attr *attr;
1352 struct community *new = NULL;
1353 struct community *old;
1354 struct community *merge;
1356 if (type == RMAP_BGP)
1358 rcs = rule;
1359 binfo = object;
1360 attr = binfo->attr;
1361 old = attr->community;
1363 /* "none" case. */
1364 if (rcs->none)
1366 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES));
1367 attr->community = NULL;
1368 return RMAP_OKAY;
1371 /* "additive" case. */
1372 if (rcs->additive && old)
1374 merge = community_merge (community_dup (old), rcs->com);
1376 /* HACK: if the old community is not intern'd,
1377 * we should free it here, or all reference to it may be lost.
1378 * Really need to cleanup attribute caching sometime.
1380 if (old->refcnt == 0)
1381 community_free (old);
1382 new = community_uniq_sort (merge);
1383 community_free (merge);
1385 else
1386 new = community_dup (rcs->com);
1388 /* will be interned by caller if required */
1389 attr->community = new;
1391 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1394 return RMAP_OKAY;
1397 /* Compile function for set community. */
1398 static void *
1399 route_set_community_compile (const char *arg)
1401 struct rmap_com_set *rcs;
1402 struct community *com = NULL;
1403 char *sp;
1404 int additive = 0;
1405 int none = 0;
1407 if (strcmp (arg, "none") == 0)
1408 none = 1;
1409 else
1411 sp = strstr (arg, "additive");
1413 if (sp && sp > arg)
1415 /* "additive" keyworkd is included. */
1416 additive = 1;
1417 *(sp - 1) = '\0';
1420 com = community_str2com (arg);
1422 if (additive)
1423 *(sp - 1) = ' ';
1425 if (! com)
1426 return NULL;
1429 rcs = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct rmap_com_set));
1430 memset (rcs, 0, sizeof (struct rmap_com_set));
1432 rcs->com = com;
1433 rcs->additive = additive;
1434 rcs->none = none;
1436 return rcs;
1439 /* Free function for set community. */
1440 static void
1441 route_set_community_free (void *rule)
1443 struct rmap_com_set *rcs = rule;
1445 if (rcs->com)
1446 community_free (rcs->com);
1447 XFREE (MTYPE_ROUTE_MAP_COMPILED, rcs);
1450 /* Set community rule structure. */
1451 struct route_map_rule_cmd route_set_community_cmd =
1453 "community",
1454 route_set_community,
1455 route_set_community_compile,
1456 route_set_community_free,
1459 /* `set comm-list (<1-99>|<100-500>|WORD) delete' */
1461 /* For community set mechanism. */
1462 static route_map_result_t
1463 route_set_community_delete (void *rule, struct prefix *prefix,
1464 route_map_object_t type, void *object)
1466 struct community_list *list;
1467 struct community *merge;
1468 struct community *new;
1469 struct community *old;
1470 struct bgp_info *binfo;
1472 if (type == RMAP_BGP)
1474 if (! rule)
1475 return RMAP_OKAY;
1477 binfo = object;
1478 list = community_list_lookup (bgp_clist, rule, COMMUNITY_LIST_MASTER);
1479 old = binfo->attr->community;
1481 if (list && old)
1483 merge = community_list_match_delete (community_dup (old), list);
1484 new = community_uniq_sort (merge);
1485 community_free (merge);
1487 if (new->size == 0)
1489 binfo->attr->community = NULL;
1490 binfo->attr->flag &= ~ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1491 community_free (new);
1493 else
1495 binfo->attr->community = new;
1496 binfo->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES);
1501 return RMAP_OKAY;
1504 /* Compile function for set community. */
1505 static void *
1506 route_set_community_delete_compile (const char *arg)
1508 char *p;
1509 char *str;
1510 int len;
1512 p = strchr (arg, ' ');
1513 if (p)
1515 len = p - arg;
1516 str = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, len + 1);
1517 memcpy (str, arg, len);
1519 else
1520 str = NULL;
1522 return str;
1525 /* Free function for set community. */
1526 static void
1527 route_set_community_delete_free (void *rule)
1529 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1532 /* Set community rule structure. */
1533 struct route_map_rule_cmd route_set_community_delete_cmd =
1535 "comm-list",
1536 route_set_community_delete,
1537 route_set_community_delete_compile,
1538 route_set_community_delete_free,
1541 /* `set extcommunity rt COMMUNITY' */
1543 /* For community set mechanism. */
1544 static route_map_result_t
1545 route_set_ecommunity_rt (void *rule, struct prefix *prefix,
1546 route_map_object_t type, void *object)
1548 struct ecommunity *ecom;
1549 struct ecommunity *new_ecom;
1550 struct ecommunity *old_ecom;
1551 struct bgp_info *bgp_info;
1553 if (type == RMAP_BGP)
1555 ecom = rule;
1556 bgp_info = object;
1558 if (! ecom)
1559 return RMAP_OKAY;
1561 /* We assume additive for Extended Community. */
1562 old_ecom = (bgp_attr_extra_get (bgp_info->attr))->ecommunity;
1564 if (old_ecom)
1565 new_ecom = ecommunity_merge (ecommunity_dup (old_ecom), ecom);
1566 else
1567 new_ecom = ecommunity_dup (ecom);
1569 bgp_info->attr->extra->ecommunity = new_ecom;
1571 if (old_ecom)
1572 ecommunity_free (old_ecom);
1574 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
1576 return RMAP_OKAY;
1579 /* Compile function for set community. */
1580 static void *
1581 route_set_ecommunity_rt_compile (const char *arg)
1583 struct ecommunity *ecom;
1585 ecom = ecommunity_str2com (arg, ECOMMUNITY_ROUTE_TARGET, 0);
1586 if (! ecom)
1587 return NULL;
1588 return ecom;
1591 /* Free function for set community. */
1592 static void
1593 route_set_ecommunity_rt_free (void *rule)
1595 struct ecommunity *ecom = rule;
1596 ecommunity_free (ecom);
1599 /* Set community rule structure. */
1600 struct route_map_rule_cmd route_set_ecommunity_rt_cmd =
1602 "extcommunity rt",
1603 route_set_ecommunity_rt,
1604 route_set_ecommunity_rt_compile,
1605 route_set_ecommunity_rt_free,
1608 /* `set extcommunity soo COMMUNITY' */
1610 /* For community set mechanism. */
1611 static route_map_result_t
1612 route_set_ecommunity_soo (void *rule, struct prefix *prefix,
1613 route_map_object_t type, void *object)
1615 struct ecommunity *ecom;
1616 struct bgp_info *bgp_info;
1618 if (type == RMAP_BGP)
1620 ecom = rule;
1621 bgp_info = object;
1623 if (! ecom)
1624 return RMAP_OKAY;
1626 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
1627 (bgp_attr_extra_get (bgp_info->attr))->ecommunity = ecommunity_dup (ecom);
1629 return RMAP_OKAY;
1632 /* Compile function for set community. */
1633 static void *
1634 route_set_ecommunity_soo_compile (const char *arg)
1636 struct ecommunity *ecom;
1638 ecom = ecommunity_str2com (arg, ECOMMUNITY_SITE_ORIGIN, 0);
1639 if (! ecom)
1640 return NULL;
1642 return ecom;
1645 /* Free function for set community. */
1646 static void
1647 route_set_ecommunity_soo_free (void *rule)
1649 struct ecommunity *ecom = rule;
1650 ecommunity_free (ecom);
1653 /* Set community rule structure. */
1654 struct route_map_rule_cmd route_set_ecommunity_soo_cmd =
1656 "extcommunity soo",
1657 route_set_ecommunity_soo,
1658 route_set_ecommunity_soo_compile,
1659 route_set_ecommunity_soo_free,
1662 /* `set origin ORIGIN' */
1664 /* For origin set. */
1665 static route_map_result_t
1666 route_set_origin (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
1668 u_char *origin;
1669 struct bgp_info *bgp_info;
1671 if (type == RMAP_BGP)
1673 origin = rule;
1674 bgp_info = object;
1676 bgp_info->attr->origin = *origin;
1679 return RMAP_OKAY;
1682 /* Compile function for origin set. */
1683 static void *
1684 route_set_origin_compile (const char *arg)
1686 u_char *origin;
1688 origin = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_char));
1690 if (strcmp (arg, "igp") == 0)
1691 *origin = 0;
1692 else if (strcmp (arg, "egp") == 0)
1693 *origin = 1;
1694 else
1695 *origin = 2;
1697 return origin;
1700 /* Compile function for origin set. */
1701 static void
1702 route_set_origin_free (void *rule)
1704 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1707 /* Set metric rule structure. */
1708 struct route_map_rule_cmd route_set_origin_cmd =
1710 "origin",
1711 route_set_origin,
1712 route_set_origin_compile,
1713 route_set_origin_free,
1716 /* `set atomic-aggregate' */
1718 /* For atomic aggregate set. */
1719 static route_map_result_t
1720 route_set_atomic_aggregate (void *rule, struct prefix *prefix,
1721 route_map_object_t type, void *object)
1723 struct bgp_info *bgp_info;
1725 if (type == RMAP_BGP)
1727 bgp_info = object;
1728 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
1731 return RMAP_OKAY;
1734 /* Compile function for atomic aggregate. */
1735 static void *
1736 route_set_atomic_aggregate_compile (const char *arg)
1738 return (void *)1;
1741 /* Compile function for atomic aggregate. */
1742 static void
1743 route_set_atomic_aggregate_free (void *rule)
1745 return;
1748 /* Set atomic aggregate rule structure. */
1749 struct route_map_rule_cmd route_set_atomic_aggregate_cmd =
1751 "atomic-aggregate",
1752 route_set_atomic_aggregate,
1753 route_set_atomic_aggregate_compile,
1754 route_set_atomic_aggregate_free,
1757 /* `set aggregator as AS A.B.C.D' */
1758 struct aggregator
1760 as_t as;
1761 struct in_addr address;
1764 static route_map_result_t
1765 route_set_aggregator_as (void *rule, struct prefix *prefix,
1766 route_map_object_t type, void *object)
1768 struct bgp_info *bgp_info;
1769 struct aggregator *aggregator;
1770 struct attr_extra *ae;
1772 if (type == RMAP_BGP)
1774 bgp_info = object;
1775 aggregator = rule;
1776 ae = bgp_attr_extra_get (bgp_info->attr);
1778 ae->aggregator_as = aggregator->as;
1779 ae->aggregator_addr = aggregator->address;
1780 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR);
1783 return RMAP_OKAY;
1786 static void *
1787 route_set_aggregator_as_compile (const char *arg)
1789 struct aggregator *aggregator;
1790 char as[10];
1791 char address[20];
1793 aggregator = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct aggregator));
1794 memset (aggregator, 0, sizeof (struct aggregator));
1796 sscanf (arg, "%s %s", as, address);
1798 aggregator->as = strtoul (as, NULL, 10);
1799 inet_aton (address, &aggregator->address);
1801 return aggregator;
1804 static void
1805 route_set_aggregator_as_free (void *rule)
1807 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1810 struct route_map_rule_cmd route_set_aggregator_as_cmd =
1812 "aggregator as",
1813 route_set_aggregator_as,
1814 route_set_aggregator_as_compile,
1815 route_set_aggregator_as_free,
1818 #ifdef HAVE_IPV6
1819 /* `match ipv6 address IP_ACCESS_LIST' */
1821 static route_map_result_t
1822 route_match_ipv6_address (void *rule, struct prefix *prefix,
1823 route_map_object_t type, void *object)
1825 struct access_list *alist;
1827 if (type == RMAP_BGP)
1829 alist = access_list_lookup (AFI_IP6, (char *) rule);
1830 if (alist == NULL)
1831 return RMAP_NOMATCH;
1833 return (access_list_apply (alist, prefix) == FILTER_DENY ?
1834 RMAP_NOMATCH : RMAP_MATCH);
1836 return RMAP_NOMATCH;
1839 static void *
1840 route_match_ipv6_address_compile (const char *arg)
1842 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1845 static void
1846 route_match_ipv6_address_free (void *rule)
1848 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1851 /* Route map commands for ip address matching. */
1852 struct route_map_rule_cmd route_match_ipv6_address_cmd =
1854 "ipv6 address",
1855 route_match_ipv6_address,
1856 route_match_ipv6_address_compile,
1857 route_match_ipv6_address_free
1860 /* `match ipv6 next-hop IP_ADDRESS' */
1862 static route_map_result_t
1863 route_match_ipv6_next_hop (void *rule, struct prefix *prefix,
1864 route_map_object_t type, void *object)
1866 struct in6_addr *addr;
1867 struct bgp_info *bgp_info;
1869 if (type == RMAP_BGP)
1871 addr = rule;
1872 bgp_info = object;
1874 if (!bgp_info->attr->extra)
1875 return RMAP_NOMATCH;
1877 if (IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_global, rule))
1878 return RMAP_MATCH;
1880 if (bgp_info->attr->extra->mp_nexthop_len == 32 &&
1881 IPV6_ADDR_SAME (&bgp_info->attr->extra->mp_nexthop_local, rule))
1882 return RMAP_MATCH;
1884 return RMAP_NOMATCH;
1887 return RMAP_NOMATCH;
1890 static void *
1891 route_match_ipv6_next_hop_compile (const char *arg)
1893 struct in6_addr *address;
1894 int ret;
1896 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1898 ret = inet_pton (AF_INET6, arg, address);
1899 if (!ret)
1901 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
1902 return NULL;
1905 return address;
1908 static void
1909 route_match_ipv6_next_hop_free (void *rule)
1911 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1914 struct route_map_rule_cmd route_match_ipv6_next_hop_cmd =
1916 "ipv6 next-hop",
1917 route_match_ipv6_next_hop,
1918 route_match_ipv6_next_hop_compile,
1919 route_match_ipv6_next_hop_free
1922 /* `match ipv6 address prefix-list PREFIX_LIST' */
1924 static route_map_result_t
1925 route_match_ipv6_address_prefix_list (void *rule, struct prefix *prefix,
1926 route_map_object_t type, void *object)
1928 struct prefix_list *plist;
1930 if (type == RMAP_BGP)
1932 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
1933 if (plist == NULL)
1934 return RMAP_NOMATCH;
1936 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
1937 RMAP_NOMATCH : RMAP_MATCH);
1939 return RMAP_NOMATCH;
1942 static void *
1943 route_match_ipv6_address_prefix_list_compile (const char *arg)
1945 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
1948 static void
1949 route_match_ipv6_address_prefix_list_free (void *rule)
1951 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
1954 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
1956 "ipv6 address prefix-list",
1957 route_match_ipv6_address_prefix_list,
1958 route_match_ipv6_address_prefix_list_compile,
1959 route_match_ipv6_address_prefix_list_free
1962 /* `set ipv6 nexthop global IP_ADDRESS' */
1964 /* Set nexthop to object. ojbect must be pointer to struct attr. */
1965 static route_map_result_t
1966 route_set_ipv6_nexthop_global (void *rule, struct prefix *prefix,
1967 route_map_object_t type, void *object)
1969 struct in6_addr *address;
1970 struct bgp_info *bgp_info;
1972 if (type == RMAP_BGP)
1974 /* Fetch routemap's rule information. */
1975 address = rule;
1976 bgp_info = object;
1978 /* Set next hop value. */
1979 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global = *address;
1981 /* Set nexthop length. */
1982 if (bgp_info->attr->extra->mp_nexthop_len == 0)
1983 bgp_info->attr->extra->mp_nexthop_len = 16;
1986 return RMAP_OKAY;
1989 /* Route map `ip next-hop' compile function. Given string is converted
1990 to struct in_addr structure. */
1991 static void *
1992 route_set_ipv6_nexthop_global_compile (const char *arg)
1994 int ret;
1995 struct in6_addr *address;
1997 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
1999 ret = inet_pton (AF_INET6, arg, address);
2001 if (ret == 0)
2003 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2004 return NULL;
2007 return address;
2010 /* Free route map's compiled `ip next-hop' value. */
2011 static void
2012 route_set_ipv6_nexthop_global_free (void *rule)
2014 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2017 /* Route map commands for ip nexthop set. */
2018 struct route_map_rule_cmd route_set_ipv6_nexthop_global_cmd =
2020 "ipv6 next-hop global",
2021 route_set_ipv6_nexthop_global,
2022 route_set_ipv6_nexthop_global_compile,
2023 route_set_ipv6_nexthop_global_free
2026 /* `set ipv6 nexthop local IP_ADDRESS' */
2028 /* Set nexthop to object. ojbect must be pointer to struct attr. */
2029 static route_map_result_t
2030 route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
2031 route_map_object_t type, void *object)
2033 struct in6_addr *address;
2034 struct bgp_info *bgp_info;
2036 if (type == RMAP_BGP)
2038 /* Fetch routemap's rule information. */
2039 address = rule;
2040 bgp_info = object;
2042 /* Set next hop value. */
2043 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_local = *address;
2045 /* Set nexthop length. */
2046 if (bgp_info->attr->extra->mp_nexthop_len != 32)
2047 bgp_info->attr->extra->mp_nexthop_len = 32;
2050 return RMAP_OKAY;
2053 /* Route map `ip nexthop' compile function. Given string is converted
2054 to struct in_addr structure. */
2055 static void *
2056 route_set_ipv6_nexthop_local_compile (const char *arg)
2058 int ret;
2059 struct in6_addr *address;
2061 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in6_addr));
2063 ret = inet_pton (AF_INET6, arg, address);
2065 if (ret == 0)
2067 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2068 return NULL;
2071 return address;
2074 /* Free route map's compiled `ip nexthop' value. */
2075 static void
2076 route_set_ipv6_nexthop_local_free (void *rule)
2078 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2081 /* Route map commands for ip nexthop set. */
2082 struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd =
2084 "ipv6 next-hop local",
2085 route_set_ipv6_nexthop_local,
2086 route_set_ipv6_nexthop_local_compile,
2087 route_set_ipv6_nexthop_local_free
2089 #endif /* HAVE_IPV6 */
2091 /* `set vpnv4 nexthop A.B.C.D' */
2093 static route_map_result_t
2094 route_set_vpnv4_nexthop (void *rule, struct prefix *prefix,
2095 route_map_object_t type, void *object)
2097 struct in_addr *address;
2098 struct bgp_info *bgp_info;
2100 if (type == RMAP_BGP)
2102 /* Fetch routemap's rule information. */
2103 address = rule;
2104 bgp_info = object;
2106 /* Set next hop value. */
2107 (bgp_attr_extra_get (bgp_info->attr))->mp_nexthop_global_in = *address;
2110 return RMAP_OKAY;
2113 static void *
2114 route_set_vpnv4_nexthop_compile (const char *arg)
2116 int ret;
2117 struct in_addr *address;
2119 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2121 ret = inet_aton (arg, address);
2123 if (ret == 0)
2125 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2126 return NULL;
2129 return address;
2132 static void
2133 route_set_vpnv4_nexthop_free (void *rule)
2135 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2138 /* Route map commands for ip nexthop set. */
2139 struct route_map_rule_cmd route_set_vpnv4_nexthop_cmd =
2141 "vpnv4 next-hop",
2142 route_set_vpnv4_nexthop,
2143 route_set_vpnv4_nexthop_compile,
2144 route_set_vpnv4_nexthop_free
2147 /* `set originator-id' */
2149 /* For origin set. */
2150 static route_map_result_t
2151 route_set_originator_id (void *rule, struct prefix *prefix, route_map_object_t type, void *object)
2153 struct in_addr *address;
2154 struct bgp_info *bgp_info;
2156 if (type == RMAP_BGP)
2158 address = rule;
2159 bgp_info = object;
2161 bgp_info->attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID);
2162 (bgp_attr_extra_get (bgp_info->attr))->originator_id = *address;
2165 return RMAP_OKAY;
2168 /* Compile function for originator-id set. */
2169 static void *
2170 route_set_originator_id_compile (const char *arg)
2172 int ret;
2173 struct in_addr *address;
2175 address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
2177 ret = inet_aton (arg, address);
2179 if (ret == 0)
2181 XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
2182 return NULL;
2185 return address;
2188 /* Compile function for originator_id set. */
2189 static void
2190 route_set_originator_id_free (void *rule)
2192 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
2195 /* Set metric rule structure. */
2196 struct route_map_rule_cmd route_set_originator_id_cmd =
2198 "originator-id",
2199 route_set_originator_id,
2200 route_set_originator_id_compile,
2201 route_set_originator_id_free,
2204 /* Add bgp route map rule. */
2205 static int
2206 bgp_route_match_add (struct vty *vty, struct route_map_index *index,
2207 const char *command, const char *arg)
2209 int ret;
2211 ret = route_map_add_match (index, command, arg);
2212 if (ret)
2214 switch (ret)
2216 case RMAP_RULE_MISSING:
2217 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2218 return CMD_WARNING;
2219 case RMAP_COMPILE_ERROR:
2220 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2221 return CMD_WARNING;
2224 return CMD_SUCCESS;
2227 /* Delete bgp route map rule. */
2228 static int
2229 bgp_route_match_delete (struct vty *vty, struct route_map_index *index,
2230 const char *command, const char *arg)
2232 int ret;
2234 ret = route_map_delete_match (index, command, arg);
2235 if (ret)
2237 switch (ret)
2239 case RMAP_RULE_MISSING:
2240 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2241 return CMD_WARNING;
2242 case RMAP_COMPILE_ERROR:
2243 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2244 return CMD_WARNING;
2247 return CMD_SUCCESS;
2250 /* Add bgp route map rule. */
2251 static int
2252 bgp_route_set_add (struct vty *vty, struct route_map_index *index,
2253 const char *command, const char *arg)
2255 int ret;
2257 ret = route_map_add_set (index, command, arg);
2258 if (ret)
2260 switch (ret)
2262 case RMAP_RULE_MISSING:
2263 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2264 return CMD_WARNING;
2265 case RMAP_COMPILE_ERROR:
2266 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2267 return CMD_WARNING;
2270 return CMD_SUCCESS;
2273 /* Delete bgp route map rule. */
2274 static int
2275 bgp_route_set_delete (struct vty *vty, struct route_map_index *index,
2276 const char *command, const char *arg)
2278 int ret;
2280 ret = route_map_delete_set (index, command, arg);
2281 if (ret)
2283 switch (ret)
2285 case RMAP_RULE_MISSING:
2286 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
2287 return CMD_WARNING;
2288 case RMAP_COMPILE_ERROR:
2289 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
2290 return CMD_WARNING;
2293 return CMD_SUCCESS;
2296 /* Hook function for updating route_map assignment. */
2297 static void
2298 bgp_route_map_update (const char *unused)
2300 int i;
2301 afi_t afi;
2302 safi_t safi;
2303 int direct;
2304 struct listnode *node, *nnode;
2305 struct listnode *mnode, *mnnode;
2306 struct bgp *bgp;
2307 struct peer *peer;
2308 struct peer_group *group;
2309 struct bgp_filter *filter;
2310 struct bgp_node *bn;
2311 struct bgp_static *bgp_static;
2313 /* For neighbor route-map updates. */
2314 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
2316 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
2318 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2319 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2321 filter = &peer->filter[afi][safi];
2323 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
2325 if (filter->map[direct].name)
2326 filter->map[direct].map =
2327 route_map_lookup_by_name (filter->map[direct].name);
2328 else
2329 filter->map[direct].map = NULL;
2332 if (filter->usmap.name)
2333 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2334 else
2335 filter->usmap.map = NULL;
2338 for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group))
2340 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2341 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2343 filter = &group->conf->filter[afi][safi];
2345 for (direct = RMAP_IN; direct < RMAP_MAX; direct++)
2347 if (filter->map[direct].name)
2348 filter->map[direct].map =
2349 route_map_lookup_by_name (filter->map[direct].name);
2350 else
2351 filter->map[direct].map = NULL;
2354 if (filter->usmap.name)
2355 filter->usmap.map = route_map_lookup_by_name (filter->usmap.name);
2356 else
2357 filter->usmap.map = NULL;
2362 /* For default-originate route-map updates. */
2363 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
2365 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
2367 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2368 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2370 if (peer->default_rmap[afi][safi].name)
2371 peer->default_rmap[afi][safi].map =
2372 route_map_lookup_by_name (peer->default_rmap[afi][safi].name);
2373 else
2374 peer->default_rmap[afi][safi].map = NULL;
2379 /* For network route-map updates. */
2380 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
2382 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2383 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2384 for (bn = bgp_table_top (bgp->route[afi][safi]); bn;
2385 bn = bgp_route_next (bn))
2386 if ((bgp_static = bn->info) != NULL)
2388 if (bgp_static->rmap.name)
2389 bgp_static->rmap.map =
2390 route_map_lookup_by_name (bgp_static->rmap.name);
2391 else
2392 bgp_static->rmap.map = NULL;
2396 /* For redistribute route-map updates. */
2397 for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp))
2399 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
2401 if (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name)
2402 bgp->rmap[ZEBRA_FAMILY_IPV4][i].map =
2403 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV4][i].name);
2404 #ifdef HAVE_IPV6
2405 if (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name)
2406 bgp->rmap[ZEBRA_FAMILY_IPV6][i].map =
2407 route_map_lookup_by_name (bgp->rmap[ZEBRA_FAMILY_IPV6][i].name);
2408 #endif /* HAVE_IPV6 */
2413 DEFUN (match_peer,
2414 match_peer_cmd,
2415 "match peer (A.B.C.D|X:X::X:X)",
2416 MATCH_STR
2417 "Match peer address\n"
2418 "IPv6 address of peer\n"
2419 "IP address of peer\n")
2421 return bgp_route_match_add (vty, vty->index, "peer", argv[0]);
2424 DEFUN (match_peer_local,
2425 match_peer_local_cmd,
2426 "match peer local",
2427 MATCH_STR
2428 "Match peer address\n"
2429 "Static or Redistributed routes\n")
2431 return bgp_route_match_add (vty, vty->index, "peer", NULL);
2434 DEFUN (no_match_peer,
2435 no_match_peer_cmd,
2436 "no match peer",
2437 NO_STR
2438 MATCH_STR
2439 "Match peer address\n")
2441 if (argc == 0)
2442 return bgp_route_match_delete (vty, vty->index, "peer", NULL);
2444 return bgp_route_match_delete (vty, vty->index, "peer", argv[0]);
2447 ALIAS (no_match_peer,
2448 no_match_peer_val_cmd,
2449 "no match peer (A.B.C.D|X:X::X:X)",
2450 NO_STR
2451 MATCH_STR
2452 "Match peer address\n"
2453 "IPv6 address of peer\n"
2454 "IP address of peer\n")
2456 ALIAS (no_match_peer,
2457 no_match_peer_local_cmd,
2458 "no match peer local",
2459 NO_STR
2460 MATCH_STR
2461 "Match peer address\n"
2462 "Static or Redistributed routes\n")
2464 DEFUN (match_ip_address,
2465 match_ip_address_cmd,
2466 "match ip address (<1-199>|<1300-2699>|WORD)",
2467 MATCH_STR
2468 IP_STR
2469 "Match address of route\n"
2470 "IP access-list number\n"
2471 "IP access-list number (expanded range)\n"
2472 "IP Access-list name\n")
2474 return bgp_route_match_add (vty, vty->index, "ip address", argv[0]);
2477 DEFUN (no_match_ip_address,
2478 no_match_ip_address_cmd,
2479 "no match ip address",
2480 NO_STR
2481 MATCH_STR
2482 IP_STR
2483 "Match address of route\n")
2485 if (argc == 0)
2486 return bgp_route_match_delete (vty, vty->index, "ip address", NULL);
2488 return bgp_route_match_delete (vty, vty->index, "ip address", argv[0]);
2491 ALIAS (no_match_ip_address,
2492 no_match_ip_address_val_cmd,
2493 "no match ip address (<1-199>|<1300-2699>|WORD)",
2494 NO_STR
2495 MATCH_STR
2496 IP_STR
2497 "Match address of route\n"
2498 "IP access-list number\n"
2499 "IP access-list number (expanded range)\n"
2500 "IP Access-list name\n")
2502 DEFUN (match_ip_next_hop,
2503 match_ip_next_hop_cmd,
2504 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
2505 MATCH_STR
2506 IP_STR
2507 "Match next-hop address of route\n"
2508 "IP access-list number\n"
2509 "IP access-list number (expanded range)\n"
2510 "IP Access-list name\n")
2512 return bgp_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
2515 DEFUN (no_match_ip_next_hop,
2516 no_match_ip_next_hop_cmd,
2517 "no match ip next-hop",
2518 NO_STR
2519 MATCH_STR
2520 IP_STR
2521 "Match next-hop address of route\n")
2523 if (argc == 0)
2524 return bgp_route_match_delete (vty, vty->index, "ip next-hop", NULL);
2526 return bgp_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
2529 ALIAS (no_match_ip_next_hop,
2530 no_match_ip_next_hop_val_cmd,
2531 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
2532 NO_STR
2533 MATCH_STR
2534 IP_STR
2535 "Match next-hop address of route\n"
2536 "IP access-list number\n"
2537 "IP access-list number (expanded range)\n"
2538 "IP Access-list name\n")
2540 DEFUN (match_ip_route_source,
2541 match_ip_route_source_cmd,
2542 "match ip route-source (<1-199>|<1300-2699>|WORD)",
2543 MATCH_STR
2544 IP_STR
2545 "Match advertising source address of route\n"
2546 "IP access-list number\n"
2547 "IP access-list number (expanded range)\n"
2548 "IP standard access-list name\n")
2550 return bgp_route_match_add (vty, vty->index, "ip route-source", argv[0]);
2553 DEFUN (no_match_ip_route_source,
2554 no_match_ip_route_source_cmd,
2555 "no match ip route-source",
2556 NO_STR
2557 MATCH_STR
2558 IP_STR
2559 "Match advertising source address of route\n")
2561 if (argc == 0)
2562 return bgp_route_match_delete (vty, vty->index, "ip route-source", NULL);
2564 return bgp_route_match_delete (vty, vty->index, "ip route-source", argv[0]);
2567 ALIAS (no_match_ip_route_source,
2568 no_match_ip_route_source_val_cmd,
2569 "no match ip route-source (<1-199>|<1300-2699>|WORD)",
2570 NO_STR
2571 MATCH_STR
2572 IP_STR
2573 "Match advertising source address of route\n"
2574 "IP access-list number\n"
2575 "IP access-list number (expanded range)\n"
2576 "IP standard access-list name\n")
2578 DEFUN (match_ip_address_prefix_list,
2579 match_ip_address_prefix_list_cmd,
2580 "match ip address prefix-list WORD",
2581 MATCH_STR
2582 IP_STR
2583 "Match address of route\n"
2584 "Match entries of prefix-lists\n"
2585 "IP prefix-list name\n")
2587 return bgp_route_match_add (vty, vty->index, "ip address prefix-list", argv[0]);
2590 DEFUN (no_match_ip_address_prefix_list,
2591 no_match_ip_address_prefix_list_cmd,
2592 "no match ip address prefix-list",
2593 NO_STR
2594 MATCH_STR
2595 IP_STR
2596 "Match address of route\n"
2597 "Match entries of prefix-lists\n")
2599 if (argc == 0)
2600 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", NULL);
2602 return bgp_route_match_delete (vty, vty->index, "ip address prefix-list", argv[0]);
2605 ALIAS (no_match_ip_address_prefix_list,
2606 no_match_ip_address_prefix_list_val_cmd,
2607 "no match ip address prefix-list WORD",
2608 NO_STR
2609 MATCH_STR
2610 IP_STR
2611 "Match address of route\n"
2612 "Match entries of prefix-lists\n"
2613 "IP prefix-list name\n")
2615 DEFUN (match_ip_next_hop_prefix_list,
2616 match_ip_next_hop_prefix_list_cmd,
2617 "match ip next-hop prefix-list WORD",
2618 MATCH_STR
2619 IP_STR
2620 "Match next-hop address of route\n"
2621 "Match entries of prefix-lists\n"
2622 "IP prefix-list name\n")
2624 return bgp_route_match_add (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2627 DEFUN (no_match_ip_next_hop_prefix_list,
2628 no_match_ip_next_hop_prefix_list_cmd,
2629 "no match ip next-hop prefix-list",
2630 NO_STR
2631 MATCH_STR
2632 IP_STR
2633 "Match next-hop address of route\n"
2634 "Match entries of prefix-lists\n")
2636 if (argc == 0)
2637 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", NULL);
2639 return bgp_route_match_delete (vty, vty->index, "ip next-hop prefix-list", argv[0]);
2642 ALIAS (no_match_ip_next_hop_prefix_list,
2643 no_match_ip_next_hop_prefix_list_val_cmd,
2644 "no match ip next-hop prefix-list WORD",
2645 NO_STR
2646 MATCH_STR
2647 IP_STR
2648 "Match next-hop address of route\n"
2649 "Match entries of prefix-lists\n"
2650 "IP prefix-list name\n")
2652 DEFUN (match_ip_route_source_prefix_list,
2653 match_ip_route_source_prefix_list_cmd,
2654 "match ip route-source prefix-list WORD",
2655 MATCH_STR
2656 IP_STR
2657 "Match advertising source address of route\n"
2658 "Match entries of prefix-lists\n"
2659 "IP prefix-list name\n")
2661 return bgp_route_match_add (vty, vty->index, "ip route-source prefix-list", argv[0]);
2664 DEFUN (no_match_ip_route_source_prefix_list,
2665 no_match_ip_route_source_prefix_list_cmd,
2666 "no match ip route-source prefix-list",
2667 NO_STR
2668 MATCH_STR
2669 IP_STR
2670 "Match advertising source address of route\n"
2671 "Match entries of prefix-lists\n")
2673 if (argc == 0)
2674 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", NULL);
2676 return bgp_route_match_delete (vty, vty->index, "ip route-source prefix-list", argv[0]);
2679 ALIAS (no_match_ip_route_source_prefix_list,
2680 no_match_ip_route_source_prefix_list_val_cmd,
2681 "no match ip route-source prefix-list WORD",
2682 NO_STR
2683 MATCH_STR
2684 IP_STR
2685 "Match advertising source address of route\n"
2686 "Match entries of prefix-lists\n"
2687 "IP prefix-list name\n")
2689 DEFUN (match_metric,
2690 match_metric_cmd,
2691 "match metric <0-4294967295>",
2692 MATCH_STR
2693 "Match metric of route\n"
2694 "Metric value\n")
2696 return bgp_route_match_add (vty, vty->index, "metric", argv[0]);
2699 DEFUN (no_match_metric,
2700 no_match_metric_cmd,
2701 "no match metric",
2702 NO_STR
2703 MATCH_STR
2704 "Match metric of route\n")
2706 if (argc == 0)
2707 return bgp_route_match_delete (vty, vty->index, "metric", NULL);
2709 return bgp_route_match_delete (vty, vty->index, "metric", argv[0]);
2712 ALIAS (no_match_metric,
2713 no_match_metric_val_cmd,
2714 "no match metric <0-4294967295>",
2715 NO_STR
2716 MATCH_STR
2717 "Match metric of route\n"
2718 "Metric value\n")
2720 DEFUN (match_community,
2721 match_community_cmd,
2722 "match community (<1-99>|<100-500>|WORD)",
2723 MATCH_STR
2724 "Match BGP community list\n"
2725 "Community-list number (standard)\n"
2726 "Community-list number (expanded)\n"
2727 "Community-list name\n")
2729 return bgp_route_match_add (vty, vty->index, "community", argv[0]);
2732 DEFUN (match_community_exact,
2733 match_community_exact_cmd,
2734 "match community (<1-99>|<100-500>|WORD) exact-match",
2735 MATCH_STR
2736 "Match BGP community list\n"
2737 "Community-list number (standard)\n"
2738 "Community-list number (expanded)\n"
2739 "Community-list name\n"
2740 "Do exact matching of communities\n")
2742 int ret;
2743 char *argstr;
2745 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
2746 strlen (argv[0]) + strlen ("exact-match") + 2);
2748 sprintf (argstr, "%s exact-match", argv[0]);
2750 ret = bgp_route_match_add (vty, vty->index, "community", argstr);
2752 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
2754 return ret;
2757 DEFUN (no_match_community,
2758 no_match_community_cmd,
2759 "no match community",
2760 NO_STR
2761 MATCH_STR
2762 "Match BGP community list\n")
2764 return bgp_route_match_delete (vty, vty->index, "community", NULL);
2767 ALIAS (no_match_community,
2768 no_match_community_val_cmd,
2769 "no match community (<1-99>|<100-500>|WORD)",
2770 NO_STR
2771 MATCH_STR
2772 "Match BGP community list\n"
2773 "Community-list number (standard)\n"
2774 "Community-list number (expanded)\n"
2775 "Community-list name\n")
2777 ALIAS (no_match_community,
2778 no_match_community_exact_cmd,
2779 "no match community (<1-99>|<100-500>|WORD) exact-match",
2780 NO_STR
2781 MATCH_STR
2782 "Match BGP community list\n"
2783 "Community-list number (standard)\n"
2784 "Community-list number (expanded)\n"
2785 "Community-list name\n"
2786 "Do exact matching of communities\n")
2788 DEFUN (match_ecommunity,
2789 match_ecommunity_cmd,
2790 "match extcommunity (<1-99>|<100-500>|WORD)",
2791 MATCH_STR
2792 "Match BGP/VPN extended community list\n"
2793 "Extended community-list number (standard)\n"
2794 "Extended community-list number (expanded)\n"
2795 "Extended community-list name\n")
2797 return bgp_route_match_add (vty, vty->index, "extcommunity", argv[0]);
2800 DEFUN (no_match_ecommunity,
2801 no_match_ecommunity_cmd,
2802 "no match extcommunity",
2803 NO_STR
2804 MATCH_STR
2805 "Match BGP/VPN extended community list\n")
2807 return bgp_route_match_delete (vty, vty->index, "extcommunity", NULL);
2810 ALIAS (no_match_ecommunity,
2811 no_match_ecommunity_val_cmd,
2812 "no match extcommunity (<1-99>|<100-500>|WORD)",
2813 NO_STR
2814 MATCH_STR
2815 "Match BGP/VPN extended community list\n"
2816 "Extended community-list number (standard)\n"
2817 "Extended community-list number (expanded)\n"
2818 "Extended community-list name\n")
2820 DEFUN (match_aspath,
2821 match_aspath_cmd,
2822 "match as-path WORD",
2823 MATCH_STR
2824 "Match BGP AS path list\n"
2825 "AS path access-list name\n")
2827 return bgp_route_match_add (vty, vty->index, "as-path", argv[0]);
2830 DEFUN (no_match_aspath,
2831 no_match_aspath_cmd,
2832 "no match as-path",
2833 NO_STR
2834 MATCH_STR
2835 "Match BGP AS path list\n")
2837 return bgp_route_match_delete (vty, vty->index, "as-path", NULL);
2840 ALIAS (no_match_aspath,
2841 no_match_aspath_val_cmd,
2842 "no match as-path WORD",
2843 NO_STR
2844 MATCH_STR
2845 "Match BGP AS path list\n"
2846 "AS path access-list name\n")
2848 DEFUN (match_origin,
2849 match_origin_cmd,
2850 "match origin (egp|igp|incomplete)",
2851 MATCH_STR
2852 "BGP origin code\n"
2853 "remote EGP\n"
2854 "local IGP\n"
2855 "unknown heritage\n")
2857 if (strncmp (argv[0], "igp", 2) == 0)
2858 return bgp_route_match_add (vty, vty->index, "origin", "igp");
2859 if (strncmp (argv[0], "egp", 1) == 0)
2860 return bgp_route_match_add (vty, vty->index, "origin", "egp");
2861 if (strncmp (argv[0], "incomplete", 2) == 0)
2862 return bgp_route_match_add (vty, vty->index, "origin", "incomplete");
2864 return CMD_WARNING;
2867 DEFUN (no_match_origin,
2868 no_match_origin_cmd,
2869 "no match origin",
2870 NO_STR
2871 MATCH_STR
2872 "BGP origin code\n")
2874 return bgp_route_match_delete (vty, vty->index, "origin", NULL);
2877 ALIAS (no_match_origin,
2878 no_match_origin_val_cmd,
2879 "no match origin (egp|igp|incomplete)",
2880 NO_STR
2881 MATCH_STR
2882 "BGP origin code\n"
2883 "remote EGP\n"
2884 "local IGP\n"
2885 "unknown heritage\n")
2887 DEFUN (set_ip_nexthop,
2888 set_ip_nexthop_cmd,
2889 "set ip next-hop A.B.C.D",
2890 SET_STR
2891 IP_STR
2892 "Next hop address\n"
2893 "IP address of next hop\n")
2895 union sockunion su;
2896 int ret;
2898 ret = str2sockunion (argv[0], &su);
2899 if (ret < 0)
2901 vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
2902 return CMD_WARNING;
2905 return bgp_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
2908 DEFUN (set_ip_nexthop_peer,
2909 set_ip_nexthop_peer_cmd,
2910 "set ip next-hop peer-address",
2911 SET_STR
2912 IP_STR
2913 "Next hop address\n"
2914 "Use peer address (for BGP only)\n")
2916 return bgp_route_set_add (vty, vty->index, "ip next-hop", "peer-address");
2919 DEFUN_DEPRECATED (no_set_ip_nexthop_peer,
2920 no_set_ip_nexthop_peer_cmd,
2921 "no set ip next-hop peer-address",
2922 NO_STR
2923 SET_STR
2924 IP_STR
2925 "Next hop address\n"
2926 "Use peer address (for BGP only)\n")
2928 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2932 DEFUN (no_set_ip_nexthop,
2933 no_set_ip_nexthop_cmd,
2934 "no set ip next-hop",
2935 NO_STR
2936 SET_STR
2937 "Next hop address\n")
2939 if (argc == 0)
2940 return bgp_route_set_delete (vty, vty->index, "ip next-hop", NULL);
2942 return bgp_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
2945 ALIAS (no_set_ip_nexthop,
2946 no_set_ip_nexthop_val_cmd,
2947 "no set ip next-hop A.B.C.D",
2948 NO_STR
2949 SET_STR
2950 IP_STR
2951 "Next hop address\n"
2952 "IP address of next hop\n")
2954 DEFUN (set_metric,
2955 set_metric_cmd,
2956 "set metric <0-4294967295>",
2957 SET_STR
2958 "Metric value for destination routing protocol\n"
2959 "Metric value\n")
2961 return bgp_route_set_add (vty, vty->index, "metric", argv[0]);
2964 ALIAS (set_metric,
2965 set_metric_addsub_cmd,
2966 "set metric <+/-metric>",
2967 SET_STR
2968 "Metric value for destination routing protocol\n"
2969 "Add or subtract metric\n")
2971 DEFUN (no_set_metric,
2972 no_set_metric_cmd,
2973 "no set metric",
2974 NO_STR
2975 SET_STR
2976 "Metric value for destination routing protocol\n")
2978 if (argc == 0)
2979 return bgp_route_set_delete (vty, vty->index, "metric", NULL);
2981 return bgp_route_set_delete (vty, vty->index, "metric", argv[0]);
2984 ALIAS (no_set_metric,
2985 no_set_metric_val_cmd,
2986 "no set metric <0-4294967295>",
2987 NO_STR
2988 SET_STR
2989 "Metric value for destination routing protocol\n"
2990 "Metric value\n")
2992 DEFUN (set_local_pref,
2993 set_local_pref_cmd,
2994 "set local-preference <0-4294967295>",
2995 SET_STR
2996 "BGP local preference path attribute\n"
2997 "Preference value\n")
2999 return bgp_route_set_add (vty, vty->index, "local-preference", argv[0]);
3002 DEFUN (no_set_local_pref,
3003 no_set_local_pref_cmd,
3004 "no set local-preference",
3005 NO_STR
3006 SET_STR
3007 "BGP local preference path attribute\n")
3009 if (argc == 0)
3010 return bgp_route_set_delete (vty, vty->index, "local-preference", NULL);
3012 return bgp_route_set_delete (vty, vty->index, "local-preference", argv[0]);
3015 ALIAS (no_set_local_pref,
3016 no_set_local_pref_val_cmd,
3017 "no set local-preference <0-4294967295>",
3018 NO_STR
3019 SET_STR
3020 "BGP local preference path attribute\n"
3021 "Preference value\n")
3023 DEFUN (set_weight,
3024 set_weight_cmd,
3025 "set weight <0-4294967295>",
3026 SET_STR
3027 "BGP weight for routing table\n"
3028 "Weight value\n")
3030 return bgp_route_set_add (vty, vty->index, "weight", argv[0]);
3033 DEFUN (no_set_weight,
3034 no_set_weight_cmd,
3035 "no set weight",
3036 NO_STR
3037 SET_STR
3038 "BGP weight for routing table\n")
3040 if (argc == 0)
3041 return bgp_route_set_delete (vty, vty->index, "weight", NULL);
3043 return bgp_route_set_delete (vty, vty->index, "weight", argv[0]);
3046 ALIAS (no_set_weight,
3047 no_set_weight_val_cmd,
3048 "no set weight <0-4294967295>",
3049 NO_STR
3050 SET_STR
3051 "BGP weight for routing table\n"
3052 "Weight value\n")
3054 DEFUN (set_aspath_prepend,
3055 set_aspath_prepend_cmd,
3056 "set as-path prepend .<1-65535>",
3057 SET_STR
3058 "Transform BGP AS_PATH attribute\n"
3059 "Prepend to the as-path\n"
3060 "AS number\n")
3062 int ret;
3063 char *str;
3065 str = argv_concat (argv, argc, 0);
3066 ret = bgp_route_set_add (vty, vty->index, "as-path prepend", str);
3067 XFREE (MTYPE_TMP, str);
3069 return ret;
3072 DEFUN (no_set_aspath_prepend,
3073 no_set_aspath_prepend_cmd,
3074 "no set as-path prepend",
3075 NO_STR
3076 SET_STR
3077 "Transform BGP AS_PATH attribute\n"
3078 "Prepend to the as-path\n")
3080 int ret;
3081 char *str;
3083 if (argc == 0)
3084 return bgp_route_set_delete (vty, vty->index, "as-path prepend", NULL);
3086 str = argv_concat (argv, argc, 0);
3087 ret = bgp_route_set_delete (vty, vty->index, "as-path prepend", str);
3088 XFREE (MTYPE_TMP, str);
3089 return ret;
3092 ALIAS (no_set_aspath_prepend,
3093 no_set_aspath_prepend_val_cmd,
3094 "no set as-path prepend .<1-65535>",
3095 NO_STR
3096 SET_STR
3097 "Transform BGP AS_PATH attribute\n"
3098 "Prepend to the as-path\n"
3099 "AS number\n")
3101 DEFUN (set_aspath_exclude,
3102 set_aspath_exclude_cmd,
3103 "set as-path exclude .<1-65535>",
3104 SET_STR
3105 "Transform BGP AS-path attribute\n"
3106 "Exclude from the as-path\n"
3107 "AS number\n")
3109 int ret;
3110 char *str;
3112 str = argv_concat (argv, argc, 0);
3113 ret = bgp_route_set_add (vty, vty->index, "as-path exclude", str);
3114 XFREE (MTYPE_TMP, str);
3115 return ret;
3118 DEFUN (no_set_aspath_exclude,
3119 no_set_aspath_exclude_cmd,
3120 "no set as-path exclude",
3121 NO_STR
3122 SET_STR
3123 "Transform BGP AS_PATH attribute\n"
3124 "Exclude from the as-path\n")
3126 int ret;
3127 char *str;
3129 if (argc == 0)
3130 return bgp_route_set_delete (vty, vty->index, "as-path exclude", NULL);
3132 str = argv_concat (argv, argc, 0);
3133 ret = bgp_route_set_delete (vty, vty->index, "as-path exclude", str);
3134 XFREE (MTYPE_TMP, str);
3135 return ret;
3138 ALIAS (no_set_aspath_exclude,
3139 no_set_aspath_exclude_val_cmd,
3140 "no set as-path exclude .<1-65535>",
3141 NO_STR
3142 SET_STR
3143 "Transform BGP AS_PATH attribute\n"
3144 "Exclude from the as-path\n"
3145 "AS number\n")
3147 DEFUN (set_community,
3148 set_community_cmd,
3149 "set community .AA:NN",
3150 SET_STR
3151 "BGP community attribute\n"
3152 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3154 int i;
3155 int first = 0;
3156 int additive = 0;
3157 struct buffer *b;
3158 struct community *com = NULL;
3159 char *str;
3160 char *argstr;
3161 int ret;
3163 b = buffer_new (1024);
3165 for (i = 0; i < argc; i++)
3167 if (strncmp (argv[i], "additive", strlen (argv[i])) == 0)
3169 additive = 1;
3170 continue;
3173 if (first)
3174 buffer_putc (b, ' ');
3175 else
3176 first = 1;
3178 if (strncmp (argv[i], "internet", strlen (argv[i])) == 0)
3180 buffer_putstr (b, "internet");
3181 continue;
3183 if (strncmp (argv[i], "local-AS", strlen (argv[i])) == 0)
3185 buffer_putstr (b, "local-AS");
3186 continue;
3188 if (strncmp (argv[i], "no-a", strlen ("no-a")) == 0
3189 && strncmp (argv[i], "no-advertise", strlen (argv[i])) == 0)
3191 buffer_putstr (b, "no-advertise");
3192 continue;
3194 if (strncmp (argv[i], "no-e", strlen ("no-e"))== 0
3195 && strncmp (argv[i], "no-export", strlen (argv[i])) == 0)
3197 buffer_putstr (b, "no-export");
3198 continue;
3200 buffer_putstr (b, argv[i]);
3202 buffer_putc (b, '\0');
3204 /* Fetch result string then compile it to communities attribute. */
3205 str = buffer_getstr (b);
3206 buffer_free (b);
3208 if (str)
3210 com = community_str2com (str);
3211 XFREE (MTYPE_TMP, str);
3214 /* Can't compile user input into communities attribute. */
3215 if (! com)
3217 vty_out (vty, "%% Malformed communities attribute%s", VTY_NEWLINE);
3218 return CMD_WARNING;
3221 /* Set communites attribute string. */
3222 str = community_str (com);
3224 if (additive)
3226 argstr = XCALLOC (MTYPE_TMP, strlen (str) + strlen (" additive") + 1);
3227 strcpy (argstr, str);
3228 strcpy (argstr + strlen (str), " additive");
3229 ret = bgp_route_set_add (vty, vty->index, "community", argstr);
3230 XFREE (MTYPE_TMP, argstr);
3232 else
3233 ret = bgp_route_set_add (vty, vty->index, "community", str);
3235 community_free (com);
3237 return ret;
3240 DEFUN (set_community_none,
3241 set_community_none_cmd,
3242 "set community none",
3243 SET_STR
3244 "BGP community attribute\n"
3245 "No community attribute\n")
3247 return bgp_route_set_add (vty, vty->index, "community", "none");
3250 DEFUN (no_set_community,
3251 no_set_community_cmd,
3252 "no set community",
3253 NO_STR
3254 SET_STR
3255 "BGP community attribute\n")
3257 return bgp_route_set_delete (vty, vty->index, "community", NULL);
3260 ALIAS (no_set_community,
3261 no_set_community_val_cmd,
3262 "no set community .AA:NN",
3263 NO_STR
3264 SET_STR
3265 "BGP community attribute\n"
3266 "Community number in aa:nn format or local-AS|no-advertise|no-export|internet or additive\n")
3268 ALIAS (no_set_community,
3269 no_set_community_none_cmd,
3270 "no set community none",
3271 NO_STR
3272 SET_STR
3273 "BGP community attribute\n"
3274 "No community attribute\n")
3276 DEFUN (set_community_delete,
3277 set_community_delete_cmd,
3278 "set comm-list (<1-99>|<100-500>|WORD) delete",
3279 SET_STR
3280 "set BGP community list (for deletion)\n"
3281 "Community-list number (standard)\n"
3282 "Communitly-list number (expanded)\n"
3283 "Community-list name\n"
3284 "Delete matching communities\n")
3286 char *str;
3288 str = XCALLOC (MTYPE_TMP, strlen (argv[0]) + strlen (" delete") + 1);
3289 strcpy (str, argv[0]);
3290 strcpy (str + strlen (argv[0]), " delete");
3292 bgp_route_set_add (vty, vty->index, "comm-list", str);
3294 XFREE (MTYPE_TMP, str);
3295 return CMD_SUCCESS;
3298 DEFUN (no_set_community_delete,
3299 no_set_community_delete_cmd,
3300 "no set comm-list",
3301 NO_STR
3302 SET_STR
3303 "set BGP community list (for deletion)\n")
3305 return bgp_route_set_delete (vty, vty->index, "comm-list", NULL);
3308 ALIAS (no_set_community_delete,
3309 no_set_community_delete_val_cmd,
3310 "no set comm-list (<1-99>|<100-500>|WORD) delete",
3311 NO_STR
3312 SET_STR
3313 "set BGP community list (for deletion)\n"
3314 "Community-list number (standard)\n"
3315 "Communitly-list number (expanded)\n"
3316 "Community-list name\n"
3317 "Delete matching communities\n")
3319 DEFUN (set_ecommunity_rt,
3320 set_ecommunity_rt_cmd,
3321 "set extcommunity rt .ASN:nn_or_IP-address:nn",
3322 SET_STR
3323 "BGP extended community attribute\n"
3324 "Route Target extened communityt\n"
3325 "VPN extended community\n")
3327 int ret;
3328 char *str;
3330 str = argv_concat (argv, argc, 0);
3331 ret = bgp_route_set_add (vty, vty->index, "extcommunity rt", str);
3332 XFREE (MTYPE_TMP, str);
3334 return ret;
3337 DEFUN (no_set_ecommunity_rt,
3338 no_set_ecommunity_rt_cmd,
3339 "no set extcommunity rt",
3340 NO_STR
3341 SET_STR
3342 "BGP extended community attribute\n"
3343 "Route Target extened communityt\n")
3345 return bgp_route_set_delete (vty, vty->index, "extcommunity rt", NULL);
3348 ALIAS (no_set_ecommunity_rt,
3349 no_set_ecommunity_rt_val_cmd,
3350 "no set extcommunity rt .ASN:nn_or_IP-address:nn",
3351 NO_STR
3352 SET_STR
3353 "BGP extended community attribute\n"
3354 "Route Target extened communityt\n"
3355 "VPN extended community\n")
3357 DEFUN (set_ecommunity_soo,
3358 set_ecommunity_soo_cmd,
3359 "set extcommunity soo .ASN:nn_or_IP-address:nn",
3360 SET_STR
3361 "BGP extended community attribute\n"
3362 "Site-of-Origin extended community\n"
3363 "VPN extended community\n")
3365 int ret;
3366 char *str;
3368 str = argv_concat (argv, argc, 0);
3369 ret = bgp_route_set_add (vty, vty->index, "extcommunity soo", str);
3370 XFREE (MTYPE_TMP, str);
3371 return ret;
3374 DEFUN (no_set_ecommunity_soo,
3375 no_set_ecommunity_soo_cmd,
3376 "no set extcommunity soo",
3377 NO_STR
3378 SET_STR
3379 "BGP extended community attribute\n"
3380 "Site-of-Origin extended community\n")
3382 return bgp_route_set_delete (vty, vty->index, "extcommunity soo", NULL);
3385 ALIAS (no_set_ecommunity_soo,
3386 no_set_ecommunity_soo_val_cmd,
3387 "no set extcommunity soo .ASN:nn_or_IP-address:nn",
3388 NO_STR
3389 SET_STR
3390 "BGP extended community attribute\n"
3391 "Site-of-Origin extended community\n"
3392 "VPN extended community\n")
3394 DEFUN (set_origin,
3395 set_origin_cmd,
3396 "set origin (egp|igp|incomplete)",
3397 SET_STR
3398 "BGP origin code\n"
3399 "remote EGP\n"
3400 "local IGP\n"
3401 "unknown heritage\n")
3403 if (strncmp (argv[0], "igp", 2) == 0)
3404 return bgp_route_set_add (vty, vty->index, "origin", "igp");
3405 if (strncmp (argv[0], "egp", 1) == 0)
3406 return bgp_route_set_add (vty, vty->index, "origin", "egp");
3407 if (strncmp (argv[0], "incomplete", 2) == 0)
3408 return bgp_route_set_add (vty, vty->index, "origin", "incomplete");
3410 return CMD_WARNING;
3413 DEFUN (no_set_origin,
3414 no_set_origin_cmd,
3415 "no set origin",
3416 NO_STR
3417 SET_STR
3418 "BGP origin code\n")
3420 return bgp_route_set_delete (vty, vty->index, "origin", NULL);
3423 ALIAS (no_set_origin,
3424 no_set_origin_val_cmd,
3425 "no set origin (egp|igp|incomplete)",
3426 NO_STR
3427 SET_STR
3428 "BGP origin code\n"
3429 "remote EGP\n"
3430 "local IGP\n"
3431 "unknown heritage\n")
3433 DEFUN (set_atomic_aggregate,
3434 set_atomic_aggregate_cmd,
3435 "set atomic-aggregate",
3436 SET_STR
3437 "BGP atomic aggregate attribute\n" )
3439 return bgp_route_set_add (vty, vty->index, "atomic-aggregate", NULL);
3442 DEFUN (no_set_atomic_aggregate,
3443 no_set_atomic_aggregate_cmd,
3444 "no set atomic-aggregate",
3445 NO_STR
3446 SET_STR
3447 "BGP atomic aggregate attribute\n" )
3449 return bgp_route_set_delete (vty, vty->index, "atomic-aggregate", NULL);
3452 DEFUN (set_aggregator_as,
3453 set_aggregator_as_cmd,
3454 "set aggregator as " CMD_AS_RANGE " A.B.C.D",
3455 SET_STR
3456 "BGP aggregator attribute\n"
3457 "AS number of aggregator\n"
3458 "AS number\n"
3459 "IP address of aggregator\n")
3461 int ret;
3462 as_t as;
3463 struct in_addr address;
3464 char *argstr;
3466 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
3468 ret = inet_aton (argv[1], &address);
3469 if (ret == 0)
3471 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3472 return CMD_WARNING;
3475 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3476 strlen (argv[0]) + strlen (argv[1]) + 2);
3478 sprintf (argstr, "%s %s", argv[0], argv[1]);
3480 ret = bgp_route_set_add (vty, vty->index, "aggregator as", argstr);
3482 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3484 return ret;
3487 DEFUN (no_set_aggregator_as,
3488 no_set_aggregator_as_cmd,
3489 "no set aggregator as",
3490 NO_STR
3491 SET_STR
3492 "BGP aggregator attribute\n"
3493 "AS number of aggregator\n")
3495 int ret;
3496 as_t as;
3497 struct in_addr address;
3498 char *argstr;
3500 if (argv == 0)
3501 return bgp_route_set_delete (vty, vty->index, "aggregator as", NULL);
3503 VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
3505 ret = inet_aton (argv[1], &address);
3506 if (ret == 0)
3508 vty_out (vty, "Aggregator IP address is invalid%s", VTY_NEWLINE);
3509 return CMD_WARNING;
3512 argstr = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
3513 strlen (argv[0]) + strlen (argv[1]) + 2);
3515 sprintf (argstr, "%s %s", argv[0], argv[1]);
3517 ret = bgp_route_set_delete (vty, vty->index, "aggregator as", argstr);
3519 XFREE (MTYPE_ROUTE_MAP_COMPILED, argstr);
3521 return ret;
3524 ALIAS (no_set_aggregator_as,
3525 no_set_aggregator_as_val_cmd,
3526 "no set aggregator as " CMD_AS_RANGE " A.B.C.D",
3527 NO_STR
3528 SET_STR
3529 "BGP aggregator attribute\n"
3530 "AS number of aggregator\n"
3531 "AS number\n"
3532 "IP address of aggregator\n")
3535 #ifdef HAVE_IPV6
3536 DEFUN (match_ipv6_address,
3537 match_ipv6_address_cmd,
3538 "match ipv6 address WORD",
3539 MATCH_STR
3540 IPV6_STR
3541 "Match IPv6 address of route\n"
3542 "IPv6 access-list name\n")
3544 return bgp_route_match_add (vty, vty->index, "ipv6 address", argv[0]);
3547 DEFUN (no_match_ipv6_address,
3548 no_match_ipv6_address_cmd,
3549 "no match ipv6 address WORD",
3550 NO_STR
3551 MATCH_STR
3552 IPV6_STR
3553 "Match IPv6 address of route\n"
3554 "IPv6 access-list name\n")
3556 return bgp_route_match_delete (vty, vty->index, "ipv6 address", argv[0]);
3559 DEFUN (match_ipv6_next_hop,
3560 match_ipv6_next_hop_cmd,
3561 "match ipv6 next-hop X:X::X:X",
3562 MATCH_STR
3563 IPV6_STR
3564 "Match IPv6 next-hop address of route\n"
3565 "IPv6 address of next hop\n")
3567 return bgp_route_match_add (vty, vty->index, "ipv6 next-hop", argv[0]);
3570 DEFUN (no_match_ipv6_next_hop,
3571 no_match_ipv6_next_hop_cmd,
3572 "no match ipv6 next-hop X:X::X:X",
3573 NO_STR
3574 MATCH_STR
3575 IPV6_STR
3576 "Match IPv6 next-hop address of route\n"
3577 "IPv6 address of next hop\n")
3579 return bgp_route_match_delete (vty, vty->index, "ipv6 next-hop", argv[0]);
3582 DEFUN (match_ipv6_address_prefix_list,
3583 match_ipv6_address_prefix_list_cmd,
3584 "match ipv6 address prefix-list WORD",
3585 MATCH_STR
3586 IPV6_STR
3587 "Match address of route\n"
3588 "Match entries of prefix-lists\n"
3589 "IP prefix-list name\n")
3591 return bgp_route_match_add (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3594 DEFUN (no_match_ipv6_address_prefix_list,
3595 no_match_ipv6_address_prefix_list_cmd,
3596 "no match ipv6 address prefix-list WORD",
3597 NO_STR
3598 MATCH_STR
3599 IPV6_STR
3600 "Match address of route\n"
3601 "Match entries of prefix-lists\n"
3602 "IP prefix-list name\n")
3604 return bgp_route_match_delete (vty, vty->index, "ipv6 address prefix-list", argv[0]);
3607 DEFUN (set_ipv6_nexthop_global,
3608 set_ipv6_nexthop_global_cmd,
3609 "set ipv6 next-hop global X:X::X:X",
3610 SET_STR
3611 IPV6_STR
3612 "IPv6 next-hop address\n"
3613 "IPv6 global address\n"
3614 "IPv6 address of next hop\n")
3616 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop global", argv[0]);
3619 DEFUN (no_set_ipv6_nexthop_global,
3620 no_set_ipv6_nexthop_global_cmd,
3621 "no set ipv6 next-hop global",
3622 NO_STR
3623 SET_STR
3624 IPV6_STR
3625 "IPv6 next-hop address\n"
3626 "IPv6 global address\n")
3628 if (argc == 0)
3629 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", NULL);
3631 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop global", argv[0]);
3634 ALIAS (no_set_ipv6_nexthop_global,
3635 no_set_ipv6_nexthop_global_val_cmd,
3636 "no set ipv6 next-hop global X:X::X:X",
3637 NO_STR
3638 SET_STR
3639 IPV6_STR
3640 "IPv6 next-hop address\n"
3641 "IPv6 global address\n"
3642 "IPv6 address of next hop\n")
3644 DEFUN (set_ipv6_nexthop_local,
3645 set_ipv6_nexthop_local_cmd,
3646 "set ipv6 next-hop local X:X::X:X",
3647 SET_STR
3648 IPV6_STR
3649 "IPv6 next-hop address\n"
3650 "IPv6 local address\n"
3651 "IPv6 address of next hop\n")
3653 return bgp_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
3656 DEFUN (no_set_ipv6_nexthop_local,
3657 no_set_ipv6_nexthop_local_cmd,
3658 "no set ipv6 next-hop local",
3659 NO_STR
3660 SET_STR
3661 IPV6_STR
3662 "IPv6 next-hop address\n"
3663 "IPv6 local address\n")
3665 if (argc == 0)
3666 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
3668 return bgp_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
3671 ALIAS (no_set_ipv6_nexthop_local,
3672 no_set_ipv6_nexthop_local_val_cmd,
3673 "no set ipv6 next-hop local X:X::X:X",
3674 NO_STR
3675 SET_STR
3676 IPV6_STR
3677 "IPv6 next-hop address\n"
3678 "IPv6 local address\n"
3679 "IPv6 address of next hop\n")
3680 #endif /* HAVE_IPV6 */
3682 DEFUN (set_vpnv4_nexthop,
3683 set_vpnv4_nexthop_cmd,
3684 "set vpnv4 next-hop A.B.C.D",
3685 SET_STR
3686 "VPNv4 information\n"
3687 "VPNv4 next-hop address\n"
3688 "IP address of next hop\n")
3690 return bgp_route_set_add (vty, vty->index, "vpnv4 next-hop", argv[0]);
3693 DEFUN (no_set_vpnv4_nexthop,
3694 no_set_vpnv4_nexthop_cmd,
3695 "no set vpnv4 next-hop",
3696 NO_STR
3697 SET_STR
3698 "VPNv4 information\n"
3699 "VPNv4 next-hop address\n")
3701 if (argc == 0)
3702 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", NULL);
3704 return bgp_route_set_delete (vty, vty->index, "vpnv4 next-hop", argv[0]);
3707 ALIAS (no_set_vpnv4_nexthop,
3708 no_set_vpnv4_nexthop_val_cmd,
3709 "no set vpnv4 next-hop A.B.C.D",
3710 NO_STR
3711 SET_STR
3712 "VPNv4 information\n"
3713 "VPNv4 next-hop address\n"
3714 "IP address of next hop\n")
3716 DEFUN (set_originator_id,
3717 set_originator_id_cmd,
3718 "set originator-id A.B.C.D",
3719 SET_STR
3720 "BGP originator ID attribute\n"
3721 "IP address of originator\n")
3723 return bgp_route_set_add (vty, vty->index, "originator-id", argv[0]);
3726 DEFUN (no_set_originator_id,
3727 no_set_originator_id_cmd,
3728 "no set originator-id",
3729 NO_STR
3730 SET_STR
3731 "BGP originator ID attribute\n")
3733 if (argc == 0)
3734 return bgp_route_set_delete (vty, vty->index, "originator-id", NULL);
3736 return bgp_route_set_delete (vty, vty->index, "originator-id", argv[0]);
3739 ALIAS (no_set_originator_id,
3740 no_set_originator_id_val_cmd,
3741 "no set originator-id A.B.C.D",
3742 NO_STR
3743 SET_STR
3744 "BGP originator ID attribute\n"
3745 "IP address of originator\n")
3747 DEFUN (set_pathlimit_ttl,
3748 set_pathlimit_ttl_cmd,
3749 "set pathlimit ttl <1-255>",
3750 SET_STR
3751 "BGP AS-Pathlimit attribute\n"
3752 "Set AS-Path Hop-count TTL\n")
3754 return bgp_route_set_add (vty, vty->index, "pathlimit ttl", argv[0]);
3757 DEFUN (no_set_pathlimit_ttl,
3758 no_set_pathlimit_ttl_cmd,
3759 "no set pathlimit ttl",
3760 NO_STR
3761 SET_STR
3762 "BGP AS-Pathlimit attribute\n"
3763 "Set AS-Path Hop-count TTL\n")
3765 if (argc == 0)
3766 return bgp_route_set_delete (vty, vty->index, "pathlimit ttl", NULL);
3768 return bgp_route_set_delete (vty, vty->index, "pathlimit ttl", argv[0]);
3771 ALIAS (no_set_pathlimit_ttl,
3772 no_set_pathlimit_ttl_val_cmd,
3773 "no set pathlimit ttl <1-255>",
3774 NO_STR
3775 MATCH_STR
3776 "BGP AS-Pathlimit attribute\n"
3777 "Set AS-Path Hop-count TTL\n")
3779 DEFUN (match_pathlimit_as,
3780 match_pathlimit_as_cmd,
3781 "match pathlimit as <1-65535>",
3782 MATCH_STR
3783 "BGP AS-Pathlimit attribute\n"
3784 "Match Pathlimit AS number\n")
3786 return bgp_route_match_add (vty, vty->index, "pathlimit as", argv[0]);
3789 DEFUN (no_match_pathlimit_as,
3790 no_match_pathlimit_as_cmd,
3791 "no match pathlimit as",
3792 NO_STR
3793 MATCH_STR
3794 "BGP AS-Pathlimit attribute\n"
3795 "Match Pathlimit AS number\n")
3797 if (argc == 0)
3798 return bgp_route_match_delete (vty, vty->index, "pathlimit as", NULL);
3800 return bgp_route_match_delete (vty, vty->index, "pathlimit as", argv[0]);
3803 ALIAS (no_match_pathlimit_as,
3804 no_match_pathlimit_as_val_cmd,
3805 "no match pathlimit as <1-65535>",
3806 NO_STR
3807 MATCH_STR
3808 "BGP AS-Pathlimit attribute\n"
3809 "Match Pathlimit ASN\n")
3812 /* Initialization of route map. */
3813 void
3814 bgp_route_map_init (void)
3816 route_map_init ();
3817 route_map_init_vty ();
3818 route_map_add_hook (bgp_route_map_update);
3819 route_map_delete_hook (bgp_route_map_update);
3821 route_map_install_match (&route_match_peer_cmd);
3822 route_map_install_match (&route_match_ip_address_cmd);
3823 route_map_install_match (&route_match_ip_next_hop_cmd);
3824 route_map_install_match (&route_match_ip_route_source_cmd);
3825 route_map_install_match (&route_match_ip_address_prefix_list_cmd);
3826 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
3827 route_map_install_match (&route_match_ip_route_source_prefix_list_cmd);
3828 route_map_install_match (&route_match_aspath_cmd);
3829 route_map_install_match (&route_match_community_cmd);
3830 route_map_install_match (&route_match_ecommunity_cmd);
3831 route_map_install_match (&route_match_metric_cmd);
3832 route_map_install_match (&route_match_origin_cmd);
3834 route_map_install_set (&route_set_ip_nexthop_cmd);
3835 route_map_install_set (&route_set_local_pref_cmd);
3836 route_map_install_set (&route_set_weight_cmd);
3837 route_map_install_set (&route_set_metric_cmd);
3838 route_map_install_set (&route_set_aspath_prepend_cmd);
3839 route_map_install_set (&route_set_aspath_exclude_cmd);
3840 route_map_install_set (&route_set_origin_cmd);
3841 route_map_install_set (&route_set_atomic_aggregate_cmd);
3842 route_map_install_set (&route_set_aggregator_as_cmd);
3843 route_map_install_set (&route_set_community_cmd);
3844 route_map_install_set (&route_set_community_delete_cmd);
3845 route_map_install_set (&route_set_vpnv4_nexthop_cmd);
3846 route_map_install_set (&route_set_originator_id_cmd);
3847 route_map_install_set (&route_set_ecommunity_rt_cmd);
3848 route_map_install_set (&route_set_ecommunity_soo_cmd);
3850 install_element (RMAP_NODE, &match_peer_cmd);
3851 install_element (RMAP_NODE, &match_peer_local_cmd);
3852 install_element (RMAP_NODE, &no_match_peer_cmd);
3853 install_element (RMAP_NODE, &no_match_peer_val_cmd);
3854 install_element (RMAP_NODE, &no_match_peer_local_cmd);
3855 install_element (RMAP_NODE, &match_ip_address_cmd);
3856 install_element (RMAP_NODE, &no_match_ip_address_cmd);
3857 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
3858 install_element (RMAP_NODE, &match_ip_next_hop_cmd);
3859 install_element (RMAP_NODE, &no_match_ip_next_hop_cmd);
3860 install_element (RMAP_NODE, &no_match_ip_next_hop_val_cmd);
3861 install_element (RMAP_NODE, &match_ip_route_source_cmd);
3862 install_element (RMAP_NODE, &no_match_ip_route_source_cmd);
3863 install_element (RMAP_NODE, &no_match_ip_route_source_val_cmd);
3865 install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
3866 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
3867 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
3868 install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
3869 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
3870 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
3871 install_element (RMAP_NODE, &match_ip_route_source_prefix_list_cmd);
3872 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_cmd);
3873 install_element (RMAP_NODE, &no_match_ip_route_source_prefix_list_val_cmd);
3875 install_element (RMAP_NODE, &match_aspath_cmd);
3876 install_element (RMAP_NODE, &no_match_aspath_cmd);
3877 install_element (RMAP_NODE, &no_match_aspath_val_cmd);
3878 install_element (RMAP_NODE, &match_metric_cmd);
3879 install_element (RMAP_NODE, &no_match_metric_cmd);
3880 install_element (RMAP_NODE, &no_match_metric_val_cmd);
3881 install_element (RMAP_NODE, &match_community_cmd);
3882 install_element (RMAP_NODE, &match_community_exact_cmd);
3883 install_element (RMAP_NODE, &no_match_community_cmd);
3884 install_element (RMAP_NODE, &no_match_community_val_cmd);
3885 install_element (RMAP_NODE, &no_match_community_exact_cmd);
3886 install_element (RMAP_NODE, &match_ecommunity_cmd);
3887 install_element (RMAP_NODE, &no_match_ecommunity_cmd);
3888 install_element (RMAP_NODE, &no_match_ecommunity_val_cmd);
3889 install_element (RMAP_NODE, &match_origin_cmd);
3890 install_element (RMAP_NODE, &no_match_origin_cmd);
3891 install_element (RMAP_NODE, &no_match_origin_val_cmd);
3893 install_element (RMAP_NODE, &set_ip_nexthop_cmd);
3894 install_element (RMAP_NODE, &set_ip_nexthop_peer_cmd);
3895 install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
3896 install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
3897 install_element (RMAP_NODE, &set_local_pref_cmd);
3898 install_element (RMAP_NODE, &no_set_local_pref_cmd);
3899 install_element (RMAP_NODE, &no_set_local_pref_val_cmd);
3900 install_element (RMAP_NODE, &set_weight_cmd);
3901 install_element (RMAP_NODE, &no_set_weight_cmd);
3902 install_element (RMAP_NODE, &no_set_weight_val_cmd);
3903 install_element (RMAP_NODE, &set_metric_cmd);
3904 install_element (RMAP_NODE, &set_metric_addsub_cmd);
3905 install_element (RMAP_NODE, &no_set_metric_cmd);
3906 install_element (RMAP_NODE, &no_set_metric_val_cmd);
3907 install_element (RMAP_NODE, &set_aspath_prepend_cmd);
3908 install_element (RMAP_NODE, &set_aspath_exclude_cmd);
3909 install_element (RMAP_NODE, &no_set_aspath_prepend_cmd);
3910 install_element (RMAP_NODE, &no_set_aspath_prepend_val_cmd);
3911 install_element (RMAP_NODE, &no_set_aspath_exclude_cmd);
3912 install_element (RMAP_NODE, &no_set_aspath_exclude_val_cmd);
3913 install_element (RMAP_NODE, &set_origin_cmd);
3914 install_element (RMAP_NODE, &no_set_origin_cmd);
3915 install_element (RMAP_NODE, &no_set_origin_val_cmd);
3916 install_element (RMAP_NODE, &set_atomic_aggregate_cmd);
3917 install_element (RMAP_NODE, &no_set_atomic_aggregate_cmd);
3918 install_element (RMAP_NODE, &set_aggregator_as_cmd);
3919 install_element (RMAP_NODE, &no_set_aggregator_as_cmd);
3920 install_element (RMAP_NODE, &no_set_aggregator_as_val_cmd);
3921 install_element (RMAP_NODE, &set_community_cmd);
3922 install_element (RMAP_NODE, &set_community_none_cmd);
3923 install_element (RMAP_NODE, &no_set_community_cmd);
3924 install_element (RMAP_NODE, &no_set_community_val_cmd);
3925 install_element (RMAP_NODE, &no_set_community_none_cmd);
3926 install_element (RMAP_NODE, &set_community_delete_cmd);
3927 install_element (RMAP_NODE, &no_set_community_delete_cmd);
3928 install_element (RMAP_NODE, &no_set_community_delete_val_cmd);
3929 install_element (RMAP_NODE, &set_ecommunity_rt_cmd);
3930 install_element (RMAP_NODE, &no_set_ecommunity_rt_cmd);
3931 install_element (RMAP_NODE, &no_set_ecommunity_rt_val_cmd);
3932 install_element (RMAP_NODE, &set_ecommunity_soo_cmd);
3933 install_element (RMAP_NODE, &no_set_ecommunity_soo_cmd);
3934 install_element (RMAP_NODE, &no_set_ecommunity_soo_val_cmd);
3935 install_element (RMAP_NODE, &set_vpnv4_nexthop_cmd);
3936 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_cmd);
3937 install_element (RMAP_NODE, &no_set_vpnv4_nexthop_val_cmd);
3938 install_element (RMAP_NODE, &set_originator_id_cmd);
3939 install_element (RMAP_NODE, &no_set_originator_id_cmd);
3940 install_element (RMAP_NODE, &no_set_originator_id_val_cmd);
3942 #ifdef HAVE_IPV6
3943 route_map_install_match (&route_match_ipv6_address_cmd);
3944 route_map_install_match (&route_match_ipv6_next_hop_cmd);
3945 route_map_install_match (&route_match_ipv6_address_prefix_list_cmd);
3946 route_map_install_set (&route_set_ipv6_nexthop_global_cmd);
3947 route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
3949 install_element (RMAP_NODE, &match_ipv6_address_cmd);
3950 install_element (RMAP_NODE, &no_match_ipv6_address_cmd);
3951 install_element (RMAP_NODE, &match_ipv6_next_hop_cmd);
3952 install_element (RMAP_NODE, &no_match_ipv6_next_hop_cmd);
3953 install_element (RMAP_NODE, &match_ipv6_address_prefix_list_cmd);
3954 install_element (RMAP_NODE, &no_match_ipv6_address_prefix_list_cmd);
3955 install_element (RMAP_NODE, &set_ipv6_nexthop_global_cmd);
3956 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_cmd);
3957 install_element (RMAP_NODE, &no_set_ipv6_nexthop_global_val_cmd);
3958 install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
3959 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
3960 install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
3961 #endif /* HAVE_IPV6 */
3963 /* AS-Pathlimit */
3964 route_map_install_match (&route_match_pathlimit_as_cmd);
3965 route_map_install_set (&route_set_pathlimit_ttl_cmd);
3967 install_element (RMAP_NODE, &set_pathlimit_ttl_cmd);
3968 install_element (RMAP_NODE, &no_set_pathlimit_ttl_cmd);
3969 install_element (RMAP_NODE, &no_set_pathlimit_ttl_val_cmd);
3970 install_element (RMAP_NODE, &match_pathlimit_as_cmd);
3971 install_element (RMAP_NODE, &no_match_pathlimit_as_cmd);
3972 install_element (RMAP_NODE, &no_match_pathlimit_as_val_cmd);