[git administrivia] remove auto-built quagga.info, add to gitignore.
[jleu-quagga.git] / bgpd / bgp_route.c
blob0658cabe35db52f1457f17902853c53531aba7c0
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"
36 #include "workqueue.h"
38 #include "bgpd/bgpd.h"
39 #include "bgpd/bgp_table.h"
40 #include "bgpd/bgp_route.h"
41 #include "bgpd/bgp_attr.h"
42 #include "bgpd/bgp_debug.h"
43 #include "bgpd/bgp_aspath.h"
44 #include "bgpd/bgp_regex.h"
45 #include "bgpd/bgp_community.h"
46 #include "bgpd/bgp_ecommunity.h"
47 #include "bgpd/bgp_clist.h"
48 #include "bgpd/bgp_packet.h"
49 #include "bgpd/bgp_filter.h"
50 #include "bgpd/bgp_fsm.h"
51 #include "bgpd/bgp_mplsvpn.h"
52 #include "bgpd/bgp_nexthop.h"
53 #include "bgpd/bgp_damp.h"
54 #include "bgpd/bgp_advertise.h"
55 #include "bgpd/bgp_zebra.h"
56 #include "bgpd/bgp_vty.h"
58 /* Extern from bgp_dump.c */
59 extern char *bgp_origin_str[];
60 extern char *bgp_origin_long_str[];
62 static struct bgp_node *
63 bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
64 struct prefix_rd *prd)
66 struct bgp_node *rn;
67 struct bgp_node *prn = NULL;
69 if (safi == SAFI_MPLS_VPN)
71 prn = bgp_node_get (table, (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;
80 rn = bgp_node_get (table, p);
82 if (safi == SAFI_MPLS_VPN)
83 rn->prn = prn;
85 return rn;
88 /* Allocate new bgp info structure. */
89 static struct bgp_info *
90 bgp_info_new ()
92 struct bgp_info *new;
94 new = XMALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
95 memset (new, 0, sizeof (struct bgp_info));
97 return new;
100 /* Free bgp route information. */
101 static void
102 bgp_info_free (struct bgp_info *binfo)
104 if (binfo->attr)
105 bgp_attr_unintern (binfo->attr);
107 if (binfo->damp_info)
108 bgp_damp_info_free (binfo->damp_info, 0);
110 peer_unlock (binfo->peer); /* bgp_info peer reference */
112 XFREE (MTYPE_BGP_ROUTE, binfo);
115 struct bgp_info *
116 bgp_info_lock (struct bgp_info *binfo)
118 binfo->lock++;
119 return binfo;
122 struct bgp_info *
123 bgp_info_unlock (struct bgp_info *binfo)
125 assert (binfo && binfo->lock > 0);
126 binfo->lock--;
128 if (binfo->lock == 0)
130 #if 0
131 zlog_debug ("%s: unlocked and freeing", __func__);
132 zlog_backtrace (LOG_DEBUG);
133 #endif
134 bgp_info_free (binfo);
135 return NULL;
138 #if 0
139 if (binfo->lock == 1)
141 zlog_debug ("%s: unlocked to 1", __func__);
142 zlog_backtrace (LOG_DEBUG);
144 #endif
146 return binfo;
149 void
150 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
152 struct bgp_info *top;
154 top = rn->info;
156 ri->next = rn->info;
157 ri->prev = NULL;
158 if (top)
159 top->prev = ri;
160 rn->info = ri;
162 bgp_info_lock (ri);
163 bgp_lock_node (rn);
164 peer_lock (ri->peer); /* bgp_info peer reference */
167 /* Do the actual removal of info from RIB, for use by bgp_process
168 completion callback *only* */
169 static void
170 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
172 if (ri->next)
173 ri->next->prev = ri->prev;
174 if (ri->prev)
175 ri->prev->next = ri->next;
176 else
177 rn->info = ri->next;
179 bgp_info_unlock (ri);
180 bgp_unlock_node (rn);
183 void
184 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
186 /* leave info in place for now in place for now,
187 * bgp_process will reap it later. */
188 SET_FLAG (ri->flags, BGP_INFO_REMOVED);
189 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
192 /* Get MED value. If MED value is missing and "bgp bestpath
193 missing-as-worst" is specified, treat it as the worst value. */
194 static u_int32_t
195 bgp_med_value (struct attr *attr, struct bgp *bgp)
197 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
198 return attr->med;
199 else
201 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
202 return BGP_MED_MAX;
203 else
204 return 0;
208 /* Compare two bgp route entity. br is preferable then return 1. */
209 static int
210 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
212 u_int32_t new_pref;
213 u_int32_t exist_pref;
214 u_int32_t new_med;
215 u_int32_t exist_med;
216 struct in_addr new_id;
217 struct in_addr exist_id;
218 int new_cluster;
219 int exist_cluster;
220 int internal_as_route = 0;
221 int confed_as_route = 0;
222 int ret;
224 /* 0. Null check. */
225 if (new == NULL)
226 return 0;
227 if (exist == NULL)
228 return 1;
230 /* 1. Weight check. */
231 if (new->attr->weight > exist->attr->weight)
232 return 1;
233 if (new->attr->weight < exist->attr->weight)
234 return 0;
236 /* 2. Local preference check. */
237 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
238 new_pref = new->attr->local_pref;
239 else
240 new_pref = bgp->default_local_pref;
242 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
243 exist_pref = exist->attr->local_pref;
244 else
245 exist_pref = bgp->default_local_pref;
247 if (new_pref > exist_pref)
248 return 1;
249 if (new_pref < exist_pref)
250 return 0;
252 /* 3. Local route check. */
253 if (new->sub_type == BGP_ROUTE_STATIC)
254 return 1;
255 if (exist->sub_type == BGP_ROUTE_STATIC)
256 return 0;
258 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
259 return 1;
260 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
261 return 0;
263 if (new->sub_type == BGP_ROUTE_AGGREGATE)
264 return 1;
265 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
266 return 0;
268 /* 4. AS path length check. */
269 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
271 int exist_hops = aspath_count_hops (exist->attr->aspath);
272 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
274 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
276 int aspath_hops;
278 aspath_hops = aspath_count_hops (new->attr->aspath);
279 aspath_hops += aspath_count_confeds (new->attr->aspath);
281 if ( aspath_hops < (exist_hops + exist_confeds))
282 return 1;
283 if ( aspath_hops > (exist_hops + exist_confeds))
284 return 0;
286 else
288 int newhops = aspath_count_hops (new->attr->aspath);
290 if (newhops < exist_hops)
291 return 1;
292 if (newhops > exist_hops)
293 return 0;
297 /* 5. Origin check. */
298 if (new->attr->origin < exist->attr->origin)
299 return 1;
300 if (new->attr->origin > exist->attr->origin)
301 return 0;
303 /* 6. MED check. */
304 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
305 && aspath_count_hops (exist->attr->aspath) == 0);
306 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
307 && aspath_count_confeds (exist->attr->aspath) > 0
308 && aspath_count_hops (new->attr->aspath) == 0
309 && aspath_count_hops (exist->attr->aspath) == 0);
311 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
312 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
313 && confed_as_route)
314 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
315 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
316 || internal_as_route)
318 new_med = bgp_med_value (new->attr, bgp);
319 exist_med = bgp_med_value (exist->attr, bgp);
321 if (new_med < exist_med)
322 return 1;
323 if (new_med > exist_med)
324 return 0;
327 /* 7. Peer type check. */
328 if (peer_sort (new->peer) == BGP_PEER_EBGP
329 && peer_sort (exist->peer) == BGP_PEER_IBGP)
330 return 1;
331 if (peer_sort (new->peer) == BGP_PEER_EBGP
332 && peer_sort (exist->peer) == BGP_PEER_CONFED)
333 return 1;
334 if (peer_sort (new->peer) == BGP_PEER_IBGP
335 && peer_sort (exist->peer) == BGP_PEER_EBGP)
336 return 0;
337 if (peer_sort (new->peer) == BGP_PEER_CONFED
338 && peer_sort (exist->peer) == BGP_PEER_EBGP)
339 return 0;
341 /* 8. IGP metric check. */
342 if (new->igpmetric < exist->igpmetric)
343 return 1;
344 if (new->igpmetric > exist->igpmetric)
345 return 0;
347 /* 9. Maximum path check. */
349 /* 10. If both paths are external, prefer the path that was received
350 first (the oldest one). This step minimizes route-flap, since a
351 newer path won't displace an older one, even if it was the
352 preferred route based on the additional decision criteria below. */
353 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
354 && peer_sort (new->peer) == BGP_PEER_EBGP
355 && peer_sort (exist->peer) == BGP_PEER_EBGP)
357 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
358 return 1;
359 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
360 return 0;
363 /* 11. Rourter-ID comparision. */
364 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
365 new_id.s_addr = new->attr->originator_id.s_addr;
366 else
367 new_id.s_addr = new->peer->remote_id.s_addr;
368 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
369 exist_id.s_addr = exist->attr->originator_id.s_addr;
370 else
371 exist_id.s_addr = exist->peer->remote_id.s_addr;
373 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
374 return 1;
375 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
376 return 0;
378 /* 12. Cluster length comparision. */
379 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
380 new_cluster = new->attr->cluster->length;
381 else
382 new_cluster = 0;
383 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
384 exist_cluster = exist->attr->cluster->length;
385 else
386 exist_cluster = 0;
388 if (new_cluster < exist_cluster)
389 return 1;
390 if (new_cluster > exist_cluster)
391 return 0;
393 /* 13. Neighbor address comparision. */
394 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
396 if (ret == 1)
397 return 0;
398 if (ret == -1)
399 return 1;
401 return 1;
404 static enum filter_type
405 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
406 afi_t afi, safi_t safi)
408 struct bgp_filter *filter;
410 filter = &peer->filter[afi][safi];
412 if (DISTRIBUTE_IN_NAME (filter))
413 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
414 return FILTER_DENY;
416 if (PREFIX_LIST_IN_NAME (filter))
417 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
418 return FILTER_DENY;
420 if (FILTER_LIST_IN_NAME (filter))
421 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
422 return FILTER_DENY;
424 return FILTER_PERMIT;
427 static enum filter_type
428 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
429 afi_t afi, safi_t safi)
431 struct bgp_filter *filter;
433 filter = &peer->filter[afi][safi];
435 if (DISTRIBUTE_OUT_NAME (filter))
436 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
437 return FILTER_DENY;
439 if (PREFIX_LIST_OUT_NAME (filter))
440 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
441 return FILTER_DENY;
443 if (FILTER_LIST_OUT_NAME (filter))
444 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
445 return FILTER_DENY;
447 return FILTER_PERMIT;
450 /* If community attribute includes no_export then return 1. */
451 static int
452 bgp_community_filter (struct peer *peer, struct attr *attr)
454 if (attr->community)
456 /* NO_ADVERTISE check. */
457 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
458 return 1;
460 /* NO_EXPORT check. */
461 if (peer_sort (peer) == BGP_PEER_EBGP &&
462 community_include (attr->community, COMMUNITY_NO_EXPORT))
463 return 1;
465 /* NO_EXPORT_SUBCONFED check. */
466 if (peer_sort (peer) == BGP_PEER_EBGP
467 || peer_sort (peer) == BGP_PEER_CONFED)
468 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
469 return 1;
471 return 0;
474 /* Route reflection loop check. */
475 static int
476 bgp_cluster_filter (struct peer *peer, struct attr *attr)
478 struct in_addr cluster_id;
480 if (attr->cluster)
482 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
483 cluster_id = peer->bgp->cluster_id;
484 else
485 cluster_id = peer->bgp->router_id;
487 if (cluster_loop_check (attr->cluster, cluster_id))
488 return 1;
490 return 0;
493 static int
494 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
495 afi_t afi, safi_t safi)
497 struct bgp_filter *filter;
498 struct bgp_info info;
499 route_map_result_t ret;
501 filter = &peer->filter[afi][safi];
503 /* Apply default weight value. */
504 attr->weight = peer->weight;
506 /* Route map apply. */
507 if (ROUTE_MAP_IN_NAME (filter))
509 /* Duplicate current value to new strucutre for modification. */
510 info.peer = peer;
511 info.attr = attr;
513 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
515 /* Apply BGP route map to the attribute. */
516 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
518 peer->rmap_type = 0;
520 if (ret == RMAP_DENYMATCH)
522 /* Free newly generated AS path and community by route-map. */
523 bgp_attr_flush (attr);
524 return RMAP_DENY;
527 return RMAP_PERMIT;
530 static int
531 bgp_export_modifier (struct peer *rsclient, struct peer *peer,
532 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
534 struct bgp_filter *filter;
535 struct bgp_info info;
536 route_map_result_t ret;
538 filter = &peer->filter[afi][safi];
540 /* Route map apply. */
541 if (ROUTE_MAP_EXPORT_NAME (filter))
543 /* Duplicate current value to new strucutre for modification. */
544 info.peer = rsclient;
545 info.attr = attr;
547 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
549 /* Apply BGP route map to the attribute. */
550 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
552 rsclient->rmap_type = 0;
554 if (ret == RMAP_DENYMATCH)
556 /* Free newly generated AS path and community by route-map. */
557 bgp_attr_flush (attr);
558 return RMAP_DENY;
561 return RMAP_PERMIT;
564 static int
565 bgp_import_modifier (struct peer *rsclient, struct peer *peer,
566 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
568 struct bgp_filter *filter;
569 struct bgp_info info;
570 route_map_result_t ret;
572 filter = &rsclient->filter[afi][safi];
574 /* Apply default weight value. */
575 attr->weight = peer->weight;
577 /* Route map apply. */
578 if (ROUTE_MAP_IMPORT_NAME (filter))
580 /* Duplicate current value to new strucutre for modification. */
581 info.peer = peer;
582 info.attr = attr;
584 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
586 /* Apply BGP route map to the attribute. */
587 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
589 peer->rmap_type = 0;
591 if (ret == RMAP_DENYMATCH)
593 /* Free newly generated AS path and community by route-map. */
594 bgp_attr_flush (attr);
595 return RMAP_DENY;
598 return RMAP_PERMIT;
601 static int
602 bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
603 struct attr *attr, afi_t afi, safi_t safi)
605 int ret;
606 char buf[SU_ADDRSTRLEN];
607 struct bgp_filter *filter;
608 struct bgp_info info;
609 struct peer *from;
610 struct bgp *bgp;
611 struct attr dummy_attr;
612 int transparent;
613 int reflect;
615 from = ri->peer;
616 filter = &peer->filter[afi][safi];
617 bgp = peer->bgp;
619 #ifdef DISABLE_BGP_ANNOUNCE
620 return 0;
621 #endif
623 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
624 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
625 return 0;
627 /* Do not send back route to sender. */
628 if (from == peer)
629 return 0;
631 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
632 if (p->family == AF_INET
633 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
634 return 0;
635 #ifdef HAVE_IPV6
636 if (p->family == AF_INET6
637 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
638 return 0;
639 #endif
641 /* Aggregate-address suppress check. */
642 if (ri->suppress)
643 if (! UNSUPPRESS_MAP_NAME (filter))
644 return 0;
646 /* Default route check. */
647 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
649 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
650 return 0;
651 #ifdef HAVE_IPV6
652 else if (p->family == AF_INET6 && p->prefixlen == 0)
653 return 0;
654 #endif /* HAVE_IPV6 */
657 /* Transparency check. */
658 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
659 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
660 transparent = 1;
661 else
662 transparent = 0;
664 /* If community is not disabled check the no-export and local. */
665 if (! transparent && bgp_community_filter (peer, ri->attr))
666 return 0;
668 /* If the attribute has originator-id and it is same as remote
669 peer's id. */
670 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
672 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
674 if (BGP_DEBUG (filter, FILTER))
675 zlog (peer->log, LOG_DEBUG,
676 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
677 peer->host,
678 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
679 p->prefixlen);
680 return 0;
684 /* ORF prefix-list filter check */
685 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
686 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
687 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
688 if (peer->orf_plist[afi][safi])
690 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
691 return 0;
694 /* Output filter check. */
695 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
697 if (BGP_DEBUG (filter, FILTER))
698 zlog (peer->log, LOG_DEBUG,
699 "%s [Update:SEND] %s/%d is filtered",
700 peer->host,
701 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
702 p->prefixlen);
703 return 0;
706 #ifdef BGP_SEND_ASPATH_CHECK
707 /* AS path loop check. */
708 if (aspath_loop_check (ri->attr->aspath, peer->as))
710 if (BGP_DEBUG (filter, FILTER))
711 zlog (peer->log, LOG_DEBUG,
712 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
713 peer->host, peer->as);
714 return 0;
716 #endif /* BGP_SEND_ASPATH_CHECK */
718 /* If we're a CONFED we need to loop check the CONFED ID too */
719 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
721 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
723 if (BGP_DEBUG (filter, FILTER))
724 zlog (peer->log, LOG_DEBUG,
725 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
726 peer->host,
727 bgp->confed_id);
728 return 0;
732 /* Route-Reflect check. */
733 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
734 reflect = 1;
735 else
736 reflect = 0;
738 /* IBGP reflection check. */
739 if (reflect)
741 /* A route from a Client peer. */
742 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
744 /* Reflect to all the Non-Client peers and also to the
745 Client peers other than the originator. Originator check
746 is already done. So there is noting to do. */
747 /* no bgp client-to-client reflection check. */
748 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
749 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
750 return 0;
752 else
754 /* A route from a Non-client peer. Reflect to all other
755 clients. */
756 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
757 return 0;
761 /* For modify attribute, copy it to temporary structure. */
762 *attr = *ri->attr;
764 /* If local-preference is not set. */
765 if ((peer_sort (peer) == BGP_PEER_IBGP
766 || peer_sort (peer) == BGP_PEER_CONFED)
767 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
769 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
770 attr->local_pref = bgp->default_local_pref;
773 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
774 if (peer_sort (peer) == BGP_PEER_EBGP
775 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
777 if (ri->peer != bgp->peer_self && ! transparent
778 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
779 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
782 /* next-hop-set */
783 if (transparent || reflect
784 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
785 && ((p->family == AF_INET && attr->nexthop.s_addr)
786 #ifdef HAVE_IPV6
787 || (p->family == AF_INET6 &&
788 ! IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
789 #endif /* HAVE_IPV6 */
792 /* NEXT-HOP Unchanged. */
794 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
795 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
796 #ifdef HAVE_IPV6
797 || (p->family == AF_INET6 &&
798 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
799 #endif /* HAVE_IPV6 */
800 || (peer_sort (peer) == BGP_PEER_EBGP
801 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
803 /* Set IPv4 nexthop. */
804 if (p->family == AF_INET)
806 if (safi == SAFI_MPLS_VPN)
807 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
808 else
809 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
811 #ifdef HAVE_IPV6
812 /* Set IPv6 nexthop. */
813 if (p->family == AF_INET6)
815 /* IPv6 global nexthop must be included. */
816 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
817 IPV6_MAX_BYTELEN);
818 attr->mp_nexthop_len = 16;
820 #endif /* HAVE_IPV6 */
823 #ifdef HAVE_IPV6
824 if (p->family == AF_INET6)
826 /* Left nexthop_local unchanged if so configured. */
827 if ( CHECK_FLAG (peer->af_flags[afi][safi],
828 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
830 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
831 attr->mp_nexthop_len=32;
832 else
833 attr->mp_nexthop_len=16;
836 /* Default nexthop_local treatment for non-RS-Clients */
837 else
839 /* Link-local address should not be transit to different peer. */
840 attr->mp_nexthop_len = 16;
842 /* Set link-local address for shared network peer. */
843 if (peer->shared_network
844 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
846 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
847 IPV6_MAX_BYTELEN);
848 attr->mp_nexthop_len = 32;
851 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
852 address.*/
853 if (reflect)
854 attr->mp_nexthop_len = 16;
856 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
857 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
858 attr->mp_nexthop_len = 16;
862 #endif /* HAVE_IPV6 */
864 /* If this is EBGP peer and remove-private-AS is set. */
865 if (peer_sort (peer) == BGP_PEER_EBGP
866 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
867 && aspath_private_as_check (attr->aspath))
868 attr->aspath = aspath_empty_get ();
870 /* Route map & unsuppress-map apply. */
871 if (ROUTE_MAP_OUT_NAME (filter)
872 || ri->suppress)
874 info.peer = peer;
875 info.attr = attr;
877 /* The route reflector is not allowed to modify the attributes
878 of the reflected IBGP routes. */
879 if (peer_sort (from) == BGP_PEER_IBGP
880 && peer_sort (peer) == BGP_PEER_IBGP)
882 dummy_attr = *attr;
883 info.attr = &dummy_attr;
886 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
888 if (ri->suppress)
889 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
890 else
891 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
893 peer->rmap_type = 0;
895 if (ret == RMAP_DENYMATCH)
897 bgp_attr_flush (attr);
898 return 0;
901 return 1;
904 static int
905 bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
906 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
908 int ret;
909 char buf[SU_ADDRSTRLEN];
910 struct bgp_filter *filter;
911 struct bgp_info info;
912 struct peer *from;
913 struct bgp *bgp;
915 from = ri->peer;
916 filter = &rsclient->filter[afi][safi];
917 bgp = rsclient->bgp;
919 #ifdef DISABLE_BGP_ANNOUNCE
920 return 0;
921 #endif
923 /* Do not send back route to sender. */
924 if (from == rsclient)
925 return 0;
927 /* Aggregate-address suppress check. */
928 if (ri->suppress)
929 if (! UNSUPPRESS_MAP_NAME (filter))
930 return 0;
932 /* Default route check. */
933 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
934 PEER_STATUS_DEFAULT_ORIGINATE))
936 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
937 return 0;
938 #ifdef HAVE_IPV6
939 else if (p->family == AF_INET6 && p->prefixlen == 0)
940 return 0;
941 #endif /* HAVE_IPV6 */
944 /* If the attribute has originator-id and it is same as remote
945 peer's id. */
946 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
948 if (IPV4_ADDR_SAME (&rsclient->remote_id, &ri->attr->originator_id))
950 if (BGP_DEBUG (filter, FILTER))
951 zlog (rsclient->log, LOG_DEBUG,
952 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
953 rsclient->host,
954 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
955 p->prefixlen);
956 return 0;
960 /* ORF prefix-list filter check */
961 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
962 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
963 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
964 if (rsclient->orf_plist[afi][safi])
966 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
967 return 0;
970 /* Output filter check. */
971 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
973 if (BGP_DEBUG (filter, FILTER))
974 zlog (rsclient->log, LOG_DEBUG,
975 "%s [Update:SEND] %s/%d is filtered",
976 rsclient->host,
977 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
978 p->prefixlen);
979 return 0;
982 #ifdef BGP_SEND_ASPATH_CHECK
983 /* AS path loop check. */
984 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
986 if (BGP_DEBUG (filter, FILTER))
987 zlog (rsclient->log, LOG_DEBUG,
988 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
989 rsclient->host, rsclient->as);
990 return 0;
992 #endif /* BGP_SEND_ASPATH_CHECK */
994 /* For modify attribute, copy it to temporary structure. */
995 *attr = *ri->attr;
997 /* next-hop-set */
998 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
999 #ifdef HAVE_IPV6
1000 || (p->family == AF_INET6 &&
1001 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
1002 #endif /* HAVE_IPV6 */
1005 /* Set IPv4 nexthop. */
1006 if (p->family == AF_INET)
1008 if (safi == SAFI_MPLS_VPN)
1009 memcpy (&attr->mp_nexthop_global_in, &rsclient->nexthop.v4,
1010 IPV4_MAX_BYTELEN);
1011 else
1012 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1014 #ifdef HAVE_IPV6
1015 /* Set IPv6 nexthop. */
1016 if (p->family == AF_INET6)
1018 /* IPv6 global nexthop must be included. */
1019 memcpy (&attr->mp_nexthop_global, &rsclient->nexthop.v6_global,
1021 IPV6_MAX_BYTELEN);
1022 attr->mp_nexthop_len = 16;
1024 #endif /* HAVE_IPV6 */
1027 #ifdef HAVE_IPV6
1028 if (p->family == AF_INET6)
1030 /* Left nexthop_local unchanged if so configured. */
1031 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1032 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1034 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1035 attr->mp_nexthop_len=32;
1036 else
1037 attr->mp_nexthop_len=16;
1040 /* Default nexthop_local treatment for RS-Clients */
1041 else
1043 /* Announcer and RS-Client are both in the same network */
1044 if (rsclient->shared_network && from->shared_network &&
1045 (rsclient->ifindex == from->ifindex))
1047 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1048 attr->mp_nexthop_len=32;
1049 else
1050 attr->mp_nexthop_len=16;
1053 /* Set link-local address for shared network peer. */
1054 else if (rsclient->shared_network
1055 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1057 memcpy (&attr->mp_nexthop_local, &rsclient->nexthop.v6_local,
1058 IPV6_MAX_BYTELEN);
1059 attr->mp_nexthop_len = 32;
1062 else
1063 attr->mp_nexthop_len = 16;
1067 #endif /* HAVE_IPV6 */
1070 /* If this is EBGP peer and remove-private-AS is set. */
1071 if (peer_sort (rsclient) == BGP_PEER_EBGP
1072 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1073 && aspath_private_as_check (attr->aspath))
1074 attr->aspath = aspath_empty_get ();
1076 /* Route map & unsuppress-map apply. */
1077 if (ROUTE_MAP_OUT_NAME (filter) || ri->suppress)
1079 info.peer = rsclient;
1080 info.attr = attr;
1082 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1084 if (ri->suppress)
1085 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1086 else
1087 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1089 rsclient->rmap_type = 0;
1091 if (ret == RMAP_DENYMATCH)
1093 bgp_attr_flush (attr);
1094 return 0;
1098 return 1;
1101 struct bgp_info_pair
1103 struct bgp_info *old;
1104 struct bgp_info *new;
1107 static void
1108 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1110 struct bgp_info *new_select;
1111 struct bgp_info *old_select;
1112 struct bgp_info *ri;
1113 struct bgp_info *ri1;
1114 struct bgp_info *ri2;
1115 struct bgp_info *nextri = NULL;
1117 /* bgp deterministic-med */
1118 new_select = NULL;
1119 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1120 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1122 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1123 continue;
1124 if (BGP_INFO_HOLDDOWN (ri1))
1125 continue;
1127 new_select = ri1;
1128 if (ri1->next)
1129 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1131 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1132 continue;
1133 if (BGP_INFO_HOLDDOWN (ri2))
1134 continue;
1136 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1137 || aspath_cmp_left_confed (ri1->attr->aspath,
1138 ri2->attr->aspath))
1140 if (bgp_info_cmp (bgp, ri2, new_select))
1142 UNSET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1143 new_select = ri2;
1146 SET_FLAG (ri2->flags, BGP_INFO_DMED_CHECK);
1149 SET_FLAG (new_select->flags, BGP_INFO_DMED_CHECK);
1150 SET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1153 /* Check old selected route and new selected route. */
1154 old_select = NULL;
1155 new_select = NULL;
1156 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1158 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1159 old_select = ri;
1161 if (BGP_INFO_HOLDDOWN (ri))
1163 /* reap REMOVED routes, if needs be
1164 * selected route must stay for a while longer though
1166 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1167 && (ri != old_select))
1168 bgp_info_reap (rn, ri);
1170 continue;
1173 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1174 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1176 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1177 continue;
1179 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1180 UNSET_FLAG (ri->flags, BGP_INFO_DMED_SELECTED);
1182 if (bgp_info_cmp (bgp, ri, new_select))
1183 new_select = ri;
1186 result->old = old_select;
1187 result->new = new_select;
1189 return;
1192 static int
1193 bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1194 struct bgp_node *rn, struct attr *attr, afi_t afi, safi_t safi)
1196 struct prefix *p;
1198 p = &rn->p;
1200 /* Announce route to Established peer. */
1201 if (peer->status != Established)
1202 return 0;
1204 /* Address family configuration check. */
1205 if (! peer->afc_nego[afi][safi])
1206 return 0;
1208 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1209 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1210 PEER_STATUS_ORF_WAIT_REFRESH))
1211 return 0;
1213 switch (rn->table->type)
1215 case BGP_TABLE_MAIN:
1216 /* Announcement to peer->conf. If the route is filtered,
1217 withdraw it. */
1218 if (selected && bgp_announce_check (selected, peer, p, attr, afi, safi))
1219 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1220 else
1221 bgp_adj_out_unset (rn, peer, p, afi, safi);
1222 break;
1223 case BGP_TABLE_RSCLIENT:
1224 /* Announcement to peer->conf. If the route is filtered,
1225 withdraw it. */
1226 if (selected && bgp_announce_check_rsclient
1227 (selected, peer, p, attr, afi, safi))
1228 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1229 else
1230 bgp_adj_out_unset (rn, peer, p, afi, safi);
1231 break;
1233 return 0;
1236 struct bgp_process_queue
1238 struct bgp *bgp;
1239 struct bgp_node *rn;
1240 afi_t afi;
1241 safi_t safi;
1244 static wq_item_status
1245 bgp_process_rsclient (struct bgp_process_queue *pq)
1247 struct bgp *bgp = pq->bgp;
1248 struct bgp_node *rn = pq->rn;
1249 afi_t afi = pq->afi;
1250 safi_t safi = pq->safi;
1251 struct bgp_info *new_select;
1252 struct bgp_info *old_select;
1253 struct bgp_info_pair old_and_new;
1254 struct attr attr;
1255 struct listnode *node, *nnode;
1256 struct peer *rsclient = rn->table->owner;
1258 /* we shouldn't run if the clear_route_node queue is still running
1259 * or scheduled to run, or we can race with session coming up
1260 * and adding routes back before we've cleared them
1262 if (bm->clear_node_queue && bm->clear_node_queue->thread)
1263 return WQ_QUEUE_BLOCKED;
1265 /* Best path selection. */
1266 bgp_best_selection (bgp, rn, &old_and_new);
1267 new_select = old_and_new.new;
1268 old_select = old_and_new.old;
1270 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1272 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1274 /* Nothing to do. */
1275 if (old_select && old_select == new_select)
1276 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1277 continue;
1279 if (old_select)
1280 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1281 if (new_select)
1283 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1284 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1287 bgp_process_announce_selected (rsclient, new_select, rn, &attr,
1288 afi, safi);
1291 else
1293 if (old_select)
1294 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1295 if (new_select)
1297 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1298 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1300 bgp_process_announce_selected (rsclient, new_select, rn,
1301 &attr, afi, safi);
1304 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1305 bgp_info_reap (rn, old_select);
1307 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1308 return WQ_SUCCESS;
1311 static wq_item_status
1312 bgp_process_main (struct bgp_process_queue *pq)
1314 struct bgp *bgp = pq->bgp;
1315 struct bgp_node *rn = pq->rn;
1316 afi_t afi = pq->afi;
1317 safi_t safi = pq->safi;
1318 struct prefix *p = &rn->p;
1319 struct bgp_info *new_select;
1320 struct bgp_info *old_select;
1321 struct bgp_info_pair old_and_new;
1322 struct listnode *node, *nnode;
1323 struct peer *peer;
1324 struct attr attr;
1326 /* we shouldn't run if the clear_route_node queue is still running
1327 * or scheduled to run, or we can race with session coming up
1328 * and adding routes back before we've cleared them
1330 if (bm->clear_node_queue && bm->clear_node_queue->thread)
1331 return WQ_QUEUE_BLOCKED;
1333 /* Best path selection. */
1334 bgp_best_selection (bgp, rn, &old_and_new);
1335 old_select = old_and_new.old;
1336 new_select = old_and_new.new;
1338 /* Nothing to do. */
1339 if (old_select && old_select == new_select)
1341 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1343 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1344 bgp_zebra_announce (p, old_select, bgp);
1346 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1347 return WQ_SUCCESS;
1351 if (old_select)
1352 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1353 if (new_select)
1355 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1356 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1360 /* Check each BGP peer. */
1361 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
1363 bgp_process_announce_selected (peer, new_select, rn, &attr, afi, safi);
1366 /* FIB update. */
1367 if (safi == SAFI_UNICAST && ! bgp->name &&
1368 ! bgp_option_check (BGP_OPT_NO_FIB))
1370 if (new_select
1371 && new_select->type == ZEBRA_ROUTE_BGP
1372 && new_select->sub_type == BGP_ROUTE_NORMAL)
1373 bgp_zebra_announce (p, new_select, bgp);
1374 else
1376 /* Withdraw the route from the kernel. */
1377 if (old_select
1378 && old_select->type == ZEBRA_ROUTE_BGP
1379 && old_select->sub_type == BGP_ROUTE_NORMAL)
1380 bgp_zebra_withdraw (p, old_select);
1384 /* Reap old select bgp_info, it it has been removed */
1385 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1386 bgp_info_reap (rn, old_select);
1388 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1389 return WQ_SUCCESS;
1392 static void
1393 bgp_processq_del (struct bgp_process_queue *pq)
1395 bgp_unlock_node (pq->rn);
1396 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1399 static void
1400 bgp_process_queue_init (void)
1402 bm->process_main_queue
1403 = work_queue_new (bm->master, "process_main_queue");
1404 bm->process_rsclient_queue
1405 = work_queue_new (bm->master, "process_rsclient_queue");
1407 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1409 zlog_err ("%s: Failed to allocate work queue", __func__);
1410 exit (1);
1413 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1414 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1415 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1416 bm->process_rsclient_queue->spec.del_item_data
1417 = bm->process_main_queue->spec.del_item_data;
1418 bm->process_main_queue->spec.max_retries
1419 = bm->process_main_queue->spec.max_retries = 0;
1420 bm->process_rsclient_queue->spec.hold
1421 = bm->process_main_queue->spec.hold = 500;
1422 bm->process_rsclient_queue->spec.delay
1423 = bm->process_main_queue->spec.delay = 10;
1426 void
1427 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1429 struct bgp_process_queue *pqnode;
1431 /* already scheduled for processing? */
1432 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1433 return;
1435 if ( (bm->process_main_queue == NULL) ||
1436 (bm->process_rsclient_queue == NULL) )
1437 bgp_process_queue_init ();
1439 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1440 sizeof (struct bgp_process_queue));
1441 if (!pqnode)
1442 return;
1444 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1445 pqnode->bgp = bgp;
1446 pqnode->afi = afi;
1447 pqnode->safi = safi;
1449 switch (rn->table->type)
1451 case BGP_TABLE_MAIN:
1452 work_queue_add (bm->process_main_queue, pqnode);
1453 break;
1454 case BGP_TABLE_RSCLIENT:
1455 work_queue_add (bm->process_rsclient_queue, pqnode);
1456 break;
1459 return;
1462 static int
1463 bgp_maximum_prefix_restart_timer (struct thread *thread)
1465 struct peer *peer;
1467 peer = THREAD_ARG (thread);
1468 peer->t_pmax_restart = NULL;
1470 if (BGP_DEBUG (events, EVENTS))
1471 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1472 peer->host);
1474 peer_clear (peer);
1476 return 0;
1480 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1481 safi_t safi, int always)
1483 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1484 return 0;
1486 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
1488 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1489 && ! always)
1490 return 0;
1492 zlog (peer->log, LOG_INFO,
1493 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1494 "limit %ld", afi_safi_print (afi, safi), peer->host,
1495 peer->pcount[afi][safi], peer->pmax[afi][safi]);
1496 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1498 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1499 return 0;
1502 u_int8_t ndata[7];
1504 if (safi == SAFI_MPLS_VPN)
1505 safi = BGP_SAFI_VPNV4;
1507 ndata[0] = (afi >> 8);
1508 ndata[1] = afi;
1509 ndata[2] = safi;
1510 ndata[3] = (peer->pmax[afi][safi] >> 24);
1511 ndata[4] = (peer->pmax[afi][safi] >> 16);
1512 ndata[5] = (peer->pmax[afi][safi] >> 8);
1513 ndata[6] = (peer->pmax[afi][safi]);
1515 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1516 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1517 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1520 /* restart timer start */
1521 if (peer->pmax_restart[afi][safi])
1523 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1525 if (BGP_DEBUG (events, EVENTS))
1526 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1527 peer->host, peer->v_pmax_restart);
1529 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1530 peer->v_pmax_restart);
1533 return 1;
1535 else
1536 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1538 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1540 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1541 && ! always)
1542 return 0;
1544 zlog (peer->log, LOG_INFO,
1545 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1546 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1547 peer->pmax[afi][safi]);
1548 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1550 else
1551 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1552 return 0;
1555 /* Unconditionally remove the route from the RIB, without taking
1556 * damping into consideration (eg, because the session went down)
1558 static void
1559 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1560 afi_t afi, safi_t safi)
1562 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
1563 && rn->table->type == BGP_TABLE_MAIN)
1565 /* Ignore 'pcount' for RS-client tables */
1566 if ( rn->table->type == BGP_TABLE_MAIN)
1568 peer->pcount[afi][safi]--;
1569 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1572 bgp_process (peer->bgp, rn, afi, safi);
1573 bgp_info_delete (rn, ri);
1576 static void
1577 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1578 afi_t afi, safi_t safi)
1580 int status = BGP_DAMP_NONE;
1582 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
1583 && rn->table->type == BGP_TABLE_MAIN)
1585 /* Ignore 'pcount' for RS-client tables */
1586 if ( rn->table->type == BGP_TABLE_MAIN)
1588 peer->pcount[afi][safi]--;
1589 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1593 /* apply dampening, if result is suppressed, we'll be retaining
1594 * the bgp_info in the RIB for historical reference.
1596 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1597 && peer_sort (peer) == BGP_PEER_EBGP)
1598 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1599 == BGP_DAMP_SUPPRESSED)
1600 return;
1602 bgp_process (peer->bgp, rn, afi, safi);
1604 if (status != BGP_DAMP_USED)
1605 bgp_info_delete (rn, ri);
1608 static void
1609 bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1610 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1611 int sub_type, struct prefix_rd *prd, u_char *tag)
1613 struct bgp_node *rn;
1614 struct bgp *bgp;
1615 struct attr new_attr;
1616 struct attr *attr_new;
1617 struct attr *attr_new2;
1618 struct bgp_info *ri;
1619 struct bgp_info *new;
1620 const char *reason;
1621 char buf[SU_ADDRSTRLEN];
1623 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1624 if (peer == rsclient)
1625 return;
1627 bgp = peer->bgp;
1628 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1630 /* Check previously received route. */
1631 for (ri = rn->info; ri; ri = ri->next)
1632 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1633 break;
1635 /* AS path loop check. */
1636 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1638 reason = "as-path contains our own AS;";
1639 goto filtered;
1642 /* Route reflector originator ID check. */
1643 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1644 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->originator_id))
1646 reason = "originator is us;";
1647 goto filtered;
1650 new_attr = *attr;
1652 /* Apply export policy. */
1653 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1654 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1656 reason = "export-policy;";
1657 goto filtered;
1660 attr_new2 = bgp_attr_intern (&new_attr);
1662 /* Apply import policy. */
1663 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1665 bgp_attr_unintern (attr_new2);
1667 reason = "import-policy;";
1668 goto filtered;
1671 attr_new = bgp_attr_intern (&new_attr);
1672 bgp_attr_unintern (attr_new2);
1674 /* IPv4 unicast next hop check. */
1675 if (afi == AFI_IP && safi == SAFI_UNICAST)
1677 /* Next hop must not be 0.0.0.0 nor Class E address. */
1678 if (new_attr.nexthop.s_addr == 0
1679 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1681 bgp_attr_unintern (attr_new);
1683 reason = "martian next-hop;";
1684 goto filtered;
1688 /* If the update is implicit withdraw. */
1689 if (ri)
1691 ri->uptime = time (NULL);
1693 /* Same attribute comes in. */
1694 if (attrhash_cmp (ri->attr, attr_new))
1697 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1699 if (BGP_DEBUG (update, UPDATE_IN))
1700 zlog (peer->log, LOG_DEBUG,
1701 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1702 peer->host,
1703 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1704 p->prefixlen, rsclient->host);
1706 bgp_unlock_node (rn);
1707 bgp_attr_unintern (attr_new);
1709 return;
1712 /* Received Logging. */
1713 if (BGP_DEBUG (update, UPDATE_IN))
1714 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
1715 peer->host,
1716 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1717 p->prefixlen, rsclient->host);
1719 /* The attribute is changed. */
1720 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1722 /* Update to new attribute. */
1723 bgp_attr_unintern (ri->attr);
1724 ri->attr = attr_new;
1726 /* Update MPLS tag. */
1727 if (safi == SAFI_MPLS_VPN)
1728 memcpy (ri->tag, tag, 3);
1730 SET_FLAG (ri->flags, BGP_INFO_VALID);
1732 /* Process change. */
1733 bgp_process (bgp, rn, afi, safi);
1734 bgp_unlock_node (rn);
1736 return;
1739 /* Received Logging. */
1740 if (BGP_DEBUG (update, UPDATE_IN))
1742 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
1743 peer->host,
1744 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1745 p->prefixlen, rsclient->host);
1748 /* Make new BGP info. */
1749 new = bgp_info_new ();
1750 new->type = type;
1751 new->sub_type = sub_type;
1752 new->peer = peer;
1753 new->attr = attr_new;
1754 new->uptime = time (NULL);
1756 /* Update MPLS tag. */
1757 if (safi == SAFI_MPLS_VPN)
1758 memcpy (new->tag, tag, 3);
1760 SET_FLAG (new->flags, BGP_INFO_VALID);
1762 /* Register new BGP information. */
1763 bgp_info_add (rn, new);
1765 /* route_node_get lock */
1766 bgp_unlock_node (rn);
1768 /* Process change. */
1769 bgp_process (bgp, rn, afi, safi);
1771 return;
1773 filtered:
1775 /* This BGP update is filtered. Log the reason then update BGP entry. */
1776 if (BGP_DEBUG (update, UPDATE_IN))
1777 zlog (peer->log, LOG_DEBUG,
1778 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1779 peer->host,
1780 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1781 p->prefixlen, rsclient->host, reason);
1783 if (ri)
1784 bgp_rib_remove (rn, ri, peer, afi, safi);
1786 bgp_unlock_node (rn);
1788 return;
1791 static void
1792 bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1793 struct peer *peer, struct prefix *p, int type, int sub_type,
1794 struct prefix_rd *prd, u_char *tag)
1796 struct bgp_node *rn;
1797 struct bgp_info *ri;
1798 char buf[SU_ADDRSTRLEN];
1800 if (rsclient == peer)
1801 return;
1803 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1805 /* Lookup withdrawn route. */
1806 for (ri = rn->info; ri; ri = ri->next)
1807 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1808 break;
1810 /* Withdraw specified route from routing table. */
1811 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1812 bgp_rib_withdraw (rn, ri, peer, afi, safi);
1813 else if (BGP_DEBUG (update, UPDATE_IN))
1814 zlog (peer->log, LOG_DEBUG,
1815 "%s Can't find the route %s/%d", peer->host,
1816 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1817 p->prefixlen);
1819 /* Unlock bgp_node_get() lock. */
1820 bgp_unlock_node (rn);
1823 static int
1824 bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
1825 afi_t afi, safi_t safi, int type, int sub_type,
1826 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1828 int ret;
1829 int aspath_loop_count = 0;
1830 struct bgp_node *rn;
1831 struct bgp *bgp;
1832 struct attr new_attr;
1833 struct attr *attr_new;
1834 struct bgp_info *ri;
1835 struct bgp_info *new;
1836 const char *reason;
1837 char buf[SU_ADDRSTRLEN];
1839 bgp = peer->bgp;
1840 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
1842 /* When peer's soft reconfiguration enabled. Record input packet in
1843 Adj-RIBs-In. */
1844 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1845 && peer != bgp->peer_self && ! soft_reconfig)
1846 bgp_adj_in_set (rn, peer, attr);
1848 /* Check previously received route. */
1849 for (ri = rn->info; ri; ri = ri->next)
1850 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1851 break;
1853 /* AS path local-as loop check. */
1854 if (peer->change_local_as)
1856 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1857 aspath_loop_count = 1;
1859 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1861 reason = "as-path contains our own AS;";
1862 goto filtered;
1866 /* AS path loop check. */
1867 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1868 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1869 && aspath_loop_check(attr->aspath, bgp->confed_id)
1870 > peer->allowas_in[afi][safi]))
1872 reason = "as-path contains our own AS;";
1873 goto filtered;
1876 /* Route reflector originator ID check. */
1877 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1878 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1880 reason = "originator is us;";
1881 goto filtered;
1884 /* Route reflector cluster ID check. */
1885 if (bgp_cluster_filter (peer, attr))
1887 reason = "reflected from the same cluster;";
1888 goto filtered;
1891 /* Apply incoming filter. */
1892 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1894 reason = "filter;";
1895 goto filtered;
1898 /* Apply incoming route-map. */
1899 new_attr = *attr;
1901 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1903 reason = "route-map;";
1904 goto filtered;
1907 /* IPv4 unicast next hop check. */
1908 if (afi == AFI_IP && safi == SAFI_UNICAST)
1910 /* If the peer is EBGP and nexthop is not on connected route,
1911 discard it. */
1912 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1913 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
1914 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
1916 reason = "non-connected next-hop;";
1917 goto filtered;
1920 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1921 must not be my own address. */
1922 if (bgp_nexthop_self (afi, &new_attr)
1923 || new_attr.nexthop.s_addr == 0
1924 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1926 reason = "martian next-hop;";
1927 goto filtered;
1931 attr_new = bgp_attr_intern (&new_attr);
1933 /* If the update is implicit withdraw. */
1934 if (ri)
1936 ri->uptime = time (NULL);
1938 /* Same attribute comes in. */
1939 if (attrhash_cmp (ri->attr, attr_new))
1941 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1943 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1944 && peer_sort (peer) == BGP_PEER_EBGP
1945 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1947 if (BGP_DEBUG (update, UPDATE_IN))
1948 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
1949 peer->host,
1950 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1951 p->prefixlen);
1953 peer->pcount[afi][safi]++;
1954 ret = bgp_damp_update (ri, rn, afi, safi);
1955 if (ret != BGP_DAMP_SUPPRESSED)
1957 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1958 bgp_process (bgp, rn, afi, safi);
1961 else
1963 if (BGP_DEBUG (update, UPDATE_IN))
1964 zlog (peer->log, LOG_DEBUG,
1965 "%s rcvd %s/%d...duplicate ignored",
1966 peer->host,
1967 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1968 p->prefixlen);
1970 /* graceful restart STALE flag unset. */
1971 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1973 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1974 peer->pcount[afi][safi]++;
1978 bgp_unlock_node (rn);
1979 bgp_attr_unintern (attr_new);
1980 return 0;
1983 /* Received Logging. */
1984 if (BGP_DEBUG (update, UPDATE_IN))
1985 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
1986 peer->host,
1987 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1988 p->prefixlen);
1990 /* graceful restart STALE flag unset. */
1991 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1993 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1994 peer->pcount[afi][safi]++;
1997 /* The attribute is changed. */
1998 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2000 /* Update bgp route dampening information. */
2001 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2002 && peer_sort (peer) == BGP_PEER_EBGP)
2004 /* This is implicit withdraw so we should update dampening
2005 information. */
2006 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2007 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2008 else
2009 peer->pcount[afi][safi]++;
2012 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2014 /* Update to new attribute. */
2015 bgp_attr_unintern (ri->attr);
2016 ri->attr = attr_new;
2018 /* Update MPLS tag. */
2019 if (safi == SAFI_MPLS_VPN)
2020 memcpy (ri->tag, tag, 3);
2022 /* Update bgp route dampening information. */
2023 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2024 && peer_sort (peer) == BGP_PEER_EBGP)
2026 /* Now we do normal update dampening. */
2027 ret = bgp_damp_update (ri, rn, afi, safi);
2028 if (ret == BGP_DAMP_SUPPRESSED)
2030 bgp_unlock_node (rn);
2031 return 0;
2035 /* Nexthop reachability check. */
2036 if ((afi == AFI_IP || afi == AFI_IP6)
2037 && safi == SAFI_UNICAST
2038 && (peer_sort (peer) == BGP_PEER_IBGP
2039 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
2040 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
2042 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
2043 SET_FLAG (ri->flags, BGP_INFO_VALID);
2044 else
2045 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2047 else
2048 SET_FLAG (ri->flags, BGP_INFO_VALID);
2050 /* Process change. */
2051 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2053 bgp_process (bgp, rn, afi, safi);
2054 bgp_unlock_node (rn);
2055 return 0;
2058 /* Received Logging. */
2059 if (BGP_DEBUG (update, UPDATE_IN))
2061 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2062 peer->host,
2063 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2064 p->prefixlen);
2067 /* Increment prefix counter */
2068 peer->pcount[afi][safi]++;
2070 /* Make new BGP info. */
2071 new = bgp_info_new ();
2072 new->type = type;
2073 new->sub_type = sub_type;
2074 new->peer = peer;
2075 new->attr = attr_new;
2076 new->uptime = time (NULL);
2078 /* Update MPLS tag. */
2079 if (safi == SAFI_MPLS_VPN)
2080 memcpy (new->tag, tag, 3);
2082 /* Nexthop reachability check. */
2083 if ((afi == AFI_IP || afi == AFI_IP6)
2084 && safi == SAFI_UNICAST
2085 && (peer_sort (peer) == BGP_PEER_IBGP
2086 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
2087 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
2089 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
2090 SET_FLAG (new->flags, BGP_INFO_VALID);
2091 else
2092 UNSET_FLAG (new->flags, BGP_INFO_VALID);
2094 else
2095 SET_FLAG (new->flags, BGP_INFO_VALID);
2097 /* Aggregate address increment. */
2098 bgp_aggregate_increment (bgp, p, new, afi, safi);
2100 /* Register new BGP information. */
2101 bgp_info_add (rn, new);
2103 /* route_node_get lock */
2104 bgp_unlock_node (rn);
2106 /* If maximum prefix count is configured and current prefix
2107 count exeed it. */
2108 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2109 return -1;
2111 /* Process change. */
2112 bgp_process (bgp, rn, afi, safi);
2114 return 0;
2116 /* This BGP update is filtered. Log the reason then update BGP
2117 entry. */
2118 filtered:
2119 if (BGP_DEBUG (update, UPDATE_IN))
2120 zlog (peer->log, LOG_DEBUG,
2121 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2122 peer->host,
2123 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2124 p->prefixlen, reason);
2126 if (ri)
2127 bgp_rib_remove (rn, ri, peer, afi, safi);
2129 bgp_unlock_node (rn);
2131 return 0;
2135 bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2136 afi_t afi, safi_t safi, int type, int sub_type,
2137 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2139 struct peer *rsclient;
2140 struct listnode *node, *nnode;
2141 struct bgp *bgp;
2142 int ret;
2144 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2145 soft_reconfig);
2147 bgp = peer->bgp;
2149 /* Process the update for each RS-client. */
2150 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2152 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2153 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2154 sub_type, prd, tag);
2157 return ret;
2161 bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
2162 afi_t afi, safi_t safi, int type, int sub_type,
2163 struct prefix_rd *prd, u_char *tag)
2165 struct bgp *bgp;
2166 char buf[SU_ADDRSTRLEN];
2167 struct bgp_node *rn;
2168 struct bgp_info *ri;
2169 struct peer *rsclient;
2170 struct listnode *node, *nnode;
2172 bgp = peer->bgp;
2174 /* Process the withdraw for each RS-client. */
2175 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2177 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2178 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2181 /* Logging. */
2182 if (BGP_DEBUG (update, UPDATE_IN))
2183 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
2184 peer->host,
2185 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2186 p->prefixlen);
2188 /* Lookup node. */
2189 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2191 /* If peer is soft reconfiguration enabled. Record input packet for
2192 further calculation. */
2193 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2194 && peer != bgp->peer_self)
2195 bgp_adj_in_unset (rn, peer);
2197 /* Lookup withdrawn route. */
2198 for (ri = rn->info; ri; ri = ri->next)
2199 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2200 break;
2202 /* Withdraw specified route from routing table. */
2203 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2204 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2205 else if (BGP_DEBUG (update, UPDATE_IN))
2206 zlog (peer->log, LOG_DEBUG,
2207 "%s Can't find the route %s/%d", peer->host,
2208 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2209 p->prefixlen);
2211 /* Unlock bgp_node_get() lock. */
2212 bgp_unlock_node (rn);
2214 return 0;
2217 void
2218 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2220 struct bgp *bgp;
2221 struct attr attr;
2222 struct aspath *aspath;
2223 struct prefix p;
2224 struct bgp_info binfo;
2225 struct peer *from;
2226 int ret = RMAP_DENYMATCH;
2228 bgp = peer->bgp;
2229 from = bgp->peer_self;
2231 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2232 aspath = attr.aspath;
2233 attr.local_pref = bgp->default_local_pref;
2234 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2236 if (afi == AFI_IP)
2237 str2prefix ("0.0.0.0/0", &p);
2238 #ifdef HAVE_IPV6
2239 else if (afi == AFI_IP6)
2241 str2prefix ("::/0", &p);
2243 /* IPv6 global nexthop must be included. */
2244 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
2245 IPV6_MAX_BYTELEN);
2246 attr.mp_nexthop_len = 16;
2248 /* If the peer is on shared nextwork and we have link-local
2249 nexthop set it. */
2250 if (peer->shared_network
2251 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2253 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
2254 IPV6_MAX_BYTELEN);
2255 attr.mp_nexthop_len = 32;
2258 #endif /* HAVE_IPV6 */
2259 else
2260 return;
2262 if (peer->default_rmap[afi][safi].name)
2264 binfo.peer = bgp->peer_self;
2265 binfo.attr = &attr;
2267 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2269 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2270 RMAP_BGP, &binfo);
2272 bgp->peer_self->rmap_type = 0;
2274 if (ret == RMAP_DENYMATCH)
2276 bgp_attr_flush (&attr);
2277 withdraw = 1;
2281 if (withdraw)
2283 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2284 bgp_default_withdraw_send (peer, afi, safi);
2285 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2287 else
2289 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2290 bgp_default_update_send (peer, &attr, afi, safi, from);
2293 aspath_unintern (aspath);
2296 static void
2297 bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
2298 struct bgp_table *table, int rsclient)
2300 struct bgp_node *rn;
2301 struct bgp_info *ri;
2302 struct attr attr;
2304 if (! table)
2305 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
2307 if (safi != SAFI_MPLS_VPN
2308 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2309 bgp_default_originate (peer, afi, safi, 0);
2311 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2312 for (ri = rn->info; ri; ri = ri->next)
2313 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2315 if ( (rsclient) ?
2316 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2317 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
2318 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2319 else
2320 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2324 void
2325 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2327 struct bgp_node *rn;
2328 struct bgp_table *table;
2330 if (peer->status != Established)
2331 return;
2333 if (! peer->afc_nego[afi][safi])
2334 return;
2336 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2337 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2338 return;
2340 if (safi != SAFI_MPLS_VPN)
2341 bgp_announce_table (peer, afi, safi, NULL, 0);
2342 else
2343 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2344 rn = bgp_route_next(rn))
2345 if ((table = (rn->info)) != NULL)
2346 bgp_announce_table (peer, afi, safi, table, 0);
2348 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2349 bgp_announce_table (peer, afi, safi, NULL, 1);
2352 void
2353 bgp_announce_route_all (struct peer *peer)
2355 afi_t afi;
2356 safi_t safi;
2358 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2359 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2360 bgp_announce_route (peer, afi, safi);
2363 static void
2364 bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2365 safi_t safi, struct bgp_table *table)
2367 struct bgp_node *rn;
2368 struct bgp_adj_in *ain;
2370 if (! table)
2371 table = rsclient->bgp->rib[afi][safi];
2373 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2374 for (ain = rn->adj_in; ain; ain = ain->next)
2376 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2377 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2381 void
2382 bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2384 struct bgp_table *table;
2385 struct bgp_node *rn;
2387 if (safi != SAFI_MPLS_VPN)
2388 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2390 else
2391 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2392 rn = bgp_route_next (rn))
2393 if ((table = rn->info) != NULL)
2394 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2397 static void
2398 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2399 struct bgp_table *table)
2401 int ret;
2402 struct bgp_node *rn;
2403 struct bgp_adj_in *ain;
2405 if (! table)
2406 table = peer->bgp->rib[afi][safi];
2408 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2409 for (ain = rn->adj_in; ain; ain = ain->next)
2411 if (ain->peer == peer)
2413 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2414 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2415 NULL, NULL, 1);
2416 if (ret < 0)
2418 bgp_unlock_node (rn);
2419 return;
2421 continue;
2426 void
2427 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2429 struct bgp_node *rn;
2430 struct bgp_table *table;
2432 if (peer->status != Established)
2433 return;
2435 if (safi != SAFI_MPLS_VPN)
2436 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2437 else
2438 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2439 rn = bgp_route_next (rn))
2440 if ((table = rn->info) != NULL)
2441 bgp_soft_reconfig_table (peer, afi, safi, table);
2444 struct bgp_clear_node_queue
2446 struct bgp_node *rn;
2447 struct peer *peer;
2448 afi_t afi;
2449 safi_t safi;
2452 static wq_item_status
2453 bgp_clear_route_node (struct bgp_clear_node_queue *cq)
2455 struct bgp_adj_in *ain;
2456 struct bgp_adj_out *aout;
2457 struct bgp_info *ri;
2459 assert (cq->rn && cq->peer);
2461 for (ri = cq->rn->info; ri; ri = ri->next)
2462 if (ri->peer == cq->peer)
2464 /* graceful restart STALE flag set. */
2465 if (CHECK_FLAG (cq->peer->sflags, PEER_STATUS_NSF_WAIT)
2466 && cq->peer->nsf[cq->afi][cq->safi]
2467 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2468 && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
2469 && ! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2471 SET_FLAG (ri->flags, BGP_INFO_STALE);
2472 cq->peer->pcount[cq->afi][cq->safi]--;
2474 else
2475 bgp_rib_remove (cq->rn, ri, cq->peer, cq->afi, cq->safi);
2476 break;
2478 for (ain = cq->rn->adj_in; ain; ain = ain->next)
2479 if (ain->peer == cq->peer)
2481 bgp_adj_in_remove (cq->rn, ain);
2482 bgp_unlock_node (cq->rn);
2483 break;
2485 for (aout = cq->rn->adj_out; aout; aout = aout->next)
2486 if (aout->peer == cq->peer)
2488 bgp_adj_out_remove (cq->rn, aout, cq->peer, cq->afi, cq->safi);
2489 bgp_unlock_node (cq->rn);
2490 break;
2492 return WQ_SUCCESS;
2495 static void
2496 bgp_clear_node_queue_del (struct bgp_clear_node_queue *cq)
2498 bgp_unlock_node (cq->rn);
2499 peer_unlock (cq->peer); /* bgp_clear_node_queue_del */
2500 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cq);
2503 static void
2504 bgp_clear_node_complete (struct work_queue *wq)
2506 /* unplug the 2 processing queues */
2507 if (bm->process_main_queue)
2508 work_queue_unplug (bm->process_main_queue);
2509 if (bm->process_rsclient_queue)
2510 work_queue_unplug (bm->process_rsclient_queue);
2513 static void
2514 bgp_clear_node_queue_init (void)
2516 if ( (bm->clear_node_queue
2517 = work_queue_new (bm->master, "clear_route_node")) == NULL)
2519 zlog_err ("%s: Failed to allocate work queue", __func__);
2520 exit (1);
2522 bm->clear_node_queue->spec.hold = 10;
2523 bm->clear_node_queue->spec.delay = 0; /* no gathering to be gained */
2524 bm->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2525 bm->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2526 bm->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2527 bm->clear_node_queue->spec.max_retries = 0;
2530 static void
2531 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2532 struct bgp_table *table, struct peer *rsclient)
2534 struct bgp_clear_node_queue *cqnode;
2535 struct bgp_node *rn;
2537 if (! table)
2538 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
2540 /* If still no table => afi/safi isn't configured at all or smth. */
2541 if (! table)
2542 return;
2544 if (bm->clear_node_queue == NULL)
2545 bgp_clear_node_queue_init ();
2547 /* plug the two bgp_process queues to avoid any chance of racing
2548 * with a session coming back up and adding routes before we've
2549 * cleared them all. We'll unplug them with completion callback.
2551 if (bm->process_main_queue)
2552 work_queue_plug (bm->process_main_queue);
2553 if (bm->process_rsclient_queue)
2554 work_queue_plug (bm->process_rsclient_queue);
2556 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2558 if (rn->info == NULL)
2559 continue;
2561 if ( (cqnode = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2562 sizeof (struct bgp_clear_node_queue))) == NULL)
2563 continue;
2565 cqnode->rn = bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2566 cqnode->afi = afi;
2567 cqnode->safi = safi;
2568 cqnode->peer = peer_lock (peer); /* bgp_clear_node_queue_del */
2569 work_queue_add (bm->clear_node_queue, cqnode);
2571 return;
2574 void
2575 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2577 struct bgp_node *rn;
2578 struct bgp_table *table;
2579 struct peer *rsclient;
2580 struct listnode *node, *nnode;
2582 if (safi != SAFI_MPLS_VPN)
2583 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
2584 else
2585 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2586 rn = bgp_route_next (rn))
2587 if ((table = rn->info) != NULL)
2588 bgp_clear_route_table (peer, afi, safi, table, NULL);
2590 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2592 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2593 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2597 void
2598 bgp_clear_route_all (struct peer *peer)
2600 afi_t afi;
2601 safi_t safi;
2603 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2604 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2605 bgp_clear_route (peer, afi, safi);
2608 void
2609 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2611 struct bgp_table *table;
2612 struct bgp_node *rn;
2613 struct bgp_adj_in *ain;
2615 table = peer->bgp->rib[afi][safi];
2617 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2618 for (ain = rn->adj_in; ain ; ain = ain->next)
2619 if (ain->peer == peer)
2621 bgp_adj_in_remove (rn, ain);
2622 bgp_unlock_node (rn);
2623 break;
2627 void
2628 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2630 struct bgp_node *rn;
2631 struct bgp_info *ri;
2632 struct bgp_table *table;
2634 table = peer->bgp->rib[afi][safi];
2636 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2638 for (ri = rn->info; ri; ri = ri->next)
2639 if (ri->peer == peer)
2641 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2642 bgp_rib_remove (rn, ri, peer, afi, safi);
2643 break;
2648 /* Delete all kernel routes. */
2649 void
2650 bgp_cleanup_routes ()
2652 struct bgp *bgp;
2653 struct listnode *node, *nnode;
2654 struct bgp_node *rn;
2655 struct bgp_table *table;
2656 struct bgp_info *ri;
2658 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
2660 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2662 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2663 for (ri = rn->info; ri; ri = ri->next)
2664 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2665 && ri->type == ZEBRA_ROUTE_BGP
2666 && ri->sub_type == BGP_ROUTE_NORMAL)
2667 bgp_zebra_withdraw (&rn->p, ri);
2669 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2671 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2672 for (ri = rn->info; ri; ri = ri->next)
2673 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2674 && ri->type == ZEBRA_ROUTE_BGP
2675 && ri->sub_type == BGP_ROUTE_NORMAL)
2676 bgp_zebra_withdraw (&rn->p, ri);
2680 void
2681 bgp_reset ()
2683 vty_reset ();
2684 bgp_zclient_reset ();
2685 access_list_reset ();
2686 prefix_list_reset ();
2689 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2690 value. */
2692 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2694 u_char *pnt;
2695 u_char *lim;
2696 struct prefix p;
2697 int psize;
2698 int ret;
2700 /* Check peer status. */
2701 if (peer->status != Established)
2702 return 0;
2704 pnt = packet->nlri;
2705 lim = pnt + packet->length;
2707 for (; pnt < lim; pnt += psize)
2709 /* Clear prefix structure. */
2710 memset (&p, 0, sizeof (struct prefix));
2712 /* Fetch prefix length. */
2713 p.prefixlen = *pnt++;
2714 p.family = afi2family (packet->afi);
2716 /* Already checked in nlri_sanity_check(). We do double check
2717 here. */
2718 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2719 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2720 return -1;
2722 /* Packet size overflow check. */
2723 psize = PSIZE (p.prefixlen);
2725 /* When packet overflow occur return immediately. */
2726 if (pnt + psize > lim)
2727 return -1;
2729 /* Fetch prefix from NLRI packet. */
2730 memcpy (&p.u.prefix, pnt, psize);
2732 /* Check address. */
2733 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2735 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2738 * From draft-ietf-idr-bgp4-22, Section 6.3:
2739 * If a BGP router receives an UPDATE message with a
2740 * semantically incorrect NLRI field, in which a prefix is
2741 * semantically incorrect (eg. an unexpected multicast IP
2742 * address), it should ignore the prefix.
2744 zlog (peer->log, LOG_ERR,
2745 "IPv4 unicast NLRI is multicast address %s",
2746 inet_ntoa (p.u.prefix4));
2748 return -1;
2752 #ifdef HAVE_IPV6
2753 /* Check address. */
2754 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2756 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2758 char buf[BUFSIZ];
2760 zlog (peer->log, LOG_WARNING,
2761 "IPv6 link-local NLRI received %s ignore this NLRI",
2762 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2764 continue;
2767 #endif /* HAVE_IPV6 */
2769 /* Normal process. */
2770 if (attr)
2771 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2772 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2773 else
2774 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2775 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2777 /* Address family configuration mismatch or maximum-prefix count
2778 overflow. */
2779 if (ret < 0)
2780 return -1;
2783 /* Packet length consistency check. */
2784 if (pnt != lim)
2785 return -1;
2787 return 0;
2790 /* NLRI encode syntax check routine. */
2792 bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2793 bgp_size_t length)
2795 u_char *end;
2796 u_char prefixlen;
2797 int psize;
2799 end = pnt + length;
2801 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2802 syntactic validity. If the field is syntactically incorrect,
2803 then the Error Subcode is set to Invalid Network Field. */
2805 while (pnt < end)
2807 prefixlen = *pnt++;
2809 /* Prefix length check. */
2810 if ((afi == AFI_IP && prefixlen > 32)
2811 || (afi == AFI_IP6 && prefixlen > 128))
2813 plog_err (peer->log,
2814 "%s [Error] Update packet error (wrong prefix length %d)",
2815 peer->host, prefixlen);
2816 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2817 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2818 return -1;
2821 /* Packet size overflow check. */
2822 psize = PSIZE (prefixlen);
2824 if (pnt + psize > end)
2826 plog_err (peer->log,
2827 "%s [Error] Update packet error"
2828 " (prefix data overflow prefix size is %d)",
2829 peer->host, psize);
2830 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2831 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2832 return -1;
2835 pnt += psize;
2838 /* Packet length consistency check. */
2839 if (pnt != end)
2841 plog_err (peer->log,
2842 "%s [Error] Update packet error"
2843 " (prefix length mismatch with total length)",
2844 peer->host);
2845 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2846 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2847 return -1;
2849 return 0;
2852 static struct bgp_static *
2853 bgp_static_new ()
2855 struct bgp_static *new;
2856 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2857 memset (new, 0, sizeof (struct bgp_static));
2858 return new;
2861 static void
2862 bgp_static_free (struct bgp_static *bgp_static)
2864 if (bgp_static->rmap.name)
2865 free (bgp_static->rmap.name);
2866 XFREE (MTYPE_BGP_STATIC, bgp_static);
2869 static void
2870 bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2871 struct prefix *p, afi_t afi, safi_t safi)
2873 struct bgp_node *rn;
2874 struct bgp_info *ri;
2876 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2878 /* Check selected route and self inserted route. */
2879 for (ri = rn->info; ri; ri = ri->next)
2880 if (ri->peer == bgp->peer_self
2881 && ri->type == ZEBRA_ROUTE_BGP
2882 && ri->sub_type == BGP_ROUTE_STATIC)
2883 break;
2885 /* Withdraw static BGP route from routing table. */
2886 if (ri)
2888 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2889 bgp_process (bgp, rn, afi, safi);
2890 bgp_info_delete (rn, ri);
2893 /* Unlock bgp_node_lookup. */
2894 bgp_unlock_node (rn);
2897 static void
2898 bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2899 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2901 struct bgp_node *rn;
2902 struct bgp_info *ri;
2903 struct bgp_info *new;
2904 struct bgp_info info;
2905 struct attr new_attr;
2906 struct attr *attr_new;
2907 struct attr attr;
2908 struct bgp *bgp;
2909 int ret;
2910 char buf[SU_ADDRSTRLEN];
2912 bgp = rsclient->bgp;
2914 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2916 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2917 if (bgp_static)
2919 attr.nexthop = bgp_static->igpnexthop;
2920 attr.med = bgp_static->igpmetric;
2921 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
2924 new_attr = attr;
2926 /* Apply network route-map for export to this rsclient. */
2927 if (bgp_static->rmap.name)
2929 info.peer = rsclient;
2930 info.attr = &new_attr;
2932 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2933 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2935 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2937 rsclient->rmap_type = 0;
2939 if (ret == RMAP_DENYMATCH)
2941 /* Free uninterned attribute. */
2942 bgp_attr_flush (&new_attr);
2944 /* Unintern original. */
2945 aspath_unintern (attr.aspath);
2946 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2948 return;
2950 attr_new = bgp_attr_intern (&new_attr);
2952 else
2953 attr_new = bgp_attr_intern (&attr);
2955 new_attr = *attr_new;
2957 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2959 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
2961 /* This BGP update is filtered. Log the reason then update BGP entry. */
2962 if (BGP_DEBUG (update, UPDATE_IN))
2963 zlog (rsclient->log, LOG_DEBUG,
2964 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
2965 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2966 p->prefixlen, rsclient->host);
2968 bgp->peer_self->rmap_type = 0;
2970 bgp_attr_unintern (attr_new);
2971 aspath_unintern (attr.aspath);
2973 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2975 return;
2978 bgp->peer_self->rmap_type = 0;
2980 bgp_attr_unintern (attr_new);
2981 attr_new = bgp_attr_intern (&new_attr);
2983 for (ri = rn->info; ri; ri = ri->next)
2984 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
2985 && ri->sub_type == BGP_ROUTE_STATIC)
2986 break;
2988 if (ri)
2990 if (attrhash_cmp (ri->attr, attr_new))
2992 bgp_unlock_node (rn);
2993 bgp_attr_unintern (attr_new);
2994 aspath_unintern (attr.aspath);
2995 return;
2997 else
2999 /* The attribute is changed. */
3000 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3002 /* Rewrite BGP route information. */
3003 bgp_attr_unintern (ri->attr);
3004 ri->attr = attr_new;
3005 ri->uptime = time (NULL);
3007 /* Process change. */
3008 bgp_process (bgp, rn, afi, safi);
3009 bgp_unlock_node (rn);
3010 aspath_unintern (attr.aspath);
3011 return;
3015 /* Make new BGP info. */
3016 new = bgp_info_new ();
3017 new->type = ZEBRA_ROUTE_BGP;
3018 new->sub_type = BGP_ROUTE_STATIC;
3019 new->peer = bgp->peer_self;
3020 SET_FLAG (new->flags, BGP_INFO_VALID);
3021 new->attr = attr_new;
3022 new->uptime = time (NULL);
3024 /* Register new BGP information. */
3025 bgp_info_add (rn, new);
3027 /* route_node_get lock */
3028 bgp_unlock_node (rn);
3030 /* Process change. */
3031 bgp_process (bgp, rn, afi, safi);
3033 /* Unintern original. */
3034 aspath_unintern (attr.aspath);
3037 static void
3038 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3039 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3041 struct bgp_node *rn;
3042 struct bgp_info *ri;
3043 struct bgp_info *new;
3044 struct bgp_info info;
3045 struct attr attr;
3046 struct attr attr_tmp;
3047 struct attr *attr_new;
3048 int ret;
3050 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3052 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3053 if (bgp_static)
3055 attr.nexthop = bgp_static->igpnexthop;
3056 attr.med = bgp_static->igpmetric;
3057 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3060 /* Apply route-map. */
3061 if (bgp_static->rmap.name)
3063 attr_tmp = attr;
3064 info.peer = bgp->peer_self;
3065 info.attr = &attr_tmp;
3067 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3069 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3071 bgp->peer_self->rmap_type = 0;
3073 if (ret == RMAP_DENYMATCH)
3075 /* Free uninterned attribute. */
3076 bgp_attr_flush (&attr_tmp);
3078 /* Unintern original. */
3079 aspath_unintern (attr.aspath);
3080 bgp_static_withdraw (bgp, p, afi, safi);
3081 return;
3083 attr_new = bgp_attr_intern (&attr_tmp);
3085 else
3086 attr_new = bgp_attr_intern (&attr);
3088 for (ri = rn->info; ri; ri = ri->next)
3089 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3090 && ri->sub_type == BGP_ROUTE_STATIC)
3091 break;
3093 if (ri)
3095 if (attrhash_cmp (ri->attr, attr_new))
3097 bgp_unlock_node (rn);
3098 bgp_attr_unintern (attr_new);
3099 aspath_unintern (attr.aspath);
3100 return;
3102 else
3104 /* The attribute is changed. */
3105 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3107 /* Rewrite BGP route information. */
3108 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3109 bgp_attr_unintern (ri->attr);
3110 ri->attr = attr_new;
3111 ri->uptime = time (NULL);
3113 /* Process change. */
3114 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3115 bgp_process (bgp, rn, afi, safi);
3116 bgp_unlock_node (rn);
3117 aspath_unintern (attr.aspath);
3118 return;
3122 /* Make new BGP info. */
3123 new = bgp_info_new ();
3124 new->type = ZEBRA_ROUTE_BGP;
3125 new->sub_type = BGP_ROUTE_STATIC;
3126 new->peer = bgp->peer_self;
3127 SET_FLAG (new->flags, BGP_INFO_VALID);
3128 new->attr = attr_new;
3129 new->uptime = time (NULL);
3131 /* Aggregate address increment. */
3132 bgp_aggregate_increment (bgp, p, new, afi, safi);
3134 /* Register new BGP information. */
3135 bgp_info_add (rn, new);
3137 /* route_node_get lock */
3138 bgp_unlock_node (rn);
3140 /* Process change. */
3141 bgp_process (bgp, rn, afi, safi);
3143 /* Unintern original. */
3144 aspath_unintern (attr.aspath);
3147 void
3148 bgp_static_update (struct bgp *bgp, struct prefix *p,
3149 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3151 struct peer *rsclient;
3152 struct listnode *node, *nnode;
3154 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3156 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
3158 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3162 static void
3163 bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3164 u_char safi, struct prefix_rd *prd, u_char *tag)
3166 struct bgp_node *rn;
3167 struct bgp_info *new;
3169 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3171 /* Make new BGP info. */
3172 new = bgp_info_new ();
3173 new->type = ZEBRA_ROUTE_BGP;
3174 new->sub_type = BGP_ROUTE_STATIC;
3175 new->peer = bgp->peer_self;
3176 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3177 SET_FLAG (new->flags, BGP_INFO_VALID);
3178 new->uptime = time (NULL);
3179 memcpy (new->tag, tag, 3);
3181 /* Aggregate address increment. */
3182 bgp_aggregate_increment (bgp, p, new, afi, safi);
3184 /* Register new BGP information. */
3185 bgp_info_add (rn, new);
3187 /* route_node_get lock */
3188 bgp_unlock_node (rn);
3190 /* Process change. */
3191 bgp_process (bgp, rn, afi, safi);
3194 void
3195 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3196 safi_t safi)
3198 struct bgp_node *rn;
3199 struct bgp_info *ri;
3201 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3203 /* Check selected route and self inserted route. */
3204 for (ri = rn->info; ri; ri = ri->next)
3205 if (ri->peer == bgp->peer_self
3206 && ri->type == ZEBRA_ROUTE_BGP
3207 && ri->sub_type == BGP_ROUTE_STATIC)
3208 break;
3210 /* Withdraw static BGP route from routing table. */
3211 if (ri)
3213 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3214 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3215 bgp_process (bgp, rn, afi, safi);
3216 bgp_info_delete (rn, ri);
3219 /* Unlock bgp_node_lookup. */
3220 bgp_unlock_node (rn);
3223 void
3224 bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3226 struct bgp_static *bgp_static;
3227 struct bgp *bgp;
3228 struct bgp_node *rn;
3229 struct prefix *p;
3231 bgp = rsclient->bgp;
3233 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3234 if ((bgp_static = rn->info) != NULL)
3236 p = &rn->p;
3238 bgp_static_update_rsclient (rsclient, p, bgp_static,
3239 afi, safi);
3243 static void
3244 bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3245 u_char safi, struct prefix_rd *prd, u_char *tag)
3247 struct bgp_node *rn;
3248 struct bgp_info *ri;
3250 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3252 /* Check selected route and self inserted route. */
3253 for (ri = rn->info; ri; ri = ri->next)
3254 if (ri->peer == bgp->peer_self
3255 && ri->type == ZEBRA_ROUTE_BGP
3256 && ri->sub_type == BGP_ROUTE_STATIC)
3257 break;
3259 /* Withdraw static BGP route from routing table. */
3260 if (ri)
3262 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3263 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3264 bgp_process (bgp, rn, afi, safi);
3265 bgp_info_delete (rn, ri);
3268 /* Unlock bgp_node_lookup. */
3269 bgp_unlock_node (rn);
3272 /* Configure static BGP network. When user don't run zebra, static
3273 route should be installed as valid. */
3274 static int
3275 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3276 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
3278 int ret;
3279 struct prefix p;
3280 struct bgp_static *bgp_static;
3281 struct bgp_node *rn;
3282 int need_update = 0;
3284 /* Convert IP prefix string to struct prefix. */
3285 ret = str2prefix (ip_str, &p);
3286 if (! ret)
3288 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3289 return CMD_WARNING;
3291 #ifdef HAVE_IPV6
3292 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3294 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3295 VTY_NEWLINE);
3296 return CMD_WARNING;
3298 #endif /* HAVE_IPV6 */
3300 apply_mask (&p);
3302 /* Set BGP static route configuration. */
3303 rn = bgp_node_get (bgp->route[afi][safi], &p);
3305 if (rn->info)
3307 /* Configuration change. */
3308 bgp_static = rn->info;
3310 /* Check previous routes are installed into BGP. */
3311 if (! bgp_static->backdoor && bgp_static->valid)
3312 need_update = 1;
3314 bgp_static->backdoor = backdoor;
3315 if (rmap)
3317 if (bgp_static->rmap.name)
3318 free (bgp_static->rmap.name);
3319 bgp_static->rmap.name = strdup (rmap);
3320 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3322 else
3324 if (bgp_static->rmap.name)
3325 free (bgp_static->rmap.name);
3326 bgp_static->rmap.name = NULL;
3327 bgp_static->rmap.map = NULL;
3328 bgp_static->valid = 0;
3330 bgp_unlock_node (rn);
3332 else
3334 /* New configuration. */
3335 bgp_static = bgp_static_new ();
3336 bgp_static->backdoor = backdoor;
3337 bgp_static->valid = 0;
3338 bgp_static->igpmetric = 0;
3339 bgp_static->igpnexthop.s_addr = 0;
3340 if (rmap)
3342 if (bgp_static->rmap.name)
3343 free (bgp_static->rmap.name);
3344 bgp_static->rmap.name = strdup (rmap);
3345 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3347 rn->info = bgp_static;
3350 /* If BGP scan is not enabled, we should install this route here. */
3351 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3353 bgp_static->valid = 1;
3355 if (need_update)
3356 bgp_static_withdraw (bgp, &p, afi, safi);
3358 if (! bgp_static->backdoor)
3359 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3362 return CMD_SUCCESS;
3365 /* Configure static BGP network. */
3366 static int
3367 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
3368 u_int16_t afi, u_char safi)
3370 int ret;
3371 struct prefix p;
3372 struct bgp_static *bgp_static;
3373 struct bgp_node *rn;
3375 /* Convert IP prefix string to struct prefix. */
3376 ret = str2prefix (ip_str, &p);
3377 if (! ret)
3379 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3380 return CMD_WARNING;
3382 #ifdef HAVE_IPV6
3383 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3385 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3386 VTY_NEWLINE);
3387 return CMD_WARNING;
3389 #endif /* HAVE_IPV6 */
3391 apply_mask (&p);
3393 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3394 if (! rn)
3396 vty_out (vty, "%% Can't find specified static route configuration.%s",
3397 VTY_NEWLINE);
3398 return CMD_WARNING;
3401 bgp_static = rn->info;
3403 /* Update BGP RIB. */
3404 if (! bgp_static->backdoor)
3405 bgp_static_withdraw (bgp, &p, afi, safi);
3407 /* Clear configuration. */
3408 bgp_static_free (bgp_static);
3409 rn->info = NULL;
3410 bgp_unlock_node (rn);
3411 bgp_unlock_node (rn);
3413 return CMD_SUCCESS;
3416 /* Called from bgp_delete(). Delete all static routes from the BGP
3417 instance. */
3418 void
3419 bgp_static_delete (struct bgp *bgp)
3421 afi_t afi;
3422 safi_t safi;
3423 struct bgp_node *rn;
3424 struct bgp_node *rm;
3425 struct bgp_table *table;
3426 struct bgp_static *bgp_static;
3428 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3429 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3430 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3431 if (rn->info != NULL)
3433 if (safi == SAFI_MPLS_VPN)
3435 table = rn->info;
3437 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3439 bgp_static = rn->info;
3440 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3441 AFI_IP, SAFI_MPLS_VPN,
3442 (struct prefix_rd *)&rn->p,
3443 bgp_static->tag);
3444 bgp_static_free (bgp_static);
3445 rn->info = NULL;
3446 bgp_unlock_node (rn);
3449 else
3451 bgp_static = rn->info;
3452 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3453 bgp_static_free (bgp_static);
3454 rn->info = NULL;
3455 bgp_unlock_node (rn);
3461 bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3462 const char *tag_str)
3464 int ret;
3465 struct prefix p;
3466 struct prefix_rd prd;
3467 struct bgp *bgp;
3468 struct bgp_node *prn;
3469 struct bgp_node *rn;
3470 struct bgp_table *table;
3471 struct bgp_static *bgp_static;
3472 u_char tag[3];
3474 bgp = vty->index;
3476 ret = str2prefix (ip_str, &p);
3477 if (! ret)
3479 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3480 return CMD_WARNING;
3482 apply_mask (&p);
3484 ret = str2prefix_rd (rd_str, &prd);
3485 if (! ret)
3487 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3488 return CMD_WARNING;
3491 ret = str2tag (tag_str, tag);
3492 if (! ret)
3494 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3495 return CMD_WARNING;
3498 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3499 (struct prefix *)&prd);
3500 if (prn->info == NULL)
3501 prn->info = bgp_table_init ();
3502 else
3503 bgp_unlock_node (prn);
3504 table = prn->info;
3506 rn = bgp_node_get (table, &p);
3508 if (rn->info)
3510 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3511 bgp_unlock_node (rn);
3513 else
3515 /* New configuration. */
3516 bgp_static = bgp_static_new ();
3517 bgp_static->valid = 1;
3518 memcpy (bgp_static->tag, tag, 3);
3519 rn->info = bgp_static;
3521 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3524 return CMD_SUCCESS;
3527 /* Configure static BGP network. */
3529 bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3530 const char *rd_str, const char *tag_str)
3532 int ret;
3533 struct bgp *bgp;
3534 struct prefix p;
3535 struct prefix_rd prd;
3536 struct bgp_node *prn;
3537 struct bgp_node *rn;
3538 struct bgp_table *table;
3539 struct bgp_static *bgp_static;
3540 u_char tag[3];
3542 bgp = vty->index;
3544 /* Convert IP prefix string to struct prefix. */
3545 ret = str2prefix (ip_str, &p);
3546 if (! ret)
3548 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3549 return CMD_WARNING;
3551 apply_mask (&p);
3553 ret = str2prefix_rd (rd_str, &prd);
3554 if (! ret)
3556 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3557 return CMD_WARNING;
3560 ret = str2tag (tag_str, tag);
3561 if (! ret)
3563 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3564 return CMD_WARNING;
3567 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3568 (struct prefix *)&prd);
3569 if (prn->info == NULL)
3570 prn->info = bgp_table_init ();
3571 else
3572 bgp_unlock_node (prn);
3573 table = prn->info;
3575 rn = bgp_node_lookup (table, &p);
3577 if (rn)
3579 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3581 bgp_static = rn->info;
3582 bgp_static_free (bgp_static);
3583 rn->info = NULL;
3584 bgp_unlock_node (rn);
3585 bgp_unlock_node (rn);
3587 else
3588 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3590 return CMD_SUCCESS;
3593 DEFUN (bgp_network,
3594 bgp_network_cmd,
3595 "network A.B.C.D/M",
3596 "Specify a network to announce via BGP\n"
3597 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3599 return bgp_static_set (vty, vty->index, argv[0],
3600 AFI_IP, bgp_node_safi (vty), NULL, 0);
3603 DEFUN (bgp_network_route_map,
3604 bgp_network_route_map_cmd,
3605 "network A.B.C.D/M route-map WORD",
3606 "Specify a network to announce via BGP\n"
3607 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3608 "Route-map to modify the attributes\n"
3609 "Name of the route map\n")
3611 return bgp_static_set (vty, vty->index, argv[0],
3612 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3615 DEFUN (bgp_network_backdoor,
3616 bgp_network_backdoor_cmd,
3617 "network A.B.C.D/M backdoor",
3618 "Specify a network to announce via BGP\n"
3619 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3620 "Specify a BGP backdoor route\n")
3622 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3625 DEFUN (bgp_network_mask,
3626 bgp_network_mask_cmd,
3627 "network A.B.C.D mask A.B.C.D",
3628 "Specify a network to announce via BGP\n"
3629 "Network number\n"
3630 "Network mask\n"
3631 "Network mask\n")
3633 int ret;
3634 char prefix_str[BUFSIZ];
3636 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3637 if (! ret)
3639 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3640 return CMD_WARNING;
3643 return bgp_static_set (vty, vty->index, prefix_str,
3644 AFI_IP, bgp_node_safi (vty), NULL, 0);
3647 DEFUN (bgp_network_mask_route_map,
3648 bgp_network_mask_route_map_cmd,
3649 "network A.B.C.D mask A.B.C.D route-map WORD",
3650 "Specify a network to announce via BGP\n"
3651 "Network number\n"
3652 "Network mask\n"
3653 "Network mask\n"
3654 "Route-map to modify the attributes\n"
3655 "Name of the route map\n")
3657 int ret;
3658 char prefix_str[BUFSIZ];
3660 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3661 if (! ret)
3663 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3664 return CMD_WARNING;
3667 return bgp_static_set (vty, vty->index, prefix_str,
3668 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3671 DEFUN (bgp_network_mask_backdoor,
3672 bgp_network_mask_backdoor_cmd,
3673 "network A.B.C.D mask A.B.C.D backdoor",
3674 "Specify a network to announce via BGP\n"
3675 "Network number\n"
3676 "Network mask\n"
3677 "Network mask\n"
3678 "Specify a BGP backdoor route\n")
3680 int ret;
3681 char prefix_str[BUFSIZ];
3683 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3684 if (! ret)
3686 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3687 return CMD_WARNING;
3690 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3693 DEFUN (bgp_network_mask_natural,
3694 bgp_network_mask_natural_cmd,
3695 "network A.B.C.D",
3696 "Specify a network to announce via BGP\n"
3697 "Network number\n")
3699 int ret;
3700 char prefix_str[BUFSIZ];
3702 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3703 if (! ret)
3705 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3706 return CMD_WARNING;
3709 return bgp_static_set (vty, vty->index, prefix_str,
3710 AFI_IP, bgp_node_safi (vty), NULL, 0);
3713 DEFUN (bgp_network_mask_natural_route_map,
3714 bgp_network_mask_natural_route_map_cmd,
3715 "network A.B.C.D route-map WORD",
3716 "Specify a network to announce via BGP\n"
3717 "Network number\n"
3718 "Route-map to modify the attributes\n"
3719 "Name of the route map\n")
3721 int ret;
3722 char prefix_str[BUFSIZ];
3724 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3725 if (! ret)
3727 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3728 return CMD_WARNING;
3731 return bgp_static_set (vty, vty->index, prefix_str,
3732 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3735 DEFUN (bgp_network_mask_natural_backdoor,
3736 bgp_network_mask_natural_backdoor_cmd,
3737 "network A.B.C.D backdoor",
3738 "Specify a network to announce via BGP\n"
3739 "Network number\n"
3740 "Specify a BGP backdoor route\n")
3742 int ret;
3743 char prefix_str[BUFSIZ];
3745 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3746 if (! ret)
3748 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3749 return CMD_WARNING;
3752 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3755 DEFUN (no_bgp_network,
3756 no_bgp_network_cmd,
3757 "no network A.B.C.D/M",
3758 NO_STR
3759 "Specify a network to announce via BGP\n"
3760 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3762 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3763 bgp_node_safi (vty));
3766 ALIAS (no_bgp_network,
3767 no_bgp_network_route_map_cmd,
3768 "no network A.B.C.D/M route-map WORD",
3769 NO_STR
3770 "Specify a network to announce via BGP\n"
3771 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3772 "Route-map to modify the attributes\n"
3773 "Name of the route map\n")
3775 ALIAS (no_bgp_network,
3776 no_bgp_network_backdoor_cmd,
3777 "no network A.B.C.D/M backdoor",
3778 NO_STR
3779 "Specify a network to announce via BGP\n"
3780 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3781 "Specify a BGP backdoor route\n")
3783 DEFUN (no_bgp_network_mask,
3784 no_bgp_network_mask_cmd,
3785 "no network A.B.C.D mask A.B.C.D",
3786 NO_STR
3787 "Specify a network to announce via BGP\n"
3788 "Network number\n"
3789 "Network mask\n"
3790 "Network mask\n")
3792 int ret;
3793 char prefix_str[BUFSIZ];
3795 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3796 if (! ret)
3798 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3799 return CMD_WARNING;
3802 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3803 bgp_node_safi (vty));
3806 ALIAS (no_bgp_network_mask,
3807 no_bgp_network_mask_route_map_cmd,
3808 "no network A.B.C.D mask A.B.C.D route-map WORD",
3809 NO_STR
3810 "Specify a network to announce via BGP\n"
3811 "Network number\n"
3812 "Network mask\n"
3813 "Network mask\n"
3814 "Route-map to modify the attributes\n"
3815 "Name of the route map\n")
3817 ALIAS (no_bgp_network_mask,
3818 no_bgp_network_mask_backdoor_cmd,
3819 "no network A.B.C.D mask A.B.C.D backdoor",
3820 NO_STR
3821 "Specify a network to announce via BGP\n"
3822 "Network number\n"
3823 "Network mask\n"
3824 "Network mask\n"
3825 "Specify a BGP backdoor route\n")
3827 DEFUN (no_bgp_network_mask_natural,
3828 no_bgp_network_mask_natural_cmd,
3829 "no network A.B.C.D",
3830 NO_STR
3831 "Specify a network to announce via BGP\n"
3832 "Network number\n")
3834 int ret;
3835 char prefix_str[BUFSIZ];
3837 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3838 if (! ret)
3840 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3841 return CMD_WARNING;
3844 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3845 bgp_node_safi (vty));
3848 ALIAS (no_bgp_network_mask_natural,
3849 no_bgp_network_mask_natural_route_map_cmd,
3850 "no network A.B.C.D route-map WORD",
3851 NO_STR
3852 "Specify a network to announce via BGP\n"
3853 "Network number\n"
3854 "Route-map to modify the attributes\n"
3855 "Name of the route map\n")
3857 ALIAS (no_bgp_network_mask_natural,
3858 no_bgp_network_mask_natural_backdoor_cmd,
3859 "no network A.B.C.D backdoor",
3860 NO_STR
3861 "Specify a network to announce via BGP\n"
3862 "Network number\n"
3863 "Specify a BGP backdoor route\n")
3865 #ifdef HAVE_IPV6
3866 DEFUN (ipv6_bgp_network,
3867 ipv6_bgp_network_cmd,
3868 "network X:X::X:X/M",
3869 "Specify a network to announce via BGP\n"
3870 "IPv6 prefix <network>/<length>\n")
3872 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3875 DEFUN (ipv6_bgp_network_route_map,
3876 ipv6_bgp_network_route_map_cmd,
3877 "network X:X::X:X/M route-map WORD",
3878 "Specify a network to announce via BGP\n"
3879 "IPv6 prefix <network>/<length>\n"
3880 "Route-map to modify the attributes\n"
3881 "Name of the route map\n")
3883 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3884 bgp_node_safi (vty), argv[1], 0);
3887 DEFUN (no_ipv6_bgp_network,
3888 no_ipv6_bgp_network_cmd,
3889 "no network X:X::X:X/M",
3890 NO_STR
3891 "Specify a network to announce via BGP\n"
3892 "IPv6 prefix <network>/<length>\n")
3894 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3897 ALIAS (no_ipv6_bgp_network,
3898 no_ipv6_bgp_network_route_map_cmd,
3899 "no network X:X::X:X/M route-map WORD",
3900 NO_STR
3901 "Specify a network to announce via BGP\n"
3902 "IPv6 prefix <network>/<length>\n"
3903 "Route-map to modify the attributes\n"
3904 "Name of the route map\n")
3906 ALIAS (ipv6_bgp_network,
3907 old_ipv6_bgp_network_cmd,
3908 "ipv6 bgp network X:X::X:X/M",
3909 IPV6_STR
3910 BGP_STR
3911 "Specify a network to announce via BGP\n"
3912 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3914 ALIAS (no_ipv6_bgp_network,
3915 old_no_ipv6_bgp_network_cmd,
3916 "no ipv6 bgp network X:X::X:X/M",
3917 NO_STR
3918 IPV6_STR
3919 BGP_STR
3920 "Specify a network to announce via BGP\n"
3921 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3922 #endif /* HAVE_IPV6 */
3924 /* Aggreagete address:
3926 advertise-map Set condition to advertise attribute
3927 as-set Generate AS set path information
3928 attribute-map Set attributes of aggregate
3929 route-map Set parameters of aggregate
3930 summary-only Filter more specific routes from updates
3931 suppress-map Conditionally filter more specific routes from updates
3932 <cr>
3934 struct bgp_aggregate
3936 /* Summary-only flag. */
3937 u_char summary_only;
3939 /* AS set generation. */
3940 u_char as_set;
3942 /* Route-map for aggregated route. */
3943 struct route_map *map;
3945 /* Suppress-count. */
3946 unsigned long count;
3948 /* SAFI configuration. */
3949 safi_t safi;
3952 static struct bgp_aggregate *
3953 bgp_aggregate_new ()
3955 struct bgp_aggregate *new;
3956 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
3957 memset (new, 0, sizeof (struct bgp_aggregate));
3958 return new;
3961 static void
3962 bgp_aggregate_free (struct bgp_aggregate *aggregate)
3964 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
3967 static void
3968 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
3969 afi_t afi, safi_t safi, struct bgp_info *del,
3970 struct bgp_aggregate *aggregate)
3972 struct bgp_table *table;
3973 struct bgp_node *top;
3974 struct bgp_node *rn;
3975 u_char origin;
3976 struct aspath *aspath = NULL;
3977 struct aspath *asmerge = NULL;
3978 struct community *community = NULL;
3979 struct community *commerge = NULL;
3980 struct in_addr nexthop;
3981 u_int32_t med = 0;
3982 struct bgp_info *ri;
3983 struct bgp_info *new;
3984 int first = 1;
3985 unsigned long match = 0;
3987 /* Record adding route's nexthop and med. */
3988 if (rinew)
3990 nexthop = rinew->attr->nexthop;
3991 med = rinew->attr->med;
3994 /* ORIGIN attribute: If at least one route among routes that are
3995 aggregated has ORIGIN with the value INCOMPLETE, then the
3996 aggregated route must have the ORIGIN attribute with the value
3997 INCOMPLETE. Otherwise, if at least one route among routes that
3998 are aggregated has ORIGIN with the value EGP, then the aggregated
3999 route must have the origin attribute with the value EGP. In all
4000 other case the value of the ORIGIN attribute of the aggregated
4001 route is INTERNAL. */
4002 origin = BGP_ORIGIN_IGP;
4004 table = bgp->rib[afi][safi];
4006 top = bgp_node_get (table, p);
4007 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4008 if (rn->p.prefixlen > p->prefixlen)
4010 match = 0;
4012 for (ri = rn->info; ri; ri = ri->next)
4014 if (BGP_INFO_HOLDDOWN (ri))
4015 continue;
4017 if (del && ri == del)
4018 continue;
4020 if (! rinew && first)
4022 nexthop = ri->attr->nexthop;
4023 med = ri->attr->med;
4024 first = 0;
4027 #ifdef AGGREGATE_NEXTHOP_CHECK
4028 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4029 || ri->attr->med != med)
4031 if (aspath)
4032 aspath_free (aspath);
4033 if (community)
4034 community_free (community);
4035 bgp_unlock_node (rn);
4036 bgp_unlock_node (top);
4037 return;
4039 #endif /* AGGREGATE_NEXTHOP_CHECK */
4041 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4043 if (aggregate->summary_only)
4045 ri->suppress++;
4046 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4047 match++;
4050 aggregate->count++;
4052 if (aggregate->as_set)
4054 if (origin < ri->attr->origin)
4055 origin = ri->attr->origin;
4057 if (aspath)
4059 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4060 aspath_free (aspath);
4061 aspath = asmerge;
4063 else
4064 aspath = aspath_dup (ri->attr->aspath);
4066 if (ri->attr->community)
4068 if (community)
4070 commerge = community_merge (community,
4071 ri->attr->community);
4072 community = community_uniq_sort (commerge);
4073 community_free (commerge);
4075 else
4076 community = community_dup (ri->attr->community);
4081 if (match)
4082 bgp_process (bgp, rn, afi, safi);
4084 bgp_unlock_node (top);
4086 if (rinew)
4088 aggregate->count++;
4090 if (aggregate->summary_only)
4091 rinew->suppress++;
4093 if (aggregate->as_set)
4095 if (origin < rinew->attr->origin)
4096 origin = rinew->attr->origin;
4098 if (aspath)
4100 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4101 aspath_free (aspath);
4102 aspath = asmerge;
4104 else
4105 aspath = aspath_dup (rinew->attr->aspath);
4107 if (rinew->attr->community)
4109 if (community)
4111 commerge = community_merge (community,
4112 rinew->attr->community);
4113 community = community_uniq_sort (commerge);
4114 community_free (commerge);
4116 else
4117 community = community_dup (rinew->attr->community);
4122 if (aggregate->count > 0)
4124 rn = bgp_node_get (table, p);
4125 new = bgp_info_new ();
4126 new->type = ZEBRA_ROUTE_BGP;
4127 new->sub_type = BGP_ROUTE_AGGREGATE;
4128 new->peer = bgp->peer_self;
4129 SET_FLAG (new->flags, BGP_INFO_VALID);
4130 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4131 new->uptime = time (NULL);
4133 bgp_info_add (rn, new);
4134 bgp_unlock_node (rn);
4135 bgp_process (bgp, rn, afi, safi);
4137 else
4139 if (aspath)
4140 aspath_free (aspath);
4141 if (community)
4142 community_free (community);
4146 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4147 struct bgp_aggregate *);
4149 void
4150 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4151 struct bgp_info *ri, afi_t afi, safi_t safi)
4153 struct bgp_node *child;
4154 struct bgp_node *rn;
4155 struct bgp_aggregate *aggregate;
4157 /* MPLS-VPN aggregation is not yet supported. */
4158 if (safi == SAFI_MPLS_VPN)
4159 return;
4161 if (p->prefixlen == 0)
4162 return;
4164 if (BGP_INFO_HOLDDOWN (ri))
4165 return;
4167 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4169 /* Aggregate address configuration check. */
4170 for (rn = child; rn; rn = rn->parent)
4171 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4173 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4174 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
4176 bgp_unlock_node (child);
4179 void
4180 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4181 struct bgp_info *del, afi_t afi, safi_t safi)
4183 struct bgp_node *child;
4184 struct bgp_node *rn;
4185 struct bgp_aggregate *aggregate;
4187 /* MPLS-VPN aggregation is not yet supported. */
4188 if (safi == SAFI_MPLS_VPN)
4189 return;
4191 if (p->prefixlen == 0)
4192 return;
4194 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4196 /* Aggregate address configuration check. */
4197 for (rn = child; rn; rn = rn->parent)
4198 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4200 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4201 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
4203 bgp_unlock_node (child);
4206 static void
4207 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4208 struct bgp_aggregate *aggregate)
4210 struct bgp_table *table;
4211 struct bgp_node *top;
4212 struct bgp_node *rn;
4213 struct bgp_info *new;
4214 struct bgp_info *ri;
4215 unsigned long match;
4216 u_char origin = BGP_ORIGIN_IGP;
4217 struct aspath *aspath = NULL;
4218 struct aspath *asmerge = NULL;
4219 struct community *community = NULL;
4220 struct community *commerge = NULL;
4222 table = bgp->rib[afi][safi];
4224 /* Sanity check. */
4225 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4226 return;
4227 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4228 return;
4230 /* If routes exists below this node, generate aggregate routes. */
4231 top = bgp_node_get (table, p);
4232 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4233 if (rn->p.prefixlen > p->prefixlen)
4235 match = 0;
4237 for (ri = rn->info; ri; ri = ri->next)
4239 if (BGP_INFO_HOLDDOWN (ri))
4240 continue;
4242 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4244 /* summary-only aggregate route suppress aggregated
4245 route announcement. */
4246 if (aggregate->summary_only)
4248 ri->suppress++;
4249 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4250 match++;
4252 /* as-set aggregate route generate origin, as path,
4253 community aggregation. */
4254 if (aggregate->as_set)
4256 if (origin < ri->attr->origin)
4257 origin = ri->attr->origin;
4259 if (aspath)
4261 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4262 aspath_free (aspath);
4263 aspath = asmerge;
4265 else
4266 aspath = aspath_dup (ri->attr->aspath);
4268 if (ri->attr->community)
4270 if (community)
4272 commerge = community_merge (community,
4273 ri->attr->community);
4274 community = community_uniq_sort (commerge);
4275 community_free (commerge);
4277 else
4278 community = community_dup (ri->attr->community);
4281 aggregate->count++;
4285 /* If this node is suppressed, process the change. */
4286 if (match)
4287 bgp_process (bgp, rn, afi, safi);
4289 bgp_unlock_node (top);
4291 /* Add aggregate route to BGP table. */
4292 if (aggregate->count)
4294 rn = bgp_node_get (table, p);
4296 new = bgp_info_new ();
4297 new->type = ZEBRA_ROUTE_BGP;
4298 new->sub_type = BGP_ROUTE_AGGREGATE;
4299 new->peer = bgp->peer_self;
4300 SET_FLAG (new->flags, BGP_INFO_VALID);
4301 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4302 new->uptime = time (NULL);
4304 bgp_info_add (rn, new);
4305 bgp_unlock_node (rn);
4307 /* Process change. */
4308 bgp_process (bgp, rn, afi, safi);
4312 void
4313 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4314 safi_t safi, struct bgp_aggregate *aggregate)
4316 struct bgp_table *table;
4317 struct bgp_node *top;
4318 struct bgp_node *rn;
4319 struct bgp_info *ri;
4320 unsigned long match;
4322 table = bgp->rib[afi][safi];
4324 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4325 return;
4326 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4327 return;
4329 /* If routes exists below this node, generate aggregate routes. */
4330 top = bgp_node_get (table, p);
4331 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4332 if (rn->p.prefixlen > p->prefixlen)
4334 match = 0;
4336 for (ri = rn->info; ri; ri = ri->next)
4338 if (BGP_INFO_HOLDDOWN (ri))
4339 continue;
4341 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4343 if (aggregate->summary_only)
4345 ri->suppress--;
4347 if (ri->suppress == 0)
4349 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4350 match++;
4353 aggregate->count--;
4357 /* If this node is suppressed, process the change. */
4358 if (match)
4359 bgp_process (bgp, rn, afi, safi);
4361 bgp_unlock_node (top);
4363 /* Delete aggregate route from BGP table. */
4364 rn = bgp_node_get (table, p);
4366 for (ri = rn->info; ri; ri = ri->next)
4367 if (ri->peer == bgp->peer_self
4368 && ri->type == ZEBRA_ROUTE_BGP
4369 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4370 break;
4372 /* Withdraw static BGP route from routing table. */
4373 if (ri)
4375 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4376 bgp_process (bgp, rn, afi, safi);
4377 bgp_info_delete (rn, ri);
4380 /* Unlock bgp_node_lookup. */
4381 bgp_unlock_node (rn);
4384 /* Aggregate route attribute. */
4385 #define AGGREGATE_SUMMARY_ONLY 1
4386 #define AGGREGATE_AS_SET 1
4388 static int
4389 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4390 afi_t afi, safi_t safi,
4391 u_char summary_only, u_char as_set)
4393 int ret;
4394 struct prefix p;
4395 struct bgp_node *rn;
4396 struct bgp *bgp;
4397 struct bgp_aggregate *aggregate;
4399 /* Convert string to prefix structure. */
4400 ret = str2prefix (prefix_str, &p);
4401 if (!ret)
4403 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4404 return CMD_WARNING;
4406 apply_mask (&p);
4408 /* Get BGP structure. */
4409 bgp = vty->index;
4411 /* Old configuration check. */
4412 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4414 if (rn->info)
4416 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4417 bgp_unlock_node (rn);
4418 return CMD_WARNING;
4421 /* Make aggregate address structure. */
4422 aggregate = bgp_aggregate_new ();
4423 aggregate->summary_only = summary_only;
4424 aggregate->as_set = as_set;
4425 aggregate->safi = safi;
4426 rn->info = aggregate;
4428 /* Aggregate address insert into BGP routing table. */
4429 if (safi & SAFI_UNICAST)
4430 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4431 if (safi & SAFI_MULTICAST)
4432 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4434 return CMD_SUCCESS;
4437 static int
4438 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4439 afi_t afi, safi_t safi)
4441 int ret;
4442 struct prefix p;
4443 struct bgp_node *rn;
4444 struct bgp *bgp;
4445 struct bgp_aggregate *aggregate;
4447 /* Convert string to prefix structure. */
4448 ret = str2prefix (prefix_str, &p);
4449 if (!ret)
4451 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4452 return CMD_WARNING;
4454 apply_mask (&p);
4456 /* Get BGP structure. */
4457 bgp = vty->index;
4459 /* Old configuration check. */
4460 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4461 if (! rn)
4463 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4464 VTY_NEWLINE);
4465 return CMD_WARNING;
4468 aggregate = rn->info;
4469 if (aggregate->safi & SAFI_UNICAST)
4470 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4471 if (aggregate->safi & SAFI_MULTICAST)
4472 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4474 /* Unlock aggregate address configuration. */
4475 rn->info = NULL;
4476 bgp_aggregate_free (aggregate);
4477 bgp_unlock_node (rn);
4478 bgp_unlock_node (rn);
4480 return CMD_SUCCESS;
4483 DEFUN (aggregate_address,
4484 aggregate_address_cmd,
4485 "aggregate-address A.B.C.D/M",
4486 "Configure BGP aggregate entries\n"
4487 "Aggregate prefix\n")
4489 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4492 DEFUN (aggregate_address_mask,
4493 aggregate_address_mask_cmd,
4494 "aggregate-address A.B.C.D A.B.C.D",
4495 "Configure BGP aggregate entries\n"
4496 "Aggregate address\n"
4497 "Aggregate mask\n")
4499 int ret;
4500 char prefix_str[BUFSIZ];
4502 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4504 if (! ret)
4506 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4507 return CMD_WARNING;
4510 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4511 0, 0);
4514 DEFUN (aggregate_address_summary_only,
4515 aggregate_address_summary_only_cmd,
4516 "aggregate-address A.B.C.D/M summary-only",
4517 "Configure BGP aggregate entries\n"
4518 "Aggregate prefix\n"
4519 "Filter more specific routes from updates\n")
4521 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4522 AGGREGATE_SUMMARY_ONLY, 0);
4525 DEFUN (aggregate_address_mask_summary_only,
4526 aggregate_address_mask_summary_only_cmd,
4527 "aggregate-address A.B.C.D A.B.C.D summary-only",
4528 "Configure BGP aggregate entries\n"
4529 "Aggregate address\n"
4530 "Aggregate mask\n"
4531 "Filter more specific routes from updates\n")
4533 int ret;
4534 char prefix_str[BUFSIZ];
4536 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4538 if (! ret)
4540 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4541 return CMD_WARNING;
4544 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4545 AGGREGATE_SUMMARY_ONLY, 0);
4548 DEFUN (aggregate_address_as_set,
4549 aggregate_address_as_set_cmd,
4550 "aggregate-address A.B.C.D/M as-set",
4551 "Configure BGP aggregate entries\n"
4552 "Aggregate prefix\n"
4553 "Generate AS set path information\n")
4555 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4556 0, AGGREGATE_AS_SET);
4559 DEFUN (aggregate_address_mask_as_set,
4560 aggregate_address_mask_as_set_cmd,
4561 "aggregate-address A.B.C.D A.B.C.D as-set",
4562 "Configure BGP aggregate entries\n"
4563 "Aggregate address\n"
4564 "Aggregate mask\n"
4565 "Generate AS set path information\n")
4567 int ret;
4568 char prefix_str[BUFSIZ];
4570 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4572 if (! ret)
4574 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4575 return CMD_WARNING;
4578 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4579 0, AGGREGATE_AS_SET);
4583 DEFUN (aggregate_address_as_set_summary,
4584 aggregate_address_as_set_summary_cmd,
4585 "aggregate-address A.B.C.D/M as-set summary-only",
4586 "Configure BGP aggregate entries\n"
4587 "Aggregate prefix\n"
4588 "Generate AS set path information\n"
4589 "Filter more specific routes from updates\n")
4591 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4592 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4595 ALIAS (aggregate_address_as_set_summary,
4596 aggregate_address_summary_as_set_cmd,
4597 "aggregate-address A.B.C.D/M summary-only as-set",
4598 "Configure BGP aggregate entries\n"
4599 "Aggregate prefix\n"
4600 "Filter more specific routes from updates\n"
4601 "Generate AS set path information\n")
4603 DEFUN (aggregate_address_mask_as_set_summary,
4604 aggregate_address_mask_as_set_summary_cmd,
4605 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4606 "Configure BGP aggregate entries\n"
4607 "Aggregate address\n"
4608 "Aggregate mask\n"
4609 "Generate AS set path information\n"
4610 "Filter more specific routes from updates\n")
4612 int ret;
4613 char prefix_str[BUFSIZ];
4615 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4617 if (! ret)
4619 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4620 return CMD_WARNING;
4623 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4624 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4627 ALIAS (aggregate_address_mask_as_set_summary,
4628 aggregate_address_mask_summary_as_set_cmd,
4629 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4630 "Configure BGP aggregate entries\n"
4631 "Aggregate address\n"
4632 "Aggregate mask\n"
4633 "Filter more specific routes from updates\n"
4634 "Generate AS set path information\n")
4636 DEFUN (no_aggregate_address,
4637 no_aggregate_address_cmd,
4638 "no aggregate-address A.B.C.D/M",
4639 NO_STR
4640 "Configure BGP aggregate entries\n"
4641 "Aggregate prefix\n")
4643 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4646 ALIAS (no_aggregate_address,
4647 no_aggregate_address_summary_only_cmd,
4648 "no aggregate-address A.B.C.D/M summary-only",
4649 NO_STR
4650 "Configure BGP aggregate entries\n"
4651 "Aggregate prefix\n"
4652 "Filter more specific routes from updates\n")
4654 ALIAS (no_aggregate_address,
4655 no_aggregate_address_as_set_cmd,
4656 "no aggregate-address A.B.C.D/M as-set",
4657 NO_STR
4658 "Configure BGP aggregate entries\n"
4659 "Aggregate prefix\n"
4660 "Generate AS set path information\n")
4662 ALIAS (no_aggregate_address,
4663 no_aggregate_address_as_set_summary_cmd,
4664 "no aggregate-address A.B.C.D/M as-set summary-only",
4665 NO_STR
4666 "Configure BGP aggregate entries\n"
4667 "Aggregate prefix\n"
4668 "Generate AS set path information\n"
4669 "Filter more specific routes from updates\n")
4671 ALIAS (no_aggregate_address,
4672 no_aggregate_address_summary_as_set_cmd,
4673 "no aggregate-address A.B.C.D/M summary-only as-set",
4674 NO_STR
4675 "Configure BGP aggregate entries\n"
4676 "Aggregate prefix\n"
4677 "Filter more specific routes from updates\n"
4678 "Generate AS set path information\n")
4680 DEFUN (no_aggregate_address_mask,
4681 no_aggregate_address_mask_cmd,
4682 "no aggregate-address A.B.C.D A.B.C.D",
4683 NO_STR
4684 "Configure BGP aggregate entries\n"
4685 "Aggregate address\n"
4686 "Aggregate mask\n")
4688 int ret;
4689 char prefix_str[BUFSIZ];
4691 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4693 if (! ret)
4695 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4696 return CMD_WARNING;
4699 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4702 ALIAS (no_aggregate_address_mask,
4703 no_aggregate_address_mask_summary_only_cmd,
4704 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4705 NO_STR
4706 "Configure BGP aggregate entries\n"
4707 "Aggregate address\n"
4708 "Aggregate mask\n"
4709 "Filter more specific routes from updates\n")
4711 ALIAS (no_aggregate_address_mask,
4712 no_aggregate_address_mask_as_set_cmd,
4713 "no aggregate-address A.B.C.D A.B.C.D as-set",
4714 NO_STR
4715 "Configure BGP aggregate entries\n"
4716 "Aggregate address\n"
4717 "Aggregate mask\n"
4718 "Generate AS set path information\n")
4720 ALIAS (no_aggregate_address_mask,
4721 no_aggregate_address_mask_as_set_summary_cmd,
4722 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4723 NO_STR
4724 "Configure BGP aggregate entries\n"
4725 "Aggregate address\n"
4726 "Aggregate mask\n"
4727 "Generate AS set path information\n"
4728 "Filter more specific routes from updates\n")
4730 ALIAS (no_aggregate_address_mask,
4731 no_aggregate_address_mask_summary_as_set_cmd,
4732 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4733 NO_STR
4734 "Configure BGP aggregate entries\n"
4735 "Aggregate address\n"
4736 "Aggregate mask\n"
4737 "Filter more specific routes from updates\n"
4738 "Generate AS set path information\n")
4740 #ifdef HAVE_IPV6
4741 DEFUN (ipv6_aggregate_address,
4742 ipv6_aggregate_address_cmd,
4743 "aggregate-address X:X::X:X/M",
4744 "Configure BGP aggregate entries\n"
4745 "Aggregate prefix\n")
4747 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4750 DEFUN (ipv6_aggregate_address_summary_only,
4751 ipv6_aggregate_address_summary_only_cmd,
4752 "aggregate-address X:X::X:X/M summary-only",
4753 "Configure BGP aggregate entries\n"
4754 "Aggregate prefix\n"
4755 "Filter more specific routes from updates\n")
4757 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4758 AGGREGATE_SUMMARY_ONLY, 0);
4761 DEFUN (no_ipv6_aggregate_address,
4762 no_ipv6_aggregate_address_cmd,
4763 "no aggregate-address X:X::X:X/M",
4764 NO_STR
4765 "Configure BGP aggregate entries\n"
4766 "Aggregate prefix\n")
4768 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4771 DEFUN (no_ipv6_aggregate_address_summary_only,
4772 no_ipv6_aggregate_address_summary_only_cmd,
4773 "no aggregate-address X:X::X:X/M summary-only",
4774 NO_STR
4775 "Configure BGP aggregate entries\n"
4776 "Aggregate prefix\n"
4777 "Filter more specific routes from updates\n")
4779 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4782 ALIAS (ipv6_aggregate_address,
4783 old_ipv6_aggregate_address_cmd,
4784 "ipv6 bgp aggregate-address X:X::X:X/M",
4785 IPV6_STR
4786 BGP_STR
4787 "Configure BGP aggregate entries\n"
4788 "Aggregate prefix\n")
4790 ALIAS (ipv6_aggregate_address_summary_only,
4791 old_ipv6_aggregate_address_summary_only_cmd,
4792 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4793 IPV6_STR
4794 BGP_STR
4795 "Configure BGP aggregate entries\n"
4796 "Aggregate prefix\n"
4797 "Filter more specific routes from updates\n")
4799 ALIAS (no_ipv6_aggregate_address,
4800 old_no_ipv6_aggregate_address_cmd,
4801 "no ipv6 bgp aggregate-address X:X::X:X/M",
4802 NO_STR
4803 IPV6_STR
4804 BGP_STR
4805 "Configure BGP aggregate entries\n"
4806 "Aggregate prefix\n")
4808 ALIAS (no_ipv6_aggregate_address_summary_only,
4809 old_no_ipv6_aggregate_address_summary_only_cmd,
4810 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4811 NO_STR
4812 IPV6_STR
4813 BGP_STR
4814 "Configure BGP aggregate entries\n"
4815 "Aggregate prefix\n"
4816 "Filter more specific routes from updates\n")
4817 #endif /* HAVE_IPV6 */
4819 /* Redistribute route treatment. */
4820 void
4821 bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4822 u_int32_t metric, u_char type)
4824 struct bgp *bgp;
4825 struct listnode *node, *nnode;
4826 struct bgp_info *new;
4827 struct bgp_info *bi;
4828 struct bgp_info info;
4829 struct bgp_node *bn;
4830 struct attr attr;
4831 struct attr attr_new;
4832 struct attr *new_attr;
4833 afi_t afi;
4834 int ret;
4836 /* Make default attribute. */
4837 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4838 if (nexthop)
4839 attr.nexthop = *nexthop;
4841 attr.med = metric;
4842 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4844 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
4846 afi = family2afi (p->family);
4848 if (bgp->redist[afi][type])
4850 /* Copy attribute for modification. */
4851 attr_new = attr;
4853 if (bgp->redist_metric_flag[afi][type])
4854 attr_new.med = bgp->redist_metric[afi][type];
4856 /* Apply route-map. */
4857 if (bgp->rmap[afi][type].map)
4859 info.peer = bgp->peer_self;
4860 info.attr = &attr_new;
4862 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4864 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4865 &info);
4867 bgp->peer_self->rmap_type = 0;
4869 if (ret == RMAP_DENYMATCH)
4871 /* Free uninterned attribute. */
4872 bgp_attr_flush (&attr_new);
4874 /* Unintern original. */
4875 aspath_unintern (attr.aspath);
4876 bgp_redistribute_delete (p, type);
4877 return;
4881 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
4882 new_attr = bgp_attr_intern (&attr_new);
4884 for (bi = bn->info; bi; bi = bi->next)
4885 if (bi->peer == bgp->peer_self
4886 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4887 break;
4889 if (bi)
4891 if (attrhash_cmp (bi->attr, new_attr))
4893 bgp_attr_unintern (new_attr);
4894 aspath_unintern (attr.aspath);
4895 bgp_unlock_node (bn);
4896 return;
4898 else
4900 /* The attribute is changed. */
4901 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
4903 /* Rewrite BGP route information. */
4904 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4905 bgp_attr_unintern (bi->attr);
4906 bi->attr = new_attr;
4907 bi->uptime = time (NULL);
4909 /* Process change. */
4910 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4911 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4912 bgp_unlock_node (bn);
4913 aspath_unintern (attr.aspath);
4914 return;
4918 new = bgp_info_new ();
4919 new->type = type;
4920 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4921 new->peer = bgp->peer_self;
4922 SET_FLAG (new->flags, BGP_INFO_VALID);
4923 new->attr = new_attr;
4924 new->uptime = time (NULL);
4926 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4927 bgp_info_add (bn, new);
4928 bgp_unlock_node (bn);
4929 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4933 /* Unintern original. */
4934 aspath_unintern (attr.aspath);
4937 void
4938 bgp_redistribute_delete (struct prefix *p, u_char type)
4940 struct bgp *bgp;
4941 struct listnode *node, *nnode;
4942 afi_t afi;
4943 struct bgp_node *rn;
4944 struct bgp_info *ri;
4946 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
4948 afi = family2afi (p->family);
4950 if (bgp->redist[afi][type])
4952 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
4954 for (ri = rn->info; ri; ri = ri->next)
4955 if (ri->peer == bgp->peer_self
4956 && ri->type == type)
4957 break;
4959 if (ri)
4961 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
4962 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4963 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4964 bgp_info_delete (rn, ri);
4966 bgp_unlock_node (rn);
4971 /* Withdraw specified route type's route. */
4972 void
4973 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
4975 struct bgp_node *rn;
4976 struct bgp_info *ri;
4977 struct bgp_table *table;
4979 table = bgp->rib[afi][SAFI_UNICAST];
4981 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4983 for (ri = rn->info; ri; ri = ri->next)
4984 if (ri->peer == bgp->peer_self
4985 && ri->type == type)
4986 break;
4988 if (ri)
4990 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
4991 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4992 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4993 bgp_info_delete (rn, ri);
4998 /* Static function to display route. */
4999 static void
5000 route_vty_out_route (struct prefix *p, struct vty *vty)
5002 int len;
5003 u_int32_t destination;
5004 char buf[BUFSIZ];
5006 if (p->family == AF_INET)
5008 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5009 destination = ntohl (p->u.prefix4.s_addr);
5011 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5012 || (IN_CLASSB (destination) && p->prefixlen == 16)
5013 || (IN_CLASSA (destination) && p->prefixlen == 8)
5014 || p->u.prefix4.s_addr == 0)
5016 /* When mask is natural, mask is not displayed. */
5018 else
5019 len += vty_out (vty, "/%d", p->prefixlen);
5021 else
5022 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5023 p->prefixlen);
5025 len = 17 - len;
5026 if (len < 1)
5027 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5028 else
5029 vty_out (vty, "%*s", len, " ");
5032 enum bgp_display_type
5034 normal_list,
5037 /* Print the short form route status for a bgp_info */
5038 static void
5039 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
5041 /* Route status display. */
5042 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5043 vty_out (vty, "R");
5044 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5045 vty_out (vty, "S");
5046 else if (binfo->suppress)
5047 vty_out (vty, "s");
5048 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5049 vty_out (vty, "*");
5050 else
5051 vty_out (vty, " ");
5053 /* Selected */
5054 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5055 vty_out (vty, "h");
5056 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5057 vty_out (vty, "d");
5058 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5059 vty_out (vty, ">");
5060 else
5061 vty_out (vty, " ");
5063 /* Internal route. */
5064 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5065 vty_out (vty, "i");
5066 else
5067 vty_out (vty, " ");
5070 /* called from terminal list command */
5071 void
5072 route_vty_out (struct vty *vty, struct prefix *p,
5073 struct bgp_info *binfo, int display, safi_t safi)
5075 struct attr *attr;
5077 /* short status lead text */
5078 route_vty_short_status_out (vty, binfo);
5080 /* print prefix and mask */
5081 if (! display)
5082 route_vty_out_route (p, vty);
5083 else
5084 vty_out (vty, "%*s", 17, " ");
5086 /* Print attribute */
5087 attr = binfo->attr;
5088 if (attr)
5090 if (p->family == AF_INET)
5092 if (safi == SAFI_MPLS_VPN)
5093 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5094 else
5095 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5097 #ifdef HAVE_IPV6
5098 else if (p->family == AF_INET6)
5100 int len;
5101 char buf[BUFSIZ];
5103 len = vty_out (vty, "%s",
5104 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5105 len = 16 - len;
5106 if (len < 1)
5107 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5108 else
5109 vty_out (vty, "%*s", len, " ");
5111 #endif /* HAVE_IPV6 */
5113 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5114 vty_out (vty, "%10d", attr->med);
5115 else
5116 vty_out (vty, " ");
5118 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5119 vty_out (vty, "%7d", attr->local_pref);
5120 else
5121 vty_out (vty, " ");
5123 vty_out (vty, "%7u ",attr->weight);
5125 /* Print aspath */
5126 if (attr->aspath)
5127 aspath_print_vty (vty, attr->aspath);
5129 /* Print origin */
5130 if (strlen (attr->aspath->str) == 0)
5131 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5132 else
5133 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5135 vty_out (vty, "%s", VTY_NEWLINE);
5138 /* called from terminal list command */
5139 void
5140 route_vty_out_tmp (struct vty *vty, struct prefix *p,
5141 struct attr *attr, safi_t safi)
5143 /* Route status display. */
5144 vty_out (vty, "*");
5145 vty_out (vty, ">");
5146 vty_out (vty, " ");
5148 /* print prefix and mask */
5149 route_vty_out_route (p, vty);
5151 /* Print attribute */
5152 if (attr)
5154 if (p->family == AF_INET)
5156 if (safi == SAFI_MPLS_VPN)
5157 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5158 else
5159 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5161 #ifdef HAVE_IPV6
5162 else if (p->family == AF_INET6)
5164 int len;
5165 char buf[BUFSIZ];
5167 len = vty_out (vty, "%s",
5168 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5169 len = 16 - len;
5170 if (len < 1)
5171 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5172 else
5173 vty_out (vty, "%*s", len, " ");
5175 #endif /* HAVE_IPV6 */
5177 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5178 vty_out (vty, "%10d", attr->med);
5179 else
5180 vty_out (vty, " ");
5182 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5183 vty_out (vty, "%7d", attr->local_pref);
5184 else
5185 vty_out (vty, " ");
5187 vty_out (vty, "%7d ",attr->weight);
5189 /* Print aspath */
5190 if (attr->aspath)
5191 aspath_print_vty (vty, attr->aspath);
5193 /* Print origin */
5194 if (strlen (attr->aspath->str) == 0)
5195 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5196 else
5197 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5200 vty_out (vty, "%s", VTY_NEWLINE);
5203 void
5204 route_vty_out_tag (struct vty *vty, struct prefix *p,
5205 struct bgp_info *binfo, int display, safi_t safi)
5207 struct attr *attr;
5208 u_int32_t label = 0;
5210 /* short status lead text */
5211 route_vty_short_status_out (vty, binfo);
5213 /* print prefix and mask */
5214 if (! display)
5215 route_vty_out_route (p, vty);
5216 else
5217 vty_out (vty, "%*s", 17, " ");
5219 /* Print attribute */
5220 attr = binfo->attr;
5221 if (attr)
5223 if (p->family == AF_INET)
5225 if (safi == SAFI_MPLS_VPN)
5226 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5227 else
5228 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5230 #ifdef HAVE_IPV6
5231 else if (p->family == AF_INET6)
5233 char buf[BUFSIZ];
5234 char buf1[BUFSIZ];
5235 if (attr->mp_nexthop_len == 16)
5236 vty_out (vty, "%s",
5237 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5238 else if (attr->mp_nexthop_len == 32)
5239 vty_out (vty, "%s(%s)",
5240 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5241 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5244 #endif /* HAVE_IPV6 */
5247 label = decode_label (binfo->tag);
5249 vty_out (vty, "notag/%d", label);
5251 vty_out (vty, "%s", VTY_NEWLINE);
5254 /* dampening route */
5255 static void
5256 damp_route_vty_out (struct vty *vty, struct prefix *p,
5257 struct bgp_info *binfo, int display, safi_t safi)
5259 struct attr *attr;
5260 int len;
5262 /* short status lead text */
5263 route_vty_short_status_out (vty, binfo);
5265 /* print prefix and mask */
5266 if (! display)
5267 route_vty_out_route (p, vty);
5268 else
5269 vty_out (vty, "%*s", 17, " ");
5271 len = vty_out (vty, "%s", binfo->peer->host);
5272 len = 17 - len;
5273 if (len < 1)
5274 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5275 else
5276 vty_out (vty, "%*s", len, " ");
5278 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5280 /* Print attribute */
5281 attr = binfo->attr;
5282 if (attr)
5284 /* Print aspath */
5285 if (attr->aspath)
5286 aspath_print_vty (vty, attr->aspath);
5288 /* Print origin */
5289 if (strlen (attr->aspath->str) == 0)
5290 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5291 else
5292 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5294 vty_out (vty, "%s", VTY_NEWLINE);
5297 #define BGP_UPTIME_LEN 25
5299 /* flap route */
5300 static void
5301 flap_route_vty_out (struct vty *vty, struct prefix *p,
5302 struct bgp_info *binfo, int display, safi_t safi)
5304 struct attr *attr;
5305 struct bgp_damp_info *bdi;
5306 char timebuf[BGP_UPTIME_LEN];
5307 int len;
5309 bdi = binfo->damp_info;
5311 /* short status lead text */
5312 route_vty_short_status_out (vty, binfo);
5314 /* print prefix and mask */
5315 if (! display)
5316 route_vty_out_route (p, vty);
5317 else
5318 vty_out (vty, "%*s", 17, " ");
5320 len = vty_out (vty, "%s", binfo->peer->host);
5321 len = 16 - len;
5322 if (len < 1)
5323 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5324 else
5325 vty_out (vty, "%*s", len, " ");
5327 len = vty_out (vty, "%d", bdi->flap);
5328 len = 5 - len;
5329 if (len < 1)
5330 vty_out (vty, " ");
5331 else
5332 vty_out (vty, "%*s ", len, " ");
5334 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5335 timebuf, BGP_UPTIME_LEN));
5337 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5338 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5339 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5340 else
5341 vty_out (vty, "%*s ", 8, " ");
5343 /* Print attribute */
5344 attr = binfo->attr;
5345 if (attr)
5347 /* Print aspath */
5348 if (attr->aspath)
5349 aspath_print_vty (vty, attr->aspath);
5351 /* Print origin */
5352 if (strlen (attr->aspath->str) == 0)
5353 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5354 else
5355 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5357 vty_out (vty, "%s", VTY_NEWLINE);
5360 static void
5361 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5362 struct bgp_info *binfo, afi_t afi, safi_t safi)
5364 char buf[INET6_ADDRSTRLEN];
5365 char buf1[BUFSIZ];
5366 struct attr *attr;
5367 int sockunion_vty_out (struct vty *, union sockunion *);
5369 attr = binfo->attr;
5371 if (attr)
5373 /* Line1 display AS-path, Aggregator */
5374 if (attr->aspath)
5376 vty_out (vty, " ");
5377 if (aspath_count_hops (attr->aspath) == 0)
5378 vty_out (vty, "Local");
5379 else
5380 aspath_print_vty (vty, attr->aspath);
5383 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5384 vty_out (vty, ", (removed)");
5385 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5386 vty_out (vty, ", (stale)");
5387 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5388 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5389 inet_ntoa (attr->aggregator_addr));
5390 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5391 vty_out (vty, ", (Received from a RR-client)");
5392 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5393 vty_out (vty, ", (Received from a RS-client)");
5394 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5395 vty_out (vty, ", (history entry)");
5396 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5397 vty_out (vty, ", (suppressed due to dampening)");
5398 vty_out (vty, "%s", VTY_NEWLINE);
5400 /* Line2 display Next-hop, Neighbor, Router-id */
5401 if (p->family == AF_INET)
5403 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5404 inet_ntoa (attr->mp_nexthop_global_in) :
5405 inet_ntoa (attr->nexthop));
5407 #ifdef HAVE_IPV6
5408 else
5410 vty_out (vty, " %s",
5411 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5412 buf, INET6_ADDRSTRLEN));
5414 #endif /* HAVE_IPV6 */
5416 if (binfo->peer == bgp->peer_self)
5418 vty_out (vty, " from %s ",
5419 p->family == AF_INET ? "0.0.0.0" : "::");
5420 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5422 else
5424 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5425 vty_out (vty, " (inaccessible)");
5426 else if (binfo->igpmetric)
5427 vty_out (vty, " (metric %d)", binfo->igpmetric);
5428 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
5429 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5430 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5431 else
5432 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5434 vty_out (vty, "%s", VTY_NEWLINE);
5436 #ifdef HAVE_IPV6
5437 /* display nexthop local */
5438 if (attr->mp_nexthop_len == 32)
5440 vty_out (vty, " (%s)%s",
5441 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5442 buf, INET6_ADDRSTRLEN),
5443 VTY_NEWLINE);
5445 #endif /* HAVE_IPV6 */
5447 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5448 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5450 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5451 vty_out (vty, ", metric %d", attr->med);
5453 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5454 vty_out (vty, ", localpref %d", attr->local_pref);
5455 else
5456 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5458 if (attr->weight != 0)
5459 vty_out (vty, ", weight %d", attr->weight);
5461 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5462 vty_out (vty, ", valid");
5464 if (binfo->peer != bgp->peer_self)
5466 if (binfo->peer->as == binfo->peer->local_as)
5467 vty_out (vty, ", internal");
5468 else
5469 vty_out (vty, ", %s",
5470 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5472 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5473 vty_out (vty, ", aggregated, local");
5474 else if (binfo->type != ZEBRA_ROUTE_BGP)
5475 vty_out (vty, ", sourced");
5476 else
5477 vty_out (vty, ", sourced, local");
5479 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5480 vty_out (vty, ", atomic-aggregate");
5482 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5483 vty_out (vty, ", best");
5485 vty_out (vty, "%s", VTY_NEWLINE);
5487 /* Line 4 display Community */
5488 if (attr->community)
5489 vty_out (vty, " Community: %s%s", attr->community->str,
5490 VTY_NEWLINE);
5492 /* Line 5 display Extended-community */
5493 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5494 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5495 VTY_NEWLINE);
5497 /* Line 6 display Originator, Cluster-id */
5498 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5499 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5501 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5502 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5504 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5506 int i;
5507 vty_out (vty, ", Cluster list: ");
5508 for (i = 0; i < attr->cluster->length / 4; i++)
5509 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5511 vty_out (vty, "%s", VTY_NEWLINE);
5514 if (binfo->damp_info)
5515 bgp_damp_info_vty (vty, binfo);
5517 /* Line 7 display Uptime */
5518 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5520 vty_out (vty, "%s", VTY_NEWLINE);
5523 #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,%s r RIB-failure, S Stale, R Removed%s"
5524 #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
5525 #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5526 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5527 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5529 enum bgp_show_type
5531 bgp_show_type_normal,
5532 bgp_show_type_regexp,
5533 bgp_show_type_prefix_list,
5534 bgp_show_type_filter_list,
5535 bgp_show_type_route_map,
5536 bgp_show_type_neighbor,
5537 bgp_show_type_cidr_only,
5538 bgp_show_type_prefix_longer,
5539 bgp_show_type_community_all,
5540 bgp_show_type_community,
5541 bgp_show_type_community_exact,
5542 bgp_show_type_community_list,
5543 bgp_show_type_community_list_exact,
5544 bgp_show_type_flap_statistics,
5545 bgp_show_type_flap_address,
5546 bgp_show_type_flap_prefix,
5547 bgp_show_type_flap_cidr_only,
5548 bgp_show_type_flap_regexp,
5549 bgp_show_type_flap_filter_list,
5550 bgp_show_type_flap_prefix_list,
5551 bgp_show_type_flap_prefix_longer,
5552 bgp_show_type_flap_route_map,
5553 bgp_show_type_flap_neighbor,
5554 bgp_show_type_dampend_paths,
5555 bgp_show_type_damp_neighbor
5558 static int
5559 bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
5560 enum bgp_show_type type, void *output_arg)
5562 struct bgp_info *ri;
5563 struct bgp_node *rn;
5564 int header = 1;
5565 int display;
5566 unsigned long output_count;
5568 /* This is first entry point, so reset total line. */
5569 output_count = 0;
5571 /* Start processing of routes. */
5572 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5573 if (rn->info != NULL)
5575 display = 0;
5577 for (ri = rn->info; ri; ri = ri->next)
5579 if (type == bgp_show_type_flap_statistics
5580 || type == bgp_show_type_flap_address
5581 || type == bgp_show_type_flap_prefix
5582 || type == bgp_show_type_flap_cidr_only
5583 || type == bgp_show_type_flap_regexp
5584 || type == bgp_show_type_flap_filter_list
5585 || type == bgp_show_type_flap_prefix_list
5586 || type == bgp_show_type_flap_prefix_longer
5587 || type == bgp_show_type_flap_route_map
5588 || type == bgp_show_type_flap_neighbor
5589 || type == bgp_show_type_dampend_paths
5590 || type == bgp_show_type_damp_neighbor)
5592 if (! ri->damp_info)
5593 continue;
5595 if (type == bgp_show_type_regexp
5596 || type == bgp_show_type_flap_regexp)
5598 regex_t *regex = output_arg;
5600 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5601 continue;
5603 if (type == bgp_show_type_prefix_list
5604 || type == bgp_show_type_flap_prefix_list)
5606 struct prefix_list *plist = output_arg;
5608 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5609 continue;
5611 if (type == bgp_show_type_filter_list
5612 || type == bgp_show_type_flap_filter_list)
5614 struct as_list *as_list = output_arg;
5616 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5617 continue;
5619 if (type == bgp_show_type_route_map
5620 || type == bgp_show_type_flap_route_map)
5622 struct route_map *rmap = output_arg;
5623 struct bgp_info binfo;
5624 struct attr dummy_attr;
5625 int ret;
5627 dummy_attr = *ri->attr;
5628 binfo.peer = ri->peer;
5629 binfo.attr = &dummy_attr;
5631 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5633 if (ret == RMAP_DENYMATCH)
5634 continue;
5636 if (type == bgp_show_type_neighbor
5637 || type == bgp_show_type_flap_neighbor
5638 || type == bgp_show_type_damp_neighbor)
5640 union sockunion *su = output_arg;
5642 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5643 continue;
5645 if (type == bgp_show_type_cidr_only
5646 || type == bgp_show_type_flap_cidr_only)
5648 u_int32_t destination;
5650 destination = ntohl (rn->p.u.prefix4.s_addr);
5651 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5652 continue;
5653 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5654 continue;
5655 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5656 continue;
5658 if (type == bgp_show_type_prefix_longer
5659 || type == bgp_show_type_flap_prefix_longer)
5661 struct prefix *p = output_arg;
5663 if (! prefix_match (p, &rn->p))
5664 continue;
5666 if (type == bgp_show_type_community_all)
5668 if (! ri->attr->community)
5669 continue;
5671 if (type == bgp_show_type_community)
5673 struct community *com = output_arg;
5675 if (! ri->attr->community ||
5676 ! community_match (ri->attr->community, com))
5677 continue;
5679 if (type == bgp_show_type_community_exact)
5681 struct community *com = output_arg;
5683 if (! ri->attr->community ||
5684 ! community_cmp (ri->attr->community, com))
5685 continue;
5687 if (type == bgp_show_type_community_list)
5689 struct community_list *list = output_arg;
5691 if (! community_list_match (ri->attr->community, list))
5692 continue;
5694 if (type == bgp_show_type_community_list_exact)
5696 struct community_list *list = output_arg;
5698 if (! community_list_exact_match (ri->attr->community, list))
5699 continue;
5701 if (type == bgp_show_type_flap_address
5702 || type == bgp_show_type_flap_prefix)
5704 struct prefix *p = output_arg;
5706 if (! prefix_match (&rn->p, p))
5707 continue;
5709 if (type == bgp_show_type_flap_prefix)
5710 if (p->prefixlen != rn->p.prefixlen)
5711 continue;
5713 if (type == bgp_show_type_dampend_paths
5714 || type == bgp_show_type_damp_neighbor)
5716 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5717 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5718 continue;
5721 if (header)
5723 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5724 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5725 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5726 if (type == bgp_show_type_dampend_paths
5727 || type == bgp_show_type_damp_neighbor)
5728 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5729 else if (type == bgp_show_type_flap_statistics
5730 || type == bgp_show_type_flap_address
5731 || type == bgp_show_type_flap_prefix
5732 || type == bgp_show_type_flap_cidr_only
5733 || type == bgp_show_type_flap_regexp
5734 || type == bgp_show_type_flap_filter_list
5735 || type == bgp_show_type_flap_prefix_list
5736 || type == bgp_show_type_flap_prefix_longer
5737 || type == bgp_show_type_flap_route_map
5738 || type == bgp_show_type_flap_neighbor)
5739 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5740 else
5741 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
5742 header = 0;
5745 if (type == bgp_show_type_dampend_paths
5746 || type == bgp_show_type_damp_neighbor)
5747 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
5748 else if (type == bgp_show_type_flap_statistics
5749 || type == bgp_show_type_flap_address
5750 || type == bgp_show_type_flap_prefix
5751 || type == bgp_show_type_flap_cidr_only
5752 || type == bgp_show_type_flap_regexp
5753 || type == bgp_show_type_flap_filter_list
5754 || type == bgp_show_type_flap_prefix_list
5755 || type == bgp_show_type_flap_prefix_longer
5756 || type == bgp_show_type_flap_route_map
5757 || type == bgp_show_type_flap_neighbor)
5758 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
5759 else
5760 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
5761 display++;
5763 if (display)
5764 output_count++;
5767 /* No route is displayed */
5768 if (output_count == 0)
5770 if (type == bgp_show_type_normal)
5771 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5773 else
5774 vty_out (vty, "%sTotal number of prefixes %ld%s",
5775 VTY_NEWLINE, output_count, VTY_NEWLINE);
5777 return CMD_SUCCESS;
5780 static int
5781 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
5782 enum bgp_show_type type, void *output_arg)
5784 struct bgp_table *table;
5786 if (bgp == NULL) {
5787 bgp = bgp_get_default ();
5790 if (bgp == NULL)
5792 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5793 return CMD_WARNING;
5797 table = bgp->rib[afi][safi];
5799 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
5802 /* Header of detailed BGP route information */
5803 static void
5804 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5805 struct bgp_node *rn,
5806 struct prefix_rd *prd, afi_t afi, safi_t safi)
5808 struct bgp_info *ri;
5809 struct prefix *p;
5810 struct peer *peer;
5811 struct listnode *node, *nnode;
5812 char buf1[INET6_ADDRSTRLEN];
5813 char buf2[INET6_ADDRSTRLEN];
5814 int count = 0;
5815 int best = 0;
5816 int suppress = 0;
5817 int no_export = 0;
5818 int no_advertise = 0;
5819 int local_as = 0;
5820 int first = 0;
5822 p = &rn->p;
5823 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5824 (safi == SAFI_MPLS_VPN ?
5825 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5826 safi == SAFI_MPLS_VPN ? ":" : "",
5827 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5828 p->prefixlen, VTY_NEWLINE);
5830 for (ri = rn->info; ri; ri = ri->next)
5832 count++;
5833 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5835 best = count;
5836 if (ri->suppress)
5837 suppress = 1;
5838 if (ri->attr->community != NULL)
5840 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5841 no_advertise = 1;
5842 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5843 no_export = 1;
5844 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5845 local_as = 1;
5850 vty_out (vty, "Paths: (%d available", count);
5851 if (best)
5853 vty_out (vty, ", best #%d", best);
5854 if (safi == SAFI_UNICAST)
5855 vty_out (vty, ", table Default-IP-Routing-Table");
5857 else
5858 vty_out (vty, ", no best path");
5859 if (no_advertise)
5860 vty_out (vty, ", not advertised to any peer");
5861 else if (no_export)
5862 vty_out (vty, ", not advertised to EBGP peer");
5863 else if (local_as)
5864 vty_out (vty, ", not advertised outside local AS");
5865 if (suppress)
5866 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5867 vty_out (vty, ")%s", VTY_NEWLINE);
5869 /* advertised peer */
5870 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
5872 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5874 if (! first)
5875 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5876 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5877 first = 1;
5880 if (! first)
5881 vty_out (vty, " Not advertised to any peer");
5882 vty_out (vty, "%s", VTY_NEWLINE);
5885 /* Display specified route of BGP table. */
5886 static int
5887 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
5888 struct bgp_table *rib, const char *ip_str,
5889 afi_t afi, safi_t safi, struct prefix_rd *prd,
5890 int prefix_check)
5892 int ret;
5893 int header;
5894 int display = 0;
5895 struct prefix match;
5896 struct bgp_node *rn;
5897 struct bgp_node *rm;
5898 struct bgp_info *ri;
5899 struct bgp_table *table;
5901 /* Check IP address argument. */
5902 ret = str2prefix (ip_str, &match);
5903 if (! ret)
5905 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5906 return CMD_WARNING;
5909 match.family = afi2family (afi);
5911 if (safi == SAFI_MPLS_VPN)
5913 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
5915 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5916 continue;
5918 if ((table = rn->info) != NULL)
5920 header = 1;
5922 if ((rm = bgp_node_match (table, &match)) != NULL)
5924 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5925 continue;
5927 for (ri = rm->info; ri; ri = ri->next)
5929 if (header)
5931 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5932 AFI_IP, SAFI_MPLS_VPN);
5934 header = 0;
5936 display++;
5937 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5943 else
5945 header = 1;
5947 if ((rn = bgp_node_match (rib, &match)) != NULL)
5949 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5951 for (ri = rn->info; ri; ri = ri->next)
5953 if (header)
5955 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5956 header = 0;
5958 display++;
5959 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5965 if (! display)
5967 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5968 return CMD_WARNING;
5971 return CMD_SUCCESS;
5974 /* Display specified route of Main RIB */
5975 static int
5976 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
5977 afi_t afi, safi_t safi, struct prefix_rd *prd,
5978 int prefix_check)
5980 struct bgp *bgp;
5982 /* BGP structure lookup. */
5983 if (view_name)
5985 bgp = bgp_lookup_by_name (view_name);
5986 if (bgp == NULL)
5988 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
5989 return CMD_WARNING;
5992 else
5994 bgp = bgp_get_default ();
5995 if (bgp == NULL)
5997 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5998 return CMD_WARNING;
6002 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6003 afi, safi, prd, prefix_check);
6006 /* BGP route print out function. */
6007 DEFUN (show_ip_bgp,
6008 show_ip_bgp_cmd,
6009 "show ip bgp",
6010 SHOW_STR
6011 IP_STR
6012 BGP_STR)
6014 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6017 DEFUN (show_ip_bgp_ipv4,
6018 show_ip_bgp_ipv4_cmd,
6019 "show ip bgp ipv4 (unicast|multicast)",
6020 SHOW_STR
6021 IP_STR
6022 BGP_STR
6023 "Address family\n"
6024 "Address Family modifier\n"
6025 "Address Family modifier\n")
6027 if (strncmp (argv[0], "m", 1) == 0)
6028 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6029 NULL);
6031 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6034 DEFUN (show_ip_bgp_route,
6035 show_ip_bgp_route_cmd,
6036 "show ip bgp A.B.C.D",
6037 SHOW_STR
6038 IP_STR
6039 BGP_STR
6040 "Network in the BGP routing table to display\n")
6042 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6045 DEFUN (show_ip_bgp_ipv4_route,
6046 show_ip_bgp_ipv4_route_cmd,
6047 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6048 SHOW_STR
6049 IP_STR
6050 BGP_STR
6051 "Address family\n"
6052 "Address Family modifier\n"
6053 "Address Family modifier\n"
6054 "Network in the BGP routing table to display\n")
6056 if (strncmp (argv[0], "m", 1) == 0)
6057 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6059 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6062 DEFUN (show_ip_bgp_vpnv4_all_route,
6063 show_ip_bgp_vpnv4_all_route_cmd,
6064 "show ip bgp vpnv4 all A.B.C.D",
6065 SHOW_STR
6066 IP_STR
6067 BGP_STR
6068 "Display VPNv4 NLRI specific information\n"
6069 "Display information about all VPNv4 NLRIs\n"
6070 "Network in the BGP routing table to display\n")
6072 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6075 DEFUN (show_ip_bgp_vpnv4_rd_route,
6076 show_ip_bgp_vpnv4_rd_route_cmd,
6077 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6078 SHOW_STR
6079 IP_STR
6080 BGP_STR
6081 "Display VPNv4 NLRI specific information\n"
6082 "Display information for a route distinguisher\n"
6083 "VPN Route Distinguisher\n"
6084 "Network in the BGP routing table to display\n")
6086 int ret;
6087 struct prefix_rd prd;
6089 ret = str2prefix_rd (argv[0], &prd);
6090 if (! ret)
6092 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6093 return CMD_WARNING;
6095 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6098 DEFUN (show_ip_bgp_prefix,
6099 show_ip_bgp_prefix_cmd,
6100 "show ip bgp A.B.C.D/M",
6101 SHOW_STR
6102 IP_STR
6103 BGP_STR
6104 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6106 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6109 DEFUN (show_ip_bgp_ipv4_prefix,
6110 show_ip_bgp_ipv4_prefix_cmd,
6111 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6112 SHOW_STR
6113 IP_STR
6114 BGP_STR
6115 "Address family\n"
6116 "Address Family modifier\n"
6117 "Address Family modifier\n"
6118 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6120 if (strncmp (argv[0], "m", 1) == 0)
6121 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6123 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6126 DEFUN (show_ip_bgp_vpnv4_all_prefix,
6127 show_ip_bgp_vpnv4_all_prefix_cmd,
6128 "show ip bgp vpnv4 all A.B.C.D/M",
6129 SHOW_STR
6130 IP_STR
6131 BGP_STR
6132 "Display VPNv4 NLRI specific information\n"
6133 "Display information about all VPNv4 NLRIs\n"
6134 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6136 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6139 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6140 show_ip_bgp_vpnv4_rd_prefix_cmd,
6141 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6142 SHOW_STR
6143 IP_STR
6144 BGP_STR
6145 "Display VPNv4 NLRI specific information\n"
6146 "Display information for a route distinguisher\n"
6147 "VPN Route Distinguisher\n"
6148 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6150 int ret;
6151 struct prefix_rd prd;
6153 ret = str2prefix_rd (argv[0], &prd);
6154 if (! ret)
6156 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6157 return CMD_WARNING;
6159 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6162 DEFUN (show_ip_bgp_view,
6163 show_ip_bgp_view_cmd,
6164 "show ip bgp view WORD",
6165 SHOW_STR
6166 IP_STR
6167 BGP_STR
6168 "BGP view\n"
6169 "BGP view name\n")
6171 struct bgp *bgp;
6173 /* BGP structure lookup. */
6174 bgp = bgp_lookup_by_name (argv[0]);
6175 if (bgp == NULL)
6177 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6178 return CMD_WARNING;
6181 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6184 DEFUN (show_ip_bgp_view_route,
6185 show_ip_bgp_view_route_cmd,
6186 "show ip bgp view WORD A.B.C.D",
6187 SHOW_STR
6188 IP_STR
6189 BGP_STR
6190 "BGP view\n"
6191 "BGP view name\n"
6192 "Network in the BGP routing table to display\n")
6194 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6197 DEFUN (show_ip_bgp_view_prefix,
6198 show_ip_bgp_view_prefix_cmd,
6199 "show ip bgp view WORD A.B.C.D/M",
6200 SHOW_STR
6201 IP_STR
6202 BGP_STR
6203 "BGP view\n"
6204 "BGP view name\n"
6205 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6207 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6210 #ifdef HAVE_IPV6
6211 DEFUN (show_bgp,
6212 show_bgp_cmd,
6213 "show bgp",
6214 SHOW_STR
6215 BGP_STR)
6217 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6218 NULL);
6221 ALIAS (show_bgp,
6222 show_bgp_ipv6_cmd,
6223 "show bgp ipv6",
6224 SHOW_STR
6225 BGP_STR
6226 "Address family\n")
6228 /* old command */
6229 DEFUN (show_ipv6_bgp,
6230 show_ipv6_bgp_cmd,
6231 "show ipv6 bgp",
6232 SHOW_STR
6233 IP_STR
6234 BGP_STR)
6236 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6237 NULL);
6240 DEFUN (show_bgp_route,
6241 show_bgp_route_cmd,
6242 "show bgp X:X::X:X",
6243 SHOW_STR
6244 BGP_STR
6245 "Network in the BGP routing table to display\n")
6247 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6250 ALIAS (show_bgp_route,
6251 show_bgp_ipv6_route_cmd,
6252 "show bgp ipv6 X:X::X:X",
6253 SHOW_STR
6254 BGP_STR
6255 "Address family\n"
6256 "Network in the BGP routing table to display\n")
6258 /* old command */
6259 DEFUN (show_ipv6_bgp_route,
6260 show_ipv6_bgp_route_cmd,
6261 "show ipv6 bgp X:X::X:X",
6262 SHOW_STR
6263 IP_STR
6264 BGP_STR
6265 "Network in the BGP routing table to display\n")
6267 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6270 DEFUN (show_bgp_prefix,
6271 show_bgp_prefix_cmd,
6272 "show bgp X:X::X:X/M",
6273 SHOW_STR
6274 BGP_STR
6275 "IPv6 prefix <network>/<length>\n")
6277 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6280 ALIAS (show_bgp_prefix,
6281 show_bgp_ipv6_prefix_cmd,
6282 "show bgp ipv6 X:X::X:X/M",
6283 SHOW_STR
6284 BGP_STR
6285 "Address family\n"
6286 "IPv6 prefix <network>/<length>\n")
6288 /* old command */
6289 DEFUN (show_ipv6_bgp_prefix,
6290 show_ipv6_bgp_prefix_cmd,
6291 "show ipv6 bgp X:X::X:X/M",
6292 SHOW_STR
6293 IP_STR
6294 BGP_STR
6295 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6297 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6300 DEFUN (show_bgp_view,
6301 show_bgp_view_cmd,
6302 "show bgp view WORD",
6303 SHOW_STR
6304 BGP_STR
6305 "BGP view\n"
6306 "View name\n")
6308 struct bgp *bgp;
6310 /* BGP structure lookup. */
6311 bgp = bgp_lookup_by_name (argv[0]);
6312 if (bgp == NULL)
6314 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6315 return CMD_WARNING;
6318 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6321 ALIAS (show_bgp_view,
6322 show_bgp_view_ipv6_cmd,
6323 "show bgp view WORD ipv6",
6324 SHOW_STR
6325 BGP_STR
6326 "BGP view\n"
6327 "View name\n"
6328 "Address family\n")
6330 DEFUN (show_bgp_view_route,
6331 show_bgp_view_route_cmd,
6332 "show bgp view WORD X:X::X:X",
6333 SHOW_STR
6334 BGP_STR
6335 "BGP view\n"
6336 "View name\n"
6337 "Network in the BGP routing table to display\n")
6339 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6342 ALIAS (show_bgp_view_route,
6343 show_bgp_view_ipv6_route_cmd,
6344 "show bgp view WORD ipv6 X:X::X:X",
6345 SHOW_STR
6346 BGP_STR
6347 "BGP view\n"
6348 "View name\n"
6349 "Address family\n"
6350 "Network in the BGP routing table to display\n")
6352 DEFUN (show_bgp_view_prefix,
6353 show_bgp_view_prefix_cmd,
6354 "show bgp view WORD X:X::X:X/M",
6355 SHOW_STR
6356 BGP_STR
6357 "BGP view\n"
6358 "View name\n"
6359 "IPv6 prefix <network>/<length>\n")
6361 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6364 ALIAS (show_bgp_view_prefix,
6365 show_bgp_view_ipv6_prefix_cmd,
6366 "show bgp view WORD ipv6 X:X::X:X/M",
6367 SHOW_STR
6368 BGP_STR
6369 "BGP view\n"
6370 "View name\n"
6371 "Address family\n"
6372 "IPv6 prefix <network>/<length>\n")
6374 /* old command */
6375 DEFUN (show_ipv6_mbgp,
6376 show_ipv6_mbgp_cmd,
6377 "show ipv6 mbgp",
6378 SHOW_STR
6379 IP_STR
6380 MBGP_STR)
6382 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6383 NULL);
6386 /* old command */
6387 DEFUN (show_ipv6_mbgp_route,
6388 show_ipv6_mbgp_route_cmd,
6389 "show ipv6 mbgp X:X::X:X",
6390 SHOW_STR
6391 IP_STR
6392 MBGP_STR
6393 "Network in the MBGP routing table to display\n")
6395 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6398 /* old command */
6399 DEFUN (show_ipv6_mbgp_prefix,
6400 show_ipv6_mbgp_prefix_cmd,
6401 "show ipv6 mbgp X:X::X:X/M",
6402 SHOW_STR
6403 IP_STR
6404 MBGP_STR
6405 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6407 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6409 #endif
6412 static int
6413 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
6414 safi_t safi, enum bgp_show_type type)
6416 int i;
6417 struct buffer *b;
6418 char *regstr;
6419 int first;
6420 regex_t *regex;
6421 int rc;
6423 first = 0;
6424 b = buffer_new (1024);
6425 for (i = 0; i < argc; i++)
6427 if (first)
6428 buffer_putc (b, ' ');
6429 else
6431 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6432 continue;
6433 first = 1;
6436 buffer_putstr (b, argv[i]);
6438 buffer_putc (b, '\0');
6440 regstr = buffer_getstr (b);
6441 buffer_free (b);
6443 regex = bgp_regcomp (regstr);
6444 XFREE(MTYPE_TMP, regstr);
6445 if (! regex)
6447 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6448 VTY_NEWLINE);
6449 return CMD_WARNING;
6452 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6453 bgp_regex_free (regex);
6454 return rc;
6457 DEFUN (show_ip_bgp_regexp,
6458 show_ip_bgp_regexp_cmd,
6459 "show ip bgp regexp .LINE",
6460 SHOW_STR
6461 IP_STR
6462 BGP_STR
6463 "Display routes matching the AS path regular expression\n"
6464 "A regular-expression to match the BGP AS paths\n")
6466 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6467 bgp_show_type_regexp);
6470 DEFUN (show_ip_bgp_flap_regexp,
6471 show_ip_bgp_flap_regexp_cmd,
6472 "show ip bgp flap-statistics regexp .LINE",
6473 SHOW_STR
6474 IP_STR
6475 BGP_STR
6476 "Display flap statistics of routes\n"
6477 "Display routes matching the AS path regular expression\n"
6478 "A regular-expression to match the BGP AS paths\n")
6480 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6481 bgp_show_type_flap_regexp);
6484 DEFUN (show_ip_bgp_ipv4_regexp,
6485 show_ip_bgp_ipv4_regexp_cmd,
6486 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6487 SHOW_STR
6488 IP_STR
6489 BGP_STR
6490 "Address family\n"
6491 "Address Family modifier\n"
6492 "Address Family modifier\n"
6493 "Display routes matching the AS path regular expression\n"
6494 "A regular-expression to match the BGP AS paths\n")
6496 if (strncmp (argv[0], "m", 1) == 0)
6497 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6498 bgp_show_type_regexp);
6500 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6501 bgp_show_type_regexp);
6504 #ifdef HAVE_IPV6
6505 DEFUN (show_bgp_regexp,
6506 show_bgp_regexp_cmd,
6507 "show bgp regexp .LINE",
6508 SHOW_STR
6509 BGP_STR
6510 "Display routes matching the AS path regular expression\n"
6511 "A regular-expression to match the BGP AS paths\n")
6513 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6514 bgp_show_type_regexp);
6517 ALIAS (show_bgp_regexp,
6518 show_bgp_ipv6_regexp_cmd,
6519 "show bgp ipv6 regexp .LINE",
6520 SHOW_STR
6521 BGP_STR
6522 "Address family\n"
6523 "Display routes matching the AS path regular expression\n"
6524 "A regular-expression to match the BGP AS paths\n")
6526 /* old command */
6527 DEFUN (show_ipv6_bgp_regexp,
6528 show_ipv6_bgp_regexp_cmd,
6529 "show ipv6 bgp regexp .LINE",
6530 SHOW_STR
6531 IP_STR
6532 BGP_STR
6533 "Display routes matching the AS path regular expression\n"
6534 "A regular-expression to match the BGP AS paths\n")
6536 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6537 bgp_show_type_regexp);
6540 /* old command */
6541 DEFUN (show_ipv6_mbgp_regexp,
6542 show_ipv6_mbgp_regexp_cmd,
6543 "show ipv6 mbgp regexp .LINE",
6544 SHOW_STR
6545 IP_STR
6546 BGP_STR
6547 "Display routes matching the AS path regular expression\n"
6548 "A regular-expression to match the MBGP AS paths\n")
6550 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6551 bgp_show_type_regexp);
6553 #endif /* HAVE_IPV6 */
6555 static int
6556 bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
6557 safi_t safi, enum bgp_show_type type)
6559 struct prefix_list *plist;
6561 plist = prefix_list_lookup (afi, prefix_list_str);
6562 if (plist == NULL)
6564 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6565 prefix_list_str, VTY_NEWLINE);
6566 return CMD_WARNING;
6569 return bgp_show (vty, NULL, afi, safi, type, plist);
6572 DEFUN (show_ip_bgp_prefix_list,
6573 show_ip_bgp_prefix_list_cmd,
6574 "show ip bgp prefix-list WORD",
6575 SHOW_STR
6576 IP_STR
6577 BGP_STR
6578 "Display routes conforming to the prefix-list\n"
6579 "IP prefix-list name\n")
6581 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6582 bgp_show_type_prefix_list);
6585 DEFUN (show_ip_bgp_flap_prefix_list,
6586 show_ip_bgp_flap_prefix_list_cmd,
6587 "show ip bgp flap-statistics prefix-list WORD",
6588 SHOW_STR
6589 IP_STR
6590 BGP_STR
6591 "Display flap statistics of routes\n"
6592 "Display routes conforming to the prefix-list\n"
6593 "IP prefix-list name\n")
6595 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6596 bgp_show_type_flap_prefix_list);
6599 DEFUN (show_ip_bgp_ipv4_prefix_list,
6600 show_ip_bgp_ipv4_prefix_list_cmd,
6601 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6602 SHOW_STR
6603 IP_STR
6604 BGP_STR
6605 "Address family\n"
6606 "Address Family modifier\n"
6607 "Address Family modifier\n"
6608 "Display routes conforming to the prefix-list\n"
6609 "IP prefix-list name\n")
6611 if (strncmp (argv[0], "m", 1) == 0)
6612 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6613 bgp_show_type_prefix_list);
6615 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6616 bgp_show_type_prefix_list);
6619 #ifdef HAVE_IPV6
6620 DEFUN (show_bgp_prefix_list,
6621 show_bgp_prefix_list_cmd,
6622 "show bgp prefix-list WORD",
6623 SHOW_STR
6624 BGP_STR
6625 "Display routes conforming to the prefix-list\n"
6626 "IPv6 prefix-list name\n")
6628 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6629 bgp_show_type_prefix_list);
6632 ALIAS (show_bgp_prefix_list,
6633 show_bgp_ipv6_prefix_list_cmd,
6634 "show bgp ipv6 prefix-list WORD",
6635 SHOW_STR
6636 BGP_STR
6637 "Address family\n"
6638 "Display routes conforming to the prefix-list\n"
6639 "IPv6 prefix-list name\n")
6641 /* old command */
6642 DEFUN (show_ipv6_bgp_prefix_list,
6643 show_ipv6_bgp_prefix_list_cmd,
6644 "show ipv6 bgp prefix-list WORD",
6645 SHOW_STR
6646 IPV6_STR
6647 BGP_STR
6648 "Display routes matching the prefix-list\n"
6649 "IPv6 prefix-list name\n")
6651 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6652 bgp_show_type_prefix_list);
6655 /* old command */
6656 DEFUN (show_ipv6_mbgp_prefix_list,
6657 show_ipv6_mbgp_prefix_list_cmd,
6658 "show ipv6 mbgp prefix-list WORD",
6659 SHOW_STR
6660 IPV6_STR
6661 MBGP_STR
6662 "Display routes matching the prefix-list\n"
6663 "IPv6 prefix-list name\n")
6665 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6666 bgp_show_type_prefix_list);
6668 #endif /* HAVE_IPV6 */
6670 static int
6671 bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
6672 safi_t safi, enum bgp_show_type type)
6674 struct as_list *as_list;
6676 as_list = as_list_lookup (filter);
6677 if (as_list == NULL)
6679 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6680 return CMD_WARNING;
6683 return bgp_show (vty, NULL, afi, safi, type, as_list);
6686 DEFUN (show_ip_bgp_filter_list,
6687 show_ip_bgp_filter_list_cmd,
6688 "show ip bgp filter-list WORD",
6689 SHOW_STR
6690 IP_STR
6691 BGP_STR
6692 "Display routes conforming to the filter-list\n"
6693 "Regular expression access list name\n")
6695 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6696 bgp_show_type_filter_list);
6699 DEFUN (show_ip_bgp_flap_filter_list,
6700 show_ip_bgp_flap_filter_list_cmd,
6701 "show ip bgp flap-statistics filter-list WORD",
6702 SHOW_STR
6703 IP_STR
6704 BGP_STR
6705 "Display flap statistics of routes\n"
6706 "Display routes conforming to the filter-list\n"
6707 "Regular expression access list name\n")
6709 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6710 bgp_show_type_flap_filter_list);
6713 DEFUN (show_ip_bgp_ipv4_filter_list,
6714 show_ip_bgp_ipv4_filter_list_cmd,
6715 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6716 SHOW_STR
6717 IP_STR
6718 BGP_STR
6719 "Address family\n"
6720 "Address Family modifier\n"
6721 "Address Family modifier\n"
6722 "Display routes conforming to the filter-list\n"
6723 "Regular expression access list name\n")
6725 if (strncmp (argv[0], "m", 1) == 0)
6726 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6727 bgp_show_type_filter_list);
6729 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6730 bgp_show_type_filter_list);
6733 #ifdef HAVE_IPV6
6734 DEFUN (show_bgp_filter_list,
6735 show_bgp_filter_list_cmd,
6736 "show bgp filter-list WORD",
6737 SHOW_STR
6738 BGP_STR
6739 "Display routes conforming to the filter-list\n"
6740 "Regular expression access list name\n")
6742 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6743 bgp_show_type_filter_list);
6746 ALIAS (show_bgp_filter_list,
6747 show_bgp_ipv6_filter_list_cmd,
6748 "show bgp ipv6 filter-list WORD",
6749 SHOW_STR
6750 BGP_STR
6751 "Address family\n"
6752 "Display routes conforming to the filter-list\n"
6753 "Regular expression access list name\n")
6755 /* old command */
6756 DEFUN (show_ipv6_bgp_filter_list,
6757 show_ipv6_bgp_filter_list_cmd,
6758 "show ipv6 bgp filter-list WORD",
6759 SHOW_STR
6760 IPV6_STR
6761 BGP_STR
6762 "Display routes conforming to the filter-list\n"
6763 "Regular expression access list name\n")
6765 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6766 bgp_show_type_filter_list);
6769 /* old command */
6770 DEFUN (show_ipv6_mbgp_filter_list,
6771 show_ipv6_mbgp_filter_list_cmd,
6772 "show ipv6 mbgp filter-list WORD",
6773 SHOW_STR
6774 IPV6_STR
6775 MBGP_STR
6776 "Display routes conforming to the filter-list\n"
6777 "Regular expression access list name\n")
6779 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6780 bgp_show_type_filter_list);
6782 #endif /* HAVE_IPV6 */
6784 static int
6785 bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
6786 safi_t safi, enum bgp_show_type type)
6788 struct route_map *rmap;
6790 rmap = route_map_lookup_by_name (rmap_str);
6791 if (! rmap)
6793 vty_out (vty, "%% %s is not a valid route-map name%s",
6794 rmap_str, VTY_NEWLINE);
6795 return CMD_WARNING;
6798 return bgp_show (vty, NULL, afi, safi, type, rmap);
6801 DEFUN (show_ip_bgp_route_map,
6802 show_ip_bgp_route_map_cmd,
6803 "show ip bgp route-map WORD",
6804 SHOW_STR
6805 IP_STR
6806 BGP_STR
6807 "Display routes matching the route-map\n"
6808 "A route-map to match on\n")
6810 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6811 bgp_show_type_route_map);
6814 DEFUN (show_ip_bgp_flap_route_map,
6815 show_ip_bgp_flap_route_map_cmd,
6816 "show ip bgp flap-statistics route-map WORD",
6817 SHOW_STR
6818 IP_STR
6819 BGP_STR
6820 "Display flap statistics of routes\n"
6821 "Display routes matching the route-map\n"
6822 "A route-map to match on\n")
6824 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6825 bgp_show_type_flap_route_map);
6828 DEFUN (show_ip_bgp_ipv4_route_map,
6829 show_ip_bgp_ipv4_route_map_cmd,
6830 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6831 SHOW_STR
6832 IP_STR
6833 BGP_STR
6834 "Address family\n"
6835 "Address Family modifier\n"
6836 "Address Family modifier\n"
6837 "Display routes matching the route-map\n"
6838 "A route-map to match on\n")
6840 if (strncmp (argv[0], "m", 1) == 0)
6841 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6842 bgp_show_type_route_map);
6844 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6845 bgp_show_type_route_map);
6848 DEFUN (show_bgp_route_map,
6849 show_bgp_route_map_cmd,
6850 "show bgp route-map WORD",
6851 SHOW_STR
6852 BGP_STR
6853 "Display routes matching the route-map\n"
6854 "A route-map to match on\n")
6856 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6857 bgp_show_type_route_map);
6860 ALIAS (show_bgp_route_map,
6861 show_bgp_ipv6_route_map_cmd,
6862 "show bgp ipv6 route-map WORD",
6863 SHOW_STR
6864 BGP_STR
6865 "Address family\n"
6866 "Display routes matching the route-map\n"
6867 "A route-map to match on\n")
6869 DEFUN (show_ip_bgp_cidr_only,
6870 show_ip_bgp_cidr_only_cmd,
6871 "show ip bgp cidr-only",
6872 SHOW_STR
6873 IP_STR
6874 BGP_STR
6875 "Display only routes with non-natural netmasks\n")
6877 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6878 bgp_show_type_cidr_only, NULL);
6881 DEFUN (show_ip_bgp_flap_cidr_only,
6882 show_ip_bgp_flap_cidr_only_cmd,
6883 "show ip bgp flap-statistics cidr-only",
6884 SHOW_STR
6885 IP_STR
6886 BGP_STR
6887 "Display flap statistics of routes\n"
6888 "Display only routes with non-natural netmasks\n")
6890 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6891 bgp_show_type_flap_cidr_only, NULL);
6894 DEFUN (show_ip_bgp_ipv4_cidr_only,
6895 show_ip_bgp_ipv4_cidr_only_cmd,
6896 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6897 SHOW_STR
6898 IP_STR
6899 BGP_STR
6900 "Address family\n"
6901 "Address Family modifier\n"
6902 "Address Family modifier\n"
6903 "Display only routes with non-natural netmasks\n")
6905 if (strncmp (argv[0], "m", 1) == 0)
6906 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
6907 bgp_show_type_cidr_only, NULL);
6909 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6910 bgp_show_type_cidr_only, NULL);
6913 DEFUN (show_ip_bgp_community_all,
6914 show_ip_bgp_community_all_cmd,
6915 "show ip bgp community",
6916 SHOW_STR
6917 IP_STR
6918 BGP_STR
6919 "Display routes matching the communities\n")
6921 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6922 bgp_show_type_community_all, NULL);
6925 DEFUN (show_ip_bgp_ipv4_community_all,
6926 show_ip_bgp_ipv4_community_all_cmd,
6927 "show ip bgp ipv4 (unicast|multicast) community",
6928 SHOW_STR
6929 IP_STR
6930 BGP_STR
6931 "Address family\n"
6932 "Address Family modifier\n"
6933 "Address Family modifier\n"
6934 "Display routes matching the communities\n")
6936 if (strncmp (argv[0], "m", 1) == 0)
6937 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
6938 bgp_show_type_community_all, NULL);
6940 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6941 bgp_show_type_community_all, NULL);
6944 #ifdef HAVE_IPV6
6945 DEFUN (show_bgp_community_all,
6946 show_bgp_community_all_cmd,
6947 "show bgp community",
6948 SHOW_STR
6949 BGP_STR
6950 "Display routes matching the communities\n")
6952 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
6953 bgp_show_type_community_all, NULL);
6956 ALIAS (show_bgp_community_all,
6957 show_bgp_ipv6_community_all_cmd,
6958 "show bgp ipv6 community",
6959 SHOW_STR
6960 BGP_STR
6961 "Address family\n"
6962 "Display routes matching the communities\n")
6964 /* old command */
6965 DEFUN (show_ipv6_bgp_community_all,
6966 show_ipv6_bgp_community_all_cmd,
6967 "show ipv6 bgp community",
6968 SHOW_STR
6969 IPV6_STR
6970 BGP_STR
6971 "Display routes matching the communities\n")
6973 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
6974 bgp_show_type_community_all, NULL);
6977 /* old command */
6978 DEFUN (show_ipv6_mbgp_community_all,
6979 show_ipv6_mbgp_community_all_cmd,
6980 "show ipv6 mbgp community",
6981 SHOW_STR
6982 IPV6_STR
6983 MBGP_STR
6984 "Display routes matching the communities\n")
6986 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
6987 bgp_show_type_community_all, NULL);
6989 #endif /* HAVE_IPV6 */
6991 static int
6992 bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
6993 u_int16_t afi, u_char safi)
6995 struct community *com;
6996 struct buffer *b;
6997 int i;
6998 char *str;
6999 int first = 0;
7001 b = buffer_new (1024);
7002 for (i = 0; i < argc; i++)
7004 if (first)
7005 buffer_putc (b, ' ');
7006 else
7008 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7009 continue;
7010 first = 1;
7013 buffer_putstr (b, argv[i]);
7015 buffer_putc (b, '\0');
7017 str = buffer_getstr (b);
7018 buffer_free (b);
7020 com = community_str2com (str);
7021 XFREE (MTYPE_TMP, str);
7022 if (! com)
7024 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7025 return CMD_WARNING;
7028 return bgp_show (vty, NULL, afi, safi,
7029 (exact ? bgp_show_type_community_exact :
7030 bgp_show_type_community), com);
7033 DEFUN (show_ip_bgp_community,
7034 show_ip_bgp_community_cmd,
7035 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7036 SHOW_STR
7037 IP_STR
7038 BGP_STR
7039 "Display routes matching the communities\n"
7040 "community number\n"
7041 "Do not send outside local AS (well-known community)\n"
7042 "Do not advertise to any peer (well-known community)\n"
7043 "Do not export to next AS (well-known community)\n")
7045 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7048 ALIAS (show_ip_bgp_community,
7049 show_ip_bgp_community2_cmd,
7050 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7051 SHOW_STR
7052 IP_STR
7053 BGP_STR
7054 "Display routes matching the communities\n"
7055 "community number\n"
7056 "Do not send outside local AS (well-known community)\n"
7057 "Do not advertise to any peer (well-known community)\n"
7058 "Do not export to next AS (well-known community)\n"
7059 "community number\n"
7060 "Do not send outside local AS (well-known community)\n"
7061 "Do not advertise to any peer (well-known community)\n"
7062 "Do not export to next AS (well-known community)\n")
7064 ALIAS (show_ip_bgp_community,
7065 show_ip_bgp_community3_cmd,
7066 "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)",
7067 SHOW_STR
7068 IP_STR
7069 BGP_STR
7070 "Display routes matching the communities\n"
7071 "community number\n"
7072 "Do not send outside local AS (well-known community)\n"
7073 "Do not advertise to any peer (well-known community)\n"
7074 "Do not export to next AS (well-known community)\n"
7075 "community number\n"
7076 "Do not send outside local AS (well-known community)\n"
7077 "Do not advertise to any peer (well-known community)\n"
7078 "Do not export to next AS (well-known community)\n"
7079 "community number\n"
7080 "Do not send outside local AS (well-known community)\n"
7081 "Do not advertise to any peer (well-known community)\n"
7082 "Do not export to next AS (well-known community)\n")
7084 ALIAS (show_ip_bgp_community,
7085 show_ip_bgp_community4_cmd,
7086 "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)",
7087 SHOW_STR
7088 IP_STR
7089 BGP_STR
7090 "Display routes matching the communities\n"
7091 "community number\n"
7092 "Do not send outside local AS (well-known community)\n"
7093 "Do not advertise to any peer (well-known community)\n"
7094 "Do not export to next AS (well-known community)\n"
7095 "community number\n"
7096 "Do not send outside local AS (well-known community)\n"
7097 "Do not advertise to any peer (well-known community)\n"
7098 "Do not export to next AS (well-known community)\n"
7099 "community number\n"
7100 "Do not send outside local AS (well-known community)\n"
7101 "Do not advertise to any peer (well-known community)\n"
7102 "Do not export to next AS (well-known community)\n"
7103 "community number\n"
7104 "Do not send outside local AS (well-known community)\n"
7105 "Do not advertise to any peer (well-known community)\n"
7106 "Do not export to next AS (well-known community)\n")
7108 DEFUN (show_ip_bgp_ipv4_community,
7109 show_ip_bgp_ipv4_community_cmd,
7110 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7111 SHOW_STR
7112 IP_STR
7113 BGP_STR
7114 "Address family\n"
7115 "Address Family modifier\n"
7116 "Address Family modifier\n"
7117 "Display routes matching the communities\n"
7118 "community number\n"
7119 "Do not send outside local AS (well-known community)\n"
7120 "Do not advertise to any peer (well-known community)\n"
7121 "Do not export to next AS (well-known community)\n")
7123 if (strncmp (argv[0], "m", 1) == 0)
7124 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7126 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7129 ALIAS (show_ip_bgp_ipv4_community,
7130 show_ip_bgp_ipv4_community2_cmd,
7131 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7132 SHOW_STR
7133 IP_STR
7134 BGP_STR
7135 "Address family\n"
7136 "Address Family modifier\n"
7137 "Address Family modifier\n"
7138 "Display routes matching the communities\n"
7139 "community number\n"
7140 "Do not send outside local AS (well-known community)\n"
7141 "Do not advertise to any peer (well-known community)\n"
7142 "Do not export to next AS (well-known community)\n"
7143 "community number\n"
7144 "Do not send outside local AS (well-known community)\n"
7145 "Do not advertise to any peer (well-known community)\n"
7146 "Do not export to next AS (well-known community)\n")
7148 ALIAS (show_ip_bgp_ipv4_community,
7149 show_ip_bgp_ipv4_community3_cmd,
7150 "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)",
7151 SHOW_STR
7152 IP_STR
7153 BGP_STR
7154 "Address family\n"
7155 "Address Family modifier\n"
7156 "Address Family modifier\n"
7157 "Display routes matching the communities\n"
7158 "community number\n"
7159 "Do not send outside local AS (well-known community)\n"
7160 "Do not advertise to any peer (well-known community)\n"
7161 "Do not export to next AS (well-known community)\n"
7162 "community number\n"
7163 "Do not send outside local AS (well-known community)\n"
7164 "Do not advertise to any peer (well-known community)\n"
7165 "Do not export to next AS (well-known community)\n"
7166 "community number\n"
7167 "Do not send outside local AS (well-known community)\n"
7168 "Do not advertise to any peer (well-known community)\n"
7169 "Do not export to next AS (well-known community)\n")
7171 ALIAS (show_ip_bgp_ipv4_community,
7172 show_ip_bgp_ipv4_community4_cmd,
7173 "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)",
7174 SHOW_STR
7175 IP_STR
7176 BGP_STR
7177 "Address family\n"
7178 "Address Family modifier\n"
7179 "Address Family modifier\n"
7180 "Display routes matching the communities\n"
7181 "community number\n"
7182 "Do not send outside local AS (well-known community)\n"
7183 "Do not advertise to any peer (well-known community)\n"
7184 "Do not export to next AS (well-known community)\n"
7185 "community number\n"
7186 "Do not send outside local AS (well-known community)\n"
7187 "Do not advertise to any peer (well-known community)\n"
7188 "Do not export to next AS (well-known community)\n"
7189 "community number\n"
7190 "Do not send outside local AS (well-known community)\n"
7191 "Do not advertise to any peer (well-known community)\n"
7192 "Do not export to next AS (well-known community)\n"
7193 "community number\n"
7194 "Do not send outside local AS (well-known community)\n"
7195 "Do not advertise to any peer (well-known community)\n"
7196 "Do not export to next AS (well-known community)\n")
7198 DEFUN (show_ip_bgp_community_exact,
7199 show_ip_bgp_community_exact_cmd,
7200 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7201 SHOW_STR
7202 IP_STR
7203 BGP_STR
7204 "Display routes matching the communities\n"
7205 "community number\n"
7206 "Do not send outside local AS (well-known community)\n"
7207 "Do not advertise to any peer (well-known community)\n"
7208 "Do not export to next AS (well-known community)\n"
7209 "Exact match of the communities")
7211 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7214 ALIAS (show_ip_bgp_community_exact,
7215 show_ip_bgp_community2_exact_cmd,
7216 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7217 SHOW_STR
7218 IP_STR
7219 BGP_STR
7220 "Display routes matching the communities\n"
7221 "community number\n"
7222 "Do not send outside local AS (well-known community)\n"
7223 "Do not advertise to any peer (well-known community)\n"
7224 "Do not export to next AS (well-known community)\n"
7225 "community number\n"
7226 "Do not send outside local AS (well-known community)\n"
7227 "Do not advertise to any peer (well-known community)\n"
7228 "Do not export to next AS (well-known community)\n"
7229 "Exact match of the communities")
7231 ALIAS (show_ip_bgp_community_exact,
7232 show_ip_bgp_community3_exact_cmd,
7233 "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",
7234 SHOW_STR
7235 IP_STR
7236 BGP_STR
7237 "Display routes matching the communities\n"
7238 "community number\n"
7239 "Do not send outside local AS (well-known community)\n"
7240 "Do not advertise to any peer (well-known community)\n"
7241 "Do not export to next AS (well-known community)\n"
7242 "community number\n"
7243 "Do not send outside local AS (well-known community)\n"
7244 "Do not advertise to any peer (well-known community)\n"
7245 "Do not export to next AS (well-known community)\n"
7246 "community number\n"
7247 "Do not send outside local AS (well-known community)\n"
7248 "Do not advertise to any peer (well-known community)\n"
7249 "Do not export to next AS (well-known community)\n"
7250 "Exact match of the communities")
7252 ALIAS (show_ip_bgp_community_exact,
7253 show_ip_bgp_community4_exact_cmd,
7254 "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",
7255 SHOW_STR
7256 IP_STR
7257 BGP_STR
7258 "Display routes matching the communities\n"
7259 "community number\n"
7260 "Do not send outside local AS (well-known community)\n"
7261 "Do not advertise to any peer (well-known community)\n"
7262 "Do not export to next AS (well-known community)\n"
7263 "community number\n"
7264 "Do not send outside local AS (well-known community)\n"
7265 "Do not advertise to any peer (well-known community)\n"
7266 "Do not export to next AS (well-known community)\n"
7267 "community number\n"
7268 "Do not send outside local AS (well-known community)\n"
7269 "Do not advertise to any peer (well-known community)\n"
7270 "Do not export to next AS (well-known community)\n"
7271 "community number\n"
7272 "Do not send outside local AS (well-known community)\n"
7273 "Do not advertise to any peer (well-known community)\n"
7274 "Do not export to next AS (well-known community)\n"
7275 "Exact match of the communities")
7277 DEFUN (show_ip_bgp_ipv4_community_exact,
7278 show_ip_bgp_ipv4_community_exact_cmd,
7279 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7280 SHOW_STR
7281 IP_STR
7282 BGP_STR
7283 "Address family\n"
7284 "Address Family modifier\n"
7285 "Address Family modifier\n"
7286 "Display routes matching the communities\n"
7287 "community number\n"
7288 "Do not send outside local AS (well-known community)\n"
7289 "Do not advertise to any peer (well-known community)\n"
7290 "Do not export to next AS (well-known community)\n"
7291 "Exact match of the communities")
7293 if (strncmp (argv[0], "m", 1) == 0)
7294 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7296 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7299 ALIAS (show_ip_bgp_ipv4_community_exact,
7300 show_ip_bgp_ipv4_community2_exact_cmd,
7301 "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",
7302 SHOW_STR
7303 IP_STR
7304 BGP_STR
7305 "Address family\n"
7306 "Address Family modifier\n"
7307 "Address Family modifier\n"
7308 "Display routes matching the communities\n"
7309 "community number\n"
7310 "Do not send outside local AS (well-known community)\n"
7311 "Do not advertise to any peer (well-known community)\n"
7312 "Do not export to next AS (well-known community)\n"
7313 "community number\n"
7314 "Do not send outside local AS (well-known community)\n"
7315 "Do not advertise to any peer (well-known community)\n"
7316 "Do not export to next AS (well-known community)\n"
7317 "Exact match of the communities")
7319 ALIAS (show_ip_bgp_ipv4_community_exact,
7320 show_ip_bgp_ipv4_community3_exact_cmd,
7321 "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",
7322 SHOW_STR
7323 IP_STR
7324 BGP_STR
7325 "Address family\n"
7326 "Address Family modifier\n"
7327 "Address Family modifier\n"
7328 "Display routes matching the communities\n"
7329 "community number\n"
7330 "Do not send outside local AS (well-known community)\n"
7331 "Do not advertise to any peer (well-known community)\n"
7332 "Do not export to next AS (well-known community)\n"
7333 "community number\n"
7334 "Do not send outside local AS (well-known community)\n"
7335 "Do not advertise to any peer (well-known community)\n"
7336 "Do not export to next AS (well-known community)\n"
7337 "community number\n"
7338 "Do not send outside local AS (well-known community)\n"
7339 "Do not advertise to any peer (well-known community)\n"
7340 "Do not export to next AS (well-known community)\n"
7341 "Exact match of the communities")
7343 ALIAS (show_ip_bgp_ipv4_community_exact,
7344 show_ip_bgp_ipv4_community4_exact_cmd,
7345 "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",
7346 SHOW_STR
7347 IP_STR
7348 BGP_STR
7349 "Address family\n"
7350 "Address Family modifier\n"
7351 "Address Family modifier\n"
7352 "Display routes matching the communities\n"
7353 "community number\n"
7354 "Do not send outside local AS (well-known community)\n"
7355 "Do not advertise to any peer (well-known community)\n"
7356 "Do not export to next AS (well-known community)\n"
7357 "community number\n"
7358 "Do not send outside local AS (well-known community)\n"
7359 "Do not advertise to any peer (well-known community)\n"
7360 "Do not export to next AS (well-known community)\n"
7361 "community number\n"
7362 "Do not send outside local AS (well-known community)\n"
7363 "Do not advertise to any peer (well-known community)\n"
7364 "Do not export to next AS (well-known community)\n"
7365 "community number\n"
7366 "Do not send outside local AS (well-known community)\n"
7367 "Do not advertise to any peer (well-known community)\n"
7368 "Do not export to next AS (well-known community)\n"
7369 "Exact match of the communities")
7371 #ifdef HAVE_IPV6
7372 DEFUN (show_bgp_community,
7373 show_bgp_community_cmd,
7374 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7375 SHOW_STR
7376 BGP_STR
7377 "Display routes matching the communities\n"
7378 "community number\n"
7379 "Do not send outside local AS (well-known community)\n"
7380 "Do not advertise to any peer (well-known community)\n"
7381 "Do not export to next AS (well-known community)\n")
7383 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7386 ALIAS (show_bgp_community,
7387 show_bgp_ipv6_community_cmd,
7388 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7389 SHOW_STR
7390 BGP_STR
7391 "Address family\n"
7392 "Display routes matching the communities\n"
7393 "community number\n"
7394 "Do not send outside local AS (well-known community)\n"
7395 "Do not advertise to any peer (well-known community)\n"
7396 "Do not export to next AS (well-known community)\n")
7398 ALIAS (show_bgp_community,
7399 show_bgp_community2_cmd,
7400 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7401 SHOW_STR
7402 BGP_STR
7403 "Display routes matching the communities\n"
7404 "community number\n"
7405 "Do not send outside local AS (well-known community)\n"
7406 "Do not advertise to any peer (well-known community)\n"
7407 "Do not export to next AS (well-known community)\n"
7408 "community number\n"
7409 "Do not send outside local AS (well-known community)\n"
7410 "Do not advertise to any peer (well-known community)\n"
7411 "Do not export to next AS (well-known community)\n")
7413 ALIAS (show_bgp_community,
7414 show_bgp_ipv6_community2_cmd,
7415 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7416 SHOW_STR
7417 BGP_STR
7418 "Address family\n"
7419 "Display routes matching the communities\n"
7420 "community number\n"
7421 "Do not send outside local AS (well-known community)\n"
7422 "Do not advertise to any peer (well-known community)\n"
7423 "Do not export to next AS (well-known community)\n"
7424 "community number\n"
7425 "Do not send outside local AS (well-known community)\n"
7426 "Do not advertise to any peer (well-known community)\n"
7427 "Do not export to next AS (well-known community)\n")
7429 ALIAS (show_bgp_community,
7430 show_bgp_community3_cmd,
7431 "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)",
7432 SHOW_STR
7433 BGP_STR
7434 "Display routes matching the communities\n"
7435 "community number\n"
7436 "Do not send outside local AS (well-known community)\n"
7437 "Do not advertise to any peer (well-known community)\n"
7438 "Do not export to next AS (well-known community)\n"
7439 "community number\n"
7440 "Do not send outside local AS (well-known community)\n"
7441 "Do not advertise to any peer (well-known community)\n"
7442 "Do not export to next AS (well-known community)\n"
7443 "community number\n"
7444 "Do not send outside local AS (well-known community)\n"
7445 "Do not advertise to any peer (well-known community)\n"
7446 "Do not export to next AS (well-known community)\n")
7448 ALIAS (show_bgp_community,
7449 show_bgp_ipv6_community3_cmd,
7450 "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)",
7451 SHOW_STR
7452 BGP_STR
7453 "Address family\n"
7454 "Display routes matching the communities\n"
7455 "community number\n"
7456 "Do not send outside local AS (well-known community)\n"
7457 "Do not advertise to any peer (well-known community)\n"
7458 "Do not export to next AS (well-known community)\n"
7459 "community number\n"
7460 "Do not send outside local AS (well-known community)\n"
7461 "Do not advertise to any peer (well-known community)\n"
7462 "Do not export to next AS (well-known community)\n"
7463 "community number\n"
7464 "Do not send outside local AS (well-known community)\n"
7465 "Do not advertise to any peer (well-known community)\n"
7466 "Do not export to next AS (well-known community)\n")
7468 ALIAS (show_bgp_community,
7469 show_bgp_community4_cmd,
7470 "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)",
7471 SHOW_STR
7472 BGP_STR
7473 "Display routes matching the communities\n"
7474 "community number\n"
7475 "Do not send outside local AS (well-known community)\n"
7476 "Do not advertise to any peer (well-known community)\n"
7477 "Do not export to next AS (well-known community)\n"
7478 "community number\n"
7479 "Do not send outside local AS (well-known community)\n"
7480 "Do not advertise to any peer (well-known community)\n"
7481 "Do not export to next AS (well-known community)\n"
7482 "community number\n"
7483 "Do not send outside local AS (well-known community)\n"
7484 "Do not advertise to any peer (well-known community)\n"
7485 "Do not export to next AS (well-known community)\n"
7486 "community number\n"
7487 "Do not send outside local AS (well-known community)\n"
7488 "Do not advertise to any peer (well-known community)\n"
7489 "Do not export to next AS (well-known community)\n")
7491 ALIAS (show_bgp_community,
7492 show_bgp_ipv6_community4_cmd,
7493 "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)",
7494 SHOW_STR
7495 BGP_STR
7496 "Address family\n"
7497 "Display routes matching the communities\n"
7498 "community number\n"
7499 "Do not send outside local AS (well-known community)\n"
7500 "Do not advertise to any peer (well-known community)\n"
7501 "Do not export to next AS (well-known community)\n"
7502 "community number\n"
7503 "Do not send outside local AS (well-known community)\n"
7504 "Do not advertise to any peer (well-known community)\n"
7505 "Do not export to next AS (well-known community)\n"
7506 "community number\n"
7507 "Do not send outside local AS (well-known community)\n"
7508 "Do not advertise to any peer (well-known community)\n"
7509 "Do not export to next AS (well-known community)\n"
7510 "community number\n"
7511 "Do not send outside local AS (well-known community)\n"
7512 "Do not advertise to any peer (well-known community)\n"
7513 "Do not export to next AS (well-known community)\n")
7515 /* old command */
7516 DEFUN (show_ipv6_bgp_community,
7517 show_ipv6_bgp_community_cmd,
7518 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7519 SHOW_STR
7520 IPV6_STR
7521 BGP_STR
7522 "Display routes matching the communities\n"
7523 "community number\n"
7524 "Do not send outside local AS (well-known community)\n"
7525 "Do not advertise to any peer (well-known community)\n"
7526 "Do not export to next AS (well-known community)\n")
7528 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7531 /* old command */
7532 ALIAS (show_ipv6_bgp_community,
7533 show_ipv6_bgp_community2_cmd,
7534 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7535 SHOW_STR
7536 IPV6_STR
7537 BGP_STR
7538 "Display routes matching the communities\n"
7539 "community number\n"
7540 "Do not send outside local AS (well-known community)\n"
7541 "Do not advertise to any peer (well-known community)\n"
7542 "Do not export to next AS (well-known community)\n"
7543 "community number\n"
7544 "Do not send outside local AS (well-known community)\n"
7545 "Do not advertise to any peer (well-known community)\n"
7546 "Do not export to next AS (well-known community)\n")
7548 /* old command */
7549 ALIAS (show_ipv6_bgp_community,
7550 show_ipv6_bgp_community3_cmd,
7551 "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)",
7552 SHOW_STR
7553 IPV6_STR
7554 BGP_STR
7555 "Display routes matching the communities\n"
7556 "community number\n"
7557 "Do not send outside local AS (well-known community)\n"
7558 "Do not advertise to any peer (well-known community)\n"
7559 "Do not export to next AS (well-known community)\n"
7560 "community number\n"
7561 "Do not send outside local AS (well-known community)\n"
7562 "Do not advertise to any peer (well-known community)\n"
7563 "Do not export to next AS (well-known community)\n"
7564 "community number\n"
7565 "Do not send outside local AS (well-known community)\n"
7566 "Do not advertise to any peer (well-known community)\n"
7567 "Do not export to next AS (well-known community)\n")
7569 /* old command */
7570 ALIAS (show_ipv6_bgp_community,
7571 show_ipv6_bgp_community4_cmd,
7572 "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)",
7573 SHOW_STR
7574 IPV6_STR
7575 BGP_STR
7576 "Display routes matching the communities\n"
7577 "community number\n"
7578 "Do not send outside local AS (well-known community)\n"
7579 "Do not advertise to any peer (well-known community)\n"
7580 "Do not export to next AS (well-known community)\n"
7581 "community number\n"
7582 "Do not send outside local AS (well-known community)\n"
7583 "Do not advertise to any peer (well-known community)\n"
7584 "Do not export to next AS (well-known community)\n"
7585 "community number\n"
7586 "Do not send outside local AS (well-known community)\n"
7587 "Do not advertise to any peer (well-known community)\n"
7588 "Do not export to next AS (well-known community)\n"
7589 "community number\n"
7590 "Do not send outside local AS (well-known community)\n"
7591 "Do not advertise to any peer (well-known community)\n"
7592 "Do not export to next AS (well-known community)\n")
7594 DEFUN (show_bgp_community_exact,
7595 show_bgp_community_exact_cmd,
7596 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7597 SHOW_STR
7598 BGP_STR
7599 "Display routes matching the communities\n"
7600 "community number\n"
7601 "Do not send outside local AS (well-known community)\n"
7602 "Do not advertise to any peer (well-known community)\n"
7603 "Do not export to next AS (well-known community)\n"
7604 "Exact match of the communities")
7606 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7609 ALIAS (show_bgp_community_exact,
7610 show_bgp_ipv6_community_exact_cmd,
7611 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7612 SHOW_STR
7613 BGP_STR
7614 "Address family\n"
7615 "Display routes matching the communities\n"
7616 "community number\n"
7617 "Do not send outside local AS (well-known community)\n"
7618 "Do not advertise to any peer (well-known community)\n"
7619 "Do not export to next AS (well-known community)\n"
7620 "Exact match of the communities")
7622 ALIAS (show_bgp_community_exact,
7623 show_bgp_community2_exact_cmd,
7624 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7625 SHOW_STR
7626 BGP_STR
7627 "Display routes matching the communities\n"
7628 "community number\n"
7629 "Do not send outside local AS (well-known community)\n"
7630 "Do not advertise to any peer (well-known community)\n"
7631 "Do not export to next AS (well-known community)\n"
7632 "community number\n"
7633 "Do not send outside local AS (well-known community)\n"
7634 "Do not advertise to any peer (well-known community)\n"
7635 "Do not export to next AS (well-known community)\n"
7636 "Exact match of the communities")
7638 ALIAS (show_bgp_community_exact,
7639 show_bgp_ipv6_community2_exact_cmd,
7640 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7641 SHOW_STR
7642 BGP_STR
7643 "Address family\n"
7644 "Display routes matching the communities\n"
7645 "community number\n"
7646 "Do not send outside local AS (well-known community)\n"
7647 "Do not advertise to any peer (well-known community)\n"
7648 "Do not export to next AS (well-known community)\n"
7649 "community number\n"
7650 "Do not send outside local AS (well-known community)\n"
7651 "Do not advertise to any peer (well-known community)\n"
7652 "Do not export to next AS (well-known community)\n"
7653 "Exact match of the communities")
7655 ALIAS (show_bgp_community_exact,
7656 show_bgp_community3_exact_cmd,
7657 "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",
7658 SHOW_STR
7659 BGP_STR
7660 "Display routes matching the communities\n"
7661 "community number\n"
7662 "Do not send outside local AS (well-known community)\n"
7663 "Do not advertise to any peer (well-known community)\n"
7664 "Do not export to next AS (well-known community)\n"
7665 "community number\n"
7666 "Do not send outside local AS (well-known community)\n"
7667 "Do not advertise to any peer (well-known community)\n"
7668 "Do not export to next AS (well-known community)\n"
7669 "community number\n"
7670 "Do not send outside local AS (well-known community)\n"
7671 "Do not advertise to any peer (well-known community)\n"
7672 "Do not export to next AS (well-known community)\n"
7673 "Exact match of the communities")
7675 ALIAS (show_bgp_community_exact,
7676 show_bgp_ipv6_community3_exact_cmd,
7677 "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",
7678 SHOW_STR
7679 BGP_STR
7680 "Address family\n"
7681 "Display routes matching the communities\n"
7682 "community number\n"
7683 "Do not send outside local AS (well-known community)\n"
7684 "Do not advertise to any peer (well-known community)\n"
7685 "Do not export to next AS (well-known community)\n"
7686 "community number\n"
7687 "Do not send outside local AS (well-known community)\n"
7688 "Do not advertise to any peer (well-known community)\n"
7689 "Do not export to next AS (well-known community)\n"
7690 "community number\n"
7691 "Do not send outside local AS (well-known community)\n"
7692 "Do not advertise to any peer (well-known community)\n"
7693 "Do not export to next AS (well-known community)\n"
7694 "Exact match of the communities")
7696 ALIAS (show_bgp_community_exact,
7697 show_bgp_community4_exact_cmd,
7698 "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",
7699 SHOW_STR
7700 BGP_STR
7701 "Display routes matching the communities\n"
7702 "community number\n"
7703 "Do not send outside local AS (well-known community)\n"
7704 "Do not advertise to any peer (well-known community)\n"
7705 "Do not export to next AS (well-known community)\n"
7706 "community number\n"
7707 "Do not send outside local AS (well-known community)\n"
7708 "Do not advertise to any peer (well-known community)\n"
7709 "Do not export to next AS (well-known community)\n"
7710 "community number\n"
7711 "Do not send outside local AS (well-known community)\n"
7712 "Do not advertise to any peer (well-known community)\n"
7713 "Do not export to next AS (well-known community)\n"
7714 "community number\n"
7715 "Do not send outside local AS (well-known community)\n"
7716 "Do not advertise to any peer (well-known community)\n"
7717 "Do not export to next AS (well-known community)\n"
7718 "Exact match of the communities")
7720 ALIAS (show_bgp_community_exact,
7721 show_bgp_ipv6_community4_exact_cmd,
7722 "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",
7723 SHOW_STR
7724 BGP_STR
7725 "Address family\n"
7726 "Display routes matching the communities\n"
7727 "community number\n"
7728 "Do not send outside local AS (well-known community)\n"
7729 "Do not advertise to any peer (well-known community)\n"
7730 "Do not export to next AS (well-known community)\n"
7731 "community number\n"
7732 "Do not send outside local AS (well-known community)\n"
7733 "Do not advertise to any peer (well-known community)\n"
7734 "Do not export to next AS (well-known community)\n"
7735 "community number\n"
7736 "Do not send outside local AS (well-known community)\n"
7737 "Do not advertise to any peer (well-known community)\n"
7738 "Do not export to next AS (well-known community)\n"
7739 "community number\n"
7740 "Do not send outside local AS (well-known community)\n"
7741 "Do not advertise to any peer (well-known community)\n"
7742 "Do not export to next AS (well-known community)\n"
7743 "Exact match of the communities")
7745 /* old command */
7746 DEFUN (show_ipv6_bgp_community_exact,
7747 show_ipv6_bgp_community_exact_cmd,
7748 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7749 SHOW_STR
7750 IPV6_STR
7751 BGP_STR
7752 "Display routes matching the communities\n"
7753 "community number\n"
7754 "Do not send outside local AS (well-known community)\n"
7755 "Do not advertise to any peer (well-known community)\n"
7756 "Do not export to next AS (well-known community)\n"
7757 "Exact match of the communities")
7759 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7762 /* old command */
7763 ALIAS (show_ipv6_bgp_community_exact,
7764 show_ipv6_bgp_community2_exact_cmd,
7765 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7766 SHOW_STR
7767 IPV6_STR
7768 BGP_STR
7769 "Display routes matching the communities\n"
7770 "community number\n"
7771 "Do not send outside local AS (well-known community)\n"
7772 "Do not advertise to any peer (well-known community)\n"
7773 "Do not export to next AS (well-known community)\n"
7774 "community number\n"
7775 "Do not send outside local AS (well-known community)\n"
7776 "Do not advertise to any peer (well-known community)\n"
7777 "Do not export to next AS (well-known community)\n"
7778 "Exact match of the communities")
7780 /* old command */
7781 ALIAS (show_ipv6_bgp_community_exact,
7782 show_ipv6_bgp_community3_exact_cmd,
7783 "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",
7784 SHOW_STR
7785 IPV6_STR
7786 BGP_STR
7787 "Display routes matching the communities\n"
7788 "community number\n"
7789 "Do not send outside local AS (well-known community)\n"
7790 "Do not advertise to any peer (well-known community)\n"
7791 "Do not export to next AS (well-known community)\n"
7792 "community number\n"
7793 "Do not send outside local AS (well-known community)\n"
7794 "Do not advertise to any peer (well-known community)\n"
7795 "Do not export to next AS (well-known community)\n"
7796 "community number\n"
7797 "Do not send outside local AS (well-known community)\n"
7798 "Do not advertise to any peer (well-known community)\n"
7799 "Do not export to next AS (well-known community)\n"
7800 "Exact match of the communities")
7802 /* old command */
7803 ALIAS (show_ipv6_bgp_community_exact,
7804 show_ipv6_bgp_community4_exact_cmd,
7805 "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",
7806 SHOW_STR
7807 IPV6_STR
7808 BGP_STR
7809 "Display routes matching the communities\n"
7810 "community number\n"
7811 "Do not send outside local AS (well-known community)\n"
7812 "Do not advertise to any peer (well-known community)\n"
7813 "Do not export to next AS (well-known community)\n"
7814 "community number\n"
7815 "Do not send outside local AS (well-known community)\n"
7816 "Do not advertise to any peer (well-known community)\n"
7817 "Do not export to next AS (well-known community)\n"
7818 "community number\n"
7819 "Do not send outside local AS (well-known community)\n"
7820 "Do not advertise to any peer (well-known community)\n"
7821 "Do not export to next AS (well-known community)\n"
7822 "community number\n"
7823 "Do not send outside local AS (well-known community)\n"
7824 "Do not advertise to any peer (well-known community)\n"
7825 "Do not export to next AS (well-known community)\n"
7826 "Exact match of the communities")
7828 /* old command */
7829 DEFUN (show_ipv6_mbgp_community,
7830 show_ipv6_mbgp_community_cmd,
7831 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7832 SHOW_STR
7833 IPV6_STR
7834 MBGP_STR
7835 "Display routes matching the communities\n"
7836 "community number\n"
7837 "Do not send outside local AS (well-known community)\n"
7838 "Do not advertise to any peer (well-known community)\n"
7839 "Do not export to next AS (well-known community)\n")
7841 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7844 /* old command */
7845 ALIAS (show_ipv6_mbgp_community,
7846 show_ipv6_mbgp_community2_cmd,
7847 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7848 SHOW_STR
7849 IPV6_STR
7850 MBGP_STR
7851 "Display routes matching the communities\n"
7852 "community number\n"
7853 "Do not send outside local AS (well-known community)\n"
7854 "Do not advertise to any peer (well-known community)\n"
7855 "Do not export to next AS (well-known community)\n"
7856 "community number\n"
7857 "Do not send outside local AS (well-known community)\n"
7858 "Do not advertise to any peer (well-known community)\n"
7859 "Do not export to next AS (well-known community)\n")
7861 /* old command */
7862 ALIAS (show_ipv6_mbgp_community,
7863 show_ipv6_mbgp_community3_cmd,
7864 "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)",
7865 SHOW_STR
7866 IPV6_STR
7867 MBGP_STR
7868 "Display routes matching the communities\n"
7869 "community number\n"
7870 "Do not send outside local AS (well-known community)\n"
7871 "Do not advertise to any peer (well-known community)\n"
7872 "Do not export to next AS (well-known community)\n"
7873 "community number\n"
7874 "Do not send outside local AS (well-known community)\n"
7875 "Do not advertise to any peer (well-known community)\n"
7876 "Do not export to next AS (well-known community)\n"
7877 "community number\n"
7878 "Do not send outside local AS (well-known community)\n"
7879 "Do not advertise to any peer (well-known community)\n"
7880 "Do not export to next AS (well-known community)\n")
7882 /* old command */
7883 ALIAS (show_ipv6_mbgp_community,
7884 show_ipv6_mbgp_community4_cmd,
7885 "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)",
7886 SHOW_STR
7887 IPV6_STR
7888 MBGP_STR
7889 "Display routes matching the communities\n"
7890 "community number\n"
7891 "Do not send outside local AS (well-known community)\n"
7892 "Do not advertise to any peer (well-known community)\n"
7893 "Do not export to next AS (well-known community)\n"
7894 "community number\n"
7895 "Do not send outside local AS (well-known community)\n"
7896 "Do not advertise to any peer (well-known community)\n"
7897 "Do not export to next AS (well-known community)\n"
7898 "community number\n"
7899 "Do not send outside local AS (well-known community)\n"
7900 "Do not advertise to any peer (well-known community)\n"
7901 "Do not export to next AS (well-known community)\n"
7902 "community number\n"
7903 "Do not send outside local AS (well-known community)\n"
7904 "Do not advertise to any peer (well-known community)\n"
7905 "Do not export to next AS (well-known community)\n")
7907 /* old command */
7908 DEFUN (show_ipv6_mbgp_community_exact,
7909 show_ipv6_mbgp_community_exact_cmd,
7910 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7911 SHOW_STR
7912 IPV6_STR
7913 MBGP_STR
7914 "Display routes matching the communities\n"
7915 "community number\n"
7916 "Do not send outside local AS (well-known community)\n"
7917 "Do not advertise to any peer (well-known community)\n"
7918 "Do not export to next AS (well-known community)\n"
7919 "Exact match of the communities")
7921 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7924 /* old command */
7925 ALIAS (show_ipv6_mbgp_community_exact,
7926 show_ipv6_mbgp_community2_exact_cmd,
7927 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7928 SHOW_STR
7929 IPV6_STR
7930 MBGP_STR
7931 "Display routes matching the communities\n"
7932 "community number\n"
7933 "Do not send outside local AS (well-known community)\n"
7934 "Do not advertise to any peer (well-known community)\n"
7935 "Do not export to next AS (well-known community)\n"
7936 "community number\n"
7937 "Do not send outside local AS (well-known community)\n"
7938 "Do not advertise to any peer (well-known community)\n"
7939 "Do not export to next AS (well-known community)\n"
7940 "Exact match of the communities")
7942 /* old command */
7943 ALIAS (show_ipv6_mbgp_community_exact,
7944 show_ipv6_mbgp_community3_exact_cmd,
7945 "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",
7946 SHOW_STR
7947 IPV6_STR
7948 MBGP_STR
7949 "Display routes matching the communities\n"
7950 "community number\n"
7951 "Do not send outside local AS (well-known community)\n"
7952 "Do not advertise to any peer (well-known community)\n"
7953 "Do not export to next AS (well-known community)\n"
7954 "community number\n"
7955 "Do not send outside local AS (well-known community)\n"
7956 "Do not advertise to any peer (well-known community)\n"
7957 "Do not export to next AS (well-known community)\n"
7958 "community number\n"
7959 "Do not send outside local AS (well-known community)\n"
7960 "Do not advertise to any peer (well-known community)\n"
7961 "Do not export to next AS (well-known community)\n"
7962 "Exact match of the communities")
7964 /* old command */
7965 ALIAS (show_ipv6_mbgp_community_exact,
7966 show_ipv6_mbgp_community4_exact_cmd,
7967 "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",
7968 SHOW_STR
7969 IPV6_STR
7970 MBGP_STR
7971 "Display routes matching the communities\n"
7972 "community number\n"
7973 "Do not send outside local AS (well-known community)\n"
7974 "Do not advertise to any peer (well-known community)\n"
7975 "Do not export to next AS (well-known community)\n"
7976 "community number\n"
7977 "Do not send outside local AS (well-known community)\n"
7978 "Do not advertise to any peer (well-known community)\n"
7979 "Do not export to next AS (well-known community)\n"
7980 "community number\n"
7981 "Do not send outside local AS (well-known community)\n"
7982 "Do not advertise to any peer (well-known community)\n"
7983 "Do not export to next AS (well-known community)\n"
7984 "community number\n"
7985 "Do not send outside local AS (well-known community)\n"
7986 "Do not advertise to any peer (well-known community)\n"
7987 "Do not export to next AS (well-known community)\n"
7988 "Exact match of the communities")
7989 #endif /* HAVE_IPV6 */
7991 static int
7992 bgp_show_community_list (struct vty *vty, const char *com, int exact,
7993 u_int16_t afi, u_char safi)
7995 struct community_list *list;
7997 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
7998 if (list == NULL)
8000 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8001 VTY_NEWLINE);
8002 return CMD_WARNING;
8005 return bgp_show (vty, NULL, afi, safi,
8006 (exact ? bgp_show_type_community_list_exact :
8007 bgp_show_type_community_list), list);
8010 DEFUN (show_ip_bgp_community_list,
8011 show_ip_bgp_community_list_cmd,
8012 "show ip bgp community-list (<1-500>|WORD)",
8013 SHOW_STR
8014 IP_STR
8015 BGP_STR
8016 "Display routes matching the community-list\n"
8017 "community-list number\n"
8018 "community-list name\n")
8020 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8023 DEFUN (show_ip_bgp_ipv4_community_list,
8024 show_ip_bgp_ipv4_community_list_cmd,
8025 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
8026 SHOW_STR
8027 IP_STR
8028 BGP_STR
8029 "Address family\n"
8030 "Address Family modifier\n"
8031 "Address Family modifier\n"
8032 "Display routes matching the community-list\n"
8033 "community-list number\n"
8034 "community-list name\n")
8036 if (strncmp (argv[0], "m", 1) == 0)
8037 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8039 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8042 DEFUN (show_ip_bgp_community_list_exact,
8043 show_ip_bgp_community_list_exact_cmd,
8044 "show ip bgp community-list (<1-500>|WORD) exact-match",
8045 SHOW_STR
8046 IP_STR
8047 BGP_STR
8048 "Display routes matching the community-list\n"
8049 "community-list number\n"
8050 "community-list name\n"
8051 "Exact match of the communities\n")
8053 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8056 DEFUN (show_ip_bgp_ipv4_community_list_exact,
8057 show_ip_bgp_ipv4_community_list_exact_cmd,
8058 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
8059 SHOW_STR
8060 IP_STR
8061 BGP_STR
8062 "Address family\n"
8063 "Address Family modifier\n"
8064 "Address Family modifier\n"
8065 "Display routes matching the community-list\n"
8066 "community-list number\n"
8067 "community-list name\n"
8068 "Exact match of the communities\n")
8070 if (strncmp (argv[0], "m", 1) == 0)
8071 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8073 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8076 #ifdef HAVE_IPV6
8077 DEFUN (show_bgp_community_list,
8078 show_bgp_community_list_cmd,
8079 "show bgp community-list (<1-500>|WORD)",
8080 SHOW_STR
8081 BGP_STR
8082 "Display routes matching the community-list\n"
8083 "community-list number\n"
8084 "community-list name\n")
8086 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8089 ALIAS (show_bgp_community_list,
8090 show_bgp_ipv6_community_list_cmd,
8091 "show bgp ipv6 community-list (<1-500>|WORD)",
8092 SHOW_STR
8093 BGP_STR
8094 "Address family\n"
8095 "Display routes matching the community-list\n"
8096 "community-list number\n"
8097 "community-list name\n");
8099 /* old command */
8100 DEFUN (show_ipv6_bgp_community_list,
8101 show_ipv6_bgp_community_list_cmd,
8102 "show ipv6 bgp community-list WORD",
8103 SHOW_STR
8104 IPV6_STR
8105 BGP_STR
8106 "Display routes matching the community-list\n"
8107 "community-list name\n")
8109 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8112 /* old command */
8113 DEFUN (show_ipv6_mbgp_community_list,
8114 show_ipv6_mbgp_community_list_cmd,
8115 "show ipv6 mbgp community-list WORD",
8116 SHOW_STR
8117 IPV6_STR
8118 MBGP_STR
8119 "Display routes matching the community-list\n"
8120 "community-list name\n")
8122 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8125 DEFUN (show_bgp_community_list_exact,
8126 show_bgp_community_list_exact_cmd,
8127 "show bgp community-list (<1-500>|WORD) exact-match",
8128 SHOW_STR
8129 BGP_STR
8130 "Display routes matching the community-list\n"
8131 "community-list number\n"
8132 "community-list name\n"
8133 "Exact match of the communities\n")
8135 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8138 ALIAS (show_bgp_community_list_exact,
8139 show_bgp_ipv6_community_list_exact_cmd,
8140 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
8141 SHOW_STR
8142 BGP_STR
8143 "Address family\n"
8144 "Display routes matching the community-list\n"
8145 "community-list number\n"
8146 "community-list name\n"
8147 "Exact match of the communities\n")
8149 /* old command */
8150 DEFUN (show_ipv6_bgp_community_list_exact,
8151 show_ipv6_bgp_community_list_exact_cmd,
8152 "show ipv6 bgp community-list WORD exact-match",
8153 SHOW_STR
8154 IPV6_STR
8155 BGP_STR
8156 "Display routes matching the community-list\n"
8157 "community-list name\n"
8158 "Exact match of the communities\n")
8160 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8163 /* old command */
8164 DEFUN (show_ipv6_mbgp_community_list_exact,
8165 show_ipv6_mbgp_community_list_exact_cmd,
8166 "show ipv6 mbgp community-list WORD exact-match",
8167 SHOW_STR
8168 IPV6_STR
8169 MBGP_STR
8170 "Display routes matching the community-list\n"
8171 "community-list name\n"
8172 "Exact match of the communities\n")
8174 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8176 #endif /* HAVE_IPV6 */
8178 static int
8179 bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
8180 safi_t safi, enum bgp_show_type type)
8182 int ret;
8183 struct prefix *p;
8185 p = prefix_new();
8187 ret = str2prefix (prefix, p);
8188 if (! ret)
8190 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8191 return CMD_WARNING;
8194 ret = bgp_show (vty, NULL, afi, safi, type, p);
8195 prefix_free(p);
8196 return ret;
8199 DEFUN (show_ip_bgp_prefix_longer,
8200 show_ip_bgp_prefix_longer_cmd,
8201 "show ip bgp A.B.C.D/M longer-prefixes",
8202 SHOW_STR
8203 IP_STR
8204 BGP_STR
8205 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8206 "Display route and more specific routes\n")
8208 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8209 bgp_show_type_prefix_longer);
8212 DEFUN (show_ip_bgp_flap_prefix_longer,
8213 show_ip_bgp_flap_prefix_longer_cmd,
8214 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8215 SHOW_STR
8216 IP_STR
8217 BGP_STR
8218 "Display flap statistics of routes\n"
8219 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8220 "Display route and more specific routes\n")
8222 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8223 bgp_show_type_flap_prefix_longer);
8226 DEFUN (show_ip_bgp_ipv4_prefix_longer,
8227 show_ip_bgp_ipv4_prefix_longer_cmd,
8228 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8229 SHOW_STR
8230 IP_STR
8231 BGP_STR
8232 "Address family\n"
8233 "Address Family modifier\n"
8234 "Address Family modifier\n"
8235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8236 "Display route and more specific routes\n")
8238 if (strncmp (argv[0], "m", 1) == 0)
8239 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8240 bgp_show_type_prefix_longer);
8242 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8243 bgp_show_type_prefix_longer);
8246 DEFUN (show_ip_bgp_flap_address,
8247 show_ip_bgp_flap_address_cmd,
8248 "show ip bgp flap-statistics A.B.C.D",
8249 SHOW_STR
8250 IP_STR
8251 BGP_STR
8252 "Display flap statistics of routes\n"
8253 "Network in the BGP routing table to display\n")
8255 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8256 bgp_show_type_flap_address);
8259 DEFUN (show_ip_bgp_flap_prefix,
8260 show_ip_bgp_flap_prefix_cmd,
8261 "show ip bgp flap-statistics A.B.C.D/M",
8262 SHOW_STR
8263 IP_STR
8264 BGP_STR
8265 "Display flap statistics of routes\n"
8266 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8268 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8269 bgp_show_type_flap_prefix);
8271 #ifdef HAVE_IPV6
8272 DEFUN (show_bgp_prefix_longer,
8273 show_bgp_prefix_longer_cmd,
8274 "show bgp X:X::X:X/M longer-prefixes",
8275 SHOW_STR
8276 BGP_STR
8277 "IPv6 prefix <network>/<length>\n"
8278 "Display route and more specific routes\n")
8280 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8281 bgp_show_type_prefix_longer);
8284 ALIAS (show_bgp_prefix_longer,
8285 show_bgp_ipv6_prefix_longer_cmd,
8286 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8287 SHOW_STR
8288 BGP_STR
8289 "Address family\n"
8290 "IPv6 prefix <network>/<length>\n"
8291 "Display route and more specific routes\n")
8293 /* old command */
8294 DEFUN (show_ipv6_bgp_prefix_longer,
8295 show_ipv6_bgp_prefix_longer_cmd,
8296 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8297 SHOW_STR
8298 IPV6_STR
8299 BGP_STR
8300 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8301 "Display route and more specific routes\n")
8303 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8304 bgp_show_type_prefix_longer);
8307 /* old command */
8308 DEFUN (show_ipv6_mbgp_prefix_longer,
8309 show_ipv6_mbgp_prefix_longer_cmd,
8310 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8311 SHOW_STR
8312 IPV6_STR
8313 MBGP_STR
8314 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8315 "Display route and more specific routes\n")
8317 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8318 bgp_show_type_prefix_longer);
8320 #endif /* HAVE_IPV6 */
8322 static struct peer *
8323 peer_lookup_in_view (struct vty *vty, const char *view_name,
8324 const char *ip_str)
8326 int ret;
8327 struct bgp *bgp;
8328 struct peer *peer;
8329 union sockunion su;
8331 /* BGP structure lookup. */
8332 if (view_name)
8334 bgp = bgp_lookup_by_name (view_name);
8335 if (! bgp)
8337 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8338 return NULL;
8341 else
8343 bgp = bgp_get_default ();
8344 if (! bgp)
8346 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8347 return NULL;
8351 /* Get peer sockunion. */
8352 ret = str2sockunion (ip_str, &su);
8353 if (ret < 0)
8355 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8356 return NULL;
8359 /* Peer structure lookup. */
8360 peer = peer_lookup (bgp, &su);
8361 if (! peer)
8363 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8364 return NULL;
8367 return peer;
8370 static void
8371 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8372 int in)
8374 struct bgp_table *table;
8375 struct bgp_adj_in *ain;
8376 struct bgp_adj_out *adj;
8377 unsigned long output_count;
8378 struct bgp_node *rn;
8379 int header1 = 1;
8380 struct bgp *bgp;
8381 int header2 = 1;
8383 bgp = peer->bgp;
8385 if (! bgp)
8386 return;
8388 table = bgp->rib[afi][safi];
8390 output_count = 0;
8392 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8393 PEER_STATUS_DEFAULT_ORIGINATE))
8395 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8396 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8397 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8399 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8400 VTY_NEWLINE, VTY_NEWLINE);
8401 header1 = 0;
8404 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8405 if (in)
8407 for (ain = rn->adj_in; ain; ain = ain->next)
8408 if (ain->peer == peer)
8410 if (header1)
8412 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8413 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8414 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8415 header1 = 0;
8417 if (header2)
8419 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8420 header2 = 0;
8422 if (ain->attr)
8424 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8425 output_count++;
8429 else
8431 for (adj = rn->adj_out; adj; adj = adj->next)
8432 if (adj->peer == peer)
8434 if (header1)
8436 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8437 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8438 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8439 header1 = 0;
8441 if (header2)
8443 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8444 header2 = 0;
8446 if (adj->attr)
8448 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8449 output_count++;
8454 if (output_count != 0)
8455 vty_out (vty, "%sTotal number of prefixes %ld%s",
8456 VTY_NEWLINE, output_count, VTY_NEWLINE);
8459 static int
8460 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8462 if (! peer || ! peer->afc[afi][safi])
8464 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8465 return CMD_WARNING;
8468 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8470 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8471 VTY_NEWLINE);
8472 return CMD_WARNING;
8475 show_adj_route (vty, peer, afi, safi, in);
8477 return CMD_SUCCESS;
8480 DEFUN (show_ip_bgp_neighbor_advertised_route,
8481 show_ip_bgp_neighbor_advertised_route_cmd,
8482 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8483 SHOW_STR
8484 IP_STR
8485 BGP_STR
8486 "Detailed information on TCP and BGP neighbor connections\n"
8487 "Neighbor to display information about\n"
8488 "Neighbor to display information about\n"
8489 "Display the routes advertised to a BGP neighbor\n")
8491 struct peer *peer;
8493 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8494 if (! peer)
8495 return CMD_WARNING;
8497 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
8500 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8501 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8502 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8503 SHOW_STR
8504 IP_STR
8505 BGP_STR
8506 "Address family\n"
8507 "Address Family modifier\n"
8508 "Address Family modifier\n"
8509 "Detailed information on TCP and BGP neighbor connections\n"
8510 "Neighbor to display information about\n"
8511 "Neighbor to display information about\n"
8512 "Display the routes advertised to a BGP neighbor\n")
8514 struct peer *peer;
8516 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8517 if (! peer)
8518 return CMD_WARNING;
8520 if (strncmp (argv[0], "m", 1) == 0)
8521 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8523 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
8526 #ifdef HAVE_IPV6
8527 DEFUN (show_bgp_view_neighbor_advertised_route,
8528 show_bgp_view_neighbor_advertised_route_cmd,
8529 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8530 SHOW_STR
8531 BGP_STR
8532 "BGP view\n"
8533 "View name\n"
8534 "Detailed information on TCP and BGP neighbor connections\n"
8535 "Neighbor to display information about\n"
8536 "Neighbor to display information about\n"
8537 "Display the routes advertised to a BGP neighbor\n")
8539 struct peer *peer;
8541 if (argc == 2)
8542 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8543 else
8544 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8546 if (! peer)
8547 return CMD_WARNING;
8549 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8552 ALIAS (show_bgp_view_neighbor_advertised_route,
8553 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8554 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8555 SHOW_STR
8556 BGP_STR
8557 "BGP view\n"
8558 "View name\n"
8559 "Address family\n"
8560 "Detailed information on TCP and BGP neighbor connections\n"
8561 "Neighbor to display information about\n"
8562 "Neighbor to display information about\n"
8563 "Display the routes advertised to a BGP neighbor\n")
8565 DEFUN (show_bgp_view_neighbor_received_routes,
8566 show_bgp_view_neighbor_received_routes_cmd,
8567 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8568 SHOW_STR
8569 BGP_STR
8570 "BGP view\n"
8571 "View name\n"
8572 "Detailed information on TCP and BGP neighbor connections\n"
8573 "Neighbor to display information about\n"
8574 "Neighbor to display information about\n"
8575 "Display the received routes from neighbor\n")
8577 struct peer *peer;
8579 if (argc == 2)
8580 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8581 else
8582 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8584 if (! peer)
8585 return CMD_WARNING;
8587 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8590 ALIAS (show_bgp_view_neighbor_received_routes,
8591 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8592 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8593 SHOW_STR
8594 BGP_STR
8595 "BGP view\n"
8596 "View name\n"
8597 "Address family\n"
8598 "Detailed information on TCP and BGP neighbor connections\n"
8599 "Neighbor to display information about\n"
8600 "Neighbor to display information about\n"
8601 "Display the received routes from neighbor\n")
8603 ALIAS (show_bgp_view_neighbor_advertised_route,
8604 show_bgp_neighbor_advertised_route_cmd,
8605 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8606 SHOW_STR
8607 BGP_STR
8608 "Detailed information on TCP and BGP neighbor connections\n"
8609 "Neighbor to display information about\n"
8610 "Neighbor to display information about\n"
8611 "Display the routes advertised to a BGP neighbor\n")
8613 ALIAS (show_bgp_view_neighbor_advertised_route,
8614 show_bgp_ipv6_neighbor_advertised_route_cmd,
8615 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8616 SHOW_STR
8617 BGP_STR
8618 "Address family\n"
8619 "Detailed information on TCP and BGP neighbor connections\n"
8620 "Neighbor to display information about\n"
8621 "Neighbor to display information about\n"
8622 "Display the routes advertised to a BGP neighbor\n")
8624 /* old command */
8625 ALIAS (show_bgp_view_neighbor_advertised_route,
8626 ipv6_bgp_neighbor_advertised_route_cmd,
8627 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8628 SHOW_STR
8629 IPV6_STR
8630 BGP_STR
8631 "Detailed information on TCP and BGP neighbor connections\n"
8632 "Neighbor to display information about\n"
8633 "Neighbor to display information about\n"
8634 "Display the routes advertised to a BGP neighbor\n")
8636 /* old command */
8637 DEFUN (ipv6_mbgp_neighbor_advertised_route,
8638 ipv6_mbgp_neighbor_advertised_route_cmd,
8639 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8640 SHOW_STR
8641 IPV6_STR
8642 MBGP_STR
8643 "Detailed information on TCP and BGP neighbor connections\n"
8644 "Neighbor to display information about\n"
8645 "Neighbor to display information about\n"
8646 "Display the routes advertised to a BGP neighbor\n")
8648 struct peer *peer;
8650 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8651 if (! peer)
8652 return CMD_WARNING;
8654 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
8656 #endif /* HAVE_IPV6 */
8658 DEFUN (show_ip_bgp_neighbor_received_routes,
8659 show_ip_bgp_neighbor_received_routes_cmd,
8660 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8661 SHOW_STR
8662 IP_STR
8663 BGP_STR
8664 "Detailed information on TCP and BGP neighbor connections\n"
8665 "Neighbor to display information about\n"
8666 "Neighbor to display information about\n"
8667 "Display the received routes from neighbor\n")
8669 struct peer *peer;
8671 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8672 if (! peer)
8673 return CMD_WARNING;
8675 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
8678 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
8679 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8680 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8681 SHOW_STR
8682 IP_STR
8683 BGP_STR
8684 "Address family\n"
8685 "Address Family modifier\n"
8686 "Address Family modifier\n"
8687 "Detailed information on TCP and BGP neighbor connections\n"
8688 "Neighbor to display information about\n"
8689 "Neighbor to display information about\n"
8690 "Display the received routes from neighbor\n")
8692 struct peer *peer;
8694 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8695 if (! peer)
8696 return CMD_WARNING;
8698 if (strncmp (argv[0], "m", 1) == 0)
8699 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8701 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
8704 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8705 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8706 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8707 SHOW_STR
8708 IP_STR
8709 BGP_STR
8710 "Detailed information on TCP and BGP neighbor connections\n"
8711 "Neighbor to display information about\n"
8712 "Neighbor to display information about\n"
8713 "Display information received from a BGP neighbor\n"
8714 "Display the prefixlist filter\n")
8716 char name[BUFSIZ];
8717 union sockunion *su;
8718 struct peer *peer;
8719 int count;
8721 su = sockunion_str2su (argv[0]);
8722 if (su == NULL)
8723 return CMD_WARNING;
8725 peer = peer_lookup (NULL, su);
8726 if (! peer)
8727 return CMD_WARNING;
8729 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8730 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8731 if (count)
8733 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8734 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8737 return CMD_SUCCESS;
8740 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8741 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8742 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8743 SHOW_STR
8744 IP_STR
8745 BGP_STR
8746 "Address family\n"
8747 "Address Family modifier\n"
8748 "Address Family modifier\n"
8749 "Detailed information on TCP and BGP neighbor connections\n"
8750 "Neighbor to display information about\n"
8751 "Neighbor to display information about\n"
8752 "Display information received from a BGP neighbor\n"
8753 "Display the prefixlist filter\n")
8755 char name[BUFSIZ];
8756 union sockunion *su;
8757 struct peer *peer;
8758 int count;
8760 su = sockunion_str2su (argv[1]);
8761 if (su == NULL)
8762 return CMD_WARNING;
8764 peer = peer_lookup (NULL, su);
8765 if (! peer)
8766 return CMD_WARNING;
8768 if (strncmp (argv[0], "m", 1) == 0)
8770 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
8771 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8772 if (count)
8774 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
8775 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8778 else
8780 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8781 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8782 if (count)
8784 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8785 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8789 return CMD_SUCCESS;
8793 #ifdef HAVE_IPV6
8794 ALIAS (show_bgp_view_neighbor_received_routes,
8795 show_bgp_neighbor_received_routes_cmd,
8796 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8797 SHOW_STR
8798 BGP_STR
8799 "Detailed information on TCP and BGP neighbor connections\n"
8800 "Neighbor to display information about\n"
8801 "Neighbor to display information about\n"
8802 "Display the received routes from neighbor\n")
8804 ALIAS (show_bgp_view_neighbor_received_routes,
8805 show_bgp_ipv6_neighbor_received_routes_cmd,
8806 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8807 SHOW_STR
8808 BGP_STR
8809 "Address family\n"
8810 "Detailed information on TCP and BGP neighbor connections\n"
8811 "Neighbor to display information about\n"
8812 "Neighbor to display information about\n"
8813 "Display the received routes from neighbor\n")
8815 DEFUN (show_bgp_neighbor_received_prefix_filter,
8816 show_bgp_neighbor_received_prefix_filter_cmd,
8817 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8818 SHOW_STR
8819 BGP_STR
8820 "Detailed information on TCP and BGP neighbor connections\n"
8821 "Neighbor to display information about\n"
8822 "Neighbor to display information about\n"
8823 "Display information received from a BGP neighbor\n"
8824 "Display the prefixlist filter\n")
8826 char name[BUFSIZ];
8827 union sockunion *su;
8828 struct peer *peer;
8829 int count;
8831 su = sockunion_str2su (argv[0]);
8832 if (su == NULL)
8833 return CMD_WARNING;
8835 peer = peer_lookup (NULL, su);
8836 if (! peer)
8837 return CMD_WARNING;
8839 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8840 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8841 if (count)
8843 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8844 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8847 return CMD_SUCCESS;
8850 ALIAS (show_bgp_neighbor_received_prefix_filter,
8851 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
8852 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8853 SHOW_STR
8854 BGP_STR
8855 "Address family\n"
8856 "Detailed information on TCP and BGP neighbor connections\n"
8857 "Neighbor to display information about\n"
8858 "Neighbor to display information about\n"
8859 "Display information received from a BGP neighbor\n"
8860 "Display the prefixlist filter\n")
8862 /* old command */
8863 ALIAS (show_bgp_view_neighbor_received_routes,
8864 ipv6_bgp_neighbor_received_routes_cmd,
8865 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8866 SHOW_STR
8867 IPV6_STR
8868 BGP_STR
8869 "Detailed information on TCP and BGP neighbor connections\n"
8870 "Neighbor to display information about\n"
8871 "Neighbor to display information about\n"
8872 "Display the received routes from neighbor\n")
8874 /* old command */
8875 DEFUN (ipv6_mbgp_neighbor_received_routes,
8876 ipv6_mbgp_neighbor_received_routes_cmd,
8877 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8878 SHOW_STR
8879 IPV6_STR
8880 MBGP_STR
8881 "Detailed information on TCP and BGP neighbor connections\n"
8882 "Neighbor to display information about\n"
8883 "Neighbor to display information about\n"
8884 "Display the received routes from neighbor\n")
8886 struct peer *peer;
8888 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8889 if (! peer)
8890 return CMD_WARNING;
8892 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
8895 DEFUN (show_bgp_view_neighbor_received_prefix_filter,
8896 show_bgp_view_neighbor_received_prefix_filter_cmd,
8897 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8898 SHOW_STR
8899 BGP_STR
8900 "BGP view\n"
8901 "View name\n"
8902 "Detailed information on TCP and BGP neighbor connections\n"
8903 "Neighbor to display information about\n"
8904 "Neighbor to display information about\n"
8905 "Display information received from a BGP neighbor\n"
8906 "Display the prefixlist filter\n")
8908 char name[BUFSIZ];
8909 union sockunion *su;
8910 struct peer *peer;
8911 struct bgp *bgp;
8912 int count;
8914 /* BGP structure lookup. */
8915 bgp = bgp_lookup_by_name (argv[0]);
8916 if (bgp == NULL)
8918 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8919 return CMD_WARNING;
8922 su = sockunion_str2su (argv[1]);
8923 if (su == NULL)
8924 return CMD_WARNING;
8926 peer = peer_lookup (bgp, su);
8927 if (! peer)
8928 return CMD_WARNING;
8930 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8931 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8932 if (count)
8934 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8935 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8938 return CMD_SUCCESS;
8941 ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8942 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8943 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8944 SHOW_STR
8945 BGP_STR
8946 "BGP view\n"
8947 "View name\n"
8948 "Address family\n"
8949 "Detailed information on TCP and BGP neighbor connections\n"
8950 "Neighbor to display information about\n"
8951 "Neighbor to display information about\n"
8952 "Display information received from a BGP neighbor\n"
8953 "Display the prefixlist filter\n")
8954 #endif /* HAVE_IPV6 */
8956 static int
8957 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
8958 safi_t safi, enum bgp_show_type type)
8960 if (! peer || ! peer->afc[afi][safi])
8962 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8963 return CMD_WARNING;
8966 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
8969 DEFUN (show_ip_bgp_neighbor_routes,
8970 show_ip_bgp_neighbor_routes_cmd,
8971 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8972 SHOW_STR
8973 IP_STR
8974 BGP_STR
8975 "Detailed information on TCP and BGP neighbor connections\n"
8976 "Neighbor to display information about\n"
8977 "Neighbor to display information about\n"
8978 "Display routes learned from neighbor\n")
8980 struct peer *peer;
8982 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8983 if (! peer)
8984 return CMD_WARNING;
8986 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
8987 bgp_show_type_neighbor);
8990 DEFUN (show_ip_bgp_neighbor_flap,
8991 show_ip_bgp_neighbor_flap_cmd,
8992 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8993 SHOW_STR
8994 IP_STR
8995 BGP_STR
8996 "Detailed information on TCP and BGP neighbor connections\n"
8997 "Neighbor to display information about\n"
8998 "Neighbor to display information about\n"
8999 "Display flap statistics of the routes learned from neighbor\n")
9001 struct peer *peer;
9003 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9004 if (! peer)
9005 return CMD_WARNING;
9007 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
9008 bgp_show_type_flap_neighbor);
9011 DEFUN (show_ip_bgp_neighbor_damp,
9012 show_ip_bgp_neighbor_damp_cmd,
9013 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9014 SHOW_STR
9015 IP_STR
9016 BGP_STR
9017 "Detailed information on TCP and BGP neighbor connections\n"
9018 "Neighbor to display information about\n"
9019 "Neighbor to display information about\n"
9020 "Display the dampened routes received from neighbor\n")
9022 struct peer *peer;
9024 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9025 if (! peer)
9026 return CMD_WARNING;
9028 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
9029 bgp_show_type_damp_neighbor);
9032 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9033 show_ip_bgp_ipv4_neighbor_routes_cmd,
9034 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9035 SHOW_STR
9036 IP_STR
9037 BGP_STR
9038 "Address family\n"
9039 "Address Family modifier\n"
9040 "Address Family modifier\n"
9041 "Detailed information on TCP and BGP neighbor connections\n"
9042 "Neighbor to display information about\n"
9043 "Neighbor to display information about\n"
9044 "Display routes learned from neighbor\n")
9046 struct peer *peer;
9048 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9049 if (! peer)
9050 return CMD_WARNING;
9052 if (strncmp (argv[0], "m", 1) == 0)
9053 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
9054 bgp_show_type_neighbor);
9056 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
9057 bgp_show_type_neighbor);
9060 DEFUN (show_ip_bgp_view_rsclient,
9061 show_ip_bgp_view_rsclient_cmd,
9062 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9063 SHOW_STR
9064 IP_STR
9065 BGP_STR
9066 "BGP view\n"
9067 "BGP view name\n"
9068 "Information about Route Server Client\n"
9069 NEIGHBOR_ADDR_STR)
9071 struct bgp_table *table;
9072 struct peer *peer;
9074 if (argc == 2)
9075 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9076 else
9077 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9079 if (! peer)
9080 return CMD_WARNING;
9082 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9084 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9085 VTY_NEWLINE);
9086 return CMD_WARNING;
9089 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9090 PEER_FLAG_RSERVER_CLIENT))
9092 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9093 VTY_NEWLINE);
9094 return CMD_WARNING;
9097 table = peer->rib[AFI_IP][SAFI_UNICAST];
9099 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
9102 ALIAS (show_ip_bgp_view_rsclient,
9103 show_ip_bgp_rsclient_cmd,
9104 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9105 SHOW_STR
9106 IP_STR
9107 BGP_STR
9108 "Information about Route Server Client\n"
9109 NEIGHBOR_ADDR_STR)
9111 DEFUN (show_ip_bgp_view_rsclient_route,
9112 show_ip_bgp_view_rsclient_route_cmd,
9113 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9114 SHOW_STR
9115 IP_STR
9116 BGP_STR
9117 "BGP view\n"
9118 "BGP view name\n"
9119 "Information about Route Server Client\n"
9120 NEIGHBOR_ADDR_STR
9121 "Network in the BGP routing table to display\n")
9123 struct bgp *bgp;
9124 struct peer *peer;
9126 /* BGP structure lookup. */
9127 if (argc == 3)
9129 bgp = bgp_lookup_by_name (argv[0]);
9130 if (bgp == NULL)
9132 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9133 return CMD_WARNING;
9136 else
9138 bgp = bgp_get_default ();
9139 if (bgp == NULL)
9141 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9142 return CMD_WARNING;
9146 if (argc == 3)
9147 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9148 else
9149 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9151 if (! peer)
9152 return CMD_WARNING;
9154 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9156 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9157 VTY_NEWLINE);
9158 return CMD_WARNING;
9161 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9162 PEER_FLAG_RSERVER_CLIENT))
9164 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9165 VTY_NEWLINE);
9166 return CMD_WARNING;
9169 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9170 (argc == 3) ? argv[2] : argv[1],
9171 AFI_IP, SAFI_UNICAST, NULL, 0);
9174 ALIAS (show_ip_bgp_view_rsclient_route,
9175 show_ip_bgp_rsclient_route_cmd,
9176 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9177 SHOW_STR
9178 IP_STR
9179 BGP_STR
9180 "Information about Route Server Client\n"
9181 NEIGHBOR_ADDR_STR
9182 "Network in the BGP routing table to display\n")
9184 DEFUN (show_ip_bgp_view_rsclient_prefix,
9185 show_ip_bgp_view_rsclient_prefix_cmd,
9186 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9187 SHOW_STR
9188 IP_STR
9189 BGP_STR
9190 "BGP view\n"
9191 "BGP view name\n"
9192 "Information about Route Server Client\n"
9193 NEIGHBOR_ADDR_STR
9194 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9196 struct bgp *bgp;
9197 struct peer *peer;
9199 /* BGP structure lookup. */
9200 if (argc == 3)
9202 bgp = bgp_lookup_by_name (argv[0]);
9203 if (bgp == NULL)
9205 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9206 return CMD_WARNING;
9209 else
9211 bgp = bgp_get_default ();
9212 if (bgp == NULL)
9214 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9215 return CMD_WARNING;
9219 if (argc == 3)
9220 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9221 else
9222 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9224 if (! peer)
9225 return CMD_WARNING;
9227 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9229 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9230 VTY_NEWLINE);
9231 return CMD_WARNING;
9234 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9235 PEER_FLAG_RSERVER_CLIENT))
9237 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9238 VTY_NEWLINE);
9239 return CMD_WARNING;
9242 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9243 (argc == 3) ? argv[2] : argv[1],
9244 AFI_IP, SAFI_UNICAST, NULL, 1);
9247 ALIAS (show_ip_bgp_view_rsclient_prefix,
9248 show_ip_bgp_rsclient_prefix_cmd,
9249 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9250 SHOW_STR
9251 IP_STR
9252 BGP_STR
9253 "Information about Route Server Client\n"
9254 NEIGHBOR_ADDR_STR
9255 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9258 #ifdef HAVE_IPV6
9259 DEFUN (show_bgp_view_neighbor_routes,
9260 show_bgp_view_neighbor_routes_cmd,
9261 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9262 SHOW_STR
9263 BGP_STR
9264 "BGP view\n"
9265 "BGP view name\n"
9266 "Detailed information on TCP and BGP neighbor connections\n"
9267 "Neighbor to display information about\n"
9268 "Neighbor to display information about\n"
9269 "Display routes learned from neighbor\n")
9271 struct peer *peer;
9273 if (argc == 2)
9274 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9275 else
9276 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9278 if (! peer)
9279 return CMD_WARNING;
9281 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9282 bgp_show_type_neighbor);
9285 ALIAS (show_bgp_view_neighbor_routes,
9286 show_bgp_view_ipv6_neighbor_routes_cmd,
9287 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9288 SHOW_STR
9289 BGP_STR
9290 "BGP view\n"
9291 "BGP view name\n"
9292 "Address family\n"
9293 "Detailed information on TCP and BGP neighbor connections\n"
9294 "Neighbor to display information about\n"
9295 "Neighbor to display information about\n"
9296 "Display routes learned from neighbor\n")
9298 DEFUN (show_bgp_view_neighbor_damp,
9299 show_bgp_view_neighbor_damp_cmd,
9300 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9301 SHOW_STR
9302 BGP_STR
9303 "BGP view\n"
9304 "BGP view name\n"
9305 "Detailed information on TCP and BGP neighbor connections\n"
9306 "Neighbor to display information about\n"
9307 "Neighbor to display information about\n"
9308 "Display the dampened routes received from neighbor\n")
9310 struct peer *peer;
9312 if (argc == 2)
9313 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9314 else
9315 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9317 if (! peer)
9318 return CMD_WARNING;
9320 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9321 bgp_show_type_damp_neighbor);
9324 ALIAS (show_bgp_view_neighbor_damp,
9325 show_bgp_view_ipv6_neighbor_damp_cmd,
9326 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9327 SHOW_STR
9328 BGP_STR
9329 "BGP view\n"
9330 "BGP view name\n"
9331 "Address family\n"
9332 "Detailed information on TCP and BGP neighbor connections\n"
9333 "Neighbor to display information about\n"
9334 "Neighbor to display information about\n"
9335 "Display the dampened routes received from neighbor\n")
9337 DEFUN (show_bgp_view_neighbor_flap,
9338 show_bgp_view_neighbor_flap_cmd,
9339 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9340 SHOW_STR
9341 BGP_STR
9342 "BGP view\n"
9343 "BGP view name\n"
9344 "Detailed information on TCP and BGP neighbor connections\n"
9345 "Neighbor to display information about\n"
9346 "Neighbor to display information about\n"
9347 "Display flap statistics of the routes learned from neighbor\n")
9349 struct peer *peer;
9351 if (argc == 2)
9352 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9353 else
9354 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9356 if (! peer)
9357 return CMD_WARNING;
9359 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9360 bgp_show_type_flap_neighbor);
9363 ALIAS (show_bgp_view_neighbor_flap,
9364 show_bgp_view_ipv6_neighbor_flap_cmd,
9365 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9366 SHOW_STR
9367 BGP_STR
9368 "BGP view\n"
9369 "BGP view name\n"
9370 "Address family\n"
9371 "Detailed information on TCP and BGP neighbor connections\n"
9372 "Neighbor to display information about\n"
9373 "Neighbor to display information about\n"
9374 "Display flap statistics of the routes learned from neighbor\n")
9376 ALIAS (show_bgp_view_neighbor_routes,
9377 show_bgp_neighbor_routes_cmd,
9378 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9379 SHOW_STR
9380 BGP_STR
9381 "Detailed information on TCP and BGP neighbor connections\n"
9382 "Neighbor to display information about\n"
9383 "Neighbor to display information about\n"
9384 "Display routes learned from neighbor\n")
9387 ALIAS (show_bgp_view_neighbor_routes,
9388 show_bgp_ipv6_neighbor_routes_cmd,
9389 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9390 SHOW_STR
9391 BGP_STR
9392 "Address family\n"
9393 "Detailed information on TCP and BGP neighbor connections\n"
9394 "Neighbor to display information about\n"
9395 "Neighbor to display information about\n"
9396 "Display routes learned from neighbor\n")
9398 /* old command */
9399 ALIAS (show_bgp_view_neighbor_routes,
9400 ipv6_bgp_neighbor_routes_cmd,
9401 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9402 SHOW_STR
9403 IPV6_STR
9404 BGP_STR
9405 "Detailed information on TCP and BGP neighbor connections\n"
9406 "Neighbor to display information about\n"
9407 "Neighbor to display information about\n"
9408 "Display routes learned from neighbor\n")
9410 /* old command */
9411 DEFUN (ipv6_mbgp_neighbor_routes,
9412 ipv6_mbgp_neighbor_routes_cmd,
9413 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9414 SHOW_STR
9415 IPV6_STR
9416 MBGP_STR
9417 "Detailed information on TCP and BGP neighbor connections\n"
9418 "Neighbor to display information about\n"
9419 "Neighbor to display information about\n"
9420 "Display routes learned from neighbor\n")
9422 struct peer *peer;
9424 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9425 if (! peer)
9426 return CMD_WARNING;
9428 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
9429 bgp_show_type_neighbor);
9432 ALIAS (show_bgp_view_neighbor_flap,
9433 show_bgp_neighbor_flap_cmd,
9434 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9435 SHOW_STR
9436 BGP_STR
9437 "Detailed information on TCP and BGP neighbor connections\n"
9438 "Neighbor to display information about\n"
9439 "Neighbor to display information about\n"
9440 "Display flap statistics of the routes learned from neighbor\n")
9442 ALIAS (show_bgp_view_neighbor_flap,
9443 show_bgp_ipv6_neighbor_flap_cmd,
9444 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9445 SHOW_STR
9446 BGP_STR
9447 "Address family\n"
9448 "Detailed information on TCP and BGP neighbor connections\n"
9449 "Neighbor to display information about\n"
9450 "Neighbor to display information about\n"
9451 "Display flap statistics of the routes learned from neighbor\n")
9453 ALIAS (show_bgp_view_neighbor_damp,
9454 show_bgp_neighbor_damp_cmd,
9455 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9456 SHOW_STR
9457 BGP_STR
9458 "Detailed information on TCP and BGP neighbor connections\n"
9459 "Neighbor to display information about\n"
9460 "Neighbor to display information about\n"
9461 "Display the dampened routes received from neighbor\n")
9463 ALIAS (show_bgp_view_neighbor_damp,
9464 show_bgp_ipv6_neighbor_damp_cmd,
9465 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9466 SHOW_STR
9467 BGP_STR
9468 "Address family\n"
9469 "Detailed information on TCP and BGP neighbor connections\n"
9470 "Neighbor to display information about\n"
9471 "Neighbor to display information about\n"
9472 "Display the dampened routes received from neighbor\n")
9474 DEFUN (show_bgp_view_rsclient,
9475 show_bgp_view_rsclient_cmd,
9476 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9477 SHOW_STR
9478 BGP_STR
9479 "BGP view\n"
9480 "BGP view name\n"
9481 "Information about Route Server Client\n"
9482 NEIGHBOR_ADDR_STR)
9484 struct bgp_table *table;
9485 struct peer *peer;
9487 if (argc == 2)
9488 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9489 else
9490 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9492 if (! peer)
9493 return CMD_WARNING;
9495 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9497 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9498 VTY_NEWLINE);
9499 return CMD_WARNING;
9502 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9503 PEER_FLAG_RSERVER_CLIENT))
9505 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9506 VTY_NEWLINE);
9507 return CMD_WARNING;
9510 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9512 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
9515 ALIAS (show_bgp_view_rsclient,
9516 show_bgp_rsclient_cmd,
9517 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9518 SHOW_STR
9519 BGP_STR
9520 "Information about Route Server Client\n"
9521 NEIGHBOR_ADDR_STR)
9523 DEFUN (show_bgp_view_rsclient_route,
9524 show_bgp_view_rsclient_route_cmd,
9525 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9526 SHOW_STR
9527 BGP_STR
9528 "BGP view\n"
9529 "BGP view name\n"
9530 "Information about Route Server Client\n"
9531 NEIGHBOR_ADDR_STR
9532 "Network in the BGP routing table to display\n")
9534 struct bgp *bgp;
9535 struct peer *peer;
9537 /* BGP structure lookup. */
9538 if (argc == 3)
9540 bgp = bgp_lookup_by_name (argv[0]);
9541 if (bgp == NULL)
9543 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9544 return CMD_WARNING;
9547 else
9549 bgp = bgp_get_default ();
9550 if (bgp == NULL)
9552 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9553 return CMD_WARNING;
9557 if (argc == 3)
9558 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9559 else
9560 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9562 if (! peer)
9563 return CMD_WARNING;
9565 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9567 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9568 VTY_NEWLINE);
9569 return CMD_WARNING;
9572 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9573 PEER_FLAG_RSERVER_CLIENT))
9575 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9576 VTY_NEWLINE);
9577 return CMD_WARNING;
9580 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9581 (argc == 3) ? argv[2] : argv[1],
9582 AFI_IP6, SAFI_UNICAST, NULL, 0);
9585 ALIAS (show_bgp_view_rsclient_route,
9586 show_bgp_rsclient_route_cmd,
9587 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9588 SHOW_STR
9589 BGP_STR
9590 "Information about Route Server Client\n"
9591 NEIGHBOR_ADDR_STR
9592 "Network in the BGP routing table to display\n")
9594 DEFUN (show_bgp_view_rsclient_prefix,
9595 show_bgp_view_rsclient_prefix_cmd,
9596 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9597 SHOW_STR
9598 BGP_STR
9599 "BGP view\n"
9600 "BGP view name\n"
9601 "Information about Route Server Client\n"
9602 NEIGHBOR_ADDR_STR
9603 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9605 struct bgp *bgp;
9606 struct peer *peer;
9608 /* BGP structure lookup. */
9609 if (argc == 3)
9611 bgp = bgp_lookup_by_name (argv[0]);
9612 if (bgp == NULL)
9614 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9615 return CMD_WARNING;
9618 else
9620 bgp = bgp_get_default ();
9621 if (bgp == NULL)
9623 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9624 return CMD_WARNING;
9628 if (argc == 3)
9629 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9630 else
9631 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9633 if (! peer)
9634 return CMD_WARNING;
9636 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9638 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9639 VTY_NEWLINE);
9640 return CMD_WARNING;
9643 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9644 PEER_FLAG_RSERVER_CLIENT))
9646 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9647 VTY_NEWLINE);
9648 return CMD_WARNING;
9651 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9652 (argc == 3) ? argv[2] : argv[1],
9653 AFI_IP6, SAFI_UNICAST, NULL, 1);
9656 ALIAS (show_bgp_view_rsclient_prefix,
9657 show_bgp_rsclient_prefix_cmd,
9658 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9659 SHOW_STR
9660 BGP_STR
9661 "Information about Route Server Client\n"
9662 NEIGHBOR_ADDR_STR
9663 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9665 #endif /* HAVE_IPV6 */
9667 struct bgp_table *bgp_distance_table;
9669 struct bgp_distance
9671 /* Distance value for the IP source prefix. */
9672 u_char distance;
9674 /* Name of the access-list to be matched. */
9675 char *access_list;
9678 static struct bgp_distance *
9679 bgp_distance_new ()
9681 struct bgp_distance *new;
9682 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9683 memset (new, 0, sizeof (struct bgp_distance));
9684 return new;
9687 static void
9688 bgp_distance_free (struct bgp_distance *bdistance)
9690 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9693 static int
9694 bgp_distance_set (struct vty *vty, const char *distance_str,
9695 const char *ip_str, const char *access_list_str)
9697 int ret;
9698 struct prefix_ipv4 p;
9699 u_char distance;
9700 struct bgp_node *rn;
9701 struct bgp_distance *bdistance;
9703 ret = str2prefix_ipv4 (ip_str, &p);
9704 if (ret == 0)
9706 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9707 return CMD_WARNING;
9710 distance = atoi (distance_str);
9712 /* Get BGP distance node. */
9713 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9714 if (rn->info)
9716 bdistance = rn->info;
9717 bgp_unlock_node (rn);
9719 else
9721 bdistance = bgp_distance_new ();
9722 rn->info = bdistance;
9725 /* Set distance value. */
9726 bdistance->distance = distance;
9728 /* Reset access-list configuration. */
9729 if (bdistance->access_list)
9731 free (bdistance->access_list);
9732 bdistance->access_list = NULL;
9734 if (access_list_str)
9735 bdistance->access_list = strdup (access_list_str);
9737 return CMD_SUCCESS;
9740 static int
9741 bgp_distance_unset (struct vty *vty, const char *distance_str,
9742 const char *ip_str, const char *access_list_str)
9744 int ret;
9745 struct prefix_ipv4 p;
9746 u_char distance;
9747 struct bgp_node *rn;
9748 struct bgp_distance *bdistance;
9750 ret = str2prefix_ipv4 (ip_str, &p);
9751 if (ret == 0)
9753 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9754 return CMD_WARNING;
9757 distance = atoi (distance_str);
9759 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9760 if (! rn)
9762 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9763 return CMD_WARNING;
9766 bdistance = rn->info;
9768 if (bdistance->access_list)
9769 free (bdistance->access_list);
9770 bgp_distance_free (bdistance);
9772 rn->info = NULL;
9773 bgp_unlock_node (rn);
9774 bgp_unlock_node (rn);
9776 return CMD_SUCCESS;
9779 static void
9780 bgp_distance_reset ()
9782 struct bgp_node *rn;
9783 struct bgp_distance *bdistance;
9785 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9786 if ((bdistance = rn->info) != NULL)
9788 if (bdistance->access_list)
9789 free (bdistance->access_list);
9790 bgp_distance_free (bdistance);
9791 rn->info = NULL;
9792 bgp_unlock_node (rn);
9796 /* Apply BGP information to distance method. */
9797 u_char
9798 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
9800 struct bgp_node *rn;
9801 struct prefix_ipv4 q;
9802 struct peer *peer;
9803 struct bgp_distance *bdistance;
9804 struct access_list *alist;
9805 struct bgp_static *bgp_static;
9807 if (! bgp)
9808 return 0;
9810 if (p->family != AF_INET)
9811 return 0;
9813 peer = rinfo->peer;
9815 if (peer->su.sa.sa_family != AF_INET)
9816 return 0;
9818 memset (&q, 0, sizeof (struct prefix_ipv4));
9819 q.family = AF_INET;
9820 q.prefix = peer->su.sin.sin_addr;
9821 q.prefixlen = IPV4_MAX_BITLEN;
9823 /* Check source address. */
9824 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
9825 if (rn)
9827 bdistance = rn->info;
9828 bgp_unlock_node (rn);
9830 if (bdistance->access_list)
9832 alist = access_list_lookup (AFI_IP, bdistance->access_list);
9833 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
9834 return bdistance->distance;
9836 else
9837 return bdistance->distance;
9840 /* Backdoor check. */
9841 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
9842 if (rn)
9844 bgp_static = rn->info;
9845 bgp_unlock_node (rn);
9847 if (bgp_static->backdoor)
9849 if (bgp->distance_local)
9850 return bgp->distance_local;
9851 else
9852 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9856 if (peer_sort (peer) == BGP_PEER_EBGP)
9858 if (bgp->distance_ebgp)
9859 return bgp->distance_ebgp;
9860 return ZEBRA_EBGP_DISTANCE_DEFAULT;
9862 else
9864 if (bgp->distance_ibgp)
9865 return bgp->distance_ibgp;
9866 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9870 DEFUN (bgp_distance,
9871 bgp_distance_cmd,
9872 "distance bgp <1-255> <1-255> <1-255>",
9873 "Define an administrative distance\n"
9874 "BGP distance\n"
9875 "Distance for routes external to the AS\n"
9876 "Distance for routes internal to the AS\n"
9877 "Distance for local routes\n")
9879 struct bgp *bgp;
9881 bgp = vty->index;
9883 bgp->distance_ebgp = atoi (argv[0]);
9884 bgp->distance_ibgp = atoi (argv[1]);
9885 bgp->distance_local = atoi (argv[2]);
9886 return CMD_SUCCESS;
9889 DEFUN (no_bgp_distance,
9890 no_bgp_distance_cmd,
9891 "no distance bgp <1-255> <1-255> <1-255>",
9892 NO_STR
9893 "Define an administrative distance\n"
9894 "BGP distance\n"
9895 "Distance for routes external to the AS\n"
9896 "Distance for routes internal to the AS\n"
9897 "Distance for local routes\n")
9899 struct bgp *bgp;
9901 bgp = vty->index;
9903 bgp->distance_ebgp= 0;
9904 bgp->distance_ibgp = 0;
9905 bgp->distance_local = 0;
9906 return CMD_SUCCESS;
9909 ALIAS (no_bgp_distance,
9910 no_bgp_distance2_cmd,
9911 "no distance bgp",
9912 NO_STR
9913 "Define an administrative distance\n"
9914 "BGP distance\n")
9916 DEFUN (bgp_distance_source,
9917 bgp_distance_source_cmd,
9918 "distance <1-255> A.B.C.D/M",
9919 "Define an administrative distance\n"
9920 "Administrative distance\n"
9921 "IP source prefix\n")
9923 bgp_distance_set (vty, argv[0], argv[1], NULL);
9924 return CMD_SUCCESS;
9927 DEFUN (no_bgp_distance_source,
9928 no_bgp_distance_source_cmd,
9929 "no distance <1-255> A.B.C.D/M",
9930 NO_STR
9931 "Define an administrative distance\n"
9932 "Administrative distance\n"
9933 "IP source prefix\n")
9935 bgp_distance_unset (vty, argv[0], argv[1], NULL);
9936 return CMD_SUCCESS;
9939 DEFUN (bgp_distance_source_access_list,
9940 bgp_distance_source_access_list_cmd,
9941 "distance <1-255> A.B.C.D/M WORD",
9942 "Define an administrative distance\n"
9943 "Administrative distance\n"
9944 "IP source prefix\n"
9945 "Access list name\n")
9947 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
9948 return CMD_SUCCESS;
9951 DEFUN (no_bgp_distance_source_access_list,
9952 no_bgp_distance_source_access_list_cmd,
9953 "no distance <1-255> A.B.C.D/M WORD",
9954 NO_STR
9955 "Define an administrative distance\n"
9956 "Administrative distance\n"
9957 "IP source prefix\n"
9958 "Access list name\n")
9960 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
9961 return CMD_SUCCESS;
9964 DEFUN (bgp_damp_set,
9965 bgp_damp_set_cmd,
9966 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9967 "BGP Specific commands\n"
9968 "Enable route-flap dampening\n"
9969 "Half-life time for the penalty\n"
9970 "Value to start reusing a route\n"
9971 "Value to start suppressing a route\n"
9972 "Maximum duration to suppress a stable route\n")
9974 struct bgp *bgp;
9975 int half = DEFAULT_HALF_LIFE * 60;
9976 int reuse = DEFAULT_REUSE;
9977 int suppress = DEFAULT_SUPPRESS;
9978 int max = 4 * half;
9980 if (argc == 4)
9982 half = atoi (argv[0]) * 60;
9983 reuse = atoi (argv[1]);
9984 suppress = atoi (argv[2]);
9985 max = atoi (argv[3]) * 60;
9987 else if (argc == 1)
9989 half = atoi (argv[0]) * 60;
9990 max = 4 * half;
9993 bgp = vty->index;
9994 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
9995 half, reuse, suppress, max);
9998 ALIAS (bgp_damp_set,
9999 bgp_damp_set2_cmd,
10000 "bgp dampening <1-45>",
10001 "BGP Specific commands\n"
10002 "Enable route-flap dampening\n"
10003 "Half-life time for the penalty\n")
10005 ALIAS (bgp_damp_set,
10006 bgp_damp_set3_cmd,
10007 "bgp dampening",
10008 "BGP Specific commands\n"
10009 "Enable route-flap dampening\n")
10011 DEFUN (bgp_damp_unset,
10012 bgp_damp_unset_cmd,
10013 "no bgp dampening",
10014 NO_STR
10015 "BGP Specific commands\n"
10016 "Enable route-flap dampening\n")
10018 struct bgp *bgp;
10020 bgp = vty->index;
10021 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10024 ALIAS (bgp_damp_unset,
10025 bgp_damp_unset2_cmd,
10026 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10027 NO_STR
10028 "BGP Specific commands\n"
10029 "Enable route-flap dampening\n"
10030 "Half-life time for the penalty\n"
10031 "Value to start reusing a route\n"
10032 "Value to start suppressing a route\n"
10033 "Maximum duration to suppress a stable route\n")
10035 DEFUN (show_ip_bgp_dampened_paths,
10036 show_ip_bgp_dampened_paths_cmd,
10037 "show ip bgp dampened-paths",
10038 SHOW_STR
10039 IP_STR
10040 BGP_STR
10041 "Display paths suppressed due to dampening\n")
10043 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10044 NULL);
10047 DEFUN (show_ip_bgp_flap_statistics,
10048 show_ip_bgp_flap_statistics_cmd,
10049 "show ip bgp flap-statistics",
10050 SHOW_STR
10051 IP_STR
10052 BGP_STR
10053 "Display flap statistics of routes\n")
10055 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10056 bgp_show_type_flap_statistics, NULL);
10059 /* Display specified route of BGP table. */
10060 static int
10061 bgp_clear_damp_route (struct vty *vty, const char *view_name,
10062 const char *ip_str, afi_t afi, safi_t safi,
10063 struct prefix_rd *prd, int prefix_check)
10065 int ret;
10066 struct prefix match;
10067 struct bgp_node *rn;
10068 struct bgp_node *rm;
10069 struct bgp_info *ri;
10070 struct bgp_info *ri_temp;
10071 struct bgp *bgp;
10072 struct bgp_table *table;
10074 /* BGP structure lookup. */
10075 if (view_name)
10077 bgp = bgp_lookup_by_name (view_name);
10078 if (bgp == NULL)
10080 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10081 return CMD_WARNING;
10084 else
10086 bgp = bgp_get_default ();
10087 if (bgp == NULL)
10089 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10090 return CMD_WARNING;
10094 /* Check IP address argument. */
10095 ret = str2prefix (ip_str, &match);
10096 if (! ret)
10098 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10099 return CMD_WARNING;
10102 match.family = afi2family (afi);
10104 if (safi == SAFI_MPLS_VPN)
10106 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10108 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10109 continue;
10111 if ((table = rn->info) != NULL)
10112 if ((rm = bgp_node_match (table, &match)) != NULL)
10113 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10115 ri = rm->info;
10116 while (ri)
10118 if (ri->damp_info)
10120 ri_temp = ri->next;
10121 bgp_damp_info_free (ri->damp_info, 1);
10122 ri = ri_temp;
10124 else
10125 ri = ri->next;
10130 else
10132 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10133 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10135 ri = rn->info;
10136 while (ri)
10138 if (ri->damp_info)
10140 ri_temp = ri->next;
10141 bgp_damp_info_free (ri->damp_info, 1);
10142 ri = ri_temp;
10144 else
10145 ri = ri->next;
10150 return CMD_SUCCESS;
10153 DEFUN (clear_ip_bgp_dampening,
10154 clear_ip_bgp_dampening_cmd,
10155 "clear ip bgp dampening",
10156 CLEAR_STR
10157 IP_STR
10158 BGP_STR
10159 "Clear route flap dampening information\n")
10161 bgp_damp_info_clean ();
10162 return CMD_SUCCESS;
10165 DEFUN (clear_ip_bgp_dampening_prefix,
10166 clear_ip_bgp_dampening_prefix_cmd,
10167 "clear ip bgp dampening A.B.C.D/M",
10168 CLEAR_STR
10169 IP_STR
10170 BGP_STR
10171 "Clear route flap dampening information\n"
10172 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10174 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10175 SAFI_UNICAST, NULL, 1);
10178 DEFUN (clear_ip_bgp_dampening_address,
10179 clear_ip_bgp_dampening_address_cmd,
10180 "clear ip bgp dampening A.B.C.D",
10181 CLEAR_STR
10182 IP_STR
10183 BGP_STR
10184 "Clear route flap dampening information\n"
10185 "Network to clear damping information\n")
10187 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10188 SAFI_UNICAST, NULL, 0);
10191 DEFUN (clear_ip_bgp_dampening_address_mask,
10192 clear_ip_bgp_dampening_address_mask_cmd,
10193 "clear ip bgp dampening A.B.C.D A.B.C.D",
10194 CLEAR_STR
10195 IP_STR
10196 BGP_STR
10197 "Clear route flap dampening information\n"
10198 "Network to clear damping information\n"
10199 "Network mask\n")
10201 int ret;
10202 char prefix_str[BUFSIZ];
10204 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10205 if (! ret)
10207 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10208 return CMD_WARNING;
10211 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10212 SAFI_UNICAST, NULL, 0);
10215 static int
10216 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10217 afi_t afi, safi_t safi, int *write)
10219 struct bgp_node *prn;
10220 struct bgp_node *rn;
10221 struct bgp_table *table;
10222 struct prefix *p;
10223 struct prefix_rd *prd;
10224 struct bgp_static *bgp_static;
10225 u_int32_t label;
10226 char buf[SU_ADDRSTRLEN];
10227 char rdbuf[RD_ADDRSTRLEN];
10229 /* Network configuration. */
10230 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10231 if ((table = prn->info) != NULL)
10232 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10233 if ((bgp_static = rn->info) != NULL)
10235 p = &rn->p;
10236 prd = (struct prefix_rd *) &prn->p;
10238 /* "address-family" display. */
10239 bgp_config_write_family_header (vty, afi, safi, write);
10241 /* "network" configuration display. */
10242 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10243 label = decode_label (bgp_static->tag);
10245 vty_out (vty, " network %s/%d rd %s tag %d",
10246 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10247 p->prefixlen,
10248 rdbuf, label);
10249 vty_out (vty, "%s", VTY_NEWLINE);
10251 return 0;
10254 /* Configuration of static route announcement and aggregate
10255 information. */
10257 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10258 afi_t afi, safi_t safi, int *write)
10260 struct bgp_node *rn;
10261 struct prefix *p;
10262 struct bgp_static *bgp_static;
10263 struct bgp_aggregate *bgp_aggregate;
10264 char buf[SU_ADDRSTRLEN];
10266 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10267 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10269 /* Network configuration. */
10270 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10271 if ((bgp_static = rn->info) != NULL)
10273 p = &rn->p;
10275 /* "address-family" display. */
10276 bgp_config_write_family_header (vty, afi, safi, write);
10278 /* "network" configuration display. */
10279 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10281 u_int32_t destination;
10282 struct in_addr netmask;
10284 destination = ntohl (p->u.prefix4.s_addr);
10285 masklen2ip (p->prefixlen, &netmask);
10286 vty_out (vty, " network %s",
10287 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10289 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10290 || (IN_CLASSB (destination) && p->prefixlen == 16)
10291 || (IN_CLASSA (destination) && p->prefixlen == 8)
10292 || p->u.prefix4.s_addr == 0)
10294 /* Natural mask is not display. */
10296 else
10297 vty_out (vty, " mask %s", inet_ntoa (netmask));
10299 else
10301 vty_out (vty, " network %s/%d",
10302 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10303 p->prefixlen);
10306 if (bgp_static->rmap.name)
10307 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10308 else if (bgp_static->backdoor)
10309 vty_out (vty, " backdoor");
10311 vty_out (vty, "%s", VTY_NEWLINE);
10314 /* Aggregate-address configuration. */
10315 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10316 if ((bgp_aggregate = rn->info) != NULL)
10318 p = &rn->p;
10320 /* "address-family" display. */
10321 bgp_config_write_family_header (vty, afi, safi, write);
10323 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10325 struct in_addr netmask;
10327 masklen2ip (p->prefixlen, &netmask);
10328 vty_out (vty, " aggregate-address %s %s",
10329 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10330 inet_ntoa (netmask));
10332 else
10334 vty_out (vty, " aggregate-address %s/%d",
10335 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10336 p->prefixlen);
10339 if (bgp_aggregate->as_set)
10340 vty_out (vty, " as-set");
10342 if (bgp_aggregate->summary_only)
10343 vty_out (vty, " summary-only");
10345 vty_out (vty, "%s", VTY_NEWLINE);
10348 return 0;
10352 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10354 struct bgp_node *rn;
10355 struct bgp_distance *bdistance;
10357 /* Distance configuration. */
10358 if (bgp->distance_ebgp
10359 && bgp->distance_ibgp
10360 && bgp->distance_local
10361 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10362 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10363 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10364 vty_out (vty, " distance bgp %d %d %d%s",
10365 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10366 VTY_NEWLINE);
10368 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10369 if ((bdistance = rn->info) != NULL)
10371 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10372 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10373 bdistance->access_list ? bdistance->access_list : "",
10374 VTY_NEWLINE);
10377 return 0;
10380 /* Allocate routing table structure and install commands. */
10381 void
10382 bgp_route_init ()
10384 /* Init BGP distance table. */
10385 bgp_distance_table = bgp_table_init ();
10387 /* IPv4 BGP commands. */
10388 install_element (BGP_NODE, &bgp_network_cmd);
10389 install_element (BGP_NODE, &bgp_network_mask_cmd);
10390 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10391 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10392 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10393 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10394 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10395 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10396 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10397 install_element (BGP_NODE, &no_bgp_network_cmd);
10398 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10399 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10400 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10401 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10402 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10403 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10404 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10405 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10407 install_element (BGP_NODE, &aggregate_address_cmd);
10408 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10409 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10410 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10411 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10412 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10413 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10414 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10415 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10416 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10417 install_element (BGP_NODE, &no_aggregate_address_cmd);
10418 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10419 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10420 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10421 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10422 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10423 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10424 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10425 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10426 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10428 /* IPv4 unicast configuration. */
10429 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10430 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10431 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10432 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10433 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10434 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10435 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10436 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10437 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10438 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10439 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10440 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10441 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10442 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10443 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10444 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10445 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10446 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10447 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10448 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10449 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10450 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10451 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10452 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10453 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10454 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10455 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10456 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10457 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10458 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10459 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10460 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10462 /* IPv4 multicast configuration. */
10463 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10464 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10465 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10466 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10467 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10468 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10469 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10470 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10471 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10472 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10473 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10474 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10475 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10476 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10477 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10478 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10479 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10480 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10481 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10482 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10483 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10484 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10485 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10486 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10487 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10488 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10489 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10490 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10493 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10494 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10496 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10497 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10498 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10499 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10500 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10501 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10502 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10504 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10505 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10506 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10507 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10508 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10509 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10511 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10512 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10513 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10514 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10515 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10516 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10517 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10518 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10519 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10520 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10521 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10522 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10523 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10524 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10526 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10527 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10528 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10529 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10530 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10531 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10532 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10533 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10535 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10536 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10537 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10539 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10540 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10541 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10542 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10543 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10545 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10546 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10547 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10548 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10549 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10550 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10551 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10552 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10553 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10554 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10555 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10556 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10557 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10558 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10559 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10560 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10561 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10562 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
10563 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10564 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10565 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10566 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10567 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10568 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
10570 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10571 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10572 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10573 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10574 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10575 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10576 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10577 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10578 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10579 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10580 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10581 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10582 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10583 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10584 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10585 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10586 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10587 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10588 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10589 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10590 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10591 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10592 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10593 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10594 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10595 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10596 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10597 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10598 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10599 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10600 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10601 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10602 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10603 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10604 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10605 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10606 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10607 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10608 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10609 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10610 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10611 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10613 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10614 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10615 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10616 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10617 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10618 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10619 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10620 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10621 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10622 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10623 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10624 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10625 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10626 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10627 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10628 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10629 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10630 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10631 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10632 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10633 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10634 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10635 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10636 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
10637 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10638 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10639 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10640 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10641 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10642 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
10644 /* BGP dampening clear commands */
10645 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10646 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10647 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10648 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10650 #ifdef HAVE_IPV6
10651 /* New config IPv6 BGP commands. */
10652 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10653 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10654 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10655 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10657 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10658 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10659 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10660 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10662 /* Old config IPv6 BGP commands. */
10663 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10664 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10666 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10667 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10668 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10669 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10671 install_element (VIEW_NODE, &show_bgp_cmd);
10672 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10673 install_element (VIEW_NODE, &show_bgp_route_cmd);
10674 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10675 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10676 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10677 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10678 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10679 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10680 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10681 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10682 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10683 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10684 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10685 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10686 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10687 install_element (VIEW_NODE, &show_bgp_community_cmd);
10688 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10689 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10690 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10691 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10692 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10693 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10694 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10695 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10696 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10697 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10698 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10699 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10700 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10701 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10702 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10703 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10704 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10705 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10706 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10707 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10708 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10709 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10710 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10711 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10712 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10713 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10714 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10715 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10716 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
10717 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10718 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10719 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10720 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
10721 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10722 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10723 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
10724 install_element (VIEW_NODE, &show_bgp_view_cmd);
10725 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10726 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10727 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10728 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10729 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10730 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10731 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10732 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10733 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10734 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10735 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10736 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10737 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10738 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10739 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10740 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10741 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
10742 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10743 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10744 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
10746 install_element (ENABLE_NODE, &show_bgp_cmd);
10747 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10748 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10749 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10750 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10751 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10752 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10753 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10754 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10755 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10756 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10757 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10758 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10759 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10760 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10761 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
10762 install_element (ENABLE_NODE, &show_bgp_community_cmd);
10763 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
10764 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
10765 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
10766 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
10767 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
10768 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
10769 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
10770 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
10771 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
10772 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
10773 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
10774 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
10775 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
10776 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
10777 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
10778 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
10779 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
10780 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
10781 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10782 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
10783 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10784 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
10785 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10786 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
10787 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10788 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
10789 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10790 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10791 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
10792 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
10793 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10794 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
10795 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
10796 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
10797 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
10798 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
10799 install_element (ENABLE_NODE, &show_bgp_view_cmd);
10800 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
10801 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
10802 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
10803 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
10804 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
10805 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10806 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10807 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10808 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10809 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
10810 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10811 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10812 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10813 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
10814 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10815 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
10816 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
10817 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
10818 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
10819 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
10821 /* old command */
10822 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
10823 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
10824 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
10825 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
10826 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
10827 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
10828 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
10829 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
10830 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
10831 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
10832 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
10833 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
10834 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
10835 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
10836 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
10837 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
10838 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10839 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10840 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
10841 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
10842 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
10843 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
10844 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10845 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
10846 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
10847 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
10848 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
10849 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
10850 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
10851 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
10852 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10853 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10854 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10855 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
10856 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10857 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10859 /* old command */
10860 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
10861 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
10862 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
10863 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
10864 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
10865 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
10866 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
10867 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
10868 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
10869 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
10870 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
10871 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
10872 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
10873 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
10874 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
10875 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
10876 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10877 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10878 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
10879 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
10880 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
10881 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
10882 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10883 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
10884 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
10885 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
10886 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
10887 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
10888 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
10889 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
10890 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10891 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10892 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10893 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
10894 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10895 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10897 /* old command */
10898 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10899 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10900 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10901 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10903 /* old command */
10904 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10905 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10906 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10907 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10909 /* old command */
10910 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
10911 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
10912 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10913 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10914 #endif /* HAVE_IPV6 */
10916 install_element (BGP_NODE, &bgp_distance_cmd);
10917 install_element (BGP_NODE, &no_bgp_distance_cmd);
10918 install_element (BGP_NODE, &no_bgp_distance2_cmd);
10919 install_element (BGP_NODE, &bgp_distance_source_cmd);
10920 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
10921 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
10922 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
10924 install_element (BGP_NODE, &bgp_damp_set_cmd);
10925 install_element (BGP_NODE, &bgp_damp_set2_cmd);
10926 install_element (BGP_NODE, &bgp_damp_set3_cmd);
10927 install_element (BGP_NODE, &bgp_damp_unset_cmd);
10928 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
10929 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
10930 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
10931 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
10932 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
10933 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);