[bgpd] Fix triggerable crash when compiled with --disable-bgp-announce
[jleu-quagga.git] / bgpd / bgp_route.c
blobb639db05c2c3f08b4753e7e79ae872f35021ef3c
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 assert (table);
70 if (!table)
71 return NULL;
73 if (safi == SAFI_MPLS_VPN)
75 prn = bgp_node_get (table, (struct prefix *) prd);
77 if (prn->info == NULL)
78 prn->info = bgp_table_init (afi, safi);
79 else
80 bgp_unlock_node (prn);
81 table = prn->info;
84 rn = bgp_node_get (table, p);
86 if (safi == SAFI_MPLS_VPN)
87 rn->prn = prn;
89 return rn;
92 /* Allocate bgp_info_extra */
93 static struct bgp_info_extra *
94 bgp_info_extra_new (void)
96 struct bgp_info_extra *new;
97 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
98 return new;
101 static void
102 bgp_info_extra_free (struct bgp_info_extra **extra)
104 if (extra && *extra)
106 if ((*extra)->damp_info)
107 bgp_damp_info_free ((*extra)->damp_info, 0);
109 (*extra)->damp_info = NULL;
111 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113 *extra = NULL;
117 /* Get bgp_info extra information for the given bgp_info, lazy allocated
118 * if required.
120 struct bgp_info_extra *
121 bgp_info_extra_get (struct bgp_info *ri)
123 if (!ri->extra)
124 ri->extra = bgp_info_extra_new();
125 return ri->extra;
128 /* Allocate new bgp info structure. */
129 static struct bgp_info *
130 bgp_info_new ()
132 struct bgp_info *new;
134 new = XMALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
135 memset (new, 0, sizeof (struct bgp_info));
137 return new;
140 /* Free bgp route information. */
141 static void
142 bgp_info_free (struct bgp_info *binfo)
144 if (binfo->attr)
145 bgp_attr_unintern (binfo->attr);
147 bgp_info_extra_free (&binfo->extra);
149 peer_unlock (binfo->peer); /* bgp_info peer reference */
151 XFREE (MTYPE_BGP_ROUTE, binfo);
154 struct bgp_info *
155 bgp_info_lock (struct bgp_info *binfo)
157 binfo->lock++;
158 return binfo;
161 struct bgp_info *
162 bgp_info_unlock (struct bgp_info *binfo)
164 assert (binfo && binfo->lock > 0);
165 binfo->lock--;
167 if (binfo->lock == 0)
169 #if 0
170 zlog_debug ("%s: unlocked and freeing", __func__);
171 zlog_backtrace (LOG_DEBUG);
172 #endif
173 bgp_info_free (binfo);
174 return NULL;
177 #if 0
178 if (binfo->lock == 1)
180 zlog_debug ("%s: unlocked to 1", __func__);
181 zlog_backtrace (LOG_DEBUG);
183 #endif
185 return binfo;
188 void
189 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
191 struct bgp_info *top;
193 top = rn->info;
195 ri->next = rn->info;
196 ri->prev = NULL;
197 if (top)
198 top->prev = ri;
199 rn->info = ri;
201 bgp_info_lock (ri);
202 bgp_lock_node (rn);
203 peer_lock (ri->peer); /* bgp_info peer reference */
206 /* Do the actual removal of info from RIB, for use by bgp_process
207 completion callback *only* */
208 static void
209 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
211 if (ri->next)
212 ri->next->prev = ri->prev;
213 if (ri->prev)
214 ri->prev->next = ri->next;
215 else
216 rn->info = ri->next;
218 bgp_info_unlock (ri);
219 bgp_unlock_node (rn);
222 void
223 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
225 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
226 /* set of previous already took care of pcount */
227 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
230 /* undo the effects of a previous call to bgp_info_delete; typically
231 called when a route is deleted and then quickly re-added before the
232 deletion has been processed */
233 static void
234 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
236 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
237 /* unset of previous already took care of pcount */
238 SET_FLAG (ri->flags, BGP_INFO_VALID);
241 /* Adjust pcount as required */
242 static void
243 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
245 assert (rn && rn->table);
246 assert (ri && ri->peer && ri->peer->bgp);
248 /* Ignore 'pcount' for RS-client tables */
249 if (rn->table->type != BGP_TABLE_MAIN
250 || ri->peer == ri->peer->bgp->peer_self)
251 return;
253 if (BGP_INFO_HOLDDOWN (ri)
254 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
257 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
259 /* slight hack, but more robust against errors. */
260 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
261 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
262 else
264 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
265 __func__, ri->peer->host);
266 zlog_backtrace (LOG_WARNING);
267 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
270 else if (!BGP_INFO_HOLDDOWN (ri)
271 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
273 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
274 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
279 /* Set/unset bgp_info flags, adjusting any other state as needed.
280 * This is here primarily to keep prefix-count in check.
282 void
283 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
285 SET_FLAG (ri->flags, flag);
287 /* early bath if we know it's not a flag that changes useability state */
288 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
289 return;
291 bgp_pcount_adjust (rn, ri);
294 void
295 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
297 UNSET_FLAG (ri->flags, flag);
299 /* early bath if we know it's not a flag that changes useability state */
300 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
301 return;
303 bgp_pcount_adjust (rn, ri);
306 /* Get MED value. If MED value is missing and "bgp bestpath
307 missing-as-worst" is specified, treat it as the worst value. */
308 static u_int32_t
309 bgp_med_value (struct attr *attr, struct bgp *bgp)
311 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
312 return attr->med;
313 else
315 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
316 return BGP_MED_MAX;
317 else
318 return 0;
322 /* Compare two bgp route entity. br is preferable then return 1. */
323 static int
324 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
326 u_int32_t new_pref;
327 u_int32_t exist_pref;
328 u_int32_t new_med;
329 u_int32_t exist_med;
330 u_int32_t new_weight = 0;
331 u_int32_t exist_weight = 0;
332 struct in_addr new_id;
333 struct in_addr exist_id;
334 int new_cluster;
335 int exist_cluster;
336 int internal_as_route = 0;
337 int confed_as_route = 0;
338 int ret;
340 /* 0. Null check. */
341 if (new == NULL)
342 return 0;
343 if (exist == NULL)
344 return 1;
346 /* 1. Weight check. */
347 if (new->attr->extra)
348 new_weight = new->attr->extra->weight;
349 if (exist->attr->extra)
350 exist_weight = exist->attr->extra->weight;
351 if (new_weight > exist_weight)
352 return 1;
353 if (new_weight < exist_weight)
354 return 0;
356 /* 2. Local preference check. */
357 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
358 new_pref = new->attr->local_pref;
359 else
360 new_pref = bgp->default_local_pref;
362 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
363 exist_pref = exist->attr->local_pref;
364 else
365 exist_pref = bgp->default_local_pref;
367 if (new_pref > exist_pref)
368 return 1;
369 if (new_pref < exist_pref)
370 return 0;
372 /* 3. Local route check. */
373 if (new->sub_type == BGP_ROUTE_STATIC)
374 return 1;
375 if (exist->sub_type == BGP_ROUTE_STATIC)
376 return 0;
378 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
379 return 1;
380 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
381 return 0;
383 if (new->sub_type == BGP_ROUTE_AGGREGATE)
384 return 1;
385 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
386 return 0;
388 /* 4. AS path length check. */
389 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
391 int exist_hops = aspath_count_hops (exist->attr->aspath);
392 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
394 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
396 int aspath_hops;
398 aspath_hops = aspath_count_hops (new->attr->aspath);
399 aspath_hops += aspath_count_confeds (new->attr->aspath);
401 if ( aspath_hops < (exist_hops + exist_confeds))
402 return 1;
403 if ( aspath_hops > (exist_hops + exist_confeds))
404 return 0;
406 else
408 int newhops = aspath_count_hops (new->attr->aspath);
410 if (newhops < exist_hops)
411 return 1;
412 if (newhops > exist_hops)
413 return 0;
417 /* 5. Origin check. */
418 if (new->attr->origin < exist->attr->origin)
419 return 1;
420 if (new->attr->origin > exist->attr->origin)
421 return 0;
423 /* 6. MED check. */
424 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
425 && aspath_count_hops (exist->attr->aspath) == 0);
426 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
427 && aspath_count_confeds (exist->attr->aspath) > 0
428 && aspath_count_hops (new->attr->aspath) == 0
429 && aspath_count_hops (exist->attr->aspath) == 0);
431 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
432 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
433 && confed_as_route)
434 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
435 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
436 || internal_as_route)
438 new_med = bgp_med_value (new->attr, bgp);
439 exist_med = bgp_med_value (exist->attr, bgp);
441 if (new_med < exist_med)
442 return 1;
443 if (new_med > exist_med)
444 return 0;
447 /* 7. Peer type check. */
448 if (peer_sort (new->peer) == BGP_PEER_EBGP
449 && peer_sort (exist->peer) == BGP_PEER_IBGP)
450 return 1;
451 if (peer_sort (new->peer) == BGP_PEER_EBGP
452 && peer_sort (exist->peer) == BGP_PEER_CONFED)
453 return 1;
454 if (peer_sort (new->peer) == BGP_PEER_IBGP
455 && peer_sort (exist->peer) == BGP_PEER_EBGP)
456 return 0;
457 if (peer_sort (new->peer) == BGP_PEER_CONFED
458 && peer_sort (exist->peer) == BGP_PEER_EBGP)
459 return 0;
461 /* 8. IGP metric check. */
462 if (new->extra || exist->extra)
464 uint32_t newm = (new->extra ? new->extra->igpmetric : 0);
465 uint32_t existm = (exist->extra ? exist->extra->igpmetric : 0);
467 if (newm < existm)
468 return 1;
469 if (newm > existm)
470 return 0;
473 /* 9. Maximum path check. */
475 /* 10. If both paths are external, prefer the path that was received
476 first (the oldest one). This step minimizes route-flap, since a
477 newer path won't displace an older one, even if it was the
478 preferred route based on the additional decision criteria below. */
479 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
480 && peer_sort (new->peer) == BGP_PEER_EBGP
481 && peer_sort (exist->peer) == BGP_PEER_EBGP)
483 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
484 return 1;
485 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
486 return 0;
489 /* 11. Rourter-ID comparision. */
490 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
491 new_id.s_addr = new->attr->extra->originator_id.s_addr;
492 else
493 new_id.s_addr = new->peer->remote_id.s_addr;
494 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
495 exist_id.s_addr = exist->attr->extra->originator_id.s_addr;
496 else
497 exist_id.s_addr = exist->peer->remote_id.s_addr;
499 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
500 return 1;
501 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
502 return 0;
504 /* 12. Cluster length comparision. */
505 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
506 new_cluster = new->attr->extra->cluster->length;
507 else
508 new_cluster = 0;
509 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
510 exist_cluster = exist->attr->extra->cluster->length;
511 else
512 exist_cluster = 0;
514 if (new_cluster < exist_cluster)
515 return 1;
516 if (new_cluster > exist_cluster)
517 return 0;
519 /* 13. Neighbor address comparision. */
520 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
522 if (ret == 1)
523 return 0;
524 if (ret == -1)
525 return 1;
527 return 1;
530 static enum filter_type
531 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
532 afi_t afi, safi_t safi)
534 struct bgp_filter *filter;
536 filter = &peer->filter[afi][safi];
538 if (DISTRIBUTE_IN_NAME (filter))
539 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
540 return FILTER_DENY;
542 if (PREFIX_LIST_IN_NAME (filter))
543 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
544 return FILTER_DENY;
546 if (FILTER_LIST_IN_NAME (filter))
547 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
548 return FILTER_DENY;
550 return FILTER_PERMIT;
553 static enum filter_type
554 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
555 afi_t afi, safi_t safi)
557 struct bgp_filter *filter;
559 filter = &peer->filter[afi][safi];
561 if (DISTRIBUTE_OUT_NAME (filter))
562 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
563 return FILTER_DENY;
565 if (PREFIX_LIST_OUT_NAME (filter))
566 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
567 return FILTER_DENY;
569 if (FILTER_LIST_OUT_NAME (filter))
570 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
571 return FILTER_DENY;
573 return FILTER_PERMIT;
576 /* If community attribute includes no_export then return 1. */
577 static int
578 bgp_community_filter (struct peer *peer, struct attr *attr)
580 if (attr->community)
582 /* NO_ADVERTISE check. */
583 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
584 return 1;
586 /* NO_EXPORT check. */
587 if (peer_sort (peer) == BGP_PEER_EBGP &&
588 community_include (attr->community, COMMUNITY_NO_EXPORT))
589 return 1;
591 /* NO_EXPORT_SUBCONFED check. */
592 if (peer_sort (peer) == BGP_PEER_EBGP
593 || peer_sort (peer) == BGP_PEER_CONFED)
594 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
595 return 1;
597 return 0;
600 /* Route reflection loop check. */
601 static int
602 bgp_cluster_filter (struct peer *peer, struct attr *attr)
604 struct in_addr cluster_id;
606 if (attr->extra && attr->extra->cluster)
608 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
609 cluster_id = peer->bgp->cluster_id;
610 else
611 cluster_id = peer->bgp->router_id;
613 if (cluster_loop_check (attr->extra->cluster, cluster_id))
614 return 1;
616 return 0;
619 static int
620 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
621 afi_t afi, safi_t safi)
623 struct bgp_filter *filter;
624 struct bgp_info info;
625 route_map_result_t ret;
627 filter = &peer->filter[afi][safi];
629 /* Apply default weight value. */
630 if (peer->weight)
631 (bgp_attr_extra_get (attr))->weight = peer->weight;
633 /* Route map apply. */
634 if (ROUTE_MAP_IN_NAME (filter))
636 /* Duplicate current value to new strucutre for modification. */
637 info.peer = peer;
638 info.attr = attr;
640 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
642 /* Apply BGP route map to the attribute. */
643 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
645 peer->rmap_type = 0;
647 if (ret == RMAP_DENYMATCH)
649 /* Free newly generated AS path and community by route-map. */
650 bgp_attr_flush (attr);
651 return RMAP_DENY;
654 return RMAP_PERMIT;
657 static int
658 bgp_export_modifier (struct peer *rsclient, struct peer *peer,
659 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
661 struct bgp_filter *filter;
662 struct bgp_info info;
663 route_map_result_t ret;
665 filter = &peer->filter[afi][safi];
667 /* Route map apply. */
668 if (ROUTE_MAP_EXPORT_NAME (filter))
670 /* Duplicate current value to new strucutre for modification. */
671 info.peer = rsclient;
672 info.attr = attr;
674 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
676 /* Apply BGP route map to the attribute. */
677 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
679 rsclient->rmap_type = 0;
681 if (ret == RMAP_DENYMATCH)
683 /* Free newly generated AS path and community by route-map. */
684 bgp_attr_flush (attr);
685 return RMAP_DENY;
688 return RMAP_PERMIT;
691 static int
692 bgp_import_modifier (struct peer *rsclient, struct peer *peer,
693 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
695 struct bgp_filter *filter;
696 struct bgp_info info;
697 route_map_result_t ret;
699 filter = &rsclient->filter[afi][safi];
701 /* Apply default weight value. */
702 if (peer->weight)
703 (bgp_attr_extra_get (attr))->weight = peer->weight;
705 /* Route map apply. */
706 if (ROUTE_MAP_IMPORT_NAME (filter))
708 /* Duplicate current value to new strucutre for modification. */
709 info.peer = peer;
710 info.attr = attr;
712 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
714 /* Apply BGP route map to the attribute. */
715 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
717 peer->rmap_type = 0;
719 if (ret == RMAP_DENYMATCH)
721 /* Free newly generated AS path and community by route-map. */
722 bgp_attr_flush (attr);
723 return RMAP_DENY;
726 return RMAP_PERMIT;
729 static int
730 bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
731 struct attr *attr, afi_t afi, safi_t safi)
733 int ret;
734 char buf[SU_ADDRSTRLEN];
735 struct bgp_filter *filter;
736 struct peer *from;
737 struct bgp *bgp;
738 int transparent;
739 int reflect;
741 from = ri->peer;
742 filter = &peer->filter[afi][safi];
743 bgp = peer->bgp;
745 if (DISABLE_BGP_ANNOUNCE)
746 return 0;
748 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
749 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
750 return 0;
752 /* Do not send back route to sender. */
753 if (from == peer)
754 return 0;
756 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
757 if (p->family == AF_INET
758 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
759 return 0;
760 #ifdef HAVE_IPV6
761 if (p->family == AF_INET6
762 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
763 return 0;
764 #endif
766 /* Aggregate-address suppress check. */
767 if (ri->extra && ri->extra->suppress)
768 if (! UNSUPPRESS_MAP_NAME (filter))
769 return 0;
771 /* Default route check. */
772 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
774 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
775 return 0;
776 #ifdef HAVE_IPV6
777 else if (p->family == AF_INET6 && p->prefixlen == 0)
778 return 0;
779 #endif /* HAVE_IPV6 */
782 /* Transparency check. */
783 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
784 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
785 transparent = 1;
786 else
787 transparent = 0;
789 /* If community is not disabled check the no-export and local. */
790 if (! transparent && bgp_community_filter (peer, ri->attr))
791 return 0;
793 /* If the attribute has originator-id and it is same as remote
794 peer's id. */
795 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
797 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->extra->originator_id))
799 if (BGP_DEBUG (filter, FILTER))
800 zlog (peer->log, LOG_DEBUG,
801 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
802 peer->host,
803 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
804 p->prefixlen);
805 return 0;
809 /* ORF prefix-list filter check */
810 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
811 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
812 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
813 if (peer->orf_plist[afi][safi])
815 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
816 return 0;
819 /* Output filter check. */
820 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
822 if (BGP_DEBUG (filter, FILTER))
823 zlog (peer->log, LOG_DEBUG,
824 "%s [Update:SEND] %s/%d is filtered",
825 peer->host,
826 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
827 p->prefixlen);
828 return 0;
831 #ifdef BGP_SEND_ASPATH_CHECK
832 /* AS path loop check. */
833 if (aspath_loop_check (ri->attr->aspath, peer->as))
835 if (BGP_DEBUG (filter, FILTER))
836 zlog (peer->log, LOG_DEBUG,
837 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
838 peer->host, peer->as);
839 return 0;
841 #endif /* BGP_SEND_ASPATH_CHECK */
843 /* If we're a CONFED we need to loop check the CONFED ID too */
844 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
846 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
848 if (BGP_DEBUG (filter, FILTER))
849 zlog (peer->log, LOG_DEBUG,
850 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
851 peer->host,
852 bgp->confed_id);
853 return 0;
857 /* Route-Reflect check. */
858 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
859 reflect = 1;
860 else
861 reflect = 0;
863 /* IBGP reflection check. */
864 if (reflect)
866 /* A route from a Client peer. */
867 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
869 /* Reflect to all the Non-Client peers and also to the
870 Client peers other than the originator. Originator check
871 is already done. So there is noting to do. */
872 /* no bgp client-to-client reflection check. */
873 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
874 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
875 return 0;
877 else
879 /* A route from a Non-client peer. Reflect to all other
880 clients. */
881 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
882 return 0;
886 /* AS-Pathlimit check */
887 if (ri->attr->pathlimit.ttl && peer_sort (peer) == BGP_PEER_EBGP)
888 /* Our ASN has not yet been pre-pended, that's done in packet_attribute
889 * on output. Hence the test here is for >=.
891 if (aspath_count_hops (ri->attr->aspath) >= ri->attr->pathlimit.ttl)
893 if (BGP_DEBUG (filter, FILTER))
894 zlog_info ("%s [Update:SEND] suppressed, AS-Pathlimit TTL %u exceeded",
895 peer->host, ri->attr->pathlimit.ttl);
896 return 0;
899 /* For modify attribute, copy it to temporary structure. */
900 bgp_attr_dup (attr, ri->attr);
902 /* If local-preference is not set. */
903 if ((peer_sort (peer) == BGP_PEER_IBGP
904 || peer_sort (peer) == BGP_PEER_CONFED)
905 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
907 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
908 attr->local_pref = bgp->default_local_pref;
911 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
912 if (peer_sort (peer) == BGP_PEER_EBGP
913 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
915 if (ri->peer != bgp->peer_self && ! transparent
916 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
917 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
920 /* next-hop-set */
921 if (transparent || reflect
922 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
923 && ((p->family == AF_INET && attr->nexthop.s_addr)
924 #ifdef HAVE_IPV6
925 || (p->family == AF_INET6 &&
926 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
927 #endif /* HAVE_IPV6 */
930 /* NEXT-HOP Unchanged. */
932 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
933 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
934 #ifdef HAVE_IPV6
935 || (p->family == AF_INET6 &&
936 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
937 #endif /* HAVE_IPV6 */
938 || (peer_sort (peer) == BGP_PEER_EBGP
939 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
941 /* Set IPv4 nexthop. */
942 if (p->family == AF_INET)
944 if (safi == SAFI_MPLS_VPN)
945 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
946 IPV4_MAX_BYTELEN);
947 else
948 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
950 #ifdef HAVE_IPV6
951 /* Set IPv6 nexthop. */
952 if (p->family == AF_INET6)
954 /* IPv6 global nexthop must be included. */
955 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
956 IPV6_MAX_BYTELEN);
957 attr->extra->mp_nexthop_len = 16;
959 #endif /* HAVE_IPV6 */
962 #ifdef HAVE_IPV6
963 if (p->family == AF_INET6)
965 /* Left nexthop_local unchanged if so configured. */
966 if ( CHECK_FLAG (peer->af_flags[afi][safi],
967 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
969 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
970 attr->extra->mp_nexthop_len=32;
971 else
972 attr->extra->mp_nexthop_len=16;
975 /* Default nexthop_local treatment for non-RS-Clients */
976 else
978 /* Link-local address should not be transit to different peer. */
979 attr->extra->mp_nexthop_len = 16;
981 /* Set link-local address for shared network peer. */
982 if (peer->shared_network
983 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
985 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
986 IPV6_MAX_BYTELEN);
987 attr->extra->mp_nexthop_len = 32;
990 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
991 address.*/
992 if (reflect)
993 attr->extra->mp_nexthop_len = 16;
995 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
996 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
997 attr->extra->mp_nexthop_len = 16;
1001 #endif /* HAVE_IPV6 */
1003 /* AS-Pathlimit: Check ASN for private/confed */
1004 if (attr->pathlimit.ttl)
1006 /* locally originated update */
1007 if (!attr->pathlimit.as)
1008 attr->pathlimit.as = peer->local_as;
1010 /* if the AS_PATHLIMIT attribute is attached to a prefix by a
1011 member of a confederation, then when the prefix is advertised outside
1012 of the confederation boundary, then the AS number of the
1013 confederation member inside of the AS_PATHLIMIT attribute should be
1014 replaced by the confederation's AS number. */
1015 if (peer_sort (from) == BGP_PEER_CONFED
1016 && peer_sort (peer) != BGP_PEER_CONFED)
1017 attr->pathlimit.as = peer->local_as;
1019 /* Private ASN should be updated whenever announcement leaves
1020 * private space. This is deliberately done after simple confed
1021 * based update..
1023 if (attr->pathlimit.as >= BGP_PRIVATE_AS_MIN
1024 && attr->pathlimit.as <= BGP_PRIVATE_AS_MAX)
1026 if (peer->local_as < BGP_PRIVATE_AS_MIN
1027 || peer->local_as > BGP_PRIVATE_AS_MAX)
1028 attr->pathlimit.as = peer->local_as;
1029 /* Ours is private, try using theirs.. */
1030 else if (peer->as < BGP_PRIVATE_AS_MIN
1031 || peer->local_as > BGP_PRIVATE_AS_MAX)
1032 attr->pathlimit.as = peer->as;
1036 /* If this is EBGP peer and remove-private-AS is set. */
1037 if (peer_sort (peer) == BGP_PEER_EBGP
1038 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1039 && aspath_private_as_check (attr->aspath))
1040 attr->aspath = aspath_empty_get ();
1042 /* Route map & unsuppress-map apply. */
1043 if (ROUTE_MAP_OUT_NAME (filter)
1044 || (ri->extra && ri->extra->suppress) )
1046 struct bgp_info info;
1047 struct attr dummy_attr = { 0 };
1049 info.peer = peer;
1050 info.attr = attr;
1052 /* The route reflector is not allowed to modify the attributes
1053 of the reflected IBGP routes. */
1054 if (peer_sort (from) == BGP_PEER_IBGP
1055 && peer_sort (peer) == BGP_PEER_IBGP)
1057 bgp_attr_dup (&dummy_attr, attr);
1058 info.attr = &dummy_attr;
1061 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1063 if (ri->extra && ri->extra->suppress)
1064 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1065 else
1066 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1068 peer->rmap_type = 0;
1070 if (dummy_attr.extra)
1071 bgp_attr_extra_free (&dummy_attr);
1073 if (ret == RMAP_DENYMATCH)
1075 bgp_attr_flush (attr);
1076 return 0;
1079 return 1;
1082 static int
1083 bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1084 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1086 int ret;
1087 char buf[SU_ADDRSTRLEN];
1088 struct bgp_filter *filter;
1089 struct bgp_info info;
1090 struct peer *from;
1091 struct bgp *bgp;
1093 from = ri->peer;
1094 filter = &rsclient->filter[afi][safi];
1095 bgp = rsclient->bgp;
1097 if (DISABLE_BGP_ANNOUNCE)
1098 return 0;
1100 /* Do not send back route to sender. */
1101 if (from == rsclient)
1102 return 0;
1104 /* Aggregate-address suppress check. */
1105 if (ri->extra && ri->extra->suppress)
1106 if (! UNSUPPRESS_MAP_NAME (filter))
1107 return 0;
1109 /* Default route check. */
1110 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1111 PEER_STATUS_DEFAULT_ORIGINATE))
1113 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1114 return 0;
1115 #ifdef HAVE_IPV6
1116 else if (p->family == AF_INET6 && p->prefixlen == 0)
1117 return 0;
1118 #endif /* HAVE_IPV6 */
1121 /* If the attribute has originator-id and it is same as remote
1122 peer's id. */
1123 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1125 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1126 &ri->attr->extra->originator_id))
1128 if (BGP_DEBUG (filter, FILTER))
1129 zlog (rsclient->log, LOG_DEBUG,
1130 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1131 rsclient->host,
1132 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1133 p->prefixlen);
1134 return 0;
1138 /* ORF prefix-list filter check */
1139 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1140 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1141 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1142 if (rsclient->orf_plist[afi][safi])
1144 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1145 return 0;
1148 /* Output filter check. */
1149 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1151 if (BGP_DEBUG (filter, FILTER))
1152 zlog (rsclient->log, LOG_DEBUG,
1153 "%s [Update:SEND] %s/%d is filtered",
1154 rsclient->host,
1155 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1156 p->prefixlen);
1157 return 0;
1160 #ifdef BGP_SEND_ASPATH_CHECK
1161 /* AS path loop check. */
1162 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1164 if (BGP_DEBUG (filter, FILTER))
1165 zlog (rsclient->log, LOG_DEBUG,
1166 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
1167 rsclient->host, rsclient->as);
1168 return 0;
1170 #endif /* BGP_SEND_ASPATH_CHECK */
1172 /* For modify attribute, copy it to temporary structure. */
1173 bgp_attr_dup (attr, ri->attr);
1175 /* next-hop-set */
1176 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1177 #ifdef HAVE_IPV6
1178 || (p->family == AF_INET6 &&
1179 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1180 #endif /* HAVE_IPV6 */
1183 /* Set IPv4 nexthop. */
1184 if (p->family == AF_INET)
1186 if (safi == SAFI_MPLS_VPN)
1187 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
1188 IPV4_MAX_BYTELEN);
1189 else
1190 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1192 #ifdef HAVE_IPV6
1193 /* Set IPv6 nexthop. */
1194 if (p->family == AF_INET6)
1196 /* IPv6 global nexthop must be included. */
1197 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
1198 IPV6_MAX_BYTELEN);
1199 attr->extra->mp_nexthop_len = 16;
1201 #endif /* HAVE_IPV6 */
1204 #ifdef HAVE_IPV6
1205 if (p->family == AF_INET6)
1207 struct attr_extra *attre = attr->extra;
1209 assert (attr->extra);
1211 /* Left nexthop_local unchanged if so configured. */
1212 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1213 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1215 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1216 attre->mp_nexthop_len=32;
1217 else
1218 attre->mp_nexthop_len=16;
1221 /* Default nexthop_local treatment for RS-Clients */
1222 else
1224 /* Announcer and RS-Client are both in the same network */
1225 if (rsclient->shared_network && from->shared_network &&
1226 (rsclient->ifindex == from->ifindex))
1228 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1229 attre->mp_nexthop_len=32;
1230 else
1231 attre->mp_nexthop_len=16;
1234 /* Set link-local address for shared network peer. */
1235 else if (rsclient->shared_network
1236 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1238 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
1239 IPV6_MAX_BYTELEN);
1240 attre->mp_nexthop_len = 32;
1243 else
1244 attre->mp_nexthop_len = 16;
1248 #endif /* HAVE_IPV6 */
1251 /* If this is EBGP peer and remove-private-AS is set. */
1252 if (peer_sort (rsclient) == BGP_PEER_EBGP
1253 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1254 && aspath_private_as_check (attr->aspath))
1255 attr->aspath = aspath_empty_get ();
1257 /* Route map & unsuppress-map apply. */
1258 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
1260 info.peer = rsclient;
1261 info.attr = attr;
1263 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1265 if (ri->extra && ri->extra->suppress)
1266 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1267 else
1268 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1270 rsclient->rmap_type = 0;
1272 if (ret == RMAP_DENYMATCH)
1274 bgp_attr_flush (attr);
1275 return 0;
1279 return 1;
1282 struct bgp_info_pair
1284 struct bgp_info *old;
1285 struct bgp_info *new;
1288 static void
1289 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1291 struct bgp_info *new_select;
1292 struct bgp_info *old_select;
1293 struct bgp_info *ri;
1294 struct bgp_info *ri1;
1295 struct bgp_info *ri2;
1296 struct bgp_info *nextri = NULL;
1298 /* bgp deterministic-med */
1299 new_select = NULL;
1300 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1301 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1303 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1304 continue;
1305 if (BGP_INFO_HOLDDOWN (ri1))
1306 continue;
1308 new_select = ri1;
1309 if (ri1->next)
1310 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1312 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1313 continue;
1314 if (BGP_INFO_HOLDDOWN (ri2))
1315 continue;
1317 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1318 || aspath_cmp_left_confed (ri1->attr->aspath,
1319 ri2->attr->aspath))
1321 if (bgp_info_cmp (bgp, ri2, new_select))
1323 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1324 new_select = ri2;
1327 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1330 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1331 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1334 /* Check old selected route and new selected route. */
1335 old_select = NULL;
1336 new_select = NULL;
1337 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1339 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1340 old_select = ri;
1342 if (BGP_INFO_HOLDDOWN (ri))
1344 /* reap REMOVED routes, if needs be
1345 * selected route must stay for a while longer though
1347 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1348 && (ri != old_select))
1349 bgp_info_reap (rn, ri);
1351 continue;
1354 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1355 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1357 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1358 continue;
1360 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1361 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
1363 if (bgp_info_cmp (bgp, ri, new_select))
1364 new_select = ri;
1367 result->old = old_select;
1368 result->new = new_select;
1370 return;
1373 static int
1374 bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1375 struct bgp_node *rn, afi_t afi, safi_t safi)
1377 struct prefix *p;
1378 struct attr attr = { 0 };
1380 p = &rn->p;
1382 /* Announce route to Established peer. */
1383 if (peer->status != Established)
1384 return 0;
1386 /* Address family configuration check. */
1387 if (! peer->afc_nego[afi][safi])
1388 return 0;
1390 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1391 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1392 PEER_STATUS_ORF_WAIT_REFRESH))
1393 return 0;
1395 switch (rn->table->type)
1397 case BGP_TABLE_MAIN:
1398 /* Announcement to peer->conf. If the route is filtered,
1399 withdraw it. */
1400 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1401 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1402 else
1403 bgp_adj_out_unset (rn, peer, p, afi, safi);
1404 break;
1405 case BGP_TABLE_RSCLIENT:
1406 /* Announcement to peer->conf. If the route is filtered,
1407 withdraw it. */
1408 if (selected &&
1409 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1410 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1411 else
1412 bgp_adj_out_unset (rn, peer, p, afi, safi);
1413 break;
1416 bgp_attr_extra_free (&attr);
1418 return 0;
1421 struct bgp_process_queue
1423 struct bgp *bgp;
1424 struct bgp_node *rn;
1425 afi_t afi;
1426 safi_t safi;
1429 static wq_item_status
1430 bgp_process_rsclient (struct work_queue *wq, void *data)
1432 struct bgp_process_queue *pq = data;
1433 struct bgp *bgp = pq->bgp;
1434 struct bgp_node *rn = pq->rn;
1435 afi_t afi = pq->afi;
1436 safi_t safi = pq->safi;
1437 struct bgp_info *new_select;
1438 struct bgp_info *old_select;
1439 struct bgp_info_pair old_and_new;
1440 struct attr attr;
1441 struct listnode *node, *nnode;
1442 struct peer *rsclient = rn->table->owner;
1444 memset (&attr, 0, sizeof (struct attr));
1445 /* Best path selection. */
1446 bgp_best_selection (bgp, rn, &old_and_new);
1447 new_select = old_and_new.new;
1448 old_select = old_and_new.old;
1450 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1452 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1454 /* Nothing to do. */
1455 if (old_select && old_select == new_select)
1456 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1457 continue;
1459 if (old_select)
1460 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1461 if (new_select)
1463 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1464 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1467 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
1470 else
1472 if (old_select)
1473 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1474 if (new_select)
1476 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1477 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1479 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
1482 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1483 bgp_info_reap (rn, old_select);
1485 bgp_attr_extra_free (&attr);
1487 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1488 return WQ_SUCCESS;
1491 static wq_item_status
1492 bgp_process_main (struct work_queue *wq, void *data)
1494 struct bgp_process_queue *pq = data;
1495 struct bgp *bgp = pq->bgp;
1496 struct bgp_node *rn = pq->rn;
1497 afi_t afi = pq->afi;
1498 safi_t safi = pq->safi;
1499 struct prefix *p = &rn->p;
1500 struct bgp_info *new_select;
1501 struct bgp_info *old_select;
1502 struct bgp_info_pair old_and_new;
1503 struct listnode *node, *nnode;
1504 struct peer *peer;
1506 /* Best path selection. */
1507 bgp_best_selection (bgp, rn, &old_and_new);
1508 old_select = old_and_new.old;
1509 new_select = old_and_new.new;
1511 /* Nothing to do. */
1512 if (old_select && old_select == new_select)
1514 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1516 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1517 bgp_zebra_announce (p, old_select, bgp);
1519 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1520 return WQ_SUCCESS;
1524 if (old_select)
1525 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1526 if (new_select)
1528 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1529 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1533 /* Check each BGP peer. */
1534 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
1536 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
1539 /* FIB update. */
1540 if (safi == SAFI_UNICAST && ! bgp->name &&
1541 ! bgp_option_check (BGP_OPT_NO_FIB))
1543 if (new_select
1544 && new_select->type == ZEBRA_ROUTE_BGP
1545 && new_select->sub_type == BGP_ROUTE_NORMAL)
1546 bgp_zebra_announce (p, new_select, bgp);
1547 else
1549 /* Withdraw the route from the kernel. */
1550 if (old_select
1551 && old_select->type == ZEBRA_ROUTE_BGP
1552 && old_select->sub_type == BGP_ROUTE_NORMAL)
1553 bgp_zebra_withdraw (p, old_select);
1557 /* Reap old select bgp_info, it it has been removed */
1558 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1559 bgp_info_reap (rn, old_select);
1561 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1562 return WQ_SUCCESS;
1565 static void
1566 bgp_processq_del (struct work_queue *wq, void *data)
1568 struct bgp_process_queue *pq = data;
1570 bgp_unlock_node (pq->rn);
1571 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1574 static void
1575 bgp_process_queue_init (void)
1577 bm->process_main_queue
1578 = work_queue_new (bm->master, "process_main_queue");
1579 bm->process_rsclient_queue
1580 = work_queue_new (bm->master, "process_rsclient_queue");
1582 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1584 zlog_err ("%s: Failed to allocate work queue", __func__);
1585 exit (1);
1588 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1589 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1590 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1591 bm->process_rsclient_queue->spec.del_item_data
1592 = bm->process_main_queue->spec.del_item_data;
1593 bm->process_main_queue->spec.max_retries
1594 = bm->process_main_queue->spec.max_retries = 0;
1595 bm->process_rsclient_queue->spec.hold
1596 = bm->process_main_queue->spec.hold = 50;
1599 void
1600 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1602 struct bgp_process_queue *pqnode;
1604 /* already scheduled for processing? */
1605 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1606 return;
1608 if ( (bm->process_main_queue == NULL) ||
1609 (bm->process_rsclient_queue == NULL) )
1610 bgp_process_queue_init ();
1612 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1613 sizeof (struct bgp_process_queue));
1614 if (!pqnode)
1615 return;
1617 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1618 pqnode->bgp = bgp;
1619 pqnode->afi = afi;
1620 pqnode->safi = safi;
1622 switch (rn->table->type)
1624 case BGP_TABLE_MAIN:
1625 work_queue_add (bm->process_main_queue, pqnode);
1626 break;
1627 case BGP_TABLE_RSCLIENT:
1628 work_queue_add (bm->process_rsclient_queue, pqnode);
1629 break;
1632 return;
1635 static int
1636 bgp_maximum_prefix_restart_timer (struct thread *thread)
1638 struct peer *peer;
1640 peer = THREAD_ARG (thread);
1641 peer->t_pmax_restart = NULL;
1643 if (BGP_DEBUG (events, EVENTS))
1644 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1645 peer->host);
1647 peer_clear (peer);
1649 return 0;
1653 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1654 safi_t safi, int always)
1656 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1657 return 0;
1659 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
1661 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1662 && ! always)
1663 return 0;
1665 zlog (peer->log, LOG_INFO,
1666 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1667 "limit %ld", afi_safi_print (afi, safi), peer->host,
1668 peer->pcount[afi][safi], peer->pmax[afi][safi]);
1669 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1671 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1672 return 0;
1675 u_int8_t ndata[7];
1677 if (safi == SAFI_MPLS_VPN)
1678 safi = BGP_SAFI_VPNV4;
1680 ndata[0] = (afi >> 8);
1681 ndata[1] = afi;
1682 ndata[2] = safi;
1683 ndata[3] = (peer->pmax[afi][safi] >> 24);
1684 ndata[4] = (peer->pmax[afi][safi] >> 16);
1685 ndata[5] = (peer->pmax[afi][safi] >> 8);
1686 ndata[6] = (peer->pmax[afi][safi]);
1688 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1689 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1690 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1693 /* restart timer start */
1694 if (peer->pmax_restart[afi][safi])
1696 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1698 if (BGP_DEBUG (events, EVENTS))
1699 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1700 peer->host, peer->v_pmax_restart);
1702 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1703 peer->v_pmax_restart);
1706 return 1;
1708 else
1709 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1711 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1713 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1714 && ! always)
1715 return 0;
1717 zlog (peer->log, LOG_INFO,
1718 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1719 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1720 peer->pmax[afi][safi]);
1721 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1723 else
1724 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1725 return 0;
1728 /* Unconditionally remove the route from the RIB, without taking
1729 * damping into consideration (eg, because the session went down)
1731 static void
1732 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1733 afi_t afi, safi_t safi)
1735 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1737 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1738 bgp_info_delete (rn, ri); /* keep historical info */
1740 bgp_process (peer->bgp, rn, afi, safi);
1743 static void
1744 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1745 afi_t afi, safi_t safi)
1747 int status = BGP_DAMP_NONE;
1749 /* apply dampening, if result is suppressed, we'll be retaining
1750 * the bgp_info in the RIB for historical reference.
1752 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1753 && peer_sort (peer) == BGP_PEER_EBGP)
1754 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1755 == BGP_DAMP_SUPPRESSED)
1757 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1758 return;
1761 bgp_rib_remove (rn, ri, peer, afi, safi);
1764 static void
1765 bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1766 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1767 int sub_type, struct prefix_rd *prd, u_char *tag)
1769 struct bgp_node *rn;
1770 struct bgp *bgp;
1771 struct attr new_attr = { 0 };
1772 struct attr *attr_new;
1773 struct attr *attr_new2;
1774 struct bgp_info *ri;
1775 struct bgp_info *new;
1776 const char *reason;
1777 char buf[SU_ADDRSTRLEN];
1779 //memset (new_attr, 0, sizeof (struct attr));
1781 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1782 if (peer == rsclient)
1783 return;
1785 bgp = peer->bgp;
1786 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1788 /* Check previously received route. */
1789 for (ri = rn->info; ri; ri = ri->next)
1790 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1791 break;
1793 /* AS path loop check. */
1794 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1796 reason = "as-path contains our own AS;";
1797 goto filtered;
1800 /* Route reflector originator ID check. */
1801 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1802 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
1804 reason = "originator is us;";
1805 goto filtered;
1808 bgp_attr_dup (&new_attr, attr);
1810 /* Apply export policy. */
1811 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1812 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1814 reason = "export-policy;";
1815 goto filtered;
1818 attr_new2 = bgp_attr_intern (&new_attr);
1820 /* Apply import policy. */
1821 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1823 bgp_attr_unintern (attr_new2);
1825 reason = "import-policy;";
1826 goto filtered;
1829 attr_new = bgp_attr_intern (&new_attr);
1830 bgp_attr_unintern (attr_new2);
1832 /* IPv4 unicast next hop check. */
1833 if (afi == AFI_IP && safi == SAFI_UNICAST)
1835 /* Next hop must not be 0.0.0.0 nor Class E address. */
1836 if (new_attr.nexthop.s_addr == 0
1837 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1839 bgp_attr_unintern (attr_new);
1841 reason = "martian next-hop;";
1842 goto filtered;
1846 /* new_attr isn't passed to any functions after here */
1847 bgp_attr_extra_free (&new_attr);
1849 /* If the update is implicit withdraw. */
1850 if (ri)
1852 ri->uptime = time (NULL);
1854 /* Same attribute comes in. */
1855 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1856 && attrhash_cmp (ri->attr, attr_new))
1859 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
1861 if (BGP_DEBUG (update, UPDATE_IN))
1862 zlog (peer->log, LOG_DEBUG,
1863 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1864 peer->host,
1865 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1866 p->prefixlen, rsclient->host);
1868 bgp_unlock_node (rn);
1869 bgp_attr_unintern (attr_new);
1871 return;
1874 /* Withdraw/Announce before we fully processed the withdraw */
1875 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1876 bgp_info_restore (rn, ri);
1878 /* Received Logging. */
1879 if (BGP_DEBUG (update, UPDATE_IN))
1880 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
1881 peer->host,
1882 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1883 p->prefixlen, rsclient->host);
1885 /* The attribute is changed. */
1886 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
1888 /* Update to new attribute. */
1889 bgp_attr_unintern (ri->attr);
1890 ri->attr = attr_new;
1892 /* Update MPLS tag. */
1893 if (safi == SAFI_MPLS_VPN)
1894 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
1896 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
1898 /* Process change. */
1899 bgp_process (bgp, rn, afi, safi);
1900 bgp_unlock_node (rn);
1902 return;
1905 /* Received Logging. */
1906 if (BGP_DEBUG (update, UPDATE_IN))
1908 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
1909 peer->host,
1910 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1911 p->prefixlen, rsclient->host);
1914 /* Make new BGP info. */
1915 new = bgp_info_new ();
1916 new->type = type;
1917 new->sub_type = sub_type;
1918 new->peer = peer;
1919 new->attr = attr_new;
1920 new->uptime = time (NULL);
1922 /* Update MPLS tag. */
1923 if (safi == SAFI_MPLS_VPN)
1924 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
1926 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
1928 /* Register new BGP information. */
1929 bgp_info_add (rn, new);
1931 /* route_node_get lock */
1932 bgp_unlock_node (rn);
1934 /* Process change. */
1935 bgp_process (bgp, rn, afi, safi);
1937 bgp_attr_extra_free (&new_attr);
1939 return;
1941 filtered:
1943 /* This BGP update is filtered. Log the reason then update BGP entry. */
1944 if (BGP_DEBUG (update, UPDATE_IN))
1945 zlog (peer->log, LOG_DEBUG,
1946 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1947 peer->host,
1948 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1949 p->prefixlen, rsclient->host, reason);
1951 if (ri)
1952 bgp_rib_remove (rn, ri, peer, afi, safi);
1954 bgp_unlock_node (rn);
1956 if (new_attr.extra)
1957 bgp_attr_extra_free (&new_attr);
1959 return;
1962 static void
1963 bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1964 struct peer *peer, struct prefix *p, int type, int sub_type,
1965 struct prefix_rd *prd, u_char *tag)
1967 struct bgp_node *rn;
1968 struct bgp_info *ri;
1969 char buf[SU_ADDRSTRLEN];
1971 if (rsclient == peer)
1972 return;
1974 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1976 /* Lookup withdrawn route. */
1977 for (ri = rn->info; ri; ri = ri->next)
1978 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1979 break;
1981 /* Withdraw specified route from routing table. */
1982 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1983 bgp_rib_withdraw (rn, ri, peer, afi, safi);
1984 else if (BGP_DEBUG (update, UPDATE_IN))
1985 zlog (peer->log, LOG_DEBUG,
1986 "%s Can't find the route %s/%d", peer->host,
1987 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1988 p->prefixlen);
1990 /* Unlock bgp_node_get() lock. */
1991 bgp_unlock_node (rn);
1994 static int
1995 bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
1996 afi_t afi, safi_t safi, int type, int sub_type,
1997 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1999 int ret;
2000 int aspath_loop_count = 0;
2001 struct bgp_node *rn;
2002 struct bgp *bgp;
2003 struct attr new_attr = { 0 };
2004 struct attr *attr_new;
2005 struct bgp_info *ri;
2006 struct bgp_info *new;
2007 const char *reason;
2008 char buf[SU_ADDRSTRLEN];
2010 bgp = peer->bgp;
2011 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2013 /* When peer's soft reconfiguration enabled. Record input packet in
2014 Adj-RIBs-In. */
2015 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2016 && peer != bgp->peer_self && ! soft_reconfig)
2017 bgp_adj_in_set (rn, peer, attr);
2019 /* Check previously received route. */
2020 for (ri = rn->info; ri; ri = ri->next)
2021 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2022 break;
2024 /* AS path local-as loop check. */
2025 if (peer->change_local_as)
2027 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2028 aspath_loop_count = 1;
2030 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2032 reason = "as-path contains our own AS;";
2033 goto filtered;
2037 /* AS path loop check. */
2038 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2039 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2040 && aspath_loop_check(attr->aspath, bgp->confed_id)
2041 > peer->allowas_in[afi][safi]))
2043 reason = "as-path contains our own AS;";
2044 goto filtered;
2047 /* Route reflector originator ID check. */
2048 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2049 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2051 reason = "originator is us;";
2052 goto filtered;
2055 /* Route reflector cluster ID check. */
2056 if (bgp_cluster_filter (peer, attr))
2058 reason = "reflected from the same cluster;";
2059 goto filtered;
2062 /* Apply incoming filter. */
2063 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2065 reason = "filter;";
2066 goto filtered;
2069 /* Apply incoming route-map. */
2070 bgp_attr_dup (&new_attr, attr);
2072 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2074 reason = "route-map;";
2075 goto filtered;
2078 /* IPv4 unicast next hop check. */
2079 if (afi == AFI_IP && safi == SAFI_UNICAST)
2081 /* If the peer is EBGP and nexthop is not on connected route,
2082 discard it. */
2083 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2084 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
2085 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
2087 reason = "non-connected next-hop;";
2088 goto filtered;
2091 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2092 must not be my own address. */
2093 if (bgp_nexthop_self (afi, &new_attr)
2094 || new_attr.nexthop.s_addr == 0
2095 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2097 reason = "martian next-hop;";
2098 goto filtered;
2102 attr_new = bgp_attr_intern (&new_attr);
2104 /* If the update is implicit withdraw. */
2105 if (ri)
2107 ri->uptime = time (NULL);
2109 /* Same attribute comes in. */
2110 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2111 && attrhash_cmp (ri->attr, attr_new))
2113 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2115 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2116 && peer_sort (peer) == BGP_PEER_EBGP
2117 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2119 if (BGP_DEBUG (update, UPDATE_IN))
2120 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2121 peer->host,
2122 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2123 p->prefixlen);
2125 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2127 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2128 bgp_process (bgp, rn, afi, safi);
2131 else /* Duplicate - odd */
2133 if (BGP_DEBUG (update, UPDATE_IN))
2134 zlog (peer->log, LOG_DEBUG,
2135 "%s rcvd %s/%d...duplicate ignored",
2136 peer->host,
2137 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2138 p->prefixlen);
2140 /* graceful restart STALE flag unset. */
2141 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2143 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2144 bgp_process (bgp, rn, afi, safi);
2148 bgp_unlock_node (rn);
2149 bgp_attr_unintern (attr_new);
2150 bgp_attr_extra_free (&new_attr);
2152 return 0;
2155 /* Withdraw/Announce before we fully processed the withdraw */
2156 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2158 if (BGP_DEBUG (update, UPDATE_IN))
2159 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2160 peer->host,
2161 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2162 p->prefixlen);
2163 bgp_info_restore (rn, ri);
2166 /* Received Logging. */
2167 if (BGP_DEBUG (update, UPDATE_IN))
2168 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2169 peer->host,
2170 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2171 p->prefixlen);
2173 /* graceful restart STALE flag unset. */
2174 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2175 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2177 /* The attribute is changed. */
2178 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2180 /* implicit withdraw, decrement aggregate and pcount here.
2181 * only if update is accepted, they'll increment below.
2183 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2185 /* Update bgp route dampening information. */
2186 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2187 && peer_sort (peer) == BGP_PEER_EBGP)
2189 /* This is implicit withdraw so we should update dampening
2190 information. */
2191 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2192 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2195 /* Update to new attribute. */
2196 bgp_attr_unintern (ri->attr);
2197 ri->attr = attr_new;
2199 /* Update MPLS tag. */
2200 if (safi == SAFI_MPLS_VPN)
2201 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2203 /* Update bgp route dampening information. */
2204 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2205 && peer_sort (peer) == BGP_PEER_EBGP)
2207 /* Now we do normal update dampening. */
2208 ret = bgp_damp_update (ri, rn, afi, safi);
2209 if (ret == BGP_DAMP_SUPPRESSED)
2211 bgp_unlock_node (rn);
2212 bgp_attr_extra_free (&new_attr);
2213 return 0;
2217 /* Nexthop reachability check. */
2218 if ((afi == AFI_IP || afi == AFI_IP6)
2219 && safi == SAFI_UNICAST
2220 && (peer_sort (peer) == BGP_PEER_IBGP
2221 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
2222 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
2224 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
2225 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2226 else
2227 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2229 else
2230 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2232 /* Process change. */
2233 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2235 bgp_process (bgp, rn, afi, safi);
2236 bgp_unlock_node (rn);
2237 bgp_attr_extra_free (&new_attr);
2239 return 0;
2242 /* Received Logging. */
2243 if (BGP_DEBUG (update, UPDATE_IN))
2245 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2246 peer->host,
2247 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2248 p->prefixlen);
2251 /* Make new BGP info. */
2252 new = bgp_info_new ();
2253 new->type = type;
2254 new->sub_type = sub_type;
2255 new->peer = peer;
2256 new->attr = attr_new;
2257 new->uptime = time (NULL);
2259 /* Update MPLS tag. */
2260 if (safi == SAFI_MPLS_VPN)
2261 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2263 /* Nexthop reachability check. */
2264 if ((afi == AFI_IP || afi == AFI_IP6)
2265 && safi == SAFI_UNICAST
2266 && (peer_sort (peer) == BGP_PEER_IBGP
2267 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
2268 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
2270 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
2271 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2272 else
2273 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2275 else
2276 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2278 /* Increment prefix */
2279 bgp_aggregate_increment (bgp, p, new, afi, safi);
2281 /* Register new BGP information. */
2282 bgp_info_add (rn, new);
2284 /* route_node_get lock */
2285 bgp_unlock_node (rn);
2287 bgp_attr_extra_free (&new_attr);
2289 /* If maximum prefix count is configured and current prefix
2290 count exeed it. */
2291 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2292 return -1;
2294 /* Process change. */
2295 bgp_process (bgp, rn, afi, safi);
2297 return 0;
2299 /* This BGP update is filtered. Log the reason then update BGP
2300 entry. */
2301 filtered:
2302 if (BGP_DEBUG (update, UPDATE_IN))
2303 zlog (peer->log, LOG_DEBUG,
2304 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2305 peer->host,
2306 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2307 p->prefixlen, reason);
2309 if (ri)
2310 bgp_rib_remove (rn, ri, peer, afi, safi);
2312 bgp_unlock_node (rn);
2314 bgp_attr_extra_free (&new_attr);
2316 return 0;
2320 bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2321 afi_t afi, safi_t safi, int type, int sub_type,
2322 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2324 struct peer *rsclient;
2325 struct listnode *node, *nnode;
2326 struct bgp *bgp;
2327 int ret;
2329 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2330 soft_reconfig);
2332 bgp = peer->bgp;
2334 /* Process the update for each RS-client. */
2335 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2337 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2338 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2339 sub_type, prd, tag);
2342 return ret;
2346 bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
2347 afi_t afi, safi_t safi, int type, int sub_type,
2348 struct prefix_rd *prd, u_char *tag)
2350 struct bgp *bgp;
2351 char buf[SU_ADDRSTRLEN];
2352 struct bgp_node *rn;
2353 struct bgp_info *ri;
2354 struct peer *rsclient;
2355 struct listnode *node, *nnode;
2357 bgp = peer->bgp;
2359 /* Process the withdraw for each RS-client. */
2360 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2362 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2363 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2366 /* Logging. */
2367 if (BGP_DEBUG (update, UPDATE_IN))
2368 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
2369 peer->host,
2370 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2371 p->prefixlen);
2373 /* Lookup node. */
2374 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2376 /* If peer is soft reconfiguration enabled. Record input packet for
2377 further calculation. */
2378 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2379 && peer != bgp->peer_self)
2380 bgp_adj_in_unset (rn, peer);
2382 /* Lookup withdrawn route. */
2383 for (ri = rn->info; ri; ri = ri->next)
2384 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2385 break;
2387 /* Withdraw specified route from routing table. */
2388 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2389 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2390 else if (BGP_DEBUG (update, UPDATE_IN))
2391 zlog (peer->log, LOG_DEBUG,
2392 "%s Can't find the route %s/%d", peer->host,
2393 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2394 p->prefixlen);
2396 /* Unlock bgp_node_get() lock. */
2397 bgp_unlock_node (rn);
2399 return 0;
2402 void
2403 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2405 struct bgp *bgp;
2406 struct attr attr;
2407 struct aspath *aspath = { 0 };
2408 struct prefix p;
2409 struct bgp_info binfo;
2410 struct peer *from;
2411 int ret = RMAP_DENYMATCH;
2413 if (!(afi == AFI_IP || afi == AFI_IP6))
2414 return;
2416 bgp = peer->bgp;
2417 from = bgp->peer_self;
2419 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2420 aspath = attr.aspath;
2421 attr.local_pref = bgp->default_local_pref;
2422 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2424 if (afi == AFI_IP)
2425 str2prefix ("0.0.0.0/0", &p);
2426 #ifdef HAVE_IPV6
2427 else if (afi == AFI_IP6)
2429 struct attr_extra *ae;
2430 attr.extra = NULL;
2432 ae = bgp_attr_extra_get (&attr);
2433 attr.extra = ae;
2435 str2prefix ("::/0", &p);
2437 /* IPv6 global nexthop must be included. */
2438 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
2439 IPV6_MAX_BYTELEN);
2440 ae->mp_nexthop_len = 16;
2442 /* If the peer is on shared nextwork and we have link-local
2443 nexthop set it. */
2444 if (peer->shared_network
2445 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2447 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
2448 IPV6_MAX_BYTELEN);
2449 ae->mp_nexthop_len = 32;
2452 #endif /* HAVE_IPV6 */
2454 if (peer->default_rmap[afi][safi].name)
2456 binfo.peer = bgp->peer_self;
2457 binfo.attr = &attr;
2459 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2461 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2462 RMAP_BGP, &binfo);
2464 bgp->peer_self->rmap_type = 0;
2466 if (ret == RMAP_DENYMATCH)
2468 bgp_attr_flush (&attr);
2469 withdraw = 1;
2473 if (withdraw)
2475 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2476 bgp_default_withdraw_send (peer, afi, safi);
2477 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2479 else
2481 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2482 bgp_default_update_send (peer, &attr, afi, safi, from);
2485 bgp_attr_extra_free (&attr);
2486 aspath_unintern (aspath);
2489 static void
2490 bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
2491 struct bgp_table *table, int rsclient)
2493 struct bgp_node *rn;
2494 struct bgp_info *ri;
2495 struct attr attr;
2497 memset (&attr, 0, sizeof (struct attr));
2499 if (! table)
2500 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
2502 if (safi != SAFI_MPLS_VPN
2503 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2504 bgp_default_originate (peer, afi, safi, 0);
2506 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2507 for (ri = rn->info; ri; ri = ri->next)
2508 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2510 if ( (rsclient) ?
2511 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2512 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
2513 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2514 else
2515 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2517 bgp_attr_extra_free (&attr);
2521 void
2522 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2524 struct bgp_node *rn;
2525 struct bgp_table *table;
2527 if (peer->status != Established)
2528 return;
2530 if (! peer->afc_nego[afi][safi])
2531 return;
2533 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2534 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2535 return;
2537 if (safi != SAFI_MPLS_VPN)
2538 bgp_announce_table (peer, afi, safi, NULL, 0);
2539 else
2540 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2541 rn = bgp_route_next(rn))
2542 if ((table = (rn->info)) != NULL)
2543 bgp_announce_table (peer, afi, safi, table, 0);
2545 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2546 bgp_announce_table (peer, afi, safi, NULL, 1);
2549 void
2550 bgp_announce_route_all (struct peer *peer)
2552 afi_t afi;
2553 safi_t safi;
2555 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2556 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2557 bgp_announce_route (peer, afi, safi);
2560 static void
2561 bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2562 safi_t safi, struct bgp_table *table)
2564 struct bgp_node *rn;
2565 struct bgp_adj_in *ain;
2567 if (! table)
2568 table = rsclient->bgp->rib[afi][safi];
2570 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2571 for (ain = rn->adj_in; ain; ain = ain->next)
2573 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2574 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2578 void
2579 bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2581 struct bgp_table *table;
2582 struct bgp_node *rn;
2584 if (safi != SAFI_MPLS_VPN)
2585 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2587 else
2588 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2589 rn = bgp_route_next (rn))
2590 if ((table = rn->info) != NULL)
2591 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2594 static void
2595 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2596 struct bgp_table *table)
2598 int ret;
2599 struct bgp_node *rn;
2600 struct bgp_adj_in *ain;
2602 if (! table)
2603 table = peer->bgp->rib[afi][safi];
2605 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2606 for (ain = rn->adj_in; ain; ain = ain->next)
2608 if (ain->peer == peer)
2610 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2611 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2612 NULL, NULL, 1);
2613 if (ret < 0)
2615 bgp_unlock_node (rn);
2616 return;
2618 continue;
2623 void
2624 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2626 struct bgp_node *rn;
2627 struct bgp_table *table;
2629 if (peer->status != Established)
2630 return;
2632 if (safi != SAFI_MPLS_VPN)
2633 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2634 else
2635 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2636 rn = bgp_route_next (rn))
2637 if ((table = rn->info) != NULL)
2638 bgp_soft_reconfig_table (peer, afi, safi, table);
2641 static wq_item_status
2642 bgp_clear_route_node (struct work_queue *wq, void *data)
2644 struct bgp_node *rn = data;
2645 struct peer *peer = wq->spec.data;
2646 struct bgp_info *ri;
2647 afi_t afi = rn->table->afi;
2648 safi_t safi = rn->table->safi;
2650 assert (rn && peer);
2652 for (ri = rn->info; ri; ri = ri->next)
2653 if (ri->peer == peer)
2655 /* graceful restart STALE flag set. */
2656 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2657 && peer->nsf[afi][safi]
2658 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2659 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2660 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
2661 else
2662 bgp_rib_remove (rn, ri, peer, afi, safi);
2663 break;
2665 return WQ_SUCCESS;
2668 static void
2669 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
2671 struct bgp_node *rn = data;
2673 bgp_unlock_node (rn);
2676 static void
2677 bgp_clear_node_complete (struct work_queue *wq)
2679 struct peer *peer = wq->spec.data;
2681 peer_unlock (peer); /* bgp_clear_node_complete */
2683 /* Tickle FSM to start moving again */
2684 BGP_EVENT_ADD (peer, Clearing_Completed);
2687 static void
2688 bgp_clear_node_queue_init (struct peer *peer)
2690 #define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2691 char wname[CLEAR_QUEUE_NAME_LEN];
2693 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2694 #undef CLEAR_QUEUE_NAME_LEN
2696 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
2698 zlog_err ("%s: Failed to allocate work queue", __func__);
2699 exit (1);
2701 peer->clear_node_queue->spec.hold = 10;
2702 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2703 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2704 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2705 peer->clear_node_queue->spec.max_retries = 0;
2707 /* we only 'lock' this peer reference when the queue is actually active */
2708 peer->clear_node_queue->spec.data = peer;
2711 static void
2712 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2713 struct bgp_table *table, struct peer *rsclient)
2715 struct bgp_node *rn;
2718 if (! table)
2719 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
2721 /* If still no table => afi/safi isn't configured at all or smth. */
2722 if (! table)
2723 return;
2725 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2727 struct bgp_info *ri;
2728 struct bgp_adj_in *ain;
2729 struct bgp_adj_out *aout;
2731 if (rn->info == NULL)
2732 continue;
2734 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2735 * queued for every clearing peer, regardless of whether it is
2736 * relevant to the peer at hand.
2738 * Overview: There are 3 different indices which need to be
2739 * scrubbed, potentially, when a peer is removed:
2741 * 1 peer's routes visible via the RIB (ie accepted routes)
2742 * 2 peer's routes visible by the (optional) peer's adj-in index
2743 * 3 other routes visible by the peer's adj-out index
2745 * 3 there is no hurry in scrubbing, once the struct peer is
2746 * removed from bgp->peer, we could just GC such deleted peer's
2747 * adj-outs at our leisure.
2749 * 1 and 2 must be 'scrubbed' in some way, at least made
2750 * invisible via RIB index before peer session is allowed to be
2751 * brought back up. So one needs to know when such a 'search' is
2752 * complete.
2754 * Ideally:
2756 * - there'd be a single global queue or a single RIB walker
2757 * - rather than tracking which route_nodes still need to be
2758 * examined on a peer basis, we'd track which peers still
2759 * aren't cleared
2761 * Given that our per-peer prefix-counts now should be reliable,
2762 * this may actually be achievable. It doesn't seem to be a huge
2763 * problem at this time,
2765 for (ri = rn->info; ri; ri = ri->next)
2766 if (ri->peer == peer)
2768 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2769 work_queue_add (peer->clear_node_queue, rn);
2772 for (ain = rn->adj_in; ain; ain = ain->next)
2773 if (ain->peer == peer)
2775 bgp_adj_in_remove (rn, ain);
2776 bgp_unlock_node (rn);
2777 break;
2779 for (aout = rn->adj_out; aout; aout = aout->next)
2780 if (aout->peer == peer)
2782 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2783 bgp_unlock_node (rn);
2784 break;
2787 return;
2790 void
2791 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2793 struct bgp_node *rn;
2794 struct bgp_table *table;
2795 struct peer *rsclient;
2796 struct listnode *node, *nnode;
2798 if (peer->clear_node_queue == NULL)
2799 bgp_clear_node_queue_init (peer);
2801 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2802 * Idle until it receives a Clearing_Completed event. This protects
2803 * against peers which flap faster than we can we clear, which could
2804 * lead to:
2806 * a) race with routes from the new session being installed before
2807 * clear_route_node visits the node (to delete the route of that
2808 * peer)
2809 * b) resource exhaustion, clear_route_node likely leads to an entry
2810 * on the process_main queue. Fast-flapping could cause that queue
2811 * to grow and grow.
2813 if (!peer->clear_node_queue->thread)
2814 peer_lock (peer); /* bgp_clear_node_complete */
2816 if (safi != SAFI_MPLS_VPN)
2817 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
2818 else
2819 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2820 rn = bgp_route_next (rn))
2821 if ((table = rn->info) != NULL)
2822 bgp_clear_route_table (peer, afi, safi, table, NULL);
2824 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2826 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2827 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2830 /* If no routes were cleared, nothing was added to workqueue, the
2831 * completion function won't be run by workqueue code - call it here.
2832 * XXX: Actually, this assumption doesn't hold, see
2833 * bgp_clear_route_table(), we queue all non-empty nodes.
2835 * Additionally, there is a presumption in FSM that clearing is only
2836 * really needed if peer state is Established - peers in
2837 * pre-Established states shouldn't have any route-update state
2838 * associated with them (in or out).
2840 * We still can get here in pre-Established though, through
2841 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2842 * check to ensure the assumption above holds.
2844 * At some future point, this check could be move to the top of the
2845 * function, and do a quick early-return when state is
2846 * pre-Established, avoiding above list and table scans. Once we're
2847 * sure it is safe..
2849 if (!peer->clear_node_queue->thread)
2850 bgp_clear_node_complete (peer->clear_node_queue);
2851 else
2853 /* clearing queue scheduled. Normal if in Established state
2854 * (and about to transition out of it), but otherwise...
2856 if (peer->status != Established)
2858 plog_err (peer->log, "%s [Error] State %s is not Established,"
2859 " but routes were cleared - bug!",
2860 peer->host, LOOKUP (bgp_status_msg, peer->status));
2861 assert (peer->status == Established);
2866 void
2867 bgp_clear_route_all (struct peer *peer)
2869 afi_t afi;
2870 safi_t safi;
2872 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2873 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2874 bgp_clear_route (peer, afi, safi);
2877 void
2878 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2880 struct bgp_table *table;
2881 struct bgp_node *rn;
2882 struct bgp_adj_in *ain;
2884 table = peer->bgp->rib[afi][safi];
2886 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2887 for (ain = rn->adj_in; ain ; ain = ain->next)
2888 if (ain->peer == peer)
2890 bgp_adj_in_remove (rn, ain);
2891 bgp_unlock_node (rn);
2892 break;
2896 void
2897 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2899 struct bgp_node *rn;
2900 struct bgp_info *ri;
2901 struct bgp_table *table;
2903 table = peer->bgp->rib[afi][safi];
2905 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2907 for (ri = rn->info; ri; ri = ri->next)
2908 if (ri->peer == peer)
2910 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2911 bgp_rib_remove (rn, ri, peer, afi, safi);
2912 break;
2917 /* Delete all kernel routes. */
2918 void
2919 bgp_cleanup_routes ()
2921 struct bgp *bgp;
2922 struct listnode *node, *nnode;
2923 struct bgp_node *rn;
2924 struct bgp_table *table;
2925 struct bgp_info *ri;
2927 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
2929 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2931 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2932 for (ri = rn->info; ri; ri = ri->next)
2933 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2934 && ri->type == ZEBRA_ROUTE_BGP
2935 && ri->sub_type == BGP_ROUTE_NORMAL)
2936 bgp_zebra_withdraw (&rn->p, ri);
2938 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2940 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2941 for (ri = rn->info; ri; ri = ri->next)
2942 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2943 && ri->type == ZEBRA_ROUTE_BGP
2944 && ri->sub_type == BGP_ROUTE_NORMAL)
2945 bgp_zebra_withdraw (&rn->p, ri);
2949 void
2950 bgp_reset ()
2952 vty_reset ();
2953 bgp_zclient_reset ();
2954 access_list_reset ();
2955 prefix_list_reset ();
2958 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2959 value. */
2961 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2963 u_char *pnt;
2964 u_char *lim;
2965 struct prefix p;
2966 int psize;
2967 int ret;
2969 /* Check peer status. */
2970 if (peer->status != Established)
2971 return 0;
2973 pnt = packet->nlri;
2974 lim = pnt + packet->length;
2976 for (; pnt < lim; pnt += psize)
2978 /* Clear prefix structure. */
2979 memset (&p, 0, sizeof (struct prefix));
2981 /* Fetch prefix length. */
2982 p.prefixlen = *pnt++;
2983 p.family = afi2family (packet->afi);
2985 /* Already checked in nlri_sanity_check(). We do double check
2986 here. */
2987 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2988 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2989 return -1;
2991 /* Packet size overflow check. */
2992 psize = PSIZE (p.prefixlen);
2994 /* When packet overflow occur return immediately. */
2995 if (pnt + psize > lim)
2996 return -1;
2998 /* Fetch prefix from NLRI packet. */
2999 memcpy (&p.u.prefix, pnt, psize);
3001 /* Check address. */
3002 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3004 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3007 * From draft-ietf-idr-bgp4-22, Section 6.3:
3008 * If a BGP router receives an UPDATE message with a
3009 * semantically incorrect NLRI field, in which a prefix is
3010 * semantically incorrect (eg. an unexpected multicast IP
3011 * address), it should ignore the prefix.
3013 zlog (peer->log, LOG_ERR,
3014 "IPv4 unicast NLRI is multicast address %s",
3015 inet_ntoa (p.u.prefix4));
3017 return -1;
3021 #ifdef HAVE_IPV6
3022 /* Check address. */
3023 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3025 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3027 char buf[BUFSIZ];
3029 zlog (peer->log, LOG_WARNING,
3030 "IPv6 link-local NLRI received %s ignore this NLRI",
3031 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3033 continue;
3036 #endif /* HAVE_IPV6 */
3038 /* Normal process. */
3039 if (attr)
3040 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3041 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3042 else
3043 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3044 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3046 /* Address family configuration mismatch or maximum-prefix count
3047 overflow. */
3048 if (ret < 0)
3049 return -1;
3052 /* Packet length consistency check. */
3053 if (pnt != lim)
3054 return -1;
3056 return 0;
3059 /* NLRI encode syntax check routine. */
3061 bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3062 bgp_size_t length)
3064 u_char *end;
3065 u_char prefixlen;
3066 int psize;
3068 end = pnt + length;
3070 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3071 syntactic validity. If the field is syntactically incorrect,
3072 then the Error Subcode is set to Invalid Network Field. */
3074 while (pnt < end)
3076 prefixlen = *pnt++;
3078 /* Prefix length check. */
3079 if ((afi == AFI_IP && prefixlen > 32)
3080 || (afi == AFI_IP6 && prefixlen > 128))
3082 plog_err (peer->log,
3083 "%s [Error] Update packet error (wrong prefix length %d)",
3084 peer->host, prefixlen);
3085 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3086 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3087 return -1;
3090 /* Packet size overflow check. */
3091 psize = PSIZE (prefixlen);
3093 if (pnt + psize > end)
3095 plog_err (peer->log,
3096 "%s [Error] Update packet error"
3097 " (prefix data overflow prefix size is %d)",
3098 peer->host, psize);
3099 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3100 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3101 return -1;
3104 pnt += psize;
3107 /* Packet length consistency check. */
3108 if (pnt != end)
3110 plog_err (peer->log,
3111 "%s [Error] Update packet error"
3112 " (prefix length mismatch with total length)",
3113 peer->host);
3114 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3115 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3116 return -1;
3118 return 0;
3121 static struct bgp_static *
3122 bgp_static_new ()
3124 struct bgp_static *new;
3125 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3126 memset (new, 0, sizeof (struct bgp_static));
3127 return new;
3130 static void
3131 bgp_static_free (struct bgp_static *bgp_static)
3133 if (bgp_static->rmap.name)
3134 free (bgp_static->rmap.name);
3135 XFREE (MTYPE_BGP_STATIC, bgp_static);
3138 static void
3139 bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3140 struct prefix *p, afi_t afi, safi_t safi)
3142 struct bgp_node *rn;
3143 struct bgp_info *ri;
3145 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3147 /* Check selected route and self inserted route. */
3148 for (ri = rn->info; ri; ri = ri->next)
3149 if (ri->peer == bgp->peer_self
3150 && ri->type == ZEBRA_ROUTE_BGP
3151 && ri->sub_type == BGP_ROUTE_STATIC)
3152 break;
3154 /* Withdraw static BGP route from routing table. */
3155 if (ri)
3157 bgp_info_delete (rn, ri);
3158 bgp_process (bgp, rn, afi, safi);
3161 /* Unlock bgp_node_lookup. */
3162 bgp_unlock_node (rn);
3165 static void
3166 bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
3167 struct bgp_static *bgp_static,
3168 afi_t afi, safi_t safi)
3170 struct bgp_node *rn;
3171 struct bgp_info *ri;
3172 struct bgp_info *new;
3173 struct bgp_info info;
3174 struct attr *attr_new;
3175 struct attr attr = {0 };
3176 struct attr new_attr = { .extra = 0 };
3177 struct bgp *bgp;
3178 int ret;
3179 char buf[SU_ADDRSTRLEN];
3181 bgp = rsclient->bgp;
3183 assert (bgp_static);
3184 if (!bgp_static)
3185 return;
3187 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3189 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3191 attr.nexthop = bgp_static->igpnexthop;
3192 attr.med = bgp_static->igpmetric;
3193 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3195 if (bgp_static->ttl)
3197 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3198 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3199 attr.pathlimit.as = 0;
3200 attr.pathlimit.ttl = bgp_static->ttl;
3203 if (bgp_static->atomic)
3204 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3206 /* Apply network route-map for export to this rsclient. */
3207 if (bgp_static->rmap.name)
3209 struct attr attr_tmp = attr;
3210 info.peer = rsclient;
3211 info.attr = &attr_tmp;
3213 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3214 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3216 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3218 rsclient->rmap_type = 0;
3220 if (ret == RMAP_DENYMATCH)
3222 /* Free uninterned attribute. */
3223 bgp_attr_flush (&attr_tmp);
3225 /* Unintern original. */
3226 aspath_unintern (attr.aspath);
3227 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3228 bgp_attr_extra_free (&attr);
3230 return;
3232 attr_new = bgp_attr_intern (&attr_tmp);
3234 else
3235 attr_new = bgp_attr_intern (&attr);
3237 new_attr = *attr_new;
3239 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3241 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3242 == RMAP_DENY)
3244 /* This BGP update is filtered. Log the reason then update BGP entry. */
3245 if (BGP_DEBUG (update, UPDATE_IN))
3246 zlog (rsclient->log, LOG_DEBUG,
3247 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3248 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3249 p->prefixlen, rsclient->host);
3251 bgp->peer_self->rmap_type = 0;
3253 bgp_attr_unintern (attr_new);
3254 aspath_unintern (attr.aspath);
3255 bgp_attr_extra_free (&attr);
3257 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3259 return;
3262 bgp->peer_self->rmap_type = 0;
3264 bgp_attr_unintern (attr_new);
3265 attr_new = bgp_attr_intern (&new_attr);
3267 for (ri = rn->info; ri; ri = ri->next)
3268 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3269 && ri->sub_type == BGP_ROUTE_STATIC)
3270 break;
3272 if (ri)
3274 if (attrhash_cmp (ri->attr, attr_new) &&
3275 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3277 bgp_unlock_node (rn);
3278 bgp_attr_unintern (attr_new);
3279 aspath_unintern (attr.aspath);
3280 bgp_attr_extra_free (&attr);
3281 return;
3283 else
3285 /* The attribute is changed. */
3286 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3288 /* Rewrite BGP route information. */
3289 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3290 bgp_info_restore(rn, ri);
3291 bgp_attr_unintern (ri->attr);
3292 ri->attr = attr_new;
3293 ri->uptime = time (NULL);
3295 /* Process change. */
3296 bgp_process (bgp, rn, afi, safi);
3297 bgp_unlock_node (rn);
3298 aspath_unintern (attr.aspath);
3299 bgp_attr_extra_free (&attr);
3300 return;
3304 /* Make new BGP info. */
3305 new = bgp_info_new ();
3306 new->type = ZEBRA_ROUTE_BGP;
3307 new->sub_type = BGP_ROUTE_STATIC;
3308 new->peer = bgp->peer_self;
3309 SET_FLAG (new->flags, BGP_INFO_VALID);
3310 new->attr = attr_new;
3311 new->uptime = time (NULL);
3313 /* Register new BGP information. */
3314 bgp_info_add (rn, new);
3316 /* route_node_get lock */
3317 bgp_unlock_node (rn);
3319 /* Process change. */
3320 bgp_process (bgp, rn, afi, safi);
3322 /* Unintern original. */
3323 aspath_unintern (attr.aspath);
3324 bgp_attr_extra_free (&attr);
3327 static void
3328 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3329 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3331 struct bgp_node *rn;
3332 struct bgp_info *ri;
3333 struct bgp_info *new;
3334 struct bgp_info info;
3335 struct attr attr = { 0 };
3336 struct attr *attr_new;
3337 int ret;
3339 assert (bgp_static);
3340 if (!bgp_static)
3341 return;
3343 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3345 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3347 attr.nexthop = bgp_static->igpnexthop;
3348 attr.med = bgp_static->igpmetric;
3349 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3351 if (bgp_static->ttl)
3353 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3354 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3355 attr.pathlimit.as = 0;
3356 attr.pathlimit.ttl = bgp_static->ttl;
3359 if (bgp_static->atomic)
3360 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3362 /* Apply route-map. */
3363 if (bgp_static->rmap.name)
3365 struct attr attr_tmp = attr;
3366 info.peer = bgp->peer_self;
3367 info.attr = &attr_tmp;
3369 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3371 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3373 bgp->peer_self->rmap_type = 0;
3375 if (ret == RMAP_DENYMATCH)
3377 /* Free uninterned attribute. */
3378 bgp_attr_flush (&attr_tmp);
3380 /* Unintern original. */
3381 aspath_unintern (attr.aspath);
3382 bgp_attr_extra_free (&attr);
3383 bgp_static_withdraw (bgp, p, afi, safi);
3384 return;
3386 attr_new = bgp_attr_intern (&attr_tmp);
3388 else
3389 attr_new = bgp_attr_intern (&attr);
3391 for (ri = rn->info; ri; ri = ri->next)
3392 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3393 && ri->sub_type == BGP_ROUTE_STATIC)
3394 break;
3396 if (ri)
3398 if (attrhash_cmp (ri->attr, attr_new) &&
3399 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3401 bgp_unlock_node (rn);
3402 bgp_attr_unintern (attr_new);
3403 aspath_unintern (attr.aspath);
3404 bgp_attr_extra_free (&attr);
3405 return;
3407 else
3409 /* The attribute is changed. */
3410 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3412 /* Rewrite BGP route information. */
3413 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3414 bgp_info_restore(rn, ri);
3415 else
3416 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3417 bgp_attr_unintern (ri->attr);
3418 ri->attr = attr_new;
3419 ri->uptime = time (NULL);
3421 /* Process change. */
3422 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3423 bgp_process (bgp, rn, afi, safi);
3424 bgp_unlock_node (rn);
3425 aspath_unintern (attr.aspath);
3426 bgp_attr_extra_free (&attr);
3427 return;
3431 /* Make new BGP info. */
3432 new = bgp_info_new ();
3433 new->type = ZEBRA_ROUTE_BGP;
3434 new->sub_type = BGP_ROUTE_STATIC;
3435 new->peer = bgp->peer_self;
3436 SET_FLAG (new->flags, BGP_INFO_VALID);
3437 new->attr = attr_new;
3438 new->uptime = time (NULL);
3440 /* Aggregate address increment. */
3441 bgp_aggregate_increment (bgp, p, new, afi, safi);
3443 /* Register new BGP information. */
3444 bgp_info_add (rn, new);
3446 /* route_node_get lock */
3447 bgp_unlock_node (rn);
3449 /* Process change. */
3450 bgp_process (bgp, rn, afi, safi);
3452 /* Unintern original. */
3453 aspath_unintern (attr.aspath);
3454 bgp_attr_extra_free (&attr);
3457 void
3458 bgp_static_update (struct bgp *bgp, struct prefix *p,
3459 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3461 struct peer *rsclient;
3462 struct listnode *node, *nnode;
3464 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3466 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
3468 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3469 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3473 static void
3474 bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3475 u_char safi, struct prefix_rd *prd, u_char *tag)
3477 struct bgp_node *rn;
3478 struct bgp_info *new;
3480 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3482 /* Make new BGP info. */
3483 new = bgp_info_new ();
3484 new->type = ZEBRA_ROUTE_BGP;
3485 new->sub_type = BGP_ROUTE_STATIC;
3486 new->peer = bgp->peer_self;
3487 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3488 SET_FLAG (new->flags, BGP_INFO_VALID);
3489 new->uptime = time (NULL);
3490 new->extra = bgp_info_extra_new();
3491 memcpy (new->extra->tag, tag, 3);
3493 /* Aggregate address increment. */
3494 bgp_aggregate_increment (bgp, p, new, afi, safi);
3496 /* Register new BGP information. */
3497 bgp_info_add (rn, new);
3499 /* route_node_get lock */
3500 bgp_unlock_node (rn);
3502 /* Process change. */
3503 bgp_process (bgp, rn, afi, safi);
3506 void
3507 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3508 safi_t safi)
3510 struct bgp_node *rn;
3511 struct bgp_info *ri;
3513 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3515 /* Check selected route and self inserted route. */
3516 for (ri = rn->info; ri; ri = ri->next)
3517 if (ri->peer == bgp->peer_self
3518 && ri->type == ZEBRA_ROUTE_BGP
3519 && ri->sub_type == BGP_ROUTE_STATIC)
3520 break;
3522 /* Withdraw static BGP route from routing table. */
3523 if (ri)
3525 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3526 bgp_info_delete (rn, ri);
3527 bgp_process (bgp, rn, afi, safi);
3530 /* Unlock bgp_node_lookup. */
3531 bgp_unlock_node (rn);
3534 void
3535 bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3537 struct bgp_static *bgp_static;
3538 struct bgp *bgp;
3539 struct bgp_node *rn;
3540 struct prefix *p;
3542 bgp = rsclient->bgp;
3544 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3545 if ((bgp_static = rn->info) != NULL)
3547 p = &rn->p;
3549 bgp_static_update_rsclient (rsclient, p, bgp_static,
3550 afi, safi);
3554 static void
3555 bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3556 u_char safi, struct prefix_rd *prd, u_char *tag)
3558 struct bgp_node *rn;
3559 struct bgp_info *ri;
3561 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3563 /* Check selected route and self inserted route. */
3564 for (ri = rn->info; ri; ri = ri->next)
3565 if (ri->peer == bgp->peer_self
3566 && ri->type == ZEBRA_ROUTE_BGP
3567 && ri->sub_type == BGP_ROUTE_STATIC)
3568 break;
3570 /* Withdraw static BGP route from routing table. */
3571 if (ri)
3573 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3574 bgp_info_delete (rn, ri);
3575 bgp_process (bgp, rn, afi, safi);
3578 /* Unlock bgp_node_lookup. */
3579 bgp_unlock_node (rn);
3582 static void
3583 bgp_pathlimit_update_parents (struct bgp *bgp, struct bgp_node *rn,
3584 int ttl_edge)
3586 struct bgp_node *parent = rn;
3587 struct bgp_static *sp;
3589 /* Existing static changed TTL, search parents and adjust their atomic */
3590 while ((parent = parent->parent))
3591 if ((sp = parent->info))
3593 int sp_level = (sp->atomic ? 1 : 0);
3594 ttl_edge ? sp->atomic++ : sp->atomic--;
3596 /* did we change state of parent whether atomic is set or not? */
3597 if (sp_level != (sp->atomic ? 1 : 0))
3599 bgp_static_update (bgp, &parent->p, sp,
3600 rn->table->afi, rn->table->safi);
3605 /* Configure static BGP network. When user don't run zebra, static
3606 route should be installed as valid. */
3607 static int
3608 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3609 u_int16_t afi, u_char safi, const char *rmap, int backdoor,
3610 u_char ttl)
3612 int ret;
3613 struct prefix p;
3614 struct bgp_static *bgp_static;
3615 struct bgp_node *rn;
3616 u_char need_update = 0;
3617 u_char ttl_change = 0;
3618 u_char ttl_edge = (ttl ? 1 : 0);
3619 u_char new = 0;
3621 /* Convert IP prefix string to struct prefix. */
3622 ret = str2prefix (ip_str, &p);
3623 if (! ret)
3625 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3626 return CMD_WARNING;
3628 #ifdef HAVE_IPV6
3629 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3631 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3632 VTY_NEWLINE);
3633 return CMD_WARNING;
3635 #endif /* HAVE_IPV6 */
3637 apply_mask (&p);
3639 /* Set BGP static route configuration. */
3640 rn = bgp_node_get (bgp->route[afi][safi], &p);
3642 if (rn->info)
3644 /* Configuration change. */
3645 bgp_static = rn->info;
3647 /* Check previous routes are installed into BGP. */
3648 if (bgp_static->valid)
3650 if (bgp_static->backdoor != backdoor
3651 || bgp_static->ttl != ttl)
3652 need_update = 1;
3655 /* need to catch TTL set/unset transitions for handling of
3656 * ATOMIC_AGGREGATE
3658 if ((bgp_static->ttl ? 1 : 0) != ttl_edge)
3659 ttl_change = 1;
3661 bgp_static->backdoor = backdoor;
3662 bgp_static->ttl = ttl;
3664 if (rmap)
3666 if (bgp_static->rmap.name)
3667 free (bgp_static->rmap.name);
3668 bgp_static->rmap.name = strdup (rmap);
3669 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3671 else
3673 if (bgp_static->rmap.name)
3674 free (bgp_static->rmap.name);
3675 bgp_static->rmap.name = NULL;
3676 bgp_static->rmap.map = NULL;
3677 bgp_static->valid = 0;
3679 bgp_unlock_node (rn);
3681 else
3683 /* New configuration. */
3684 bgp_static = bgp_static_new ();
3685 bgp_static->backdoor = backdoor;
3686 bgp_static->valid = 0;
3687 bgp_static->igpmetric = 0;
3688 bgp_static->igpnexthop.s_addr = 0;
3689 bgp_static->ttl = ttl;
3690 ttl_change = ttl_edge;
3691 new = 1;
3693 if (rmap)
3695 if (bgp_static->rmap.name)
3696 free (bgp_static->rmap.name);
3697 bgp_static->rmap.name = strdup (rmap);
3698 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3700 rn->info = bgp_static;
3703 /* ".. sites that choose to advertise the
3704 * AS_PATHLIMIT path attribute SHOULD advertise the ATOMIC_AGGREGATE on
3705 * all less specific covering prefixes as well as the more specific
3706 * prefixes."
3708 * So:
3709 * Prefix that has just had pathlimit set/unset:
3710 * - Must bump ATOMIC refcount on all parents.
3712 * To catch less specific prefixes:
3713 * - Must search children for ones with TTL, bump atomic refcount
3714 * (we dont care if we're deleting a less specific prefix..)
3716 if (ttl_change)
3718 /* Existing static changed TTL, search parents and adjust their atomic */
3719 bgp_pathlimit_update_parents (bgp, rn, ttl_edge);
3722 if (new)
3724 struct bgp_node *child;
3725 struct bgp_static *sc;
3727 /* New static, search children and bump this statics atomic.. */
3728 child = bgp_lock_node (rn); /* route_next_until unlocks it.. */
3729 while ((child = bgp_route_next_until (child, rn)))
3731 if ((sc = child->info) && sc->ttl)
3732 bgp_static->atomic++;
3736 /* If BGP scan is not enabled, we should install this route here. */
3737 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3739 bgp_static->valid = 1;
3741 if (need_update)
3742 bgp_static_withdraw (bgp, &p, afi, safi);
3744 if (! bgp_static->backdoor)
3745 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3748 return CMD_SUCCESS;
3751 /* Configure static BGP network. */
3752 static int
3753 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
3754 u_int16_t afi, u_char safi)
3756 int ret;
3757 struct prefix p;
3758 struct bgp_static *bgp_static;
3759 struct bgp_node *rn;
3761 /* Convert IP prefix string to struct prefix. */
3762 ret = str2prefix (ip_str, &p);
3763 if (! ret)
3765 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3766 return CMD_WARNING;
3768 #ifdef HAVE_IPV6
3769 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3771 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3772 VTY_NEWLINE);
3773 return CMD_WARNING;
3775 #endif /* HAVE_IPV6 */
3777 apply_mask (&p);
3779 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3780 if (! rn)
3782 vty_out (vty, "%% Can't find specified static route configuration.%s",
3783 VTY_NEWLINE);
3784 return CMD_WARNING;
3787 bgp_static = rn->info;
3789 /* decrement atomic in parents, see bgp_static_set */
3790 bgp_pathlimit_update_parents (bgp, rn, 0);
3792 /* Update BGP RIB. */
3793 if (! bgp_static->backdoor)
3794 bgp_static_withdraw (bgp, &p, afi, safi);
3796 /* Clear configuration. */
3797 bgp_static_free (bgp_static);
3798 rn->info = NULL;
3799 bgp_unlock_node (rn);
3800 bgp_unlock_node (rn);
3802 return CMD_SUCCESS;
3805 /* Called from bgp_delete(). Delete all static routes from the BGP
3806 instance. */
3807 void
3808 bgp_static_delete (struct bgp *bgp)
3810 afi_t afi;
3811 safi_t safi;
3812 struct bgp_node *rn;
3813 struct bgp_node *rm;
3814 struct bgp_table *table;
3815 struct bgp_static *bgp_static;
3817 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3818 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3819 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3820 if (rn->info != NULL)
3822 if (safi == SAFI_MPLS_VPN)
3824 table = rn->info;
3826 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3828 bgp_static = rn->info;
3829 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3830 AFI_IP, SAFI_MPLS_VPN,
3831 (struct prefix_rd *)&rn->p,
3832 bgp_static->tag);
3833 bgp_static_free (bgp_static);
3834 rn->info = NULL;
3835 bgp_unlock_node (rn);
3838 else
3840 bgp_static = rn->info;
3841 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3842 bgp_static_free (bgp_static);
3843 rn->info = NULL;
3844 bgp_unlock_node (rn);
3850 bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3851 const char *tag_str)
3853 int ret;
3854 struct prefix p;
3855 struct prefix_rd prd;
3856 struct bgp *bgp;
3857 struct bgp_node *prn;
3858 struct bgp_node *rn;
3859 struct bgp_table *table;
3860 struct bgp_static *bgp_static;
3861 u_char tag[3];
3863 bgp = vty->index;
3865 ret = str2prefix (ip_str, &p);
3866 if (! ret)
3868 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3869 return CMD_WARNING;
3871 apply_mask (&p);
3873 ret = str2prefix_rd (rd_str, &prd);
3874 if (! ret)
3876 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3877 return CMD_WARNING;
3880 ret = str2tag (tag_str, tag);
3881 if (! ret)
3883 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3884 return CMD_WARNING;
3887 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3888 (struct prefix *)&prd);
3889 if (prn->info == NULL)
3890 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3891 else
3892 bgp_unlock_node (prn);
3893 table = prn->info;
3895 rn = bgp_node_get (table, &p);
3897 if (rn->info)
3899 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3900 bgp_unlock_node (rn);
3902 else
3904 /* New configuration. */
3905 bgp_static = bgp_static_new ();
3906 bgp_static->valid = 1;
3907 memcpy (bgp_static->tag, tag, 3);
3908 rn->info = bgp_static;
3910 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3913 return CMD_SUCCESS;
3916 /* Configure static BGP network. */
3918 bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3919 const char *rd_str, const char *tag_str)
3921 int ret;
3922 struct bgp *bgp;
3923 struct prefix p;
3924 struct prefix_rd prd;
3925 struct bgp_node *prn;
3926 struct bgp_node *rn;
3927 struct bgp_table *table;
3928 struct bgp_static *bgp_static;
3929 u_char tag[3];
3931 bgp = vty->index;
3933 /* Convert IP prefix string to struct prefix. */
3934 ret = str2prefix (ip_str, &p);
3935 if (! ret)
3937 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3938 return CMD_WARNING;
3940 apply_mask (&p);
3942 ret = str2prefix_rd (rd_str, &prd);
3943 if (! ret)
3945 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3946 return CMD_WARNING;
3949 ret = str2tag (tag_str, tag);
3950 if (! ret)
3952 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3953 return CMD_WARNING;
3956 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3957 (struct prefix *)&prd);
3958 if (prn->info == NULL)
3959 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3960 else
3961 bgp_unlock_node (prn);
3962 table = prn->info;
3964 rn = bgp_node_lookup (table, &p);
3966 if (rn)
3968 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3970 bgp_static = rn->info;
3971 bgp_static_free (bgp_static);
3972 rn->info = NULL;
3973 bgp_unlock_node (rn);
3974 bgp_unlock_node (rn);
3976 else
3977 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3979 return CMD_SUCCESS;
3982 DEFUN (bgp_network,
3983 bgp_network_cmd,
3984 "network A.B.C.D/M",
3985 "Specify a network to announce via BGP\n"
3986 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3988 u_char ttl = 0;
3990 if (argc == 2)
3991 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
3993 return bgp_static_set (vty, vty->index, argv[0],
3994 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
3997 ALIAS (bgp_network,
3998 bgp_network_ttl_cmd,
3999 "network A.B.C.D/M pathlimit <0-255>",
4000 "Specify a network to announce via BGP\n"
4001 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4002 "AS-Path hopcount limit attribute\n"
4003 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4005 DEFUN (bgp_network_route_map,
4006 bgp_network_route_map_cmd,
4007 "network A.B.C.D/M route-map WORD",
4008 "Specify a network to announce via BGP\n"
4009 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4010 "Route-map to modify the attributes\n"
4011 "Name of the route map\n")
4013 return bgp_static_set (vty, vty->index, argv[0],
4014 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
4017 DEFUN (bgp_network_backdoor,
4018 bgp_network_backdoor_cmd,
4019 "network A.B.C.D/M backdoor",
4020 "Specify a network to announce via BGP\n"
4021 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4022 "Specify a BGP backdoor route\n")
4024 u_char ttl = 0;
4026 if (argc == 2)
4027 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4029 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4030 NULL, 1, ttl);
4033 ALIAS (bgp_network_backdoor,
4034 bgp_network_backdoor_ttl_cmd,
4035 "network A.B.C.D/M backdoor pathlimit <0-255>",
4036 "Specify a network to announce via BGP\n"
4037 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4038 "Specify a BGP backdoor route\n"
4039 "AS-Path hopcount limit attribute\n"
4040 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4042 DEFUN (bgp_network_mask,
4043 bgp_network_mask_cmd,
4044 "network A.B.C.D mask A.B.C.D",
4045 "Specify a network to announce via BGP\n"
4046 "Network number\n"
4047 "Network mask\n"
4048 "Network mask\n")
4050 int ret;
4051 char prefix_str[BUFSIZ];
4052 u_char ttl = 0;
4054 if (argc == 3)
4055 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4057 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4058 if (! ret)
4060 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4061 return CMD_WARNING;
4064 return bgp_static_set (vty, vty->index, prefix_str,
4065 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
4068 ALIAS (bgp_network_mask,
4069 bgp_network_mask_ttl_cmd,
4070 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4071 "Specify a network to announce via BGP\n"
4072 "Network number\n"
4073 "Network mask\n"
4074 "Network mask\n"
4075 "AS-Path hopcount limit attribute\n"
4076 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4078 DEFUN (bgp_network_mask_route_map,
4079 bgp_network_mask_route_map_cmd,
4080 "network A.B.C.D mask A.B.C.D route-map WORD",
4081 "Specify a network to announce via BGP\n"
4082 "Network number\n"
4083 "Network mask\n"
4084 "Network mask\n"
4085 "Route-map to modify the attributes\n"
4086 "Name of the route map\n")
4088 int ret;
4089 char prefix_str[BUFSIZ];
4091 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4092 if (! ret)
4094 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4095 return CMD_WARNING;
4098 return bgp_static_set (vty, vty->index, prefix_str,
4099 AFI_IP, bgp_node_safi (vty), argv[2], 0, 0);
4102 DEFUN (bgp_network_mask_backdoor,
4103 bgp_network_mask_backdoor_cmd,
4104 "network A.B.C.D mask A.B.C.D backdoor",
4105 "Specify a network to announce via BGP\n"
4106 "Network number\n"
4107 "Network mask\n"
4108 "Network mask\n"
4109 "Specify a BGP backdoor route\n")
4111 int ret;
4112 char prefix_str[BUFSIZ];
4113 u_char ttl = 0;
4115 if (argc == 3)
4116 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4118 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4119 if (! ret)
4121 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4122 return CMD_WARNING;
4125 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4126 NULL, 1, ttl);
4129 ALIAS (bgp_network_mask_backdoor,
4130 bgp_network_mask_backdoor_ttl_cmd,
4131 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4132 "Specify a network to announce via BGP\n"
4133 "Network number\n"
4134 "Network mask\n"
4135 "Network mask\n"
4136 "Specify a BGP backdoor route\n"
4137 "AS-Path hopcount limit attribute\n"
4138 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4140 DEFUN (bgp_network_mask_natural,
4141 bgp_network_mask_natural_cmd,
4142 "network A.B.C.D",
4143 "Specify a network to announce via BGP\n"
4144 "Network number\n")
4146 int ret;
4147 char prefix_str[BUFSIZ];
4148 u_char ttl = 0;
4150 if (argc == 2)
4151 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4153 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4154 if (! ret)
4156 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4157 return CMD_WARNING;
4160 return bgp_static_set (vty, vty->index, prefix_str,
4161 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
4164 ALIAS (bgp_network_mask_natural,
4165 bgp_network_mask_natural_ttl_cmd,
4166 "network A.B.C.D pathlimit <0-255>",
4167 "Specify a network to announce via BGP\n"
4168 "Network number\n"
4169 "AS-Path hopcount limit attribute\n"
4170 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4172 DEFUN (bgp_network_mask_natural_route_map,
4173 bgp_network_mask_natural_route_map_cmd,
4174 "network A.B.C.D route-map WORD",
4175 "Specify a network to announce via BGP\n"
4176 "Network number\n"
4177 "Route-map to modify the attributes\n"
4178 "Name of the route map\n")
4180 int ret;
4181 char prefix_str[BUFSIZ];
4183 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4184 if (! ret)
4186 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4187 return CMD_WARNING;
4190 return bgp_static_set (vty, vty->index, prefix_str,
4191 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
4194 DEFUN (bgp_network_mask_natural_backdoor,
4195 bgp_network_mask_natural_backdoor_cmd,
4196 "network A.B.C.D backdoor",
4197 "Specify a network to announce via BGP\n"
4198 "Network number\n"
4199 "Specify a BGP backdoor route\n")
4201 int ret;
4202 char prefix_str[BUFSIZ];
4203 u_char ttl = 0;
4205 if (argc == 2)
4206 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4208 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4209 if (! ret)
4211 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4212 return CMD_WARNING;
4215 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4216 NULL, 1, ttl);
4219 ALIAS (bgp_network_mask_natural_backdoor,
4220 bgp_network_mask_natural_backdoor_ttl_cmd,
4221 "network A.B.C.D backdoor pathlimit (1-255>",
4222 "Specify a network to announce via BGP\n"
4223 "Network number\n"
4224 "Specify a BGP backdoor route\n"
4225 "AS-Path hopcount limit attribute\n"
4226 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4228 DEFUN (no_bgp_network,
4229 no_bgp_network_cmd,
4230 "no network A.B.C.D/M",
4231 NO_STR
4232 "Specify a network to announce via BGP\n"
4233 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4235 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4236 bgp_node_safi (vty));
4239 ALIAS (no_bgp_network,
4240 no_bgp_network_ttl_cmd,
4241 "no network A.B.C.D/M pathlimit <0-255>",
4242 NO_STR
4243 "Specify a network to announce via BGP\n"
4244 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4245 "AS-Path hopcount limit attribute\n"
4246 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4248 ALIAS (no_bgp_network,
4249 no_bgp_network_route_map_cmd,
4250 "no network A.B.C.D/M route-map WORD",
4251 NO_STR
4252 "Specify a network to announce via BGP\n"
4253 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4254 "Route-map to modify the attributes\n"
4255 "Name of the route map\n")
4257 ALIAS (no_bgp_network,
4258 no_bgp_network_backdoor_cmd,
4259 "no network A.B.C.D/M backdoor",
4260 NO_STR
4261 "Specify a network to announce via BGP\n"
4262 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4263 "Specify a BGP backdoor route\n")
4265 ALIAS (no_bgp_network,
4266 no_bgp_network_backdoor_ttl_cmd,
4267 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4268 NO_STR
4269 "Specify a network to announce via BGP\n"
4270 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4271 "Specify a BGP backdoor route\n"
4272 "AS-Path hopcount limit attribute\n"
4273 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4275 DEFUN (no_bgp_network_mask,
4276 no_bgp_network_mask_cmd,
4277 "no network A.B.C.D mask A.B.C.D",
4278 NO_STR
4279 "Specify a network to announce via BGP\n"
4280 "Network number\n"
4281 "Network mask\n"
4282 "Network mask\n")
4284 int ret;
4285 char prefix_str[BUFSIZ];
4287 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4288 if (! ret)
4290 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4291 return CMD_WARNING;
4294 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4295 bgp_node_safi (vty));
4298 ALIAS (no_bgp_network,
4299 no_bgp_network_mask_ttl_cmd,
4300 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4301 NO_STR
4302 "Specify a network to announce via BGP\n"
4303 "Network number\n"
4304 "Network mask\n"
4305 "Network mask\n"
4306 "AS-Path hopcount limit attribute\n"
4307 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4309 ALIAS (no_bgp_network_mask,
4310 no_bgp_network_mask_route_map_cmd,
4311 "no network A.B.C.D mask A.B.C.D route-map WORD",
4312 NO_STR
4313 "Specify a network to announce via BGP\n"
4314 "Network number\n"
4315 "Network mask\n"
4316 "Network mask\n"
4317 "Route-map to modify the attributes\n"
4318 "Name of the route map\n")
4320 ALIAS (no_bgp_network_mask,
4321 no_bgp_network_mask_backdoor_cmd,
4322 "no network A.B.C.D mask A.B.C.D backdoor",
4323 NO_STR
4324 "Specify a network to announce via BGP\n"
4325 "Network number\n"
4326 "Network mask\n"
4327 "Network mask\n"
4328 "Specify a BGP backdoor route\n")
4330 ALIAS (no_bgp_network_mask,
4331 no_bgp_network_mask_backdoor_ttl_cmd,
4332 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4333 NO_STR
4334 "Specify a network to announce via BGP\n"
4335 "Network number\n"
4336 "Network mask\n"
4337 "Network mask\n"
4338 "Specify a BGP backdoor route\n"
4339 "AS-Path hopcount limit attribute\n"
4340 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4342 DEFUN (no_bgp_network_mask_natural,
4343 no_bgp_network_mask_natural_cmd,
4344 "no network A.B.C.D",
4345 NO_STR
4346 "Specify a network to announce via BGP\n"
4347 "Network number\n")
4349 int ret;
4350 char prefix_str[BUFSIZ];
4352 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4353 if (! ret)
4355 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4356 return CMD_WARNING;
4359 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4360 bgp_node_safi (vty));
4363 ALIAS (no_bgp_network_mask_natural,
4364 no_bgp_network_mask_natural_route_map_cmd,
4365 "no network A.B.C.D route-map WORD",
4366 NO_STR
4367 "Specify a network to announce via BGP\n"
4368 "Network number\n"
4369 "Route-map to modify the attributes\n"
4370 "Name of the route map\n")
4372 ALIAS (no_bgp_network_mask_natural,
4373 no_bgp_network_mask_natural_backdoor_cmd,
4374 "no network A.B.C.D backdoor",
4375 NO_STR
4376 "Specify a network to announce via BGP\n"
4377 "Network number\n"
4378 "Specify a BGP backdoor route\n")
4380 ALIAS (no_bgp_network_mask_natural,
4381 no_bgp_network_mask_natural_ttl_cmd,
4382 "no network A.B.C.D pathlimit <0-255>",
4383 NO_STR
4384 "Specify a network to announce via BGP\n"
4385 "Network number\n"
4386 "AS-Path hopcount limit attribute\n"
4387 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4389 ALIAS (no_bgp_network_mask_natural,
4390 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4391 "no network A.B.C.D backdoor pathlimit <0-255>",
4392 NO_STR
4393 "Specify a network to announce via BGP\n"
4394 "Network number\n"
4395 "Specify a BGP backdoor route\n"
4396 "AS-Path hopcount limit attribute\n"
4397 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4399 #ifdef HAVE_IPV6
4400 DEFUN (ipv6_bgp_network,
4401 ipv6_bgp_network_cmd,
4402 "network X:X::X:X/M",
4403 "Specify a network to announce via BGP\n"
4404 "IPv6 prefix <network>/<length>\n")
4406 u_char ttl = 0;
4408 if (argc == 2)
4409 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4411 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
4412 NULL, 0, ttl);
4415 ALIAS (ipv6_bgp_network,
4416 ipv6_bgp_network_ttl_cmd,
4417 "network X:X::X:X/M pathlimit <0-255>",
4418 "Specify a network to announce via BGP\n"
4419 "IPv6 prefix <network>/<length>\n"
4420 "AS-Path hopcount limit attribute\n"
4421 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4423 DEFUN (ipv6_bgp_network_route_map,
4424 ipv6_bgp_network_route_map_cmd,
4425 "network X:X::X:X/M route-map WORD",
4426 "Specify a network to announce via BGP\n"
4427 "IPv6 prefix <network>/<length>\n"
4428 "Route-map to modify the attributes\n"
4429 "Name of the route map\n")
4431 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4432 bgp_node_safi (vty), argv[1], 0, 0);
4435 DEFUN (no_ipv6_bgp_network,
4436 no_ipv6_bgp_network_cmd,
4437 "no network X:X::X:X/M",
4438 NO_STR
4439 "Specify a network to announce via BGP\n"
4440 "IPv6 prefix <network>/<length>\n")
4442 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4445 ALIAS (no_ipv6_bgp_network,
4446 no_ipv6_bgp_network_route_map_cmd,
4447 "no network X:X::X:X/M route-map WORD",
4448 NO_STR
4449 "Specify a network to announce via BGP\n"
4450 "IPv6 prefix <network>/<length>\n"
4451 "Route-map to modify the attributes\n"
4452 "Name of the route map\n")
4454 ALIAS (no_ipv6_bgp_network,
4455 no_ipv6_bgp_network_ttl_cmd,
4456 "no network X:X::X:X/M pathlimit <0-255>",
4457 NO_STR
4458 "Specify a network to announce via BGP\n"
4459 "IPv6 prefix <network>/<length>\n"
4460 "AS-Path hopcount limit attribute\n"
4461 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4463 ALIAS (ipv6_bgp_network,
4464 old_ipv6_bgp_network_cmd,
4465 "ipv6 bgp network X:X::X:X/M",
4466 IPV6_STR
4467 BGP_STR
4468 "Specify a network to announce via BGP\n"
4469 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4471 ALIAS (no_ipv6_bgp_network,
4472 old_no_ipv6_bgp_network_cmd,
4473 "no ipv6 bgp network X:X::X:X/M",
4474 NO_STR
4475 IPV6_STR
4476 BGP_STR
4477 "Specify a network to announce via BGP\n"
4478 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4479 #endif /* HAVE_IPV6 */
4481 /* Aggreagete address:
4483 advertise-map Set condition to advertise attribute
4484 as-set Generate AS set path information
4485 attribute-map Set attributes of aggregate
4486 route-map Set parameters of aggregate
4487 summary-only Filter more specific routes from updates
4488 suppress-map Conditionally filter more specific routes from updates
4489 <cr>
4491 struct bgp_aggregate
4493 /* Summary-only flag. */
4494 u_char summary_only;
4496 /* AS set generation. */
4497 u_char as_set;
4499 /* Route-map for aggregated route. */
4500 struct route_map *map;
4502 /* Suppress-count. */
4503 unsigned long count;
4505 /* SAFI configuration. */
4506 safi_t safi;
4509 static struct bgp_aggregate *
4510 bgp_aggregate_new ()
4512 struct bgp_aggregate *new;
4513 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4514 memset (new, 0, sizeof (struct bgp_aggregate));
4515 return new;
4518 static void
4519 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4521 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4524 static void
4525 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4526 afi_t afi, safi_t safi, struct bgp_info *del,
4527 struct bgp_aggregate *aggregate)
4529 struct bgp_table *table;
4530 struct bgp_node *top;
4531 struct bgp_node *rn;
4532 u_char origin;
4533 struct aspath *aspath = NULL;
4534 struct aspath *asmerge = NULL;
4535 struct community *community = NULL;
4536 struct community *commerge = NULL;
4537 struct in_addr nexthop;
4538 u_int32_t med = 0;
4539 struct bgp_info *ri;
4540 struct bgp_info *new;
4541 int first = 1;
4542 unsigned long match = 0;
4544 /* Record adding route's nexthop and med. */
4545 if (rinew)
4547 nexthop = rinew->attr->nexthop;
4548 med = rinew->attr->med;
4551 /* ORIGIN attribute: If at least one route among routes that are
4552 aggregated has ORIGIN with the value INCOMPLETE, then the
4553 aggregated route must have the ORIGIN attribute with the value
4554 INCOMPLETE. Otherwise, if at least one route among routes that
4555 are aggregated has ORIGIN with the value EGP, then the aggregated
4556 route must have the origin attribute with the value EGP. In all
4557 other case the value of the ORIGIN attribute of the aggregated
4558 route is INTERNAL. */
4559 origin = BGP_ORIGIN_IGP;
4561 table = bgp->rib[afi][safi];
4563 top = bgp_node_get (table, p);
4564 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4565 if (rn->p.prefixlen > p->prefixlen)
4567 match = 0;
4569 for (ri = rn->info; ri; ri = ri->next)
4571 if (BGP_INFO_HOLDDOWN (ri))
4572 continue;
4574 if (del && ri == del)
4575 continue;
4577 if (! rinew && first)
4579 nexthop = ri->attr->nexthop;
4580 med = ri->attr->med;
4581 first = 0;
4584 #ifdef AGGREGATE_NEXTHOP_CHECK
4585 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4586 || ri->attr->med != med)
4588 if (aspath)
4589 aspath_free (aspath);
4590 if (community)
4591 community_free (community);
4592 bgp_unlock_node (rn);
4593 bgp_unlock_node (top);
4594 return;
4596 #endif /* AGGREGATE_NEXTHOP_CHECK */
4598 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4600 if (aggregate->summary_only)
4602 (bgp_info_extra_get (ri))->suppress++;
4603 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4604 match++;
4607 aggregate->count++;
4609 if (aggregate->as_set)
4611 if (origin < ri->attr->origin)
4612 origin = ri->attr->origin;
4614 if (aspath)
4616 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4617 aspath_free (aspath);
4618 aspath = asmerge;
4620 else
4621 aspath = aspath_dup (ri->attr->aspath);
4623 if (ri->attr->community)
4625 if (community)
4627 commerge = community_merge (community,
4628 ri->attr->community);
4629 community = community_uniq_sort (commerge);
4630 community_free (commerge);
4632 else
4633 community = community_dup (ri->attr->community);
4638 if (match)
4639 bgp_process (bgp, rn, afi, safi);
4641 bgp_unlock_node (top);
4643 if (rinew)
4645 aggregate->count++;
4647 if (aggregate->summary_only)
4648 (bgp_info_extra_get (rinew))->suppress++;
4650 if (aggregate->as_set)
4652 if (origin < rinew->attr->origin)
4653 origin = rinew->attr->origin;
4655 if (aspath)
4657 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4658 aspath_free (aspath);
4659 aspath = asmerge;
4661 else
4662 aspath = aspath_dup (rinew->attr->aspath);
4664 if (rinew->attr->community)
4666 if (community)
4668 commerge = community_merge (community,
4669 rinew->attr->community);
4670 community = community_uniq_sort (commerge);
4671 community_free (commerge);
4673 else
4674 community = community_dup (rinew->attr->community);
4679 if (aggregate->count > 0)
4681 rn = bgp_node_get (table, p);
4682 new = bgp_info_new ();
4683 new->type = ZEBRA_ROUTE_BGP;
4684 new->sub_type = BGP_ROUTE_AGGREGATE;
4685 new->peer = bgp->peer_self;
4686 SET_FLAG (new->flags, BGP_INFO_VALID);
4687 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4688 new->uptime = time (NULL);
4690 bgp_info_add (rn, new);
4691 bgp_unlock_node (rn);
4692 bgp_process (bgp, rn, afi, safi);
4694 else
4696 if (aspath)
4697 aspath_free (aspath);
4698 if (community)
4699 community_free (community);
4703 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4704 struct bgp_aggregate *);
4706 void
4707 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4708 struct bgp_info *ri, afi_t afi, safi_t safi)
4710 struct bgp_node *child;
4711 struct bgp_node *rn;
4712 struct bgp_aggregate *aggregate;
4714 /* MPLS-VPN aggregation is not yet supported. */
4715 if (safi == SAFI_MPLS_VPN)
4716 return;
4718 if (p->prefixlen == 0)
4719 return;
4721 if (BGP_INFO_HOLDDOWN (ri))
4722 return;
4724 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4726 /* Aggregate address configuration check. */
4727 for (rn = child; rn; rn = rn->parent)
4728 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4730 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4731 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
4733 bgp_unlock_node (child);
4736 void
4737 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4738 struct bgp_info *del, afi_t afi, safi_t safi)
4740 struct bgp_node *child;
4741 struct bgp_node *rn;
4742 struct bgp_aggregate *aggregate;
4744 /* MPLS-VPN aggregation is not yet supported. */
4745 if (safi == SAFI_MPLS_VPN)
4746 return;
4748 if (p->prefixlen == 0)
4749 return;
4751 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4753 /* Aggregate address configuration check. */
4754 for (rn = child; rn; rn = rn->parent)
4755 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4757 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4758 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
4760 bgp_unlock_node (child);
4763 static void
4764 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4765 struct bgp_aggregate *aggregate)
4767 struct bgp_table *table;
4768 struct bgp_node *top;
4769 struct bgp_node *rn;
4770 struct bgp_info *new;
4771 struct bgp_info *ri;
4772 unsigned long match;
4773 u_char origin = BGP_ORIGIN_IGP;
4774 struct aspath *aspath = NULL;
4775 struct aspath *asmerge = NULL;
4776 struct community *community = NULL;
4777 struct community *commerge = NULL;
4779 table = bgp->rib[afi][safi];
4781 /* Sanity check. */
4782 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4783 return;
4784 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4785 return;
4787 /* If routes exists below this node, generate aggregate routes. */
4788 top = bgp_node_get (table, p);
4789 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4790 if (rn->p.prefixlen > p->prefixlen)
4792 match = 0;
4794 for (ri = rn->info; ri; ri = ri->next)
4796 if (BGP_INFO_HOLDDOWN (ri))
4797 continue;
4799 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4801 /* summary-only aggregate route suppress aggregated
4802 route announcement. */
4803 if (aggregate->summary_only)
4805 (bgp_info_extra_get (ri))->suppress++;
4806 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4807 match++;
4809 /* as-set aggregate route generate origin, as path,
4810 community aggregation. */
4811 if (aggregate->as_set)
4813 if (origin < ri->attr->origin)
4814 origin = ri->attr->origin;
4816 if (aspath)
4818 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4819 aspath_free (aspath);
4820 aspath = asmerge;
4822 else
4823 aspath = aspath_dup (ri->attr->aspath);
4825 if (ri->attr->community)
4827 if (community)
4829 commerge = community_merge (community,
4830 ri->attr->community);
4831 community = community_uniq_sort (commerge);
4832 community_free (commerge);
4834 else
4835 community = community_dup (ri->attr->community);
4838 aggregate->count++;
4842 /* If this node is suppressed, process the change. */
4843 if (match)
4844 bgp_process (bgp, rn, afi, safi);
4846 bgp_unlock_node (top);
4848 /* Add aggregate route to BGP table. */
4849 if (aggregate->count)
4851 rn = bgp_node_get (table, p);
4853 new = bgp_info_new ();
4854 new->type = ZEBRA_ROUTE_BGP;
4855 new->sub_type = BGP_ROUTE_AGGREGATE;
4856 new->peer = bgp->peer_self;
4857 SET_FLAG (new->flags, BGP_INFO_VALID);
4858 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4859 new->uptime = time (NULL);
4861 bgp_info_add (rn, new);
4862 bgp_unlock_node (rn);
4864 /* Process change. */
4865 bgp_process (bgp, rn, afi, safi);
4869 void
4870 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4871 safi_t safi, struct bgp_aggregate *aggregate)
4873 struct bgp_table *table;
4874 struct bgp_node *top;
4875 struct bgp_node *rn;
4876 struct bgp_info *ri;
4877 unsigned long match;
4879 table = bgp->rib[afi][safi];
4881 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4882 return;
4883 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4884 return;
4886 /* If routes exists below this node, generate aggregate routes. */
4887 top = bgp_node_get (table, p);
4888 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4889 if (rn->p.prefixlen > p->prefixlen)
4891 match = 0;
4893 for (ri = rn->info; ri; ri = ri->next)
4895 if (BGP_INFO_HOLDDOWN (ri))
4896 continue;
4898 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4900 if (aggregate->summary_only && ri->extra)
4902 ri->extra->suppress--;
4904 if (ri->extra->suppress == 0)
4906 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4907 match++;
4910 aggregate->count--;
4914 /* If this node was suppressed, process the change. */
4915 if (match)
4916 bgp_process (bgp, rn, afi, safi);
4918 bgp_unlock_node (top);
4920 /* Delete aggregate route from BGP table. */
4921 rn = bgp_node_get (table, p);
4923 for (ri = rn->info; ri; ri = ri->next)
4924 if (ri->peer == bgp->peer_self
4925 && ri->type == ZEBRA_ROUTE_BGP
4926 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4927 break;
4929 /* Withdraw static BGP route from routing table. */
4930 if (ri)
4932 bgp_info_delete (rn, ri);
4933 bgp_process (bgp, rn, afi, safi);
4936 /* Unlock bgp_node_lookup. */
4937 bgp_unlock_node (rn);
4940 /* Aggregate route attribute. */
4941 #define AGGREGATE_SUMMARY_ONLY 1
4942 #define AGGREGATE_AS_SET 1
4944 static int
4945 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4946 afi_t afi, safi_t safi,
4947 u_char summary_only, u_char as_set)
4949 int ret;
4950 struct prefix p;
4951 struct bgp_node *rn;
4952 struct bgp *bgp;
4953 struct bgp_aggregate *aggregate;
4955 /* Convert string to prefix structure. */
4956 ret = str2prefix (prefix_str, &p);
4957 if (!ret)
4959 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4960 return CMD_WARNING;
4962 apply_mask (&p);
4964 /* Get BGP structure. */
4965 bgp = vty->index;
4967 /* Old configuration check. */
4968 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4970 if (rn->info)
4972 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4973 bgp_unlock_node (rn);
4974 return CMD_WARNING;
4977 /* Make aggregate address structure. */
4978 aggregate = bgp_aggregate_new ();
4979 aggregate->summary_only = summary_only;
4980 aggregate->as_set = as_set;
4981 aggregate->safi = safi;
4982 rn->info = aggregate;
4984 /* Aggregate address insert into BGP routing table. */
4985 if (safi & SAFI_UNICAST)
4986 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4987 if (safi & SAFI_MULTICAST)
4988 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4990 return CMD_SUCCESS;
4993 static int
4994 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4995 afi_t afi, safi_t safi)
4997 int ret;
4998 struct prefix p;
4999 struct bgp_node *rn;
5000 struct bgp *bgp;
5001 struct bgp_aggregate *aggregate;
5003 /* Convert string to prefix structure. */
5004 ret = str2prefix (prefix_str, &p);
5005 if (!ret)
5007 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5008 return CMD_WARNING;
5010 apply_mask (&p);
5012 /* Get BGP structure. */
5013 bgp = vty->index;
5015 /* Old configuration check. */
5016 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5017 if (! rn)
5019 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5020 VTY_NEWLINE);
5021 return CMD_WARNING;
5024 aggregate = rn->info;
5025 if (aggregate->safi & SAFI_UNICAST)
5026 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5027 if (aggregate->safi & SAFI_MULTICAST)
5028 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5030 /* Unlock aggregate address configuration. */
5031 rn->info = NULL;
5032 bgp_aggregate_free (aggregate);
5033 bgp_unlock_node (rn);
5034 bgp_unlock_node (rn);
5036 return CMD_SUCCESS;
5039 DEFUN (aggregate_address,
5040 aggregate_address_cmd,
5041 "aggregate-address A.B.C.D/M",
5042 "Configure BGP aggregate entries\n"
5043 "Aggregate prefix\n")
5045 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5048 DEFUN (aggregate_address_mask,
5049 aggregate_address_mask_cmd,
5050 "aggregate-address A.B.C.D A.B.C.D",
5051 "Configure BGP aggregate entries\n"
5052 "Aggregate address\n"
5053 "Aggregate mask\n")
5055 int ret;
5056 char prefix_str[BUFSIZ];
5058 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5060 if (! ret)
5062 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5063 return CMD_WARNING;
5066 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5067 0, 0);
5070 DEFUN (aggregate_address_summary_only,
5071 aggregate_address_summary_only_cmd,
5072 "aggregate-address A.B.C.D/M summary-only",
5073 "Configure BGP aggregate entries\n"
5074 "Aggregate prefix\n"
5075 "Filter more specific routes from updates\n")
5077 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5078 AGGREGATE_SUMMARY_ONLY, 0);
5081 DEFUN (aggregate_address_mask_summary_only,
5082 aggregate_address_mask_summary_only_cmd,
5083 "aggregate-address A.B.C.D A.B.C.D summary-only",
5084 "Configure BGP aggregate entries\n"
5085 "Aggregate address\n"
5086 "Aggregate mask\n"
5087 "Filter more specific routes from updates\n")
5089 int ret;
5090 char prefix_str[BUFSIZ];
5092 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5094 if (! ret)
5096 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5097 return CMD_WARNING;
5100 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5101 AGGREGATE_SUMMARY_ONLY, 0);
5104 DEFUN (aggregate_address_as_set,
5105 aggregate_address_as_set_cmd,
5106 "aggregate-address A.B.C.D/M as-set",
5107 "Configure BGP aggregate entries\n"
5108 "Aggregate prefix\n"
5109 "Generate AS set path information\n")
5111 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5112 0, AGGREGATE_AS_SET);
5115 DEFUN (aggregate_address_mask_as_set,
5116 aggregate_address_mask_as_set_cmd,
5117 "aggregate-address A.B.C.D A.B.C.D as-set",
5118 "Configure BGP aggregate entries\n"
5119 "Aggregate address\n"
5120 "Aggregate mask\n"
5121 "Generate AS set path information\n")
5123 int ret;
5124 char prefix_str[BUFSIZ];
5126 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5128 if (! ret)
5130 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5131 return CMD_WARNING;
5134 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5135 0, AGGREGATE_AS_SET);
5139 DEFUN (aggregate_address_as_set_summary,
5140 aggregate_address_as_set_summary_cmd,
5141 "aggregate-address A.B.C.D/M as-set summary-only",
5142 "Configure BGP aggregate entries\n"
5143 "Aggregate prefix\n"
5144 "Generate AS set path information\n"
5145 "Filter more specific routes from updates\n")
5147 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5148 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5151 ALIAS (aggregate_address_as_set_summary,
5152 aggregate_address_summary_as_set_cmd,
5153 "aggregate-address A.B.C.D/M summary-only as-set",
5154 "Configure BGP aggregate entries\n"
5155 "Aggregate prefix\n"
5156 "Filter more specific routes from updates\n"
5157 "Generate AS set path information\n")
5159 DEFUN (aggregate_address_mask_as_set_summary,
5160 aggregate_address_mask_as_set_summary_cmd,
5161 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5162 "Configure BGP aggregate entries\n"
5163 "Aggregate address\n"
5164 "Aggregate mask\n"
5165 "Generate AS set path information\n"
5166 "Filter more specific routes from updates\n")
5168 int ret;
5169 char prefix_str[BUFSIZ];
5171 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5173 if (! ret)
5175 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5176 return CMD_WARNING;
5179 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5180 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5183 ALIAS (aggregate_address_mask_as_set_summary,
5184 aggregate_address_mask_summary_as_set_cmd,
5185 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5186 "Configure BGP aggregate entries\n"
5187 "Aggregate address\n"
5188 "Aggregate mask\n"
5189 "Filter more specific routes from updates\n"
5190 "Generate AS set path information\n")
5192 DEFUN (no_aggregate_address,
5193 no_aggregate_address_cmd,
5194 "no aggregate-address A.B.C.D/M",
5195 NO_STR
5196 "Configure BGP aggregate entries\n"
5197 "Aggregate prefix\n")
5199 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5202 ALIAS (no_aggregate_address,
5203 no_aggregate_address_summary_only_cmd,
5204 "no aggregate-address A.B.C.D/M summary-only",
5205 NO_STR
5206 "Configure BGP aggregate entries\n"
5207 "Aggregate prefix\n"
5208 "Filter more specific routes from updates\n")
5210 ALIAS (no_aggregate_address,
5211 no_aggregate_address_as_set_cmd,
5212 "no aggregate-address A.B.C.D/M as-set",
5213 NO_STR
5214 "Configure BGP aggregate entries\n"
5215 "Aggregate prefix\n"
5216 "Generate AS set path information\n")
5218 ALIAS (no_aggregate_address,
5219 no_aggregate_address_as_set_summary_cmd,
5220 "no aggregate-address A.B.C.D/M as-set summary-only",
5221 NO_STR
5222 "Configure BGP aggregate entries\n"
5223 "Aggregate prefix\n"
5224 "Generate AS set path information\n"
5225 "Filter more specific routes from updates\n")
5227 ALIAS (no_aggregate_address,
5228 no_aggregate_address_summary_as_set_cmd,
5229 "no aggregate-address A.B.C.D/M summary-only as-set",
5230 NO_STR
5231 "Configure BGP aggregate entries\n"
5232 "Aggregate prefix\n"
5233 "Filter more specific routes from updates\n"
5234 "Generate AS set path information\n")
5236 DEFUN (no_aggregate_address_mask,
5237 no_aggregate_address_mask_cmd,
5238 "no aggregate-address A.B.C.D A.B.C.D",
5239 NO_STR
5240 "Configure BGP aggregate entries\n"
5241 "Aggregate address\n"
5242 "Aggregate mask\n")
5244 int ret;
5245 char prefix_str[BUFSIZ];
5247 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5249 if (! ret)
5251 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5252 return CMD_WARNING;
5255 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5258 ALIAS (no_aggregate_address_mask,
5259 no_aggregate_address_mask_summary_only_cmd,
5260 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5261 NO_STR
5262 "Configure BGP aggregate entries\n"
5263 "Aggregate address\n"
5264 "Aggregate mask\n"
5265 "Filter more specific routes from updates\n")
5267 ALIAS (no_aggregate_address_mask,
5268 no_aggregate_address_mask_as_set_cmd,
5269 "no aggregate-address A.B.C.D A.B.C.D as-set",
5270 NO_STR
5271 "Configure BGP aggregate entries\n"
5272 "Aggregate address\n"
5273 "Aggregate mask\n"
5274 "Generate AS set path information\n")
5276 ALIAS (no_aggregate_address_mask,
5277 no_aggregate_address_mask_as_set_summary_cmd,
5278 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5279 NO_STR
5280 "Configure BGP aggregate entries\n"
5281 "Aggregate address\n"
5282 "Aggregate mask\n"
5283 "Generate AS set path information\n"
5284 "Filter more specific routes from updates\n")
5286 ALIAS (no_aggregate_address_mask,
5287 no_aggregate_address_mask_summary_as_set_cmd,
5288 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5289 NO_STR
5290 "Configure BGP aggregate entries\n"
5291 "Aggregate address\n"
5292 "Aggregate mask\n"
5293 "Filter more specific routes from updates\n"
5294 "Generate AS set path information\n")
5296 #ifdef HAVE_IPV6
5297 DEFUN (ipv6_aggregate_address,
5298 ipv6_aggregate_address_cmd,
5299 "aggregate-address X:X::X:X/M",
5300 "Configure BGP aggregate entries\n"
5301 "Aggregate prefix\n")
5303 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5306 DEFUN (ipv6_aggregate_address_summary_only,
5307 ipv6_aggregate_address_summary_only_cmd,
5308 "aggregate-address X:X::X:X/M summary-only",
5309 "Configure BGP aggregate entries\n"
5310 "Aggregate prefix\n"
5311 "Filter more specific routes from updates\n")
5313 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5314 AGGREGATE_SUMMARY_ONLY, 0);
5317 DEFUN (no_ipv6_aggregate_address,
5318 no_ipv6_aggregate_address_cmd,
5319 "no aggregate-address X:X::X:X/M",
5320 NO_STR
5321 "Configure BGP aggregate entries\n"
5322 "Aggregate prefix\n")
5324 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5327 DEFUN (no_ipv6_aggregate_address_summary_only,
5328 no_ipv6_aggregate_address_summary_only_cmd,
5329 "no aggregate-address X:X::X:X/M summary-only",
5330 NO_STR
5331 "Configure BGP aggregate entries\n"
5332 "Aggregate prefix\n"
5333 "Filter more specific routes from updates\n")
5335 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5338 ALIAS (ipv6_aggregate_address,
5339 old_ipv6_aggregate_address_cmd,
5340 "ipv6 bgp aggregate-address X:X::X:X/M",
5341 IPV6_STR
5342 BGP_STR
5343 "Configure BGP aggregate entries\n"
5344 "Aggregate prefix\n")
5346 ALIAS (ipv6_aggregate_address_summary_only,
5347 old_ipv6_aggregate_address_summary_only_cmd,
5348 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5349 IPV6_STR
5350 BGP_STR
5351 "Configure BGP aggregate entries\n"
5352 "Aggregate prefix\n"
5353 "Filter more specific routes from updates\n")
5355 ALIAS (no_ipv6_aggregate_address,
5356 old_no_ipv6_aggregate_address_cmd,
5357 "no ipv6 bgp aggregate-address X:X::X:X/M",
5358 NO_STR
5359 IPV6_STR
5360 BGP_STR
5361 "Configure BGP aggregate entries\n"
5362 "Aggregate prefix\n")
5364 ALIAS (no_ipv6_aggregate_address_summary_only,
5365 old_no_ipv6_aggregate_address_summary_only_cmd,
5366 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5367 NO_STR
5368 IPV6_STR
5369 BGP_STR
5370 "Configure BGP aggregate entries\n"
5371 "Aggregate prefix\n"
5372 "Filter more specific routes from updates\n")
5373 #endif /* HAVE_IPV6 */
5375 /* Redistribute route treatment. */
5376 void
5377 bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5378 u_int32_t metric, u_char type)
5380 struct bgp *bgp;
5381 struct listnode *node, *nnode;
5382 struct bgp_info *new;
5383 struct bgp_info *bi;
5384 struct bgp_info info;
5385 struct bgp_node *bn;
5386 struct attr attr = { 0 };
5387 struct attr attr_new = { 0 };
5388 struct attr *new_attr;
5389 afi_t afi;
5390 int ret;
5392 /* Make default attribute. */
5393 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5394 if (nexthop)
5395 attr.nexthop = *nexthop;
5397 attr.med = metric;
5398 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5400 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5402 afi = family2afi (p->family);
5404 if (bgp->redist[afi][type])
5406 /* Copy attribute for modification. */
5407 bgp_attr_dup (&attr_new, &attr);
5409 if (bgp->redist_metric_flag[afi][type])
5410 attr_new.med = bgp->redist_metric[afi][type];
5412 /* Apply route-map. */
5413 if (bgp->rmap[afi][type].map)
5415 info.peer = bgp->peer_self;
5416 info.attr = &attr_new;
5418 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5420 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5421 &info);
5423 bgp->peer_self->rmap_type = 0;
5425 if (ret == RMAP_DENYMATCH)
5427 /* Free uninterned attribute. */
5428 bgp_attr_flush (&attr_new);
5429 bgp_attr_extra_free (&attr_new);
5431 /* Unintern original. */
5432 aspath_unintern (attr.aspath);
5433 bgp_attr_extra_free (&attr);
5434 bgp_redistribute_delete (p, type);
5435 return;
5439 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5440 afi, SAFI_UNICAST, p, NULL);
5442 new_attr = bgp_attr_intern (&attr_new);
5443 bgp_attr_extra_free (&attr_new);
5445 for (bi = bn->info; bi; bi = bi->next)
5446 if (bi->peer == bgp->peer_self
5447 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5448 break;
5450 if (bi)
5452 if (attrhash_cmp (bi->attr, new_attr) &&
5453 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5455 bgp_attr_unintern (new_attr);
5456 aspath_unintern (attr.aspath);
5457 bgp_attr_extra_free (&attr);
5458 bgp_unlock_node (bn);
5459 return;
5461 else
5463 /* The attribute is changed. */
5464 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5466 /* Rewrite BGP route information. */
5467 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5468 bgp_info_restore(bn, bi);
5469 else
5470 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5471 bgp_attr_unintern (bi->attr);
5472 bi->attr = new_attr;
5473 bi->uptime = time (NULL);
5475 /* Process change. */
5476 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5477 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5478 bgp_unlock_node (bn);
5479 aspath_unintern (attr.aspath);
5480 bgp_attr_extra_free (&attr);
5481 return;
5485 new = bgp_info_new ();
5486 new->type = type;
5487 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5488 new->peer = bgp->peer_self;
5489 SET_FLAG (new->flags, BGP_INFO_VALID);
5490 new->attr = new_attr;
5491 new->uptime = time (NULL);
5493 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5494 bgp_info_add (bn, new);
5495 bgp_unlock_node (bn);
5496 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5500 /* Unintern original. */
5501 aspath_unintern (attr.aspath);
5502 bgp_attr_extra_free (&attr);
5505 void
5506 bgp_redistribute_delete (struct prefix *p, u_char type)
5508 struct bgp *bgp;
5509 struct listnode *node, *nnode;
5510 afi_t afi;
5511 struct bgp_node *rn;
5512 struct bgp_info *ri;
5514 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5516 afi = family2afi (p->family);
5518 if (bgp->redist[afi][type])
5520 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5522 for (ri = rn->info; ri; ri = ri->next)
5523 if (ri->peer == bgp->peer_self
5524 && ri->type == type)
5525 break;
5527 if (ri)
5529 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5530 bgp_info_delete (rn, ri);
5531 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5533 bgp_unlock_node (rn);
5538 /* Withdraw specified route type's route. */
5539 void
5540 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5542 struct bgp_node *rn;
5543 struct bgp_info *ri;
5544 struct bgp_table *table;
5546 table = bgp->rib[afi][SAFI_UNICAST];
5548 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5550 for (ri = rn->info; ri; ri = ri->next)
5551 if (ri->peer == bgp->peer_self
5552 && ri->type == type)
5553 break;
5555 if (ri)
5557 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5558 bgp_info_delete (rn, ri);
5559 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5564 /* Static function to display route. */
5565 static void
5566 route_vty_out_route (struct prefix *p, struct vty *vty)
5568 int len;
5569 u_int32_t destination;
5570 char buf[BUFSIZ];
5572 if (p->family == AF_INET)
5574 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5575 destination = ntohl (p->u.prefix4.s_addr);
5577 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5578 || (IN_CLASSB (destination) && p->prefixlen == 16)
5579 || (IN_CLASSA (destination) && p->prefixlen == 8)
5580 || p->u.prefix4.s_addr == 0)
5582 /* When mask is natural, mask is not displayed. */
5584 else
5585 len += vty_out (vty, "/%d", p->prefixlen);
5587 else
5588 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5589 p->prefixlen);
5591 len = 17 - len;
5592 if (len < 1)
5593 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5594 else
5595 vty_out (vty, "%*s", len, " ");
5598 enum bgp_display_type
5600 normal_list,
5603 /* Print the short form route status for a bgp_info */
5604 static void
5605 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
5607 /* Route status display. */
5608 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5609 vty_out (vty, "R");
5610 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5611 vty_out (vty, "S");
5612 else if (binfo->extra && binfo->extra->suppress)
5613 vty_out (vty, "s");
5614 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5615 vty_out (vty, "*");
5616 else
5617 vty_out (vty, " ");
5619 /* Selected */
5620 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5621 vty_out (vty, "h");
5622 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5623 vty_out (vty, "d");
5624 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5625 vty_out (vty, ">");
5626 else
5627 vty_out (vty, " ");
5629 /* Internal route. */
5630 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5631 vty_out (vty, "i");
5632 else
5633 vty_out (vty, " ");
5636 /* called from terminal list command */
5637 void
5638 route_vty_out (struct vty *vty, struct prefix *p,
5639 struct bgp_info *binfo, int display, safi_t safi)
5641 struct attr *attr;
5643 /* short status lead text */
5644 route_vty_short_status_out (vty, binfo);
5646 /* print prefix and mask */
5647 if (! display)
5648 route_vty_out_route (p, vty);
5649 else
5650 vty_out (vty, "%*s", 17, " ");
5652 /* Print attribute */
5653 attr = binfo->attr;
5654 if (attr)
5656 if (p->family == AF_INET)
5658 if (safi == SAFI_MPLS_VPN)
5659 vty_out (vty, "%-16s",
5660 inet_ntoa (attr->extra->mp_nexthop_global_in));
5661 else
5662 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5664 #ifdef HAVE_IPV6
5665 else if (p->family == AF_INET6)
5667 int len;
5668 char buf[BUFSIZ];
5670 len = vty_out (vty, "%s",
5671 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5672 buf, BUFSIZ));
5673 len = 16 - len;
5674 if (len < 1)
5675 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5676 else
5677 vty_out (vty, "%*s", len, " ");
5679 #endif /* HAVE_IPV6 */
5681 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5682 vty_out (vty, "%10d", attr->med);
5683 else
5684 vty_out (vty, " ");
5686 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5687 vty_out (vty, "%7d", attr->local_pref);
5688 else
5689 vty_out (vty, " ");
5691 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
5693 /* Print aspath */
5694 if (attr->aspath)
5695 aspath_print_vty (vty, "%s", attr->aspath, " ");
5697 /* Print origin */
5698 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5700 vty_out (vty, "%s", VTY_NEWLINE);
5703 /* called from terminal list command */
5704 void
5705 route_vty_out_tmp (struct vty *vty, struct prefix *p,
5706 struct attr *attr, safi_t safi)
5708 /* Route status display. */
5709 vty_out (vty, "*");
5710 vty_out (vty, ">");
5711 vty_out (vty, " ");
5713 /* print prefix and mask */
5714 route_vty_out_route (p, vty);
5716 /* Print attribute */
5717 if (attr)
5719 if (p->family == AF_INET)
5721 if (safi == SAFI_MPLS_VPN)
5722 vty_out (vty, "%-16s",
5723 inet_ntoa (attr->extra->mp_nexthop_global_in));
5724 else
5725 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5727 #ifdef HAVE_IPV6
5728 else if (p->family == AF_INET6)
5730 int len;
5731 char buf[BUFSIZ];
5733 assert (attr->extra);
5735 len = vty_out (vty, "%s",
5736 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5737 buf, BUFSIZ));
5738 len = 16 - len;
5739 if (len < 1)
5740 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5741 else
5742 vty_out (vty, "%*s", len, " ");
5744 #endif /* HAVE_IPV6 */
5746 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5747 vty_out (vty, "%10d", attr->med);
5748 else
5749 vty_out (vty, " ");
5751 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5752 vty_out (vty, "%7d", attr->local_pref);
5753 else
5754 vty_out (vty, " ");
5756 vty_out (vty, "%7d ", (attr->extra ? attr->extra->weight : 0));
5758 /* Print aspath */
5759 if (attr->aspath)
5760 aspath_print_vty (vty, "%s", attr->aspath, " ");
5762 /* Print origin */
5763 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5766 vty_out (vty, "%s", VTY_NEWLINE);
5769 void
5770 route_vty_out_tag (struct vty *vty, struct prefix *p,
5771 struct bgp_info *binfo, int display, safi_t safi)
5773 struct attr *attr;
5774 u_int32_t label = 0;
5776 if (!binfo->extra)
5777 return;
5779 /* short status lead text */
5780 route_vty_short_status_out (vty, binfo);
5782 /* print prefix and mask */
5783 if (! display)
5784 route_vty_out_route (p, vty);
5785 else
5786 vty_out (vty, "%*s", 17, " ");
5788 /* Print attribute */
5789 attr = binfo->attr;
5790 if (attr)
5792 if (p->family == AF_INET)
5794 if (safi == SAFI_MPLS_VPN)
5795 vty_out (vty, "%-16s",
5796 inet_ntoa (attr->extra->mp_nexthop_global_in));
5797 else
5798 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5800 #ifdef HAVE_IPV6
5801 else if (p->family == AF_INET6)
5803 assert (attr->extra);
5804 char buf[BUFSIZ];
5805 char buf1[BUFSIZ];
5806 if (attr->extra->mp_nexthop_len == 16)
5807 vty_out (vty, "%s",
5808 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5809 buf, BUFSIZ));
5810 else if (attr->extra->mp_nexthop_len == 32)
5811 vty_out (vty, "%s(%s)",
5812 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5813 buf, BUFSIZ),
5814 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5815 buf1, BUFSIZ));
5818 #endif /* HAVE_IPV6 */
5821 label = decode_label (binfo->extra->tag);
5823 vty_out (vty, "notag/%d", label);
5825 vty_out (vty, "%s", VTY_NEWLINE);
5828 /* dampening route */
5829 static void
5830 damp_route_vty_out (struct vty *vty, struct prefix *p,
5831 struct bgp_info *binfo, int display, safi_t safi)
5833 struct attr *attr;
5834 int len;
5836 /* short status lead text */
5837 route_vty_short_status_out (vty, binfo);
5839 /* print prefix and mask */
5840 if (! display)
5841 route_vty_out_route (p, vty);
5842 else
5843 vty_out (vty, "%*s", 17, " ");
5845 len = vty_out (vty, "%s", binfo->peer->host);
5846 len = 17 - len;
5847 if (len < 1)
5848 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5849 else
5850 vty_out (vty, "%*s", len, " ");
5852 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5854 /* Print attribute */
5855 attr = binfo->attr;
5856 if (attr)
5858 /* Print aspath */
5859 if (attr->aspath)
5860 aspath_print_vty (vty, "%s", attr->aspath, " ");
5862 /* Print origin */
5863 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5865 vty_out (vty, "%s", VTY_NEWLINE);
5868 #define BGP_UPTIME_LEN 25
5870 /* flap route */
5871 static void
5872 flap_route_vty_out (struct vty *vty, struct prefix *p,
5873 struct bgp_info *binfo, int display, safi_t safi)
5875 struct attr *attr;
5876 struct bgp_damp_info *bdi;
5877 char timebuf[BGP_UPTIME_LEN];
5878 int len;
5880 if (!binfo->extra)
5881 return;
5883 bdi = binfo->extra->damp_info;
5885 /* short status lead text */
5886 route_vty_short_status_out (vty, binfo);
5888 /* print prefix and mask */
5889 if (! display)
5890 route_vty_out_route (p, vty);
5891 else
5892 vty_out (vty, "%*s", 17, " ");
5894 len = vty_out (vty, "%s", binfo->peer->host);
5895 len = 16 - len;
5896 if (len < 1)
5897 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5898 else
5899 vty_out (vty, "%*s", len, " ");
5901 len = vty_out (vty, "%d", bdi->flap);
5902 len = 5 - len;
5903 if (len < 1)
5904 vty_out (vty, " ");
5905 else
5906 vty_out (vty, "%*s ", len, " ");
5908 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5909 timebuf, BGP_UPTIME_LEN));
5911 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5912 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5913 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5914 else
5915 vty_out (vty, "%*s ", 8, " ");
5917 /* Print attribute */
5918 attr = binfo->attr;
5919 if (attr)
5921 /* Print aspath */
5922 if (attr->aspath)
5923 aspath_print_vty (vty, "%s", attr->aspath, " ");
5925 /* Print origin */
5926 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5928 vty_out (vty, "%s", VTY_NEWLINE);
5931 static void
5932 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5933 struct bgp_info *binfo, afi_t afi, safi_t safi)
5935 char buf[INET6_ADDRSTRLEN];
5936 char buf1[BUFSIZ];
5937 struct attr *attr;
5938 int sockunion_vty_out (struct vty *, union sockunion *);
5940 attr = binfo->attr;
5942 if (attr)
5944 /* Line1 display AS-path, Aggregator */
5945 if (attr->aspath)
5947 vty_out (vty, " ");
5948 if (aspath_count_hops (attr->aspath) == 0)
5949 vty_out (vty, "Local");
5950 else
5951 aspath_print_vty (vty, "%s", attr->aspath, "");
5954 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5955 vty_out (vty, ", (removed)");
5956 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5957 vty_out (vty, ", (stale)");
5958 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5959 vty_out (vty, ", (aggregated by %d %s)",
5960 attr->extra->aggregator_as,
5961 inet_ntoa (attr->extra->aggregator_addr));
5962 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5963 vty_out (vty, ", (Received from a RR-client)");
5964 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5965 vty_out (vty, ", (Received from a RS-client)");
5966 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5967 vty_out (vty, ", (history entry)");
5968 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5969 vty_out (vty, ", (suppressed due to dampening)");
5970 vty_out (vty, "%s", VTY_NEWLINE);
5972 /* Line2 display Next-hop, Neighbor, Router-id */
5973 if (p->family == AF_INET)
5975 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5976 inet_ntoa (attr->extra->mp_nexthop_global_in) :
5977 inet_ntoa (attr->nexthop));
5979 #ifdef HAVE_IPV6
5980 else
5982 assert (attr->extra);
5983 vty_out (vty, " %s",
5984 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5985 buf, INET6_ADDRSTRLEN));
5987 #endif /* HAVE_IPV6 */
5989 if (binfo->peer == bgp->peer_self)
5991 vty_out (vty, " from %s ",
5992 p->family == AF_INET ? "0.0.0.0" : "::");
5993 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5995 else
5997 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5998 vty_out (vty, " (inaccessible)");
5999 else if (binfo->extra && binfo->extra->igpmetric)
6000 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
6001 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
6002 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6003 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
6004 else
6005 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6007 vty_out (vty, "%s", VTY_NEWLINE);
6009 #ifdef HAVE_IPV6
6010 /* display nexthop local */
6011 if (attr->extra && attr->extra->mp_nexthop_len == 32)
6013 vty_out (vty, " (%s)%s",
6014 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6015 buf, INET6_ADDRSTRLEN),
6016 VTY_NEWLINE);
6018 #endif /* HAVE_IPV6 */
6020 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6021 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6023 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6024 vty_out (vty, ", metric %d", attr->med);
6026 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6027 vty_out (vty, ", localpref %d", attr->local_pref);
6028 else
6029 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6031 if (attr->extra && attr->extra->weight != 0)
6032 vty_out (vty, ", weight %d", attr->extra->weight);
6034 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6035 vty_out (vty, ", valid");
6037 if (binfo->peer != bgp->peer_self)
6039 if (binfo->peer->as == binfo->peer->local_as)
6040 vty_out (vty, ", internal");
6041 else
6042 vty_out (vty, ", %s",
6043 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6045 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6046 vty_out (vty, ", aggregated, local");
6047 else if (binfo->type != ZEBRA_ROUTE_BGP)
6048 vty_out (vty, ", sourced");
6049 else
6050 vty_out (vty, ", sourced, local");
6052 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6053 vty_out (vty, ", atomic-aggregate");
6055 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6056 vty_out (vty, ", best");
6058 vty_out (vty, "%s", VTY_NEWLINE);
6060 /* Line 4 display Community */
6061 if (attr->community)
6062 vty_out (vty, " Community: %s%s", attr->community->str,
6063 VTY_NEWLINE);
6065 /* Line 5 display Extended-community */
6066 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
6067 vty_out (vty, " Extended Community: %s%s",
6068 attr->extra->ecommunity->str, VTY_NEWLINE);
6070 /* Line 6 display Originator, Cluster-id */
6071 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6072 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6074 assert (attr->extra);
6075 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6076 vty_out (vty, " Originator: %s",
6077 inet_ntoa (attr->extra->originator_id));
6079 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6081 int i;
6082 vty_out (vty, ", Cluster list: ");
6083 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6084 vty_out (vty, "%s ",
6085 inet_ntoa (attr->extra->cluster->list[i]));
6087 vty_out (vty, "%s", VTY_NEWLINE);
6090 /* 7: AS Pathlimit */
6091 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6094 vty_out (vty, " AS-Pathlimit: %u",
6095 attr->pathlimit.ttl);
6096 if (attr->pathlimit.as)
6097 vty_out (vty, " (%u)", attr->pathlimit.as);
6098 vty_out (vty, "%s", VTY_NEWLINE);
6101 if (binfo->extra && binfo->extra->damp_info)
6102 bgp_damp_info_vty (vty, binfo);
6104 /* Line 7 display Uptime */
6105 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
6107 vty_out (vty, "%s", VTY_NEWLINE);
6110 #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"
6111 #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
6112 #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6113 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6114 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6116 enum bgp_show_type
6118 bgp_show_type_normal,
6119 bgp_show_type_regexp,
6120 bgp_show_type_prefix_list,
6121 bgp_show_type_filter_list,
6122 bgp_show_type_route_map,
6123 bgp_show_type_neighbor,
6124 bgp_show_type_cidr_only,
6125 bgp_show_type_prefix_longer,
6126 bgp_show_type_community_all,
6127 bgp_show_type_community,
6128 bgp_show_type_community_exact,
6129 bgp_show_type_community_list,
6130 bgp_show_type_community_list_exact,
6131 bgp_show_type_flap_statistics,
6132 bgp_show_type_flap_address,
6133 bgp_show_type_flap_prefix,
6134 bgp_show_type_flap_cidr_only,
6135 bgp_show_type_flap_regexp,
6136 bgp_show_type_flap_filter_list,
6137 bgp_show_type_flap_prefix_list,
6138 bgp_show_type_flap_prefix_longer,
6139 bgp_show_type_flap_route_map,
6140 bgp_show_type_flap_neighbor,
6141 bgp_show_type_dampend_paths,
6142 bgp_show_type_damp_neighbor
6145 static int
6146 bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
6147 enum bgp_show_type type, void *output_arg)
6149 struct bgp_info *ri;
6150 struct bgp_node *rn;
6151 int header = 1;
6152 int display;
6153 unsigned long output_count;
6155 /* This is first entry point, so reset total line. */
6156 output_count = 0;
6158 /* Start processing of routes. */
6159 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6160 if (rn->info != NULL)
6162 display = 0;
6164 for (ri = rn->info; ri; ri = ri->next)
6166 if (type == bgp_show_type_flap_statistics
6167 || type == bgp_show_type_flap_address
6168 || type == bgp_show_type_flap_prefix
6169 || type == bgp_show_type_flap_cidr_only
6170 || type == bgp_show_type_flap_regexp
6171 || type == bgp_show_type_flap_filter_list
6172 || type == bgp_show_type_flap_prefix_list
6173 || type == bgp_show_type_flap_prefix_longer
6174 || type == bgp_show_type_flap_route_map
6175 || type == bgp_show_type_flap_neighbor
6176 || type == bgp_show_type_dampend_paths
6177 || type == bgp_show_type_damp_neighbor)
6179 if (!(ri->extra && ri->extra->damp_info))
6180 continue;
6182 if (type == bgp_show_type_regexp
6183 || type == bgp_show_type_flap_regexp)
6185 regex_t *regex = output_arg;
6187 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6188 continue;
6190 if (type == bgp_show_type_prefix_list
6191 || type == bgp_show_type_flap_prefix_list)
6193 struct prefix_list *plist = output_arg;
6195 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6196 continue;
6198 if (type == bgp_show_type_filter_list
6199 || type == bgp_show_type_flap_filter_list)
6201 struct as_list *as_list = output_arg;
6203 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6204 continue;
6206 if (type == bgp_show_type_route_map
6207 || type == bgp_show_type_flap_route_map)
6209 struct route_map *rmap = output_arg;
6210 struct bgp_info binfo;
6211 struct attr dummy_attr = { 0 };
6212 int ret;
6214 bgp_attr_dup (&dummy_attr, ri->attr);
6215 binfo.peer = ri->peer;
6216 binfo.attr = &dummy_attr;
6218 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
6220 bgp_attr_extra_free (&dummy_attr);
6222 if (ret == RMAP_DENYMATCH)
6223 continue;
6225 if (type == bgp_show_type_neighbor
6226 || type == bgp_show_type_flap_neighbor
6227 || type == bgp_show_type_damp_neighbor)
6229 union sockunion *su = output_arg;
6231 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6232 continue;
6234 if (type == bgp_show_type_cidr_only
6235 || type == bgp_show_type_flap_cidr_only)
6237 u_int32_t destination;
6239 destination = ntohl (rn->p.u.prefix4.s_addr);
6240 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6241 continue;
6242 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6243 continue;
6244 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6245 continue;
6247 if (type == bgp_show_type_prefix_longer
6248 || type == bgp_show_type_flap_prefix_longer)
6250 struct prefix *p = output_arg;
6252 if (! prefix_match (p, &rn->p))
6253 continue;
6255 if (type == bgp_show_type_community_all)
6257 if (! ri->attr->community)
6258 continue;
6260 if (type == bgp_show_type_community)
6262 struct community *com = output_arg;
6264 if (! ri->attr->community ||
6265 ! community_match (ri->attr->community, com))
6266 continue;
6268 if (type == bgp_show_type_community_exact)
6270 struct community *com = output_arg;
6272 if (! ri->attr->community ||
6273 ! community_cmp (ri->attr->community, com))
6274 continue;
6276 if (type == bgp_show_type_community_list)
6278 struct community_list *list = output_arg;
6280 if (! community_list_match (ri->attr->community, list))
6281 continue;
6283 if (type == bgp_show_type_community_list_exact)
6285 struct community_list *list = output_arg;
6287 if (! community_list_exact_match (ri->attr->community, list))
6288 continue;
6290 if (type == bgp_show_type_flap_address
6291 || type == bgp_show_type_flap_prefix)
6293 struct prefix *p = output_arg;
6295 if (! prefix_match (&rn->p, p))
6296 continue;
6298 if (type == bgp_show_type_flap_prefix)
6299 if (p->prefixlen != rn->p.prefixlen)
6300 continue;
6302 if (type == bgp_show_type_dampend_paths
6303 || type == bgp_show_type_damp_neighbor)
6305 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6306 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6307 continue;
6310 if (header)
6312 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6313 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6314 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6315 if (type == bgp_show_type_dampend_paths
6316 || type == bgp_show_type_damp_neighbor)
6317 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6318 else if (type == bgp_show_type_flap_statistics
6319 || type == bgp_show_type_flap_address
6320 || type == bgp_show_type_flap_prefix
6321 || type == bgp_show_type_flap_cidr_only
6322 || type == bgp_show_type_flap_regexp
6323 || type == bgp_show_type_flap_filter_list
6324 || type == bgp_show_type_flap_prefix_list
6325 || type == bgp_show_type_flap_prefix_longer
6326 || type == bgp_show_type_flap_route_map
6327 || type == bgp_show_type_flap_neighbor)
6328 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6329 else
6330 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
6331 header = 0;
6334 if (type == bgp_show_type_dampend_paths
6335 || type == bgp_show_type_damp_neighbor)
6336 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6337 else if (type == bgp_show_type_flap_statistics
6338 || type == bgp_show_type_flap_address
6339 || type == bgp_show_type_flap_prefix
6340 || type == bgp_show_type_flap_cidr_only
6341 || type == bgp_show_type_flap_regexp
6342 || type == bgp_show_type_flap_filter_list
6343 || type == bgp_show_type_flap_prefix_list
6344 || type == bgp_show_type_flap_prefix_longer
6345 || type == bgp_show_type_flap_route_map
6346 || type == bgp_show_type_flap_neighbor)
6347 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6348 else
6349 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6350 display++;
6352 if (display)
6353 output_count++;
6356 /* No route is displayed */
6357 if (output_count == 0)
6359 if (type == bgp_show_type_normal)
6360 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6362 else
6363 vty_out (vty, "%sTotal number of prefixes %ld%s",
6364 VTY_NEWLINE, output_count, VTY_NEWLINE);
6366 return CMD_SUCCESS;
6369 static int
6370 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
6371 enum bgp_show_type type, void *output_arg)
6373 struct bgp_table *table;
6375 if (bgp == NULL) {
6376 bgp = bgp_get_default ();
6379 if (bgp == NULL)
6381 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6382 return CMD_WARNING;
6386 table = bgp->rib[afi][safi];
6388 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
6391 /* Header of detailed BGP route information */
6392 static void
6393 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6394 struct bgp_node *rn,
6395 struct prefix_rd *prd, afi_t afi, safi_t safi)
6397 struct bgp_info *ri;
6398 struct prefix *p;
6399 struct peer *peer;
6400 struct listnode *node, *nnode;
6401 char buf1[INET6_ADDRSTRLEN];
6402 char buf2[INET6_ADDRSTRLEN];
6403 int count = 0;
6404 int best = 0;
6405 int suppress = 0;
6406 int no_export = 0;
6407 int no_advertise = 0;
6408 int local_as = 0;
6409 int first = 0;
6411 p = &rn->p;
6412 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6413 (safi == SAFI_MPLS_VPN ?
6414 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6415 safi == SAFI_MPLS_VPN ? ":" : "",
6416 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6417 p->prefixlen, VTY_NEWLINE);
6419 for (ri = rn->info; ri; ri = ri->next)
6421 count++;
6422 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6424 best = count;
6425 if (ri->extra && ri->extra->suppress)
6426 suppress = 1;
6427 if (ri->attr->community != NULL)
6429 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6430 no_advertise = 1;
6431 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6432 no_export = 1;
6433 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6434 local_as = 1;
6439 vty_out (vty, "Paths: (%d available", count);
6440 if (best)
6442 vty_out (vty, ", best #%d", best);
6443 if (safi == SAFI_UNICAST)
6444 vty_out (vty, ", table Default-IP-Routing-Table");
6446 else
6447 vty_out (vty, ", no best path");
6448 if (no_advertise)
6449 vty_out (vty, ", not advertised to any peer");
6450 else if (no_export)
6451 vty_out (vty, ", not advertised to EBGP peer");
6452 else if (local_as)
6453 vty_out (vty, ", not advertised outside local AS");
6454 if (suppress)
6455 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6456 vty_out (vty, ")%s", VTY_NEWLINE);
6458 /* advertised peer */
6459 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6461 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6463 if (! first)
6464 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6465 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6466 first = 1;
6469 if (! first)
6470 vty_out (vty, " Not advertised to any peer");
6471 vty_out (vty, "%s", VTY_NEWLINE);
6474 /* Display specified route of BGP table. */
6475 static int
6476 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
6477 struct bgp_table *rib, const char *ip_str,
6478 afi_t afi, safi_t safi, struct prefix_rd *prd,
6479 int prefix_check)
6481 int ret;
6482 int header;
6483 int display = 0;
6484 struct prefix match;
6485 struct bgp_node *rn;
6486 struct bgp_node *rm;
6487 struct bgp_info *ri;
6488 struct bgp_table *table;
6490 /* Check IP address argument. */
6491 ret = str2prefix (ip_str, &match);
6492 if (! ret)
6494 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6495 return CMD_WARNING;
6498 match.family = afi2family (afi);
6500 if (safi == SAFI_MPLS_VPN)
6502 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
6504 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6505 continue;
6507 if ((table = rn->info) != NULL)
6509 header = 1;
6511 if ((rm = bgp_node_match (table, &match)) != NULL)
6513 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6514 continue;
6516 for (ri = rm->info; ri; ri = ri->next)
6518 if (header)
6520 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6521 AFI_IP, SAFI_MPLS_VPN);
6523 header = 0;
6525 display++;
6526 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6532 else
6534 header = 1;
6536 if ((rn = bgp_node_match (rib, &match)) != NULL)
6538 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6540 for (ri = rn->info; ri; ri = ri->next)
6542 if (header)
6544 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6545 header = 0;
6547 display++;
6548 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6554 if (! display)
6556 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6557 return CMD_WARNING;
6560 return CMD_SUCCESS;
6563 /* Display specified route of Main RIB */
6564 static int
6565 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
6566 afi_t afi, safi_t safi, struct prefix_rd *prd,
6567 int prefix_check)
6569 struct bgp *bgp;
6571 /* BGP structure lookup. */
6572 if (view_name)
6574 bgp = bgp_lookup_by_name (view_name);
6575 if (bgp == NULL)
6577 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6578 return CMD_WARNING;
6581 else
6583 bgp = bgp_get_default ();
6584 if (bgp == NULL)
6586 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6587 return CMD_WARNING;
6591 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6592 afi, safi, prd, prefix_check);
6595 /* BGP route print out function. */
6596 DEFUN (show_ip_bgp,
6597 show_ip_bgp_cmd,
6598 "show ip bgp",
6599 SHOW_STR
6600 IP_STR
6601 BGP_STR)
6603 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6606 DEFUN (show_ip_bgp_ipv4,
6607 show_ip_bgp_ipv4_cmd,
6608 "show ip bgp ipv4 (unicast|multicast)",
6609 SHOW_STR
6610 IP_STR
6611 BGP_STR
6612 "Address family\n"
6613 "Address Family modifier\n"
6614 "Address Family modifier\n")
6616 if (strncmp (argv[0], "m", 1) == 0)
6617 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6618 NULL);
6620 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6623 DEFUN (show_ip_bgp_route,
6624 show_ip_bgp_route_cmd,
6625 "show ip bgp A.B.C.D",
6626 SHOW_STR
6627 IP_STR
6628 BGP_STR
6629 "Network in the BGP routing table to display\n")
6631 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6634 DEFUN (show_ip_bgp_ipv4_route,
6635 show_ip_bgp_ipv4_route_cmd,
6636 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6637 SHOW_STR
6638 IP_STR
6639 BGP_STR
6640 "Address family\n"
6641 "Address Family modifier\n"
6642 "Address Family modifier\n"
6643 "Network in the BGP routing table to display\n")
6645 if (strncmp (argv[0], "m", 1) == 0)
6646 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6648 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6651 DEFUN (show_ip_bgp_vpnv4_all_route,
6652 show_ip_bgp_vpnv4_all_route_cmd,
6653 "show ip bgp vpnv4 all A.B.C.D",
6654 SHOW_STR
6655 IP_STR
6656 BGP_STR
6657 "Display VPNv4 NLRI specific information\n"
6658 "Display information about all VPNv4 NLRIs\n"
6659 "Network in the BGP routing table to display\n")
6661 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6664 DEFUN (show_ip_bgp_vpnv4_rd_route,
6665 show_ip_bgp_vpnv4_rd_route_cmd,
6666 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6667 SHOW_STR
6668 IP_STR
6669 BGP_STR
6670 "Display VPNv4 NLRI specific information\n"
6671 "Display information for a route distinguisher\n"
6672 "VPN Route Distinguisher\n"
6673 "Network in the BGP routing table to display\n")
6675 int ret;
6676 struct prefix_rd prd;
6678 ret = str2prefix_rd (argv[0], &prd);
6679 if (! ret)
6681 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6682 return CMD_WARNING;
6684 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6687 DEFUN (show_ip_bgp_prefix,
6688 show_ip_bgp_prefix_cmd,
6689 "show ip bgp A.B.C.D/M",
6690 SHOW_STR
6691 IP_STR
6692 BGP_STR
6693 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6695 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6698 DEFUN (show_ip_bgp_ipv4_prefix,
6699 show_ip_bgp_ipv4_prefix_cmd,
6700 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6701 SHOW_STR
6702 IP_STR
6703 BGP_STR
6704 "Address family\n"
6705 "Address Family modifier\n"
6706 "Address Family modifier\n"
6707 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6709 if (strncmp (argv[0], "m", 1) == 0)
6710 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6712 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6715 DEFUN (show_ip_bgp_vpnv4_all_prefix,
6716 show_ip_bgp_vpnv4_all_prefix_cmd,
6717 "show ip bgp vpnv4 all A.B.C.D/M",
6718 SHOW_STR
6719 IP_STR
6720 BGP_STR
6721 "Display VPNv4 NLRI specific information\n"
6722 "Display information about all VPNv4 NLRIs\n"
6723 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6725 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6728 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6729 show_ip_bgp_vpnv4_rd_prefix_cmd,
6730 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6731 SHOW_STR
6732 IP_STR
6733 BGP_STR
6734 "Display VPNv4 NLRI specific information\n"
6735 "Display information for a route distinguisher\n"
6736 "VPN Route Distinguisher\n"
6737 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6739 int ret;
6740 struct prefix_rd prd;
6742 ret = str2prefix_rd (argv[0], &prd);
6743 if (! ret)
6745 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6746 return CMD_WARNING;
6748 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6751 DEFUN (show_ip_bgp_view,
6752 show_ip_bgp_view_cmd,
6753 "show ip bgp view WORD",
6754 SHOW_STR
6755 IP_STR
6756 BGP_STR
6757 "BGP view\n"
6758 "BGP view name\n")
6760 struct bgp *bgp;
6762 /* BGP structure lookup. */
6763 bgp = bgp_lookup_by_name (argv[0]);
6764 if (bgp == NULL)
6766 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6767 return CMD_WARNING;
6770 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6773 DEFUN (show_ip_bgp_view_route,
6774 show_ip_bgp_view_route_cmd,
6775 "show ip bgp view WORD A.B.C.D",
6776 SHOW_STR
6777 IP_STR
6778 BGP_STR
6779 "BGP view\n"
6780 "BGP view name\n"
6781 "Network in the BGP routing table to display\n")
6783 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6786 DEFUN (show_ip_bgp_view_prefix,
6787 show_ip_bgp_view_prefix_cmd,
6788 "show ip bgp view WORD A.B.C.D/M",
6789 SHOW_STR
6790 IP_STR
6791 BGP_STR
6792 "BGP view\n"
6793 "BGP view name\n"
6794 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6796 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6799 #ifdef HAVE_IPV6
6800 DEFUN (show_bgp,
6801 show_bgp_cmd,
6802 "show bgp",
6803 SHOW_STR
6804 BGP_STR)
6806 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6807 NULL);
6810 ALIAS (show_bgp,
6811 show_bgp_ipv6_cmd,
6812 "show bgp ipv6",
6813 SHOW_STR
6814 BGP_STR
6815 "Address family\n")
6817 /* old command */
6818 DEFUN (show_ipv6_bgp,
6819 show_ipv6_bgp_cmd,
6820 "show ipv6 bgp",
6821 SHOW_STR
6822 IP_STR
6823 BGP_STR)
6825 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6826 NULL);
6829 DEFUN (show_bgp_route,
6830 show_bgp_route_cmd,
6831 "show bgp X:X::X:X",
6832 SHOW_STR
6833 BGP_STR
6834 "Network in the BGP routing table to display\n")
6836 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6839 ALIAS (show_bgp_route,
6840 show_bgp_ipv6_route_cmd,
6841 "show bgp ipv6 X:X::X:X",
6842 SHOW_STR
6843 BGP_STR
6844 "Address family\n"
6845 "Network in the BGP routing table to display\n")
6847 /* old command */
6848 DEFUN (show_ipv6_bgp_route,
6849 show_ipv6_bgp_route_cmd,
6850 "show ipv6 bgp X:X::X:X",
6851 SHOW_STR
6852 IP_STR
6853 BGP_STR
6854 "Network in the BGP routing table to display\n")
6856 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6859 DEFUN (show_bgp_prefix,
6860 show_bgp_prefix_cmd,
6861 "show bgp X:X::X:X/M",
6862 SHOW_STR
6863 BGP_STR
6864 "IPv6 prefix <network>/<length>\n")
6866 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6869 ALIAS (show_bgp_prefix,
6870 show_bgp_ipv6_prefix_cmd,
6871 "show bgp ipv6 X:X::X:X/M",
6872 SHOW_STR
6873 BGP_STR
6874 "Address family\n"
6875 "IPv6 prefix <network>/<length>\n")
6877 /* old command */
6878 DEFUN (show_ipv6_bgp_prefix,
6879 show_ipv6_bgp_prefix_cmd,
6880 "show ipv6 bgp X:X::X:X/M",
6881 SHOW_STR
6882 IP_STR
6883 BGP_STR
6884 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6886 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6889 DEFUN (show_bgp_view,
6890 show_bgp_view_cmd,
6891 "show bgp view WORD",
6892 SHOW_STR
6893 BGP_STR
6894 "BGP view\n"
6895 "View name\n")
6897 struct bgp *bgp;
6899 /* BGP structure lookup. */
6900 bgp = bgp_lookup_by_name (argv[0]);
6901 if (bgp == NULL)
6903 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6904 return CMD_WARNING;
6907 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6910 ALIAS (show_bgp_view,
6911 show_bgp_view_ipv6_cmd,
6912 "show bgp view WORD ipv6",
6913 SHOW_STR
6914 BGP_STR
6915 "BGP view\n"
6916 "View name\n"
6917 "Address family\n")
6919 DEFUN (show_bgp_view_route,
6920 show_bgp_view_route_cmd,
6921 "show bgp view WORD X:X::X:X",
6922 SHOW_STR
6923 BGP_STR
6924 "BGP view\n"
6925 "View name\n"
6926 "Network in the BGP routing table to display\n")
6928 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6931 ALIAS (show_bgp_view_route,
6932 show_bgp_view_ipv6_route_cmd,
6933 "show bgp view WORD ipv6 X:X::X:X",
6934 SHOW_STR
6935 BGP_STR
6936 "BGP view\n"
6937 "View name\n"
6938 "Address family\n"
6939 "Network in the BGP routing table to display\n")
6941 DEFUN (show_bgp_view_prefix,
6942 show_bgp_view_prefix_cmd,
6943 "show bgp view WORD X:X::X:X/M",
6944 SHOW_STR
6945 BGP_STR
6946 "BGP view\n"
6947 "View name\n"
6948 "IPv6 prefix <network>/<length>\n")
6950 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6953 ALIAS (show_bgp_view_prefix,
6954 show_bgp_view_ipv6_prefix_cmd,
6955 "show bgp view WORD ipv6 X:X::X:X/M",
6956 SHOW_STR
6957 BGP_STR
6958 "BGP view\n"
6959 "View name\n"
6960 "Address family\n"
6961 "IPv6 prefix <network>/<length>\n")
6963 /* old command */
6964 DEFUN (show_ipv6_mbgp,
6965 show_ipv6_mbgp_cmd,
6966 "show ipv6 mbgp",
6967 SHOW_STR
6968 IP_STR
6969 MBGP_STR)
6971 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6972 NULL);
6975 /* old command */
6976 DEFUN (show_ipv6_mbgp_route,
6977 show_ipv6_mbgp_route_cmd,
6978 "show ipv6 mbgp X:X::X:X",
6979 SHOW_STR
6980 IP_STR
6981 MBGP_STR
6982 "Network in the MBGP routing table to display\n")
6984 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6987 /* old command */
6988 DEFUN (show_ipv6_mbgp_prefix,
6989 show_ipv6_mbgp_prefix_cmd,
6990 "show ipv6 mbgp X:X::X:X/M",
6991 SHOW_STR
6992 IP_STR
6993 MBGP_STR
6994 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6996 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6998 #endif
7001 static int
7002 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
7003 safi_t safi, enum bgp_show_type type)
7005 int i;
7006 struct buffer *b;
7007 char *regstr;
7008 int first;
7009 regex_t *regex;
7010 int rc;
7012 first = 0;
7013 b = buffer_new (1024);
7014 for (i = 0; i < argc; i++)
7016 if (first)
7017 buffer_putc (b, ' ');
7018 else
7020 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7021 continue;
7022 first = 1;
7025 buffer_putstr (b, argv[i]);
7027 buffer_putc (b, '\0');
7029 regstr = buffer_getstr (b);
7030 buffer_free (b);
7032 regex = bgp_regcomp (regstr);
7033 XFREE(MTYPE_TMP, regstr);
7034 if (! regex)
7036 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7037 VTY_NEWLINE);
7038 return CMD_WARNING;
7041 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7042 bgp_regex_free (regex);
7043 return rc;
7046 DEFUN (show_ip_bgp_regexp,
7047 show_ip_bgp_regexp_cmd,
7048 "show ip bgp regexp .LINE",
7049 SHOW_STR
7050 IP_STR
7051 BGP_STR
7052 "Display routes matching the AS path regular expression\n"
7053 "A regular-expression to match the BGP AS paths\n")
7055 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7056 bgp_show_type_regexp);
7059 DEFUN (show_ip_bgp_flap_regexp,
7060 show_ip_bgp_flap_regexp_cmd,
7061 "show ip bgp flap-statistics regexp .LINE",
7062 SHOW_STR
7063 IP_STR
7064 BGP_STR
7065 "Display flap statistics of routes\n"
7066 "Display routes matching the AS path regular expression\n"
7067 "A regular-expression to match the BGP AS paths\n")
7069 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7070 bgp_show_type_flap_regexp);
7073 DEFUN (show_ip_bgp_ipv4_regexp,
7074 show_ip_bgp_ipv4_regexp_cmd,
7075 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7076 SHOW_STR
7077 IP_STR
7078 BGP_STR
7079 "Address family\n"
7080 "Address Family modifier\n"
7081 "Address Family modifier\n"
7082 "Display routes matching the AS path regular expression\n"
7083 "A regular-expression to match the BGP AS paths\n")
7085 if (strncmp (argv[0], "m", 1) == 0)
7086 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7087 bgp_show_type_regexp);
7089 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7090 bgp_show_type_regexp);
7093 #ifdef HAVE_IPV6
7094 DEFUN (show_bgp_regexp,
7095 show_bgp_regexp_cmd,
7096 "show bgp regexp .LINE",
7097 SHOW_STR
7098 BGP_STR
7099 "Display routes matching the AS path regular expression\n"
7100 "A regular-expression to match the BGP AS paths\n")
7102 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7103 bgp_show_type_regexp);
7106 ALIAS (show_bgp_regexp,
7107 show_bgp_ipv6_regexp_cmd,
7108 "show bgp ipv6 regexp .LINE",
7109 SHOW_STR
7110 BGP_STR
7111 "Address family\n"
7112 "Display routes matching the AS path regular expression\n"
7113 "A regular-expression to match the BGP AS paths\n")
7115 /* old command */
7116 DEFUN (show_ipv6_bgp_regexp,
7117 show_ipv6_bgp_regexp_cmd,
7118 "show ipv6 bgp regexp .LINE",
7119 SHOW_STR
7120 IP_STR
7121 BGP_STR
7122 "Display routes matching the AS path regular expression\n"
7123 "A regular-expression to match the BGP AS paths\n")
7125 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7126 bgp_show_type_regexp);
7129 /* old command */
7130 DEFUN (show_ipv6_mbgp_regexp,
7131 show_ipv6_mbgp_regexp_cmd,
7132 "show ipv6 mbgp regexp .LINE",
7133 SHOW_STR
7134 IP_STR
7135 BGP_STR
7136 "Display routes matching the AS path regular expression\n"
7137 "A regular-expression to match the MBGP AS paths\n")
7139 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7140 bgp_show_type_regexp);
7142 #endif /* HAVE_IPV6 */
7144 static int
7145 bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
7146 safi_t safi, enum bgp_show_type type)
7148 struct prefix_list *plist;
7150 plist = prefix_list_lookup (afi, prefix_list_str);
7151 if (plist == NULL)
7153 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7154 prefix_list_str, VTY_NEWLINE);
7155 return CMD_WARNING;
7158 return bgp_show (vty, NULL, afi, safi, type, plist);
7161 DEFUN (show_ip_bgp_prefix_list,
7162 show_ip_bgp_prefix_list_cmd,
7163 "show ip bgp prefix-list WORD",
7164 SHOW_STR
7165 IP_STR
7166 BGP_STR
7167 "Display routes conforming to the prefix-list\n"
7168 "IP prefix-list name\n")
7170 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7171 bgp_show_type_prefix_list);
7174 DEFUN (show_ip_bgp_flap_prefix_list,
7175 show_ip_bgp_flap_prefix_list_cmd,
7176 "show ip bgp flap-statistics prefix-list WORD",
7177 SHOW_STR
7178 IP_STR
7179 BGP_STR
7180 "Display flap statistics of routes\n"
7181 "Display routes conforming to the prefix-list\n"
7182 "IP prefix-list name\n")
7184 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7185 bgp_show_type_flap_prefix_list);
7188 DEFUN (show_ip_bgp_ipv4_prefix_list,
7189 show_ip_bgp_ipv4_prefix_list_cmd,
7190 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7191 SHOW_STR
7192 IP_STR
7193 BGP_STR
7194 "Address family\n"
7195 "Address Family modifier\n"
7196 "Address Family modifier\n"
7197 "Display routes conforming to the prefix-list\n"
7198 "IP prefix-list name\n")
7200 if (strncmp (argv[0], "m", 1) == 0)
7201 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7202 bgp_show_type_prefix_list);
7204 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7205 bgp_show_type_prefix_list);
7208 #ifdef HAVE_IPV6
7209 DEFUN (show_bgp_prefix_list,
7210 show_bgp_prefix_list_cmd,
7211 "show bgp prefix-list WORD",
7212 SHOW_STR
7213 BGP_STR
7214 "Display routes conforming to the prefix-list\n"
7215 "IPv6 prefix-list name\n")
7217 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7218 bgp_show_type_prefix_list);
7221 ALIAS (show_bgp_prefix_list,
7222 show_bgp_ipv6_prefix_list_cmd,
7223 "show bgp ipv6 prefix-list WORD",
7224 SHOW_STR
7225 BGP_STR
7226 "Address family\n"
7227 "Display routes conforming to the prefix-list\n"
7228 "IPv6 prefix-list name\n")
7230 /* old command */
7231 DEFUN (show_ipv6_bgp_prefix_list,
7232 show_ipv6_bgp_prefix_list_cmd,
7233 "show ipv6 bgp prefix-list WORD",
7234 SHOW_STR
7235 IPV6_STR
7236 BGP_STR
7237 "Display routes matching the prefix-list\n"
7238 "IPv6 prefix-list name\n")
7240 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7241 bgp_show_type_prefix_list);
7244 /* old command */
7245 DEFUN (show_ipv6_mbgp_prefix_list,
7246 show_ipv6_mbgp_prefix_list_cmd,
7247 "show ipv6 mbgp prefix-list WORD",
7248 SHOW_STR
7249 IPV6_STR
7250 MBGP_STR
7251 "Display routes matching the prefix-list\n"
7252 "IPv6 prefix-list name\n")
7254 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7255 bgp_show_type_prefix_list);
7257 #endif /* HAVE_IPV6 */
7259 static int
7260 bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
7261 safi_t safi, enum bgp_show_type type)
7263 struct as_list *as_list;
7265 as_list = as_list_lookup (filter);
7266 if (as_list == NULL)
7268 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7269 return CMD_WARNING;
7272 return bgp_show (vty, NULL, afi, safi, type, as_list);
7275 DEFUN (show_ip_bgp_filter_list,
7276 show_ip_bgp_filter_list_cmd,
7277 "show ip bgp filter-list WORD",
7278 SHOW_STR
7279 IP_STR
7280 BGP_STR
7281 "Display routes conforming to the filter-list\n"
7282 "Regular expression access list name\n")
7284 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7285 bgp_show_type_filter_list);
7288 DEFUN (show_ip_bgp_flap_filter_list,
7289 show_ip_bgp_flap_filter_list_cmd,
7290 "show ip bgp flap-statistics filter-list WORD",
7291 SHOW_STR
7292 IP_STR
7293 BGP_STR
7294 "Display flap statistics of routes\n"
7295 "Display routes conforming to the filter-list\n"
7296 "Regular expression access list name\n")
7298 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7299 bgp_show_type_flap_filter_list);
7302 DEFUN (show_ip_bgp_ipv4_filter_list,
7303 show_ip_bgp_ipv4_filter_list_cmd,
7304 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7305 SHOW_STR
7306 IP_STR
7307 BGP_STR
7308 "Address family\n"
7309 "Address Family modifier\n"
7310 "Address Family modifier\n"
7311 "Display routes conforming to the filter-list\n"
7312 "Regular expression access list name\n")
7314 if (strncmp (argv[0], "m", 1) == 0)
7315 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7316 bgp_show_type_filter_list);
7318 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7319 bgp_show_type_filter_list);
7322 #ifdef HAVE_IPV6
7323 DEFUN (show_bgp_filter_list,
7324 show_bgp_filter_list_cmd,
7325 "show bgp filter-list WORD",
7326 SHOW_STR
7327 BGP_STR
7328 "Display routes conforming to the filter-list\n"
7329 "Regular expression access list name\n")
7331 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7332 bgp_show_type_filter_list);
7335 ALIAS (show_bgp_filter_list,
7336 show_bgp_ipv6_filter_list_cmd,
7337 "show bgp ipv6 filter-list WORD",
7338 SHOW_STR
7339 BGP_STR
7340 "Address family\n"
7341 "Display routes conforming to the filter-list\n"
7342 "Regular expression access list name\n")
7344 /* old command */
7345 DEFUN (show_ipv6_bgp_filter_list,
7346 show_ipv6_bgp_filter_list_cmd,
7347 "show ipv6 bgp filter-list WORD",
7348 SHOW_STR
7349 IPV6_STR
7350 BGP_STR
7351 "Display routes conforming to the filter-list\n"
7352 "Regular expression access list name\n")
7354 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7355 bgp_show_type_filter_list);
7358 /* old command */
7359 DEFUN (show_ipv6_mbgp_filter_list,
7360 show_ipv6_mbgp_filter_list_cmd,
7361 "show ipv6 mbgp filter-list WORD",
7362 SHOW_STR
7363 IPV6_STR
7364 MBGP_STR
7365 "Display routes conforming to the filter-list\n"
7366 "Regular expression access list name\n")
7368 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7369 bgp_show_type_filter_list);
7371 #endif /* HAVE_IPV6 */
7373 static int
7374 bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
7375 safi_t safi, enum bgp_show_type type)
7377 struct route_map *rmap;
7379 rmap = route_map_lookup_by_name (rmap_str);
7380 if (! rmap)
7382 vty_out (vty, "%% %s is not a valid route-map name%s",
7383 rmap_str, VTY_NEWLINE);
7384 return CMD_WARNING;
7387 return bgp_show (vty, NULL, afi, safi, type, rmap);
7390 DEFUN (show_ip_bgp_route_map,
7391 show_ip_bgp_route_map_cmd,
7392 "show ip bgp route-map WORD",
7393 SHOW_STR
7394 IP_STR
7395 BGP_STR
7396 "Display routes matching the route-map\n"
7397 "A route-map to match on\n")
7399 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7400 bgp_show_type_route_map);
7403 DEFUN (show_ip_bgp_flap_route_map,
7404 show_ip_bgp_flap_route_map_cmd,
7405 "show ip bgp flap-statistics route-map WORD",
7406 SHOW_STR
7407 IP_STR
7408 BGP_STR
7409 "Display flap statistics of routes\n"
7410 "Display routes matching the route-map\n"
7411 "A route-map to match on\n")
7413 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7414 bgp_show_type_flap_route_map);
7417 DEFUN (show_ip_bgp_ipv4_route_map,
7418 show_ip_bgp_ipv4_route_map_cmd,
7419 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7420 SHOW_STR
7421 IP_STR
7422 BGP_STR
7423 "Address family\n"
7424 "Address Family modifier\n"
7425 "Address Family modifier\n"
7426 "Display routes matching the route-map\n"
7427 "A route-map to match on\n")
7429 if (strncmp (argv[0], "m", 1) == 0)
7430 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7431 bgp_show_type_route_map);
7433 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7434 bgp_show_type_route_map);
7437 DEFUN (show_bgp_route_map,
7438 show_bgp_route_map_cmd,
7439 "show bgp route-map WORD",
7440 SHOW_STR
7441 BGP_STR
7442 "Display routes matching the route-map\n"
7443 "A route-map to match on\n")
7445 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7446 bgp_show_type_route_map);
7449 ALIAS (show_bgp_route_map,
7450 show_bgp_ipv6_route_map_cmd,
7451 "show bgp ipv6 route-map WORD",
7452 SHOW_STR
7453 BGP_STR
7454 "Address family\n"
7455 "Display routes matching the route-map\n"
7456 "A route-map to match on\n")
7458 DEFUN (show_ip_bgp_cidr_only,
7459 show_ip_bgp_cidr_only_cmd,
7460 "show ip bgp cidr-only",
7461 SHOW_STR
7462 IP_STR
7463 BGP_STR
7464 "Display only routes with non-natural netmasks\n")
7466 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7467 bgp_show_type_cidr_only, NULL);
7470 DEFUN (show_ip_bgp_flap_cidr_only,
7471 show_ip_bgp_flap_cidr_only_cmd,
7472 "show ip bgp flap-statistics cidr-only",
7473 SHOW_STR
7474 IP_STR
7475 BGP_STR
7476 "Display flap statistics of routes\n"
7477 "Display only routes with non-natural netmasks\n")
7479 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7480 bgp_show_type_flap_cidr_only, NULL);
7483 DEFUN (show_ip_bgp_ipv4_cidr_only,
7484 show_ip_bgp_ipv4_cidr_only_cmd,
7485 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7486 SHOW_STR
7487 IP_STR
7488 BGP_STR
7489 "Address family\n"
7490 "Address Family modifier\n"
7491 "Address Family modifier\n"
7492 "Display only routes with non-natural netmasks\n")
7494 if (strncmp (argv[0], "m", 1) == 0)
7495 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
7496 bgp_show_type_cidr_only, NULL);
7498 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7499 bgp_show_type_cidr_only, NULL);
7502 DEFUN (show_ip_bgp_community_all,
7503 show_ip_bgp_community_all_cmd,
7504 "show ip bgp community",
7505 SHOW_STR
7506 IP_STR
7507 BGP_STR
7508 "Display routes matching the communities\n")
7510 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7511 bgp_show_type_community_all, NULL);
7514 DEFUN (show_ip_bgp_ipv4_community_all,
7515 show_ip_bgp_ipv4_community_all_cmd,
7516 "show ip bgp ipv4 (unicast|multicast) community",
7517 SHOW_STR
7518 IP_STR
7519 BGP_STR
7520 "Address family\n"
7521 "Address Family modifier\n"
7522 "Address Family modifier\n"
7523 "Display routes matching the communities\n")
7525 if (strncmp (argv[0], "m", 1) == 0)
7526 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
7527 bgp_show_type_community_all, NULL);
7529 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7530 bgp_show_type_community_all, NULL);
7533 #ifdef HAVE_IPV6
7534 DEFUN (show_bgp_community_all,
7535 show_bgp_community_all_cmd,
7536 "show bgp community",
7537 SHOW_STR
7538 BGP_STR
7539 "Display routes matching the communities\n")
7541 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
7542 bgp_show_type_community_all, NULL);
7545 ALIAS (show_bgp_community_all,
7546 show_bgp_ipv6_community_all_cmd,
7547 "show bgp ipv6 community",
7548 SHOW_STR
7549 BGP_STR
7550 "Address family\n"
7551 "Display routes matching the communities\n")
7553 /* old command */
7554 DEFUN (show_ipv6_bgp_community_all,
7555 show_ipv6_bgp_community_all_cmd,
7556 "show ipv6 bgp community",
7557 SHOW_STR
7558 IPV6_STR
7559 BGP_STR
7560 "Display routes matching the communities\n")
7562 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
7563 bgp_show_type_community_all, NULL);
7566 /* old command */
7567 DEFUN (show_ipv6_mbgp_community_all,
7568 show_ipv6_mbgp_community_all_cmd,
7569 "show ipv6 mbgp community",
7570 SHOW_STR
7571 IPV6_STR
7572 MBGP_STR
7573 "Display routes matching the communities\n")
7575 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
7576 bgp_show_type_community_all, NULL);
7578 #endif /* HAVE_IPV6 */
7580 static int
7581 bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7582 u_int16_t afi, u_char safi)
7584 struct community *com;
7585 struct buffer *b;
7586 int i;
7587 char *str;
7588 int first = 0;
7590 b = buffer_new (1024);
7591 for (i = 0; i < argc; i++)
7593 if (first)
7594 buffer_putc (b, ' ');
7595 else
7597 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7598 continue;
7599 first = 1;
7602 buffer_putstr (b, argv[i]);
7604 buffer_putc (b, '\0');
7606 str = buffer_getstr (b);
7607 buffer_free (b);
7609 com = community_str2com (str);
7610 XFREE (MTYPE_TMP, str);
7611 if (! com)
7613 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7614 return CMD_WARNING;
7617 return bgp_show (vty, NULL, afi, safi,
7618 (exact ? bgp_show_type_community_exact :
7619 bgp_show_type_community), com);
7622 DEFUN (show_ip_bgp_community,
7623 show_ip_bgp_community_cmd,
7624 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7625 SHOW_STR
7626 IP_STR
7627 BGP_STR
7628 "Display routes matching the communities\n"
7629 "community number\n"
7630 "Do not send outside local AS (well-known community)\n"
7631 "Do not advertise to any peer (well-known community)\n"
7632 "Do not export to next AS (well-known community)\n")
7634 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7637 ALIAS (show_ip_bgp_community,
7638 show_ip_bgp_community2_cmd,
7639 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7640 SHOW_STR
7641 IP_STR
7642 BGP_STR
7643 "Display routes matching the communities\n"
7644 "community number\n"
7645 "Do not send outside local AS (well-known community)\n"
7646 "Do not advertise to any peer (well-known community)\n"
7647 "Do not export to next AS (well-known community)\n"
7648 "community number\n"
7649 "Do not send outside local AS (well-known community)\n"
7650 "Do not advertise to any peer (well-known community)\n"
7651 "Do not export to next AS (well-known community)\n")
7653 ALIAS (show_ip_bgp_community,
7654 show_ip_bgp_community3_cmd,
7655 "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)",
7656 SHOW_STR
7657 IP_STR
7658 BGP_STR
7659 "Display routes matching the communities\n"
7660 "community number\n"
7661 "Do not send outside local AS (well-known community)\n"
7662 "Do not advertise to any peer (well-known community)\n"
7663 "Do not export to next AS (well-known community)\n"
7664 "community number\n"
7665 "Do not send outside local AS (well-known community)\n"
7666 "Do not advertise to any peer (well-known community)\n"
7667 "Do not export to next AS (well-known community)\n"
7668 "community number\n"
7669 "Do not send outside local AS (well-known community)\n"
7670 "Do not advertise to any peer (well-known community)\n"
7671 "Do not export to next AS (well-known community)\n")
7673 ALIAS (show_ip_bgp_community,
7674 show_ip_bgp_community4_cmd,
7675 "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)",
7676 SHOW_STR
7677 IP_STR
7678 BGP_STR
7679 "Display routes matching the communities\n"
7680 "community number\n"
7681 "Do not send outside local AS (well-known community)\n"
7682 "Do not advertise to any peer (well-known community)\n"
7683 "Do not export to next AS (well-known community)\n"
7684 "community number\n"
7685 "Do not send outside local AS (well-known community)\n"
7686 "Do not advertise to any peer (well-known community)\n"
7687 "Do not export to next AS (well-known community)\n"
7688 "community number\n"
7689 "Do not send outside local AS (well-known community)\n"
7690 "Do not advertise to any peer (well-known community)\n"
7691 "Do not export to next AS (well-known community)\n"
7692 "community number\n"
7693 "Do not send outside local AS (well-known community)\n"
7694 "Do not advertise to any peer (well-known community)\n"
7695 "Do not export to next AS (well-known community)\n")
7697 DEFUN (show_ip_bgp_ipv4_community,
7698 show_ip_bgp_ipv4_community_cmd,
7699 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7700 SHOW_STR
7701 IP_STR
7702 BGP_STR
7703 "Address family\n"
7704 "Address Family modifier\n"
7705 "Address Family modifier\n"
7706 "Display routes matching the communities\n"
7707 "community number\n"
7708 "Do not send outside local AS (well-known community)\n"
7709 "Do not advertise to any peer (well-known community)\n"
7710 "Do not export to next AS (well-known community)\n")
7712 if (strncmp (argv[0], "m", 1) == 0)
7713 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7715 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7718 ALIAS (show_ip_bgp_ipv4_community,
7719 show_ip_bgp_ipv4_community2_cmd,
7720 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7721 SHOW_STR
7722 IP_STR
7723 BGP_STR
7724 "Address family\n"
7725 "Address Family modifier\n"
7726 "Address Family modifier\n"
7727 "Display routes matching the communities\n"
7728 "community number\n"
7729 "Do not send outside local AS (well-known community)\n"
7730 "Do not advertise to any peer (well-known community)\n"
7731 "Do not export to next AS (well-known community)\n"
7732 "community number\n"
7733 "Do not send outside local AS (well-known community)\n"
7734 "Do not advertise to any peer (well-known community)\n"
7735 "Do not export to next AS (well-known community)\n")
7737 ALIAS (show_ip_bgp_ipv4_community,
7738 show_ip_bgp_ipv4_community3_cmd,
7739 "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)",
7740 SHOW_STR
7741 IP_STR
7742 BGP_STR
7743 "Address family\n"
7744 "Address Family modifier\n"
7745 "Address Family modifier\n"
7746 "Display routes matching the communities\n"
7747 "community number\n"
7748 "Do not send outside local AS (well-known community)\n"
7749 "Do not advertise to any peer (well-known community)\n"
7750 "Do not export to next AS (well-known community)\n"
7751 "community number\n"
7752 "Do not send outside local AS (well-known community)\n"
7753 "Do not advertise to any peer (well-known community)\n"
7754 "Do not export to next AS (well-known community)\n"
7755 "community number\n"
7756 "Do not send outside local AS (well-known community)\n"
7757 "Do not advertise to any peer (well-known community)\n"
7758 "Do not export to next AS (well-known community)\n")
7760 ALIAS (show_ip_bgp_ipv4_community,
7761 show_ip_bgp_ipv4_community4_cmd,
7762 "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)",
7763 SHOW_STR
7764 IP_STR
7765 BGP_STR
7766 "Address family\n"
7767 "Address Family modifier\n"
7768 "Address Family modifier\n"
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 "community number\n"
7779 "Do not send outside local AS (well-known community)\n"
7780 "Do not advertise to any peer (well-known community)\n"
7781 "Do not export to next AS (well-known community)\n"
7782 "community number\n"
7783 "Do not send outside local AS (well-known community)\n"
7784 "Do not advertise to any peer (well-known community)\n"
7785 "Do not export to next AS (well-known community)\n")
7787 DEFUN (show_ip_bgp_community_exact,
7788 show_ip_bgp_community_exact_cmd,
7789 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7790 SHOW_STR
7791 IP_STR
7792 BGP_STR
7793 "Display routes matching the communities\n"
7794 "community number\n"
7795 "Do not send outside local AS (well-known community)\n"
7796 "Do not advertise to any peer (well-known community)\n"
7797 "Do not export to next AS (well-known community)\n"
7798 "Exact match of the communities")
7800 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7803 ALIAS (show_ip_bgp_community_exact,
7804 show_ip_bgp_community2_exact_cmd,
7805 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7806 SHOW_STR
7807 IP_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 "Exact match of the communities")
7820 ALIAS (show_ip_bgp_community_exact,
7821 show_ip_bgp_community3_exact_cmd,
7822 "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",
7823 SHOW_STR
7824 IP_STR
7825 BGP_STR
7826 "Display routes matching the communities\n"
7827 "community number\n"
7828 "Do not send outside local AS (well-known community)\n"
7829 "Do not advertise to any peer (well-known community)\n"
7830 "Do not export to next AS (well-known community)\n"
7831 "community number\n"
7832 "Do not send outside local AS (well-known community)\n"
7833 "Do not advertise to any peer (well-known community)\n"
7834 "Do not export to next AS (well-known community)\n"
7835 "community number\n"
7836 "Do not send outside local AS (well-known community)\n"
7837 "Do not advertise to any peer (well-known community)\n"
7838 "Do not export to next AS (well-known community)\n"
7839 "Exact match of the communities")
7841 ALIAS (show_ip_bgp_community_exact,
7842 show_ip_bgp_community4_exact_cmd,
7843 "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",
7844 SHOW_STR
7845 IP_STR
7846 BGP_STR
7847 "Display routes matching the communities\n"
7848 "community number\n"
7849 "Do not send outside local AS (well-known community)\n"
7850 "Do not advertise to any peer (well-known community)\n"
7851 "Do not export to next AS (well-known community)\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"
7860 "community number\n"
7861 "Do not send outside local AS (well-known community)\n"
7862 "Do not advertise to any peer (well-known community)\n"
7863 "Do not export to next AS (well-known community)\n"
7864 "Exact match of the communities")
7866 DEFUN (show_ip_bgp_ipv4_community_exact,
7867 show_ip_bgp_ipv4_community_exact_cmd,
7868 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7869 SHOW_STR
7870 IP_STR
7871 BGP_STR
7872 "Address family\n"
7873 "Address Family modifier\n"
7874 "Address Family modifier\n"
7875 "Display routes matching the communities\n"
7876 "community number\n"
7877 "Do not send outside local AS (well-known community)\n"
7878 "Do not advertise to any peer (well-known community)\n"
7879 "Do not export to next AS (well-known community)\n"
7880 "Exact match of the communities")
7882 if (strncmp (argv[0], "m", 1) == 0)
7883 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7885 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7888 ALIAS (show_ip_bgp_ipv4_community_exact,
7889 show_ip_bgp_ipv4_community2_exact_cmd,
7890 "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",
7891 SHOW_STR
7892 IP_STR
7893 BGP_STR
7894 "Address family\n"
7895 "Address Family modifier\n"
7896 "Address Family modifier\n"
7897 "Display routes matching the communities\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"
7906 "Exact match of the communities")
7908 ALIAS (show_ip_bgp_ipv4_community_exact,
7909 show_ip_bgp_ipv4_community3_exact_cmd,
7910 "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",
7911 SHOW_STR
7912 IP_STR
7913 BGP_STR
7914 "Address family\n"
7915 "Address Family modifier\n"
7916 "Address Family modifier\n"
7917 "Display routes matching the communities\n"
7918 "community number\n"
7919 "Do not send outside local AS (well-known community)\n"
7920 "Do not advertise to any peer (well-known community)\n"
7921 "Do not export to next AS (well-known community)\n"
7922 "community number\n"
7923 "Do not send outside local AS (well-known community)\n"
7924 "Do not advertise to any peer (well-known community)\n"
7925 "Do not export to next AS (well-known community)\n"
7926 "community number\n"
7927 "Do not send outside local AS (well-known community)\n"
7928 "Do not advertise to any peer (well-known community)\n"
7929 "Do not export to next AS (well-known community)\n"
7930 "Exact match of the communities")
7932 ALIAS (show_ip_bgp_ipv4_community_exact,
7933 show_ip_bgp_ipv4_community4_exact_cmd,
7934 "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",
7935 SHOW_STR
7936 IP_STR
7937 BGP_STR
7938 "Address family\n"
7939 "Address Family modifier\n"
7940 "Address Family modifier\n"
7941 "Display routes matching the communities\n"
7942 "community number\n"
7943 "Do not send outside local AS (well-known community)\n"
7944 "Do not advertise to any peer (well-known community)\n"
7945 "Do not export to next AS (well-known community)\n"
7946 "community number\n"
7947 "Do not send outside local AS (well-known community)\n"
7948 "Do not advertise to any peer (well-known community)\n"
7949 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7960 #ifdef HAVE_IPV6
7961 DEFUN (show_bgp_community,
7962 show_bgp_community_cmd,
7963 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7964 SHOW_STR
7965 BGP_STR
7966 "Display routes matching the communities\n"
7967 "community number\n"
7968 "Do not send outside local AS (well-known community)\n"
7969 "Do not advertise to any peer (well-known community)\n"
7970 "Do not export to next AS (well-known community)\n")
7972 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7975 ALIAS (show_bgp_community,
7976 show_bgp_ipv6_community_cmd,
7977 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7978 SHOW_STR
7979 BGP_STR
7980 "Address family\n"
7981 "Display routes matching the communities\n"
7982 "community number\n"
7983 "Do not send outside local AS (well-known community)\n"
7984 "Do not advertise to any peer (well-known community)\n"
7985 "Do not export to next AS (well-known community)\n")
7987 ALIAS (show_bgp_community,
7988 show_bgp_community2_cmd,
7989 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7990 SHOW_STR
7991 BGP_STR
7992 "Display routes matching the communities\n"
7993 "community number\n"
7994 "Do not send outside local AS (well-known community)\n"
7995 "Do not advertise to any peer (well-known community)\n"
7996 "Do not export to next AS (well-known community)\n"
7997 "community number\n"
7998 "Do not send outside local AS (well-known community)\n"
7999 "Do not advertise to any peer (well-known community)\n"
8000 "Do not export to next AS (well-known community)\n")
8002 ALIAS (show_bgp_community,
8003 show_bgp_ipv6_community2_cmd,
8004 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8005 SHOW_STR
8006 BGP_STR
8007 "Address family\n"
8008 "Display routes matching the communities\n"
8009 "community number\n"
8010 "Do not send outside local AS (well-known community)\n"
8011 "Do not advertise to any peer (well-known community)\n"
8012 "Do not export to next AS (well-known community)\n"
8013 "community number\n"
8014 "Do not send outside local AS (well-known community)\n"
8015 "Do not advertise to any peer (well-known community)\n"
8016 "Do not export to next AS (well-known community)\n")
8018 ALIAS (show_bgp_community,
8019 show_bgp_community3_cmd,
8020 "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)",
8021 SHOW_STR
8022 BGP_STR
8023 "Display routes matching the communities\n"
8024 "community number\n"
8025 "Do not send outside local AS (well-known community)\n"
8026 "Do not advertise to any peer (well-known community)\n"
8027 "Do not export to next AS (well-known community)\n"
8028 "community number\n"
8029 "Do not send outside local AS (well-known community)\n"
8030 "Do not advertise to any peer (well-known community)\n"
8031 "Do not export to next AS (well-known community)\n"
8032 "community number\n"
8033 "Do not send outside local AS (well-known community)\n"
8034 "Do not advertise to any peer (well-known community)\n"
8035 "Do not export to next AS (well-known community)\n")
8037 ALIAS (show_bgp_community,
8038 show_bgp_ipv6_community3_cmd,
8039 "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)",
8040 SHOW_STR
8041 BGP_STR
8042 "Address family\n"
8043 "Display routes matching the communities\n"
8044 "community number\n"
8045 "Do not send outside local AS (well-known community)\n"
8046 "Do not advertise to any peer (well-known community)\n"
8047 "Do not export to next AS (well-known community)\n"
8048 "community number\n"
8049 "Do not send outside local AS (well-known community)\n"
8050 "Do not advertise to any peer (well-known community)\n"
8051 "Do not export to next AS (well-known community)\n"
8052 "community number\n"
8053 "Do not send outside local AS (well-known community)\n"
8054 "Do not advertise to any peer (well-known community)\n"
8055 "Do not export to next AS (well-known community)\n")
8057 ALIAS (show_bgp_community,
8058 show_bgp_community4_cmd,
8059 "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)",
8060 SHOW_STR
8061 BGP_STR
8062 "Display routes matching the communities\n"
8063 "community number\n"
8064 "Do not send outside local AS (well-known community)\n"
8065 "Do not advertise to any peer (well-known community)\n"
8066 "Do not export to next AS (well-known community)\n"
8067 "community number\n"
8068 "Do not send outside local AS (well-known community)\n"
8069 "Do not advertise to any peer (well-known community)\n"
8070 "Do not export to next AS (well-known community)\n"
8071 "community number\n"
8072 "Do not send outside local AS (well-known community)\n"
8073 "Do not advertise to any peer (well-known community)\n"
8074 "Do not export to next AS (well-known community)\n"
8075 "community number\n"
8076 "Do not send outside local AS (well-known community)\n"
8077 "Do not advertise to any peer (well-known community)\n"
8078 "Do not export to next AS (well-known community)\n")
8080 ALIAS (show_bgp_community,
8081 show_bgp_ipv6_community4_cmd,
8082 "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)",
8083 SHOW_STR
8084 BGP_STR
8085 "Address family\n"
8086 "Display routes matching the communities\n"
8087 "community number\n"
8088 "Do not send outside local AS (well-known community)\n"
8089 "Do not advertise to any peer (well-known community)\n"
8090 "Do not export to next AS (well-known community)\n"
8091 "community number\n"
8092 "Do not send outside local AS (well-known community)\n"
8093 "Do not advertise to any peer (well-known community)\n"
8094 "Do not export to next AS (well-known community)\n"
8095 "community number\n"
8096 "Do not send outside local AS (well-known community)\n"
8097 "Do not advertise to any peer (well-known community)\n"
8098 "Do not export to next AS (well-known community)\n"
8099 "community number\n"
8100 "Do not send outside local AS (well-known community)\n"
8101 "Do not advertise to any peer (well-known community)\n"
8102 "Do not export to next AS (well-known community)\n")
8104 /* old command */
8105 DEFUN (show_ipv6_bgp_community,
8106 show_ipv6_bgp_community_cmd,
8107 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8108 SHOW_STR
8109 IPV6_STR
8110 BGP_STR
8111 "Display routes matching the communities\n"
8112 "community number\n"
8113 "Do not send outside local AS (well-known community)\n"
8114 "Do not advertise to any peer (well-known community)\n"
8115 "Do not export to next AS (well-known community)\n")
8117 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8120 /* old command */
8121 ALIAS (show_ipv6_bgp_community,
8122 show_ipv6_bgp_community2_cmd,
8123 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8124 SHOW_STR
8125 IPV6_STR
8126 BGP_STR
8127 "Display routes matching the communities\n"
8128 "community number\n"
8129 "Do not send outside local AS (well-known community)\n"
8130 "Do not advertise to any peer (well-known community)\n"
8131 "Do not export to next AS (well-known community)\n"
8132 "community number\n"
8133 "Do not send outside local AS (well-known community)\n"
8134 "Do not advertise to any peer (well-known community)\n"
8135 "Do not export to next AS (well-known community)\n")
8137 /* old command */
8138 ALIAS (show_ipv6_bgp_community,
8139 show_ipv6_bgp_community3_cmd,
8140 "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)",
8141 SHOW_STR
8142 IPV6_STR
8143 BGP_STR
8144 "Display routes matching the communities\n"
8145 "community number\n"
8146 "Do not send outside local AS (well-known community)\n"
8147 "Do not advertise to any peer (well-known community)\n"
8148 "Do not export to next AS (well-known community)\n"
8149 "community number\n"
8150 "Do not send outside local AS (well-known community)\n"
8151 "Do not advertise to any peer (well-known community)\n"
8152 "Do not export to next AS (well-known community)\n"
8153 "community number\n"
8154 "Do not send outside local AS (well-known community)\n"
8155 "Do not advertise to any peer (well-known community)\n"
8156 "Do not export to next AS (well-known community)\n")
8158 /* old command */
8159 ALIAS (show_ipv6_bgp_community,
8160 show_ipv6_bgp_community4_cmd,
8161 "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)",
8162 SHOW_STR
8163 IPV6_STR
8164 BGP_STR
8165 "Display routes matching the communities\n"
8166 "community number\n"
8167 "Do not send outside local AS (well-known community)\n"
8168 "Do not advertise to any peer (well-known community)\n"
8169 "Do not export to next AS (well-known community)\n"
8170 "community number\n"
8171 "Do not send outside local AS (well-known community)\n"
8172 "Do not advertise to any peer (well-known community)\n"
8173 "Do not export to next AS (well-known community)\n"
8174 "community number\n"
8175 "Do not send outside local AS (well-known community)\n"
8176 "Do not advertise to any peer (well-known community)\n"
8177 "Do not export to next AS (well-known community)\n"
8178 "community number\n"
8179 "Do not send outside local AS (well-known community)\n"
8180 "Do not advertise to any peer (well-known community)\n"
8181 "Do not export to next AS (well-known community)\n")
8183 DEFUN (show_bgp_community_exact,
8184 show_bgp_community_exact_cmd,
8185 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8186 SHOW_STR
8187 BGP_STR
8188 "Display routes matching the communities\n"
8189 "community number\n"
8190 "Do not send outside local AS (well-known community)\n"
8191 "Do not advertise to any peer (well-known community)\n"
8192 "Do not export to next AS (well-known community)\n"
8193 "Exact match of the communities")
8195 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8198 ALIAS (show_bgp_community_exact,
8199 show_bgp_ipv6_community_exact_cmd,
8200 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8201 SHOW_STR
8202 BGP_STR
8203 "Address family\n"
8204 "Display routes matching the communities\n"
8205 "community number\n"
8206 "Do not send outside local AS (well-known community)\n"
8207 "Do not advertise to any peer (well-known community)\n"
8208 "Do not export to next AS (well-known community)\n"
8209 "Exact match of the communities")
8211 ALIAS (show_bgp_community_exact,
8212 show_bgp_community2_exact_cmd,
8213 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8214 SHOW_STR
8215 BGP_STR
8216 "Display routes matching the communities\n"
8217 "community number\n"
8218 "Do not send outside local AS (well-known community)\n"
8219 "Do not advertise to any peer (well-known community)\n"
8220 "Do not export to next AS (well-known community)\n"
8221 "community number\n"
8222 "Do not send outside local AS (well-known community)\n"
8223 "Do not advertise to any peer (well-known community)\n"
8224 "Do not export to next AS (well-known community)\n"
8225 "Exact match of the communities")
8227 ALIAS (show_bgp_community_exact,
8228 show_bgp_ipv6_community2_exact_cmd,
8229 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8230 SHOW_STR
8231 BGP_STR
8232 "Address family\n"
8233 "Display routes matching the communities\n"
8234 "community number\n"
8235 "Do not send outside local AS (well-known community)\n"
8236 "Do not advertise to any peer (well-known community)\n"
8237 "Do not export to next AS (well-known community)\n"
8238 "community number\n"
8239 "Do not send outside local AS (well-known community)\n"
8240 "Do not advertise to any peer (well-known community)\n"
8241 "Do not export to next AS (well-known community)\n"
8242 "Exact match of the communities")
8244 ALIAS (show_bgp_community_exact,
8245 show_bgp_community3_exact_cmd,
8246 "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",
8247 SHOW_STR
8248 BGP_STR
8249 "Display routes matching the communities\n"
8250 "community number\n"
8251 "Do not send outside local AS (well-known community)\n"
8252 "Do not advertise to any peer (well-known community)\n"
8253 "Do not export to next AS (well-known community)\n"
8254 "community number\n"
8255 "Do not send outside local AS (well-known community)\n"
8256 "Do not advertise to any peer (well-known community)\n"
8257 "Do not export to next AS (well-known community)\n"
8258 "community number\n"
8259 "Do not send outside local AS (well-known community)\n"
8260 "Do not advertise to any peer (well-known community)\n"
8261 "Do not export to next AS (well-known community)\n"
8262 "Exact match of the communities")
8264 ALIAS (show_bgp_community_exact,
8265 show_bgp_ipv6_community3_exact_cmd,
8266 "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",
8267 SHOW_STR
8268 BGP_STR
8269 "Address family\n"
8270 "Display routes matching the communities\n"
8271 "community number\n"
8272 "Do not send outside local AS (well-known community)\n"
8273 "Do not advertise to any peer (well-known community)\n"
8274 "Do not export to next AS (well-known community)\n"
8275 "community number\n"
8276 "Do not send outside local AS (well-known community)\n"
8277 "Do not advertise to any peer (well-known community)\n"
8278 "Do not export to next AS (well-known community)\n"
8279 "community number\n"
8280 "Do not send outside local AS (well-known community)\n"
8281 "Do not advertise to any peer (well-known community)\n"
8282 "Do not export to next AS (well-known community)\n"
8283 "Exact match of the communities")
8285 ALIAS (show_bgp_community_exact,
8286 show_bgp_community4_exact_cmd,
8287 "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",
8288 SHOW_STR
8289 BGP_STR
8290 "Display routes matching the communities\n"
8291 "community number\n"
8292 "Do not send outside local AS (well-known community)\n"
8293 "Do not advertise to any peer (well-known community)\n"
8294 "Do not export to next AS (well-known community)\n"
8295 "community number\n"
8296 "Do not send outside local AS (well-known community)\n"
8297 "Do not advertise to any peer (well-known community)\n"
8298 "Do not export to next AS (well-known community)\n"
8299 "community number\n"
8300 "Do not send outside local AS (well-known community)\n"
8301 "Do not advertise to any peer (well-known community)\n"
8302 "Do not export to next AS (well-known community)\n"
8303 "community number\n"
8304 "Do not send outside local AS (well-known community)\n"
8305 "Do not advertise to any peer (well-known community)\n"
8306 "Do not export to next AS (well-known community)\n"
8307 "Exact match of the communities")
8309 ALIAS (show_bgp_community_exact,
8310 show_bgp_ipv6_community4_exact_cmd,
8311 "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",
8312 SHOW_STR
8313 BGP_STR
8314 "Address family\n"
8315 "Display routes matching the communities\n"
8316 "community number\n"
8317 "Do not send outside local AS (well-known community)\n"
8318 "Do not advertise to any peer (well-known community)\n"
8319 "Do not export to next AS (well-known community)\n"
8320 "community number\n"
8321 "Do not send outside local AS (well-known community)\n"
8322 "Do not advertise to any peer (well-known community)\n"
8323 "Do not export to next AS (well-known community)\n"
8324 "community number\n"
8325 "Do not send outside local AS (well-known community)\n"
8326 "Do not advertise to any peer (well-known community)\n"
8327 "Do not export to next AS (well-known community)\n"
8328 "community number\n"
8329 "Do not send outside local AS (well-known community)\n"
8330 "Do not advertise to any peer (well-known community)\n"
8331 "Do not export to next AS (well-known community)\n"
8332 "Exact match of the communities")
8334 /* old command */
8335 DEFUN (show_ipv6_bgp_community_exact,
8336 show_ipv6_bgp_community_exact_cmd,
8337 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8338 SHOW_STR
8339 IPV6_STR
8340 BGP_STR
8341 "Display routes matching the communities\n"
8342 "community number\n"
8343 "Do not send outside local AS (well-known community)\n"
8344 "Do not advertise to any peer (well-known community)\n"
8345 "Do not export to next AS (well-known community)\n"
8346 "Exact match of the communities")
8348 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8351 /* old command */
8352 ALIAS (show_ipv6_bgp_community_exact,
8353 show_ipv6_bgp_community2_exact_cmd,
8354 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8355 SHOW_STR
8356 IPV6_STR
8357 BGP_STR
8358 "Display routes matching the communities\n"
8359 "community number\n"
8360 "Do not send outside local AS (well-known community)\n"
8361 "Do not advertise to any peer (well-known community)\n"
8362 "Do not export to next AS (well-known community)\n"
8363 "community number\n"
8364 "Do not send outside local AS (well-known community)\n"
8365 "Do not advertise to any peer (well-known community)\n"
8366 "Do not export to next AS (well-known community)\n"
8367 "Exact match of the communities")
8369 /* old command */
8370 ALIAS (show_ipv6_bgp_community_exact,
8371 show_ipv6_bgp_community3_exact_cmd,
8372 "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",
8373 SHOW_STR
8374 IPV6_STR
8375 BGP_STR
8376 "Display routes matching the communities\n"
8377 "community number\n"
8378 "Do not send outside local AS (well-known community)\n"
8379 "Do not advertise to any peer (well-known community)\n"
8380 "Do not export to next AS (well-known community)\n"
8381 "community number\n"
8382 "Do not send outside local AS (well-known community)\n"
8383 "Do not advertise to any peer (well-known community)\n"
8384 "Do not export to next AS (well-known community)\n"
8385 "community number\n"
8386 "Do not send outside local AS (well-known community)\n"
8387 "Do not advertise to any peer (well-known community)\n"
8388 "Do not export to next AS (well-known community)\n"
8389 "Exact match of the communities")
8391 /* old command */
8392 ALIAS (show_ipv6_bgp_community_exact,
8393 show_ipv6_bgp_community4_exact_cmd,
8394 "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",
8395 SHOW_STR
8396 IPV6_STR
8397 BGP_STR
8398 "Display routes matching the communities\n"
8399 "community number\n"
8400 "Do not send outside local AS (well-known community)\n"
8401 "Do not advertise to any peer (well-known community)\n"
8402 "Do not export to next AS (well-known community)\n"
8403 "community number\n"
8404 "Do not send outside local AS (well-known community)\n"
8405 "Do not advertise to any peer (well-known community)\n"
8406 "Do not export to next AS (well-known community)\n"
8407 "community number\n"
8408 "Do not send outside local AS (well-known community)\n"
8409 "Do not advertise to any peer (well-known community)\n"
8410 "Do not export to next AS (well-known community)\n"
8411 "community number\n"
8412 "Do not send outside local AS (well-known community)\n"
8413 "Do not advertise to any peer (well-known community)\n"
8414 "Do not export to next AS (well-known community)\n"
8415 "Exact match of the communities")
8417 /* old command */
8418 DEFUN (show_ipv6_mbgp_community,
8419 show_ipv6_mbgp_community_cmd,
8420 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8421 SHOW_STR
8422 IPV6_STR
8423 MBGP_STR
8424 "Display routes matching the communities\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n")
8430 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8433 /* old command */
8434 ALIAS (show_ipv6_mbgp_community,
8435 show_ipv6_mbgp_community2_cmd,
8436 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8437 SHOW_STR
8438 IPV6_STR
8439 MBGP_STR
8440 "Display routes matching the communities\n"
8441 "community number\n"
8442 "Do not send outside local AS (well-known community)\n"
8443 "Do not advertise to any peer (well-known community)\n"
8444 "Do not export to next AS (well-known community)\n"
8445 "community number\n"
8446 "Do not send outside local AS (well-known community)\n"
8447 "Do not advertise to any peer (well-known community)\n"
8448 "Do not export to next AS (well-known community)\n")
8450 /* old command */
8451 ALIAS (show_ipv6_mbgp_community,
8452 show_ipv6_mbgp_community3_cmd,
8453 "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)",
8454 SHOW_STR
8455 IPV6_STR
8456 MBGP_STR
8457 "Display routes matching the communities\n"
8458 "community number\n"
8459 "Do not send outside local AS (well-known community)\n"
8460 "Do not advertise to any peer (well-known community)\n"
8461 "Do not export to next AS (well-known community)\n"
8462 "community number\n"
8463 "Do not send outside local AS (well-known community)\n"
8464 "Do not advertise to any peer (well-known community)\n"
8465 "Do not export to next AS (well-known community)\n"
8466 "community number\n"
8467 "Do not send outside local AS (well-known community)\n"
8468 "Do not advertise to any peer (well-known community)\n"
8469 "Do not export to next AS (well-known community)\n")
8471 /* old command */
8472 ALIAS (show_ipv6_mbgp_community,
8473 show_ipv6_mbgp_community4_cmd,
8474 "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)",
8475 SHOW_STR
8476 IPV6_STR
8477 MBGP_STR
8478 "Display routes matching the communities\n"
8479 "community number\n"
8480 "Do not send outside local AS (well-known community)\n"
8481 "Do not advertise to any peer (well-known community)\n"
8482 "Do not export to next AS (well-known community)\n"
8483 "community number\n"
8484 "Do not send outside local AS (well-known community)\n"
8485 "Do not advertise to any peer (well-known community)\n"
8486 "Do not export to next AS (well-known community)\n"
8487 "community number\n"
8488 "Do not send outside local AS (well-known community)\n"
8489 "Do not advertise to any peer (well-known community)\n"
8490 "Do not export to next AS (well-known community)\n"
8491 "community number\n"
8492 "Do not send outside local AS (well-known community)\n"
8493 "Do not advertise to any peer (well-known community)\n"
8494 "Do not export to next AS (well-known community)\n")
8496 /* old command */
8497 DEFUN (show_ipv6_mbgp_community_exact,
8498 show_ipv6_mbgp_community_exact_cmd,
8499 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8500 SHOW_STR
8501 IPV6_STR
8502 MBGP_STR
8503 "Display routes matching the communities\n"
8504 "community number\n"
8505 "Do not send outside local AS (well-known community)\n"
8506 "Do not advertise to any peer (well-known community)\n"
8507 "Do not export to next AS (well-known community)\n"
8508 "Exact match of the communities")
8510 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8513 /* old command */
8514 ALIAS (show_ipv6_mbgp_community_exact,
8515 show_ipv6_mbgp_community2_exact_cmd,
8516 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8517 SHOW_STR
8518 IPV6_STR
8519 MBGP_STR
8520 "Display routes matching the communities\n"
8521 "community number\n"
8522 "Do not send outside local AS (well-known community)\n"
8523 "Do not advertise to any peer (well-known community)\n"
8524 "Do not export to next AS (well-known community)\n"
8525 "community number\n"
8526 "Do not send outside local AS (well-known community)\n"
8527 "Do not advertise to any peer (well-known community)\n"
8528 "Do not export to next AS (well-known community)\n"
8529 "Exact match of the communities")
8531 /* old command */
8532 ALIAS (show_ipv6_mbgp_community_exact,
8533 show_ipv6_mbgp_community3_exact_cmd,
8534 "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",
8535 SHOW_STR
8536 IPV6_STR
8537 MBGP_STR
8538 "Display routes matching the communities\n"
8539 "community number\n"
8540 "Do not send outside local AS (well-known community)\n"
8541 "Do not advertise to any peer (well-known community)\n"
8542 "Do not export to next AS (well-known community)\n"
8543 "community number\n"
8544 "Do not send outside local AS (well-known community)\n"
8545 "Do not advertise to any peer (well-known community)\n"
8546 "Do not export to next AS (well-known community)\n"
8547 "community number\n"
8548 "Do not send outside local AS (well-known community)\n"
8549 "Do not advertise to any peer (well-known community)\n"
8550 "Do not export to next AS (well-known community)\n"
8551 "Exact match of the communities")
8553 /* old command */
8554 ALIAS (show_ipv6_mbgp_community_exact,
8555 show_ipv6_mbgp_community4_exact_cmd,
8556 "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",
8557 SHOW_STR
8558 IPV6_STR
8559 MBGP_STR
8560 "Display routes matching the communities\n"
8561 "community number\n"
8562 "Do not send outside local AS (well-known community)\n"
8563 "Do not advertise to any peer (well-known community)\n"
8564 "Do not export to next AS (well-known community)\n"
8565 "community number\n"
8566 "Do not send outside local AS (well-known community)\n"
8567 "Do not advertise to any peer (well-known community)\n"
8568 "Do not export to next AS (well-known community)\n"
8569 "community number\n"
8570 "Do not send outside local AS (well-known community)\n"
8571 "Do not advertise to any peer (well-known community)\n"
8572 "Do not export to next AS (well-known community)\n"
8573 "community number\n"
8574 "Do not send outside local AS (well-known community)\n"
8575 "Do not advertise to any peer (well-known community)\n"
8576 "Do not export to next AS (well-known community)\n"
8577 "Exact match of the communities")
8578 #endif /* HAVE_IPV6 */
8580 static int
8581 bgp_show_community_list (struct vty *vty, const char *com, int exact,
8582 u_int16_t afi, u_char safi)
8584 struct community_list *list;
8586 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
8587 if (list == NULL)
8589 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8590 VTY_NEWLINE);
8591 return CMD_WARNING;
8594 return bgp_show (vty, NULL, afi, safi,
8595 (exact ? bgp_show_type_community_list_exact :
8596 bgp_show_type_community_list), list);
8599 DEFUN (show_ip_bgp_community_list,
8600 show_ip_bgp_community_list_cmd,
8601 "show ip bgp community-list (<1-500>|WORD)",
8602 SHOW_STR
8603 IP_STR
8604 BGP_STR
8605 "Display routes matching the community-list\n"
8606 "community-list number\n"
8607 "community-list name\n")
8609 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8612 DEFUN (show_ip_bgp_ipv4_community_list,
8613 show_ip_bgp_ipv4_community_list_cmd,
8614 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
8615 SHOW_STR
8616 IP_STR
8617 BGP_STR
8618 "Address family\n"
8619 "Address Family modifier\n"
8620 "Address Family modifier\n"
8621 "Display routes matching the community-list\n"
8622 "community-list number\n"
8623 "community-list name\n")
8625 if (strncmp (argv[0], "m", 1) == 0)
8626 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8628 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8631 DEFUN (show_ip_bgp_community_list_exact,
8632 show_ip_bgp_community_list_exact_cmd,
8633 "show ip bgp community-list (<1-500>|WORD) exact-match",
8634 SHOW_STR
8635 IP_STR
8636 BGP_STR
8637 "Display routes matching the community-list\n"
8638 "community-list number\n"
8639 "community-list name\n"
8640 "Exact match of the communities\n")
8642 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8645 DEFUN (show_ip_bgp_ipv4_community_list_exact,
8646 show_ip_bgp_ipv4_community_list_exact_cmd,
8647 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
8648 SHOW_STR
8649 IP_STR
8650 BGP_STR
8651 "Address family\n"
8652 "Address Family modifier\n"
8653 "Address Family modifier\n"
8654 "Display routes matching the community-list\n"
8655 "community-list number\n"
8656 "community-list name\n"
8657 "Exact match of the communities\n")
8659 if (strncmp (argv[0], "m", 1) == 0)
8660 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8662 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8665 #ifdef HAVE_IPV6
8666 DEFUN (show_bgp_community_list,
8667 show_bgp_community_list_cmd,
8668 "show bgp community-list (<1-500>|WORD)",
8669 SHOW_STR
8670 BGP_STR
8671 "Display routes matching the community-list\n"
8672 "community-list number\n"
8673 "community-list name\n")
8675 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8678 ALIAS (show_bgp_community_list,
8679 show_bgp_ipv6_community_list_cmd,
8680 "show bgp ipv6 community-list (<1-500>|WORD)",
8681 SHOW_STR
8682 BGP_STR
8683 "Address family\n"
8684 "Display routes matching the community-list\n"
8685 "community-list number\n"
8686 "community-list name\n")
8688 /* old command */
8689 DEFUN (show_ipv6_bgp_community_list,
8690 show_ipv6_bgp_community_list_cmd,
8691 "show ipv6 bgp community-list WORD",
8692 SHOW_STR
8693 IPV6_STR
8694 BGP_STR
8695 "Display routes matching the community-list\n"
8696 "community-list name\n")
8698 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8701 /* old command */
8702 DEFUN (show_ipv6_mbgp_community_list,
8703 show_ipv6_mbgp_community_list_cmd,
8704 "show ipv6 mbgp community-list WORD",
8705 SHOW_STR
8706 IPV6_STR
8707 MBGP_STR
8708 "Display routes matching the community-list\n"
8709 "community-list name\n")
8711 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8714 DEFUN (show_bgp_community_list_exact,
8715 show_bgp_community_list_exact_cmd,
8716 "show bgp community-list (<1-500>|WORD) exact-match",
8717 SHOW_STR
8718 BGP_STR
8719 "Display routes matching the community-list\n"
8720 "community-list number\n"
8721 "community-list name\n"
8722 "Exact match of the communities\n")
8724 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8727 ALIAS (show_bgp_community_list_exact,
8728 show_bgp_ipv6_community_list_exact_cmd,
8729 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
8730 SHOW_STR
8731 BGP_STR
8732 "Address family\n"
8733 "Display routes matching the community-list\n"
8734 "community-list number\n"
8735 "community-list name\n"
8736 "Exact match of the communities\n")
8738 /* old command */
8739 DEFUN (show_ipv6_bgp_community_list_exact,
8740 show_ipv6_bgp_community_list_exact_cmd,
8741 "show ipv6 bgp community-list WORD exact-match",
8742 SHOW_STR
8743 IPV6_STR
8744 BGP_STR
8745 "Display routes matching the community-list\n"
8746 "community-list name\n"
8747 "Exact match of the communities\n")
8749 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8752 /* old command */
8753 DEFUN (show_ipv6_mbgp_community_list_exact,
8754 show_ipv6_mbgp_community_list_exact_cmd,
8755 "show ipv6 mbgp community-list WORD exact-match",
8756 SHOW_STR
8757 IPV6_STR
8758 MBGP_STR
8759 "Display routes matching the community-list\n"
8760 "community-list name\n"
8761 "Exact match of the communities\n")
8763 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8765 #endif /* HAVE_IPV6 */
8767 static int
8768 bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
8769 safi_t safi, enum bgp_show_type type)
8771 int ret;
8772 struct prefix *p;
8774 p = prefix_new();
8776 ret = str2prefix (prefix, p);
8777 if (! ret)
8779 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8780 return CMD_WARNING;
8783 ret = bgp_show (vty, NULL, afi, safi, type, p);
8784 prefix_free(p);
8785 return ret;
8788 DEFUN (show_ip_bgp_prefix_longer,
8789 show_ip_bgp_prefix_longer_cmd,
8790 "show ip bgp A.B.C.D/M longer-prefixes",
8791 SHOW_STR
8792 IP_STR
8793 BGP_STR
8794 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8795 "Display route and more specific routes\n")
8797 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8798 bgp_show_type_prefix_longer);
8801 DEFUN (show_ip_bgp_flap_prefix_longer,
8802 show_ip_bgp_flap_prefix_longer_cmd,
8803 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8804 SHOW_STR
8805 IP_STR
8806 BGP_STR
8807 "Display flap statistics of routes\n"
8808 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8809 "Display route and more specific routes\n")
8811 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8812 bgp_show_type_flap_prefix_longer);
8815 DEFUN (show_ip_bgp_ipv4_prefix_longer,
8816 show_ip_bgp_ipv4_prefix_longer_cmd,
8817 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8818 SHOW_STR
8819 IP_STR
8820 BGP_STR
8821 "Address family\n"
8822 "Address Family modifier\n"
8823 "Address Family modifier\n"
8824 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8825 "Display route and more specific routes\n")
8827 if (strncmp (argv[0], "m", 1) == 0)
8828 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8829 bgp_show_type_prefix_longer);
8831 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8832 bgp_show_type_prefix_longer);
8835 DEFUN (show_ip_bgp_flap_address,
8836 show_ip_bgp_flap_address_cmd,
8837 "show ip bgp flap-statistics A.B.C.D",
8838 SHOW_STR
8839 IP_STR
8840 BGP_STR
8841 "Display flap statistics of routes\n"
8842 "Network in the BGP routing table to display\n")
8844 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8845 bgp_show_type_flap_address);
8848 DEFUN (show_ip_bgp_flap_prefix,
8849 show_ip_bgp_flap_prefix_cmd,
8850 "show ip bgp flap-statistics A.B.C.D/M",
8851 SHOW_STR
8852 IP_STR
8853 BGP_STR
8854 "Display flap statistics of routes\n"
8855 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8857 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8858 bgp_show_type_flap_prefix);
8860 #ifdef HAVE_IPV6
8861 DEFUN (show_bgp_prefix_longer,
8862 show_bgp_prefix_longer_cmd,
8863 "show bgp X:X::X:X/M longer-prefixes",
8864 SHOW_STR
8865 BGP_STR
8866 "IPv6 prefix <network>/<length>\n"
8867 "Display route and more specific routes\n")
8869 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8870 bgp_show_type_prefix_longer);
8873 ALIAS (show_bgp_prefix_longer,
8874 show_bgp_ipv6_prefix_longer_cmd,
8875 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8876 SHOW_STR
8877 BGP_STR
8878 "Address family\n"
8879 "IPv6 prefix <network>/<length>\n"
8880 "Display route and more specific routes\n")
8882 /* old command */
8883 DEFUN (show_ipv6_bgp_prefix_longer,
8884 show_ipv6_bgp_prefix_longer_cmd,
8885 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8886 SHOW_STR
8887 IPV6_STR
8888 BGP_STR
8889 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8890 "Display route and more specific routes\n")
8892 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8893 bgp_show_type_prefix_longer);
8896 /* old command */
8897 DEFUN (show_ipv6_mbgp_prefix_longer,
8898 show_ipv6_mbgp_prefix_longer_cmd,
8899 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8900 SHOW_STR
8901 IPV6_STR
8902 MBGP_STR
8903 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8904 "Display route and more specific routes\n")
8906 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8907 bgp_show_type_prefix_longer);
8909 #endif /* HAVE_IPV6 */
8911 static struct peer *
8912 peer_lookup_in_view (struct vty *vty, const char *view_name,
8913 const char *ip_str)
8915 int ret;
8916 struct bgp *bgp;
8917 struct peer *peer;
8918 union sockunion su;
8920 /* BGP structure lookup. */
8921 if (view_name)
8923 bgp = bgp_lookup_by_name (view_name);
8924 if (! bgp)
8926 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8927 return NULL;
8930 else
8932 bgp = bgp_get_default ();
8933 if (! bgp)
8935 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8936 return NULL;
8940 /* Get peer sockunion. */
8941 ret = str2sockunion (ip_str, &su);
8942 if (ret < 0)
8944 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8945 return NULL;
8948 /* Peer structure lookup. */
8949 peer = peer_lookup (bgp, &su);
8950 if (! peer)
8952 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8953 return NULL;
8956 return peer;
8959 enum bgp_stats
8961 BGP_STATS_MAXBITLEN = 0,
8962 BGP_STATS_RIB,
8963 BGP_STATS_PREFIXES,
8964 BGP_STATS_TOTPLEN,
8965 BGP_STATS_UNAGGREGATEABLE,
8966 BGP_STATS_MAX_AGGREGATEABLE,
8967 BGP_STATS_AGGREGATES,
8968 BGP_STATS_SPACE,
8969 BGP_STATS_ASPATH_COUNT,
8970 BGP_STATS_ASPATH_MAXHOPS,
8971 BGP_STATS_ASPATH_TOTHOPS,
8972 BGP_STATS_ASPATH_MAXSIZE,
8973 BGP_STATS_ASPATH_TOTSIZE,
8974 BGP_STATS_ASN_HIGHEST,
8975 BGP_STATS_MAX,
8978 static const char *table_stats_strs[] =
8980 [BGP_STATS_PREFIXES] = "Total Prefixes",
8981 [BGP_STATS_TOTPLEN] = "Average prefix length",
8982 [BGP_STATS_RIB] = "Total Advertisements",
8983 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8984 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8985 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8986 [BGP_STATS_SPACE] = "Address space advertised",
8987 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8988 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8989 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8990 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8991 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8992 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8993 [BGP_STATS_MAX] = NULL,
8996 struct bgp_table_stats
8998 struct bgp_table *table;
8999 unsigned long long counts[BGP_STATS_MAX];
9002 #if 0
9003 #define TALLY_SIGFIG 100000
9004 static unsigned long
9005 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9007 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9008 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9009 unsigned long ret = newtot / count;
9011 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9012 return ret + 1;
9013 else
9014 return ret;
9016 #endif
9018 static int
9019 bgp_table_stats_walker (struct thread *t)
9021 struct bgp_node *rn;
9022 struct bgp_node *top;
9023 struct bgp_table_stats *ts = THREAD_ARG (t);
9024 unsigned int space = 0;
9026 if (!(top = bgp_table_top (ts->table)))
9027 return 0;
9029 switch (top->p.family)
9031 case AF_INET:
9032 space = IPV4_MAX_BITLEN;
9033 break;
9034 case AF_INET6:
9035 space = IPV6_MAX_BITLEN;
9036 break;
9039 ts->counts[BGP_STATS_MAXBITLEN] = space;
9041 for (rn = top; rn; rn = bgp_route_next (rn))
9043 struct bgp_info *ri;
9044 struct bgp_node *prn = rn->parent;
9045 unsigned int rinum = 0;
9047 if (rn == top)
9048 continue;
9050 if (!rn->info)
9051 continue;
9053 ts->counts[BGP_STATS_PREFIXES]++;
9054 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9056 #if 0
9057 ts->counts[BGP_STATS_AVGPLEN]
9058 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9059 ts->counts[BGP_STATS_AVGPLEN],
9060 rn->p.prefixlen);
9061 #endif
9063 /* check if the prefix is included by any other announcements */
9064 while (prn && !prn->info)
9065 prn = prn->parent;
9067 if (prn == NULL || prn == top)
9069 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9070 /* announced address space */
9071 if (space)
9072 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9074 else if (prn->info)
9075 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9077 for (ri = rn->info; ri; ri = ri->next)
9079 rinum++;
9080 ts->counts[BGP_STATS_RIB]++;
9082 if (ri->attr &&
9083 (CHECK_FLAG (ri->attr->flag,
9084 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9085 ts->counts[BGP_STATS_AGGREGATES]++;
9087 /* as-path stats */
9088 if (ri->attr && ri->attr->aspath)
9090 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9091 unsigned int size = aspath_size (ri->attr->aspath);
9092 as_t highest = aspath_highest (ri->attr->aspath);
9094 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9096 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9097 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9099 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9100 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9102 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9103 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9104 #if 0
9105 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9106 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9107 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9108 hops);
9109 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9110 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9111 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9112 size);
9113 #endif
9114 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9115 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9119 return 0;
9122 static int
9123 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9125 struct bgp_table_stats ts;
9126 unsigned int i;
9128 if (!bgp->rib[afi][safi])
9130 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9131 return CMD_WARNING;
9134 memset (&ts, 0, sizeof (ts));
9135 ts.table = bgp->rib[afi][safi];
9136 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9138 vty_out (vty, "BGP %s RIB statistics%s%s",
9139 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9141 for (i = 0; i < BGP_STATS_MAX; i++)
9143 if (!table_stats_strs[i])
9144 continue;
9146 switch (i)
9148 #if 0
9149 case BGP_STATS_ASPATH_AVGHOPS:
9150 case BGP_STATS_ASPATH_AVGSIZE:
9151 case BGP_STATS_AVGPLEN:
9152 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9153 vty_out (vty, "%12.2f",
9154 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9155 break;
9156 #endif
9157 case BGP_STATS_ASPATH_TOTHOPS:
9158 case BGP_STATS_ASPATH_TOTSIZE:
9159 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9160 vty_out (vty, "%12.2f",
9161 ts.counts[i] ?
9162 (float)ts.counts[i] /
9163 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9164 : 0);
9165 break;
9166 case BGP_STATS_TOTPLEN:
9167 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9168 vty_out (vty, "%12.2f",
9169 ts.counts[i] ?
9170 (float)ts.counts[i] /
9171 (float)ts.counts[BGP_STATS_PREFIXES]
9172 : 0);
9173 break;
9174 case BGP_STATS_SPACE:
9175 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9176 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9177 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9178 break;
9179 vty_out (vty, "%30s: ", "\% announced ");
9180 vty_out (vty, "%12.2f%s",
9181 100 * (float)ts.counts[BGP_STATS_SPACE] /
9182 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
9183 VTY_NEWLINE);
9184 vty_out (vty, "%30s: ", "/8 equivalent ");
9185 vty_out (vty, "%12.2f%s",
9186 (float)ts.counts[BGP_STATS_SPACE] /
9187 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9188 VTY_NEWLINE);
9189 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9190 break;
9191 vty_out (vty, "%30s: ", "/24 equivalent ");
9192 vty_out (vty, "%12.2f",
9193 (float)ts.counts[BGP_STATS_SPACE] /
9194 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9195 break;
9196 default:
9197 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9198 vty_out (vty, "%12llu", ts.counts[i]);
9201 vty_out (vty, "%s", VTY_NEWLINE);
9203 return CMD_SUCCESS;
9206 static int
9207 bgp_table_stats_vty (struct vty *vty, const char *name,
9208 const char *afi_str, const char *safi_str)
9210 struct bgp *bgp;
9211 afi_t afi;
9212 safi_t safi;
9214 if (name)
9215 bgp = bgp_lookup_by_name (name);
9216 else
9217 bgp = bgp_get_default ();
9219 if (!bgp)
9221 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9222 return CMD_WARNING;
9224 if (strncmp (afi_str, "ipv", 3) == 0)
9226 if (strncmp (afi_str, "ipv4", 4) == 0)
9227 afi = AFI_IP;
9228 else if (strncmp (afi_str, "ipv6", 4) == 0)
9229 afi = AFI_IP6;
9230 else
9232 vty_out (vty, "%% Invalid address family %s%s",
9233 afi_str, VTY_NEWLINE);
9234 return CMD_WARNING;
9236 if (strncmp (safi_str, "m", 1) == 0)
9237 safi = SAFI_MULTICAST;
9238 else if (strncmp (safi_str, "u", 1) == 0)
9239 safi = SAFI_UNICAST;
9240 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9241 safi = BGP_SAFI_VPNV4;
9242 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9243 safi = BGP_SAFI_VPNV6;
9244 else
9246 vty_out (vty, "%% Invalid subsequent address family %s%s",
9247 safi_str, VTY_NEWLINE);
9248 return CMD_WARNING;
9251 else
9253 vty_out (vty, "%% Invalid address family %s%s",
9254 afi_str, VTY_NEWLINE);
9255 return CMD_WARNING;
9258 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9259 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9261 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9262 afi_str, safi_str, VTY_NEWLINE);
9263 return CMD_WARNING;
9265 return bgp_table_stats (vty, bgp, afi, safi);
9268 DEFUN (show_bgp_statistics,
9269 show_bgp_statistics_cmd,
9270 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9271 SHOW_STR
9272 BGP_STR
9273 "Address family\n"
9274 "Address family\n"
9275 "Address Family modifier\n"
9276 "Address Family modifier\n"
9277 "BGP RIB advertisement statistics\n")
9279 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9282 ALIAS (show_bgp_statistics,
9283 show_bgp_statistics_vpnv4_cmd,
9284 "show bgp (ipv4) (vpnv4) statistics",
9285 SHOW_STR
9286 BGP_STR
9287 "Address family\n"
9288 "Address Family modifier\n"
9289 "BGP RIB advertisement statistics\n")
9291 DEFUN (show_bgp_statistics_view,
9292 show_bgp_statistics_view_cmd,
9293 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9294 SHOW_STR
9295 BGP_STR
9296 "BGP view\n"
9297 "Address family\n"
9298 "Address family\n"
9299 "Address Family modifier\n"
9300 "Address Family modifier\n"
9301 "BGP RIB advertisement statistics\n")
9303 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9306 ALIAS (show_bgp_statistics_view,
9307 show_bgp_statistics_view_vpnv4_cmd,
9308 "show bgp view WORD (ipv4) (vpnv4) statistics",
9309 SHOW_STR
9310 BGP_STR
9311 "BGP view\n"
9312 "Address family\n"
9313 "Address Family modifier\n"
9314 "BGP RIB advertisement statistics\n")
9316 enum bgp_pcounts
9318 PCOUNT_ADJ_IN = 0,
9319 PCOUNT_DAMPED,
9320 PCOUNT_REMOVED,
9321 PCOUNT_HISTORY,
9322 PCOUNT_STALE,
9323 PCOUNT_VALID,
9324 PCOUNT_ALL,
9325 PCOUNT_COUNTED,
9326 PCOUNT_PFCNT, /* the figure we display to users */
9327 PCOUNT_MAX,
9330 static const char *pcount_strs[] =
9332 [PCOUNT_ADJ_IN] = "Adj-in",
9333 [PCOUNT_DAMPED] = "Damped",
9334 [PCOUNT_REMOVED] = "Removed",
9335 [PCOUNT_HISTORY] = "History",
9336 [PCOUNT_STALE] = "Stale",
9337 [PCOUNT_VALID] = "Valid",
9338 [PCOUNT_ALL] = "All RIB",
9339 [PCOUNT_COUNTED] = "PfxCt counted",
9340 [PCOUNT_PFCNT] = "Useable",
9341 [PCOUNT_MAX] = NULL,
9344 struct peer_pcounts
9346 unsigned int count[PCOUNT_MAX];
9347 const struct peer *peer;
9348 const struct bgp_table *table;
9351 static int
9352 bgp_peer_count_walker (struct thread *t)
9354 struct bgp_node *rn;
9355 struct peer_pcounts *pc = THREAD_ARG (t);
9356 const struct peer *peer = pc->peer;
9358 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
9360 struct bgp_adj_in *ain;
9361 struct bgp_info *ri;
9363 for (ain = rn->adj_in; ain; ain = ain->next)
9364 if (ain->peer == peer)
9365 pc->count[PCOUNT_ADJ_IN]++;
9367 for (ri = rn->info; ri; ri = ri->next)
9369 char buf[SU_ADDRSTRLEN];
9371 if (ri->peer != peer)
9372 continue;
9374 pc->count[PCOUNT_ALL]++;
9376 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
9377 pc->count[PCOUNT_DAMPED]++;
9378 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
9379 pc->count[PCOUNT_HISTORY]++;
9380 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
9381 pc->count[PCOUNT_REMOVED]++;
9382 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
9383 pc->count[PCOUNT_STALE]++;
9384 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
9385 pc->count[PCOUNT_VALID]++;
9386 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
9387 pc->count[PCOUNT_PFCNT]++;
9389 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9391 pc->count[PCOUNT_COUNTED]++;
9392 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
9393 plog_warn (peer->log,
9394 "%s [pcount] %s/%d is counted but flags 0x%x",
9395 peer->host,
9396 inet_ntop(rn->p.family, &rn->p.u.prefix,
9397 buf, SU_ADDRSTRLEN),
9398 rn->p.prefixlen,
9399 ri->flags);
9401 else
9403 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
9404 plog_warn (peer->log,
9405 "%s [pcount] %s/%d not counted but flags 0x%x",
9406 peer->host,
9407 inet_ntop(rn->p.family, &rn->p.u.prefix,
9408 buf, SU_ADDRSTRLEN),
9409 rn->p.prefixlen,
9410 ri->flags);
9414 return 0;
9417 static int
9418 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9420 struct peer_pcounts pcounts = { .peer = peer };
9421 unsigned int i;
9423 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9424 || !peer->bgp->rib[afi][safi])
9426 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9427 return CMD_WARNING;
9430 memset (&pcounts, 0, sizeof(pcounts));
9431 pcounts.peer = peer;
9432 pcounts.table = peer->bgp->rib[afi][safi];
9434 /* in-place call via thread subsystem so as to record execution time
9435 * stats for the thread-walk (i.e. ensure this can't be blamed on
9436 * on just vty_read()).
9438 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9440 vty_out (vty, "Prefix counts for %s, %s%s",
9441 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9442 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9443 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9444 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9446 for (i = 0; i < PCOUNT_MAX; i++)
9447 vty_out (vty, "%20s: %-10d%s",
9448 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
9450 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
9452 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9453 peer->host, VTY_NEWLINE);
9454 vty_out (vty, "Please report this bug, with the above command output%s",
9455 VTY_NEWLINE);
9458 return CMD_SUCCESS;
9461 DEFUN (show_ip_bgp_neighbor_prefix_counts,
9462 show_ip_bgp_neighbor_prefix_counts_cmd,
9463 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9464 SHOW_STR
9465 IP_STR
9466 BGP_STR
9467 "Detailed information on TCP and BGP neighbor connections\n"
9468 "Neighbor to display information about\n"
9469 "Neighbor to display information about\n"
9470 "Display detailed prefix count information\n")
9472 struct peer *peer;
9474 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9475 if (! peer)
9476 return CMD_WARNING;
9478 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9481 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9482 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9483 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9484 SHOW_STR
9485 BGP_STR
9486 "Address family\n"
9487 "Detailed information on TCP and BGP neighbor connections\n"
9488 "Neighbor to display information about\n"
9489 "Neighbor to display information about\n"
9490 "Display detailed prefix count information\n")
9492 struct peer *peer;
9494 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9495 if (! peer)
9496 return CMD_WARNING;
9498 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9501 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9502 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9503 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9504 SHOW_STR
9505 IP_STR
9506 BGP_STR
9507 "Address family\n"
9508 "Address Family modifier\n"
9509 "Address Family modifier\n"
9510 "Detailed information on TCP and BGP neighbor connections\n"
9511 "Neighbor to display information about\n"
9512 "Neighbor to display information about\n"
9513 "Display detailed prefix count information\n")
9515 struct peer *peer;
9517 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9518 if (! peer)
9519 return CMD_WARNING;
9521 if (strncmp (argv[0], "m", 1) == 0)
9522 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9524 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9527 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9528 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9529 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9530 SHOW_STR
9531 IP_STR
9532 BGP_STR
9533 "Address family\n"
9534 "Address Family modifier\n"
9535 "Address Family modifier\n"
9536 "Detailed information on TCP and BGP neighbor connections\n"
9537 "Neighbor to display information about\n"
9538 "Neighbor to display information about\n"
9539 "Display detailed prefix count information\n")
9541 struct peer *peer;
9543 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9544 if (! peer)
9545 return CMD_WARNING;
9547 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9551 static void
9552 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9553 int in)
9555 struct bgp_table *table;
9556 struct bgp_adj_in *ain;
9557 struct bgp_adj_out *adj;
9558 unsigned long output_count;
9559 struct bgp_node *rn;
9560 int header1 = 1;
9561 struct bgp *bgp;
9562 int header2 = 1;
9564 bgp = peer->bgp;
9566 if (! bgp)
9567 return;
9569 table = bgp->rib[afi][safi];
9571 output_count = 0;
9573 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9574 PEER_STATUS_DEFAULT_ORIGINATE))
9576 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
9577 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9578 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9580 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9581 VTY_NEWLINE, VTY_NEWLINE);
9582 header1 = 0;
9585 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9586 if (in)
9588 for (ain = rn->adj_in; ain; ain = ain->next)
9589 if (ain->peer == peer)
9591 if (header1)
9593 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
9594 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9595 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9596 header1 = 0;
9598 if (header2)
9600 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9601 header2 = 0;
9603 if (ain->attr)
9605 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9606 output_count++;
9610 else
9612 for (adj = rn->adj_out; adj; adj = adj->next)
9613 if (adj->peer == peer)
9615 if (header1)
9617 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
9618 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9619 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9620 header1 = 0;
9622 if (header2)
9624 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9625 header2 = 0;
9627 if (adj->attr)
9629 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9630 output_count++;
9635 if (output_count != 0)
9636 vty_out (vty, "%sTotal number of prefixes %ld%s",
9637 VTY_NEWLINE, output_count, VTY_NEWLINE);
9640 static int
9641 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9643 if (! peer || ! peer->afc[afi][safi])
9645 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9646 return CMD_WARNING;
9649 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9651 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9652 VTY_NEWLINE);
9653 return CMD_WARNING;
9656 show_adj_route (vty, peer, afi, safi, in);
9658 return CMD_SUCCESS;
9661 DEFUN (show_ip_bgp_neighbor_advertised_route,
9662 show_ip_bgp_neighbor_advertised_route_cmd,
9663 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9664 SHOW_STR
9665 IP_STR
9666 BGP_STR
9667 "Detailed information on TCP and BGP neighbor connections\n"
9668 "Neighbor to display information about\n"
9669 "Neighbor to display information about\n"
9670 "Display the routes advertised to a BGP neighbor\n")
9672 struct peer *peer;
9674 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9675 if (! peer)
9676 return CMD_WARNING;
9678 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9681 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9682 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9683 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9684 SHOW_STR
9685 IP_STR
9686 BGP_STR
9687 "Address family\n"
9688 "Address Family modifier\n"
9689 "Address Family modifier\n"
9690 "Detailed information on TCP and BGP neighbor connections\n"
9691 "Neighbor to display information about\n"
9692 "Neighbor to display information about\n"
9693 "Display the routes advertised to a BGP neighbor\n")
9695 struct peer *peer;
9697 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9698 if (! peer)
9699 return CMD_WARNING;
9701 if (strncmp (argv[0], "m", 1) == 0)
9702 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9704 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9707 #ifdef HAVE_IPV6
9708 DEFUN (show_bgp_view_neighbor_advertised_route,
9709 show_bgp_view_neighbor_advertised_route_cmd,
9710 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9711 SHOW_STR
9712 BGP_STR
9713 "BGP view\n"
9714 "View name\n"
9715 "Detailed information on TCP and BGP neighbor connections\n"
9716 "Neighbor to display information about\n"
9717 "Neighbor to display information about\n"
9718 "Display the routes advertised to a BGP neighbor\n")
9720 struct peer *peer;
9722 if (argc == 2)
9723 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9724 else
9725 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9727 if (! peer)
9728 return CMD_WARNING;
9730 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9733 ALIAS (show_bgp_view_neighbor_advertised_route,
9734 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9735 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9736 SHOW_STR
9737 BGP_STR
9738 "BGP view\n"
9739 "View name\n"
9740 "Address family\n"
9741 "Detailed information on TCP and BGP neighbor connections\n"
9742 "Neighbor to display information about\n"
9743 "Neighbor to display information about\n"
9744 "Display the routes advertised to a BGP neighbor\n")
9746 DEFUN (show_bgp_view_neighbor_received_routes,
9747 show_bgp_view_neighbor_received_routes_cmd,
9748 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9749 SHOW_STR
9750 BGP_STR
9751 "BGP view\n"
9752 "View name\n"
9753 "Detailed information on TCP and BGP neighbor connections\n"
9754 "Neighbor to display information about\n"
9755 "Neighbor to display information about\n"
9756 "Display the received routes from neighbor\n")
9758 struct peer *peer;
9760 if (argc == 2)
9761 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9762 else
9763 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9765 if (! peer)
9766 return CMD_WARNING;
9768 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9771 ALIAS (show_bgp_view_neighbor_received_routes,
9772 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9773 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9774 SHOW_STR
9775 BGP_STR
9776 "BGP view\n"
9777 "View name\n"
9778 "Address family\n"
9779 "Detailed information on TCP and BGP neighbor connections\n"
9780 "Neighbor to display information about\n"
9781 "Neighbor to display information about\n"
9782 "Display the received routes from neighbor\n")
9784 ALIAS (show_bgp_view_neighbor_advertised_route,
9785 show_bgp_neighbor_advertised_route_cmd,
9786 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9787 SHOW_STR
9788 BGP_STR
9789 "Detailed information on TCP and BGP neighbor connections\n"
9790 "Neighbor to display information about\n"
9791 "Neighbor to display information about\n"
9792 "Display the routes advertised to a BGP neighbor\n")
9794 ALIAS (show_bgp_view_neighbor_advertised_route,
9795 show_bgp_ipv6_neighbor_advertised_route_cmd,
9796 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9797 SHOW_STR
9798 BGP_STR
9799 "Address family\n"
9800 "Detailed information on TCP and BGP neighbor connections\n"
9801 "Neighbor to display information about\n"
9802 "Neighbor to display information about\n"
9803 "Display the routes advertised to a BGP neighbor\n")
9805 /* old command */
9806 ALIAS (show_bgp_view_neighbor_advertised_route,
9807 ipv6_bgp_neighbor_advertised_route_cmd,
9808 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9809 SHOW_STR
9810 IPV6_STR
9811 BGP_STR
9812 "Detailed information on TCP and BGP neighbor connections\n"
9813 "Neighbor to display information about\n"
9814 "Neighbor to display information about\n"
9815 "Display the routes advertised to a BGP neighbor\n")
9817 /* old command */
9818 DEFUN (ipv6_mbgp_neighbor_advertised_route,
9819 ipv6_mbgp_neighbor_advertised_route_cmd,
9820 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9821 SHOW_STR
9822 IPV6_STR
9823 MBGP_STR
9824 "Detailed information on TCP and BGP neighbor connections\n"
9825 "Neighbor to display information about\n"
9826 "Neighbor to display information about\n"
9827 "Display the routes advertised to a BGP neighbor\n")
9829 struct peer *peer;
9831 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9832 if (! peer)
9833 return CMD_WARNING;
9835 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
9837 #endif /* HAVE_IPV6 */
9839 DEFUN (show_ip_bgp_neighbor_received_routes,
9840 show_ip_bgp_neighbor_received_routes_cmd,
9841 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9842 SHOW_STR
9843 IP_STR
9844 BGP_STR
9845 "Detailed information on TCP and BGP neighbor connections\n"
9846 "Neighbor to display information about\n"
9847 "Neighbor to display information about\n"
9848 "Display the received routes from neighbor\n")
9850 struct peer *peer;
9852 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9853 if (! peer)
9854 return CMD_WARNING;
9856 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9859 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9860 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9861 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9862 SHOW_STR
9863 IP_STR
9864 BGP_STR
9865 "Address family\n"
9866 "Address Family modifier\n"
9867 "Address Family modifier\n"
9868 "Detailed information on TCP and BGP neighbor connections\n"
9869 "Neighbor to display information about\n"
9870 "Neighbor to display information about\n"
9871 "Display the received routes from neighbor\n")
9873 struct peer *peer;
9875 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9876 if (! peer)
9877 return CMD_WARNING;
9879 if (strncmp (argv[0], "m", 1) == 0)
9880 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9882 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9885 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9886 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9887 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9888 SHOW_STR
9889 IP_STR
9890 BGP_STR
9891 "Detailed information on TCP and BGP neighbor connections\n"
9892 "Neighbor to display information about\n"
9893 "Neighbor to display information about\n"
9894 "Display information received from a BGP neighbor\n"
9895 "Display the prefixlist filter\n")
9897 char name[BUFSIZ];
9898 union sockunion *su;
9899 struct peer *peer;
9900 int count;
9902 su = sockunion_str2su (argv[0]);
9903 if (su == NULL)
9904 return CMD_WARNING;
9906 peer = peer_lookup (NULL, su);
9907 if (! peer)
9908 return CMD_WARNING;
9910 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9911 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9912 if (count)
9914 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9915 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9918 return CMD_SUCCESS;
9921 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9922 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9923 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9924 SHOW_STR
9925 IP_STR
9926 BGP_STR
9927 "Address family\n"
9928 "Address Family modifier\n"
9929 "Address Family modifier\n"
9930 "Detailed information on TCP and BGP neighbor connections\n"
9931 "Neighbor to display information about\n"
9932 "Neighbor to display information about\n"
9933 "Display information received from a BGP neighbor\n"
9934 "Display the prefixlist filter\n")
9936 char name[BUFSIZ];
9937 union sockunion *su;
9938 struct peer *peer;
9939 int count;
9941 su = sockunion_str2su (argv[1]);
9942 if (su == NULL)
9943 return CMD_WARNING;
9945 peer = peer_lookup (NULL, su);
9946 if (! peer)
9947 return CMD_WARNING;
9949 if (strncmp (argv[0], "m", 1) == 0)
9951 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9952 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9953 if (count)
9955 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9956 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9959 else
9961 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9962 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9963 if (count)
9965 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9966 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9970 return CMD_SUCCESS;
9974 #ifdef HAVE_IPV6
9975 ALIAS (show_bgp_view_neighbor_received_routes,
9976 show_bgp_neighbor_received_routes_cmd,
9977 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9978 SHOW_STR
9979 BGP_STR
9980 "Detailed information on TCP and BGP neighbor connections\n"
9981 "Neighbor to display information about\n"
9982 "Neighbor to display information about\n"
9983 "Display the received routes from neighbor\n")
9985 ALIAS (show_bgp_view_neighbor_received_routes,
9986 show_bgp_ipv6_neighbor_received_routes_cmd,
9987 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9988 SHOW_STR
9989 BGP_STR
9990 "Address family\n"
9991 "Detailed information on TCP and BGP neighbor connections\n"
9992 "Neighbor to display information about\n"
9993 "Neighbor to display information about\n"
9994 "Display the received routes from neighbor\n")
9996 DEFUN (show_bgp_neighbor_received_prefix_filter,
9997 show_bgp_neighbor_received_prefix_filter_cmd,
9998 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9999 SHOW_STR
10000 BGP_STR
10001 "Detailed information on TCP and BGP neighbor connections\n"
10002 "Neighbor to display information about\n"
10003 "Neighbor to display information about\n"
10004 "Display information received from a BGP neighbor\n"
10005 "Display the prefixlist filter\n")
10007 char name[BUFSIZ];
10008 union sockunion *su;
10009 struct peer *peer;
10010 int count;
10012 su = sockunion_str2su (argv[0]);
10013 if (su == NULL)
10014 return CMD_WARNING;
10016 peer = peer_lookup (NULL, su);
10017 if (! peer)
10018 return CMD_WARNING;
10020 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10021 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10022 if (count)
10024 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10025 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10028 return CMD_SUCCESS;
10031 ALIAS (show_bgp_neighbor_received_prefix_filter,
10032 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10033 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10034 SHOW_STR
10035 BGP_STR
10036 "Address family\n"
10037 "Detailed information on TCP and BGP neighbor connections\n"
10038 "Neighbor to display information about\n"
10039 "Neighbor to display information about\n"
10040 "Display information received from a BGP neighbor\n"
10041 "Display the prefixlist filter\n")
10043 /* old command */
10044 ALIAS (show_bgp_view_neighbor_received_routes,
10045 ipv6_bgp_neighbor_received_routes_cmd,
10046 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10047 SHOW_STR
10048 IPV6_STR
10049 BGP_STR
10050 "Detailed information on TCP and BGP neighbor connections\n"
10051 "Neighbor to display information about\n"
10052 "Neighbor to display information about\n"
10053 "Display the received routes from neighbor\n")
10055 /* old command */
10056 DEFUN (ipv6_mbgp_neighbor_received_routes,
10057 ipv6_mbgp_neighbor_received_routes_cmd,
10058 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10059 SHOW_STR
10060 IPV6_STR
10061 MBGP_STR
10062 "Detailed information on TCP and BGP neighbor connections\n"
10063 "Neighbor to display information about\n"
10064 "Neighbor to display information about\n"
10065 "Display the received routes from neighbor\n")
10067 struct peer *peer;
10069 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10070 if (! peer)
10071 return CMD_WARNING;
10073 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
10076 DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10077 show_bgp_view_neighbor_received_prefix_filter_cmd,
10078 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10079 SHOW_STR
10080 BGP_STR
10081 "BGP view\n"
10082 "View name\n"
10083 "Detailed information on TCP and BGP neighbor connections\n"
10084 "Neighbor to display information about\n"
10085 "Neighbor to display information about\n"
10086 "Display information received from a BGP neighbor\n"
10087 "Display the prefixlist filter\n")
10089 char name[BUFSIZ];
10090 union sockunion *su;
10091 struct peer *peer;
10092 struct bgp *bgp;
10093 int count;
10095 /* BGP structure lookup. */
10096 bgp = bgp_lookup_by_name (argv[0]);
10097 if (bgp == NULL)
10099 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10100 return CMD_WARNING;
10103 su = sockunion_str2su (argv[1]);
10104 if (su == NULL)
10105 return CMD_WARNING;
10107 peer = peer_lookup (bgp, su);
10108 if (! peer)
10109 return CMD_WARNING;
10111 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10112 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10113 if (count)
10115 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10116 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10119 return CMD_SUCCESS;
10122 ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10123 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10124 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10125 SHOW_STR
10126 BGP_STR
10127 "BGP view\n"
10128 "View name\n"
10129 "Address family\n"
10130 "Detailed information on TCP and BGP neighbor connections\n"
10131 "Neighbor to display information about\n"
10132 "Neighbor to display information about\n"
10133 "Display information received from a BGP neighbor\n"
10134 "Display the prefixlist filter\n")
10135 #endif /* HAVE_IPV6 */
10137 static int
10138 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
10139 safi_t safi, enum bgp_show_type type)
10141 if (! peer || ! peer->afc[afi][safi])
10143 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10144 return CMD_WARNING;
10147 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
10150 DEFUN (show_ip_bgp_neighbor_routes,
10151 show_ip_bgp_neighbor_routes_cmd,
10152 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10153 SHOW_STR
10154 IP_STR
10155 BGP_STR
10156 "Detailed information on TCP and BGP neighbor connections\n"
10157 "Neighbor to display information about\n"
10158 "Neighbor to display information about\n"
10159 "Display routes learned from neighbor\n")
10161 struct peer *peer;
10163 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10164 if (! peer)
10165 return CMD_WARNING;
10167 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10168 bgp_show_type_neighbor);
10171 DEFUN (show_ip_bgp_neighbor_flap,
10172 show_ip_bgp_neighbor_flap_cmd,
10173 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10174 SHOW_STR
10175 IP_STR
10176 BGP_STR
10177 "Detailed information on TCP and BGP neighbor connections\n"
10178 "Neighbor to display information about\n"
10179 "Neighbor to display information about\n"
10180 "Display flap statistics of the routes learned from neighbor\n")
10182 struct peer *peer;
10184 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10185 if (! peer)
10186 return CMD_WARNING;
10188 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10189 bgp_show_type_flap_neighbor);
10192 DEFUN (show_ip_bgp_neighbor_damp,
10193 show_ip_bgp_neighbor_damp_cmd,
10194 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10195 SHOW_STR
10196 IP_STR
10197 BGP_STR
10198 "Detailed information on TCP and BGP neighbor connections\n"
10199 "Neighbor to display information about\n"
10200 "Neighbor to display information about\n"
10201 "Display the dampened routes received from neighbor\n")
10203 struct peer *peer;
10205 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10206 if (! peer)
10207 return CMD_WARNING;
10209 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10210 bgp_show_type_damp_neighbor);
10213 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10214 show_ip_bgp_ipv4_neighbor_routes_cmd,
10215 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10216 SHOW_STR
10217 IP_STR
10218 BGP_STR
10219 "Address family\n"
10220 "Address Family modifier\n"
10221 "Address Family modifier\n"
10222 "Detailed information on TCP and BGP neighbor connections\n"
10223 "Neighbor to display information about\n"
10224 "Neighbor to display information about\n"
10225 "Display routes learned from neighbor\n")
10227 struct peer *peer;
10229 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10230 if (! peer)
10231 return CMD_WARNING;
10233 if (strncmp (argv[0], "m", 1) == 0)
10234 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
10235 bgp_show_type_neighbor);
10237 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10238 bgp_show_type_neighbor);
10241 DEFUN (show_ip_bgp_view_rsclient,
10242 show_ip_bgp_view_rsclient_cmd,
10243 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10244 SHOW_STR
10245 IP_STR
10246 BGP_STR
10247 "BGP view\n"
10248 "BGP view name\n"
10249 "Information about Route Server Client\n"
10250 NEIGHBOR_ADDR_STR)
10252 struct bgp_table *table;
10253 struct peer *peer;
10255 if (argc == 2)
10256 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10257 else
10258 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10260 if (! peer)
10261 return CMD_WARNING;
10263 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10265 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10266 VTY_NEWLINE);
10267 return CMD_WARNING;
10270 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10271 PEER_FLAG_RSERVER_CLIENT))
10273 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10274 VTY_NEWLINE);
10275 return CMD_WARNING;
10278 table = peer->rib[AFI_IP][SAFI_UNICAST];
10280 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10283 ALIAS (show_ip_bgp_view_rsclient,
10284 show_ip_bgp_rsclient_cmd,
10285 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10286 SHOW_STR
10287 IP_STR
10288 BGP_STR
10289 "Information about Route Server Client\n"
10290 NEIGHBOR_ADDR_STR)
10292 DEFUN (show_ip_bgp_view_rsclient_route,
10293 show_ip_bgp_view_rsclient_route_cmd,
10294 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10295 SHOW_STR
10296 IP_STR
10297 BGP_STR
10298 "BGP view\n"
10299 "BGP view name\n"
10300 "Information about Route Server Client\n"
10301 NEIGHBOR_ADDR_STR
10302 "Network in the BGP routing table to display\n")
10304 struct bgp *bgp;
10305 struct peer *peer;
10307 /* BGP structure lookup. */
10308 if (argc == 3)
10310 bgp = bgp_lookup_by_name (argv[0]);
10311 if (bgp == NULL)
10313 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10314 return CMD_WARNING;
10317 else
10319 bgp = bgp_get_default ();
10320 if (bgp == NULL)
10322 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10323 return CMD_WARNING;
10327 if (argc == 3)
10328 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10329 else
10330 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10332 if (! peer)
10333 return CMD_WARNING;
10335 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10337 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10338 VTY_NEWLINE);
10339 return CMD_WARNING;
10342 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10343 PEER_FLAG_RSERVER_CLIENT))
10345 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10346 VTY_NEWLINE);
10347 return CMD_WARNING;
10350 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10351 (argc == 3) ? argv[2] : argv[1],
10352 AFI_IP, SAFI_UNICAST, NULL, 0);
10355 ALIAS (show_ip_bgp_view_rsclient_route,
10356 show_ip_bgp_rsclient_route_cmd,
10357 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10358 SHOW_STR
10359 IP_STR
10360 BGP_STR
10361 "Information about Route Server Client\n"
10362 NEIGHBOR_ADDR_STR
10363 "Network in the BGP routing table to display\n")
10365 DEFUN (show_ip_bgp_view_rsclient_prefix,
10366 show_ip_bgp_view_rsclient_prefix_cmd,
10367 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10368 SHOW_STR
10369 IP_STR
10370 BGP_STR
10371 "BGP view\n"
10372 "BGP view name\n"
10373 "Information about Route Server Client\n"
10374 NEIGHBOR_ADDR_STR
10375 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10377 struct bgp *bgp;
10378 struct peer *peer;
10380 /* BGP structure lookup. */
10381 if (argc == 3)
10383 bgp = bgp_lookup_by_name (argv[0]);
10384 if (bgp == NULL)
10386 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10387 return CMD_WARNING;
10390 else
10392 bgp = bgp_get_default ();
10393 if (bgp == NULL)
10395 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10396 return CMD_WARNING;
10400 if (argc == 3)
10401 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10402 else
10403 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10405 if (! peer)
10406 return CMD_WARNING;
10408 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10410 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10411 VTY_NEWLINE);
10412 return CMD_WARNING;
10415 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10416 PEER_FLAG_RSERVER_CLIENT))
10418 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10419 VTY_NEWLINE);
10420 return CMD_WARNING;
10423 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10424 (argc == 3) ? argv[2] : argv[1],
10425 AFI_IP, SAFI_UNICAST, NULL, 1);
10428 ALIAS (show_ip_bgp_view_rsclient_prefix,
10429 show_ip_bgp_rsclient_prefix_cmd,
10430 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10431 SHOW_STR
10432 IP_STR
10433 BGP_STR
10434 "Information about Route Server Client\n"
10435 NEIGHBOR_ADDR_STR
10436 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10439 #ifdef HAVE_IPV6
10440 DEFUN (show_bgp_view_neighbor_routes,
10441 show_bgp_view_neighbor_routes_cmd,
10442 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10443 SHOW_STR
10444 BGP_STR
10445 "BGP view\n"
10446 "BGP view name\n"
10447 "Detailed information on TCP and BGP neighbor connections\n"
10448 "Neighbor to display information about\n"
10449 "Neighbor to display information about\n"
10450 "Display routes learned from neighbor\n")
10452 struct peer *peer;
10454 if (argc == 2)
10455 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10456 else
10457 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10459 if (! peer)
10460 return CMD_WARNING;
10462 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10463 bgp_show_type_neighbor);
10466 ALIAS (show_bgp_view_neighbor_routes,
10467 show_bgp_view_ipv6_neighbor_routes_cmd,
10468 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10469 SHOW_STR
10470 BGP_STR
10471 "BGP view\n"
10472 "BGP view name\n"
10473 "Address family\n"
10474 "Detailed information on TCP and BGP neighbor connections\n"
10475 "Neighbor to display information about\n"
10476 "Neighbor to display information about\n"
10477 "Display routes learned from neighbor\n")
10479 DEFUN (show_bgp_view_neighbor_damp,
10480 show_bgp_view_neighbor_damp_cmd,
10481 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10482 SHOW_STR
10483 BGP_STR
10484 "BGP view\n"
10485 "BGP view name\n"
10486 "Detailed information on TCP and BGP neighbor connections\n"
10487 "Neighbor to display information about\n"
10488 "Neighbor to display information about\n"
10489 "Display the dampened routes received from neighbor\n")
10491 struct peer *peer;
10493 if (argc == 2)
10494 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10495 else
10496 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10498 if (! peer)
10499 return CMD_WARNING;
10501 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10502 bgp_show_type_damp_neighbor);
10505 ALIAS (show_bgp_view_neighbor_damp,
10506 show_bgp_view_ipv6_neighbor_damp_cmd,
10507 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10508 SHOW_STR
10509 BGP_STR
10510 "BGP view\n"
10511 "BGP view name\n"
10512 "Address family\n"
10513 "Detailed information on TCP and BGP neighbor connections\n"
10514 "Neighbor to display information about\n"
10515 "Neighbor to display information about\n"
10516 "Display the dampened routes received from neighbor\n")
10518 DEFUN (show_bgp_view_neighbor_flap,
10519 show_bgp_view_neighbor_flap_cmd,
10520 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10521 SHOW_STR
10522 BGP_STR
10523 "BGP view\n"
10524 "BGP view name\n"
10525 "Detailed information on TCP and BGP neighbor connections\n"
10526 "Neighbor to display information about\n"
10527 "Neighbor to display information about\n"
10528 "Display flap statistics of the routes learned from neighbor\n")
10530 struct peer *peer;
10532 if (argc == 2)
10533 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10534 else
10535 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10537 if (! peer)
10538 return CMD_WARNING;
10540 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10541 bgp_show_type_flap_neighbor);
10544 ALIAS (show_bgp_view_neighbor_flap,
10545 show_bgp_view_ipv6_neighbor_flap_cmd,
10546 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10547 SHOW_STR
10548 BGP_STR
10549 "BGP view\n"
10550 "BGP view name\n"
10551 "Address family\n"
10552 "Detailed information on TCP and BGP neighbor connections\n"
10553 "Neighbor to display information about\n"
10554 "Neighbor to display information about\n"
10555 "Display flap statistics of the routes learned from neighbor\n")
10557 ALIAS (show_bgp_view_neighbor_routes,
10558 show_bgp_neighbor_routes_cmd,
10559 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10560 SHOW_STR
10561 BGP_STR
10562 "Detailed information on TCP and BGP neighbor connections\n"
10563 "Neighbor to display information about\n"
10564 "Neighbor to display information about\n"
10565 "Display routes learned from neighbor\n")
10568 ALIAS (show_bgp_view_neighbor_routes,
10569 show_bgp_ipv6_neighbor_routes_cmd,
10570 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10571 SHOW_STR
10572 BGP_STR
10573 "Address family\n"
10574 "Detailed information on TCP and BGP neighbor connections\n"
10575 "Neighbor to display information about\n"
10576 "Neighbor to display information about\n"
10577 "Display routes learned from neighbor\n")
10579 /* old command */
10580 ALIAS (show_bgp_view_neighbor_routes,
10581 ipv6_bgp_neighbor_routes_cmd,
10582 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10583 SHOW_STR
10584 IPV6_STR
10585 BGP_STR
10586 "Detailed information on TCP and BGP neighbor connections\n"
10587 "Neighbor to display information about\n"
10588 "Neighbor to display information about\n"
10589 "Display routes learned from neighbor\n")
10591 /* old command */
10592 DEFUN (ipv6_mbgp_neighbor_routes,
10593 ipv6_mbgp_neighbor_routes_cmd,
10594 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10595 SHOW_STR
10596 IPV6_STR
10597 MBGP_STR
10598 "Detailed information on TCP and BGP neighbor connections\n"
10599 "Neighbor to display information about\n"
10600 "Neighbor to display information about\n"
10601 "Display routes learned from neighbor\n")
10603 struct peer *peer;
10605 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10606 if (! peer)
10607 return CMD_WARNING;
10609 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
10610 bgp_show_type_neighbor);
10613 ALIAS (show_bgp_view_neighbor_flap,
10614 show_bgp_neighbor_flap_cmd,
10615 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10616 SHOW_STR
10617 BGP_STR
10618 "Detailed information on TCP and BGP neighbor connections\n"
10619 "Neighbor to display information about\n"
10620 "Neighbor to display information about\n"
10621 "Display flap statistics of the routes learned from neighbor\n")
10623 ALIAS (show_bgp_view_neighbor_flap,
10624 show_bgp_ipv6_neighbor_flap_cmd,
10625 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10626 SHOW_STR
10627 BGP_STR
10628 "Address family\n"
10629 "Detailed information on TCP and BGP neighbor connections\n"
10630 "Neighbor to display information about\n"
10631 "Neighbor to display information about\n"
10632 "Display flap statistics of the routes learned from neighbor\n")
10634 ALIAS (show_bgp_view_neighbor_damp,
10635 show_bgp_neighbor_damp_cmd,
10636 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10637 SHOW_STR
10638 BGP_STR
10639 "Detailed information on TCP and BGP neighbor connections\n"
10640 "Neighbor to display information about\n"
10641 "Neighbor to display information about\n"
10642 "Display the dampened routes received from neighbor\n")
10644 ALIAS (show_bgp_view_neighbor_damp,
10645 show_bgp_ipv6_neighbor_damp_cmd,
10646 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10647 SHOW_STR
10648 BGP_STR
10649 "Address family\n"
10650 "Detailed information on TCP and BGP neighbor connections\n"
10651 "Neighbor to display information about\n"
10652 "Neighbor to display information about\n"
10653 "Display the dampened routes received from neighbor\n")
10655 DEFUN (show_bgp_view_rsclient,
10656 show_bgp_view_rsclient_cmd,
10657 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10658 SHOW_STR
10659 BGP_STR
10660 "BGP view\n"
10661 "BGP view name\n"
10662 "Information about Route Server Client\n"
10663 NEIGHBOR_ADDR_STR)
10665 struct bgp_table *table;
10666 struct peer *peer;
10668 if (argc == 2)
10669 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10670 else
10671 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10673 if (! peer)
10674 return CMD_WARNING;
10676 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10678 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10679 VTY_NEWLINE);
10680 return CMD_WARNING;
10683 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10684 PEER_FLAG_RSERVER_CLIENT))
10686 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10687 VTY_NEWLINE);
10688 return CMD_WARNING;
10691 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10693 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10696 ALIAS (show_bgp_view_rsclient,
10697 show_bgp_rsclient_cmd,
10698 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10699 SHOW_STR
10700 BGP_STR
10701 "Information about Route Server Client\n"
10702 NEIGHBOR_ADDR_STR)
10704 DEFUN (show_bgp_view_rsclient_route,
10705 show_bgp_view_rsclient_route_cmd,
10706 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10707 SHOW_STR
10708 BGP_STR
10709 "BGP view\n"
10710 "BGP view name\n"
10711 "Information about Route Server Client\n"
10712 NEIGHBOR_ADDR_STR
10713 "Network in the BGP routing table to display\n")
10715 struct bgp *bgp;
10716 struct peer *peer;
10718 /* BGP structure lookup. */
10719 if (argc == 3)
10721 bgp = bgp_lookup_by_name (argv[0]);
10722 if (bgp == NULL)
10724 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10725 return CMD_WARNING;
10728 else
10730 bgp = bgp_get_default ();
10731 if (bgp == NULL)
10733 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10734 return CMD_WARNING;
10738 if (argc == 3)
10739 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10740 else
10741 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10743 if (! peer)
10744 return CMD_WARNING;
10746 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10748 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10749 VTY_NEWLINE);
10750 return CMD_WARNING;
10753 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10754 PEER_FLAG_RSERVER_CLIENT))
10756 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10757 VTY_NEWLINE);
10758 return CMD_WARNING;
10761 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10762 (argc == 3) ? argv[2] : argv[1],
10763 AFI_IP6, SAFI_UNICAST, NULL, 0);
10766 ALIAS (show_bgp_view_rsclient_route,
10767 show_bgp_rsclient_route_cmd,
10768 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10769 SHOW_STR
10770 BGP_STR
10771 "Information about Route Server Client\n"
10772 NEIGHBOR_ADDR_STR
10773 "Network in the BGP routing table to display\n")
10775 DEFUN (show_bgp_view_rsclient_prefix,
10776 show_bgp_view_rsclient_prefix_cmd,
10777 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10778 SHOW_STR
10779 BGP_STR
10780 "BGP view\n"
10781 "BGP view name\n"
10782 "Information about Route Server Client\n"
10783 NEIGHBOR_ADDR_STR
10784 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10786 struct bgp *bgp;
10787 struct peer *peer;
10789 /* BGP structure lookup. */
10790 if (argc == 3)
10792 bgp = bgp_lookup_by_name (argv[0]);
10793 if (bgp == NULL)
10795 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10796 return CMD_WARNING;
10799 else
10801 bgp = bgp_get_default ();
10802 if (bgp == NULL)
10804 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10805 return CMD_WARNING;
10809 if (argc == 3)
10810 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10811 else
10812 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10814 if (! peer)
10815 return CMD_WARNING;
10817 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10819 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10820 VTY_NEWLINE);
10821 return CMD_WARNING;
10824 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10825 PEER_FLAG_RSERVER_CLIENT))
10827 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10828 VTY_NEWLINE);
10829 return CMD_WARNING;
10832 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10833 (argc == 3) ? argv[2] : argv[1],
10834 AFI_IP6, SAFI_UNICAST, NULL, 1);
10837 ALIAS (show_bgp_view_rsclient_prefix,
10838 show_bgp_rsclient_prefix_cmd,
10839 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10840 SHOW_STR
10841 BGP_STR
10842 "Information about Route Server Client\n"
10843 NEIGHBOR_ADDR_STR
10844 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10846 #endif /* HAVE_IPV6 */
10848 struct bgp_table *bgp_distance_table;
10850 struct bgp_distance
10852 /* Distance value for the IP source prefix. */
10853 u_char distance;
10855 /* Name of the access-list to be matched. */
10856 char *access_list;
10859 static struct bgp_distance *
10860 bgp_distance_new ()
10862 struct bgp_distance *new;
10863 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
10864 memset (new, 0, sizeof (struct bgp_distance));
10865 return new;
10868 static void
10869 bgp_distance_free (struct bgp_distance *bdistance)
10871 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10874 static int
10875 bgp_distance_set (struct vty *vty, const char *distance_str,
10876 const char *ip_str, const char *access_list_str)
10878 int ret;
10879 struct prefix_ipv4 p;
10880 u_char distance;
10881 struct bgp_node *rn;
10882 struct bgp_distance *bdistance;
10884 ret = str2prefix_ipv4 (ip_str, &p);
10885 if (ret == 0)
10887 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10888 return CMD_WARNING;
10891 distance = atoi (distance_str);
10893 /* Get BGP distance node. */
10894 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10895 if (rn->info)
10897 bdistance = rn->info;
10898 bgp_unlock_node (rn);
10900 else
10902 bdistance = bgp_distance_new ();
10903 rn->info = bdistance;
10906 /* Set distance value. */
10907 bdistance->distance = distance;
10909 /* Reset access-list configuration. */
10910 if (bdistance->access_list)
10912 free (bdistance->access_list);
10913 bdistance->access_list = NULL;
10915 if (access_list_str)
10916 bdistance->access_list = strdup (access_list_str);
10918 return CMD_SUCCESS;
10921 static int
10922 bgp_distance_unset (struct vty *vty, const char *distance_str,
10923 const char *ip_str, const char *access_list_str)
10925 int ret;
10926 struct prefix_ipv4 p;
10927 u_char distance;
10928 struct bgp_node *rn;
10929 struct bgp_distance *bdistance;
10931 ret = str2prefix_ipv4 (ip_str, &p);
10932 if (ret == 0)
10934 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10935 return CMD_WARNING;
10938 distance = atoi (distance_str);
10940 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10941 if (! rn)
10943 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10944 return CMD_WARNING;
10947 bdistance = rn->info;
10949 if (bdistance->access_list)
10950 free (bdistance->access_list);
10951 bgp_distance_free (bdistance);
10953 rn->info = NULL;
10954 bgp_unlock_node (rn);
10955 bgp_unlock_node (rn);
10957 return CMD_SUCCESS;
10960 static void
10961 bgp_distance_reset ()
10963 struct bgp_node *rn;
10964 struct bgp_distance *bdistance;
10966 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10967 if ((bdistance = rn->info) != NULL)
10969 if (bdistance->access_list)
10970 free (bdistance->access_list);
10971 bgp_distance_free (bdistance);
10972 rn->info = NULL;
10973 bgp_unlock_node (rn);
10977 /* Apply BGP information to distance method. */
10978 u_char
10979 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10981 struct bgp_node *rn;
10982 struct prefix_ipv4 q;
10983 struct peer *peer;
10984 struct bgp_distance *bdistance;
10985 struct access_list *alist;
10986 struct bgp_static *bgp_static;
10988 if (! bgp)
10989 return 0;
10991 if (p->family != AF_INET)
10992 return 0;
10994 peer = rinfo->peer;
10996 if (peer->su.sa.sa_family != AF_INET)
10997 return 0;
10999 memset (&q, 0, sizeof (struct prefix_ipv4));
11000 q.family = AF_INET;
11001 q.prefix = peer->su.sin.sin_addr;
11002 q.prefixlen = IPV4_MAX_BITLEN;
11004 /* Check source address. */
11005 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11006 if (rn)
11008 bdistance = rn->info;
11009 bgp_unlock_node (rn);
11011 if (bdistance->access_list)
11013 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11014 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11015 return bdistance->distance;
11017 else
11018 return bdistance->distance;
11021 /* Backdoor check. */
11022 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11023 if (rn)
11025 bgp_static = rn->info;
11026 bgp_unlock_node (rn);
11028 if (bgp_static->backdoor)
11030 if (bgp->distance_local)
11031 return bgp->distance_local;
11032 else
11033 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11037 if (peer_sort (peer) == BGP_PEER_EBGP)
11039 if (bgp->distance_ebgp)
11040 return bgp->distance_ebgp;
11041 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11043 else
11045 if (bgp->distance_ibgp)
11046 return bgp->distance_ibgp;
11047 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11051 DEFUN (bgp_distance,
11052 bgp_distance_cmd,
11053 "distance bgp <1-255> <1-255> <1-255>",
11054 "Define an administrative distance\n"
11055 "BGP distance\n"
11056 "Distance for routes external to the AS\n"
11057 "Distance for routes internal to the AS\n"
11058 "Distance for local routes\n")
11060 struct bgp *bgp;
11062 bgp = vty->index;
11064 bgp->distance_ebgp = atoi (argv[0]);
11065 bgp->distance_ibgp = atoi (argv[1]);
11066 bgp->distance_local = atoi (argv[2]);
11067 return CMD_SUCCESS;
11070 DEFUN (no_bgp_distance,
11071 no_bgp_distance_cmd,
11072 "no distance bgp <1-255> <1-255> <1-255>",
11073 NO_STR
11074 "Define an administrative distance\n"
11075 "BGP distance\n"
11076 "Distance for routes external to the AS\n"
11077 "Distance for routes internal to the AS\n"
11078 "Distance for local routes\n")
11080 struct bgp *bgp;
11082 bgp = vty->index;
11084 bgp->distance_ebgp= 0;
11085 bgp->distance_ibgp = 0;
11086 bgp->distance_local = 0;
11087 return CMD_SUCCESS;
11090 ALIAS (no_bgp_distance,
11091 no_bgp_distance2_cmd,
11092 "no distance bgp",
11093 NO_STR
11094 "Define an administrative distance\n"
11095 "BGP distance\n")
11097 DEFUN (bgp_distance_source,
11098 bgp_distance_source_cmd,
11099 "distance <1-255> A.B.C.D/M",
11100 "Define an administrative distance\n"
11101 "Administrative distance\n"
11102 "IP source prefix\n")
11104 bgp_distance_set (vty, argv[0], argv[1], NULL);
11105 return CMD_SUCCESS;
11108 DEFUN (no_bgp_distance_source,
11109 no_bgp_distance_source_cmd,
11110 "no distance <1-255> A.B.C.D/M",
11111 NO_STR
11112 "Define an administrative distance\n"
11113 "Administrative distance\n"
11114 "IP source prefix\n")
11116 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11117 return CMD_SUCCESS;
11120 DEFUN (bgp_distance_source_access_list,
11121 bgp_distance_source_access_list_cmd,
11122 "distance <1-255> A.B.C.D/M WORD",
11123 "Define an administrative distance\n"
11124 "Administrative distance\n"
11125 "IP source prefix\n"
11126 "Access list name\n")
11128 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11129 return CMD_SUCCESS;
11132 DEFUN (no_bgp_distance_source_access_list,
11133 no_bgp_distance_source_access_list_cmd,
11134 "no distance <1-255> A.B.C.D/M WORD",
11135 NO_STR
11136 "Define an administrative distance\n"
11137 "Administrative distance\n"
11138 "IP source prefix\n"
11139 "Access list name\n")
11141 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11142 return CMD_SUCCESS;
11145 DEFUN (bgp_damp_set,
11146 bgp_damp_set_cmd,
11147 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11148 "BGP Specific commands\n"
11149 "Enable route-flap dampening\n"
11150 "Half-life time for the penalty\n"
11151 "Value to start reusing a route\n"
11152 "Value to start suppressing a route\n"
11153 "Maximum duration to suppress a stable route\n")
11155 struct bgp *bgp;
11156 int half = DEFAULT_HALF_LIFE * 60;
11157 int reuse = DEFAULT_REUSE;
11158 int suppress = DEFAULT_SUPPRESS;
11159 int max = 4 * half;
11161 if (argc == 4)
11163 half = atoi (argv[0]) * 60;
11164 reuse = atoi (argv[1]);
11165 suppress = atoi (argv[2]);
11166 max = atoi (argv[3]) * 60;
11168 else if (argc == 1)
11170 half = atoi (argv[0]) * 60;
11171 max = 4 * half;
11174 bgp = vty->index;
11175 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11176 half, reuse, suppress, max);
11179 ALIAS (bgp_damp_set,
11180 bgp_damp_set2_cmd,
11181 "bgp dampening <1-45>",
11182 "BGP Specific commands\n"
11183 "Enable route-flap dampening\n"
11184 "Half-life time for the penalty\n")
11186 ALIAS (bgp_damp_set,
11187 bgp_damp_set3_cmd,
11188 "bgp dampening",
11189 "BGP Specific commands\n"
11190 "Enable route-flap dampening\n")
11192 DEFUN (bgp_damp_unset,
11193 bgp_damp_unset_cmd,
11194 "no bgp dampening",
11195 NO_STR
11196 "BGP Specific commands\n"
11197 "Enable route-flap dampening\n")
11199 struct bgp *bgp;
11201 bgp = vty->index;
11202 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11205 ALIAS (bgp_damp_unset,
11206 bgp_damp_unset2_cmd,
11207 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11208 NO_STR
11209 "BGP Specific commands\n"
11210 "Enable route-flap dampening\n"
11211 "Half-life time for the penalty\n"
11212 "Value to start reusing a route\n"
11213 "Value to start suppressing a route\n"
11214 "Maximum duration to suppress a stable route\n")
11216 DEFUN (show_ip_bgp_dampened_paths,
11217 show_ip_bgp_dampened_paths_cmd,
11218 "show ip bgp dampened-paths",
11219 SHOW_STR
11220 IP_STR
11221 BGP_STR
11222 "Display paths suppressed due to dampening\n")
11224 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11225 NULL);
11228 DEFUN (show_ip_bgp_flap_statistics,
11229 show_ip_bgp_flap_statistics_cmd,
11230 "show ip bgp flap-statistics",
11231 SHOW_STR
11232 IP_STR
11233 BGP_STR
11234 "Display flap statistics of routes\n")
11236 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11237 bgp_show_type_flap_statistics, NULL);
11240 /* Display specified route of BGP table. */
11241 static int
11242 bgp_clear_damp_route (struct vty *vty, const char *view_name,
11243 const char *ip_str, afi_t afi, safi_t safi,
11244 struct prefix_rd *prd, int prefix_check)
11246 int ret;
11247 struct prefix match;
11248 struct bgp_node *rn;
11249 struct bgp_node *rm;
11250 struct bgp_info *ri;
11251 struct bgp_info *ri_temp;
11252 struct bgp *bgp;
11253 struct bgp_table *table;
11255 /* BGP structure lookup. */
11256 if (view_name)
11258 bgp = bgp_lookup_by_name (view_name);
11259 if (bgp == NULL)
11261 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11262 return CMD_WARNING;
11265 else
11267 bgp = bgp_get_default ();
11268 if (bgp == NULL)
11270 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11271 return CMD_WARNING;
11275 /* Check IP address argument. */
11276 ret = str2prefix (ip_str, &match);
11277 if (! ret)
11279 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11280 return CMD_WARNING;
11283 match.family = afi2family (afi);
11285 if (safi == SAFI_MPLS_VPN)
11287 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11289 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11290 continue;
11292 if ((table = rn->info) != NULL)
11293 if ((rm = bgp_node_match (table, &match)) != NULL)
11294 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11296 ri = rm->info;
11297 while (ri)
11299 if (ri->extra && ri->extra->damp_info)
11301 ri_temp = ri->next;
11302 bgp_damp_info_free (ri->extra->damp_info, 1);
11303 ri = ri_temp;
11305 else
11306 ri = ri->next;
11311 else
11313 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11314 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11316 ri = rn->info;
11317 while (ri)
11319 if (ri->extra && ri->extra->damp_info)
11321 ri_temp = ri->next;
11322 bgp_damp_info_free (ri->extra->damp_info, 1);
11323 ri = ri_temp;
11325 else
11326 ri = ri->next;
11331 return CMD_SUCCESS;
11334 DEFUN (clear_ip_bgp_dampening,
11335 clear_ip_bgp_dampening_cmd,
11336 "clear ip bgp dampening",
11337 CLEAR_STR
11338 IP_STR
11339 BGP_STR
11340 "Clear route flap dampening information\n")
11342 bgp_damp_info_clean ();
11343 return CMD_SUCCESS;
11346 DEFUN (clear_ip_bgp_dampening_prefix,
11347 clear_ip_bgp_dampening_prefix_cmd,
11348 "clear ip bgp dampening A.B.C.D/M",
11349 CLEAR_STR
11350 IP_STR
11351 BGP_STR
11352 "Clear route flap dampening information\n"
11353 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11355 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11356 SAFI_UNICAST, NULL, 1);
11359 DEFUN (clear_ip_bgp_dampening_address,
11360 clear_ip_bgp_dampening_address_cmd,
11361 "clear ip bgp dampening A.B.C.D",
11362 CLEAR_STR
11363 IP_STR
11364 BGP_STR
11365 "Clear route flap dampening information\n"
11366 "Network to clear damping information\n")
11368 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11369 SAFI_UNICAST, NULL, 0);
11372 DEFUN (clear_ip_bgp_dampening_address_mask,
11373 clear_ip_bgp_dampening_address_mask_cmd,
11374 "clear ip bgp dampening A.B.C.D A.B.C.D",
11375 CLEAR_STR
11376 IP_STR
11377 BGP_STR
11378 "Clear route flap dampening information\n"
11379 "Network to clear damping information\n"
11380 "Network mask\n")
11382 int ret;
11383 char prefix_str[BUFSIZ];
11385 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11386 if (! ret)
11388 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11389 return CMD_WARNING;
11392 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11393 SAFI_UNICAST, NULL, 0);
11396 static int
11397 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11398 afi_t afi, safi_t safi, int *write)
11400 struct bgp_node *prn;
11401 struct bgp_node *rn;
11402 struct bgp_table *table;
11403 struct prefix *p;
11404 struct prefix_rd *prd;
11405 struct bgp_static *bgp_static;
11406 u_int32_t label;
11407 char buf[SU_ADDRSTRLEN];
11408 char rdbuf[RD_ADDRSTRLEN];
11410 /* Network configuration. */
11411 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11412 if ((table = prn->info) != NULL)
11413 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11414 if ((bgp_static = rn->info) != NULL)
11416 p = &rn->p;
11417 prd = (struct prefix_rd *) &prn->p;
11419 /* "address-family" display. */
11420 bgp_config_write_family_header (vty, afi, safi, write);
11422 /* "network" configuration display. */
11423 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11424 label = decode_label (bgp_static->tag);
11426 vty_out (vty, " network %s/%d rd %s tag %d",
11427 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11428 p->prefixlen,
11429 rdbuf, label);
11430 vty_out (vty, "%s", VTY_NEWLINE);
11432 return 0;
11435 /* Configuration of static route announcement and aggregate
11436 information. */
11438 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11439 afi_t afi, safi_t safi, int *write)
11441 struct bgp_node *rn;
11442 struct prefix *p;
11443 struct bgp_static *bgp_static;
11444 struct bgp_aggregate *bgp_aggregate;
11445 char buf[SU_ADDRSTRLEN];
11447 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11448 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11450 /* Network configuration. */
11451 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11452 if ((bgp_static = rn->info) != NULL)
11454 p = &rn->p;
11456 /* "address-family" display. */
11457 bgp_config_write_family_header (vty, afi, safi, write);
11459 /* "network" configuration display. */
11460 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11462 u_int32_t destination;
11463 struct in_addr netmask;
11465 destination = ntohl (p->u.prefix4.s_addr);
11466 masklen2ip (p->prefixlen, &netmask);
11467 vty_out (vty, " network %s",
11468 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11470 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11471 || (IN_CLASSB (destination) && p->prefixlen == 16)
11472 || (IN_CLASSA (destination) && p->prefixlen == 8)
11473 || p->u.prefix4.s_addr == 0)
11475 /* Natural mask is not display. */
11477 else
11478 vty_out (vty, " mask %s", inet_ntoa (netmask));
11480 else
11482 vty_out (vty, " network %s/%d",
11483 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11484 p->prefixlen);
11487 if (bgp_static->rmap.name)
11488 vty_out (vty, " route-map %s", bgp_static->rmap.name);
11489 else
11491 if (bgp_static->backdoor)
11492 vty_out (vty, " backdoor");
11493 if (bgp_static->ttl)
11494 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11497 vty_out (vty, "%s", VTY_NEWLINE);
11500 /* Aggregate-address configuration. */
11501 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11502 if ((bgp_aggregate = rn->info) != NULL)
11504 p = &rn->p;
11506 /* "address-family" display. */
11507 bgp_config_write_family_header (vty, afi, safi, write);
11509 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11511 struct in_addr netmask;
11513 masklen2ip (p->prefixlen, &netmask);
11514 vty_out (vty, " aggregate-address %s %s",
11515 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11516 inet_ntoa (netmask));
11518 else
11520 vty_out (vty, " aggregate-address %s/%d",
11521 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11522 p->prefixlen);
11525 if (bgp_aggregate->as_set)
11526 vty_out (vty, " as-set");
11528 if (bgp_aggregate->summary_only)
11529 vty_out (vty, " summary-only");
11531 vty_out (vty, "%s", VTY_NEWLINE);
11534 return 0;
11538 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11540 struct bgp_node *rn;
11541 struct bgp_distance *bdistance;
11543 /* Distance configuration. */
11544 if (bgp->distance_ebgp
11545 && bgp->distance_ibgp
11546 && bgp->distance_local
11547 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11548 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11549 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11550 vty_out (vty, " distance bgp %d %d %d%s",
11551 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11552 VTY_NEWLINE);
11554 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11555 if ((bdistance = rn->info) != NULL)
11557 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11558 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11559 bdistance->access_list ? bdistance->access_list : "",
11560 VTY_NEWLINE);
11563 return 0;
11566 /* Allocate routing table structure and install commands. */
11567 void
11568 bgp_route_init ()
11570 /* Init BGP distance table. */
11571 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
11573 /* IPv4 BGP commands. */
11574 install_element (BGP_NODE, &bgp_network_cmd);
11575 install_element (BGP_NODE, &bgp_network_mask_cmd);
11576 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11577 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11578 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11579 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11580 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11581 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11582 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
11583 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11584 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11585 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11586 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11587 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11588 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
11589 install_element (BGP_NODE, &no_bgp_network_cmd);
11590 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11591 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11592 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11593 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11594 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11595 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11596 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11597 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
11598 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11599 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11600 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11601 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11602 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11603 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
11605 install_element (BGP_NODE, &aggregate_address_cmd);
11606 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11607 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11608 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11609 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11610 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11611 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11612 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11613 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11614 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11615 install_element (BGP_NODE, &no_aggregate_address_cmd);
11616 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11617 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11618 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11619 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11620 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11621 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11622 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11623 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11624 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11626 /* IPv4 unicast configuration. */
11627 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11628 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11629 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11630 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11631 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11632 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
11633 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11634 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11635 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11636 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11637 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11638 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11639 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11640 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11641 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11642 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11643 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11644 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11645 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11646 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11647 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11648 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11649 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11650 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11651 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11652 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11653 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11654 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11655 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11656 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11657 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11658 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11659 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11660 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11661 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11662 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11663 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11664 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11665 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11666 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11667 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11668 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11669 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11671 /* IPv4 multicast configuration. */
11672 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11673 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11674 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11675 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11676 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11677 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
11678 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11679 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11680 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11681 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11682 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11683 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11684 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11685 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11686 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11687 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11688 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11689 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11690 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11691 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11692 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11693 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11694 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11695 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11696 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11697 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11698 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11699 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11700 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11701 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11702 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11703 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11704 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11705 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11706 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11707 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11708 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11709 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11710 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11711 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11712 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11713 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11714 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11715 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11717 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11718 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11719 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11720 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11721 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11722 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11723 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11724 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11725 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11726 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11727 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11728 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11729 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11730 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11731 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11732 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11733 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11734 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11735 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11736 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11737 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11738 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11739 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11740 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11741 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11742 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11743 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11744 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11745 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11746 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11747 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11748 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11749 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11750 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11751 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11752 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11753 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11754 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11755 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11756 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11757 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11758 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11759 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11760 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11761 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11762 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11763 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11764 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11765 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11766 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11767 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11768 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11769 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11770 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11771 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11772 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11773 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11774 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11775 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11776 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11777 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11778 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11779 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11780 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11781 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11782 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11783 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
11784 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11785 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11786 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11787 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11788 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11789 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
11791 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11792 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11793 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11794 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11795 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11796 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11797 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11798 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11799 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11800 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11801 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11802 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11803 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11804 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11805 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11806 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11807 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11808 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11809 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11810 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11811 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11812 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11813 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11814 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11815 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11816 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11817 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11818 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11819 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11820 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11821 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11822 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11823 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11824 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11825 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11826 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11827 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11828 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11829 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11830 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11831 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11832 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11833 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11834 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11835 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11836 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11837 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11838 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11839 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11840 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11841 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11842 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11843 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11844 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11845 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11846 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11847 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11848 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11849 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11850 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11851 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11852 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11853 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11854 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11855 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11856 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11857 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
11858 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11859 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11860 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11861 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11862 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11863 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
11865 /* BGP dampening clear commands */
11866 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11867 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11868 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11869 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11871 /* prefix count */
11872 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11873 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11874 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
11875 #ifdef HAVE_IPV6
11876 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11878 /* New config IPv6 BGP commands. */
11879 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11880 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
11881 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
11882 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11883 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
11884 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
11886 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11887 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11888 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11889 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11891 /* Old config IPv6 BGP commands. */
11892 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11893 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11895 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11896 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11897 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11898 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11900 install_element (VIEW_NODE, &show_bgp_cmd);
11901 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11902 install_element (VIEW_NODE, &show_bgp_route_cmd);
11903 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11904 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11905 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11906 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11907 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11908 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11909 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11910 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11911 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11912 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11913 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11914 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11915 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11916 install_element (VIEW_NODE, &show_bgp_community_cmd);
11917 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11918 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11919 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11920 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11921 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11922 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11923 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11924 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11925 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11926 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11927 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11928 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11929 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11930 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11931 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11932 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11933 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11934 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11935 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11936 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11937 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11938 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11939 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11940 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11941 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11942 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11943 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11944 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11945 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
11946 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11947 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11948 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11949 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
11950 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11951 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11952 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
11953 install_element (VIEW_NODE, &show_bgp_view_cmd);
11954 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11955 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11956 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11957 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11958 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11959 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11960 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11961 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11962 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11963 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11964 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11965 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11966 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11967 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11968 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11969 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11970 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
11971 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11972 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11973 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
11975 install_element (ENABLE_NODE, &show_bgp_cmd);
11976 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
11977 install_element (ENABLE_NODE, &show_bgp_route_cmd);
11978 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
11979 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
11980 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
11981 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
11982 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
11983 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
11984 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
11985 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
11986 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
11987 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
11988 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
11989 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
11990 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11991 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11992 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11993 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
11994 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
11995 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
11996 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
11997 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
11998 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
11999 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12000 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12001 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12002 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12003 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12004 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12005 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12006 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12007 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12008 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12009 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12010 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12011 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12012 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12013 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12014 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12015 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12016 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12017 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12018 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12019 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12020 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
12021 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12022 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12023 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12024 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
12025 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12026 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12027 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
12028 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12029 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12030 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12031 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12032 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12033 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12034 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12035 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12036 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12037 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12038 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12039 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12040 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12041 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12042 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12043 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12044 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12045 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
12046 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12047 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12048 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
12050 /* Statistics */
12051 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12052 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12053 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12054 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12056 /* old command */
12057 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12058 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12059 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12060 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12061 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12062 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12063 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12064 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12065 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12066 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12067 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12068 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12069 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12070 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12071 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12072 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12073 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12074 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12075 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12076 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12077 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12078 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12079 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12080 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12081 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12082 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12083 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12084 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12085 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12086 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12087 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12088 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12089 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12090 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12091 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12092 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12094 /* old command */
12095 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12096 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12097 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12098 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12099 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12100 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12101 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12102 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12103 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12104 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12105 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12106 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12107 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12108 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12109 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12110 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12111 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12112 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12113 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12114 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12115 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12116 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12117 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12118 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12119 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12120 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12121 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12122 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12123 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12124 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12125 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12126 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12127 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12128 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12129 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12130 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12132 /* old command */
12133 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12134 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12135 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12136 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12138 /* old command */
12139 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12140 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12141 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12142 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12144 /* old command */
12145 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12146 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12147 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12148 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12149 #endif /* HAVE_IPV6 */
12151 install_element (BGP_NODE, &bgp_distance_cmd);
12152 install_element (BGP_NODE, &no_bgp_distance_cmd);
12153 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12154 install_element (BGP_NODE, &bgp_distance_source_cmd);
12155 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12156 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12157 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12159 install_element (BGP_NODE, &bgp_damp_set_cmd);
12160 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12161 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12162 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12163 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12164 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12165 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12166 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12167 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12168 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);