usbmodeswitch: Updated to v.1.2.6 from shibby's branch.
[tomato.git] / release / src / router / zebra / bgpd / bgp_route.c
blob2623c7cd1524bef0b6df3a35778539de665e243d
1 /* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 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 "linklist.h"
25 #include "memory.h"
26 #include "command.h"
27 #include "stream.h"
28 #include "filter.h"
29 #include "str.h"
30 #include "log.h"
31 #include "routemap.h"
32 #include "buffer.h"
33 #include "sockunion.h"
34 #include "plist.h"
35 #include "thread.h"
37 #include "bgpd/bgpd.h"
38 #include "bgpd/bgp_table.h"
39 #include "bgpd/bgp_route.h"
40 #include "bgpd/bgp_attr.h"
41 #include "bgpd/bgp_debug.h"
42 #include "bgpd/bgp_aspath.h"
43 #include "bgpd/bgp_regex.h"
44 #include "bgpd/bgp_community.h"
45 #include "bgpd/bgp_ecommunity.h"
46 #include "bgpd/bgp_clist.h"
47 #include "bgpd/bgp_packet.h"
48 #include "bgpd/bgp_filter.h"
49 #include "bgpd/bgp_fsm.h"
50 #include "bgpd/bgp_mplsvpn.h"
51 #include "bgpd/bgp_nexthop.h"
52 #include "bgpd/bgp_damp.h"
53 #include "bgpd/bgp_advertise.h"
54 #include "bgpd/bgp_zebra.h"
55 #include "bgpd/bgp_vty.h"
57 /* Extern from bgp_dump.c */
58 extern char *bgp_origin_str[];
59 extern char *bgp_origin_long_str[];
61 struct bgp_node *
62 bgp_afi_node_get (struct bgp *bgp, afi_t afi, safi_t safi, struct prefix *p,
63 struct prefix_rd *prd)
65 struct bgp_node *rn;
66 struct bgp_node *prn = NULL;
67 struct bgp_table *table;
69 if (safi == SAFI_MPLS_VPN)
71 prn = bgp_node_get (bgp->rib[afi][safi], (struct prefix *) prd);
73 if (prn->info == NULL)
74 prn->info = bgp_table_init ();
75 else
76 bgp_unlock_node (prn);
77 table = prn->info;
79 else
80 table = bgp->rib[afi][safi];
82 rn = bgp_node_get (table, p);
84 if (safi == SAFI_MPLS_VPN)
85 rn->prn = prn;
87 return rn;
90 /* Allocate new bgp info structure. */
91 struct bgp_info *
92 bgp_info_new ()
94 struct bgp_info *new;
96 new = XMALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
97 memset (new, 0, sizeof (struct bgp_info));
99 return new;
102 /* Free bgp route information. */
103 void
104 bgp_info_free (struct bgp_info *binfo)
106 if (binfo->attr)
107 bgp_attr_unintern (binfo->attr);
109 if (binfo->damp_info)
110 bgp_damp_info_free (binfo->damp_info, 0);
112 XFREE (MTYPE_BGP_ROUTE, binfo);
115 void
116 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
118 struct bgp_info *top;
120 top = rn->info;
122 ri->next = rn->info;
123 ri->prev = NULL;
124 if (top)
125 top->prev = ri;
126 rn->info = ri;
129 void
130 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
132 if (ri->next)
133 ri->next->prev = ri->prev;
134 if (ri->prev)
135 ri->prev->next = ri->next;
136 else
137 rn->info = ri->next;
140 /* Get MED value. If MED value is missing and "bgp bestpath
141 missing-as-worst" is specified, treat it as the worst value. */
142 u_int32_t
143 bgp_med_value (struct attr *attr, struct bgp *bgp)
145 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
146 return attr->med;
147 else
149 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
150 return 4294967295ul;
151 else
152 return 0;
156 /* Compare two bgp route entity. br is preferable then return 1. */
158 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
160 u_int32_t new_pref;
161 u_int32_t exist_pref;
162 u_int32_t new_med;
163 u_int32_t exist_med;
164 struct in_addr new_id;
165 struct in_addr exist_id;
166 int new_cluster;
167 int exist_cluster;
168 int internal_as_route = 0;
169 int confed_as_route = 0;
170 int cost_community = 0;
171 int ret;
173 /* 0. Null check. */
174 if (new == NULL)
175 return 0;
176 if (exist == NULL)
177 return 1;
179 /* 1. Weight check. */
180 if (new->attr->weight > exist->attr->weight)
181 return 1;
182 if (new->attr->weight < exist->attr->weight)
183 return 0;
185 /* 2. Local preference check. */
186 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
187 new_pref = new->attr->local_pref;
188 else
189 new_pref = bgp->default_local_pref;
191 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
192 exist_pref = exist->attr->local_pref;
193 else
194 exist_pref = bgp->default_local_pref;
196 if (new_pref > exist_pref)
197 return 1;
198 if (new_pref < exist_pref)
199 return 0;
201 /* 3. Local route check. */
202 if (new->sub_type == BGP_ROUTE_STATIC)
203 return 1;
204 if (exist->sub_type == BGP_ROUTE_STATIC)
205 return 0;
207 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
208 return 1;
209 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
210 return 0;
212 if (new->sub_type == BGP_ROUTE_AGGREGATE)
213 return 1;
214 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
215 return 0;
217 /* 4. AS path length check. */
218 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
220 if (new->attr->aspath->count < exist->attr->aspath->count)
221 return 1;
222 if (new->attr->aspath->count > exist->attr->aspath->count)
223 return 0;
226 /* 5. Origin check. */
227 if (new->attr->origin < exist->attr->origin)
228 return 1;
229 if (new->attr->origin > exist->attr->origin)
230 return 0;
232 /* 6. MED check. */
233 internal_as_route = (new->attr->aspath->length == 0
234 && exist->attr->aspath->length == 0);
235 confed_as_route = (new->attr->aspath->length > 0
236 && exist->attr->aspath->length > 0
237 && new->attr->aspath->count == 0
238 && exist->attr->aspath->count == 0);
240 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
241 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
242 && confed_as_route)
243 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
244 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
245 || internal_as_route)
247 new_med = bgp_med_value (new->attr, bgp);
248 exist_med = bgp_med_value (exist->attr, bgp);
250 if (new_med < exist_med)
251 return 1;
252 if (new_med > exist_med)
253 return 0;
256 /* 7. Peer type check. */
257 if (peer_sort (new->peer) == BGP_PEER_EBGP
258 && peer_sort (exist->peer) == BGP_PEER_IBGP)
259 return 1;
260 if (peer_sort (new->peer) == BGP_PEER_EBGP
261 && peer_sort (exist->peer) == BGP_PEER_CONFED)
262 return 1;
263 if (peer_sort (new->peer) == BGP_PEER_IBGP
264 && peer_sort (exist->peer) == BGP_PEER_EBGP)
265 return 0;
266 if (peer_sort (new->peer) == BGP_PEER_CONFED
267 && peer_sort (exist->peer) == BGP_PEER_EBGP)
268 return 0;
270 /* 8. IGP metric check. */
271 if (new->igpmetric < exist->igpmetric)
272 return 1;
273 if (new->igpmetric > exist->igpmetric)
274 return 0;
276 /* 9. cost community check. */
277 if (! bgp_flag_check (bgp, BGP_FLAG_COST_COMMUNITY_IGNORE))
279 cost_community = ecommunity_cost_cmp (new->attr->ecommunity,
280 exist->attr->ecommunity, ECOMMUNITY_COST_POI_IGP);
281 if (cost_community > 0)
282 return 1;
283 if (cost_community < 0)
284 return 0;
287 /* 10. Maximum path check. */
289 /* 11. If both paths are external, prefer the path that was received
290 first (the oldest one). This step minimizes route-flap, since a
291 newer path won't displace an older one, even if it was the
292 preferred route based on the additional decision criteria below. */
293 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
294 && peer_sort (new->peer) == BGP_PEER_EBGP
295 && peer_sort (exist->peer) == BGP_PEER_EBGP)
297 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
298 return 1;
299 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
300 return 0;
303 /* 12. Rourter-ID comparision. */
304 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
305 new_id.s_addr = new->attr->originator_id.s_addr;
306 else
307 new_id.s_addr = new->peer->remote_id.s_addr;
308 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
309 exist_id.s_addr = exist->attr->originator_id.s_addr;
310 else
311 exist_id.s_addr = exist->peer->remote_id.s_addr;
313 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
314 return 1;
315 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
316 return 0;
318 /* 13. Cluster length comparision. */
319 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
320 new_cluster = new->attr->cluster->length;
321 else
322 new_cluster = 0;
323 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
324 exist_cluster = exist->attr->cluster->length;
325 else
326 exist_cluster = 0;
328 if (new_cluster < exist_cluster)
329 return 1;
330 if (new_cluster > exist_cluster)
331 return 0;
333 /* 14. Neighbor address comparision. */
334 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
336 if (ret == 1)
337 return 0;
338 if (ret == -1)
339 return 1;
341 return 1;
344 enum filter_type
345 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
346 afi_t afi, safi_t safi)
348 struct bgp_filter *filter;
350 filter = &peer->filter[afi][safi];
352 if (DISTRIBUTE_IN_NAME (filter))
353 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
354 return FILTER_DENY;
356 if (PREFIX_LIST_IN_NAME (filter))
357 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
358 return FILTER_DENY;
360 if (FILTER_LIST_IN_NAME (filter))
361 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
362 return FILTER_DENY;
364 return FILTER_PERMIT;
367 enum filter_type
368 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
369 afi_t afi, safi_t safi)
371 struct bgp_filter *filter;
373 filter = &peer->filter[afi][safi];
375 if (DISTRIBUTE_OUT_NAME (filter))
376 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
377 return FILTER_DENY;
379 if (PREFIX_LIST_OUT_NAME (filter))
380 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
381 return FILTER_DENY;
383 if (FILTER_LIST_OUT_NAME (filter))
384 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
385 return FILTER_DENY;
387 return FILTER_PERMIT;
390 /* If community attribute includes no_export then return 1. */
392 bgp_community_filter (struct peer *peer, struct attr *attr)
394 if (attr->community)
396 /* NO_ADVERTISE check. */
397 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
398 return 1;
400 /* NO_EXPORT check. */
401 if (peer_sort (peer) == BGP_PEER_EBGP &&
402 community_include (attr->community, COMMUNITY_NO_EXPORT))
403 return 1;
405 /* NO_EXPORT_SUBCONFED check. */
406 if (peer_sort (peer) == BGP_PEER_EBGP
407 || peer_sort (peer) == BGP_PEER_CONFED)
408 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
409 return 1;
411 return 0;
414 /* Route reflection loop check. */
415 static int
416 bgp_cluster_filter (struct peer *peer, struct attr *attr)
418 struct in_addr cluster_id;
420 if (attr->cluster)
422 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
423 cluster_id = peer->bgp->cluster_id;
424 else
425 cluster_id = peer->bgp->router_id;
427 if (cluster_loop_check (attr->cluster, cluster_id))
428 return 1;
430 return 0;
434 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
435 afi_t afi, safi_t safi)
437 struct bgp_filter *filter;
438 struct bgp_info info;
439 route_map_result_t ret;
441 filter = &peer->filter[afi][safi];
443 /* Apply default weight value. */
444 if (CHECK_FLAG (peer->af_config[afi][safi], PEER_AF_CONFIG_WEIGHT))
445 attr->weight = peer->weight[afi][safi];
446 else
447 attr->weight = 0;
449 /* Route map apply. */
450 if (ROUTE_MAP_IN_NAME (filter))
452 /* Duplicate current value to new strucutre for modification. */
453 info.peer = peer;
454 info.attr = attr;
456 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
458 /* Apply BGP route map to the attribute. */
459 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
461 peer->rmap_type = 0;
463 if (ret == RMAP_DENYMATCH)
465 /* Free newly generated AS path and community by route-map. */
466 bgp_attr_flush (attr);
467 return RMAP_DENY;
470 return RMAP_PERMIT;
474 bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
475 struct attr *attr, afi_t afi, safi_t safi)
477 int ret;
478 char buf[SU_ADDRSTRLEN];
479 struct bgp_filter *filter;
480 struct bgp_info info;
481 struct peer *from;
482 struct bgp *bgp;
483 struct attr dummy_attr;
484 int transparent;
485 int reflect;
487 from = ri->peer;
488 filter = &peer->filter[afi][safi];
489 bgp = peer->bgp;
491 #ifdef DISABLE_BGP_ANNOUNCE
492 return 0;
493 #endif
495 /* Do not send back route to sender. */
496 if (from == peer)
497 return 0;
499 /* Aggregate-address suppress check. */
500 if (ri->suppress)
501 if (! UNSUPPRESS_MAP_NAME (filter))
502 return 0;
504 /* Default route check. */
505 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
507 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
508 return 0;
509 #ifdef HAVE_IPV6
510 else if (p->family == AF_INET6 && p->prefixlen == 0)
511 return 0;
512 #endif /* HAVE_IPV6 */
515 /* Transparency check. */
516 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
517 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
518 transparent = 1;
519 else
520 transparent = 0;
522 /* If community is not disabled check the no-export and local. */
523 if (! transparent && bgp_community_filter (peer, ri->attr))
524 return 0;
526 /* If the attribute has originator-id and it is same as remote
527 peer's id. */
528 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
530 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
532 if (BGP_DEBUG (filter, FILTER))
533 zlog (peer->log, LOG_INFO,
534 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
535 peer->host,
536 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
537 p->prefixlen);
538 return 0;
542 /* ORF prefix-list filter check */
543 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
544 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
545 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
546 if (peer->orf_plist[afi][safi])
548 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
549 return 0;
552 /* Output filter check. */
553 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
555 if (BGP_DEBUG (filter, FILTER))
556 zlog (peer->log, LOG_INFO,
557 "%s [Update:SEND] %s/%d is filtered",
558 peer->host,
559 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
560 p->prefixlen);
561 return 0;
564 #ifdef BGP_SEND_ASPATH_CHECK
565 /* AS path loop check. */
566 if (aspath_loop_check (ri->attr->aspath, peer->as))
568 if (BGP_DEBUG (filter, FILTER))
569 zlog (peer->log, LOG_INFO,
570 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
571 peer->host, peer->as);
572 return 0;
574 #endif /* BGP_SEND_ASPATH_CHECK */
576 /* If we're a CONFED we need to loop check the CONFED ID too */
577 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
579 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
581 if (BGP_DEBUG (filter, FILTER))
582 zlog (peer->log, LOG_INFO,
583 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
584 peer->host,
585 bgp->confed_id);
586 return 0;
590 /* Route-Reflect check. */
591 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
592 reflect = 1;
593 else
594 reflect = 0;
596 /* IBGP reflection check. */
597 if (reflect)
599 /* A route from a Client peer. */
600 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
602 /* Reflect to all the Non-Client peers and also to the
603 Client peers other than the originator. Originator check
604 is already done. So there is noting to do. */
605 /* no bgp client-to-client reflection check. */
606 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
607 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
608 return 0;
610 else
612 /* A route from a Non-client peer. Reflect to all other
613 clients. */
614 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
615 return 0;
619 /* For modify attribute, copy it to temporary structure. */
620 *attr = *ri->attr;
622 /* If local-preference is not set. */
623 if ((peer_sort (peer) == BGP_PEER_IBGP
624 || peer_sort (peer) == BGP_PEER_CONFED)
625 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
627 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
628 attr->local_pref = bgp->default_local_pref;
631 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
632 if (peer_sort (peer) == BGP_PEER_EBGP
633 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
635 if (ri->peer != bgp->peer_self && ! transparent
636 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
637 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
640 /* next-hop-set */
641 if (transparent || reflect
642 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
643 && ((p->family == AF_INET && attr->nexthop.s_addr)
644 #ifdef HAVE_IPV6
645 || (p->family == AF_INET6 && ri->peer != bgp->peer_self)
646 #endif /* HAVE_IPV6 */
649 /* NEXT-HOP Unchanged. */
651 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
652 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
653 #ifdef HAVE_IPV6
654 || (p->family == AF_INET6 && ri->peer == bgp->peer_self)
655 #endif /* HAVE_IPV6 */
656 || (peer_sort (peer) == BGP_PEER_EBGP
657 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
659 /* Set IPv4 nexthop. */
660 if (p->family == AF_INET)
662 if (safi == SAFI_MPLS_VPN)
663 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
664 else
665 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
667 #ifdef HAVE_IPV6
668 /* Set IPv6 nexthop. */
669 if (p->family == AF_INET6)
671 /* IPv6 global nexthop must be included. */
672 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
673 IPV6_MAX_BYTELEN);
674 attr->mp_nexthop_len = 16;
676 #endif /* HAVE_IPV6 */
679 #ifdef HAVE_IPV6
680 if (p->family == AF_INET6)
682 /* Link-local address should not be transit to different peer. */
683 attr->mp_nexthop_len = 16;
685 /* Set link-local address for shared network peer. */
686 if (peer->shared_network
687 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
689 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
690 IPV6_MAX_BYTELEN);
691 attr->mp_nexthop_len = 32;
694 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
695 address.*/
696 if (reflect)
697 attr->mp_nexthop_len = 16;
699 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
700 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
701 attr->mp_nexthop_len = 16;
703 #endif /* HAVE_IPV6 */
705 /* If this is EBGP peer and remove-private-AS is set. */
706 if (peer_sort (peer) == BGP_PEER_EBGP
707 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
708 && aspath_private_as_check (attr->aspath))
709 attr->aspath = aspath_empty_get ();
711 /* Route map & unsuppress-map apply. */
712 if (ROUTE_MAP_OUT_NAME (filter)
713 || ri->suppress)
715 info.peer = peer;
716 info.attr = attr;
718 /* The route reflector is not allowed to modify the attributes
719 of the reflected IBGP routes. */
720 if (peer_sort (from) == BGP_PEER_IBGP
721 && peer_sort (peer) == BGP_PEER_IBGP)
723 dummy_attr = *attr;
724 info.attr = &dummy_attr;
727 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
729 if (ri->suppress)
730 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
731 else
732 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
734 peer->rmap_type = 0;
736 if (ret == RMAP_DENYMATCH)
738 bgp_attr_flush (attr);
739 return 0;
742 return 1;
746 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
748 struct prefix *p;
749 struct bgp_info *ri;
750 struct bgp_info *new_select;
751 struct bgp_info *old_select;
752 struct listnode *nn;
753 struct peer *peer;
754 struct attr attr;
755 struct bgp_info *ri1;
756 struct bgp_info *ri2;
758 p = &rn->p;
760 /* bgp deterministic-med */
761 new_select = NULL;
762 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
763 for (ri1 = rn->info; ri1; ri1 = ri1->next)
765 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
766 continue;
767 if (BGP_INFO_HOLDDOWN (ri1))
768 continue;
770 new_select = ri1;
771 if (ri1->next)
772 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
774 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
775 continue;
776 if (BGP_INFO_HOLDDOWN (ri2))
777 continue;
779 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
780 || aspath_cmp_left_confed (ri1->attr->aspath,
781 ri2->attr->aspath))
783 if (bgp_info_cmp (bgp, ri2, new_select))
785 UNSET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
786 new_select = ri2;
789 SET_FLAG (ri2->flags, BGP_INFO_DMED_CHECK);
792 SET_FLAG (new_select->flags, BGP_INFO_DMED_CHECK);
793 SET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
796 /* Check old selected route and new selected route. */
797 old_select = NULL;
798 new_select = NULL;
799 for (ri = rn->info; ri; ri = ri->next)
801 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
802 old_select = ri;
804 if (BGP_INFO_HOLDDOWN (ri))
805 continue;
807 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
808 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
810 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
811 continue;
813 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
814 UNSET_FLAG (ri->flags, BGP_INFO_DMED_SELECTED);
816 if (bgp_info_cmp (bgp, ri, new_select))
817 new_select = ri;
820 /* Nothing to do. */
821 if (old_select && old_select == new_select)
823 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
825 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
826 bgp_zebra_announce (p, old_select, bgp);
827 return 0;
831 if (old_select)
832 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
833 if (new_select)
835 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
836 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
839 /* Check each BGP peer. */
840 LIST_LOOP (bgp->peer, peer, nn)
842 /* Announce route to Established peer. */
843 if (peer->status != Established)
844 continue;
846 /* Address family configuration check. */
847 if (! peer->afc_nego[afi][safi])
848 continue;
850 /* First update is deferred until ORF or ROUTE-REFRESH is received */
851 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
852 continue;
854 /* Announcement to peer->conf. If the route is filtered,
855 withdraw it. */
856 if (new_select
857 && bgp_announce_check (new_select, peer, p, &attr, afi, safi))
858 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, new_select);
859 else
860 bgp_adj_out_unset (rn, peer, p, afi, safi);
863 /* FIB update. */
864 if (safi == SAFI_UNICAST && ! bgp->name &&
865 ! bgp_option_check (BGP_OPT_NO_FIB))
867 if (new_select
868 && new_select->type == ZEBRA_ROUTE_BGP
869 && new_select->sub_type == BGP_ROUTE_NORMAL)
870 bgp_zebra_announce (p, new_select, bgp);
871 else
873 /* Withdraw the route from the kernel. */
874 if (old_select
875 && old_select->type == ZEBRA_ROUTE_BGP
876 && old_select->sub_type == BGP_ROUTE_NORMAL)
877 bgp_zebra_withdraw (p, old_select);
880 return 0;
884 bgp_maximum_prefix_restart_timer (struct thread *thread)
886 struct peer *peer;
888 peer = THREAD_ARG (thread);
889 peer->t_pmax_restart = NULL;
891 if (BGP_DEBUG (events, EVENTS))
892 zlog_info ("%s Maximum-prefix restart timer expired, restore peering", peer->host);
894 peer_clear (peer);
896 return 0;
900 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi, safi_t safi, int always)
902 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
903 return 0;
905 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
907 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
908 && ! always)
909 return 0;
911 zlog (peer->log, LOG_INFO,
912 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, limit %ld",
913 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
914 peer->pmax[afi][safi]);
915 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
917 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
918 return 0;
921 char ndata[7];
923 ndata[0] = (u_char)(afi >> 8);
924 ndata[1] = (u_char) afi;
925 ndata[3] = (u_char)(peer->pmax[afi][safi] >> 24);
926 ndata[4] = (u_char)(peer->pmax[afi][safi] >> 16);
927 ndata[5] = (u_char)(peer->pmax[afi][safi] >> 8);
928 ndata[6] = (u_char)(peer->pmax[afi][safi]);
930 if (safi == SAFI_MPLS_VPN)
931 safi = BGP_SAFI_VPNV4;
932 ndata[2] = (u_char) safi;
934 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
935 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
936 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
939 /* restart timer start */
940 if (peer->pmax_restart[afi][safi])
942 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
944 if (BGP_DEBUG (events, EVENTS))
945 zlog_info ("%s Maximum-prefix restart timer started for %d secs",
946 peer->host, peer->v_pmax_restart);
948 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
949 peer->v_pmax_restart);
952 return 1;
954 else
955 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
957 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
959 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
960 && ! always)
961 return 0;
963 zlog (peer->log, LOG_INFO,
964 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
965 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
966 peer->pmax[afi][safi]);
967 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
969 else
970 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
972 return 0;
975 void
976 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
977 afi_t afi, safi_t safi)
979 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
981 if (! CHECK_FLAG (ri->flags, BGP_INFO_STALE))
982 peer->pcount[afi][safi]--;
983 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
984 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
985 bgp_process (peer->bgp, rn, afi, safi);
987 bgp_info_delete (rn, ri);
988 bgp_info_free (ri);
989 bgp_unlock_node (rn);
992 void
993 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
994 afi_t afi, safi_t safi, int force)
996 int valid;
997 int status = BGP_DAMP_NONE;
999 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1001 peer->pcount[afi][safi]--;
1002 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1005 if (! force)
1007 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1008 && peer_sort (peer) == BGP_PEER_EBGP)
1009 status = bgp_damp_withdraw (ri, rn, afi, safi, 0);
1011 if (status == BGP_DAMP_SUPPRESSED)
1012 return;
1015 valid = CHECK_FLAG (ri->flags, BGP_INFO_VALID);
1016 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
1017 bgp_process (peer->bgp, rn, afi, safi);
1019 if (valid)
1020 SET_FLAG (ri->flags, BGP_INFO_VALID);
1022 if (status != BGP_DAMP_USED)
1024 bgp_info_delete (rn, ri);
1025 bgp_info_free (ri);
1026 bgp_unlock_node (rn);
1031 bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
1032 afi_t afi, safi_t safi, int type, int sub_type,
1033 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1035 int ret;
1036 int aspath_loop_count = 0;
1037 struct bgp_node *rn;
1038 struct bgp *bgp;
1039 struct attr new_attr;
1040 struct attr *attr_new;
1041 struct bgp_info *ri;
1042 struct bgp_info *new;
1043 char *reason;
1044 char buf[SU_ADDRSTRLEN];
1046 bgp = peer->bgp;
1047 rn = bgp_afi_node_get (bgp, afi, safi, p, prd);
1049 /* When peer's soft reconfiguration enabled. Record input packet in
1050 Adj-RIBs-In. */
1051 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1052 && peer != bgp->peer_self && ! soft_reconfig)
1053 bgp_adj_in_set (rn, peer, attr);
1055 /* Check previously received route. */
1056 for (ri = rn->info; ri; ri = ri->next)
1057 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1058 break;
1060 /* AS path local-as loop check. */
1061 if (peer->change_local_as)
1063 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1064 aspath_loop_count = 1;
1066 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1068 reason = "as-path contains our own AS;";
1069 goto filtered;
1073 /* AS path loop check. */
1074 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1075 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1076 && aspath_loop_check(attr->aspath, bgp->confed_id)
1077 > peer->allowas_in[afi][safi]))
1079 reason = "as-path contains our own AS;";
1080 goto filtered;
1083 /* Route reflector originator ID check. */
1084 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1085 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1087 reason = "originator is us;";
1088 goto filtered;
1091 /* Route reflector cluster ID check. */
1092 if (bgp_cluster_filter (peer, attr))
1094 reason = "reflected from the same cluster;";
1095 goto filtered;
1098 /* Apply incoming filter. */
1099 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1101 reason = "filter;";
1102 goto filtered;
1105 /* Apply incoming route-map. */
1106 new_attr = *attr;
1108 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1110 reason = "route-map;";
1111 goto filtered;
1114 /* IPv4 unicast next hop check. */
1115 if (afi == AFI_IP && safi == SAFI_UNICAST)
1117 /* If the peer is EBGP and nexthop is not on connected route,
1118 discard it. */
1119 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1120 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
1121 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
1123 reason = "non-connected next-hop;";
1124 goto filtered;
1127 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1128 must not be my own address. */
1129 if (bgp_nexthop_self (afi, &new_attr)
1130 || new_attr.nexthop.s_addr == 0
1131 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1133 reason = "martian next-hop;";
1134 goto filtered;
1138 attr_new = bgp_attr_intern (&new_attr);
1140 /* If the update is implicit withdraw. */
1141 if (ri)
1143 ri->uptime = time (NULL);
1145 /* Same attribute comes in. */
1146 if (attrhash_cmp (ri->attr, attr_new))
1148 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1150 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1151 && peer_sort (peer) == BGP_PEER_EBGP
1152 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1154 if (BGP_DEBUG (update, UPDATE_IN))
1155 zlog (peer->log, LOG_INFO, "%s rcvd %s/%d",
1156 peer->host,
1157 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1158 p->prefixlen);
1160 peer->pcount[afi][safi]++;
1161 ret = bgp_damp_update (ri, rn, afi, safi);
1162 if (ret != BGP_DAMP_SUPPRESSED)
1164 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1165 bgp_process (bgp, rn, afi, safi);
1168 else
1170 if (BGP_DEBUG (update, UPDATE_IN))
1171 zlog (peer->log, LOG_INFO,
1172 "%s rcvd %s/%d...duplicate ignored",
1173 peer->host,
1174 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1175 p->prefixlen);
1177 /* graceful restart STALE flag unset. */
1178 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1180 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1181 peer->pcount[afi][safi]++;
1185 bgp_unlock_node (rn);
1186 bgp_attr_unintern (attr_new);
1187 return 0;
1190 /* Received Logging. */
1191 if (BGP_DEBUG (update, UPDATE_IN))
1192 zlog (peer->log, LOG_INFO, "%s rcvd %s/%d",
1193 peer->host,
1194 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1195 p->prefixlen);
1197 /* graceful restart STALE flag unset. */
1198 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1200 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1201 peer->pcount[afi][safi]++;
1204 /* The attribute is changed. */
1205 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1207 /* Update bgp route dampening information. */
1208 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1209 && peer_sort (peer) == BGP_PEER_EBGP)
1211 /* This is implicit withdraw so we should update dampening
1212 information. */
1213 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1214 bgp_damp_withdraw (ri, rn, afi, safi, 1);
1215 else
1216 peer->pcount[afi][safi]++;
1219 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1221 /* Update to new attribute. */
1222 bgp_attr_unintern (ri->attr);
1223 ri->attr = attr_new;
1225 /* Update MPLS tag. */
1226 if (safi == SAFI_MPLS_VPN)
1227 memcpy (ri->tag, tag, 3);
1229 /* Update bgp route dampening information. */
1230 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1231 && peer_sort (peer) == BGP_PEER_EBGP)
1233 /* Now we do normal update dampening. */
1234 ret = bgp_damp_update (ri, rn, afi, safi);
1235 if (ret == BGP_DAMP_SUPPRESSED)
1237 bgp_unlock_node (rn);
1238 return 0;
1242 /* Nexthop reachability check. */
1243 if ((afi == AFI_IP || afi == AFI_IP6)
1244 && safi == SAFI_UNICAST
1245 && (peer_sort (peer) == BGP_PEER_IBGP
1246 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
1247 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
1249 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
1250 SET_FLAG (ri->flags, BGP_INFO_VALID);
1251 else
1252 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
1254 else
1255 SET_FLAG (ri->flags, BGP_INFO_VALID);
1257 /* Process change. */
1258 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1260 bgp_process (bgp, rn, afi, safi);
1261 bgp_unlock_node (rn);
1262 return 0;
1265 /* Received Logging. */
1266 if (BGP_DEBUG (update, UPDATE_IN))
1268 zlog (peer->log, LOG_INFO, "%s rcvd %s/%d",
1269 peer->host,
1270 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1271 p->prefixlen);
1274 /* Increment prefix counter */
1275 peer->pcount[afi][safi]++;
1277 /* Make new BGP info. */
1278 new = bgp_info_new ();
1279 new->type = type;
1280 new->sub_type = sub_type;
1281 new->peer = peer;
1282 new->attr = attr_new;
1283 new->uptime = time (NULL);
1285 /* Update MPLS tag. */
1286 if (safi == SAFI_MPLS_VPN)
1287 memcpy (new->tag, tag, 3);
1289 /* Nexthop reachability check. */
1290 if ((afi == AFI_IP || afi == AFI_IP6)
1291 && safi == SAFI_UNICAST
1292 && (peer_sort (peer) == BGP_PEER_IBGP
1293 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
1294 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
1296 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
1297 SET_FLAG (new->flags, BGP_INFO_VALID);
1298 else
1299 UNSET_FLAG (new->flags, BGP_INFO_VALID);
1301 else
1302 SET_FLAG (new->flags, BGP_INFO_VALID);
1304 /* Aggregate address increment. */
1305 bgp_aggregate_increment (bgp, p, new, afi, safi);
1307 /* Register new BGP information. */
1308 bgp_info_add (rn, new);
1310 /* If maximum prefix count is configured and current prefix
1311 count exeed it. */
1312 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
1313 return -1;
1315 /* Process change. */
1316 bgp_process (bgp, rn, afi, safi);
1318 return 0;
1320 /* This BGP update is filtered. Log the reason then update BGP
1321 entry. */
1322 filtered:
1323 if (BGP_DEBUG (update, UPDATE_IN))
1324 zlog (peer->log, LOG_INFO,
1325 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
1326 peer->host,
1327 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1328 p->prefixlen, reason);
1330 if (ri)
1331 bgp_rib_withdraw (rn, ri, peer, afi, safi, 1);
1333 bgp_unlock_node (rn);
1335 return 0;
1339 bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
1340 int afi, int safi, int type, int sub_type, struct prefix_rd *prd,
1341 u_char *tag)
1343 struct bgp *bgp;
1344 char buf[SU_ADDRSTRLEN];
1345 struct bgp_node *rn;
1346 struct bgp_info *ri;
1348 bgp = peer->bgp;
1350 /* Logging. */
1351 if (BGP_DEBUG (update, UPDATE_IN))
1352 zlog (peer->log, LOG_INFO, "%s rcvd UPDATE about %s/%d -- withdrawn",
1353 peer->host,
1354 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1355 p->prefixlen);
1357 /* Lookup node. */
1358 rn = bgp_afi_node_get (bgp, afi, safi, p, prd);
1360 /* If peer is soft reconfiguration enabled. Record input packet for
1361 further calculation. */
1362 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1363 && peer != bgp->peer_self)
1364 bgp_adj_in_unset (rn, peer);
1366 /* Lookup withdrawn route. */
1367 for (ri = rn->info; ri; ri = ri->next)
1368 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1369 break;
1371 /* Withdraw specified route from routing table. */
1372 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1373 bgp_rib_withdraw (rn, ri, peer, afi, safi, 0);
1374 else if (BGP_DEBUG (update, UPDATE_IN))
1375 zlog (peer->log, LOG_INFO,
1376 "%s Can't find the route %s/%d", peer->host,
1377 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1378 p->prefixlen);
1380 /* Unlock bgp_node_get() lock. */
1381 bgp_unlock_node (rn);
1383 return 0;
1386 void
1387 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
1389 struct bgp *bgp;
1390 struct attr attr;
1391 struct aspath *aspath;
1392 struct prefix p;
1393 struct bgp_info binfo;
1394 struct peer *from;
1395 int ret = RMAP_DENYMATCH;
1397 bgp = peer->bgp;
1398 from = bgp->peer_self;
1400 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
1401 aspath = attr.aspath;
1402 attr.local_pref = bgp->default_local_pref;
1403 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1405 if (afi == AFI_IP)
1406 str2prefix ("0.0.0.0/0", &p);
1407 #ifdef HAVE_IPV6
1408 else if (afi == AFI_IP6)
1410 str2prefix ("::/0", &p);
1412 /* IPv6 global nexthop must be included. */
1413 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
1414 IPV6_MAX_BYTELEN);
1415 attr.mp_nexthop_len = 16;
1417 /* If the peer is on shared nextwork and we have link-local
1418 nexthop set it. */
1419 if (peer->shared_network
1420 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1422 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
1423 IPV6_MAX_BYTELEN);
1424 attr.mp_nexthop_len = 32;
1427 #endif /* HAVE_IPV6 */
1428 else
1429 return;
1431 if (peer->default_rmap[afi][safi].name)
1433 binfo.peer = bgp->peer_self;
1434 binfo.attr = &attr;
1436 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
1437 RMAP_BGP, &binfo);
1439 if (ret == RMAP_DENYMATCH)
1441 bgp_attr_flush (&attr);
1442 withdraw = 1;
1446 if (withdraw)
1448 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
1449 bgp_default_withdraw_send (peer, afi, safi);
1450 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
1452 else
1454 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
1455 bgp_default_update_send (peer, &attr, afi, safi, from);
1458 aspath_unintern (aspath);
1461 static void
1462 bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
1463 struct bgp_table *table)
1465 struct bgp_node *rn;
1466 struct bgp_info *ri;
1467 struct attr attr;
1469 if (! table)
1470 table = peer->bgp->rib[afi][safi];
1472 if (safi != SAFI_MPLS_VPN
1473 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
1474 bgp_default_originate (peer, afi, safi, 0);
1476 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
1477 for (ri = rn->info; ri; ri = ri->next)
1478 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
1480 if (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi))
1481 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
1482 else
1483 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
1487 void
1488 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
1490 struct bgp_node *rn;
1491 struct bgp_table *table;
1493 if (peer->status != Established)
1494 return;
1496 if (! peer->afc_nego[afi][safi])
1497 return;
1499 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1500 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
1501 return;
1503 if (safi != SAFI_MPLS_VPN)
1504 bgp_announce_table (peer, afi, safi, NULL);
1505 else
1506 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
1507 rn = bgp_route_next(rn))
1508 if ((table = (rn->info)) != NULL)
1509 bgp_announce_table (peer, afi, safi, table);
1511 if (! peer->t_routeadv[afi][safi])
1512 bgp_routeadv_timer (peer, afi, safi);
1515 void
1516 bgp_announce_route_all (struct peer *peer)
1518 afi_t afi;
1519 safi_t safi;
1521 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1522 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1523 bgp_announce_route (peer, afi, safi);
1526 static void
1527 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
1528 struct bgp_table *table)
1530 int ret;
1531 struct bgp_node *rn;
1532 struct bgp_adj_in *ain;
1534 if (! table)
1535 table = peer->bgp->rib[afi][safi];
1537 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
1538 for (ain = rn->adj_in; ain; ain = ain->next)
1540 if (ain->peer == peer)
1542 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
1543 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
1544 NULL, NULL, 1);
1545 if (ret < 0)
1547 bgp_unlock_node (rn);
1548 return;
1550 continue;
1555 void
1556 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
1558 struct bgp_node *rn;
1559 struct bgp_table *table;
1561 if (peer->status != Established)
1562 return;
1564 if (safi != SAFI_MPLS_VPN)
1565 bgp_soft_reconfig_table (peer, afi, safi, NULL);
1566 else
1567 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
1568 rn = bgp_route_next (rn))
1569 if ((table = rn->info) != NULL)
1570 bgp_soft_reconfig_table (peer, afi, safi, table);
1573 static void
1574 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
1575 struct bgp_table *table)
1577 struct bgp_node *rn;
1578 struct bgp_adj_in *ain;
1579 struct bgp_adj_out *aout;
1580 struct bgp_info *ri;
1582 if (! table)
1583 table = peer->bgp->rib[afi][safi];
1585 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
1587 for (ri = rn->info; ri; ri = ri->next)
1588 if (ri->peer == peer)
1590 /* graceful restart STALE flag set. */
1591 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
1592 && peer->nsf[afi][safi]
1593 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
1594 && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
1595 && ! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
1597 SET_FLAG (ri->flags, BGP_INFO_STALE);
1598 peer->pcount[afi][safi]--;
1600 else
1601 bgp_rib_remove (rn, ri, peer, afi, safi);
1602 break;
1604 for (ain = rn->adj_in; ain; ain = ain->next)
1605 if (ain->peer == peer)
1607 bgp_adj_in_remove (rn, ain);
1608 bgp_unlock_node (rn);
1609 break;
1611 for (aout = rn->adj_out; aout; aout = aout->next)
1612 if (aout->peer == peer)
1614 bgp_adj_out_remove (rn, aout, peer, afi, safi);
1615 bgp_unlock_node (rn);
1616 break;
1621 void
1622 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
1624 struct bgp_node *rn;
1625 struct bgp_table *table;
1627 if (safi != SAFI_MPLS_VPN)
1628 bgp_clear_route_table (peer, afi, safi, NULL);
1629 else
1630 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
1631 rn = bgp_route_next (rn))
1632 if ((table = rn->info) != NULL)
1633 bgp_clear_route_table (peer, afi, safi, table);
1636 void
1637 bgp_clear_route_all (struct peer *peer)
1639 afi_t afi;
1640 safi_t safi;
1642 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1643 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
1644 bgp_clear_route (peer, afi, safi);
1647 void
1648 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
1650 struct bgp_table *table;
1651 struct bgp_node *rn;
1652 struct bgp_adj_in *ain;
1654 table = peer->bgp->rib[afi][safi];
1656 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
1657 for (ain = rn->adj_in; ain ; ain = ain->next)
1658 if (ain->peer == peer)
1660 bgp_adj_in_remove (rn, ain);
1661 bgp_unlock_node (rn);
1662 break;
1666 void
1667 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
1669 struct bgp_node *rn;
1670 struct bgp_info *ri;
1671 struct bgp_table *table;
1673 table = peer->bgp->rib[afi][safi];
1675 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
1677 for (ri = rn->info; ri; ri = ri->next)
1678 if (ri->peer == peer)
1680 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1681 bgp_rib_remove (rn, ri, peer, afi, safi);
1682 break;
1687 /* Delete all kernel routes. */
1688 void
1689 bgp_terminate ()
1691 struct bgp *bgp;
1692 struct listnode *nn;
1693 struct bgp_node *rn;
1694 struct bgp_table *table;
1695 struct bgp_info *ri;
1697 LIST_LOOP (bm->bgp, bgp, nn)
1699 table = bgp->rib[AFI_IP][SAFI_UNICAST];
1701 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
1702 for (ri = rn->info; ri; ri = ri->next)
1703 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
1704 && ri->type == ZEBRA_ROUTE_BGP
1705 && ri->sub_type == BGP_ROUTE_NORMAL)
1706 bgp_zebra_withdraw (&rn->p, ri);
1708 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
1710 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
1711 for (ri = rn->info; ri; ri = ri->next)
1712 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
1713 && ri->type == ZEBRA_ROUTE_BGP
1714 && ri->sub_type == BGP_ROUTE_NORMAL)
1715 bgp_zebra_withdraw (&rn->p, ri);
1719 void
1720 bgp_reset ()
1722 vty_reset ();
1723 bgp_zclient_reset ();
1724 access_list_reset ();
1725 prefix_list_reset ();
1728 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
1729 value. */
1731 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
1733 u_char *pnt;
1734 u_char *lim;
1735 struct prefix p;
1736 int psize;
1737 int ret;
1739 /* Check peer status. */
1740 if (peer->status != Established)
1741 return 0;
1743 pnt = packet->nlri;
1744 lim = pnt + packet->length;
1746 for (; pnt < lim; pnt += psize)
1748 /* Clear prefix structure. */
1749 memset (&p, 0, sizeof (struct prefix));
1751 /* Fetch prefix length. */
1752 p.prefixlen = *pnt++;
1753 p.family = afi2family (packet->afi);
1755 /* Already checked in nlri_sanity_check(). We do double check
1756 here. */
1757 if ((packet->afi == AFI_IP && p.prefixlen > 32)
1758 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
1759 return -1;
1761 /* Packet size overflow check. */
1762 psize = PSIZE (p.prefixlen);
1764 /* When packet overflow occur return immediately. */
1765 if (pnt + psize > lim)
1766 return -1;
1768 /* Fetch prefix from NLRI packet. */
1769 memcpy (&p.u.prefix, pnt, psize);
1771 /* Check address. */
1772 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
1774 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
1776 zlog (peer->log, LOG_ERR,
1777 "IPv4 unicast NLRI is multicast address %s",
1778 inet_ntoa (p.u.prefix4));
1779 bgp_notify_send (peer,
1780 BGP_NOTIFY_UPDATE_ERR,
1781 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1782 return -1;
1786 #ifdef HAVE_IPV6
1787 /* Check address. */
1788 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
1790 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
1792 char buf[BUFSIZ];
1794 zlog (peer->log, LOG_WARNING,
1795 "IPv6 link-local NLRI received %s ignore this NLRI",
1796 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
1798 continue;
1801 #endif /* HAVE_IPV6 */
1803 /* Normal process. */
1804 if (attr)
1805 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
1806 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
1807 else
1808 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
1809 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
1811 /* Address family configuration mismatch or maximum-prefix count
1812 overflow. */
1813 if (ret < 0)
1814 return -1;
1817 /* Packet length consistency check. */
1818 if (pnt != lim)
1819 return -1;
1821 return 0;
1824 /* NLRI encode syntax check routine. */
1826 bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
1827 bgp_size_t length)
1829 u_char *end;
1830 u_char prefixlen;
1831 int psize;
1833 end = pnt + length;
1835 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
1836 syntactic validity. If the field is syntactically incorrect,
1837 then the Error Subcode is set to Invalid Network Field. */
1839 while (pnt < end)
1841 prefixlen = *pnt++;
1843 /* Prefix length check. */
1844 if ((afi == AFI_IP && prefixlen > 32)
1845 || (afi == AFI_IP6 && prefixlen > 128))
1847 plog_err (peer->log,
1848 "%s [Error] Update packet error (wrong prefix length %d)",
1849 peer->host, prefixlen);
1850 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1851 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1852 return -1;
1855 /* Packet size overflow check. */
1856 psize = PSIZE (prefixlen);
1858 if (pnt + psize > end)
1860 plog_err (peer->log,
1861 "%s [Error] Update packet error"
1862 " (prefix data overflow prefix size is %d)",
1863 peer->host, psize);
1864 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1865 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1866 return -1;
1869 pnt += psize;
1872 /* Packet length consistency check. */
1873 if (pnt != end)
1875 plog_err (peer->log,
1876 "%s [Error] Update packet error"
1877 " (prefix length mismatch with total length)",
1878 peer->host);
1879 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1880 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1881 return -1;
1883 return 0;
1886 struct bgp_static *
1887 bgp_static_new ()
1889 struct bgp_static *new;
1890 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
1891 memset (new, 0, sizeof (struct bgp_static));
1892 return new;
1895 void
1896 bgp_static_free (struct bgp_static *bgp_static)
1898 if (bgp_static->rmap.name)
1899 free (bgp_static->rmap.name);
1900 XFREE (MTYPE_BGP_STATIC, bgp_static);
1903 void
1904 bgp_static_update (struct bgp *bgp, struct prefix *p,
1905 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
1907 struct bgp_node *rn;
1908 struct bgp_info *ri;
1909 struct bgp_info *new;
1910 struct bgp_info info;
1911 struct attr attr;
1912 struct attr attr_tmp;
1913 struct attr *attr_new;
1914 int ret;
1916 rn = bgp_afi_node_get (bgp, afi, safi, p, NULL);
1918 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
1919 if (bgp_static)
1921 attr.nexthop = bgp_static->igpnexthop;
1922 attr.med = bgp_static->igpmetric;
1923 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
1926 /* Apply route-map. */
1927 if (bgp_static->rmap.name)
1929 attr_tmp = attr;
1930 info.peer = bgp->peer_self;
1931 info.attr = &attr_tmp;
1933 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
1935 if (ret == RMAP_DENYMATCH)
1937 /* Free uninterned attribute. */
1938 bgp_attr_flush (&attr_tmp);
1940 /* Unintern original. */
1941 aspath_unintern (attr.aspath);
1942 bgp_static_withdraw (bgp, p, afi, safi);
1943 return;
1945 attr_new = bgp_attr_intern (&attr_tmp);
1947 else
1948 attr_new = bgp_attr_intern (&attr);
1950 for (ri = rn->info; ri; ri = ri->next)
1951 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
1952 && ri->sub_type == BGP_ROUTE_STATIC)
1953 break;
1955 if (ri)
1957 if (attrhash_cmp (ri->attr, attr_new))
1959 bgp_unlock_node (rn);
1960 bgp_attr_unintern (attr_new);
1961 aspath_unintern (attr.aspath);
1962 return;
1964 else
1966 /* The attribute is changed. */
1967 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1969 /* Rewrite BGP route information. */
1970 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1971 bgp_attr_unintern (ri->attr);
1972 ri->attr = attr_new;
1973 ri->uptime = time (NULL);
1975 /* Process change. */
1976 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1977 bgp_process (bgp, rn, afi, safi);
1978 bgp_unlock_node (rn);
1979 aspath_unintern (attr.aspath);
1980 return;
1984 /* Make new BGP info. */
1985 new = bgp_info_new ();
1986 new->type = ZEBRA_ROUTE_BGP;
1987 new->sub_type = BGP_ROUTE_STATIC;
1988 new->peer = bgp->peer_self;
1989 SET_FLAG (new->flags, BGP_INFO_VALID);
1990 new->attr = attr_new;
1991 new->uptime = time (NULL);
1993 /* Aggregate address increment. */
1994 bgp_aggregate_increment (bgp, p, new, afi, safi);
1996 /* Register new BGP information. */
1997 bgp_info_add (rn, new);
1999 /* Process change. */
2000 bgp_process (bgp, rn, afi, safi);
2002 /* Unintern original. */
2003 aspath_unintern (attr.aspath);
2006 void
2007 bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
2008 u_char safi, struct prefix_rd *prd, u_char *tag)
2010 struct bgp_node *rn;
2011 struct bgp_info *new;
2013 rn = bgp_afi_node_get (bgp, afi, safi, p, prd);
2015 /* Make new BGP info. */
2016 new = bgp_info_new ();
2017 new->type = ZEBRA_ROUTE_BGP;
2018 new->sub_type = BGP_ROUTE_STATIC;
2019 new->peer = bgp->peer_self;
2020 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
2021 SET_FLAG (new->flags, BGP_INFO_VALID);
2022 new->uptime = time (NULL);
2023 memcpy (new->tag, tag, 3);
2025 /* Aggregate address increment. */
2026 bgp_aggregate_increment (bgp, p, (struct bgp_info *) new, afi, safi);
2028 /* Register new BGP information. */
2029 bgp_info_add (rn, (struct bgp_info *) new);
2031 /* Process change. */
2032 bgp_process (bgp, rn, afi, safi);
2035 void
2036 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
2037 safi_t safi)
2039 struct bgp_node *rn;
2040 struct bgp_info *ri;
2042 rn = bgp_afi_node_get (bgp, afi, safi, p, NULL);
2044 /* Check selected route and self inserted route. */
2045 for (ri = rn->info; ri; ri = ri->next)
2046 if (ri->peer == bgp->peer_self
2047 && ri->type == ZEBRA_ROUTE_BGP
2048 && ri->sub_type == BGP_ROUTE_STATIC)
2049 break;
2051 /* Withdraw static BGP route from routing table. */
2052 if (ri)
2054 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2055 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2056 bgp_process (bgp, rn, afi, safi);
2057 bgp_info_delete (rn, ri);
2058 bgp_info_free (ri);
2059 bgp_unlock_node (rn);
2062 /* Unlock bgp_node_lookup. */
2063 bgp_unlock_node (rn);
2066 void
2067 bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
2068 u_char safi, struct prefix_rd *prd, u_char *tag)
2070 struct bgp_node *rn;
2071 struct bgp_info *ri;
2073 rn = bgp_afi_node_get (bgp, afi, safi, p, prd);
2075 /* Check selected route and self inserted route. */
2076 for (ri = rn->info; ri; ri = ri->next)
2077 if (ri->peer == bgp->peer_self
2078 && ri->type == ZEBRA_ROUTE_BGP
2079 && ri->sub_type == BGP_ROUTE_STATIC)
2080 break;
2082 /* Withdraw static BGP route from routing table. */
2083 if (ri)
2085 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2086 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2087 bgp_process (bgp, rn, afi, safi);
2088 bgp_info_delete (rn, ri);
2089 bgp_info_free (ri);
2090 bgp_unlock_node (rn);
2093 /* Unlock bgp_node_lookup. */
2094 bgp_unlock_node (rn);
2097 /* Configure static BGP network. When user don't run zebra, static
2098 route should be installed as valid. */
2100 bgp_static_set (struct vty *vty, struct bgp *bgp, char *ip_str, u_int16_t afi,
2101 u_char safi, char *rmap, int backdoor)
2103 int ret;
2104 struct prefix p;
2105 struct bgp_static *bgp_static;
2106 struct bgp_node *rn;
2107 int need_update = 0;
2109 /* Convert IP prefix string to struct prefix. */
2110 ret = str2prefix (ip_str, &p);
2111 if (! ret)
2113 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2114 return CMD_WARNING;
2116 #ifdef HAVE_IPV6
2117 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2119 vty_out (vty, "%% Malformed prefix (link-local address)%s",
2120 VTY_NEWLINE);
2121 return CMD_WARNING;
2123 #endif /* HAVE_IPV6 */
2125 apply_mask (&p);
2127 /* Set BGP static route configuration. */
2128 rn = bgp_node_get (bgp->route[afi][safi], &p);
2130 if (rn->info)
2132 /* Configuration change. */
2133 bgp_static = rn->info;
2135 /* Check previous routes are installed into BGP. */
2136 if (! bgp_static->backdoor && bgp_static->valid)
2137 need_update = 1;
2139 bgp_static->backdoor = backdoor;
2140 if (rmap)
2142 if (bgp_static->rmap.name)
2143 free (bgp_static->rmap.name);
2144 bgp_static->rmap.name = strdup (rmap);
2145 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
2147 else
2149 if (bgp_static->rmap.name)
2150 free (bgp_static->rmap.name);
2151 bgp_static->rmap.name = NULL;
2152 bgp_static->rmap.map = NULL;
2153 bgp_static->valid = 0;
2155 bgp_unlock_node (rn);
2157 else
2159 /* New configuration. */
2160 bgp_static = bgp_static_new ();
2161 bgp_static->backdoor = backdoor;
2162 bgp_static->valid = 0;
2163 bgp_static->igpmetric = 0;
2164 bgp_static->igpnexthop.s_addr = 0;
2165 if (rmap)
2167 if (bgp_static->rmap.name)
2168 free (bgp_static->rmap.name);
2169 bgp_static->rmap.name = strdup (rmap);
2170 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
2172 rn->info = bgp_static;
2175 /* If BGP scan is not enabled, we should install this route here. */
2176 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
2178 bgp_static->valid = 1;
2180 if (need_update)
2181 bgp_static_withdraw (bgp, &p, afi, safi);
2183 if (! bgp_static->backdoor)
2184 bgp_static_update (bgp, &p, bgp_static, afi, safi);
2187 return CMD_SUCCESS;
2190 /* Configure static BGP network. */
2192 bgp_static_unset (struct vty *vty, struct bgp *bgp, char *ip_str,
2193 u_int16_t afi, u_char safi)
2195 int ret;
2196 struct prefix p;
2197 struct bgp_static *bgp_static;
2198 struct bgp_node *rn;
2200 /* Convert IP prefix string to struct prefix. */
2201 ret = str2prefix (ip_str, &p);
2202 if (! ret)
2204 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2205 return CMD_WARNING;
2207 #ifdef HAVE_IPV6
2208 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2210 vty_out (vty, "%% Malformed prefix (link-local address)%s",
2211 VTY_NEWLINE);
2212 return CMD_WARNING;
2214 #endif /* HAVE_IPV6 */
2216 apply_mask (&p);
2218 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
2219 if (! rn)
2221 vty_out (vty, "%% Can't find specified static route configuration.%s",
2222 VTY_NEWLINE);
2223 return CMD_WARNING;
2226 bgp_static = rn->info;
2228 /* Update BGP RIB. */
2229 if (! bgp_static->backdoor)
2230 bgp_static_withdraw (bgp, &p, afi, safi);
2232 /* Clear configuration. */
2233 bgp_static_free (bgp_static);
2234 rn->info = NULL;
2235 bgp_unlock_node (rn);
2236 bgp_unlock_node (rn);
2238 return CMD_SUCCESS;
2241 /* Called from bgp_delete(). Delete all static routes from the BGP
2242 instance. */
2243 void
2244 bgp_static_delete (struct bgp *bgp)
2246 afi_t afi;
2247 safi_t safi;
2248 struct bgp_node *rn;
2249 struct bgp_node *rm;
2250 struct bgp_table *table;
2251 struct bgp_static *bgp_static;
2253 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2254 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2255 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
2256 if (rn->info != NULL)
2258 if (safi == SAFI_MPLS_VPN)
2260 table = rn->info;
2262 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
2264 bgp_static = rn->info;
2265 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
2266 AFI_IP, SAFI_MPLS_VPN,
2267 (struct prefix_rd *)&rn->p,
2268 bgp_static->tag);
2269 bgp_static_free (bgp_static);
2270 rn->info = NULL;
2271 bgp_unlock_node (rn);
2274 else
2276 bgp_static = rn->info;
2277 bgp_static_withdraw (bgp, &rn->p, afi, safi);
2278 bgp_static_free (bgp_static);
2279 rn->info = NULL;
2280 bgp_unlock_node (rn);
2286 bgp_static_set_vpnv4 (struct vty *vty, char *ip_str, char *rd_str,
2287 char *tag_str)
2289 int ret;
2290 struct prefix p;
2291 struct prefix_rd prd;
2292 struct bgp *bgp;
2293 struct bgp_node *prn;
2294 struct bgp_node *rn;
2295 struct bgp_table *table;
2296 struct bgp_static *bgp_static;
2297 u_char tag[3];
2299 bgp = vty->index;
2301 ret = str2prefix (ip_str, &p);
2302 if (! ret)
2304 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2305 return CMD_WARNING;
2307 apply_mask (&p);
2309 ret = str2prefix_rd (rd_str, &prd);
2310 if (! ret)
2312 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
2313 return CMD_WARNING;
2316 ret = str2tag (tag_str, tag);
2317 if (! ret)
2319 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
2320 return CMD_WARNING;
2323 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
2324 (struct prefix *)&prd);
2325 if (prn->info == NULL)
2326 prn->info = bgp_table_init ();
2327 else
2328 bgp_unlock_node (prn);
2329 table = prn->info;
2331 rn = bgp_node_get (table, &p);
2333 if (rn->info)
2335 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
2336 bgp_unlock_node (rn);
2338 else
2340 /* New configuration. */
2341 bgp_static = bgp_static_new ();
2342 bgp_static->valid = 1;
2343 memcpy (bgp_static->tag, tag, 3);
2344 rn->info = bgp_static;
2346 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
2349 return CMD_SUCCESS;
2352 /* Configure static BGP network. */
2354 bgp_static_unset_vpnv4 (struct vty *vty, char *ip_str, char *rd_str,
2355 char *tag_str)
2357 int ret;
2358 struct bgp *bgp;
2359 struct prefix p;
2360 struct prefix_rd prd;
2361 struct bgp_node *prn;
2362 struct bgp_node *rn;
2363 struct bgp_table *table;
2364 struct bgp_static *bgp_static;
2365 u_char tag[3];
2367 bgp = vty->index;
2369 /* Convert IP prefix string to struct prefix. */
2370 ret = str2prefix (ip_str, &p);
2371 if (! ret)
2373 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2374 return CMD_WARNING;
2376 apply_mask (&p);
2378 ret = str2prefix_rd (rd_str, &prd);
2379 if (! ret)
2381 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
2382 return CMD_WARNING;
2385 ret = str2tag (tag_str, tag);
2386 if (! ret)
2388 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
2389 return CMD_WARNING;
2392 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
2393 (struct prefix *)&prd);
2394 if (prn->info == NULL)
2395 prn->info = bgp_table_init ();
2396 else
2397 bgp_unlock_node (prn);
2398 table = prn->info;
2400 rn = bgp_node_lookup (table, &p);
2402 if (rn)
2404 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
2406 bgp_static = rn->info;
2407 bgp_static_free (bgp_static);
2408 rn->info = NULL;
2409 bgp_unlock_node (rn);
2410 bgp_unlock_node (rn);
2412 else
2413 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
2415 return CMD_SUCCESS;
2418 DEFUN (bgp_network,
2419 bgp_network_cmd,
2420 "network A.B.C.D/M",
2421 "Specify a network to announce via BGP\n"
2422 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2424 return bgp_static_set (vty, vty->index, argv[0],
2425 AFI_IP, bgp_node_safi (vty), NULL, 0);
2428 DEFUN (bgp_network_route_map,
2429 bgp_network_route_map_cmd,
2430 "network A.B.C.D/M route-map WORD",
2431 "Specify a network to announce via BGP\n"
2432 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2433 "Route-map to modify the attributes\n"
2434 "Name of the route map\n")
2436 return bgp_static_set (vty, vty->index, argv[0],
2437 AFI_IP, bgp_node_safi (vty), argv[1], 0);
2440 DEFUN (bgp_network_backdoor,
2441 bgp_network_backdoor_cmd,
2442 "network A.B.C.D/M backdoor",
2443 "Specify a network to announce via BGP\n"
2444 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2445 "Specify a BGP backdoor route\n")
2447 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
2450 DEFUN (bgp_network_mask,
2451 bgp_network_mask_cmd,
2452 "network A.B.C.D mask A.B.C.D",
2453 "Specify a network to announce via BGP\n"
2454 "Network number\n"
2455 "Network mask\n"
2456 "Network mask\n")
2458 int ret;
2459 char prefix_str[BUFSIZ];
2461 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2462 if (! ret)
2464 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2465 return CMD_WARNING;
2468 return bgp_static_set (vty, vty->index, prefix_str,
2469 AFI_IP, bgp_node_safi (vty), NULL, 0);
2472 DEFUN (bgp_network_mask_route_map,
2473 bgp_network_mask_route_map_cmd,
2474 "network A.B.C.D mask A.B.C.D route-map WORD",
2475 "Specify a network to announce via BGP\n"
2476 "Network number\n"
2477 "Network mask\n"
2478 "Network mask\n"
2479 "Route-map to modify the attributes\n"
2480 "Name of the route map\n")
2482 int ret;
2483 char prefix_str[BUFSIZ];
2485 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2486 if (! ret)
2488 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2489 return CMD_WARNING;
2492 return bgp_static_set (vty, vty->index, prefix_str,
2493 AFI_IP, bgp_node_safi (vty), argv[2], 0);
2496 DEFUN (bgp_network_mask_backdoor,
2497 bgp_network_mask_backdoor_cmd,
2498 "network A.B.C.D mask A.B.C.D backdoor",
2499 "Specify a network to announce via BGP\n"
2500 "Network number\n"
2501 "Network mask\n"
2502 "Network mask\n"
2503 "Specify a BGP backdoor route\n")
2505 int ret;
2506 char prefix_str[BUFSIZ];
2508 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2509 if (! ret)
2511 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2512 return CMD_WARNING;
2515 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
2518 DEFUN (bgp_network_mask_natural,
2519 bgp_network_mask_natural_cmd,
2520 "network A.B.C.D",
2521 "Specify a network to announce via BGP\n"
2522 "Network number\n")
2524 int ret;
2525 char prefix_str[BUFSIZ];
2527 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2528 if (! ret)
2530 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2531 return CMD_WARNING;
2534 return bgp_static_set (vty, vty->index, prefix_str,
2535 AFI_IP, bgp_node_safi (vty), NULL, 0);
2538 DEFUN (bgp_network_mask_natural_route_map,
2539 bgp_network_mask_natural_route_map_cmd,
2540 "network A.B.C.D route-map WORD",
2541 "Specify a network to announce via BGP\n"
2542 "Network number\n"
2543 "Route-map to modify the attributes\n"
2544 "Name of the route map\n")
2546 int ret;
2547 char prefix_str[BUFSIZ];
2549 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2550 if (! ret)
2552 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2553 return CMD_WARNING;
2556 return bgp_static_set (vty, vty->index, prefix_str,
2557 AFI_IP, bgp_node_safi (vty), argv[1], 0);
2560 DEFUN (bgp_network_mask_natural_backdoor,
2561 bgp_network_mask_natural_backdoor_cmd,
2562 "network A.B.C.D backdoor",
2563 "Specify a network to announce via BGP\n"
2564 "Network number\n"
2565 "Specify a BGP backdoor route\n")
2567 int ret;
2568 char prefix_str[BUFSIZ];
2570 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2571 if (! ret)
2573 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2574 return CMD_WARNING;
2577 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
2580 DEFUN (no_bgp_network,
2581 no_bgp_network_cmd,
2582 "no network A.B.C.D/M",
2583 NO_STR
2584 "Specify a network to announce via BGP\n"
2585 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2587 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
2588 bgp_node_safi (vty));
2591 ALIAS (no_bgp_network,
2592 no_bgp_network_route_map_cmd,
2593 "no network A.B.C.D/M route-map WORD",
2594 NO_STR
2595 "Specify a network to announce via BGP\n"
2596 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2597 "Route-map to modify the attributes\n"
2598 "Name of the route map\n");
2600 ALIAS (no_bgp_network,
2601 no_bgp_network_backdoor_cmd,
2602 "no network A.B.C.D/M backdoor",
2603 NO_STR
2604 "Specify a network to announce via BGP\n"
2605 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2606 "Specify a BGP backdoor route\n");
2608 DEFUN (no_bgp_network_mask,
2609 no_bgp_network_mask_cmd,
2610 "no network A.B.C.D mask A.B.C.D",
2611 NO_STR
2612 "Specify a network to announce via BGP\n"
2613 "Network number\n"
2614 "Network mask\n"
2615 "Network mask\n")
2617 int ret;
2618 char prefix_str[BUFSIZ];
2620 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2621 if (! ret)
2623 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2624 return CMD_WARNING;
2627 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
2628 bgp_node_safi (vty));
2631 ALIAS (no_bgp_network_mask,
2632 no_bgp_network_mask_route_map_cmd,
2633 "no network A.B.C.D mask A.B.C.D route-map WORD",
2634 NO_STR
2635 "Specify a network to announce via BGP\n"
2636 "Network number\n"
2637 "Network mask\n"
2638 "Network mask\n"
2639 "Route-map to modify the attributes\n"
2640 "Name of the route map\n");
2642 ALIAS (no_bgp_network_mask,
2643 no_bgp_network_mask_backdoor_cmd,
2644 "no network A.B.C.D mask A.B.C.D backdoor",
2645 NO_STR
2646 "Specify a network to announce via BGP\n"
2647 "Network number\n"
2648 "Network mask\n"
2649 "Network mask\n"
2650 "Specify a BGP backdoor route\n");
2652 DEFUN (no_bgp_network_mask_natural,
2653 no_bgp_network_mask_natural_cmd,
2654 "no network A.B.C.D",
2655 NO_STR
2656 "Specify a network to announce via BGP\n"
2657 "Network number\n")
2659 int ret;
2660 char prefix_str[BUFSIZ];
2662 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2663 if (! ret)
2665 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2666 return CMD_WARNING;
2669 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
2670 bgp_node_safi (vty));
2673 ALIAS (no_bgp_network_mask_natural,
2674 no_bgp_network_mask_natural_route_map_cmd,
2675 "no network A.B.C.D route-map WORD",
2676 NO_STR
2677 "Specify a network to announce via BGP\n"
2678 "Network number\n"
2679 "Route-map to modify the attributes\n"
2680 "Name of the route map\n");
2682 ALIAS (no_bgp_network_mask_natural,
2683 no_bgp_network_mask_natural_backdoor_cmd,
2684 "no network A.B.C.D backdoor",
2685 NO_STR
2686 "Specify a network to announce via BGP\n"
2687 "Network number\n"
2688 "Specify a BGP backdoor route\n");
2690 #ifdef HAVE_IPV6
2691 DEFUN (ipv6_bgp_network,
2692 ipv6_bgp_network_cmd,
2693 "network X:X::X:X/M",
2694 "Specify a network to announce via BGP\n"
2695 "IPv6 prefix <network>/<length>\n")
2697 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
2700 DEFUN (ipv6_bgp_network_route_map,
2701 ipv6_bgp_network_route_map_cmd,
2702 "network X:X::X:X/M route-map WORD",
2703 "Specify a network to announce via BGP\n"
2704 "IPv6 prefix <network>/<length>\n"
2705 "Route-map to modify the attributes\n"
2706 "Name of the route map\n")
2708 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
2709 bgp_node_safi (vty), argv[1], 0);
2712 DEFUN (no_ipv6_bgp_network,
2713 no_ipv6_bgp_network_cmd,
2714 "no network X:X::X:X/M",
2715 NO_STR
2716 "Specify a network to announce via BGP\n"
2717 "IPv6 prefix <network>/<length>\n")
2719 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
2722 ALIAS (no_ipv6_bgp_network,
2723 no_ipv6_bgp_network_route_map_cmd,
2724 "no network X:X::X:X/M route-map WORD",
2725 NO_STR
2726 "Specify a network to announce via BGP\n"
2727 "IPv6 prefix <network>/<length>\n"
2728 "Route-map to modify the attributes\n"
2729 "Name of the route map\n");
2731 ALIAS (ipv6_bgp_network,
2732 old_ipv6_bgp_network_cmd,
2733 "ipv6 bgp network X:X::X:X/M",
2734 IPV6_STR
2735 BGP_STR
2736 "Specify a network to announce via BGP\n"
2737 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n");
2739 ALIAS (no_ipv6_bgp_network,
2740 old_no_ipv6_bgp_network_cmd,
2741 "no ipv6 bgp network X:X::X:X/M",
2742 NO_STR
2743 IPV6_STR
2744 BGP_STR
2745 "Specify a network to announce via BGP\n"
2746 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n");
2747 #endif /* HAVE_IPV6 */
2749 /* Aggreagete address:
2751 advertise-map Set condition to advertise attribute
2752 as-set Generate AS set path information
2753 attribute-map Set attributes of aggregate
2754 route-map Set parameters of aggregate
2755 summary-only Filter more specific routes from updates
2756 suppress-map Conditionally filter more specific routes from updates
2757 <cr>
2759 struct bgp_aggregate
2761 /* Summary-only flag. */
2762 u_char summary_only;
2764 /* AS set generation. */
2765 u_char as_set;
2767 /* Route-map for aggregated route. */
2768 struct route_map *map;
2770 /* Suppress-count. */
2771 unsigned long count;
2773 /* SAFI configuration. */
2774 safi_t safi;
2777 struct bgp_aggregate *
2778 bgp_aggregate_new ()
2780 struct bgp_aggregate *new;
2781 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
2782 memset (new, 0, sizeof (struct bgp_aggregate));
2783 return new;
2786 void
2787 bgp_aggregate_free (struct bgp_aggregate *aggregate)
2789 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
2792 void
2793 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
2794 afi_t afi, safi_t safi, struct bgp_info *del,
2795 struct bgp_aggregate *aggregate)
2797 struct bgp_table *table;
2798 struct bgp_node *top;
2799 struct bgp_node *rn;
2800 u_char origin;
2801 struct aspath *aspath = NULL;
2802 struct aspath *asmerge = NULL;
2803 struct community *community = NULL;
2804 struct community *commerge = NULL;
2805 struct in_addr nexthop;
2806 u_int32_t med = 0;
2807 struct bgp_info *ri;
2808 struct bgp_info *new;
2809 int first = 1;
2810 unsigned long match = 0;
2812 /* Record adding route's nexthop and med. */
2813 if (rinew)
2815 nexthop = rinew->attr->nexthop;
2816 med = rinew->attr->med;
2819 /* ORIGIN attribute: If at least one route among routes that are
2820 aggregated has ORIGIN with the value INCOMPLETE, then the
2821 aggregated route must have the ORIGIN attribute with the value
2822 INCOMPLETE. Otherwise, if at least one route among routes that
2823 are aggregated has ORIGIN with the value EGP, then the aggregated
2824 route must have the origin attribute with the value EGP. In all
2825 other case the value of the ORIGIN attribute of the aggregated
2826 route is INTERNAL. */
2827 origin = BGP_ORIGIN_IGP;
2829 table = bgp->rib[afi][safi];
2831 top = bgp_node_get (table, p);
2832 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
2833 if (rn->p.prefixlen > p->prefixlen)
2835 match = 0;
2837 for (ri = rn->info; ri; ri = ri->next)
2839 if (BGP_INFO_HOLDDOWN (ri))
2840 continue;
2842 if (del && ri == del)
2843 continue;
2845 if (! rinew && first)
2847 nexthop = ri->attr->nexthop;
2848 med = ri->attr->med;
2849 first = 0;
2852 #ifdef AGGREGATE_NEXTHOP_CHECK
2853 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
2854 || ri->attr->med != med)
2856 if (aspath)
2857 aspath_free (aspath);
2858 if (community)
2859 community_free (community);
2860 bgp_unlock_node (rn);
2861 bgp_unlock_node (top);
2862 return;
2864 #endif /* AGGREGATE_NEXTHOP_CHECK */
2866 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
2868 if (aggregate->summary_only)
2870 ri->suppress++;
2871 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2872 match++;
2875 aggregate->count++;
2877 if (aggregate->as_set)
2879 if (origin < ri->attr->origin)
2880 origin = ri->attr->origin;
2882 if (aspath)
2884 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
2885 aspath_free (aspath);
2886 aspath = asmerge;
2888 else
2889 aspath = aspath_dup (ri->attr->aspath);
2891 if (ri->attr->community)
2893 if (community)
2895 commerge = community_merge (community,
2896 ri->attr->community);
2897 community = community_uniq_sort (commerge);
2898 community_free (commerge);
2900 else
2901 community = community_dup (ri->attr->community);
2906 if (match)
2907 bgp_process (bgp, rn, afi, safi);
2909 bgp_unlock_node (top);
2911 if (rinew)
2913 aggregate->count++;
2915 if (aggregate->summary_only)
2916 rinew->suppress++;
2918 if (aggregate->as_set)
2920 if (origin < rinew->attr->origin)
2921 origin = rinew->attr->origin;
2923 if (aspath)
2925 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
2926 aspath_free (aspath);
2927 aspath = asmerge;
2929 else
2930 aspath = aspath_dup (rinew->attr->aspath);
2932 if (rinew->attr->community)
2934 if (community)
2936 commerge = community_merge (community,
2937 rinew->attr->community);
2938 community = community_uniq_sort (commerge);
2939 community_free (commerge);
2941 else
2942 community = community_dup (rinew->attr->community);
2947 if (aggregate->count > 0)
2949 rn = bgp_node_get (table, p);
2950 new = bgp_info_new ();
2951 new->type = ZEBRA_ROUTE_BGP;
2952 new->sub_type = BGP_ROUTE_AGGREGATE;
2953 new->peer = bgp->peer_self;
2954 SET_FLAG (new->flags, BGP_INFO_VALID);
2955 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
2956 new->uptime = time (NULL);
2958 bgp_info_add (rn, new);
2959 bgp_process (bgp, rn, afi, safi);
2961 else
2963 if (aspath)
2964 aspath_free (aspath);
2965 if (community)
2966 community_free (community);
2970 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
2971 struct bgp_aggregate *);
2973 void
2974 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
2975 struct bgp_info *ri, afi_t afi, safi_t safi)
2977 struct bgp_node *child;
2978 struct bgp_node *rn;
2979 struct bgp_aggregate *aggregate;
2981 /* MPLS-VPN aggregation is not yet supported. */
2982 if (safi == SAFI_MPLS_VPN)
2983 return;
2985 if (p->prefixlen == 0)
2986 return;
2988 if (BGP_INFO_HOLDDOWN (ri))
2989 return;
2991 child = bgp_node_get (bgp->aggregate[afi][safi], p);
2993 /* Aggregate address configuration check. */
2994 for (rn = child; rn; rn = rn->parent)
2995 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
2997 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
2998 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
3000 bgp_unlock_node (child);
3003 void
3004 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
3005 struct bgp_info *del, afi_t afi, safi_t safi)
3007 struct bgp_node *child;
3008 struct bgp_node *rn;
3009 struct bgp_aggregate *aggregate;
3011 /* MPLS-VPN aggregation is not yet supported. */
3012 if (safi == SAFI_MPLS_VPN)
3013 return;
3015 if (p->prefixlen == 0)
3016 return;
3018 child = bgp_node_get (bgp->aggregate[afi][safi], p);
3020 /* Aggregate address configuration check. */
3021 for (rn = child; rn; rn = rn->parent)
3022 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
3024 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
3025 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
3027 bgp_unlock_node (child);
3030 void
3031 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
3032 struct bgp_aggregate *aggregate)
3034 struct bgp_table *table;
3035 struct bgp_node *top;
3036 struct bgp_node *rn;
3037 struct bgp_info *new;
3038 struct bgp_info *ri;
3039 unsigned long match;
3040 u_char origin = BGP_ORIGIN_IGP;
3041 struct aspath *aspath = NULL;
3042 struct aspath *asmerge = NULL;
3043 struct community *community = NULL;
3044 struct community *commerge = NULL;
3046 table = bgp->rib[afi][safi];
3048 /* Sanity check. */
3049 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
3050 return;
3051 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
3052 return;
3054 /* If routes exists below this node, generate aggregate routes. */
3055 top = bgp_node_get (table, p);
3056 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
3057 if (rn->p.prefixlen > p->prefixlen)
3059 match = 0;
3061 for (ri = rn->info; ri; ri = ri->next)
3063 if (BGP_INFO_HOLDDOWN (ri))
3064 continue;
3066 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
3068 /* summary-only aggregate route suppress aggregated
3069 route announcement. */
3070 if (aggregate->summary_only)
3072 ri->suppress++;
3073 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3074 match++;
3076 /* as-set aggregate route generate origin, as path,
3077 community aggregation. */
3078 if (aggregate->as_set)
3080 if (origin < ri->attr->origin)
3081 origin = ri->attr->origin;
3083 if (aspath)
3085 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
3086 aspath_free (aspath);
3087 aspath = asmerge;
3089 else
3090 aspath = aspath_dup (ri->attr->aspath);
3092 if (ri->attr->community)
3094 if (community)
3096 commerge = community_merge (community,
3097 ri->attr->community);
3098 community = community_uniq_sort (commerge);
3099 community_free (commerge);
3101 else
3102 community = community_dup (ri->attr->community);
3105 aggregate->count++;
3109 /* If this node is suppressed, process the change. */
3110 if (match)
3111 bgp_process (bgp, rn, afi, safi);
3113 bgp_unlock_node (top);
3115 /* Add aggregate route to BGP table. */
3116 if (aggregate->count)
3118 rn = bgp_node_get (table, p);
3120 new = bgp_info_new ();
3121 new->type = ZEBRA_ROUTE_BGP;
3122 new->sub_type = BGP_ROUTE_AGGREGATE;
3123 new->peer = bgp->peer_self;
3124 SET_FLAG (new->flags, BGP_INFO_VALID);
3125 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
3126 new->uptime = time (NULL);
3128 bgp_info_add (rn, new);
3130 /* Process change. */
3131 bgp_process (bgp, rn, afi, safi);
3135 void
3136 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
3137 safi_t safi, struct bgp_aggregate *aggregate)
3139 struct bgp_table *table;
3140 struct bgp_node *top;
3141 struct bgp_node *rn;
3142 struct bgp_info *ri;
3143 unsigned long match;
3145 table = bgp->rib[afi][safi];
3147 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
3148 return;
3149 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
3150 return;
3152 /* If routes exists below this node, generate aggregate routes. */
3153 top = bgp_node_get (table, p);
3154 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
3155 if (rn->p.prefixlen > p->prefixlen)
3157 match = 0;
3159 for (ri = rn->info; ri; ri = ri->next)
3161 if (BGP_INFO_HOLDDOWN (ri))
3162 continue;
3164 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
3166 if (aggregate->summary_only)
3168 ri->suppress--;
3170 if (ri->suppress == 0)
3172 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3173 match++;
3176 aggregate->count--;
3180 /* If this node is suppressed, process the change. */
3181 if (match)
3182 bgp_process (bgp, rn, afi, safi);
3184 bgp_unlock_node (top);
3186 /* Delete aggregate route from BGP table. */
3187 rn = bgp_node_get (table, p);
3189 for (ri = rn->info; ri; ri = ri->next)
3190 if (ri->peer == bgp->peer_self
3191 && ri->type == ZEBRA_ROUTE_BGP
3192 && ri->sub_type == BGP_ROUTE_AGGREGATE)
3193 break;
3195 /* Withdraw static BGP route from routing table. */
3196 if (ri)
3198 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3199 bgp_process (bgp, rn, afi, safi);
3200 bgp_info_delete (rn, ri);
3201 bgp_info_free (ri);
3202 bgp_unlock_node (rn);
3205 /* Unlock bgp_node_lookup. */
3206 bgp_unlock_node (rn);
3209 /* Aggregate route attribute. */
3210 #define AGGREGATE_SUMMARY_ONLY 1
3211 #define AGGREGATE_AS_SET 1
3214 bgp_aggregate_set (struct vty *vty, char *prefix_str, afi_t afi, safi_t safi,
3215 u_char summary_only, u_char as_set)
3217 int ret;
3218 struct prefix p;
3219 struct bgp_node *rn;
3220 struct bgp *bgp;
3221 struct bgp_aggregate *aggregate;
3223 /* Convert string to prefix structure. */
3224 ret = str2prefix (prefix_str, &p);
3225 if (!ret)
3227 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
3228 return CMD_WARNING;
3230 apply_mask (&p);
3232 /* Get BGP structure. */
3233 bgp = vty->index;
3235 /* Old configuration check. */
3236 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
3238 if (rn->info)
3240 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
3241 bgp_unlock_node (rn);
3242 return CMD_WARNING;
3245 /* Make aggregate address structure. */
3246 aggregate = bgp_aggregate_new ();
3247 aggregate->summary_only = summary_only;
3248 aggregate->as_set = as_set;
3249 aggregate->safi = safi;
3250 rn->info = aggregate;
3252 /* Aggregate address insert into BGP routing table. */
3253 if (safi & SAFI_UNICAST)
3254 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
3255 if (safi & SAFI_MULTICAST)
3256 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
3258 return CMD_SUCCESS;
3262 bgp_aggregate_unset (struct vty *vty, char *prefix_str, afi_t afi, safi_t safi)
3264 int ret;
3265 struct prefix p;
3266 struct bgp_node *rn;
3267 struct bgp *bgp;
3268 struct bgp_aggregate *aggregate;
3270 /* Convert string to prefix structure. */
3271 ret = str2prefix (prefix_str, &p);
3272 if (!ret)
3274 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
3275 return CMD_WARNING;
3277 apply_mask (&p);
3279 /* Get BGP structure. */
3280 bgp = vty->index;
3282 /* Old configuration check. */
3283 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
3284 if (! rn)
3286 vty_out (vty, "%% There is no aggregate-address configuration.%s",
3287 VTY_NEWLINE);
3288 return CMD_WARNING;
3291 aggregate = rn->info;
3292 if (aggregate->safi & SAFI_UNICAST)
3293 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
3294 if (aggregate->safi & SAFI_MULTICAST)
3295 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
3297 /* Unlock aggregate address configuration. */
3298 rn->info = NULL;
3299 bgp_aggregate_free (aggregate);
3300 bgp_unlock_node (rn);
3301 bgp_unlock_node (rn);
3303 return CMD_SUCCESS;
3306 DEFUN (aggregate_address,
3307 aggregate_address_cmd,
3308 "aggregate-address A.B.C.D/M",
3309 "Configure BGP aggregate entries\n"
3310 "Aggregate prefix\n")
3312 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
3315 DEFUN (aggregate_address_mask,
3316 aggregate_address_mask_cmd,
3317 "aggregate-address A.B.C.D A.B.C.D",
3318 "Configure BGP aggregate entries\n"
3319 "Aggregate address\n"
3320 "Aggregate mask\n")
3322 int ret;
3323 char prefix_str[BUFSIZ];
3325 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3327 if (! ret)
3329 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3330 return CMD_WARNING;
3333 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3334 0, 0);
3337 DEFUN (aggregate_address_summary_only,
3338 aggregate_address_summary_only_cmd,
3339 "aggregate-address A.B.C.D/M summary-only",
3340 "Configure BGP aggregate entries\n"
3341 "Aggregate prefix\n"
3342 "Filter more specific routes from updates\n")
3344 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3345 AGGREGATE_SUMMARY_ONLY, 0);
3348 DEFUN (aggregate_address_mask_summary_only,
3349 aggregate_address_mask_summary_only_cmd,
3350 "aggregate-address A.B.C.D A.B.C.D summary-only",
3351 "Configure BGP aggregate entries\n"
3352 "Aggregate address\n"
3353 "Aggregate mask\n"
3354 "Filter more specific routes from updates\n")
3356 int ret;
3357 char prefix_str[BUFSIZ];
3359 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3361 if (! ret)
3363 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3364 return CMD_WARNING;
3367 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3368 AGGREGATE_SUMMARY_ONLY, 0);
3371 DEFUN (aggregate_address_as_set,
3372 aggregate_address_as_set_cmd,
3373 "aggregate-address A.B.C.D/M as-set",
3374 "Configure BGP aggregate entries\n"
3375 "Aggregate prefix\n"
3376 "Generate AS set path information\n")
3378 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3379 0, AGGREGATE_AS_SET);
3382 DEFUN (aggregate_address_mask_as_set,
3383 aggregate_address_mask_as_set_cmd,
3384 "aggregate-address A.B.C.D A.B.C.D as-set",
3385 "Configure BGP aggregate entries\n"
3386 "Aggregate address\n"
3387 "Aggregate mask\n"
3388 "Generate AS set path information\n")
3390 int ret;
3391 char prefix_str[BUFSIZ];
3393 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3395 if (! ret)
3397 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3398 return CMD_WARNING;
3401 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3402 0, AGGREGATE_AS_SET);
3406 DEFUN (aggregate_address_as_set_summary,
3407 aggregate_address_as_set_summary_cmd,
3408 "aggregate-address A.B.C.D/M as-set summary-only",
3409 "Configure BGP aggregate entries\n"
3410 "Aggregate prefix\n"
3411 "Generate AS set path information\n"
3412 "Filter more specific routes from updates\n")
3414 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3415 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
3418 ALIAS (aggregate_address_as_set_summary,
3419 aggregate_address_summary_as_set_cmd,
3420 "aggregate-address A.B.C.D/M summary-only as-set",
3421 "Configure BGP aggregate entries\n"
3422 "Aggregate prefix\n"
3423 "Filter more specific routes from updates\n"
3424 "Generate AS set path information\n");
3426 DEFUN (aggregate_address_mask_as_set_summary,
3427 aggregate_address_mask_as_set_summary_cmd,
3428 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
3429 "Configure BGP aggregate entries\n"
3430 "Aggregate address\n"
3431 "Aggregate mask\n"
3432 "Generate AS set path information\n"
3433 "Filter more specific routes from updates\n")
3435 int ret;
3436 char prefix_str[BUFSIZ];
3438 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3440 if (! ret)
3442 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3443 return CMD_WARNING;
3446 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3447 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
3450 ALIAS (aggregate_address_mask_as_set_summary,
3451 aggregate_address_mask_summary_as_set_cmd,
3452 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
3453 "Configure BGP aggregate entries\n"
3454 "Aggregate address\n"
3455 "Aggregate mask\n"
3456 "Filter more specific routes from updates\n"
3457 "Generate AS set path information\n");
3459 DEFUN (no_aggregate_address,
3460 no_aggregate_address_cmd,
3461 "no aggregate-address A.B.C.D/M",
3462 NO_STR
3463 "Configure BGP aggregate entries\n"
3464 "Aggregate prefix\n")
3466 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
3469 ALIAS (no_aggregate_address,
3470 no_aggregate_address_summary_only_cmd,
3471 "no aggregate-address A.B.C.D/M summary-only",
3472 NO_STR
3473 "Configure BGP aggregate entries\n"
3474 "Aggregate prefix\n"
3475 "Filter more specific routes from updates\n");
3477 ALIAS (no_aggregate_address,
3478 no_aggregate_address_as_set_cmd,
3479 "no aggregate-address A.B.C.D/M as-set",
3480 NO_STR
3481 "Configure BGP aggregate entries\n"
3482 "Aggregate prefix\n"
3483 "Generate AS set path information\n");
3485 ALIAS (no_aggregate_address,
3486 no_aggregate_address_as_set_summary_cmd,
3487 "no aggregate-address A.B.C.D/M as-set summary-only",
3488 NO_STR
3489 "Configure BGP aggregate entries\n"
3490 "Aggregate prefix\n"
3491 "Generate AS set path information\n"
3492 "Filter more specific routes from updates\n");
3494 ALIAS (no_aggregate_address,
3495 no_aggregate_address_summary_as_set_cmd,
3496 "no aggregate-address A.B.C.D/M summary-only as-set",
3497 NO_STR
3498 "Configure BGP aggregate entries\n"
3499 "Aggregate prefix\n"
3500 "Filter more specific routes from updates\n"
3501 "Generate AS set path information\n");
3503 DEFUN (no_aggregate_address_mask,
3504 no_aggregate_address_mask_cmd,
3505 "no aggregate-address A.B.C.D A.B.C.D",
3506 NO_STR
3507 "Configure BGP aggregate entries\n"
3508 "Aggregate address\n"
3509 "Aggregate mask\n")
3511 int ret;
3512 char prefix_str[BUFSIZ];
3514 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3516 if (! ret)
3518 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3519 return CMD_WARNING;
3522 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
3525 ALIAS (no_aggregate_address_mask,
3526 no_aggregate_address_mask_summary_only_cmd,
3527 "no aggregate-address A.B.C.D A.B.C.D summary-only",
3528 NO_STR
3529 "Configure BGP aggregate entries\n"
3530 "Aggregate address\n"
3531 "Aggregate mask\n"
3532 "Filter more specific routes from updates\n");
3534 ALIAS (no_aggregate_address_mask,
3535 no_aggregate_address_mask_as_set_cmd,
3536 "no aggregate-address A.B.C.D A.B.C.D as-set",
3537 NO_STR
3538 "Configure BGP aggregate entries\n"
3539 "Aggregate address\n"
3540 "Aggregate mask\n"
3541 "Generate AS set path information\n");
3543 ALIAS (no_aggregate_address_mask,
3544 no_aggregate_address_mask_as_set_summary_cmd,
3545 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
3546 NO_STR
3547 "Configure BGP aggregate entries\n"
3548 "Aggregate address\n"
3549 "Aggregate mask\n"
3550 "Generate AS set path information\n"
3551 "Filter more specific routes from updates\n");
3553 ALIAS (no_aggregate_address_mask,
3554 no_aggregate_address_mask_summary_as_set_cmd,
3555 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
3556 NO_STR
3557 "Configure BGP aggregate entries\n"
3558 "Aggregate address\n"
3559 "Aggregate mask\n"
3560 "Filter more specific routes from updates\n"
3561 "Generate AS set path information\n");
3563 #ifdef HAVE_IPV6
3564 DEFUN (ipv6_aggregate_address,
3565 ipv6_aggregate_address_cmd,
3566 "aggregate-address X:X::X:X/M",
3567 "Configure BGP aggregate entries\n"
3568 "Aggregate prefix\n")
3570 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
3573 DEFUN (ipv6_aggregate_address_summary_only,
3574 ipv6_aggregate_address_summary_only_cmd,
3575 "aggregate-address X:X::X:X/M summary-only",
3576 "Configure BGP aggregate entries\n"
3577 "Aggregate prefix\n"
3578 "Filter more specific routes from updates\n")
3580 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3581 AGGREGATE_SUMMARY_ONLY, 0);
3584 DEFUN (no_ipv6_aggregate_address,
3585 no_ipv6_aggregate_address_cmd,
3586 "no aggregate-address X:X::X:X/M",
3587 NO_STR
3588 "Configure BGP aggregate entries\n"
3589 "Aggregate prefix\n")
3591 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
3594 DEFUN (no_ipv6_aggregate_address_summary_only,
3595 no_ipv6_aggregate_address_summary_only_cmd,
3596 "no aggregate-address X:X::X:X/M summary-only",
3597 NO_STR
3598 "Configure BGP aggregate entries\n"
3599 "Aggregate prefix\n"
3600 "Filter more specific routes from updates\n")
3602 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
3605 ALIAS (ipv6_aggregate_address,
3606 old_ipv6_aggregate_address_cmd,
3607 "ipv6 bgp aggregate-address X:X::X:X/M",
3608 IPV6_STR
3609 BGP_STR
3610 "Configure BGP aggregate entries\n"
3611 "Aggregate prefix\n");
3613 ALIAS (ipv6_aggregate_address_summary_only,
3614 old_ipv6_aggregate_address_summary_only_cmd,
3615 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
3616 IPV6_STR
3617 BGP_STR
3618 "Configure BGP aggregate entries\n"
3619 "Aggregate prefix\n"
3620 "Filter more specific routes from updates\n");
3622 ALIAS (no_ipv6_aggregate_address,
3623 old_no_ipv6_aggregate_address_cmd,
3624 "no ipv6 bgp aggregate-address X:X::X:X/M",
3625 NO_STR
3626 IPV6_STR
3627 BGP_STR
3628 "Configure BGP aggregate entries\n"
3629 "Aggregate prefix\n");
3631 ALIAS (no_ipv6_aggregate_address_summary_only,
3632 old_no_ipv6_aggregate_address_summary_only_cmd,
3633 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
3634 NO_STR
3635 IPV6_STR
3636 BGP_STR
3637 "Configure BGP aggregate entries\n"
3638 "Aggregate prefix\n"
3639 "Filter more specific routes from updates\n");
3640 #endif /* HAVE_IPV6 */
3642 /* Redistribute route treatment. */
3643 void
3644 bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
3645 u_int32_t metric, u_char type)
3647 struct bgp *bgp;
3648 struct listnode *nn;
3649 struct bgp_info *new;
3650 struct bgp_info *bi;
3651 struct bgp_info info;
3652 struct bgp_node *bn;
3653 struct attr attr;
3654 struct attr attr_new;
3655 struct attr *new_attr;
3656 afi_t afi;
3657 int ret;
3659 /* Make default attribute. */
3660 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
3661 if (nexthop)
3662 attr.nexthop = *nexthop;
3664 attr.med = metric;
3665 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3667 LIST_LOOP (bm->bgp, bgp, nn)
3669 afi = family2afi (p->family);
3671 if (bgp->redist[afi][type])
3673 /* Copy attribute for modification. */
3674 attr_new = attr;
3676 if (bgp->redist_metric_flag[afi][type])
3677 attr_new.med = bgp->redist_metric[afi][type];
3679 /* Apply route-map. */
3680 if (bgp->rmap[afi][type].map)
3682 info.peer = bgp->peer_self;
3683 info.attr = &attr_new;
3685 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
3686 &info);
3687 if (ret == RMAP_DENYMATCH)
3689 /* Free uninterned attribute. */
3690 bgp_attr_flush (&attr_new);
3692 /* Unintern original. */
3693 aspath_unintern (attr.aspath);
3694 bgp_redistribute_delete (p, type);
3695 return;
3699 bn = bgp_afi_node_get (bgp, afi, SAFI_UNICAST, p, NULL);
3700 new_attr = bgp_attr_intern (&attr_new);
3702 for (bi = bn->info; bi; bi = bi->next)
3703 if (bi->peer == bgp->peer_self
3704 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
3705 break;
3707 if (bi)
3709 if (attrhash_cmp (bi->attr, new_attr))
3711 bgp_attr_unintern (new_attr);
3712 aspath_unintern (attr.aspath);
3713 bgp_unlock_node (bn);
3714 return;
3716 else
3718 /* The attribute is changed. */
3719 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
3721 /* Rewrite BGP route information. */
3722 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
3723 bgp_attr_unintern (bi->attr);
3724 bi->attr = new_attr;
3725 bi->uptime = time (NULL);
3727 /* Process change. */
3728 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
3729 bgp_process (bgp, bn, afi, SAFI_UNICAST);
3730 bgp_unlock_node (bn);
3731 aspath_unintern (attr.aspath);
3732 return;
3736 new = bgp_info_new ();
3737 new->type = type;
3738 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
3739 new->peer = bgp->peer_self;
3740 SET_FLAG (new->flags, BGP_INFO_VALID);
3741 new->attr = new_attr;
3742 new->uptime = time (NULL);
3744 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
3745 bgp_info_add (bn, new);
3746 bgp_process (bgp, bn, afi, SAFI_UNICAST);
3750 /* Unintern original. */
3751 aspath_unintern (attr.aspath);
3754 void
3755 bgp_redistribute_delete (struct prefix *p, u_char type)
3757 struct bgp *bgp;
3758 struct listnode *nn;
3759 afi_t afi;
3760 struct bgp_node *rn;
3761 struct bgp_info *ri;
3763 LIST_LOOP (bm->bgp, bgp, nn)
3765 afi = family2afi (p->family);
3767 if (bgp->redist[afi][type])
3769 rn = bgp_afi_node_get (bgp, afi, SAFI_UNICAST, p, NULL);
3771 for (ri = rn->info; ri; ri = ri->next)
3772 if (ri->peer == bgp->peer_self
3773 && ri->type == type)
3774 break;
3776 if (ri)
3778 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
3779 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3780 bgp_process (bgp, rn, afi, SAFI_UNICAST);
3781 bgp_info_delete (rn, ri);
3782 bgp_info_free (ri);
3783 bgp_unlock_node (rn);
3785 bgp_unlock_node (rn);
3790 /* Withdraw specified route type's route. */
3791 void
3792 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
3794 struct bgp_node *rn;
3795 struct bgp_info *ri;
3796 struct bgp_table *table;
3798 table = bgp->rib[afi][SAFI_UNICAST];
3800 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3802 for (ri = rn->info; ri; ri = ri->next)
3803 if (ri->peer == bgp->peer_self
3804 && ri->type == type)
3805 break;
3807 if (ri)
3809 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
3810 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3811 bgp_process (bgp, rn, afi, SAFI_UNICAST);
3812 bgp_info_delete (rn, ri);
3813 bgp_info_free (ri);
3814 bgp_unlock_node (rn);
3819 /* Static function to display route. */
3820 static int
3821 route_vty_out_route (struct prefix *p, struct vty *vty)
3823 int len;
3824 u_int32_t destination;
3825 char buf[BUFSIZ];
3827 if (p->family == AF_INET)
3829 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
3830 destination = ntohl (p->u.prefix4.s_addr);
3832 if ((IN_CLASSC (destination) && p->prefixlen == 24)
3833 || (IN_CLASSB (destination) && p->prefixlen == 16)
3834 || (IN_CLASSA (destination) && p->prefixlen == 8)
3835 || p->u.prefix4.s_addr == 0)
3837 /* When mask is natural, mask is not displayed. */
3839 else
3840 len += vty_out (vty, "/%d", p->prefixlen);
3842 else
3843 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
3844 p->prefixlen);
3846 len = 17 - len;
3847 if (len < 1)
3848 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
3849 else
3850 vty_out (vty, "%*s", len, " ");
3852 /* return 1 if it added extra newline */
3853 if (len < 1)
3854 return 1;
3855 else
3856 return 0;
3859 /* Calculate line number of output data. */
3861 vty_calc_line (struct vty *vty, unsigned long length)
3863 return vty->width ? (((vty->obuf->length - length) / vty->width) + 1) : 1;
3866 enum bgp_display_type
3868 normal_list,
3871 /* called from terminal list command */
3873 route_vty_out (struct vty *vty, struct prefix *p,
3874 struct bgp_info *binfo, int display, safi_t safi)
3876 struct attr *attr;
3877 unsigned long length = 0;
3878 int extra_line = 0;
3880 length = vty->obuf->length;
3882 /* Route status display. */
3883 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
3884 vty_out (vty, "S");
3885 else if (binfo->suppress)
3886 vty_out (vty, "s");
3887 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3888 vty_out (vty, "*");
3889 else
3890 vty_out (vty, " ");
3892 /* Selected */
3893 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3894 vty_out (vty, "h");
3895 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
3896 vty_out (vty, "d");
3897 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
3898 vty_out (vty, ">");
3899 else
3900 vty_out (vty, " ");
3902 /* Internal route. */
3903 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
3904 vty_out (vty, "i");
3905 else
3906 vty_out (vty, " ");
3908 /* print prefix and mask */
3909 if (! display)
3910 extra_line += route_vty_out_route (p, vty);
3911 else
3912 vty_out (vty, "%*s", 17, " ");
3914 /* Print attribute */
3915 attr = binfo->attr;
3916 if (attr)
3918 if (p->family == AF_INET)
3920 if (safi == SAFI_MPLS_VPN)
3921 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
3922 else
3923 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
3925 #ifdef HAVE_IPV6
3926 else if (p->family == AF_INET6)
3928 int len;
3929 char buf[BUFSIZ];
3931 len = vty_out (vty, "%s",
3932 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
3933 len = 16 - len;
3934 if (len < 1)
3936 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
3937 extra_line++; /* Adjust More mode for newline above */
3939 else
3940 vty_out (vty, "%*s", len, " ");
3942 #endif /* HAVE_IPV6 */
3944 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
3945 vty_out (vty, "%10u", attr->med);
3946 else
3947 vty_out (vty, " ");
3949 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
3950 vty_out (vty, "%7u", attr->local_pref);
3951 else
3952 vty_out (vty, " ");
3954 vty_out (vty, "%7d ",attr->weight);
3956 /* Print aspath */
3957 if (attr->aspath)
3958 aspath_print_vty (vty, attr->aspath);
3960 /* Print origin */
3961 if (strlen (attr->aspath->str) == 0)
3962 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
3963 else
3964 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
3966 vty_out (vty, "%s", VTY_NEWLINE);
3968 return vty_calc_line (vty, length) + extra_line;
3971 /* called from terminal list command */
3972 void
3973 route_vty_out_tmp (struct vty *vty, struct prefix *p,
3974 struct attr *attr, safi_t safi)
3976 /* Route status display. */
3977 vty_out (vty, "*");
3978 vty_out (vty, ">");
3979 vty_out (vty, " ");
3981 /* print prefix and mask */
3982 route_vty_out_route (p, vty);
3984 /* Print attribute */
3985 if (attr)
3987 if (p->family == AF_INET)
3989 if (safi == SAFI_MPLS_VPN)
3990 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
3991 else
3992 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
3994 #ifdef HAVE_IPV6
3995 else if (p->family == AF_INET6)
3997 int len;
3998 char buf[BUFSIZ];
4000 len = vty_out (vty, "%s",
4001 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
4002 len = 16 - len;
4003 if (len < 1)
4004 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
4005 else
4006 vty_out (vty, "%*s", len, " ");
4008 #endif /* HAVE_IPV6 */
4010 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
4011 vty_out (vty, "%10u", attr->med);
4012 else
4013 vty_out (vty, " ");
4015 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
4016 vty_out (vty, "%7u", attr->local_pref);
4017 else
4018 vty_out (vty, " ");
4020 vty_out (vty, "%7d ",attr->weight);
4022 /* Print aspath */
4023 if (attr->aspath)
4024 aspath_print_vty (vty, attr->aspath);
4026 /* Print origin */
4027 if (strlen (attr->aspath->str) == 0)
4028 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4029 else
4030 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4033 vty_out (vty, "%s", VTY_NEWLINE);
4037 route_vty_out_tag (struct vty *vty, struct prefix *p,
4038 struct bgp_info *binfo, int display, safi_t safi)
4040 struct attr *attr;
4041 unsigned long length = 0;
4042 u_int32_t label = 0;
4043 int extra_line = 0;
4045 length = vty->obuf->length;
4047 /* Route status display. */
4048 if (binfo->suppress)
4049 vty_out (vty, "s");
4050 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4051 vty_out (vty, "*");
4052 else
4053 vty_out (vty, " ");
4055 /* Selected */
4056 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4057 vty_out (vty, "h");
4058 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4059 vty_out (vty, "d");
4060 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4061 vty_out (vty, ">");
4062 else
4063 vty_out (vty, " ");
4065 /* Internal route. */
4066 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
4067 vty_out (vty, "i");
4068 else
4069 vty_out (vty, " ");
4071 /* print prefix and mask */
4072 if (! display)
4073 extra_line += route_vty_out_route (p, vty);
4074 else
4075 vty_out (vty, "%*s", 17, " ");
4077 /* Print attribute */
4078 attr = binfo->attr;
4079 if (attr)
4081 if (p->family == AF_INET)
4083 if (safi == SAFI_MPLS_VPN)
4084 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
4085 else
4086 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
4088 #ifdef HAVE_IPV6
4089 else if (p->family == AF_INET6)
4091 char buf[BUFSIZ];
4092 char buf1[BUFSIZ];
4093 if (attr->mp_nexthop_len == 16)
4094 vty_out (vty, "%s",
4095 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
4096 else if (attr->mp_nexthop_len == 32)
4097 vty_out (vty, "%s(%s)",
4098 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
4099 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
4102 #endif /* HAVE_IPV6 */
4105 label = decode_label (binfo->tag);
4107 vty_out (vty, "notag/%d", label);
4109 vty_out (vty, "%s", VTY_NEWLINE);
4111 return vty_calc_line (vty, length) + extra_line;
4114 /* dampening route */
4116 damp_route_vty_out (struct vty *vty, struct prefix *p,
4117 struct bgp_info *binfo, int display, safi_t safi)
4119 struct attr *attr;
4120 unsigned long length = 0;
4121 int len;
4122 int extra_line = 0;
4124 length = vty->obuf->length;
4126 /* Route status display. */
4127 if (binfo->suppress)
4128 vty_out (vty, "s");
4129 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4130 vty_out (vty, "*");
4131 else
4132 vty_out (vty, " ");
4134 /* Selected */
4135 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4136 vty_out (vty, "h");
4137 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4138 vty_out (vty, "d");
4139 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4140 vty_out (vty, ">");
4141 else
4142 vty_out (vty, " ");
4144 vty_out (vty, " ");
4146 /* print prefix and mask */
4147 if (! display)
4148 extra_line += route_vty_out_route (p, vty);
4149 else
4150 vty_out (vty, "%*s", 17, " ");
4152 len = vty_out (vty, "%s", binfo->peer->host);
4153 len = 17 - len;
4154 if (len < 1)
4156 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
4157 extra_line++;
4159 else
4160 vty_out (vty, "%*s", len, " ");
4162 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
4164 /* Print attribute */
4165 attr = binfo->attr;
4166 if (attr)
4168 /* Print aspath */
4169 if (attr->aspath)
4170 aspath_print_vty (vty, attr->aspath);
4172 /* Print origin */
4173 if (strlen (attr->aspath->str) == 0)
4174 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4175 else
4176 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4178 vty_out (vty, "%s", VTY_NEWLINE);
4180 return vty_calc_line (vty, length) + extra_line;
4183 #define BGP_UPTIME_LEN 25
4185 /* flap route */
4187 flap_route_vty_out (struct vty *vty, struct prefix *p,
4188 struct bgp_info *binfo, int display, safi_t safi)
4190 struct attr *attr;
4191 struct bgp_damp_info *bdi;
4192 unsigned long length = 0;
4193 char timebuf[BGP_UPTIME_LEN];
4194 int len;
4195 int extra_line = 0;
4197 length = vty->obuf->length;
4198 bdi = binfo->damp_info;
4200 /* Route status display. */
4201 if (binfo->suppress)
4202 vty_out (vty, "s");
4203 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4204 vty_out (vty, "*");
4205 else
4206 vty_out (vty, " ");
4208 /* Selected */
4209 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4210 vty_out (vty, "h");
4211 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4212 vty_out (vty, "d");
4213 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4214 vty_out (vty, ">");
4215 else
4216 vty_out (vty, " ");
4218 vty_out (vty, " ");
4220 /* print prefix and mask */
4221 if (! display)
4222 extra_line += route_vty_out_route (p, vty);
4223 else
4224 vty_out (vty, "%*s", 17, " ");
4226 len = vty_out (vty, "%s", binfo->peer->host);
4227 len = 16 - len;
4228 if (len < 1)
4230 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
4231 extra_line++;
4233 else
4234 vty_out (vty, "%*s", len, " ");
4236 len = vty_out (vty, "%d", bdi->flap);
4237 len = 5 - len;
4238 if (len < 1)
4239 vty_out (vty, " ");
4240 else
4241 vty_out (vty, "%*s ", len, " ");
4243 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
4244 timebuf, BGP_UPTIME_LEN));
4246 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
4247 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4248 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
4249 else
4250 vty_out (vty, "%*s ", 8, " ");
4252 /* Print attribute */
4253 attr = binfo->attr;
4254 if (attr)
4256 /* Print aspath */
4257 if (attr->aspath)
4258 aspath_print_vty (vty, attr->aspath);
4260 /* Print origin */
4261 if (strlen (attr->aspath->str) == 0)
4262 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4263 else
4264 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4266 vty_out (vty, "%s", VTY_NEWLINE);
4268 return vty_calc_line (vty, length) + extra_line;
4271 void
4272 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
4273 struct bgp_info *binfo, afi_t afi, safi_t safi)
4275 char buf[INET6_ADDRSTRLEN];
4276 char buf1[BUFSIZ];
4277 struct attr *attr;
4278 int sockunion_vty_out (struct vty *, union sockunion *);
4280 attr = binfo->attr;
4282 if (attr)
4284 /* Line1 display AS-path, Aggregator */
4285 if (attr->aspath)
4287 vty_out (vty, " ");
4288 if (attr->aspath->length == 0)
4289 vty_out (vty, "Local");
4290 else
4291 aspath_print_vty (vty, attr->aspath);
4294 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
4295 vty_out (vty, ", (stale)");
4296 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
4297 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
4298 inet_ntoa (attr->aggregator_addr));
4299 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
4300 vty_out (vty, ", (Received from a RR-client)");
4301 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
4302 vty_out (vty, ", (Received from a RS-client)");
4303 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4304 vty_out (vty, ", (history entry)");
4305 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4306 vty_out (vty, ", (suppressed due to dampening)");
4307 vty_out (vty, "%s", VTY_NEWLINE);
4309 /* Line2 display Next-hop, Neighbor, Router-id */
4310 if (p->family == AF_INET)
4312 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
4313 inet_ntoa (attr->mp_nexthop_global_in) :
4314 inet_ntoa (attr->nexthop));
4316 #ifdef HAVE_IPV6
4317 else
4319 vty_out (vty, " %s",
4320 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
4321 buf, INET6_ADDRSTRLEN));
4323 #endif /* HAVE_IPV6 */
4325 if (binfo->peer == bgp->peer_self)
4327 vty_out (vty, " from %s ",
4328 p->family == AF_INET ? "0.0.0.0" : "::");
4329 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
4331 else
4333 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
4334 vty_out (vty, " (inaccessible)");
4335 else if (binfo->igpmetric)
4336 vty_out (vty, " (metric %d)", binfo->igpmetric);
4337 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
4338 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
4339 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
4340 else
4341 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
4343 vty_out (vty, "%s", VTY_NEWLINE);
4345 #ifdef HAVE_IPV6
4346 /* display nexthop local */
4347 if (attr->mp_nexthop_len == 32)
4349 vty_out (vty, " (%s)%s",
4350 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
4351 buf, INET6_ADDRSTRLEN),
4352 VTY_NEWLINE);
4354 #endif /* HAVE_IPV6 */
4356 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
4357 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
4359 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
4360 vty_out (vty, ", metric %u", attr->med);
4362 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
4363 vty_out (vty, ", localpref %u", attr->local_pref);
4364 else
4365 vty_out (vty, ", localpref %u", bgp->default_local_pref);
4367 if (attr->weight != 0)
4368 vty_out (vty, ", weight %d", attr->weight);
4370 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4371 vty_out (vty, ", valid");
4373 if (binfo->peer != bgp->peer_self)
4375 if (binfo->peer->as == binfo->peer->local_as)
4376 vty_out (vty, ", internal");
4377 else
4378 vty_out (vty, ", %s",
4379 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
4381 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
4382 vty_out (vty, ", aggregated, local");
4383 else if (binfo->type != ZEBRA_ROUTE_BGP)
4384 vty_out (vty, ", sourced");
4385 else
4386 vty_out (vty, ", sourced, local");
4388 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4389 vty_out (vty, ", atomic-aggregate");
4391 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4392 vty_out (vty, ", best");
4394 vty_out (vty, "%s", VTY_NEWLINE);
4396 /* Line 4 display Community */
4397 if (attr->community)
4398 vty_out (vty, " Community: %s%s", attr->community->str,
4399 VTY_NEWLINE);
4401 /* Line 5 display Extended-community */
4402 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
4403 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
4404 VTY_NEWLINE);
4406 /* Line 6 display Originator, Cluster-id */
4407 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
4408 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
4410 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
4411 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
4413 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
4415 int i;
4416 vty_out (vty, ", Cluster list: ");
4417 for (i = 0; i < attr->cluster->length / 4; i++)
4418 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
4420 vty_out (vty, "%s", VTY_NEWLINE);
4423 if (binfo->damp_info)
4424 bgp_damp_info_vty (vty, binfo);
4426 /* Line 7 display Uptime */
4427 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
4429 vty_out (vty, "%s", VTY_NEWLINE);
4432 #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,%s r RIB-failure, S Stale%s"
4433 #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
4434 #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
4435 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
4436 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
4438 enum bgp_show_type
4440 bgp_show_type_normal,
4441 bgp_show_type_regexp,
4442 bgp_show_type_prefix_list,
4443 bgp_show_type_filter_list,
4444 bgp_show_type_route_map,
4445 bgp_show_type_neighbor,
4446 bgp_show_type_cidr_only,
4447 bgp_show_type_prefix_longer,
4448 bgp_show_type_community_all,
4449 bgp_show_type_community,
4450 bgp_show_type_community_exact,
4451 bgp_show_type_community_list,
4452 bgp_show_type_community_list_exact,
4453 bgp_show_type_flap_statistics,
4454 bgp_show_type_flap_address,
4455 bgp_show_type_flap_prefix,
4456 bgp_show_type_flap_cidr_only,
4457 bgp_show_type_flap_regexp,
4458 bgp_show_type_flap_filter_list,
4459 bgp_show_type_flap_prefix_list,
4460 bgp_show_type_flap_prefix_longer,
4461 bgp_show_type_flap_route_map,
4462 bgp_show_type_flap_neighbor,
4463 bgp_show_type_dampend_paths,
4464 bgp_show_type_damp_neighbor
4468 bgp_show_callback (struct vty *vty, int unlock)
4470 struct bgp_node *rn;
4471 struct bgp_info *ri;
4472 int count;
4473 int limit;
4474 int display;
4476 rn = vty->output_rn;
4477 count = 0;
4478 limit = ((vty->lines == 0) ? 10 :
4479 (vty->lines > 0 ? vty->lines : vty->height - 2));
4480 if (vty->status == VTY_MORELINE)
4481 limit = 1;
4482 else
4483 limit = limit > 0 ? limit : 2;
4485 /* Quit of display. */
4486 if (unlock && rn)
4488 bgp_unlock_node (rn);
4489 if (vty->output_clean)
4490 (*vty->output_clean) (vty);
4491 vty->output_rn = NULL;
4492 vty->output_func = NULL;
4493 vty->output_clean = NULL;
4494 vty->output_arg = NULL;
4495 return 0;
4498 for (; rn; rn = bgp_route_next (rn))
4499 if (rn->info != NULL)
4501 display = 0;
4503 for (ri = rn->info; ri; ri = ri->next)
4505 if (vty->output_type == bgp_show_type_flap_statistics
4506 || vty->output_type == bgp_show_type_flap_address
4507 || vty->output_type == bgp_show_type_flap_prefix
4508 || vty->output_type == bgp_show_type_flap_cidr_only
4509 || vty->output_type == bgp_show_type_flap_regexp
4510 || vty->output_type == bgp_show_type_flap_filter_list
4511 || vty->output_type == bgp_show_type_flap_prefix_list
4512 || vty->output_type == bgp_show_type_flap_prefix_longer
4513 || vty->output_type == bgp_show_type_flap_route_map
4514 || vty->output_type == bgp_show_type_flap_neighbor
4515 || vty->output_type == bgp_show_type_dampend_paths
4516 || vty->output_type == bgp_show_type_damp_neighbor)
4518 if (! ri->damp_info)
4519 continue;
4521 if (vty->output_type == bgp_show_type_regexp
4522 || vty->output_type == bgp_show_type_flap_regexp)
4524 regex_t *regex = vty->output_arg;
4526 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
4527 continue;
4529 if (vty->output_type == bgp_show_type_prefix_list
4530 || vty->output_type == bgp_show_type_flap_prefix_list)
4532 struct prefix_list *plist = vty->output_arg;
4534 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
4535 continue;
4537 if (vty->output_type == bgp_show_type_filter_list
4538 || vty->output_type == bgp_show_type_flap_filter_list)
4540 struct as_list *as_list = vty->output_arg;
4542 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
4543 continue;
4545 if (vty->output_type == bgp_show_type_route_map
4546 || vty->output_type == bgp_show_type_flap_route_map)
4548 struct route_map *rmap = vty->output_arg;
4549 struct bgp_info binfo;
4550 struct attr dummy_attr;
4551 int ret;
4553 dummy_attr = *ri->attr;
4554 binfo.peer = ri->peer;
4555 binfo.attr = &dummy_attr;
4557 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
4559 if (ret == RMAP_DENYMATCH)
4560 continue;
4562 if (vty->output_type == bgp_show_type_neighbor
4563 || vty->output_type == bgp_show_type_flap_neighbor
4564 || vty->output_type == bgp_show_type_damp_neighbor)
4566 union sockunion *su = vty->output_arg;
4568 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
4569 continue;
4571 if (vty->output_type == bgp_show_type_cidr_only
4572 || vty->output_type == bgp_show_type_flap_cidr_only)
4574 u_int32_t destination;
4576 destination = ntohl (rn->p.u.prefix4.s_addr);
4577 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
4578 continue;
4579 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
4580 continue;
4581 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
4582 continue;
4584 if (vty->output_type == bgp_show_type_prefix_longer
4585 || vty->output_type == bgp_show_type_flap_prefix_longer)
4587 struct prefix *p = vty->output_arg;
4589 if (! prefix_match (p, &rn->p))
4590 continue;
4592 if (vty->output_type == bgp_show_type_community_all)
4594 if (! ri->attr->community)
4595 continue;
4597 if (vty->output_type == bgp_show_type_community)
4599 struct community *com = vty->output_arg;
4601 if (! ri->attr->community ||
4602 ! community_match (ri->attr->community, com))
4603 continue;
4605 if (vty->output_type == bgp_show_type_community_exact)
4607 struct community *com = vty->output_arg;
4609 if (! ri->attr->community ||
4610 ! community_cmp (ri->attr->community, com))
4611 continue;
4613 if (vty->output_type == bgp_show_type_community_list)
4615 struct community_list *list = vty->output_arg;
4617 if (! community_list_match (ri->attr->community, list))
4618 continue;
4620 if (vty->output_type == bgp_show_type_community_list_exact)
4622 struct community_list *list = vty->output_arg;
4624 if (! community_list_exact_match (ri->attr->community, list))
4625 continue;
4627 if (vty->output_type == bgp_show_type_flap_address
4628 || vty->output_type == bgp_show_type_flap_prefix)
4630 struct prefix *p = vty->output_arg;
4632 if (! prefix_match (&rn->p, p))
4633 continue;
4635 if (vty->output_type == bgp_show_type_flap_prefix)
4636 if (p->prefixlen != rn->p.prefixlen)
4637 continue;
4639 if (vty->output_type == bgp_show_type_dampend_paths
4640 || vty->output_type == bgp_show_type_damp_neighbor)
4642 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
4643 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
4644 continue;
4647 if (vty->output_type == bgp_show_type_dampend_paths
4648 || vty->output_type == bgp_show_type_damp_neighbor)
4649 count += damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4650 else if (vty->output_type == bgp_show_type_flap_statistics
4651 || vty->output_type == bgp_show_type_flap_address
4652 || vty->output_type == bgp_show_type_flap_prefix
4653 || vty->output_type == bgp_show_type_flap_cidr_only
4654 || vty->output_type == bgp_show_type_flap_regexp
4655 || vty->output_type == bgp_show_type_flap_filter_list
4656 || vty->output_type == bgp_show_type_flap_prefix_list
4657 || vty->output_type == bgp_show_type_flap_prefix_longer
4658 || vty->output_type == bgp_show_type_flap_route_map
4659 || vty->output_type == bgp_show_type_flap_neighbor)
4660 count += flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4661 else
4662 count += route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4663 display++;
4666 if (display)
4667 vty->output_count++;
4669 /* Remember current pointer then suspend output. */
4670 if (count >= limit)
4672 vty->status = VTY_CONTINUE;
4673 vty->output_rn = bgp_route_next (rn);;
4674 vty->output_func = bgp_show_callback;
4675 return 0;
4679 /* Total line display. */
4680 if (vty->output_count)
4681 vty_out (vty, "%sTotal number of prefixes %ld%s",
4682 VTY_NEWLINE, vty->output_count, VTY_NEWLINE);
4684 if (vty->output_clean)
4685 (*vty->output_clean) (vty);
4687 vty->status = VTY_CONTINUE;
4688 vty->output_rn = NULL;
4689 vty->output_func = NULL;
4690 vty->output_clean = NULL;
4691 vty->output_arg = NULL;
4693 return 0;
4697 bgp_show (struct vty *vty, char *view_name, afi_t afi, safi_t safi,
4698 enum bgp_show_type type)
4700 struct bgp *bgp;
4701 struct bgp_info *ri;
4702 struct bgp_node *rn;
4703 struct bgp_table *table;
4704 int header = 1;
4705 int count;
4706 int limit;
4707 int display;
4709 limit = ((vty->lines == 0)
4710 ? 10 : (vty->lines > 0
4711 ? vty->lines : vty->height - 2));
4712 limit = limit > 0 ? limit : 2;
4714 /* BGP structure lookup. */
4715 if (view_name)
4717 bgp = bgp_lookup_by_name (view_name);
4718 if (bgp == NULL)
4720 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
4721 return CMD_WARNING;
4724 else
4726 bgp = bgp_get_default ();
4727 if (bgp == NULL)
4729 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
4730 return CMD_WARNING;
4734 count = 0;
4736 /* This is first entry point, so reset total line. */
4737 vty->output_count = 0;
4738 vty->output_type = type;
4740 table = bgp->rib[afi][safi];
4742 /* Start processing of routes. */
4743 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4744 if (rn->info != NULL)
4746 display = 0;
4748 for (ri = rn->info; ri; ri = ri->next)
4750 if (vty->output_type == bgp_show_type_flap_statistics
4751 || type == bgp_show_type_flap_address
4752 || type == bgp_show_type_flap_prefix
4753 || type == bgp_show_type_flap_cidr_only
4754 || type == bgp_show_type_flap_regexp
4755 || type == bgp_show_type_flap_filter_list
4756 || type == bgp_show_type_flap_prefix_list
4757 || type == bgp_show_type_flap_prefix_longer
4758 || type == bgp_show_type_flap_route_map
4759 || type == bgp_show_type_flap_neighbor
4760 || type == bgp_show_type_dampend_paths
4761 || type == bgp_show_type_damp_neighbor)
4763 if (! ri->damp_info)
4764 continue;
4766 if (type == bgp_show_type_regexp
4767 || type == bgp_show_type_flap_regexp)
4769 regex_t *regex = vty->output_arg;
4771 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
4772 continue;
4774 if (type == bgp_show_type_prefix_list
4775 || type == bgp_show_type_flap_prefix_list)
4777 struct prefix_list *plist = vty->output_arg;
4779 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
4780 continue;
4782 if (type == bgp_show_type_filter_list
4783 || type == bgp_show_type_flap_filter_list)
4785 struct as_list *as_list = vty->output_arg;
4787 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
4788 continue;
4790 if (type == bgp_show_type_route_map
4791 || type == bgp_show_type_flap_route_map)
4793 struct route_map *rmap = vty->output_arg;
4794 struct bgp_info binfo;
4795 struct attr dummy_attr;
4796 int ret;
4798 dummy_attr = *ri->attr;
4799 binfo.peer = ri->peer;
4800 binfo.attr = &dummy_attr;
4802 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
4804 if (ret == RMAP_DENYMATCH)
4805 continue;
4807 if (type == bgp_show_type_neighbor
4808 || type == bgp_show_type_flap_neighbor
4809 || type == bgp_show_type_damp_neighbor)
4811 union sockunion *su = vty->output_arg;
4813 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
4814 continue;
4816 if (type == bgp_show_type_cidr_only
4817 || type == bgp_show_type_flap_cidr_only)
4819 u_int32_t destination;
4821 destination = ntohl (rn->p.u.prefix4.s_addr);
4822 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
4823 continue;
4824 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
4825 continue;
4826 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
4827 continue;
4829 if (type == bgp_show_type_prefix_longer
4830 || type == bgp_show_type_flap_prefix_longer)
4832 struct prefix *p = vty->output_arg;
4834 if (! prefix_match (p, &rn->p))
4835 continue;
4837 if (type == bgp_show_type_community_all)
4839 if (! ri->attr->community)
4840 continue;
4842 if (type == bgp_show_type_community)
4844 struct community *com = vty->output_arg;
4846 if (! ri->attr->community ||
4847 ! community_match (ri->attr->community, com))
4848 continue;
4850 if (type == bgp_show_type_community_exact)
4852 struct community *com = vty->output_arg;
4854 if (! ri->attr->community ||
4855 ! community_cmp (ri->attr->community, com))
4856 continue;
4858 if (type == bgp_show_type_community_list)
4860 struct community_list *list = vty->output_arg;
4862 if (! community_list_match (ri->attr->community, list))
4863 continue;
4865 if (type == bgp_show_type_community_list_exact)
4867 struct community_list *list = vty->output_arg;
4869 if (! community_list_exact_match (ri->attr->community, list))
4870 continue;
4872 if (type == bgp_show_type_flap_address
4873 || type == bgp_show_type_flap_prefix)
4875 struct prefix *p = vty->output_arg;
4877 if (! prefix_match (&rn->p, p))
4878 continue;
4880 if (type == bgp_show_type_flap_prefix)
4881 if (p->prefixlen != rn->p.prefixlen)
4882 continue;
4884 if (type == bgp_show_type_dampend_paths
4885 || type == bgp_show_type_damp_neighbor)
4887 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
4888 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
4889 continue;
4892 if (header)
4894 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
4895 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
4896 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
4897 if (type == bgp_show_type_dampend_paths
4898 || type == bgp_show_type_damp_neighbor)
4899 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
4900 else if (type == bgp_show_type_flap_statistics
4901 || type == bgp_show_type_flap_address
4902 || type == bgp_show_type_flap_prefix
4903 || type == bgp_show_type_flap_cidr_only
4904 || type == bgp_show_type_flap_regexp
4905 || type == bgp_show_type_flap_filter_list
4906 || type == bgp_show_type_flap_prefix_list
4907 || type == bgp_show_type_flap_prefix_longer
4908 || type == bgp_show_type_flap_route_map
4909 || type == bgp_show_type_flap_neighbor)
4910 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
4911 else
4912 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
4913 count += 5;
4914 header = 0;
4917 if (type == bgp_show_type_dampend_paths
4918 || type == bgp_show_type_damp_neighbor)
4919 count += damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4920 else if (type == bgp_show_type_flap_statistics
4921 || type == bgp_show_type_flap_address
4922 || type == bgp_show_type_flap_prefix
4923 || type == bgp_show_type_flap_cidr_only
4924 || type == bgp_show_type_flap_regexp
4925 || type == bgp_show_type_flap_filter_list
4926 || type == bgp_show_type_flap_prefix_list
4927 || type == bgp_show_type_flap_prefix_longer
4928 || type == bgp_show_type_flap_route_map
4929 || type == bgp_show_type_flap_neighbor)
4930 count += flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4931 else
4932 count += route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4933 display++;
4935 if (display)
4936 vty->output_count++;
4938 /* Remember current pointer then suspend output. */
4939 if (count >= limit && vty->type != VTY_SHELL_SERV)
4941 vty->status = VTY_START;
4942 vty->output_rn = bgp_route_next (rn);
4943 vty->output_func = bgp_show_callback;
4944 vty->output_type = type;
4946 return CMD_SUCCESS;
4950 /* No route is displayed */
4951 if (vty->output_count == 0)
4953 if (type == bgp_show_type_normal)
4954 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
4956 else
4957 vty_out (vty, "%sTotal number of prefixes %ld%s",
4958 VTY_NEWLINE, vty->output_count, VTY_NEWLINE);
4960 /* Clean up allocated resources. */
4961 if (vty->output_clean)
4962 (*vty->output_clean) (vty);
4964 vty->status = VTY_START;
4965 vty->output_rn = NULL;
4966 vty->output_func = NULL;
4967 vty->output_clean = NULL;
4968 vty->output_arg = NULL;
4970 return CMD_SUCCESS;
4973 /* Header of detailed BGP route information */
4974 void
4975 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
4976 struct bgp_node *rn,
4977 struct prefix_rd *prd, afi_t afi, safi_t safi)
4979 struct bgp_info *ri;
4980 struct prefix *p;
4981 struct peer *peer;
4982 struct listnode *nn;
4983 char buf1[INET6_ADDRSTRLEN];
4984 char buf2[INET6_ADDRSTRLEN];
4985 int count = 0;
4986 int best = 0;
4987 int suppress = 0;
4988 int no_export = 0;
4989 int no_advertise = 0;
4990 int local_as = 0;
4991 int first = 0;
4993 p = &rn->p;
4994 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
4995 (safi == SAFI_MPLS_VPN ?
4996 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
4997 safi == SAFI_MPLS_VPN ? ":" : "",
4998 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
4999 p->prefixlen, VTY_NEWLINE);
5001 for (ri = rn->info; ri; ri = ri->next)
5003 count++;
5004 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5006 best = count;
5007 if (ri->suppress)
5008 suppress = 1;
5009 if (ri->attr->community != NULL)
5011 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5012 no_advertise = 1;
5013 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5014 no_export = 1;
5015 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5016 local_as = 1;
5021 vty_out (vty, "Paths: (%d available", count);
5022 if (best)
5024 vty_out (vty, ", best #%d", best);
5025 if (safi == SAFI_UNICAST)
5026 vty_out (vty, ", table Default-IP-Routing-Table");
5028 else
5029 vty_out (vty, ", no best path");
5030 if (no_advertise)
5031 vty_out (vty, ", not advertised to any peer");
5032 else if (no_export)
5033 vty_out (vty, ", not advertised to EBGP peer");
5034 else if (local_as)
5035 vty_out (vty, ", not advertised outside local AS");
5036 if (suppress)
5037 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5038 vty_out (vty, ")%s", VTY_NEWLINE);
5040 /* advertised peer */
5041 LIST_LOOP (bgp->peer, peer, nn)
5043 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5045 if (! first)
5046 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5047 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5048 first = 1;
5051 if (! first)
5052 vty_out (vty, " Not advertised to any peer");
5053 vty_out (vty, "%s", VTY_NEWLINE);
5056 /* Display specified route of BGP table. */
5058 bgp_show_route (struct vty *vty, char *view_name, char *ip_str,
5059 afi_t afi, safi_t safi, struct prefix_rd *prd,
5060 int prefix_check)
5062 int ret;
5063 int header;
5064 int display = 0;
5065 struct prefix match;
5066 struct bgp_node *rn;
5067 struct bgp_node *rm;
5068 struct bgp_info *ri;
5069 struct bgp *bgp;
5070 struct bgp_table *table;
5072 /* BGP structure lookup. */
5073 if (view_name)
5075 bgp = bgp_lookup_by_name (view_name);
5076 if (bgp == NULL)
5078 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
5079 return CMD_WARNING;
5082 else
5084 bgp = bgp_get_default ();
5085 if (bgp == NULL)
5087 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5088 return CMD_WARNING;
5092 /* Check IP address argument. */
5093 ret = str2prefix (ip_str, &match);
5094 if (! ret)
5096 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5097 return CMD_WARNING;
5100 match.family = afi2family (afi);
5102 if (safi == SAFI_MPLS_VPN)
5104 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
5106 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5107 continue;
5109 if ((table = rn->info) != NULL)
5111 header = 1;
5113 if ((rm = bgp_node_match (table, &match)) != NULL)
5115 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5116 continue;
5118 for (ri = rm->info; ri; ri = ri->next)
5120 if (header)
5122 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5123 AFI_IP, SAFI_MPLS_VPN);
5125 header = 0;
5127 display++;
5128 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5134 else
5136 header = 1;
5138 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
5140 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5142 for (ri = rn->info; ri; ri = ri->next)
5144 if (header)
5146 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5147 header = 0;
5149 display++;
5150 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5156 if (! display)
5158 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5159 return CMD_WARNING;
5162 return CMD_SUCCESS;
5165 /* BGP route print out function. */
5166 DEFUN (show_ip_bgp,
5167 show_ip_bgp_cmd,
5168 "show ip bgp",
5169 SHOW_STR
5170 IP_STR
5171 BGP_STR)
5173 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
5176 DEFUN (show_ip_bgp_ipv4,
5177 show_ip_bgp_ipv4_cmd,
5178 "show ip bgp ipv4 (unicast|multicast)",
5179 SHOW_STR
5180 IP_STR
5181 BGP_STR
5182 "Address family\n"
5183 "Address Family modifier\n"
5184 "Address Family modifier\n")
5186 if (strncmp (argv[0], "m", 1) == 0)
5187 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal);
5189 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
5192 DEFUN (show_ip_bgp_route,
5193 show_ip_bgp_route_cmd,
5194 "show ip bgp A.B.C.D",
5195 SHOW_STR
5196 IP_STR
5197 BGP_STR
5198 "Network in the BGP routing table to display\n")
5200 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
5203 DEFUN (show_ip_bgp_ipv4_route,
5204 show_ip_bgp_ipv4_route_cmd,
5205 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
5206 SHOW_STR
5207 IP_STR
5208 BGP_STR
5209 "Address family\n"
5210 "Address Family modifier\n"
5211 "Address Family modifier\n"
5212 "Network in the BGP routing table to display\n")
5214 if (strncmp (argv[0], "m", 1) == 0)
5215 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
5217 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
5220 DEFUN (show_ip_bgp_vpnv4_all_route,
5221 show_ip_bgp_vpnv4_all_route_cmd,
5222 "show ip bgp vpnv4 all A.B.C.D",
5223 SHOW_STR
5224 IP_STR
5225 BGP_STR
5226 "Display VPNv4 NLRI specific information\n"
5227 "Display information about all VPNv4 NLRIs\n"
5228 "Network in the BGP routing table to display\n")
5230 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
5233 DEFUN (show_ip_bgp_vpnv4_rd_route,
5234 show_ip_bgp_vpnv4_rd_route_cmd,
5235 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
5236 SHOW_STR
5237 IP_STR
5238 BGP_STR
5239 "Display VPNv4 NLRI specific information\n"
5240 "Display information for a route distinguisher\n"
5241 "VPN Route Distinguisher\n"
5242 "Network in the BGP routing table to display\n")
5244 int ret;
5245 struct prefix_rd prd;
5247 ret = str2prefix_rd (argv[0], &prd);
5248 if (! ret)
5250 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
5251 return CMD_WARNING;
5253 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
5256 DEFUN (show_ip_bgp_prefix,
5257 show_ip_bgp_prefix_cmd,
5258 "show ip bgp A.B.C.D/M",
5259 SHOW_STR
5260 IP_STR
5261 BGP_STR
5262 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5264 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
5267 DEFUN (show_ip_bgp_ipv4_prefix,
5268 show_ip_bgp_ipv4_prefix_cmd,
5269 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
5270 SHOW_STR
5271 IP_STR
5272 BGP_STR
5273 "Address family\n"
5274 "Address Family modifier\n"
5275 "Address Family modifier\n"
5276 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5278 if (strncmp (argv[0], "m", 1) == 0)
5279 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
5281 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
5284 DEFUN (show_ip_bgp_vpnv4_all_prefix,
5285 show_ip_bgp_vpnv4_all_prefix_cmd,
5286 "show ip bgp vpnv4 all A.B.C.D/M",
5287 SHOW_STR
5288 IP_STR
5289 BGP_STR
5290 "Display VPNv4 NLRI specific information\n"
5291 "Display information about all VPNv4 NLRIs\n"
5292 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5294 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
5297 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
5298 show_ip_bgp_vpnv4_rd_prefix_cmd,
5299 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
5300 SHOW_STR
5301 IP_STR
5302 BGP_STR
5303 "Display VPNv4 NLRI specific information\n"
5304 "Display information for a route distinguisher\n"
5305 "VPN Route Distinguisher\n"
5306 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5308 int ret;
5309 struct prefix_rd prd;
5311 ret = str2prefix_rd (argv[0], &prd);
5312 if (! ret)
5314 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
5315 return CMD_WARNING;
5317 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
5320 DEFUN (show_ip_bgp_view,
5321 show_ip_bgp_view_cmd,
5322 "show ip bgp view WORD",
5323 SHOW_STR
5324 IP_STR
5325 BGP_STR
5326 "BGP view\n"
5327 "BGP view name\n")
5329 return bgp_show (vty, argv[0], AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
5332 DEFUN (show_ip_bgp_view_route,
5333 show_ip_bgp_view_route_cmd,
5334 "show ip bgp view WORD A.B.C.D",
5335 SHOW_STR
5336 IP_STR
5337 BGP_STR
5338 "BGP view\n"
5339 "BGP view name\n"
5340 "Network in the BGP routing table to display\n")
5342 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
5345 DEFUN (show_ip_bgp_view_prefix,
5346 show_ip_bgp_view_prefix_cmd,
5347 "show ip bgp view WORD A.B.C.D/M",
5348 SHOW_STR
5349 IP_STR
5350 BGP_STR
5351 "BGP view\n"
5352 "BGP view name\n"
5353 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5355 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
5358 #ifdef HAVE_IPV6
5359 DEFUN (show_bgp,
5360 show_bgp_cmd,
5361 "show bgp",
5362 SHOW_STR
5363 BGP_STR)
5365 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
5368 ALIAS (show_bgp,
5369 show_bgp_ipv6_cmd,
5370 "show bgp ipv6",
5371 SHOW_STR
5372 BGP_STR
5373 "Address family\n");
5375 /* old command */
5376 DEFUN (show_ipv6_bgp,
5377 show_ipv6_bgp_cmd,
5378 "show ipv6 bgp",
5379 SHOW_STR
5380 IP_STR
5381 BGP_STR)
5383 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
5386 DEFUN (show_bgp_route,
5387 show_bgp_route_cmd,
5388 "show bgp X:X::X:X",
5389 SHOW_STR
5390 BGP_STR
5391 "Network in the BGP routing table to display\n")
5393 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
5396 ALIAS (show_bgp_route,
5397 show_bgp_ipv6_route_cmd,
5398 "show bgp ipv6 X:X::X:X",
5399 SHOW_STR
5400 BGP_STR
5401 "Address family\n"
5402 "Network in the BGP routing table to display\n");
5404 /* old command */
5405 DEFUN (show_ipv6_bgp_route,
5406 show_ipv6_bgp_route_cmd,
5407 "show ipv6 bgp X:X::X:X",
5408 SHOW_STR
5409 IP_STR
5410 BGP_STR
5411 "Network in the BGP routing table to display\n")
5413 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
5416 DEFUN (show_bgp_prefix,
5417 show_bgp_prefix_cmd,
5418 "show bgp X:X::X:X/M",
5419 SHOW_STR
5420 BGP_STR
5421 "IPv6 prefix <network>/<length>\n")
5423 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
5426 ALIAS (show_bgp_prefix,
5427 show_bgp_ipv6_prefix_cmd,
5428 "show bgp ipv6 X:X::X:X/M",
5429 SHOW_STR
5430 BGP_STR
5431 "Address family\n"
5432 "IPv6 prefix <network>/<length>\n");
5434 /* old command */
5435 DEFUN (show_ipv6_bgp_prefix,
5436 show_ipv6_bgp_prefix_cmd,
5437 "show ipv6 bgp X:X::X:X/M",
5438 SHOW_STR
5439 IP_STR
5440 BGP_STR
5441 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5443 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
5446 /* old command */
5447 DEFUN (show_ipv6_mbgp,
5448 show_ipv6_mbgp_cmd,
5449 "show ipv6 mbgp",
5450 SHOW_STR
5451 IP_STR
5452 MBGP_STR)
5454 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal);
5457 /* old command */
5458 DEFUN (show_ipv6_mbgp_route,
5459 show_ipv6_mbgp_route_cmd,
5460 "show ipv6 mbgp X:X::X:X",
5461 SHOW_STR
5462 IP_STR
5463 MBGP_STR
5464 "Network in the MBGP routing table to display\n")
5466 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
5469 /* old command */
5470 DEFUN (show_ipv6_mbgp_prefix,
5471 show_ipv6_mbgp_prefix_cmd,
5472 "show ipv6 mbgp X:X::X:X/M",
5473 SHOW_STR
5474 IP_STR
5475 MBGP_STR
5476 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5478 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
5480 #endif
5482 void
5483 bgp_show_regexp_clean (struct vty *vty)
5485 bgp_regex_free (vty->output_arg);
5489 bgp_show_regexp (struct vty *vty, int argc, char **argv, afi_t afi,
5490 safi_t safi, enum bgp_show_type type)
5492 int i;
5493 struct buffer *b;
5494 char *regstr;
5495 int first;
5496 regex_t *regex;
5498 first = 0;
5499 b = buffer_new (1024);
5500 for (i = 0; i < argc; i++)
5502 if (first)
5503 buffer_putc (b, ' ');
5504 else
5506 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
5507 continue;
5508 first = 1;
5511 buffer_putstr (b, argv[i]);
5513 buffer_putc (b, '\0');
5515 regstr = buffer_getstr (b);
5516 buffer_free (b);
5518 regex = bgp_regcomp (regstr);
5519 if (! regex)
5521 vty_out (vty, "Can't compile regexp %s%s", argv[0],
5522 VTY_NEWLINE);
5523 return CMD_WARNING;
5526 vty->output_arg = regex;
5527 vty->output_clean = bgp_show_regexp_clean;
5529 return bgp_show (vty, NULL, afi, safi, type);
5532 DEFUN (show_ip_bgp_regexp,
5533 show_ip_bgp_regexp_cmd,
5534 "show ip bgp regexp .LINE",
5535 SHOW_STR
5536 IP_STR
5537 BGP_STR
5538 "Display routes matching the AS path regular expression\n"
5539 "A regular-expression to match the BGP AS paths\n")
5541 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
5542 bgp_show_type_regexp);
5545 DEFUN (show_ip_bgp_flap_regexp,
5546 show_ip_bgp_flap_regexp_cmd,
5547 "show ip bgp flap-statistics regexp .LINE",
5548 SHOW_STR
5549 IP_STR
5550 BGP_STR
5551 "Display flap statistics of routes\n"
5552 "Display routes matching the AS path regular expression\n"
5553 "A regular-expression to match the BGP AS paths\n")
5555 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
5556 bgp_show_type_flap_regexp);
5559 DEFUN (show_ip_bgp_ipv4_regexp,
5560 show_ip_bgp_ipv4_regexp_cmd,
5561 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
5562 SHOW_STR
5563 IP_STR
5564 BGP_STR
5565 "Address family\n"
5566 "Address Family modifier\n"
5567 "Address Family modifier\n"
5568 "Display routes matching the AS path regular expression\n"
5569 "A regular-expression to match the BGP AS paths\n")
5571 if (strncmp (argv[0], "m", 1) == 0)
5572 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
5573 bgp_show_type_regexp);
5575 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
5576 bgp_show_type_regexp);
5579 #ifdef HAVE_IPV6
5580 DEFUN (show_bgp_regexp,
5581 show_bgp_regexp_cmd,
5582 "show bgp regexp .LINE",
5583 SHOW_STR
5584 BGP_STR
5585 "Display routes matching the AS path regular expression\n"
5586 "A regular-expression to match the BGP AS paths\n")
5588 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
5589 bgp_show_type_regexp);
5592 ALIAS (show_bgp_regexp,
5593 show_bgp_ipv6_regexp_cmd,
5594 "show bgp ipv6 regexp .LINE",
5595 SHOW_STR
5596 BGP_STR
5597 "Address family\n"
5598 "Display routes matching the AS path regular expression\n"
5599 "A regular-expression to match the BGP AS paths\n");
5601 /* old command */
5602 DEFUN (show_ipv6_bgp_regexp,
5603 show_ipv6_bgp_regexp_cmd,
5604 "show ipv6 bgp regexp .LINE",
5605 SHOW_STR
5606 IP_STR
5607 BGP_STR
5608 "Display routes matching the AS path regular expression\n"
5609 "A regular-expression to match the BGP AS paths\n")
5611 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
5612 bgp_show_type_regexp);
5615 /* old command */
5616 DEFUN (show_ipv6_mbgp_regexp,
5617 show_ipv6_mbgp_regexp_cmd,
5618 "show ipv6 mbgp regexp .LINE",
5619 SHOW_STR
5620 IP_STR
5621 BGP_STR
5622 "Display routes matching the AS path regular expression\n"
5623 "A regular-expression to match the MBGP AS paths\n")
5625 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
5626 bgp_show_type_regexp);
5628 #endif /* HAVE_IPV6 */
5631 bgp_show_prefix_list (struct vty *vty, char *prefix_list_str, afi_t afi,
5632 safi_t safi, enum bgp_show_type type)
5634 struct prefix_list *plist;
5636 plist = prefix_list_lookup (afi, prefix_list_str);
5637 if (plist == NULL)
5639 vty_out (vty, "%% %s is not a valid prefix-list name%s",
5640 prefix_list_str, VTY_NEWLINE);
5641 return CMD_WARNING;
5644 vty->output_arg = plist;
5646 return bgp_show (vty, NULL, afi, safi, type);
5649 DEFUN (show_ip_bgp_prefix_list,
5650 show_ip_bgp_prefix_list_cmd,
5651 "show ip bgp prefix-list WORD",
5652 SHOW_STR
5653 IP_STR
5654 BGP_STR
5655 "Display routes conforming to the prefix-list\n"
5656 "IP prefix-list name\n")
5658 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5659 bgp_show_type_prefix_list);
5662 DEFUN (show_ip_bgp_flap_prefix_list,
5663 show_ip_bgp_flap_prefix_list_cmd,
5664 "show ip bgp flap-statistics prefix-list WORD",
5665 SHOW_STR
5666 IP_STR
5667 BGP_STR
5668 "Display flap statistics of routes\n"
5669 "Display routes conforming to the prefix-list\n"
5670 "IP prefix-list name\n")
5672 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5673 bgp_show_type_flap_prefix_list);
5676 DEFUN (show_ip_bgp_ipv4_prefix_list,
5677 show_ip_bgp_ipv4_prefix_list_cmd,
5678 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
5679 SHOW_STR
5680 IP_STR
5681 BGP_STR
5682 "Address family\n"
5683 "Address Family modifier\n"
5684 "Address Family modifier\n"
5685 "Display routes conforming to the prefix-list\n"
5686 "IP prefix-list name\n")
5688 if (strncmp (argv[0], "m", 1) == 0)
5689 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
5690 bgp_show_type_prefix_list);
5692 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
5693 bgp_show_type_prefix_list);
5696 #ifdef HAVE_IPV6
5697 DEFUN (show_bgp_prefix_list,
5698 show_bgp_prefix_list_cmd,
5699 "show bgp prefix-list WORD",
5700 SHOW_STR
5701 BGP_STR
5702 "Display routes conforming to the prefix-list\n"
5703 "IPv6 prefix-list name\n")
5705 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5706 bgp_show_type_prefix_list);
5709 ALIAS (show_bgp_prefix_list,
5710 show_bgp_ipv6_prefix_list_cmd,
5711 "show bgp ipv6 prefix-list WORD",
5712 SHOW_STR
5713 BGP_STR
5714 "Address family\n"
5715 "Display routes conforming to the prefix-list\n"
5716 "IPv6 prefix-list name\n");
5718 /* old command */
5719 DEFUN (show_ipv6_bgp_prefix_list,
5720 show_ipv6_bgp_prefix_list_cmd,
5721 "show ipv6 bgp prefix-list WORD",
5722 SHOW_STR
5723 IPV6_STR
5724 BGP_STR
5725 "Display routes matching the prefix-list\n"
5726 "IPv6 prefix-list name\n")
5728 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5729 bgp_show_type_prefix_list);
5732 /* old command */
5733 DEFUN (show_ipv6_mbgp_prefix_list,
5734 show_ipv6_mbgp_prefix_list_cmd,
5735 "show ipv6 mbgp prefix-list WORD",
5736 SHOW_STR
5737 IPV6_STR
5738 MBGP_STR
5739 "Display routes matching the prefix-list\n"
5740 "IPv6 prefix-list name\n")
5742 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
5743 bgp_show_type_prefix_list);
5745 #endif /* HAVE_IPV6 */
5748 bgp_show_filter_list (struct vty *vty, char *filter, afi_t afi,
5749 safi_t safi, enum bgp_show_type type)
5751 struct as_list *as_list;
5753 as_list = as_list_lookup (filter);
5754 if (as_list == NULL)
5756 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
5757 return CMD_WARNING;
5760 vty->output_arg = as_list;
5762 return bgp_show (vty, NULL, afi, safi, type);
5765 DEFUN (show_ip_bgp_filter_list,
5766 show_ip_bgp_filter_list_cmd,
5767 "show ip bgp filter-list WORD",
5768 SHOW_STR
5769 IP_STR
5770 BGP_STR
5771 "Display routes conforming to the filter-list\n"
5772 "Regular expression access list name\n")
5774 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5775 bgp_show_type_filter_list);
5778 DEFUN (show_ip_bgp_flap_filter_list,
5779 show_ip_bgp_flap_filter_list_cmd,
5780 "show ip bgp flap-statistics filter-list WORD",
5781 SHOW_STR
5782 IP_STR
5783 BGP_STR
5784 "Display flap statistics of routes\n"
5785 "Display routes conforming to the filter-list\n"
5786 "Regular expression access list name\n")
5788 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5789 bgp_show_type_flap_filter_list);
5792 DEFUN (show_ip_bgp_ipv4_filter_list,
5793 show_ip_bgp_ipv4_filter_list_cmd,
5794 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
5795 SHOW_STR
5796 IP_STR
5797 BGP_STR
5798 "Address family\n"
5799 "Address Family modifier\n"
5800 "Address Family modifier\n"
5801 "Display routes conforming to the filter-list\n"
5802 "Regular expression access list name\n")
5804 if (strncmp (argv[0], "m", 1) == 0)
5805 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
5806 bgp_show_type_filter_list);
5808 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
5809 bgp_show_type_filter_list);
5812 #ifdef HAVE_IPV6
5813 DEFUN (show_bgp_filter_list,
5814 show_bgp_filter_list_cmd,
5815 "show bgp filter-list WORD",
5816 SHOW_STR
5817 BGP_STR
5818 "Display routes conforming to the filter-list\n"
5819 "Regular expression access list name\n")
5821 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5822 bgp_show_type_filter_list);
5825 ALIAS (show_bgp_filter_list,
5826 show_bgp_ipv6_filter_list_cmd,
5827 "show bgp ipv6 filter-list WORD",
5828 SHOW_STR
5829 BGP_STR
5830 "Address family\n"
5831 "Display routes conforming to the filter-list\n"
5832 "Regular expression access list name\n");
5834 /* old command */
5835 DEFUN (show_ipv6_bgp_filter_list,
5836 show_ipv6_bgp_filter_list_cmd,
5837 "show ipv6 bgp filter-list WORD",
5838 SHOW_STR
5839 IPV6_STR
5840 BGP_STR
5841 "Display routes conforming to the filter-list\n"
5842 "Regular expression access list name\n")
5844 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5845 bgp_show_type_filter_list);
5848 /* old command */
5849 DEFUN (show_ipv6_mbgp_filter_list,
5850 show_ipv6_mbgp_filter_list_cmd,
5851 "show ipv6 mbgp filter-list WORD",
5852 SHOW_STR
5853 IPV6_STR
5854 MBGP_STR
5855 "Display routes conforming to the filter-list\n"
5856 "Regular expression access list name\n")
5858 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
5859 bgp_show_type_filter_list);
5861 #endif /* HAVE_IPV6 */
5864 bgp_show_route_map (struct vty *vty, char *rmap_str, afi_t afi,
5865 safi_t safi, enum bgp_show_type type)
5867 struct route_map *rmap;
5869 rmap = route_map_lookup_by_name (rmap_str);
5870 if (! rmap)
5872 vty_out (vty, "%% %s is not a valid route-map name%s",
5873 rmap_str, VTY_NEWLINE);
5874 return CMD_WARNING;
5877 vty->output_arg = rmap;
5879 return bgp_show (vty, NULL, afi, safi, type);
5882 DEFUN (show_ip_bgp_route_map,
5883 show_ip_bgp_route_map_cmd,
5884 "show ip bgp route-map WORD",
5885 SHOW_STR
5886 IP_STR
5887 BGP_STR
5888 "Display routes matching the route-map\n"
5889 "A route-map to match on\n")
5891 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
5892 bgp_show_type_route_map);
5895 DEFUN (show_ip_bgp_flap_route_map,
5896 show_ip_bgp_flap_route_map_cmd,
5897 "show ip bgp flap-statistics route-map WORD",
5898 SHOW_STR
5899 IP_STR
5900 BGP_STR
5901 "Display flap statistics of routes\n"
5902 "Display routes matching the route-map\n"
5903 "A route-map to match on\n")
5905 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
5906 bgp_show_type_flap_route_map);
5909 DEFUN (show_ip_bgp_ipv4_route_map,
5910 show_ip_bgp_ipv4_route_map_cmd,
5911 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
5912 SHOW_STR
5913 IP_STR
5914 BGP_STR
5915 "Address family\n"
5916 "Address Family modifier\n"
5917 "Address Family modifier\n"
5918 "Display routes matching the route-map\n"
5919 "A route-map to match on\n")
5921 if (strncmp (argv[0], "m", 1) == 0)
5922 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
5923 bgp_show_type_route_map);
5925 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
5926 bgp_show_type_route_map);
5929 DEFUN (show_bgp_route_map,
5930 show_bgp_route_map_cmd,
5931 "show bgp route-map WORD",
5932 SHOW_STR
5933 BGP_STR
5934 "Display routes matching the route-map\n"
5935 "A route-map to match on\n")
5937 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5938 bgp_show_type_route_map);
5941 ALIAS (show_bgp_route_map,
5942 show_bgp_ipv6_route_map_cmd,
5943 "show bgp ipv6 route-map WORD",
5944 SHOW_STR
5945 BGP_STR
5946 "Address family\n"
5947 "Display routes matching the route-map\n"
5948 "A route-map to match on\n");
5950 DEFUN (show_ip_bgp_cidr_only,
5951 show_ip_bgp_cidr_only_cmd,
5952 "show ip bgp cidr-only",
5953 SHOW_STR
5954 IP_STR
5955 BGP_STR
5956 "Display only routes with non-natural netmasks\n")
5958 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5959 bgp_show_type_cidr_only);
5962 DEFUN (show_ip_bgp_flap_cidr_only,
5963 show_ip_bgp_flap_cidr_only_cmd,
5964 "show ip bgp flap-statistics cidr-only",
5965 SHOW_STR
5966 IP_STR
5967 BGP_STR
5968 "Display flap statistics of routes\n"
5969 "Display only routes with non-natural netmasks\n")
5971 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5972 bgp_show_type_flap_cidr_only);
5975 DEFUN (show_ip_bgp_ipv4_cidr_only,
5976 show_ip_bgp_ipv4_cidr_only_cmd,
5977 "show ip bgp ipv4 (unicast|multicast) cidr-only",
5978 SHOW_STR
5979 IP_STR
5980 BGP_STR
5981 "Address family\n"
5982 "Address Family modifier\n"
5983 "Address Family modifier\n"
5984 "Display only routes with non-natural netmasks\n")
5986 if (strncmp (argv[0], "m", 1) == 0)
5987 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
5988 bgp_show_type_cidr_only);
5990 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5991 bgp_show_type_cidr_only);
5994 DEFUN (show_ip_bgp_community_all,
5995 show_ip_bgp_community_all_cmd,
5996 "show ip bgp community",
5997 SHOW_STR
5998 IP_STR
5999 BGP_STR
6000 "Display routes matching the communities\n")
6002 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6003 bgp_show_type_community_all);
6006 DEFUN (show_ip_bgp_ipv4_community_all,
6007 show_ip_bgp_ipv4_community_all_cmd,
6008 "show ip bgp ipv4 (unicast|multicast) community",
6009 SHOW_STR
6010 IP_STR
6011 BGP_STR
6012 "Address family\n"
6013 "Address Family modifier\n"
6014 "Address Family modifier\n"
6015 "Display routes matching the communities\n")
6017 if (strncmp (argv[0], "m", 1) == 0)
6018 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
6019 bgp_show_type_community_all);
6021 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6022 bgp_show_type_community_all);
6025 #ifdef HAVE_IPV6
6026 DEFUN (show_bgp_community_all,
6027 show_bgp_community_all_cmd,
6028 "show bgp community",
6029 SHOW_STR
6030 BGP_STR
6031 "Display routes matching the communities\n")
6033 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
6034 bgp_show_type_community_all);
6037 ALIAS (show_bgp_community_all,
6038 show_bgp_ipv6_community_all_cmd,
6039 "show bgp ipv6 community",
6040 SHOW_STR
6041 BGP_STR
6042 "Address family\n"
6043 "Display routes matching the communities\n");
6045 /* old command */
6046 DEFUN (show_ipv6_bgp_community_all,
6047 show_ipv6_bgp_community_all_cmd,
6048 "show ipv6 bgp community",
6049 SHOW_STR
6050 IPV6_STR
6051 BGP_STR
6052 "Display routes matching the communities\n")
6054 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
6055 bgp_show_type_community_all);
6058 /* old command */
6059 DEFUN (show_ipv6_mbgp_community_all,
6060 show_ipv6_mbgp_community_all_cmd,
6061 "show ipv6 mbgp community",
6062 SHOW_STR
6063 IPV6_STR
6064 MBGP_STR
6065 "Display routes matching the communities\n")
6067 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
6068 bgp_show_type_community_all);
6070 #endif /* HAVE_IPV6 */
6073 bgp_show_community (struct vty *vty, int argc, char **argv, int exact,
6074 u_int16_t afi, u_char safi)
6076 struct community *com;
6077 struct buffer *b;
6078 int i;
6079 char *str;
6080 int first = 0;
6082 b = buffer_new (1024);
6083 for (i = 0; i < argc; i++)
6085 if (first)
6086 buffer_putc (b, ' ');
6087 else
6089 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6090 continue;
6091 first = 1;
6094 buffer_putstr (b, argv[i]);
6096 buffer_putc (b, '\0');
6098 str = buffer_getstr (b);
6099 buffer_free (b);
6101 com = community_str2com (str);
6102 free (str);
6103 if (! com)
6105 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
6106 return CMD_WARNING;
6109 vty->output_arg = com;
6111 if (exact)
6112 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_exact);
6114 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community);
6117 DEFUN (show_ip_bgp_community,
6118 show_ip_bgp_community_cmd,
6119 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
6120 SHOW_STR
6121 IP_STR
6122 BGP_STR
6123 "Display routes matching the communities\n"
6124 "community number\n"
6125 "Do not send outside local AS (well-known community)\n"
6126 "Do not advertise to any peer (well-known community)\n"
6127 "Do not export to next AS (well-known community)\n")
6129 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
6132 ALIAS (show_ip_bgp_community,
6133 show_ip_bgp_community2_cmd,
6134 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6135 SHOW_STR
6136 IP_STR
6137 BGP_STR
6138 "Display routes matching the communities\n"
6139 "community number\n"
6140 "Do not send outside local AS (well-known community)\n"
6141 "Do not advertise to any peer (well-known community)\n"
6142 "Do not export to next AS (well-known community)\n"
6143 "community number\n"
6144 "Do not send outside local AS (well-known community)\n"
6145 "Do not advertise to any peer (well-known community)\n"
6146 "Do not export to next AS (well-known community)\n");
6148 ALIAS (show_ip_bgp_community,
6149 show_ip_bgp_community3_cmd,
6150 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6151 SHOW_STR
6152 IP_STR
6153 BGP_STR
6154 "Display routes matching the communities\n"
6155 "community number\n"
6156 "Do not send outside local AS (well-known community)\n"
6157 "Do not advertise to any peer (well-known community)\n"
6158 "Do not export to next AS (well-known community)\n"
6159 "community number\n"
6160 "Do not send outside local AS (well-known community)\n"
6161 "Do not advertise to any peer (well-known community)\n"
6162 "Do not export to next AS (well-known community)\n"
6163 "community number\n"
6164 "Do not send outside local AS (well-known community)\n"
6165 "Do not advertise to any peer (well-known community)\n"
6166 "Do not export to next AS (well-known community)\n");
6168 ALIAS (show_ip_bgp_community,
6169 show_ip_bgp_community4_cmd,
6170 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6171 SHOW_STR
6172 IP_STR
6173 BGP_STR
6174 "Display routes matching the communities\n"
6175 "community number\n"
6176 "Do not send outside local AS (well-known community)\n"
6177 "Do not advertise to any peer (well-known community)\n"
6178 "Do not export to next AS (well-known community)\n"
6179 "community number\n"
6180 "Do not send outside local AS (well-known community)\n"
6181 "Do not advertise to any peer (well-known community)\n"
6182 "Do not export to next AS (well-known community)\n"
6183 "community number\n"
6184 "Do not send outside local AS (well-known community)\n"
6185 "Do not advertise to any peer (well-known community)\n"
6186 "Do not export to next AS (well-known community)\n"
6187 "community number\n"
6188 "Do not send outside local AS (well-known community)\n"
6189 "Do not advertise to any peer (well-known community)\n"
6190 "Do not export to next AS (well-known community)\n");
6192 DEFUN (show_ip_bgp_ipv4_community,
6193 show_ip_bgp_ipv4_community_cmd,
6194 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
6195 SHOW_STR
6196 IP_STR
6197 BGP_STR
6198 "Address family\n"
6199 "Address Family modifier\n"
6200 "Address Family modifier\n"
6201 "Display routes matching the communities\n"
6202 "community number\n"
6203 "Do not send outside local AS (well-known community)\n"
6204 "Do not advertise to any peer (well-known community)\n"
6205 "Do not export to next AS (well-known community)\n")
6207 if (strncmp (argv[0], "m", 1) == 0)
6208 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
6210 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
6213 ALIAS (show_ip_bgp_ipv4_community,
6214 show_ip_bgp_ipv4_community2_cmd,
6215 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6216 SHOW_STR
6217 IP_STR
6218 BGP_STR
6219 "Address family\n"
6220 "Address Family modifier\n"
6221 "Address Family modifier\n"
6222 "Display routes matching the communities\n"
6223 "community number\n"
6224 "Do not send outside local AS (well-known community)\n"
6225 "Do not advertise to any peer (well-known community)\n"
6226 "Do not export to next AS (well-known community)\n"
6227 "community number\n"
6228 "Do not send outside local AS (well-known community)\n"
6229 "Do not advertise to any peer (well-known community)\n"
6230 "Do not export to next AS (well-known community)\n");
6232 ALIAS (show_ip_bgp_ipv4_community,
6233 show_ip_bgp_ipv4_community3_cmd,
6234 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6235 SHOW_STR
6236 IP_STR
6237 BGP_STR
6238 "Address family\n"
6239 "Address Family modifier\n"
6240 "Address Family modifier\n"
6241 "Display routes matching the communities\n"
6242 "community number\n"
6243 "Do not send outside local AS (well-known community)\n"
6244 "Do not advertise to any peer (well-known community)\n"
6245 "Do not export to next AS (well-known community)\n"
6246 "community number\n"
6247 "Do not send outside local AS (well-known community)\n"
6248 "Do not advertise to any peer (well-known community)\n"
6249 "Do not export to next AS (well-known community)\n"
6250 "community number\n"
6251 "Do not send outside local AS (well-known community)\n"
6252 "Do not advertise to any peer (well-known community)\n"
6253 "Do not export to next AS (well-known community)\n");
6255 ALIAS (show_ip_bgp_ipv4_community,
6256 show_ip_bgp_ipv4_community4_cmd,
6257 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6258 SHOW_STR
6259 IP_STR
6260 BGP_STR
6261 "Address family\n"
6262 "Address Family modifier\n"
6263 "Address Family modifier\n"
6264 "Display routes matching the communities\n"
6265 "community number\n"
6266 "Do not send outside local AS (well-known community)\n"
6267 "Do not advertise to any peer (well-known community)\n"
6268 "Do not export to next AS (well-known community)\n"
6269 "community number\n"
6270 "Do not send outside local AS (well-known community)\n"
6271 "Do not advertise to any peer (well-known community)\n"
6272 "Do not export to next AS (well-known community)\n"
6273 "community number\n"
6274 "Do not send outside local AS (well-known community)\n"
6275 "Do not advertise to any peer (well-known community)\n"
6276 "Do not export to next AS (well-known community)\n"
6277 "community number\n"
6278 "Do not send outside local AS (well-known community)\n"
6279 "Do not advertise to any peer (well-known community)\n"
6280 "Do not export to next AS (well-known community)\n");
6282 DEFUN (show_ip_bgp_community_exact,
6283 show_ip_bgp_community_exact_cmd,
6284 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6285 SHOW_STR
6286 IP_STR
6287 BGP_STR
6288 "Display routes matching the communities\n"
6289 "community number\n"
6290 "Do not send outside local AS (well-known community)\n"
6291 "Do not advertise to any peer (well-known community)\n"
6292 "Do not export to next AS (well-known community)\n"
6293 "Exact match of the communities")
6295 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
6298 ALIAS (show_ip_bgp_community_exact,
6299 show_ip_bgp_community2_exact_cmd,
6300 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6301 SHOW_STR
6302 IP_STR
6303 BGP_STR
6304 "Display routes matching the communities\n"
6305 "community number\n"
6306 "Do not send outside local AS (well-known community)\n"
6307 "Do not advertise to any peer (well-known community)\n"
6308 "Do not export to next AS (well-known community)\n"
6309 "community number\n"
6310 "Do not send outside local AS (well-known community)\n"
6311 "Do not advertise to any peer (well-known community)\n"
6312 "Do not export to next AS (well-known community)\n"
6313 "Exact match of the communities");
6315 ALIAS (show_ip_bgp_community_exact,
6316 show_ip_bgp_community3_exact_cmd,
6317 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6318 SHOW_STR
6319 IP_STR
6320 BGP_STR
6321 "Display routes matching the communities\n"
6322 "community number\n"
6323 "Do not send outside local AS (well-known community)\n"
6324 "Do not advertise to any peer (well-known community)\n"
6325 "Do not export to next AS (well-known community)\n"
6326 "community number\n"
6327 "Do not send outside local AS (well-known community)\n"
6328 "Do not advertise to any peer (well-known community)\n"
6329 "Do not export to next AS (well-known community)\n"
6330 "community number\n"
6331 "Do not send outside local AS (well-known community)\n"
6332 "Do not advertise to any peer (well-known community)\n"
6333 "Do not export to next AS (well-known community)\n"
6334 "Exact match of the communities");
6336 ALIAS (show_ip_bgp_community_exact,
6337 show_ip_bgp_community4_exact_cmd,
6338 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6339 SHOW_STR
6340 IP_STR
6341 BGP_STR
6342 "Display routes matching the communities\n"
6343 "community number\n"
6344 "Do not send outside local AS (well-known community)\n"
6345 "Do not advertise to any peer (well-known community)\n"
6346 "Do not export to next AS (well-known community)\n"
6347 "community number\n"
6348 "Do not send outside local AS (well-known community)\n"
6349 "Do not advertise to any peer (well-known community)\n"
6350 "Do not export to next AS (well-known community)\n"
6351 "community number\n"
6352 "Do not send outside local AS (well-known community)\n"
6353 "Do not advertise to any peer (well-known community)\n"
6354 "Do not export to next AS (well-known community)\n"
6355 "community number\n"
6356 "Do not send outside local AS (well-known community)\n"
6357 "Do not advertise to any peer (well-known community)\n"
6358 "Do not export to next AS (well-known community)\n"
6359 "Exact match of the communities");
6361 DEFUN (show_ip_bgp_ipv4_community_exact,
6362 show_ip_bgp_ipv4_community_exact_cmd,
6363 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6364 SHOW_STR
6365 IP_STR
6366 BGP_STR
6367 "Address family\n"
6368 "Address Family modifier\n"
6369 "Address Family modifier\n"
6370 "Display routes matching the communities\n"
6371 "community number\n"
6372 "Do not send outside local AS (well-known community)\n"
6373 "Do not advertise to any peer (well-known community)\n"
6374 "Do not export to next AS (well-known community)\n"
6375 "Exact match of the communities")
6377 if (strncmp (argv[0], "m", 1) == 0)
6378 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
6380 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
6383 ALIAS (show_ip_bgp_ipv4_community_exact,
6384 show_ip_bgp_ipv4_community2_exact_cmd,
6385 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6386 SHOW_STR
6387 IP_STR
6388 BGP_STR
6389 "Address family\n"
6390 "Address Family modifier\n"
6391 "Address Family modifier\n"
6392 "Display routes matching the communities\n"
6393 "community number\n"
6394 "Do not send outside local AS (well-known community)\n"
6395 "Do not advertise to any peer (well-known community)\n"
6396 "Do not export to next AS (well-known community)\n"
6397 "community number\n"
6398 "Do not send outside local AS (well-known community)\n"
6399 "Do not advertise to any peer (well-known community)\n"
6400 "Do not export to next AS (well-known community)\n"
6401 "Exact match of the communities");
6403 ALIAS (show_ip_bgp_ipv4_community_exact,
6404 show_ip_bgp_ipv4_community3_exact_cmd,
6405 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6406 SHOW_STR
6407 IP_STR
6408 BGP_STR
6409 "Address family\n"
6410 "Address Family modifier\n"
6411 "Address Family modifier\n"
6412 "Display routes matching the communities\n"
6413 "community number\n"
6414 "Do not send outside local AS (well-known community)\n"
6415 "Do not advertise to any peer (well-known community)\n"
6416 "Do not export to next AS (well-known community)\n"
6417 "community number\n"
6418 "Do not send outside local AS (well-known community)\n"
6419 "Do not advertise to any peer (well-known community)\n"
6420 "Do not export to next AS (well-known community)\n"
6421 "community number\n"
6422 "Do not send outside local AS (well-known community)\n"
6423 "Do not advertise to any peer (well-known community)\n"
6424 "Do not export to next AS (well-known community)\n"
6425 "Exact match of the communities");
6427 ALIAS (show_ip_bgp_ipv4_community_exact,
6428 show_ip_bgp_ipv4_community4_exact_cmd,
6429 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6430 SHOW_STR
6431 IP_STR
6432 BGP_STR
6433 "Address family\n"
6434 "Address Family modifier\n"
6435 "Address Family modifier\n"
6436 "Display routes matching the communities\n"
6437 "community number\n"
6438 "Do not send outside local AS (well-known community)\n"
6439 "Do not advertise to any peer (well-known community)\n"
6440 "Do not export to next AS (well-known community)\n"
6441 "community number\n"
6442 "Do not send outside local AS (well-known community)\n"
6443 "Do not advertise to any peer (well-known community)\n"
6444 "Do not export to next AS (well-known community)\n"
6445 "community number\n"
6446 "Do not send outside local AS (well-known community)\n"
6447 "Do not advertise to any peer (well-known community)\n"
6448 "Do not export to next AS (well-known community)\n"
6449 "community number\n"
6450 "Do not send outside local AS (well-known community)\n"
6451 "Do not advertise to any peer (well-known community)\n"
6452 "Do not export to next AS (well-known community)\n"
6453 "Exact match of the communities");
6455 #ifdef HAVE_IPV6
6456 DEFUN (show_bgp_community,
6457 show_bgp_community_cmd,
6458 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
6459 SHOW_STR
6460 BGP_STR
6461 "Display routes matching the communities\n"
6462 "community number\n"
6463 "Do not send outside local AS (well-known community)\n"
6464 "Do not advertise to any peer (well-known community)\n"
6465 "Do not export to next AS (well-known community)\n")
6467 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
6470 ALIAS (show_bgp_community,
6471 show_bgp_ipv6_community_cmd,
6472 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
6473 SHOW_STR
6474 BGP_STR
6475 "Address family\n"
6476 "Display routes matching the communities\n"
6477 "community number\n"
6478 "Do not send outside local AS (well-known community)\n"
6479 "Do not advertise to any peer (well-known community)\n"
6480 "Do not export to next AS (well-known community)\n");
6482 ALIAS (show_bgp_community,
6483 show_bgp_community2_cmd,
6484 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6485 SHOW_STR
6486 BGP_STR
6487 "Display routes matching the communities\n"
6488 "community number\n"
6489 "Do not send outside local AS (well-known community)\n"
6490 "Do not advertise to any peer (well-known community)\n"
6491 "Do not export to next AS (well-known community)\n"
6492 "community number\n"
6493 "Do not send outside local AS (well-known community)\n"
6494 "Do not advertise to any peer (well-known community)\n"
6495 "Do not export to next AS (well-known community)\n");
6497 ALIAS (show_bgp_community,
6498 show_bgp_ipv6_community2_cmd,
6499 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6500 SHOW_STR
6501 BGP_STR
6502 "Address family\n"
6503 "Display routes matching the communities\n"
6504 "community number\n"
6505 "Do not send outside local AS (well-known community)\n"
6506 "Do not advertise to any peer (well-known community)\n"
6507 "Do not export to next AS (well-known community)\n"
6508 "community number\n"
6509 "Do not send outside local AS (well-known community)\n"
6510 "Do not advertise to any peer (well-known community)\n"
6511 "Do not export to next AS (well-known community)\n");
6513 ALIAS (show_bgp_community,
6514 show_bgp_community3_cmd,
6515 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6516 SHOW_STR
6517 BGP_STR
6518 "Display routes matching the communities\n"
6519 "community number\n"
6520 "Do not send outside local AS (well-known community)\n"
6521 "Do not advertise to any peer (well-known community)\n"
6522 "Do not export to next AS (well-known community)\n"
6523 "community number\n"
6524 "Do not send outside local AS (well-known community)\n"
6525 "Do not advertise to any peer (well-known community)\n"
6526 "Do not export to next AS (well-known community)\n"
6527 "community number\n"
6528 "Do not send outside local AS (well-known community)\n"
6529 "Do not advertise to any peer (well-known community)\n"
6530 "Do not export to next AS (well-known community)\n");
6532 ALIAS (show_bgp_community,
6533 show_bgp_ipv6_community3_cmd,
6534 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6535 SHOW_STR
6536 BGP_STR
6537 "Address family\n"
6538 "Display routes matching the communities\n"
6539 "community number\n"
6540 "Do not send outside local AS (well-known community)\n"
6541 "Do not advertise to any peer (well-known community)\n"
6542 "Do not export to next AS (well-known community)\n"
6543 "community number\n"
6544 "Do not send outside local AS (well-known community)\n"
6545 "Do not advertise to any peer (well-known community)\n"
6546 "Do not export to next AS (well-known community)\n"
6547 "community number\n"
6548 "Do not send outside local AS (well-known community)\n"
6549 "Do not advertise to any peer (well-known community)\n"
6550 "Do not export to next AS (well-known community)\n");
6552 ALIAS (show_bgp_community,
6553 show_bgp_community4_cmd,
6554 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6555 SHOW_STR
6556 BGP_STR
6557 "Display routes matching the communities\n"
6558 "community number\n"
6559 "Do not send outside local AS (well-known community)\n"
6560 "Do not advertise to any peer (well-known community)\n"
6561 "Do not export to next AS (well-known community)\n"
6562 "community number\n"
6563 "Do not send outside local AS (well-known community)\n"
6564 "Do not advertise to any peer (well-known community)\n"
6565 "Do not export to next AS (well-known community)\n"
6566 "community number\n"
6567 "Do not send outside local AS (well-known community)\n"
6568 "Do not advertise to any peer (well-known community)\n"
6569 "Do not export to next AS (well-known community)\n"
6570 "community number\n"
6571 "Do not send outside local AS (well-known community)\n"
6572 "Do not advertise to any peer (well-known community)\n"
6573 "Do not export to next AS (well-known community)\n");
6575 ALIAS (show_bgp_community,
6576 show_bgp_ipv6_community4_cmd,
6577 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6578 SHOW_STR
6579 BGP_STR
6580 "Address family\n"
6581 "Display routes matching the communities\n"
6582 "community number\n"
6583 "Do not send outside local AS (well-known community)\n"
6584 "Do not advertise to any peer (well-known community)\n"
6585 "Do not export to next AS (well-known community)\n"
6586 "community number\n"
6587 "Do not send outside local AS (well-known community)\n"
6588 "Do not advertise to any peer (well-known community)\n"
6589 "Do not export to next AS (well-known community)\n"
6590 "community number\n"
6591 "Do not send outside local AS (well-known community)\n"
6592 "Do not advertise to any peer (well-known community)\n"
6593 "Do not export to next AS (well-known community)\n"
6594 "community number\n"
6595 "Do not send outside local AS (well-known community)\n"
6596 "Do not advertise to any peer (well-known community)\n"
6597 "Do not export to next AS (well-known community)\n");
6599 /* old command */
6600 DEFUN (show_ipv6_bgp_community,
6601 show_ipv6_bgp_community_cmd,
6602 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
6603 SHOW_STR
6604 IPV6_STR
6605 BGP_STR
6606 "Display routes matching the communities\n"
6607 "community number\n"
6608 "Do not send outside local AS (well-known community)\n"
6609 "Do not advertise to any peer (well-known community)\n"
6610 "Do not export to next AS (well-known community)\n")
6612 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
6615 /* old command */
6616 ALIAS (show_ipv6_bgp_community,
6617 show_ipv6_bgp_community2_cmd,
6618 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6619 SHOW_STR
6620 IPV6_STR
6621 BGP_STR
6622 "Display routes matching the communities\n"
6623 "community number\n"
6624 "Do not send outside local AS (well-known community)\n"
6625 "Do not advertise to any peer (well-known community)\n"
6626 "Do not export to next AS (well-known community)\n"
6627 "community number\n"
6628 "Do not send outside local AS (well-known community)\n"
6629 "Do not advertise to any peer (well-known community)\n"
6630 "Do not export to next AS (well-known community)\n");
6632 /* old command */
6633 ALIAS (show_ipv6_bgp_community,
6634 show_ipv6_bgp_community3_cmd,
6635 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6636 SHOW_STR
6637 IPV6_STR
6638 BGP_STR
6639 "Display routes matching the communities\n"
6640 "community number\n"
6641 "Do not send outside local AS (well-known community)\n"
6642 "Do not advertise to any peer (well-known community)\n"
6643 "Do not export to next AS (well-known community)\n"
6644 "community number\n"
6645 "Do not send outside local AS (well-known community)\n"
6646 "Do not advertise to any peer (well-known community)\n"
6647 "Do not export to next AS (well-known community)\n"
6648 "community number\n"
6649 "Do not send outside local AS (well-known community)\n"
6650 "Do not advertise to any peer (well-known community)\n"
6651 "Do not export to next AS (well-known community)\n");
6653 /* old command */
6654 ALIAS (show_ipv6_bgp_community,
6655 show_ipv6_bgp_community4_cmd,
6656 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6657 SHOW_STR
6658 IPV6_STR
6659 BGP_STR
6660 "Display routes matching the communities\n"
6661 "community number\n"
6662 "Do not send outside local AS (well-known community)\n"
6663 "Do not advertise to any peer (well-known community)\n"
6664 "Do not export to next AS (well-known community)\n"
6665 "community number\n"
6666 "Do not send outside local AS (well-known community)\n"
6667 "Do not advertise to any peer (well-known community)\n"
6668 "Do not export to next AS (well-known community)\n"
6669 "community number\n"
6670 "Do not send outside local AS (well-known community)\n"
6671 "Do not advertise to any peer (well-known community)\n"
6672 "Do not export to next AS (well-known community)\n"
6673 "community number\n"
6674 "Do not send outside local AS (well-known community)\n"
6675 "Do not advertise to any peer (well-known community)\n"
6676 "Do not export to next AS (well-known community)\n");
6678 DEFUN (show_bgp_community_exact,
6679 show_bgp_community_exact_cmd,
6680 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6681 SHOW_STR
6682 BGP_STR
6683 "Display routes matching the communities\n"
6684 "community number\n"
6685 "Do not send outside local AS (well-known community)\n"
6686 "Do not advertise to any peer (well-known community)\n"
6687 "Do not export to next AS (well-known community)\n"
6688 "Exact match of the communities")
6690 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
6693 ALIAS (show_bgp_community_exact,
6694 show_bgp_ipv6_community_exact_cmd,
6695 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6696 SHOW_STR
6697 BGP_STR
6698 "Address family\n"
6699 "Display routes matching the communities\n"
6700 "community number\n"
6701 "Do not send outside local AS (well-known community)\n"
6702 "Do not advertise to any peer (well-known community)\n"
6703 "Do not export to next AS (well-known community)\n"
6704 "Exact match of the communities");
6706 ALIAS (show_bgp_community_exact,
6707 show_bgp_community2_exact_cmd,
6708 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6709 SHOW_STR
6710 BGP_STR
6711 "Display routes matching the communities\n"
6712 "community number\n"
6713 "Do not send outside local AS (well-known community)\n"
6714 "Do not advertise to any peer (well-known community)\n"
6715 "Do not export to next AS (well-known community)\n"
6716 "community number\n"
6717 "Do not send outside local AS (well-known community)\n"
6718 "Do not advertise to any peer (well-known community)\n"
6719 "Do not export to next AS (well-known community)\n"
6720 "Exact match of the communities");
6722 ALIAS (show_bgp_community_exact,
6723 show_bgp_ipv6_community2_exact_cmd,
6724 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6725 SHOW_STR
6726 BGP_STR
6727 "Address family\n"
6728 "Display routes matching the communities\n"
6729 "community number\n"
6730 "Do not send outside local AS (well-known community)\n"
6731 "Do not advertise to any peer (well-known community)\n"
6732 "Do not export to next AS (well-known community)\n"
6733 "community number\n"
6734 "Do not send outside local AS (well-known community)\n"
6735 "Do not advertise to any peer (well-known community)\n"
6736 "Do not export to next AS (well-known community)\n"
6737 "Exact match of the communities");
6739 ALIAS (show_bgp_community_exact,
6740 show_bgp_community3_exact_cmd,
6741 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6742 SHOW_STR
6743 BGP_STR
6744 "Display routes matching the communities\n"
6745 "community number\n"
6746 "Do not send outside local AS (well-known community)\n"
6747 "Do not advertise to any peer (well-known community)\n"
6748 "Do not export to next AS (well-known community)\n"
6749 "community number\n"
6750 "Do not send outside local AS (well-known community)\n"
6751 "Do not advertise to any peer (well-known community)\n"
6752 "Do not export to next AS (well-known community)\n"
6753 "community number\n"
6754 "Do not send outside local AS (well-known community)\n"
6755 "Do not advertise to any peer (well-known community)\n"
6756 "Do not export to next AS (well-known community)\n"
6757 "Exact match of the communities");
6759 ALIAS (show_bgp_community_exact,
6760 show_bgp_ipv6_community3_exact_cmd,
6761 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6762 SHOW_STR
6763 BGP_STR
6764 "Address family\n"
6765 "Display routes matching the communities\n"
6766 "community number\n"
6767 "Do not send outside local AS (well-known community)\n"
6768 "Do not advertise to any peer (well-known community)\n"
6769 "Do not export to next AS (well-known community)\n"
6770 "community number\n"
6771 "Do not send outside local AS (well-known community)\n"
6772 "Do not advertise to any peer (well-known community)\n"
6773 "Do not export to next AS (well-known community)\n"
6774 "community number\n"
6775 "Do not send outside local AS (well-known community)\n"
6776 "Do not advertise to any peer (well-known community)\n"
6777 "Do not export to next AS (well-known community)\n"
6778 "Exact match of the communities");
6780 ALIAS (show_bgp_community_exact,
6781 show_bgp_community4_exact_cmd,
6782 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6783 SHOW_STR
6784 BGP_STR
6785 "Display routes matching the communities\n"
6786 "community number\n"
6787 "Do not send outside local AS (well-known community)\n"
6788 "Do not advertise to any peer (well-known community)\n"
6789 "Do not export to next AS (well-known community)\n"
6790 "community number\n"
6791 "Do not send outside local AS (well-known community)\n"
6792 "Do not advertise to any peer (well-known community)\n"
6793 "Do not export to next AS (well-known community)\n"
6794 "community number\n"
6795 "Do not send outside local AS (well-known community)\n"
6796 "Do not advertise to any peer (well-known community)\n"
6797 "Do not export to next AS (well-known community)\n"
6798 "community number\n"
6799 "Do not send outside local AS (well-known community)\n"
6800 "Do not advertise to any peer (well-known community)\n"
6801 "Do not export to next AS (well-known community)\n"
6802 "Exact match of the communities");
6804 ALIAS (show_bgp_community_exact,
6805 show_bgp_ipv6_community4_exact_cmd,
6806 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6807 SHOW_STR
6808 BGP_STR
6809 "Address family\n"
6810 "Display routes matching the communities\n"
6811 "community number\n"
6812 "Do not send outside local AS (well-known community)\n"
6813 "Do not advertise to any peer (well-known community)\n"
6814 "Do not export to next AS (well-known community)\n"
6815 "community number\n"
6816 "Do not send outside local AS (well-known community)\n"
6817 "Do not advertise to any peer (well-known community)\n"
6818 "Do not export to next AS (well-known community)\n"
6819 "community number\n"
6820 "Do not send outside local AS (well-known community)\n"
6821 "Do not advertise to any peer (well-known community)\n"
6822 "Do not export to next AS (well-known community)\n"
6823 "community number\n"
6824 "Do not send outside local AS (well-known community)\n"
6825 "Do not advertise to any peer (well-known community)\n"
6826 "Do not export to next AS (well-known community)\n"
6827 "Exact match of the communities");
6829 /* old command */
6830 DEFUN (show_ipv6_bgp_community_exact,
6831 show_ipv6_bgp_community_exact_cmd,
6832 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6833 SHOW_STR
6834 IPV6_STR
6835 BGP_STR
6836 "Display routes matching the communities\n"
6837 "community number\n"
6838 "Do not send outside local AS (well-known community)\n"
6839 "Do not advertise to any peer (well-known community)\n"
6840 "Do not export to next AS (well-known community)\n"
6841 "Exact match of the communities")
6843 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
6846 /* old command */
6847 ALIAS (show_ipv6_bgp_community_exact,
6848 show_ipv6_bgp_community2_exact_cmd,
6849 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6850 SHOW_STR
6851 IPV6_STR
6852 BGP_STR
6853 "Display routes matching the communities\n"
6854 "community number\n"
6855 "Do not send outside local AS (well-known community)\n"
6856 "Do not advertise to any peer (well-known community)\n"
6857 "Do not export to next AS (well-known community)\n"
6858 "community number\n"
6859 "Do not send outside local AS (well-known community)\n"
6860 "Do not advertise to any peer (well-known community)\n"
6861 "Do not export to next AS (well-known community)\n"
6862 "Exact match of the communities");
6864 /* old command */
6865 ALIAS (show_ipv6_bgp_community_exact,
6866 show_ipv6_bgp_community3_exact_cmd,
6867 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6868 SHOW_STR
6869 IPV6_STR
6870 BGP_STR
6871 "Display routes matching the communities\n"
6872 "community number\n"
6873 "Do not send outside local AS (well-known community)\n"
6874 "Do not advertise to any peer (well-known community)\n"
6875 "Do not export to next AS (well-known community)\n"
6876 "community number\n"
6877 "Do not send outside local AS (well-known community)\n"
6878 "Do not advertise to any peer (well-known community)\n"
6879 "Do not export to next AS (well-known community)\n"
6880 "community number\n"
6881 "Do not send outside local AS (well-known community)\n"
6882 "Do not advertise to any peer (well-known community)\n"
6883 "Do not export to next AS (well-known community)\n"
6884 "Exact match of the communities");
6886 /* old command */
6887 ALIAS (show_ipv6_bgp_community_exact,
6888 show_ipv6_bgp_community4_exact_cmd,
6889 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6890 SHOW_STR
6891 IPV6_STR
6892 BGP_STR
6893 "Display routes matching the communities\n"
6894 "community number\n"
6895 "Do not send outside local AS (well-known community)\n"
6896 "Do not advertise to any peer (well-known community)\n"
6897 "Do not export to next AS (well-known community)\n"
6898 "community number\n"
6899 "Do not send outside local AS (well-known community)\n"
6900 "Do not advertise to any peer (well-known community)\n"
6901 "Do not export to next AS (well-known community)\n"
6902 "community number\n"
6903 "Do not send outside local AS (well-known community)\n"
6904 "Do not advertise to any peer (well-known community)\n"
6905 "Do not export to next AS (well-known community)\n"
6906 "community number\n"
6907 "Do not send outside local AS (well-known community)\n"
6908 "Do not advertise to any peer (well-known community)\n"
6909 "Do not export to next AS (well-known community)\n"
6910 "Exact match of the communities");
6912 /* old command */
6913 DEFUN (show_ipv6_mbgp_community,
6914 show_ipv6_mbgp_community_cmd,
6915 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
6916 SHOW_STR
6917 IPV6_STR
6918 MBGP_STR
6919 "Display routes matching the communities\n"
6920 "community number\n"
6921 "Do not send outside local AS (well-known community)\n"
6922 "Do not advertise to any peer (well-known community)\n"
6923 "Do not export to next AS (well-known community)\n")
6925 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
6928 /* old command */
6929 ALIAS (show_ipv6_mbgp_community,
6930 show_ipv6_mbgp_community2_cmd,
6931 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6932 SHOW_STR
6933 IPV6_STR
6934 MBGP_STR
6935 "Display routes matching the communities\n"
6936 "community number\n"
6937 "Do not send outside local AS (well-known community)\n"
6938 "Do not advertise to any peer (well-known community)\n"
6939 "Do not export to next AS (well-known community)\n"
6940 "community number\n"
6941 "Do not send outside local AS (well-known community)\n"
6942 "Do not advertise to any peer (well-known community)\n"
6943 "Do not export to next AS (well-known community)\n");
6945 /* old command */
6946 ALIAS (show_ipv6_mbgp_community,
6947 show_ipv6_mbgp_community3_cmd,
6948 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6949 SHOW_STR
6950 IPV6_STR
6951 MBGP_STR
6952 "Display routes matching the communities\n"
6953 "community number\n"
6954 "Do not send outside local AS (well-known community)\n"
6955 "Do not advertise to any peer (well-known community)\n"
6956 "Do not export to next AS (well-known community)\n"
6957 "community number\n"
6958 "Do not send outside local AS (well-known community)\n"
6959 "Do not advertise to any peer (well-known community)\n"
6960 "Do not export to next AS (well-known community)\n"
6961 "community number\n"
6962 "Do not send outside local AS (well-known community)\n"
6963 "Do not advertise to any peer (well-known community)\n"
6964 "Do not export to next AS (well-known community)\n");
6966 /* old command */
6967 ALIAS (show_ipv6_mbgp_community,
6968 show_ipv6_mbgp_community4_cmd,
6969 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6970 SHOW_STR
6971 IPV6_STR
6972 MBGP_STR
6973 "Display routes matching the communities\n"
6974 "community number\n"
6975 "Do not send outside local AS (well-known community)\n"
6976 "Do not advertise to any peer (well-known community)\n"
6977 "Do not export to next AS (well-known community)\n"
6978 "community number\n"
6979 "Do not send outside local AS (well-known community)\n"
6980 "Do not advertise to any peer (well-known community)\n"
6981 "Do not export to next AS (well-known community)\n"
6982 "community number\n"
6983 "Do not send outside local AS (well-known community)\n"
6984 "Do not advertise to any peer (well-known community)\n"
6985 "Do not export to next AS (well-known community)\n"
6986 "community number\n"
6987 "Do not send outside local AS (well-known community)\n"
6988 "Do not advertise to any peer (well-known community)\n"
6989 "Do not export to next AS (well-known community)\n");
6991 /* old command */
6992 DEFUN (show_ipv6_mbgp_community_exact,
6993 show_ipv6_mbgp_community_exact_cmd,
6994 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6995 SHOW_STR
6996 IPV6_STR
6997 MBGP_STR
6998 "Display routes matching the communities\n"
6999 "community number\n"
7000 "Do not send outside local AS (well-known community)\n"
7001 "Do not advertise to any peer (well-known community)\n"
7002 "Do not export to next AS (well-known community)\n"
7003 "Exact match of the communities")
7005 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7008 /* old command */
7009 ALIAS (show_ipv6_mbgp_community_exact,
7010 show_ipv6_mbgp_community2_exact_cmd,
7011 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7012 SHOW_STR
7013 IPV6_STR
7014 MBGP_STR
7015 "Display routes matching the communities\n"
7016 "community number\n"
7017 "Do not send outside local AS (well-known community)\n"
7018 "Do not advertise to any peer (well-known community)\n"
7019 "Do not export to next AS (well-known community)\n"
7020 "community number\n"
7021 "Do not send outside local AS (well-known community)\n"
7022 "Do not advertise to any peer (well-known community)\n"
7023 "Do not export to next AS (well-known community)\n"
7024 "Exact match of the communities");
7026 /* old command */
7027 ALIAS (show_ipv6_mbgp_community_exact,
7028 show_ipv6_mbgp_community3_exact_cmd,
7029 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7030 SHOW_STR
7031 IPV6_STR
7032 MBGP_STR
7033 "Display routes matching the communities\n"
7034 "community number\n"
7035 "Do not send outside local AS (well-known community)\n"
7036 "Do not advertise to any peer (well-known community)\n"
7037 "Do not export to next AS (well-known community)\n"
7038 "community number\n"
7039 "Do not send outside local AS (well-known community)\n"
7040 "Do not advertise to any peer (well-known community)\n"
7041 "Do not export to next AS (well-known community)\n"
7042 "community number\n"
7043 "Do not send outside local AS (well-known community)\n"
7044 "Do not advertise to any peer (well-known community)\n"
7045 "Do not export to next AS (well-known community)\n"
7046 "Exact match of the communities");
7048 /* old command */
7049 ALIAS (show_ipv6_mbgp_community_exact,
7050 show_ipv6_mbgp_community4_exact_cmd,
7051 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7052 SHOW_STR
7053 IPV6_STR
7054 MBGP_STR
7055 "Display routes matching the communities\n"
7056 "community number\n"
7057 "Do not send outside local AS (well-known community)\n"
7058 "Do not advertise to any peer (well-known community)\n"
7059 "Do not export to next AS (well-known community)\n"
7060 "community number\n"
7061 "Do not send outside local AS (well-known community)\n"
7062 "Do not advertise to any peer (well-known community)\n"
7063 "Do not export to next AS (well-known community)\n"
7064 "community number\n"
7065 "Do not send outside local AS (well-known community)\n"
7066 "Do not advertise to any peer (well-known community)\n"
7067 "Do not export to next AS (well-known community)\n"
7068 "community number\n"
7069 "Do not send outside local AS (well-known community)\n"
7070 "Do not advertise to any peer (well-known community)\n"
7071 "Do not export to next AS (well-known community)\n"
7072 "Exact match of the communities");
7073 #endif /* HAVE_IPV6 */
7076 bgp_show_community_list (struct vty *vty, char *com, int exact,
7077 u_int16_t afi, u_char safi)
7079 struct community_list *list;
7081 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
7082 if (list == NULL)
7084 vty_out (vty, "%% %s is not a valid community-list name%s", com,
7085 VTY_NEWLINE);
7086 return CMD_WARNING;
7089 vty->output_arg = list;
7091 if (exact)
7092 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_list_exact);
7094 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_list);
7097 DEFUN (show_ip_bgp_community_list,
7098 show_ip_bgp_community_list_cmd,
7099 "show ip bgp community-list (<1-500>|WORD)",
7100 SHOW_STR
7101 IP_STR
7102 BGP_STR
7103 "Display routes matching the community-list\n"
7104 "community-list number\n"
7105 "community-list name\n")
7107 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
7110 DEFUN (show_ip_bgp_ipv4_community_list,
7111 show_ip_bgp_ipv4_community_list_cmd,
7112 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
7113 SHOW_STR
7114 IP_STR
7115 BGP_STR
7116 "Address family\n"
7117 "Address Family modifier\n"
7118 "Address Family modifier\n"
7119 "Display routes matching the community-list\n"
7120 "community-list number\n"
7121 "community-list name\n")
7123 if (strncmp (argv[0], "m", 1) == 0)
7124 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
7126 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
7129 DEFUN (show_ip_bgp_community_list_exact,
7130 show_ip_bgp_community_list_exact_cmd,
7131 "show ip bgp community-list (<1-500>|WORD) exact-match",
7132 SHOW_STR
7133 IP_STR
7134 BGP_STR
7135 "Display routes matching the community-list\n"
7136 "community-list number\n"
7137 "community-list name\n"
7138 "Exact match of the communities\n")
7140 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
7143 DEFUN (show_ip_bgp_ipv4_community_list_exact,
7144 show_ip_bgp_ipv4_community_list_exact_cmd,
7145 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
7146 SHOW_STR
7147 IP_STR
7148 BGP_STR
7149 "Address family\n"
7150 "Address Family modifier\n"
7151 "Address Family modifier\n"
7152 "Display routes matching the community-list\n"
7153 "community-list number\n"
7154 "community-list name\n"
7155 "Exact match of the communities\n")
7157 if (strncmp (argv[0], "m", 1) == 0)
7158 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
7160 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
7163 #ifdef HAVE_IPV6
7164 DEFUN (show_bgp_community_list,
7165 show_bgp_community_list_cmd,
7166 "show bgp community-list (<1-500>|WORD)",
7167 SHOW_STR
7168 BGP_STR
7169 "Display routes matching the community-list\n"
7170 "community-list number\n"
7171 "community-list name\n")
7173 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
7176 ALIAS (show_bgp_community_list,
7177 show_bgp_ipv6_community_list_cmd,
7178 "show bgp ipv6 community-list (<1-500>|WORD)",
7179 SHOW_STR
7180 BGP_STR
7181 "Address family\n"
7182 "Display routes matching the community-list\n"
7183 "community-list number\n"
7184 "community-list name\n");
7186 /* old command */
7187 DEFUN (show_ipv6_bgp_community_list,
7188 show_ipv6_bgp_community_list_cmd,
7189 "show ipv6 bgp community-list WORD",
7190 SHOW_STR
7191 IPV6_STR
7192 BGP_STR
7193 "Display routes matching the community-list\n"
7194 "community-list name\n")
7196 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
7199 /* old command */
7200 DEFUN (show_ipv6_mbgp_community_list,
7201 show_ipv6_mbgp_community_list_cmd,
7202 "show ipv6 mbgp community-list WORD",
7203 SHOW_STR
7204 IPV6_STR
7205 MBGP_STR
7206 "Display routes matching the community-list\n"
7207 "community-list name\n")
7209 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
7212 DEFUN (show_bgp_community_list_exact,
7213 show_bgp_community_list_exact_cmd,
7214 "show bgp community-list (<1-500>|WORD) exact-match",
7215 SHOW_STR
7216 BGP_STR
7217 "Display routes matching the community-list\n"
7218 "community-list number\n"
7219 "community-list name\n"
7220 "Exact match of the communities\n")
7222 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
7225 ALIAS (show_bgp_community_list_exact,
7226 show_bgp_ipv6_community_list_exact_cmd,
7227 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
7228 SHOW_STR
7229 BGP_STR
7230 "Address family\n"
7231 "Display routes matching the community-list\n"
7232 "community-list number\n"
7233 "community-list name\n"
7234 "Exact match of the communities\n");
7236 /* old command */
7237 DEFUN (show_ipv6_bgp_community_list_exact,
7238 show_ipv6_bgp_community_list_exact_cmd,
7239 "show ipv6 bgp community-list WORD exact-match",
7240 SHOW_STR
7241 IPV6_STR
7242 BGP_STR
7243 "Display routes matching the community-list\n"
7244 "community-list name\n"
7245 "Exact match of the communities\n")
7247 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
7250 /* old command */
7251 DEFUN (show_ipv6_mbgp_community_list_exact,
7252 show_ipv6_mbgp_community_list_exact_cmd,
7253 "show ipv6 mbgp community-list WORD exact-match",
7254 SHOW_STR
7255 IPV6_STR
7256 MBGP_STR
7257 "Display routes matching the community-list\n"
7258 "community-list name\n"
7259 "Exact match of the communities\n")
7261 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
7263 #endif /* HAVE_IPV6 */
7265 void
7266 bgp_show_prefix_longer_clean (struct vty *vty)
7268 struct prefix *p;
7270 p = vty->output_arg;
7271 prefix_free (p);
7275 bgp_show_prefix_longer (struct vty *vty, char *prefix, afi_t afi,
7276 safi_t safi, enum bgp_show_type type)
7278 int ret;
7279 struct prefix *p;
7281 p = prefix_new();
7283 ret = str2prefix (prefix, p);
7284 if (! ret)
7286 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
7287 return CMD_WARNING;
7290 vty->output_arg = p;
7291 vty->output_clean = bgp_show_prefix_longer_clean;
7293 return bgp_show (vty, NULL, afi, safi, type);
7296 DEFUN (show_ip_bgp_prefix_longer,
7297 show_ip_bgp_prefix_longer_cmd,
7298 "show ip bgp A.B.C.D/M longer-prefixes",
7299 SHOW_STR
7300 IP_STR
7301 BGP_STR
7302 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7303 "Display route and more specific routes\n")
7305 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7306 bgp_show_type_prefix_longer);
7309 DEFUN (show_ip_bgp_flap_prefix_longer,
7310 show_ip_bgp_flap_prefix_longer_cmd,
7311 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
7312 SHOW_STR
7313 IP_STR
7314 BGP_STR
7315 "Display flap statistics of routes\n"
7316 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7317 "Display route and more specific routes\n")
7319 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7320 bgp_show_type_flap_prefix_longer);
7323 DEFUN (show_ip_bgp_ipv4_prefix_longer,
7324 show_ip_bgp_ipv4_prefix_longer_cmd,
7325 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
7326 SHOW_STR
7327 IP_STR
7328 BGP_STR
7329 "Address family\n"
7330 "Address Family modifier\n"
7331 "Address Family modifier\n"
7332 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7333 "Display route and more specific routes\n")
7335 if (strncmp (argv[0], "m", 1) == 0)
7336 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7337 bgp_show_type_prefix_longer);
7339 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
7340 bgp_show_type_prefix_longer);
7343 DEFUN (show_ip_bgp_flap_address,
7344 show_ip_bgp_flap_address_cmd,
7345 "show ip bgp flap-statistics A.B.C.D",
7346 SHOW_STR
7347 IP_STR
7348 BGP_STR
7349 "Display flap statistics of routes\n"
7350 "Network in the BGP routing table to display\n")
7352 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7353 bgp_show_type_flap_address);
7356 DEFUN (show_ip_bgp_flap_prefix,
7357 show_ip_bgp_flap_prefix_cmd,
7358 "show ip bgp flap-statistics A.B.C.D/M",
7359 SHOW_STR
7360 IP_STR
7361 BGP_STR
7362 "Display flap statistics of routes\n"
7363 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7365 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7366 bgp_show_type_flap_prefix);
7368 #ifdef HAVE_IPV6
7369 DEFUN (show_bgp_prefix_longer,
7370 show_bgp_prefix_longer_cmd,
7371 "show bgp X:X::X:X/M longer-prefixes",
7372 SHOW_STR
7373 BGP_STR
7374 "IPv6 prefix <network>/<length>\n"
7375 "Display route and more specific routes\n")
7377 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7378 bgp_show_type_prefix_longer);
7381 ALIAS (show_bgp_prefix_longer,
7382 show_bgp_ipv6_prefix_longer_cmd,
7383 "show bgp ipv6 X:X::X:X/M longer-prefixes",
7384 SHOW_STR
7385 BGP_STR
7386 "Address family\n"
7387 "IPv6 prefix <network>/<length>\n"
7388 "Display route and more specific routes\n");
7390 /* old command */
7391 DEFUN (show_ipv6_bgp_prefix_longer,
7392 show_ipv6_bgp_prefix_longer_cmd,
7393 "show ipv6 bgp X:X::X:X/M longer-prefixes",
7394 SHOW_STR
7395 IPV6_STR
7396 BGP_STR
7397 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7398 "Display route and more specific routes\n")
7400 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7401 bgp_show_type_prefix_longer);
7404 /* old command */
7405 DEFUN (show_ipv6_mbgp_prefix_longer,
7406 show_ipv6_mbgp_prefix_longer_cmd,
7407 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
7408 SHOW_STR
7409 IPV6_STR
7410 MBGP_STR
7411 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7412 "Display route and more specific routes\n")
7414 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7415 bgp_show_type_prefix_longer);
7417 #endif /* HAVE_IPV6 */
7419 void
7420 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
7421 int in)
7423 struct bgp_table *table;
7424 struct bgp_adj_in *ain;
7425 struct bgp_adj_out *adj;
7426 unsigned long output_count;
7427 struct bgp_node *rn;
7428 int header1 = 1;
7429 struct bgp *bgp;
7430 int header2 = 1;
7432 bgp = bgp_get_default ();
7434 if (! bgp)
7435 return;
7437 table = bgp->rib[afi][safi];
7439 output_count = 0;
7441 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
7442 PEER_STATUS_DEFAULT_ORIGINATE))
7444 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
7445 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7446 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7448 vty_out (vty, "Originating default network 0.0.0.0%s%s",
7449 VTY_NEWLINE, VTY_NEWLINE);
7450 header1 = 0;
7453 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7454 if (in)
7456 for (ain = rn->adj_in; ain; ain = ain->next)
7457 if (ain->peer == peer)
7459 if (header1)
7461 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
7462 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7463 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7464 header1 = 0;
7466 if (header2)
7468 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7469 header2 = 0;
7471 if (ain->attr)
7473 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
7474 output_count++;
7478 else
7480 for (adj = rn->adj_out; adj; adj = adj->next)
7481 if (adj->peer == peer)
7483 if (header1)
7485 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
7486 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7487 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
7488 header1 = 0;
7490 if (header2)
7492 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7493 header2 = 0;
7495 if (adj->attr)
7497 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
7498 output_count++;
7503 if (output_count != 0)
7504 vty_out (vty, "%sTotal number of prefixes %ld%s",
7505 VTY_NEWLINE, output_count, VTY_NEWLINE);
7509 peer_adj_routes (struct vty *vty, char *ip_str, afi_t afi, safi_t safi, int in)
7511 int ret;
7512 struct peer *peer;
7513 union sockunion su;
7515 ret = str2sockunion (ip_str, &su);
7516 if (ret < 0)
7518 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
7519 return CMD_WARNING;
7521 peer = peer_lookup (NULL, &su);
7522 if (! peer || ! peer->afc[afi][safi])
7524 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
7525 return CMD_WARNING;
7528 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7530 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
7531 VTY_NEWLINE);
7532 return CMD_WARNING;
7535 show_adj_route (vty, peer, afi, safi, in);
7537 return CMD_SUCCESS;
7540 DEFUN (show_ip_bgp_neighbor_advertised_route,
7541 show_ip_bgp_neighbor_advertised_route_cmd,
7542 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7543 SHOW_STR
7544 IP_STR
7545 BGP_STR
7546 "Detailed information on TCP and BGP neighbor connections\n"
7547 "Neighbor to display information about\n"
7548 "Neighbor to display information about\n"
7549 "Display the routes advertised to a BGP neighbor\n")
7551 return peer_adj_routes (vty, argv[0], AFI_IP, SAFI_UNICAST, 0);
7554 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
7555 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
7556 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7557 SHOW_STR
7558 IP_STR
7559 BGP_STR
7560 "Address family\n"
7561 "Address Family modifier\n"
7562 "Address Family modifier\n"
7563 "Detailed information on TCP and BGP neighbor connections\n"
7564 "Neighbor to display information about\n"
7565 "Neighbor to display information about\n"
7566 "Display the routes advertised to a BGP neighbor\n")
7568 if (strncmp (argv[0], "m", 1) == 0)
7569 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_MULTICAST, 0);
7571 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_UNICAST, 0);
7574 #ifdef HAVE_IPV6
7575 DEFUN (show_bgp_neighbor_advertised_route,
7576 show_bgp_neighbor_advertised_route_cmd,
7577 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7578 SHOW_STR
7579 BGP_STR
7580 "Detailed information on TCP and BGP neighbor connections\n"
7581 "Neighbor to display information about\n"
7582 "Neighbor to display information about\n"
7583 "Display the routes advertised to a BGP neighbor\n")
7585 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0);
7588 ALIAS (show_bgp_neighbor_advertised_route,
7589 show_bgp_ipv6_neighbor_advertised_route_cmd,
7590 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7591 SHOW_STR
7592 BGP_STR
7593 "Address family\n"
7594 "Detailed information on TCP and BGP neighbor connections\n"
7595 "Neighbor to display information about\n"
7596 "Neighbor to display information about\n"
7597 "Display the routes advertised to a BGP neighbor\n");
7599 /* old command */
7600 DEFUN (ipv6_bgp_neighbor_advertised_route,
7601 ipv6_bgp_neighbor_advertised_route_cmd,
7602 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7603 SHOW_STR
7604 IPV6_STR
7605 BGP_STR
7606 "Detailed information on TCP and BGP neighbor connections\n"
7607 "Neighbor to display information about\n"
7608 "Neighbor to display information about\n"
7609 "Display the routes advertised to a BGP neighbor\n")
7611 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0);
7614 /* old command */
7615 DEFUN (ipv6_mbgp_neighbor_advertised_route,
7616 ipv6_mbgp_neighbor_advertised_route_cmd,
7617 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7618 SHOW_STR
7619 IPV6_STR
7620 MBGP_STR
7621 "Detailed information on TCP and BGP neighbor connections\n"
7622 "Neighbor to display information about\n"
7623 "Neighbor to display information about\n"
7624 "Display the routes advertised to a BGP neighbor\n")
7626 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_MULTICAST, 0);
7628 #endif /* HAVE_IPV6 */
7630 DEFUN (show_ip_bgp_neighbor_received_routes,
7631 show_ip_bgp_neighbor_received_routes_cmd,
7632 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7633 SHOW_STR
7634 IP_STR
7635 BGP_STR
7636 "Detailed information on TCP and BGP neighbor connections\n"
7637 "Neighbor to display information about\n"
7638 "Neighbor to display information about\n"
7639 "Display the received routes from neighbor\n")
7641 return peer_adj_routes (vty, argv[0], AFI_IP, SAFI_UNICAST, 1);
7644 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
7645 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
7646 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
7647 SHOW_STR
7648 IP_STR
7649 BGP_STR
7650 "Address family\n"
7651 "Address Family modifier\n"
7652 "Address Family modifier\n"
7653 "Detailed information on TCP and BGP neighbor connections\n"
7654 "Neighbor to display information about\n"
7655 "Neighbor to display information about\n"
7656 "Display the received routes from neighbor\n")
7658 if (strncmp (argv[0], "m", 1) == 0)
7659 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_MULTICAST, 1);
7661 return peer_adj_routes (vty, argv[1], AFI_IP, SAFI_UNICAST, 1);
7664 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
7665 show_ip_bgp_neighbor_received_prefix_filter_cmd,
7666 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7667 SHOW_STR
7668 IP_STR
7669 BGP_STR
7670 "Detailed information on TCP and BGP neighbor connections\n"
7671 "Neighbor to display information about\n"
7672 "Neighbor to display information about\n"
7673 "Display information received from a BGP neighbor\n"
7674 "Display the prefixlist filter\n")
7676 char name[BUFSIZ];
7677 union sockunion *su;
7678 struct peer *peer;
7679 int count;
7681 su = sockunion_str2su (argv[0]);
7682 if (su == NULL)
7683 return CMD_WARNING;
7685 peer = peer_lookup (NULL, su);
7686 if (! peer)
7687 return CMD_WARNING;
7689 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
7690 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
7691 if (count)
7693 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
7694 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
7697 return CMD_SUCCESS;
7700 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
7701 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
7702 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7703 SHOW_STR
7704 IP_STR
7705 BGP_STR
7706 "Address family\n"
7707 "Address Family modifier\n"
7708 "Address Family modifier\n"
7709 "Detailed information on TCP and BGP neighbor connections\n"
7710 "Neighbor to display information about\n"
7711 "Neighbor to display information about\n"
7712 "Display information received from a BGP neighbor\n"
7713 "Display the prefixlist filter\n")
7715 char name[BUFSIZ];
7716 union sockunion *su;
7717 struct peer *peer;
7718 int count;
7720 su = sockunion_str2su (argv[1]);
7721 if (su == NULL)
7722 return CMD_WARNING;
7724 peer = peer_lookup (NULL, su);
7725 if (! peer)
7726 return CMD_WARNING;
7728 if (strncmp (argv[0], "m", 1) == 0)
7730 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
7731 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
7732 if (count)
7734 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
7735 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
7738 else
7740 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
7741 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
7742 if (count)
7744 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
7745 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
7749 return CMD_SUCCESS;
7753 #ifdef HAVE_IPV6
7754 DEFUN (show_bgp_neighbor_received_routes,
7755 show_bgp_neighbor_received_routes_cmd,
7756 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7757 SHOW_STR
7758 BGP_STR
7759 "Detailed information on TCP and BGP neighbor connections\n"
7760 "Neighbor to display information about\n"
7761 "Neighbor to display information about\n"
7762 "Display the received routes from neighbor\n")
7764 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 1);
7767 ALIAS (show_bgp_neighbor_received_routes,
7768 show_bgp_ipv6_neighbor_received_routes_cmd,
7769 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
7770 SHOW_STR
7771 BGP_STR
7772 "Address family\n"
7773 "Detailed information on TCP and BGP neighbor connections\n"
7774 "Neighbor to display information about\n"
7775 "Neighbor to display information about\n"
7776 "Display the received routes from neighbor\n");
7778 DEFUN (show_bgp_neighbor_received_prefix_filter,
7779 show_bgp_neighbor_received_prefix_filter_cmd,
7780 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7781 SHOW_STR
7782 BGP_STR
7783 "Detailed information on TCP and BGP neighbor connections\n"
7784 "Neighbor to display information about\n"
7785 "Neighbor to display information about\n"
7786 "Display information received from a BGP neighbor\n"
7787 "Display the prefixlist filter\n")
7789 char name[BUFSIZ];
7790 union sockunion *su;
7791 struct peer *peer;
7792 int count;
7794 su = sockunion_str2su (argv[0]);
7795 if (su == NULL)
7796 return CMD_WARNING;
7798 peer = peer_lookup (NULL, su);
7799 if (! peer)
7800 return CMD_WARNING;
7802 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
7803 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
7804 if (count)
7806 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
7807 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
7810 return CMD_SUCCESS;
7813 ALIAS (show_bgp_neighbor_received_prefix_filter,
7814 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
7815 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7816 SHOW_STR
7817 BGP_STR
7818 "Address family\n"
7819 "Detailed information on TCP and BGP neighbor connections\n"
7820 "Neighbor to display information about\n"
7821 "Neighbor to display information about\n"
7822 "Display information received from a BGP neighbor\n"
7823 "Display the prefixlist filter\n");
7825 /* old command */
7826 DEFUN (ipv6_bgp_neighbor_received_routes,
7827 ipv6_bgp_neighbor_received_routes_cmd,
7828 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7829 SHOW_STR
7830 IPV6_STR
7831 BGP_STR
7832 "Detailed information on TCP and BGP neighbor connections\n"
7833 "Neighbor to display information about\n"
7834 "Neighbor to display information about\n"
7835 "Display the received routes from neighbor\n")
7837 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_UNICAST, 1);
7840 /* old command */
7841 DEFUN (ipv6_mbgp_neighbor_received_routes,
7842 ipv6_mbgp_neighbor_received_routes_cmd,
7843 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7844 SHOW_STR
7845 IPV6_STR
7846 MBGP_STR
7847 "Detailed information on TCP and BGP neighbor connections\n"
7848 "Neighbor to display information about\n"
7849 "Neighbor to display information about\n"
7850 "Display the received routes from neighbor\n")
7852 return peer_adj_routes (vty, argv[0], AFI_IP6, SAFI_MULTICAST, 1);
7854 #endif /* HAVE_IPV6 */
7856 void
7857 bgp_show_neighbor_route_clean (struct vty *vty)
7859 union sockunion *su;
7861 su = vty->output_arg;
7862 XFREE (MTYPE_SOCKUNION, su);
7866 bgp_show_neighbor_route (struct vty *vty, char *ip_str, afi_t afi,
7867 safi_t safi, enum bgp_show_type type)
7869 union sockunion *su;
7870 struct peer *peer;
7872 su = sockunion_str2su (ip_str);
7873 if (su == NULL)
7875 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
7876 return CMD_WARNING;
7879 peer = peer_lookup (NULL, su);
7880 if (! peer || ! peer->afc[afi][safi])
7882 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
7883 XFREE (MTYPE_SOCKUNION, su);
7884 return CMD_WARNING;
7887 vty->output_arg = su;
7888 vty->output_clean = bgp_show_neighbor_route_clean;
7890 return bgp_show (vty, NULL, afi, safi, type);
7893 DEFUN (show_ip_bgp_neighbor_routes,
7894 show_ip_bgp_neighbor_routes_cmd,
7895 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
7896 SHOW_STR
7897 IP_STR
7898 BGP_STR
7899 "Detailed information on TCP and BGP neighbor connections\n"
7900 "Neighbor to display information about\n"
7901 "Neighbor to display information about\n"
7902 "Display routes learned from neighbor\n")
7904 return bgp_show_neighbor_route (vty, argv[0], AFI_IP, SAFI_UNICAST,
7905 bgp_show_type_neighbor);
7908 DEFUN (show_ip_bgp_neighbor_flap,
7909 show_ip_bgp_neighbor_flap_cmd,
7910 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
7911 SHOW_STR
7912 IP_STR
7913 BGP_STR
7914 "Detailed information on TCP and BGP neighbor connections\n"
7915 "Neighbor to display information about\n"
7916 "Neighbor to display information about\n"
7917 "Display flap statistics of the routes learned from neighbor\n")
7919 return bgp_show_neighbor_route (vty, argv[0], AFI_IP, SAFI_UNICAST,
7920 bgp_show_type_flap_neighbor);
7923 DEFUN (show_ip_bgp_neighbor_damp,
7924 show_ip_bgp_neighbor_damp_cmd,
7925 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
7926 SHOW_STR
7927 IP_STR
7928 BGP_STR
7929 "Detailed information on TCP and BGP neighbor connections\n"
7930 "Neighbor to display information about\n"
7931 "Neighbor to display information about\n"
7932 "Display the dampened routes received from neighbor\n")
7934 return bgp_show_neighbor_route (vty, argv[0], AFI_IP, SAFI_UNICAST,
7935 bgp_show_type_damp_neighbor);
7938 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
7939 show_ip_bgp_ipv4_neighbor_routes_cmd,
7940 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
7941 SHOW_STR
7942 IP_STR
7943 BGP_STR
7944 "Address family\n"
7945 "Address Family modifier\n"
7946 "Address Family modifier\n"
7947 "Detailed information on TCP and BGP neighbor connections\n"
7948 "Neighbor to display information about\n"
7949 "Neighbor to display information about\n"
7950 "Display routes learned from neighbor\n")
7952 if (strncmp (argv[0], "m", 1) == 0)
7953 return bgp_show_neighbor_route (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7954 bgp_show_type_neighbor);
7956 return bgp_show_neighbor_route (vty, argv[1], AFI_IP, SAFI_UNICAST,
7957 bgp_show_type_neighbor);
7959 #ifdef HAVE_IPV6
7960 DEFUN (show_bgp_neighbor_routes,
7961 show_bgp_neighbor_routes_cmd,
7962 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
7963 SHOW_STR
7964 BGP_STR
7965 "Detailed information on TCP and BGP neighbor connections\n"
7966 "Neighbor to display information about\n"
7967 "Neighbor to display information about\n"
7968 "Display routes learned from neighbor\n")
7970 return bgp_show_neighbor_route (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7971 bgp_show_type_neighbor);
7974 ALIAS (show_bgp_neighbor_routes,
7975 show_bgp_ipv6_neighbor_routes_cmd,
7976 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
7977 SHOW_STR
7978 BGP_STR
7979 "Address family\n"
7980 "Detailed information on TCP and BGP neighbor connections\n"
7981 "Neighbor to display information about\n"
7982 "Neighbor to display information about\n"
7983 "Display routes learned from neighbor\n");
7985 /* old command */
7986 DEFUN (ipv6_bgp_neighbor_routes,
7987 ipv6_bgp_neighbor_routes_cmd,
7988 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
7989 SHOW_STR
7990 IPV6_STR
7991 BGP_STR
7992 "Detailed information on TCP and BGP neighbor connections\n"
7993 "Neighbor to display information about\n"
7994 "Neighbor to display information about\n"
7995 "Display routes learned from neighbor\n")
7997 return bgp_show_neighbor_route (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7998 bgp_show_type_neighbor);
8001 /* old command */
8002 DEFUN (ipv6_mbgp_neighbor_routes,
8003 ipv6_mbgp_neighbor_routes_cmd,
8004 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
8005 SHOW_STR
8006 IPV6_STR
8007 MBGP_STR
8008 "Detailed information on TCP and BGP neighbor connections\n"
8009 "Neighbor to display information about\n"
8010 "Neighbor to display information about\n"
8011 "Display routes learned from neighbor\n")
8013 return bgp_show_neighbor_route (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8014 bgp_show_type_neighbor);
8016 #endif /* HAVE_IPV6 */
8018 struct bgp_table *bgp_distance_table;
8020 struct bgp_distance
8022 /* Distance value for the IP source prefix. */
8023 u_char distance;
8025 /* Name of the access-list to be matched. */
8026 char *access_list;
8029 struct bgp_distance *
8030 bgp_distance_new ()
8032 struct bgp_distance *new;
8033 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
8034 memset (new, 0, sizeof (struct bgp_distance));
8035 return new;
8038 void
8039 bgp_distance_free (struct bgp_distance *bdistance)
8041 XFREE (MTYPE_BGP_DISTANCE, bdistance);
8045 bgp_distance_set (struct vty *vty, char *distance_str, char *ip_str,
8046 char *access_list_str)
8048 int ret;
8049 struct prefix_ipv4 p;
8050 u_char distance;
8051 struct bgp_node *rn;
8052 struct bgp_distance *bdistance;
8054 ret = str2prefix_ipv4 (ip_str, &p);
8055 if (ret == 0)
8057 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
8058 return CMD_WARNING;
8061 distance = atoi (distance_str);
8063 /* Get BGP distance node. */
8064 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
8065 if (rn->info)
8067 bdistance = rn->info;
8068 bgp_unlock_node (rn);
8070 else
8072 bdistance = bgp_distance_new ();
8073 rn->info = bdistance;
8076 /* Set distance value. */
8077 bdistance->distance = distance;
8079 /* Reset access-list configuration. */
8080 if (bdistance->access_list)
8082 free (bdistance->access_list);
8083 bdistance->access_list = NULL;
8085 if (access_list_str)
8086 bdistance->access_list = strdup (access_list_str);
8088 return CMD_SUCCESS;
8092 bgp_distance_unset (struct vty *vty, char *distance_str, char *ip_str,
8093 char *access_list_str)
8095 int ret;
8096 struct prefix_ipv4 p;
8097 u_char distance;
8098 struct bgp_node *rn;
8099 struct bgp_distance *bdistance;
8101 ret = str2prefix_ipv4 (ip_str, &p);
8102 if (ret == 0)
8104 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
8105 return CMD_WARNING;
8108 distance = atoi (distance_str);
8110 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
8111 if (! rn)
8113 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
8114 return CMD_WARNING;
8117 bdistance = rn->info;
8119 if (bdistance->access_list)
8120 free (bdistance->access_list);
8121 bgp_distance_free (bdistance);
8123 rn->info = NULL;
8124 bgp_unlock_node (rn);
8125 bgp_unlock_node (rn);
8127 return CMD_SUCCESS;
8130 void
8131 bgp_distance_reset ()
8133 struct bgp_node *rn;
8134 struct bgp_distance *bdistance;
8136 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
8137 if ((bdistance = rn->info) != NULL)
8139 if (bdistance->access_list)
8140 free (bdistance->access_list);
8141 bgp_distance_free (bdistance);
8142 rn->info = NULL;
8143 bgp_unlock_node (rn);
8147 /* Apply BGP information to distance method. */
8148 u_char
8149 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
8151 struct bgp_node *rn;
8152 struct prefix_ipv4 q;
8153 struct peer *peer;
8154 struct bgp_distance *bdistance;
8155 struct access_list *alist;
8156 struct bgp_static *bgp_static;
8158 if (! bgp)
8159 return 0;
8161 if (p->family != AF_INET)
8162 return 0;
8164 peer = rinfo->peer;
8166 if (peer->su.sa.sa_family != AF_INET)
8167 return 0;
8169 memset (&q, 0, sizeof (struct prefix_ipv4));
8170 q.family = AF_INET;
8171 q.prefix = peer->su.sin.sin_addr;
8172 q.prefixlen = IPV4_MAX_BITLEN;
8174 /* Check source address. */
8175 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
8176 if (rn)
8178 bdistance = rn->info;
8179 bgp_unlock_node (rn);
8181 if (bdistance->access_list)
8183 alist = access_list_lookup (AFI_IP, bdistance->access_list);
8184 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
8185 return bdistance->distance;
8187 else
8188 return bdistance->distance;
8191 /* Backdoor check. */
8192 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
8193 if (rn)
8195 bgp_static = rn->info;
8196 bgp_unlock_node (rn);
8198 if (bgp_static->backdoor)
8200 if (bgp->distance_local)
8201 return bgp->distance_local;
8202 else
8203 return ZEBRA_IBGP_DISTANCE_DEFAULT;
8207 if (peer_sort (peer) == BGP_PEER_EBGP)
8209 if (bgp->distance_ebgp)
8210 return bgp->distance_ebgp;
8211 return ZEBRA_EBGP_DISTANCE_DEFAULT;
8213 else
8215 if (bgp->distance_ibgp)
8216 return bgp->distance_ibgp;
8217 return ZEBRA_IBGP_DISTANCE_DEFAULT;
8221 DEFUN (bgp_distance,
8222 bgp_distance_cmd,
8223 "distance bgp <1-255> <1-255> <1-255>",
8224 "Define an administrative distance\n"
8225 "BGP distance\n"
8226 "Distance for routes external to the AS\n"
8227 "Distance for routes internal to the AS\n"
8228 "Distance for local routes\n")
8230 struct bgp *bgp;
8232 bgp = vty->index;
8234 bgp->distance_ebgp = atoi (argv[0]);
8235 bgp->distance_ibgp = atoi (argv[1]);
8236 bgp->distance_local = atoi (argv[2]);
8237 return CMD_SUCCESS;
8240 DEFUN (no_bgp_distance,
8241 no_bgp_distance_cmd,
8242 "no distance bgp <1-255> <1-255> <1-255>",
8243 NO_STR
8244 "Define an administrative distance\n"
8245 "BGP distance\n"
8246 "Distance for routes external to the AS\n"
8247 "Distance for routes internal to the AS\n"
8248 "Distance for local routes\n")
8250 struct bgp *bgp;
8252 bgp = vty->index;
8254 bgp->distance_ebgp= 0;
8255 bgp->distance_ibgp = 0;
8256 bgp->distance_local = 0;
8257 return CMD_SUCCESS;
8260 ALIAS (no_bgp_distance,
8261 no_bgp_distance2_cmd,
8262 "no distance bgp",
8263 NO_STR
8264 "Define an administrative distance\n"
8265 "BGP distance\n");
8267 DEFUN (bgp_distance_source,
8268 bgp_distance_source_cmd,
8269 "distance <1-255> A.B.C.D/M",
8270 "Define an administrative distance\n"
8271 "Administrative distance\n"
8272 "IP source prefix\n")
8274 bgp_distance_set (vty, argv[0], argv[1], NULL);
8275 return CMD_SUCCESS;
8278 DEFUN (no_bgp_distance_source,
8279 no_bgp_distance_source_cmd,
8280 "no distance <1-255> A.B.C.D/M",
8281 NO_STR
8282 "Define an administrative distance\n"
8283 "Administrative distance\n"
8284 "IP source prefix\n")
8286 bgp_distance_unset (vty, argv[0], argv[1], NULL);
8287 return CMD_SUCCESS;
8290 DEFUN (bgp_distance_source_access_list,
8291 bgp_distance_source_access_list_cmd,
8292 "distance <1-255> A.B.C.D/M WORD",
8293 "Define an administrative distance\n"
8294 "Administrative distance\n"
8295 "IP source prefix\n"
8296 "Access list name\n")
8298 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
8299 return CMD_SUCCESS;
8302 DEFUN (no_bgp_distance_source_access_list,
8303 no_bgp_distance_source_access_list_cmd,
8304 "no distance <1-255> A.B.C.D/M WORD",
8305 NO_STR
8306 "Define an administrative distance\n"
8307 "Administrative distance\n"
8308 "IP source prefix\n"
8309 "Access list name\n")
8311 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
8312 return CMD_SUCCESS;
8315 DEFUN (bgp_damp_set,
8316 bgp_damp_set_cmd,
8317 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
8318 "BGP Specific commands\n"
8319 "Enable route-flap dampening\n"
8320 "Half-life time for the penalty\n"
8321 "Value to start reusing a route\n"
8322 "Value to start suppressing a route\n"
8323 "Maximum duration to suppress a stable route\n")
8325 struct bgp *bgp;
8326 int half = DEFAULT_HALF_LIFE * 60;
8327 int reuse = DEFAULT_REUSE;
8328 int suppress = DEFAULT_SUPPRESS;
8329 int max = 4 * half;
8331 if (argc == 4)
8333 half = atoi (argv[0]) * 60;
8334 reuse = atoi (argv[1]);
8335 suppress = atoi (argv[2]);
8336 max = atoi (argv[3]) * 60;
8338 else if (argc == 1)
8340 half = atoi (argv[0]) * 60;
8341 max = 4 * half;
8344 bgp = vty->index;
8345 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
8346 half, reuse, suppress, max);
8349 ALIAS (bgp_damp_set,
8350 bgp_damp_set2_cmd,
8351 "bgp dampening <1-45>",
8352 "BGP Specific commands\n"
8353 "Enable route-flap dampening\n"
8354 "Half-life time for the penalty\n");
8356 ALIAS (bgp_damp_set,
8357 bgp_damp_set3_cmd,
8358 "bgp dampening",
8359 "BGP Specific commands\n"
8360 "Enable route-flap dampening\n");
8362 DEFUN (bgp_damp_unset,
8363 bgp_damp_unset_cmd,
8364 "no bgp dampening",
8365 NO_STR
8366 "BGP Specific commands\n"
8367 "Enable route-flap dampening\n")
8369 struct bgp *bgp;
8371 bgp = vty->index;
8372 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
8375 ALIAS (bgp_damp_unset,
8376 bgp_damp_unset2_cmd,
8377 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
8378 NO_STR
8379 "BGP Specific commands\n"
8380 "Enable route-flap dampening\n"
8381 "Half-life time for the penalty\n"
8382 "Value to start reusing a route\n"
8383 "Value to start suppressing a route\n"
8384 "Maximum duration to suppress a stable route\n");
8386 DEFUN (show_ip_bgp_dampened_paths,
8387 show_ip_bgp_dampened_paths_cmd,
8388 "show ip bgp dampened-paths",
8389 SHOW_STR
8390 IP_STR
8391 BGP_STR
8392 "Display paths suppressed due to dampening\n")
8394 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths);
8397 DEFUN (show_ip_bgp_flap_statistics,
8398 show_ip_bgp_flap_statistics_cmd,
8399 "show ip bgp flap-statistics",
8400 SHOW_STR
8401 IP_STR
8402 BGP_STR
8403 "Display flap statistics of routes\n")
8405 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_flap_statistics);
8408 /* Display specified route of BGP table. */
8410 bgp_clear_damp_route (struct vty *vty, char *view_name, char *ip_str,
8411 afi_t afi, safi_t safi, struct prefix_rd *prd,
8412 int prefix_check)
8414 int ret;
8415 struct prefix match;
8416 struct bgp_node *rn;
8417 struct bgp_node *rm;
8418 struct bgp_info *ri;
8419 struct bgp_info *ri_temp;
8420 struct bgp *bgp;
8421 struct bgp_table *table;
8423 /* BGP structure lookup. */
8424 if (view_name)
8426 bgp = bgp_lookup_by_name (view_name);
8427 if (bgp == NULL)
8429 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8430 return CMD_WARNING;
8433 else
8435 bgp = bgp_get_default ();
8436 if (bgp == NULL)
8438 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
8439 return CMD_WARNING;
8443 /* Check IP address argument. */
8444 ret = str2prefix (ip_str, &match);
8445 if (! ret)
8447 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
8448 return CMD_WARNING;
8451 match.family = afi2family (afi);
8453 if (safi == SAFI_MPLS_VPN)
8455 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
8457 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8458 continue;
8460 if ((table = rn->info) != NULL)
8461 if ((rm = bgp_node_match (table, &match)) != NULL)
8462 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
8464 ri = rm->info;
8465 while (ri)
8467 if (ri->damp_info)
8469 ri_temp = ri->next;
8470 bgp_damp_info_free (ri->damp_info, 1);
8471 ri = ri_temp;
8473 else
8474 ri = ri->next;
8479 else
8481 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
8482 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8484 ri = rn->info;
8485 while (ri)
8487 if (ri->damp_info)
8489 ri_temp = ri->next;
8490 bgp_damp_info_free (ri->damp_info, 1);
8491 ri = ri_temp;
8493 else
8494 ri = ri->next;
8499 return CMD_SUCCESS;
8502 DEFUN (clear_ip_bgp_dampening,
8503 clear_ip_bgp_dampening_cmd,
8504 "clear ip bgp dampening",
8505 CLEAR_STR
8506 IP_STR
8507 BGP_STR
8508 "Clear route flap dampening information\n")
8510 bgp_damp_info_clean ();
8511 return CMD_SUCCESS;
8514 DEFUN (clear_ip_bgp_dampening_prefix,
8515 clear_ip_bgp_dampening_prefix_cmd,
8516 "clear ip bgp dampening A.B.C.D/M",
8517 CLEAR_STR
8518 IP_STR
8519 BGP_STR
8520 "Clear route flap dampening information\n"
8521 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8523 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
8524 SAFI_UNICAST, NULL, 1);
8527 DEFUN (clear_ip_bgp_dampening_address,
8528 clear_ip_bgp_dampening_address_cmd,
8529 "clear ip bgp dampening A.B.C.D",
8530 CLEAR_STR
8531 IP_STR
8532 BGP_STR
8533 "Clear route flap dampening information\n"
8534 "Network to clear damping information\n")
8536 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
8537 SAFI_UNICAST, NULL, 0);
8540 DEFUN (clear_ip_bgp_dampening_address_mask,
8541 clear_ip_bgp_dampening_address_mask_cmd,
8542 "clear ip bgp dampening A.B.C.D A.B.C.D",
8543 CLEAR_STR
8544 IP_STR
8545 BGP_STR
8546 "Clear route flap dampening information\n"
8547 "Network to clear damping information\n"
8548 "Network mask\n")
8550 int ret;
8551 char prefix_str[BUFSIZ];
8553 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
8554 if (! ret)
8556 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
8557 return CMD_WARNING;
8560 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
8561 SAFI_UNICAST, NULL, 0);
8565 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
8566 afi_t afi, safi_t safi, int *write)
8568 struct bgp_node *prn;
8569 struct bgp_node *rn;
8570 struct bgp_table *table;
8571 struct prefix *p;
8572 struct prefix_rd *prd;
8573 struct bgp_static *bgp_static;
8574 u_int32_t label;
8575 char buf[SU_ADDRSTRLEN];
8576 char rdbuf[RD_ADDRSTRLEN];
8578 /* Network configuration. */
8579 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
8580 if ((table = prn->info) != NULL)
8581 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8582 if ((bgp_static = rn->info) != NULL)
8584 p = &rn->p;
8585 prd = (struct prefix_rd *) &prn->p;
8587 /* "address-family" display. */
8588 bgp_config_write_family_header (vty, afi, safi, write);
8590 /* "network" configuration display. */
8591 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
8592 label = decode_label (bgp_static->tag);
8594 vty_out (vty, " network %s/%d rd %s tag %d",
8595 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
8596 p->prefixlen,
8597 rdbuf, label);
8598 vty_out (vty, "%s", VTY_NEWLINE);
8600 return 0;
8603 /* Configuration of static route announcement and aggregate
8604 information. */
8606 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
8607 afi_t afi, safi_t safi, int *write)
8609 struct bgp_node *rn;
8610 struct prefix *p;
8611 struct bgp_static *bgp_static;
8612 struct bgp_aggregate *bgp_aggregate;
8613 char buf[SU_ADDRSTRLEN];
8615 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8616 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
8618 /* Network configuration. */
8619 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
8620 if ((bgp_static = rn->info) != NULL)
8622 p = &rn->p;
8624 /* "address-family" display. */
8625 bgp_config_write_family_header (vty, afi, safi, write);
8627 /* "network" configuration display. */
8628 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
8630 u_int32_t destination;
8631 struct in_addr netmask;
8633 destination = ntohl (p->u.prefix4.s_addr);
8634 masklen2ip (p->prefixlen, &netmask);
8635 vty_out (vty, " network %s",
8636 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
8638 if ((IN_CLASSC (destination) && p->prefixlen == 24)
8639 || (IN_CLASSB (destination) && p->prefixlen == 16)
8640 || (IN_CLASSA (destination) && p->prefixlen == 8)
8641 || p->u.prefix4.s_addr == 0)
8643 /* Natural mask is not display. */
8645 else
8646 vty_out (vty, " mask %s", inet_ntoa (netmask));
8648 else
8650 vty_out (vty, " network %s/%d",
8651 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
8652 p->prefixlen);
8655 if (bgp_static->rmap.name)
8656 vty_out (vty, " route-map %s", bgp_static->rmap.name);
8657 else if (bgp_static->backdoor)
8658 vty_out (vty, " backdoor");
8660 vty_out (vty, "%s", VTY_NEWLINE);
8663 /* Aggregate-address configuration. */
8664 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
8665 if ((bgp_aggregate = rn->info) != NULL)
8667 p = &rn->p;
8669 /* "address-family" display. */
8670 bgp_config_write_family_header (vty, afi, safi, write);
8672 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
8674 struct in_addr netmask;
8676 masklen2ip (p->prefixlen, &netmask);
8677 vty_out (vty, " aggregate-address %s %s",
8678 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
8679 inet_ntoa (netmask));
8681 else
8683 vty_out (vty, " aggregate-address %s/%d",
8684 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
8685 p->prefixlen);
8688 if (bgp_aggregate->as_set)
8689 vty_out (vty, " as-set");
8691 if (bgp_aggregate->summary_only)
8692 vty_out (vty, " summary-only");
8694 vty_out (vty, "%s", VTY_NEWLINE);
8697 return 0;
8701 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
8703 struct bgp_node *rn;
8704 struct bgp_distance *bdistance;
8706 /* Distance configuration. */
8707 if (bgp->distance_ebgp
8708 && bgp->distance_ibgp
8709 && bgp->distance_local
8710 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
8711 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
8712 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
8713 vty_out (vty, " distance bgp %d %d %d%s",
8714 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
8715 VTY_NEWLINE);
8717 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
8718 if ((bdistance = rn->info) != NULL)
8720 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
8721 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
8722 bdistance->access_list ? bdistance->access_list : "",
8723 VTY_NEWLINE);
8726 return 0;
8729 /* Allocate routing table structure and install commands. */
8730 void
8731 bgp_route_init ()
8733 /* Init BGP distance table. */
8734 bgp_distance_table = bgp_table_init ();
8736 /* IPv4 BGP commands. */
8737 install_element (BGP_NODE, &bgp_network_cmd);
8738 install_element (BGP_NODE, &bgp_network_mask_cmd);
8739 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
8740 install_element (BGP_NODE, &bgp_network_route_map_cmd);
8741 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
8742 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
8743 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
8744 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
8745 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
8746 install_element (BGP_NODE, &no_bgp_network_cmd);
8747 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
8748 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
8749 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
8750 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
8751 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
8752 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
8753 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
8754 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
8756 install_element (BGP_NODE, &aggregate_address_cmd);
8757 install_element (BGP_NODE, &aggregate_address_mask_cmd);
8758 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
8759 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
8760 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
8761 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
8762 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
8763 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
8764 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
8765 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
8766 install_element (BGP_NODE, &no_aggregate_address_cmd);
8767 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
8768 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
8769 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
8770 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
8771 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
8772 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
8773 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
8774 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
8775 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
8777 /* IPv4 unicast configuration. */
8778 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
8779 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
8780 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
8781 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
8782 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
8783 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
8784 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
8785 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
8786 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
8787 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
8788 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
8789 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
8790 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
8791 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
8792 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
8793 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
8794 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
8795 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
8796 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
8797 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
8798 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
8799 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
8800 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
8801 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
8802 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
8803 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
8804 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
8805 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
8806 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
8807 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
8808 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
8809 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
8811 /* IPv4 multicast configuration. */
8812 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
8813 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
8814 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
8815 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
8816 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
8817 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
8818 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
8819 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
8820 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
8821 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
8822 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
8823 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
8824 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
8825 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
8826 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
8827 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
8828 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
8829 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
8830 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
8831 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
8832 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
8833 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
8834 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
8835 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
8836 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
8837 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
8838 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
8839 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
8840 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
8841 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
8842 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
8843 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
8845 install_element (VIEW_NODE, &show_ip_bgp_cmd);
8846 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
8847 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
8848 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
8849 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
8850 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
8851 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
8852 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
8853 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
8854 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
8855 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
8856 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
8857 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
8858 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
8859 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
8860 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
8861 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
8862 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
8863 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
8864 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
8865 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
8866 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
8867 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
8868 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
8869 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
8870 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
8871 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
8872 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
8873 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
8874 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
8875 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
8876 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
8877 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
8878 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
8879 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
8880 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
8881 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
8882 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
8883 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
8884 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
8885 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
8886 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
8887 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
8888 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
8889 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
8890 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
8891 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
8892 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
8893 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
8894 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
8895 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
8896 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
8897 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
8898 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
8899 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
8900 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
8901 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
8902 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
8903 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
8904 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
8905 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
8906 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
8907 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
8908 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
8909 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
8910 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
8911 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
8913 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
8914 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
8915 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
8916 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
8917 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
8918 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
8919 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
8920 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
8921 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
8922 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
8923 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
8924 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
8925 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
8926 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
8927 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
8928 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
8929 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
8930 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
8931 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
8932 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
8933 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
8934 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
8935 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
8936 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
8937 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
8938 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
8939 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
8940 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
8941 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
8942 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
8943 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
8944 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
8945 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
8946 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
8947 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
8948 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
8949 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
8950 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
8951 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
8952 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
8953 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
8954 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
8955 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
8956 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
8957 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
8958 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
8959 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
8960 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
8961 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
8962 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
8963 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
8964 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
8965 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
8966 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
8967 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
8968 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
8969 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
8970 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
8971 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
8972 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
8973 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
8974 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
8975 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
8976 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
8977 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
8978 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
8979 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
8981 /* BGP dampening clear commands */
8982 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
8983 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
8984 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
8985 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
8987 #ifdef HAVE_IPV6
8988 /* New config IPv6 BGP commands. */
8989 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
8990 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
8991 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
8992 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
8994 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
8995 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
8996 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
8997 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
8999 /* Old config IPv6 BGP commands. */
9000 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
9001 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
9003 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
9004 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
9005 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
9006 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
9008 install_element (VIEW_NODE, &show_bgp_cmd);
9009 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
9010 install_element (VIEW_NODE, &show_bgp_route_cmd);
9011 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
9012 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
9013 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
9014 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
9015 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
9016 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
9017 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
9018 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
9019 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
9020 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
9021 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
9022 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
9023 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
9024 install_element (VIEW_NODE, &show_bgp_community_cmd);
9025 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
9026 install_element (VIEW_NODE, &show_bgp_community2_cmd);
9027 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
9028 install_element (VIEW_NODE, &show_bgp_community3_cmd);
9029 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
9030 install_element (VIEW_NODE, &show_bgp_community4_cmd);
9031 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
9032 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
9033 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
9034 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
9035 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
9036 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
9037 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
9038 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
9039 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
9040 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
9041 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
9042 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
9043 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
9044 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
9045 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
9046 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
9047 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
9048 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
9049 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
9050 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
9051 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
9052 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
9053 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
9055 install_element (ENABLE_NODE, &show_bgp_cmd);
9056 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
9057 install_element (ENABLE_NODE, &show_bgp_route_cmd);
9058 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
9059 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
9060 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
9061 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
9062 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
9063 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
9064 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
9065 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
9066 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
9067 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
9068 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
9069 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
9070 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
9071 install_element (ENABLE_NODE, &show_bgp_community_cmd);
9072 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
9073 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
9074 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
9075 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
9076 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
9077 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
9078 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
9079 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
9080 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
9081 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
9082 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
9083 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
9084 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
9085 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
9086 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
9087 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
9088 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
9089 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
9090 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
9091 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
9092 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
9093 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
9094 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
9095 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
9096 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
9097 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
9098 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
9099 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
9100 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
9102 /* old command */
9103 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
9104 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
9105 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
9106 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
9107 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
9108 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
9109 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
9110 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
9111 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
9112 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
9113 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
9114 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
9115 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
9116 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
9117 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
9118 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
9119 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
9120 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
9121 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
9122 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
9123 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
9124 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
9125 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
9126 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
9127 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
9128 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
9129 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
9130 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
9131 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
9132 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
9133 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
9134 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
9135 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
9136 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
9137 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
9138 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
9140 /* old command */
9141 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
9142 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
9143 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
9144 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
9145 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
9146 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
9147 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
9148 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
9149 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
9150 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
9151 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
9152 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
9153 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
9154 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
9155 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
9156 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
9157 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
9158 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
9159 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
9160 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
9161 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
9162 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
9163 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
9164 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
9165 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
9166 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
9167 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
9168 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
9169 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
9170 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
9171 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
9172 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
9173 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
9174 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
9175 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
9176 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
9178 /* old command */
9179 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
9180 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
9181 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
9182 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
9184 /* old command */
9185 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
9186 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
9187 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
9188 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
9190 /* old command */
9191 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
9192 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
9193 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
9194 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
9195 #endif /* HAVE_IPV6 */
9197 install_element (BGP_NODE, &bgp_distance_cmd);
9198 install_element (BGP_NODE, &no_bgp_distance_cmd);
9199 install_element (BGP_NODE, &no_bgp_distance2_cmd);
9200 install_element (BGP_NODE, &bgp_distance_source_cmd);
9201 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
9202 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
9203 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
9205 install_element (BGP_NODE, &bgp_damp_set_cmd);
9206 install_element (BGP_NODE, &bgp_damp_set2_cmd);
9207 install_element (BGP_NODE, &bgp_damp_set3_cmd);
9208 install_element (BGP_NODE, &bgp_damp_unset_cmd);
9209 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
9210 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
9211 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
9212 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
9213 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
9214 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);