[lib] Put symbolic backtrace on system log
[jleu-quagga.git] / bgpd / bgp_route.c
blob65f54e770926e00510aebab29ea5619eaf2328d1
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 (void)
132 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
135 /* Free bgp route information. */
136 static void
137 bgp_info_free (struct bgp_info *binfo)
139 if (binfo->attr)
140 bgp_attr_unintern (binfo->attr);
142 bgp_info_extra_free (&binfo->extra);
144 peer_unlock (binfo->peer); /* bgp_info peer reference */
146 XFREE (MTYPE_BGP_ROUTE, binfo);
149 struct bgp_info *
150 bgp_info_lock (struct bgp_info *binfo)
152 binfo->lock++;
153 return binfo;
156 struct bgp_info *
157 bgp_info_unlock (struct bgp_info *binfo)
159 assert (binfo && binfo->lock > 0);
160 binfo->lock--;
162 if (binfo->lock == 0)
164 #if 0
165 zlog_debug ("%s: unlocked and freeing", __func__);
166 zlog_backtrace (LOG_DEBUG);
167 #endif
168 bgp_info_free (binfo);
169 return NULL;
172 #if 0
173 if (binfo->lock == 1)
175 zlog_debug ("%s: unlocked to 1", __func__);
176 zlog_backtrace (LOG_DEBUG);
178 #endif
180 return binfo;
183 void
184 bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
186 struct bgp_info *top;
188 top = rn->info;
190 ri->next = rn->info;
191 ri->prev = NULL;
192 if (top)
193 top->prev = ri;
194 rn->info = ri;
196 bgp_info_lock (ri);
197 bgp_lock_node (rn);
198 peer_lock (ri->peer); /* bgp_info peer reference */
201 /* Do the actual removal of info from RIB, for use by bgp_process
202 completion callback *only* */
203 static void
204 bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
206 if (ri->next)
207 ri->next->prev = ri->prev;
208 if (ri->prev)
209 ri->prev->next = ri->next;
210 else
211 rn->info = ri->next;
213 bgp_info_unlock (ri);
214 bgp_unlock_node (rn);
217 void
218 bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
220 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
221 /* set of previous already took care of pcount */
222 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
225 /* undo the effects of a previous call to bgp_info_delete; typically
226 called when a route is deleted and then quickly re-added before the
227 deletion has been processed */
228 static void
229 bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
231 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
232 /* unset of previous already took care of pcount */
233 SET_FLAG (ri->flags, BGP_INFO_VALID);
236 /* Adjust pcount as required */
237 static void
238 bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
240 assert (rn && rn->table);
241 assert (ri && ri->peer && ri->peer->bgp);
243 /* Ignore 'pcount' for RS-client tables */
244 if (rn->table->type != BGP_TABLE_MAIN
245 || ri->peer == ri->peer->bgp->peer_self)
246 return;
248 if (BGP_INFO_HOLDDOWN (ri)
249 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
252 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
254 /* slight hack, but more robust against errors. */
255 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
256 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
257 else
259 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
260 __func__, ri->peer->host);
261 zlog_backtrace (LOG_WARNING);
262 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
265 else if (!BGP_INFO_HOLDDOWN (ri)
266 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
268 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
269 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
274 /* Set/unset bgp_info flags, adjusting any other state as needed.
275 * This is here primarily to keep prefix-count in check.
277 void
278 bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
280 SET_FLAG (ri->flags, flag);
282 /* early bath if we know it's not a flag that changes useability state */
283 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
284 return;
286 bgp_pcount_adjust (rn, ri);
289 void
290 bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
292 UNSET_FLAG (ri->flags, flag);
294 /* early bath if we know it's not a flag that changes useability state */
295 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
296 return;
298 bgp_pcount_adjust (rn, ri);
301 /* Get MED value. If MED value is missing and "bgp bestpath
302 missing-as-worst" is specified, treat it as the worst value. */
303 static u_int32_t
304 bgp_med_value (struct attr *attr, struct bgp *bgp)
306 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
307 return attr->med;
308 else
310 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
311 return BGP_MED_MAX;
312 else
313 return 0;
317 /* Compare two bgp route entity. br is preferable then return 1. */
318 static int
319 bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
321 u_int32_t new_pref;
322 u_int32_t exist_pref;
323 u_int32_t new_med;
324 u_int32_t exist_med;
325 u_int32_t new_weight = 0;
326 u_int32_t exist_weight = 0;
327 struct in_addr new_id;
328 struct in_addr exist_id;
329 int new_cluster;
330 int exist_cluster;
331 int internal_as_route = 0;
332 int confed_as_route = 0;
333 int ret;
335 /* 0. Null check. */
336 if (new == NULL)
337 return 0;
338 if (exist == NULL)
339 return 1;
341 /* 1. Weight check. */
342 if (new->attr->extra)
343 new_weight = new->attr->extra->weight;
344 if (exist->attr->extra)
345 exist_weight = exist->attr->extra->weight;
346 if (new_weight > exist_weight)
347 return 1;
348 if (new_weight < exist_weight)
349 return 0;
351 /* 2. Local preference check. */
352 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
353 new_pref = new->attr->local_pref;
354 else
355 new_pref = bgp->default_local_pref;
357 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
358 exist_pref = exist->attr->local_pref;
359 else
360 exist_pref = bgp->default_local_pref;
362 if (new_pref > exist_pref)
363 return 1;
364 if (new_pref < exist_pref)
365 return 0;
367 /* 3. Local route check. */
368 if (new->sub_type == BGP_ROUTE_STATIC)
369 return 1;
370 if (exist->sub_type == BGP_ROUTE_STATIC)
371 return 0;
373 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
374 return 1;
375 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
376 return 0;
378 if (new->sub_type == BGP_ROUTE_AGGREGATE)
379 return 1;
380 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
381 return 0;
383 /* 4. AS path length check. */
384 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
386 int exist_hops = aspath_count_hops (exist->attr->aspath);
387 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
389 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
391 int aspath_hops;
393 aspath_hops = aspath_count_hops (new->attr->aspath);
394 aspath_hops += aspath_count_confeds (new->attr->aspath);
396 if ( aspath_hops < (exist_hops + exist_confeds))
397 return 1;
398 if ( aspath_hops > (exist_hops + exist_confeds))
399 return 0;
401 else
403 int newhops = aspath_count_hops (new->attr->aspath);
405 if (newhops < exist_hops)
406 return 1;
407 if (newhops > exist_hops)
408 return 0;
412 /* 5. Origin check. */
413 if (new->attr->origin < exist->attr->origin)
414 return 1;
415 if (new->attr->origin > exist->attr->origin)
416 return 0;
418 /* 6. MED check. */
419 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
420 && aspath_count_hops (exist->attr->aspath) == 0);
421 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
422 && aspath_count_confeds (exist->attr->aspath) > 0
423 && aspath_count_hops (new->attr->aspath) == 0
424 && aspath_count_hops (exist->attr->aspath) == 0);
426 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
427 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
428 && confed_as_route)
429 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
430 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
431 || internal_as_route)
433 new_med = bgp_med_value (new->attr, bgp);
434 exist_med = bgp_med_value (exist->attr, bgp);
436 if (new_med < exist_med)
437 return 1;
438 if (new_med > exist_med)
439 return 0;
442 /* 7. Peer type check. */
443 if (peer_sort (new->peer) == BGP_PEER_EBGP
444 && peer_sort (exist->peer) == BGP_PEER_IBGP)
445 return 1;
446 if (peer_sort (new->peer) == BGP_PEER_EBGP
447 && peer_sort (exist->peer) == BGP_PEER_CONFED)
448 return 1;
449 if (peer_sort (new->peer) == BGP_PEER_IBGP
450 && peer_sort (exist->peer) == BGP_PEER_EBGP)
451 return 0;
452 if (peer_sort (new->peer) == BGP_PEER_CONFED
453 && peer_sort (exist->peer) == BGP_PEER_EBGP)
454 return 0;
456 /* 8. IGP metric check. */
457 if (new->extra || exist->extra)
459 uint32_t newm = (new->extra ? new->extra->igpmetric : 0);
460 uint32_t existm = (exist->extra ? exist->extra->igpmetric : 0);
462 if (newm < existm)
463 return 1;
464 if (newm > existm)
465 return 0;
468 /* 9. Maximum path check. */
470 /* 10. If both paths are external, prefer the path that was received
471 first (the oldest one). This step minimizes route-flap, since a
472 newer path won't displace an older one, even if it was the
473 preferred route based on the additional decision criteria below. */
474 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
475 && peer_sort (new->peer) == BGP_PEER_EBGP
476 && peer_sort (exist->peer) == BGP_PEER_EBGP)
478 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
479 return 1;
480 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
481 return 0;
484 /* 11. Rourter-ID comparision. */
485 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
486 new_id.s_addr = new->attr->extra->originator_id.s_addr;
487 else
488 new_id.s_addr = new->peer->remote_id.s_addr;
489 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
490 exist_id.s_addr = exist->attr->extra->originator_id.s_addr;
491 else
492 exist_id.s_addr = exist->peer->remote_id.s_addr;
494 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
495 return 1;
496 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
497 return 0;
499 /* 12. Cluster length comparision. */
500 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
501 new_cluster = new->attr->extra->cluster->length;
502 else
503 new_cluster = 0;
504 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
505 exist_cluster = exist->attr->extra->cluster->length;
506 else
507 exist_cluster = 0;
509 if (new_cluster < exist_cluster)
510 return 1;
511 if (new_cluster > exist_cluster)
512 return 0;
514 /* 13. Neighbor address comparision. */
515 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
517 if (ret == 1)
518 return 0;
519 if (ret == -1)
520 return 1;
522 return 1;
525 static enum filter_type
526 bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
527 afi_t afi, safi_t safi)
529 struct bgp_filter *filter;
531 filter = &peer->filter[afi][safi];
533 if (DISTRIBUTE_IN_NAME (filter))
534 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
535 return FILTER_DENY;
537 if (PREFIX_LIST_IN_NAME (filter))
538 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
539 return FILTER_DENY;
541 if (FILTER_LIST_IN_NAME (filter))
542 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
543 return FILTER_DENY;
545 return FILTER_PERMIT;
548 static enum filter_type
549 bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
550 afi_t afi, safi_t safi)
552 struct bgp_filter *filter;
554 filter = &peer->filter[afi][safi];
556 if (DISTRIBUTE_OUT_NAME (filter))
557 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
558 return FILTER_DENY;
560 if (PREFIX_LIST_OUT_NAME (filter))
561 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
562 return FILTER_DENY;
564 if (FILTER_LIST_OUT_NAME (filter))
565 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
566 return FILTER_DENY;
568 return FILTER_PERMIT;
571 /* If community attribute includes no_export then return 1. */
572 static int
573 bgp_community_filter (struct peer *peer, struct attr *attr)
575 if (attr->community)
577 /* NO_ADVERTISE check. */
578 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
579 return 1;
581 /* NO_EXPORT check. */
582 if (peer_sort (peer) == BGP_PEER_EBGP &&
583 community_include (attr->community, COMMUNITY_NO_EXPORT))
584 return 1;
586 /* NO_EXPORT_SUBCONFED check. */
587 if (peer_sort (peer) == BGP_PEER_EBGP
588 || peer_sort (peer) == BGP_PEER_CONFED)
589 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
590 return 1;
592 return 0;
595 /* Route reflection loop check. */
596 static int
597 bgp_cluster_filter (struct peer *peer, struct attr *attr)
599 struct in_addr cluster_id;
601 if (attr->extra && attr->extra->cluster)
603 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
604 cluster_id = peer->bgp->cluster_id;
605 else
606 cluster_id = peer->bgp->router_id;
608 if (cluster_loop_check (attr->extra->cluster, cluster_id))
609 return 1;
611 return 0;
614 static int
615 bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
616 afi_t afi, safi_t safi)
618 struct bgp_filter *filter;
619 struct bgp_info info;
620 route_map_result_t ret;
622 filter = &peer->filter[afi][safi];
624 /* Apply default weight value. */
625 if (peer->weight)
626 (bgp_attr_extra_get (attr))->weight = peer->weight;
628 /* Route map apply. */
629 if (ROUTE_MAP_IN_NAME (filter))
631 /* Duplicate current value to new strucutre for modification. */
632 info.peer = peer;
633 info.attr = attr;
635 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
637 /* Apply BGP route map to the attribute. */
638 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
640 peer->rmap_type = 0;
642 if (ret == RMAP_DENYMATCH)
644 /* Free newly generated AS path and community by route-map. */
645 bgp_attr_flush (attr);
646 return RMAP_DENY;
649 return RMAP_PERMIT;
652 static int
653 bgp_export_modifier (struct peer *rsclient, struct peer *peer,
654 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
656 struct bgp_filter *filter;
657 struct bgp_info info;
658 route_map_result_t ret;
660 filter = &peer->filter[afi][safi];
662 /* Route map apply. */
663 if (ROUTE_MAP_EXPORT_NAME (filter))
665 /* Duplicate current value to new strucutre for modification. */
666 info.peer = rsclient;
667 info.attr = attr;
669 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
671 /* Apply BGP route map to the attribute. */
672 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
674 rsclient->rmap_type = 0;
676 if (ret == RMAP_DENYMATCH)
678 /* Free newly generated AS path and community by route-map. */
679 bgp_attr_flush (attr);
680 return RMAP_DENY;
683 return RMAP_PERMIT;
686 static int
687 bgp_import_modifier (struct peer *rsclient, struct peer *peer,
688 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
690 struct bgp_filter *filter;
691 struct bgp_info info;
692 route_map_result_t ret;
694 filter = &rsclient->filter[afi][safi];
696 /* Apply default weight value. */
697 if (peer->weight)
698 (bgp_attr_extra_get (attr))->weight = peer->weight;
700 /* Route map apply. */
701 if (ROUTE_MAP_IMPORT_NAME (filter))
703 /* Duplicate current value to new strucutre for modification. */
704 info.peer = peer;
705 info.attr = attr;
707 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
709 /* Apply BGP route map to the attribute. */
710 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
712 peer->rmap_type = 0;
714 if (ret == RMAP_DENYMATCH)
716 /* Free newly generated AS path and community by route-map. */
717 bgp_attr_flush (attr);
718 return RMAP_DENY;
721 return RMAP_PERMIT;
724 static int
725 bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
726 struct attr *attr, afi_t afi, safi_t safi)
728 int ret;
729 char buf[SU_ADDRSTRLEN];
730 struct bgp_filter *filter;
731 struct peer *from;
732 struct bgp *bgp;
733 int transparent;
734 int reflect;
736 from = ri->peer;
737 filter = &peer->filter[afi][safi];
738 bgp = peer->bgp;
740 if (DISABLE_BGP_ANNOUNCE)
741 return 0;
743 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
744 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
745 return 0;
747 /* Do not send back route to sender. */
748 if (from == peer)
749 return 0;
751 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
752 if (p->family == AF_INET
753 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
754 return 0;
755 #ifdef HAVE_IPV6
756 if (p->family == AF_INET6
757 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
758 return 0;
759 #endif
761 /* Aggregate-address suppress check. */
762 if (ri->extra && ri->extra->suppress)
763 if (! UNSUPPRESS_MAP_NAME (filter))
764 return 0;
766 /* Default route check. */
767 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
769 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
770 return 0;
771 #ifdef HAVE_IPV6
772 else if (p->family == AF_INET6 && p->prefixlen == 0)
773 return 0;
774 #endif /* HAVE_IPV6 */
777 /* Transparency check. */
778 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
779 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
780 transparent = 1;
781 else
782 transparent = 0;
784 /* If community is not disabled check the no-export and local. */
785 if (! transparent && bgp_community_filter (peer, ri->attr))
786 return 0;
788 /* If the attribute has originator-id and it is same as remote
789 peer's id. */
790 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
792 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->extra->originator_id))
794 if (BGP_DEBUG (filter, FILTER))
795 zlog (peer->log, LOG_DEBUG,
796 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
797 peer->host,
798 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
799 p->prefixlen);
800 return 0;
804 /* ORF prefix-list filter check */
805 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
806 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
807 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
808 if (peer->orf_plist[afi][safi])
810 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
811 return 0;
814 /* Output filter check. */
815 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
817 if (BGP_DEBUG (filter, FILTER))
818 zlog (peer->log, LOG_DEBUG,
819 "%s [Update:SEND] %s/%d is filtered",
820 peer->host,
821 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
822 p->prefixlen);
823 return 0;
826 #ifdef BGP_SEND_ASPATH_CHECK
827 /* AS path loop check. */
828 if (aspath_loop_check (ri->attr->aspath, peer->as))
830 if (BGP_DEBUG (filter, FILTER))
831 zlog (peer->log, LOG_DEBUG,
832 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
833 peer->host, peer->as);
834 return 0;
836 #endif /* BGP_SEND_ASPATH_CHECK */
838 /* If we're a CONFED we need to loop check the CONFED ID too */
839 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
841 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
843 if (BGP_DEBUG (filter, FILTER))
844 zlog (peer->log, LOG_DEBUG,
845 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
846 peer->host,
847 bgp->confed_id);
848 return 0;
852 /* Route-Reflect check. */
853 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
854 reflect = 1;
855 else
856 reflect = 0;
858 /* IBGP reflection check. */
859 if (reflect)
861 /* A route from a Client peer. */
862 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
864 /* Reflect to all the Non-Client peers and also to the
865 Client peers other than the originator. Originator check
866 is already done. So there is noting to do. */
867 /* no bgp client-to-client reflection check. */
868 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
869 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
870 return 0;
872 else
874 /* A route from a Non-client peer. Reflect to all other
875 clients. */
876 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
877 return 0;
881 /* AS-Pathlimit check */
882 if (ri->attr->pathlimit.ttl && peer_sort (peer) == BGP_PEER_EBGP)
883 /* Our ASN has not yet been pre-pended, that's done in packet_attribute
884 * on output. Hence the test here is for >=.
886 if (aspath_count_hops (ri->attr->aspath) >= ri->attr->pathlimit.ttl)
888 if (BGP_DEBUG (filter, FILTER))
889 zlog_info ("%s [Update:SEND] suppressed, AS-Pathlimit TTL %u exceeded",
890 peer->host, ri->attr->pathlimit.ttl);
891 return 0;
894 /* For modify attribute, copy it to temporary structure. */
895 bgp_attr_dup (attr, ri->attr);
897 /* If local-preference is not set. */
898 if ((peer_sort (peer) == BGP_PEER_IBGP
899 || peer_sort (peer) == BGP_PEER_CONFED)
900 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
902 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
903 attr->local_pref = bgp->default_local_pref;
906 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
907 if (peer_sort (peer) == BGP_PEER_EBGP
908 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
910 if (ri->peer != bgp->peer_self && ! transparent
911 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
912 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
915 /* next-hop-set */
916 if (transparent || reflect
917 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
918 && ((p->family == AF_INET && attr->nexthop.s_addr)
919 #ifdef HAVE_IPV6
920 || (p->family == AF_INET6 &&
921 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
922 #endif /* HAVE_IPV6 */
925 /* NEXT-HOP Unchanged. */
927 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
928 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
929 #ifdef HAVE_IPV6
930 || (p->family == AF_INET6 &&
931 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
932 #endif /* HAVE_IPV6 */
933 || (peer_sort (peer) == BGP_PEER_EBGP
934 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
936 /* Set IPv4 nexthop. */
937 if (p->family == AF_INET)
939 if (safi == SAFI_MPLS_VPN)
940 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
941 IPV4_MAX_BYTELEN);
942 else
943 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
945 #ifdef HAVE_IPV6
946 /* Set IPv6 nexthop. */
947 if (p->family == AF_INET6)
949 /* IPv6 global nexthop must be included. */
950 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
951 IPV6_MAX_BYTELEN);
952 attr->extra->mp_nexthop_len = 16;
954 #endif /* HAVE_IPV6 */
957 #ifdef HAVE_IPV6
958 if (p->family == AF_INET6)
960 /* Left nexthop_local unchanged if so configured. */
961 if ( CHECK_FLAG (peer->af_flags[afi][safi],
962 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
964 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
965 attr->extra->mp_nexthop_len=32;
966 else
967 attr->extra->mp_nexthop_len=16;
970 /* Default nexthop_local treatment for non-RS-Clients */
971 else
973 /* Link-local address should not be transit to different peer. */
974 attr->extra->mp_nexthop_len = 16;
976 /* Set link-local address for shared network peer. */
977 if (peer->shared_network
978 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
980 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
981 IPV6_MAX_BYTELEN);
982 attr->extra->mp_nexthop_len = 32;
985 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
986 address.*/
987 if (reflect)
988 attr->extra->mp_nexthop_len = 16;
990 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
991 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
992 attr->extra->mp_nexthop_len = 16;
996 #endif /* HAVE_IPV6 */
998 /* AS-Pathlimit: Check ASN for private/confed */
999 if (attr->pathlimit.ttl)
1001 /* locally originated update */
1002 if (!attr->pathlimit.as)
1003 attr->pathlimit.as = peer->local_as;
1005 /* if the AS_PATHLIMIT attribute is attached to a prefix by a
1006 member of a confederation, then when the prefix is advertised outside
1007 of the confederation boundary, then the AS number of the
1008 confederation member inside of the AS_PATHLIMIT attribute should be
1009 replaced by the confederation's AS number. */
1010 if (peer_sort (from) == BGP_PEER_CONFED
1011 && peer_sort (peer) != BGP_PEER_CONFED)
1012 attr->pathlimit.as = peer->local_as;
1014 /* Private ASN should be updated whenever announcement leaves
1015 * private space. This is deliberately done after simple confed
1016 * based update..
1018 if (attr->pathlimit.as >= BGP_PRIVATE_AS_MIN
1019 && attr->pathlimit.as <= BGP_PRIVATE_AS_MAX)
1021 if (peer->local_as < BGP_PRIVATE_AS_MIN
1022 || peer->local_as > BGP_PRIVATE_AS_MAX)
1023 attr->pathlimit.as = peer->local_as;
1024 /* Ours is private, try using theirs.. */
1025 else if (peer->as < BGP_PRIVATE_AS_MIN
1026 || peer->local_as > BGP_PRIVATE_AS_MAX)
1027 attr->pathlimit.as = peer->as;
1031 /* If this is EBGP peer and remove-private-AS is set. */
1032 if (peer_sort (peer) == BGP_PEER_EBGP
1033 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1034 && aspath_private_as_check (attr->aspath))
1035 attr->aspath = aspath_empty_get ();
1037 /* Route map & unsuppress-map apply. */
1038 if (ROUTE_MAP_OUT_NAME (filter)
1039 || (ri->extra && ri->extra->suppress) )
1041 struct bgp_info info;
1042 struct attr dummy_attr = { 0 };
1044 info.peer = peer;
1045 info.attr = attr;
1047 /* The route reflector is not allowed to modify the attributes
1048 of the reflected IBGP routes. */
1049 if (peer_sort (from) == BGP_PEER_IBGP
1050 && peer_sort (peer) == BGP_PEER_IBGP)
1052 bgp_attr_dup (&dummy_attr, attr);
1053 info.attr = &dummy_attr;
1056 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1058 if (ri->extra && ri->extra->suppress)
1059 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1060 else
1061 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1063 peer->rmap_type = 0;
1065 if (dummy_attr.extra)
1066 bgp_attr_extra_free (&dummy_attr);
1068 if (ret == RMAP_DENYMATCH)
1070 bgp_attr_flush (attr);
1071 return 0;
1074 return 1;
1077 static int
1078 bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1079 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
1081 int ret;
1082 char buf[SU_ADDRSTRLEN];
1083 struct bgp_filter *filter;
1084 struct bgp_info info;
1085 struct peer *from;
1086 struct bgp *bgp;
1088 from = ri->peer;
1089 filter = &rsclient->filter[afi][safi];
1090 bgp = rsclient->bgp;
1092 if (DISABLE_BGP_ANNOUNCE)
1093 return 0;
1095 /* Do not send back route to sender. */
1096 if (from == rsclient)
1097 return 0;
1099 /* Aggregate-address suppress check. */
1100 if (ri->extra && ri->extra->suppress)
1101 if (! UNSUPPRESS_MAP_NAME (filter))
1102 return 0;
1104 /* Default route check. */
1105 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1106 PEER_STATUS_DEFAULT_ORIGINATE))
1108 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1109 return 0;
1110 #ifdef HAVE_IPV6
1111 else if (p->family == AF_INET6 && p->prefixlen == 0)
1112 return 0;
1113 #endif /* HAVE_IPV6 */
1116 /* If the attribute has originator-id and it is same as remote
1117 peer's id. */
1118 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1120 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1121 &ri->attr->extra->originator_id))
1123 if (BGP_DEBUG (filter, FILTER))
1124 zlog (rsclient->log, LOG_DEBUG,
1125 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1126 rsclient->host,
1127 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1128 p->prefixlen);
1129 return 0;
1133 /* ORF prefix-list filter check */
1134 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1135 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1136 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1137 if (rsclient->orf_plist[afi][safi])
1139 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1140 return 0;
1143 /* Output filter check. */
1144 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1146 if (BGP_DEBUG (filter, FILTER))
1147 zlog (rsclient->log, LOG_DEBUG,
1148 "%s [Update:SEND] %s/%d is filtered",
1149 rsclient->host,
1150 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1151 p->prefixlen);
1152 return 0;
1155 #ifdef BGP_SEND_ASPATH_CHECK
1156 /* AS path loop check. */
1157 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1159 if (BGP_DEBUG (filter, FILTER))
1160 zlog (rsclient->log, LOG_DEBUG,
1161 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
1162 rsclient->host, rsclient->as);
1163 return 0;
1165 #endif /* BGP_SEND_ASPATH_CHECK */
1167 /* For modify attribute, copy it to temporary structure. */
1168 bgp_attr_dup (attr, ri->attr);
1170 /* next-hop-set */
1171 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1172 #ifdef HAVE_IPV6
1173 || (p->family == AF_INET6 &&
1174 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
1175 #endif /* HAVE_IPV6 */
1178 /* Set IPv4 nexthop. */
1179 if (p->family == AF_INET)
1181 if (safi == SAFI_MPLS_VPN)
1182 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
1183 IPV4_MAX_BYTELEN);
1184 else
1185 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1187 #ifdef HAVE_IPV6
1188 /* Set IPv6 nexthop. */
1189 if (p->family == AF_INET6)
1191 /* IPv6 global nexthop must be included. */
1192 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
1193 IPV6_MAX_BYTELEN);
1194 attr->extra->mp_nexthop_len = 16;
1196 #endif /* HAVE_IPV6 */
1199 #ifdef HAVE_IPV6
1200 if (p->family == AF_INET6)
1202 struct attr_extra *attre = attr->extra;
1204 assert (attr->extra);
1206 /* Left nexthop_local unchanged if so configured. */
1207 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1208 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1210 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1211 attre->mp_nexthop_len=32;
1212 else
1213 attre->mp_nexthop_len=16;
1216 /* Default nexthop_local treatment for RS-Clients */
1217 else
1219 /* Announcer and RS-Client are both in the same network */
1220 if (rsclient->shared_network && from->shared_network &&
1221 (rsclient->ifindex == from->ifindex))
1223 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1224 attre->mp_nexthop_len=32;
1225 else
1226 attre->mp_nexthop_len=16;
1229 /* Set link-local address for shared network peer. */
1230 else if (rsclient->shared_network
1231 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1233 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
1234 IPV6_MAX_BYTELEN);
1235 attre->mp_nexthop_len = 32;
1238 else
1239 attre->mp_nexthop_len = 16;
1243 #endif /* HAVE_IPV6 */
1246 /* If this is EBGP peer and remove-private-AS is set. */
1247 if (peer_sort (rsclient) == BGP_PEER_EBGP
1248 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1249 && aspath_private_as_check (attr->aspath))
1250 attr->aspath = aspath_empty_get ();
1252 /* Route map & unsuppress-map apply. */
1253 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
1255 info.peer = rsclient;
1256 info.attr = attr;
1258 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1260 if (ri->extra && ri->extra->suppress)
1261 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1262 else
1263 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1265 rsclient->rmap_type = 0;
1267 if (ret == RMAP_DENYMATCH)
1269 bgp_attr_flush (attr);
1270 return 0;
1274 return 1;
1277 struct bgp_info_pair
1279 struct bgp_info *old;
1280 struct bgp_info *new;
1283 static void
1284 bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1286 struct bgp_info *new_select;
1287 struct bgp_info *old_select;
1288 struct bgp_info *ri;
1289 struct bgp_info *ri1;
1290 struct bgp_info *ri2;
1291 struct bgp_info *nextri = NULL;
1293 /* bgp deterministic-med */
1294 new_select = NULL;
1295 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1296 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1298 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1299 continue;
1300 if (BGP_INFO_HOLDDOWN (ri1))
1301 continue;
1303 new_select = ri1;
1304 if (ri1->next)
1305 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1307 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1308 continue;
1309 if (BGP_INFO_HOLDDOWN (ri2))
1310 continue;
1312 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1313 || aspath_cmp_left_confed (ri1->attr->aspath,
1314 ri2->attr->aspath))
1316 if (bgp_info_cmp (bgp, ri2, new_select))
1318 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1319 new_select = ri2;
1322 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
1325 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1326 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1329 /* Check old selected route and new selected route. */
1330 old_select = NULL;
1331 new_select = NULL;
1332 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
1334 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1335 old_select = ri;
1337 if (BGP_INFO_HOLDDOWN (ri))
1339 /* reap REMOVED routes, if needs be
1340 * selected route must stay for a while longer though
1342 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1343 && (ri != old_select))
1344 bgp_info_reap (rn, ri);
1346 continue;
1349 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1350 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1352 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1353 continue;
1355 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1356 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
1358 if (bgp_info_cmp (bgp, ri, new_select))
1359 new_select = ri;
1362 result->old = old_select;
1363 result->new = new_select;
1365 return;
1368 static int
1369 bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1370 struct bgp_node *rn, afi_t afi, safi_t safi)
1372 struct prefix *p;
1373 struct attr attr = { 0 };
1375 p = &rn->p;
1377 /* Announce route to Established peer. */
1378 if (peer->status != Established)
1379 return 0;
1381 /* Address family configuration check. */
1382 if (! peer->afc_nego[afi][safi])
1383 return 0;
1385 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1386 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1387 PEER_STATUS_ORF_WAIT_REFRESH))
1388 return 0;
1390 switch (rn->table->type)
1392 case BGP_TABLE_MAIN:
1393 /* Announcement to peer->conf. If the route is filtered,
1394 withdraw it. */
1395 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1396 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1397 else
1398 bgp_adj_out_unset (rn, peer, p, afi, safi);
1399 break;
1400 case BGP_TABLE_RSCLIENT:
1401 /* Announcement to peer->conf. If the route is filtered,
1402 withdraw it. */
1403 if (selected &&
1404 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1405 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1406 else
1407 bgp_adj_out_unset (rn, peer, p, afi, safi);
1408 break;
1411 bgp_attr_extra_free (&attr);
1413 return 0;
1416 struct bgp_process_queue
1418 struct bgp *bgp;
1419 struct bgp_node *rn;
1420 afi_t afi;
1421 safi_t safi;
1424 static wq_item_status
1425 bgp_process_rsclient (struct work_queue *wq, void *data)
1427 struct bgp_process_queue *pq = data;
1428 struct bgp *bgp = pq->bgp;
1429 struct bgp_node *rn = pq->rn;
1430 afi_t afi = pq->afi;
1431 safi_t safi = pq->safi;
1432 struct bgp_info *new_select;
1433 struct bgp_info *old_select;
1434 struct bgp_info_pair old_and_new;
1435 struct attr attr;
1436 struct listnode *node, *nnode;
1437 struct peer *rsclient = rn->table->owner;
1439 memset (&attr, 0, sizeof (struct attr));
1440 /* Best path selection. */
1441 bgp_best_selection (bgp, rn, &old_and_new);
1442 new_select = old_and_new.new;
1443 old_select = old_and_new.old;
1445 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1447 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1449 /* Nothing to do. */
1450 if (old_select && old_select == new_select)
1451 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1452 continue;
1454 if (old_select)
1455 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1456 if (new_select)
1458 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1459 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1462 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
1465 else
1467 if (old_select)
1468 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1469 if (new_select)
1471 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1472 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1474 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
1477 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1478 bgp_info_reap (rn, old_select);
1480 bgp_attr_extra_free (&attr);
1482 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1483 return WQ_SUCCESS;
1486 static wq_item_status
1487 bgp_process_main (struct work_queue *wq, void *data)
1489 struct bgp_process_queue *pq = data;
1490 struct bgp *bgp = pq->bgp;
1491 struct bgp_node *rn = pq->rn;
1492 afi_t afi = pq->afi;
1493 safi_t safi = pq->safi;
1494 struct prefix *p = &rn->p;
1495 struct bgp_info *new_select;
1496 struct bgp_info *old_select;
1497 struct bgp_info_pair old_and_new;
1498 struct listnode *node, *nnode;
1499 struct peer *peer;
1501 /* Best path selection. */
1502 bgp_best_selection (bgp, rn, &old_and_new);
1503 old_select = old_and_new.old;
1504 new_select = old_and_new.new;
1506 /* Nothing to do. */
1507 if (old_select && old_select == new_select)
1509 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1511 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1512 bgp_zebra_announce (p, old_select, bgp);
1514 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1515 return WQ_SUCCESS;
1519 if (old_select)
1520 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1521 if (new_select)
1523 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1524 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1528 /* Check each BGP peer. */
1529 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
1531 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
1534 /* FIB update. */
1535 if (safi == SAFI_UNICAST && ! bgp->name &&
1536 ! bgp_option_check (BGP_OPT_NO_FIB))
1538 if (new_select
1539 && new_select->type == ZEBRA_ROUTE_BGP
1540 && new_select->sub_type == BGP_ROUTE_NORMAL)
1541 bgp_zebra_announce (p, new_select, bgp);
1542 else
1544 /* Withdraw the route from the kernel. */
1545 if (old_select
1546 && old_select->type == ZEBRA_ROUTE_BGP
1547 && old_select->sub_type == BGP_ROUTE_NORMAL)
1548 bgp_zebra_withdraw (p, old_select);
1552 /* Reap old select bgp_info, it it has been removed */
1553 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1554 bgp_info_reap (rn, old_select);
1556 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1557 return WQ_SUCCESS;
1560 static void
1561 bgp_processq_del (struct work_queue *wq, void *data)
1563 struct bgp_process_queue *pq = data;
1565 bgp_unlock_node (pq->rn);
1566 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1569 static void
1570 bgp_process_queue_init (void)
1572 bm->process_main_queue
1573 = work_queue_new (bm->master, "process_main_queue");
1574 bm->process_rsclient_queue
1575 = work_queue_new (bm->master, "process_rsclient_queue");
1577 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1579 zlog_err ("%s: Failed to allocate work queue", __func__);
1580 exit (1);
1583 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1584 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1585 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1586 bm->process_rsclient_queue->spec.del_item_data
1587 = bm->process_main_queue->spec.del_item_data;
1588 bm->process_main_queue->spec.max_retries
1589 = bm->process_main_queue->spec.max_retries = 0;
1590 bm->process_rsclient_queue->spec.hold
1591 = bm->process_main_queue->spec.hold = 50;
1594 void
1595 bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1597 struct bgp_process_queue *pqnode;
1599 /* already scheduled for processing? */
1600 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1601 return;
1603 if ( (bm->process_main_queue == NULL) ||
1604 (bm->process_rsclient_queue == NULL) )
1605 bgp_process_queue_init ();
1607 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1608 sizeof (struct bgp_process_queue));
1609 if (!pqnode)
1610 return;
1612 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1613 pqnode->bgp = bgp;
1614 pqnode->afi = afi;
1615 pqnode->safi = safi;
1617 switch (rn->table->type)
1619 case BGP_TABLE_MAIN:
1620 work_queue_add (bm->process_main_queue, pqnode);
1621 break;
1622 case BGP_TABLE_RSCLIENT:
1623 work_queue_add (bm->process_rsclient_queue, pqnode);
1624 break;
1627 return;
1630 static int
1631 bgp_maximum_prefix_restart_timer (struct thread *thread)
1633 struct peer *peer;
1635 peer = THREAD_ARG (thread);
1636 peer->t_pmax_restart = NULL;
1638 if (BGP_DEBUG (events, EVENTS))
1639 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1640 peer->host);
1642 peer_clear (peer);
1644 return 0;
1648 bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1649 safi_t safi, int always)
1651 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1652 return 0;
1654 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
1656 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1657 && ! always)
1658 return 0;
1660 zlog (peer->log, LOG_INFO,
1661 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1662 "limit %ld", afi_safi_print (afi, safi), peer->host,
1663 peer->pcount[afi][safi], peer->pmax[afi][safi]);
1664 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1666 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1667 return 0;
1670 u_int8_t ndata[7];
1672 if (safi == SAFI_MPLS_VPN)
1673 safi = BGP_SAFI_VPNV4;
1675 ndata[0] = (afi >> 8);
1676 ndata[1] = afi;
1677 ndata[2] = safi;
1678 ndata[3] = (peer->pmax[afi][safi] >> 24);
1679 ndata[4] = (peer->pmax[afi][safi] >> 16);
1680 ndata[5] = (peer->pmax[afi][safi] >> 8);
1681 ndata[6] = (peer->pmax[afi][safi]);
1683 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1684 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1685 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1688 /* restart timer start */
1689 if (peer->pmax_restart[afi][safi])
1691 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1693 if (BGP_DEBUG (events, EVENTS))
1694 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1695 peer->host, peer->v_pmax_restart);
1697 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1698 peer->v_pmax_restart);
1701 return 1;
1703 else
1704 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1706 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1708 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1709 && ! always)
1710 return 0;
1712 zlog (peer->log, LOG_INFO,
1713 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1714 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1715 peer->pmax[afi][safi]);
1716 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1718 else
1719 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1720 return 0;
1723 /* Unconditionally remove the route from the RIB, without taking
1724 * damping into consideration (eg, because the session went down)
1726 static void
1727 bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1728 afi_t afi, safi_t safi)
1730 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1732 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1733 bgp_info_delete (rn, ri); /* keep historical info */
1735 bgp_process (peer->bgp, rn, afi, safi);
1738 static void
1739 bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1740 afi_t afi, safi_t safi)
1742 int status = BGP_DAMP_NONE;
1744 /* apply dampening, if result is suppressed, we'll be retaining
1745 * the bgp_info in the RIB for historical reference.
1747 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1748 && peer_sort (peer) == BGP_PEER_EBGP)
1749 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1750 == BGP_DAMP_SUPPRESSED)
1752 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1753 return;
1756 bgp_rib_remove (rn, ri, peer, afi, safi);
1759 static void
1760 bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1761 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1762 int sub_type, struct prefix_rd *prd, u_char *tag)
1764 struct bgp_node *rn;
1765 struct bgp *bgp;
1766 struct attr new_attr = { 0 };
1767 struct attr *attr_new;
1768 struct attr *attr_new2;
1769 struct bgp_info *ri;
1770 struct bgp_info *new;
1771 const char *reason;
1772 char buf[SU_ADDRSTRLEN];
1774 //memset (new_attr, 0, sizeof (struct attr));
1776 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1777 if (peer == rsclient)
1778 return;
1780 bgp = peer->bgp;
1781 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1783 /* Check previously received route. */
1784 for (ri = rn->info; ri; ri = ri->next)
1785 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1786 break;
1788 /* AS path loop check. */
1789 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1791 reason = "as-path contains our own AS;";
1792 goto filtered;
1795 /* Route reflector originator ID check. */
1796 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1797 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
1799 reason = "originator is us;";
1800 goto filtered;
1803 bgp_attr_dup (&new_attr, attr);
1805 /* Apply export policy. */
1806 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1807 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1809 reason = "export-policy;";
1810 goto filtered;
1813 attr_new2 = bgp_attr_intern (&new_attr);
1815 /* Apply import policy. */
1816 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1818 bgp_attr_unintern (attr_new2);
1820 reason = "import-policy;";
1821 goto filtered;
1824 attr_new = bgp_attr_intern (&new_attr);
1825 bgp_attr_unintern (attr_new2);
1827 /* IPv4 unicast next hop check. */
1828 if (afi == AFI_IP && safi == SAFI_UNICAST)
1830 /* Next hop must not be 0.0.0.0 nor Class E address. */
1831 if (new_attr.nexthop.s_addr == 0
1832 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1834 bgp_attr_unintern (attr_new);
1836 reason = "martian next-hop;";
1837 goto filtered;
1841 /* new_attr isn't passed to any functions after here */
1842 bgp_attr_extra_free (&new_attr);
1844 /* If the update is implicit withdraw. */
1845 if (ri)
1847 ri->uptime = time (NULL);
1849 /* Same attribute comes in. */
1850 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1851 && attrhash_cmp (ri->attr, attr_new))
1854 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
1856 if (BGP_DEBUG (update, UPDATE_IN))
1857 zlog (peer->log, LOG_DEBUG,
1858 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1859 peer->host,
1860 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1861 p->prefixlen, rsclient->host);
1863 bgp_unlock_node (rn);
1864 bgp_attr_unintern (attr_new);
1866 return;
1869 /* Withdraw/Announce before we fully processed the withdraw */
1870 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1871 bgp_info_restore (rn, ri);
1873 /* Received Logging. */
1874 if (BGP_DEBUG (update, UPDATE_IN))
1875 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
1876 peer->host,
1877 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1878 p->prefixlen, rsclient->host);
1880 /* The attribute is changed. */
1881 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
1883 /* Update to new attribute. */
1884 bgp_attr_unintern (ri->attr);
1885 ri->attr = attr_new;
1887 /* Update MPLS tag. */
1888 if (safi == SAFI_MPLS_VPN)
1889 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
1891 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
1893 /* Process change. */
1894 bgp_process (bgp, rn, afi, safi);
1895 bgp_unlock_node (rn);
1897 return;
1900 /* Received Logging. */
1901 if (BGP_DEBUG (update, UPDATE_IN))
1903 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
1904 peer->host,
1905 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1906 p->prefixlen, rsclient->host);
1909 /* Make new BGP info. */
1910 new = bgp_info_new ();
1911 new->type = type;
1912 new->sub_type = sub_type;
1913 new->peer = peer;
1914 new->attr = attr_new;
1915 new->uptime = time (NULL);
1917 /* Update MPLS tag. */
1918 if (safi == SAFI_MPLS_VPN)
1919 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
1921 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
1923 /* Register new BGP information. */
1924 bgp_info_add (rn, new);
1926 /* route_node_get lock */
1927 bgp_unlock_node (rn);
1929 /* Process change. */
1930 bgp_process (bgp, rn, afi, safi);
1932 bgp_attr_extra_free (&new_attr);
1934 return;
1936 filtered:
1938 /* This BGP update is filtered. Log the reason then update BGP entry. */
1939 if (BGP_DEBUG (update, UPDATE_IN))
1940 zlog (peer->log, LOG_DEBUG,
1941 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1942 peer->host,
1943 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1944 p->prefixlen, rsclient->host, reason);
1946 if (ri)
1947 bgp_rib_remove (rn, ri, peer, afi, safi);
1949 bgp_unlock_node (rn);
1951 if (new_attr.extra)
1952 bgp_attr_extra_free (&new_attr);
1954 return;
1957 static void
1958 bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1959 struct peer *peer, struct prefix *p, int type, int sub_type,
1960 struct prefix_rd *prd, u_char *tag)
1962 struct bgp_node *rn;
1963 struct bgp_info *ri;
1964 char buf[SU_ADDRSTRLEN];
1966 if (rsclient == peer)
1967 return;
1969 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1971 /* Lookup withdrawn route. */
1972 for (ri = rn->info; ri; ri = ri->next)
1973 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1974 break;
1976 /* Withdraw specified route from routing table. */
1977 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1978 bgp_rib_withdraw (rn, ri, peer, afi, safi);
1979 else if (BGP_DEBUG (update, UPDATE_IN))
1980 zlog (peer->log, LOG_DEBUG,
1981 "%s Can't find the route %s/%d", peer->host,
1982 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1983 p->prefixlen);
1985 /* Unlock bgp_node_get() lock. */
1986 bgp_unlock_node (rn);
1989 static int
1990 bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
1991 afi_t afi, safi_t safi, int type, int sub_type,
1992 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1994 int ret;
1995 int aspath_loop_count = 0;
1996 struct bgp_node *rn;
1997 struct bgp *bgp;
1998 struct attr new_attr = { 0 };
1999 struct attr *attr_new;
2000 struct bgp_info *ri;
2001 struct bgp_info *new;
2002 const char *reason;
2003 char buf[SU_ADDRSTRLEN];
2005 bgp = peer->bgp;
2006 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2008 /* When peer's soft reconfiguration enabled. Record input packet in
2009 Adj-RIBs-In. */
2010 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2011 && peer != bgp->peer_self && ! soft_reconfig)
2012 bgp_adj_in_set (rn, peer, attr);
2014 /* Check previously received route. */
2015 for (ri = rn->info; ri; ri = ri->next)
2016 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2017 break;
2019 /* AS path local-as loop check. */
2020 if (peer->change_local_as)
2022 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2023 aspath_loop_count = 1;
2025 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2027 reason = "as-path contains our own AS;";
2028 goto filtered;
2032 /* AS path loop check. */
2033 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2034 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2035 && aspath_loop_check(attr->aspath, bgp->confed_id)
2036 > peer->allowas_in[afi][safi]))
2038 reason = "as-path contains our own AS;";
2039 goto filtered;
2042 /* Route reflector originator ID check. */
2043 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
2044 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
2046 reason = "originator is us;";
2047 goto filtered;
2050 /* Route reflector cluster ID check. */
2051 if (bgp_cluster_filter (peer, attr))
2053 reason = "reflected from the same cluster;";
2054 goto filtered;
2057 /* Apply incoming filter. */
2058 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2060 reason = "filter;";
2061 goto filtered;
2064 /* Apply incoming route-map. */
2065 bgp_attr_dup (&new_attr, attr);
2067 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2069 reason = "route-map;";
2070 goto filtered;
2073 /* IPv4 unicast next hop check. */
2074 if (afi == AFI_IP && safi == SAFI_UNICAST)
2076 /* If the peer is EBGP and nexthop is not on connected route,
2077 discard it. */
2078 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2079 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
2080 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
2082 reason = "non-connected next-hop;";
2083 goto filtered;
2086 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2087 must not be my own address. */
2088 if (bgp_nexthop_self (afi, &new_attr)
2089 || new_attr.nexthop.s_addr == 0
2090 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2092 reason = "martian next-hop;";
2093 goto filtered;
2097 attr_new = bgp_attr_intern (&new_attr);
2099 /* If the update is implicit withdraw. */
2100 if (ri)
2102 ri->uptime = time (NULL);
2104 /* Same attribute comes in. */
2105 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2106 && attrhash_cmp (ri->attr, attr_new))
2108 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2110 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2111 && peer_sort (peer) == BGP_PEER_EBGP
2112 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2114 if (BGP_DEBUG (update, UPDATE_IN))
2115 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2116 peer->host,
2117 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2118 p->prefixlen);
2120 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2122 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2123 bgp_process (bgp, rn, afi, safi);
2126 else /* Duplicate - odd */
2128 if (BGP_DEBUG (update, UPDATE_IN))
2129 zlog (peer->log, LOG_DEBUG,
2130 "%s rcvd %s/%d...duplicate ignored",
2131 peer->host,
2132 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2133 p->prefixlen);
2135 /* graceful restart STALE flag unset. */
2136 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2138 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2139 bgp_process (bgp, rn, afi, safi);
2143 bgp_unlock_node (rn);
2144 bgp_attr_unintern (attr_new);
2145 bgp_attr_extra_free (&new_attr);
2147 return 0;
2150 /* Withdraw/Announce before we fully processed the withdraw */
2151 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2153 if (BGP_DEBUG (update, UPDATE_IN))
2154 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2155 peer->host,
2156 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2157 p->prefixlen);
2158 bgp_info_restore (rn, ri);
2161 /* Received Logging. */
2162 if (BGP_DEBUG (update, UPDATE_IN))
2163 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2164 peer->host,
2165 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2166 p->prefixlen);
2168 /* graceful restart STALE flag unset. */
2169 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2170 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
2172 /* The attribute is changed. */
2173 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
2175 /* implicit withdraw, decrement aggregate and pcount here.
2176 * only if update is accepted, they'll increment below.
2178 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2180 /* Update bgp route dampening information. */
2181 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2182 && peer_sort (peer) == BGP_PEER_EBGP)
2184 /* This is implicit withdraw so we should update dampening
2185 information. */
2186 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2187 bgp_damp_withdraw (ri, rn, afi, safi, 1);
2190 /* Update to new attribute. */
2191 bgp_attr_unintern (ri->attr);
2192 ri->attr = attr_new;
2194 /* Update MPLS tag. */
2195 if (safi == SAFI_MPLS_VPN)
2196 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
2198 /* Update bgp route dampening information. */
2199 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2200 && peer_sort (peer) == BGP_PEER_EBGP)
2202 /* Now we do normal update dampening. */
2203 ret = bgp_damp_update (ri, rn, afi, safi);
2204 if (ret == BGP_DAMP_SUPPRESSED)
2206 bgp_unlock_node (rn);
2207 bgp_attr_extra_free (&new_attr);
2208 return 0;
2212 /* Nexthop reachability check. */
2213 if ((afi == AFI_IP || afi == AFI_IP6)
2214 && safi == SAFI_UNICAST
2215 && (peer_sort (peer) == BGP_PEER_IBGP
2216 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
2217 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
2219 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
2220 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2221 else
2222 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
2224 else
2225 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
2227 /* Process change. */
2228 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2230 bgp_process (bgp, rn, afi, safi);
2231 bgp_unlock_node (rn);
2232 bgp_attr_extra_free (&new_attr);
2234 return 0;
2237 /* Received Logging. */
2238 if (BGP_DEBUG (update, UPDATE_IN))
2240 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
2241 peer->host,
2242 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2243 p->prefixlen);
2246 /* Make new BGP info. */
2247 new = bgp_info_new ();
2248 new->type = type;
2249 new->sub_type = sub_type;
2250 new->peer = peer;
2251 new->attr = attr_new;
2252 new->uptime = time (NULL);
2254 /* Update MPLS tag. */
2255 if (safi == SAFI_MPLS_VPN)
2256 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
2258 /* Nexthop reachability check. */
2259 if ((afi == AFI_IP || afi == AFI_IP6)
2260 && safi == SAFI_UNICAST
2261 && (peer_sort (peer) == BGP_PEER_IBGP
2262 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
2263 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
2265 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
2266 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2267 else
2268 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
2270 else
2271 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
2273 /* Increment prefix */
2274 bgp_aggregate_increment (bgp, p, new, afi, safi);
2276 /* Register new BGP information. */
2277 bgp_info_add (rn, new);
2279 /* route_node_get lock */
2280 bgp_unlock_node (rn);
2282 bgp_attr_extra_free (&new_attr);
2284 /* If maximum prefix count is configured and current prefix
2285 count exeed it. */
2286 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2287 return -1;
2289 /* Process change. */
2290 bgp_process (bgp, rn, afi, safi);
2292 return 0;
2294 /* This BGP update is filtered. Log the reason then update BGP
2295 entry. */
2296 filtered:
2297 if (BGP_DEBUG (update, UPDATE_IN))
2298 zlog (peer->log, LOG_DEBUG,
2299 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2300 peer->host,
2301 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2302 p->prefixlen, reason);
2304 if (ri)
2305 bgp_rib_remove (rn, ri, peer, afi, safi);
2307 bgp_unlock_node (rn);
2309 bgp_attr_extra_free (&new_attr);
2311 return 0;
2315 bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2316 afi_t afi, safi_t safi, int type, int sub_type,
2317 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2319 struct peer *rsclient;
2320 struct listnode *node, *nnode;
2321 struct bgp *bgp;
2322 int ret;
2324 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2325 soft_reconfig);
2327 bgp = peer->bgp;
2329 /* Process the update for each RS-client. */
2330 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2332 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2333 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2334 sub_type, prd, tag);
2337 return ret;
2341 bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
2342 afi_t afi, safi_t safi, int type, int sub_type,
2343 struct prefix_rd *prd, u_char *tag)
2345 struct bgp *bgp;
2346 char buf[SU_ADDRSTRLEN];
2347 struct bgp_node *rn;
2348 struct bgp_info *ri;
2349 struct peer *rsclient;
2350 struct listnode *node, *nnode;
2352 bgp = peer->bgp;
2354 /* Process the withdraw for each RS-client. */
2355 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
2357 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2358 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2361 /* Logging. */
2362 if (BGP_DEBUG (update, UPDATE_IN))
2363 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
2364 peer->host,
2365 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2366 p->prefixlen);
2368 /* Lookup node. */
2369 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2371 /* If peer is soft reconfiguration enabled. Record input packet for
2372 further calculation. */
2373 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2374 && peer != bgp->peer_self)
2375 bgp_adj_in_unset (rn, peer);
2377 /* Lookup withdrawn route. */
2378 for (ri = rn->info; ri; ri = ri->next)
2379 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2380 break;
2382 /* Withdraw specified route from routing table. */
2383 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2384 bgp_rib_withdraw (rn, ri, peer, afi, safi);
2385 else if (BGP_DEBUG (update, UPDATE_IN))
2386 zlog (peer->log, LOG_DEBUG,
2387 "%s Can't find the route %s/%d", peer->host,
2388 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2389 p->prefixlen);
2391 /* Unlock bgp_node_get() lock. */
2392 bgp_unlock_node (rn);
2394 return 0;
2397 void
2398 bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2400 struct bgp *bgp;
2401 struct attr attr;
2402 struct aspath *aspath = { 0 };
2403 struct prefix p;
2404 struct bgp_info binfo;
2405 struct peer *from;
2406 int ret = RMAP_DENYMATCH;
2408 if (!(afi == AFI_IP || afi == AFI_IP6))
2409 return;
2411 bgp = peer->bgp;
2412 from = bgp->peer_self;
2414 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2415 aspath = attr.aspath;
2416 attr.local_pref = bgp->default_local_pref;
2417 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2419 if (afi == AFI_IP)
2420 str2prefix ("0.0.0.0/0", &p);
2421 #ifdef HAVE_IPV6
2422 else if (afi == AFI_IP6)
2424 struct attr_extra *ae;
2425 attr.extra = NULL;
2427 ae = bgp_attr_extra_get (&attr);
2428 attr.extra = ae;
2430 str2prefix ("::/0", &p);
2432 /* IPv6 global nexthop must be included. */
2433 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
2434 IPV6_MAX_BYTELEN);
2435 ae->mp_nexthop_len = 16;
2437 /* If the peer is on shared nextwork and we have link-local
2438 nexthop set it. */
2439 if (peer->shared_network
2440 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2442 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
2443 IPV6_MAX_BYTELEN);
2444 ae->mp_nexthop_len = 32;
2447 #endif /* HAVE_IPV6 */
2449 if (peer->default_rmap[afi][safi].name)
2451 binfo.peer = bgp->peer_self;
2452 binfo.attr = &attr;
2454 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2456 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2457 RMAP_BGP, &binfo);
2459 bgp->peer_self->rmap_type = 0;
2461 if (ret == RMAP_DENYMATCH)
2463 bgp_attr_flush (&attr);
2464 withdraw = 1;
2468 if (withdraw)
2470 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2471 bgp_default_withdraw_send (peer, afi, safi);
2472 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2474 else
2476 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2477 bgp_default_update_send (peer, &attr, afi, safi, from);
2480 bgp_attr_extra_free (&attr);
2481 aspath_unintern (aspath);
2484 static void
2485 bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
2486 struct bgp_table *table, int rsclient)
2488 struct bgp_node *rn;
2489 struct bgp_info *ri;
2490 struct attr attr;
2492 memset (&attr, 0, sizeof (struct attr));
2494 if (! table)
2495 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
2497 if (safi != SAFI_MPLS_VPN
2498 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2499 bgp_default_originate (peer, afi, safi, 0);
2501 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2502 for (ri = rn->info; ri; ri = ri->next)
2503 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2505 if ( (rsclient) ?
2506 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2507 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
2508 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2509 else
2510 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2512 bgp_attr_extra_free (&attr);
2516 void
2517 bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2519 struct bgp_node *rn;
2520 struct bgp_table *table;
2522 if (peer->status != Established)
2523 return;
2525 if (! peer->afc_nego[afi][safi])
2526 return;
2528 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2529 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2530 return;
2532 if (safi != SAFI_MPLS_VPN)
2533 bgp_announce_table (peer, afi, safi, NULL, 0);
2534 else
2535 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2536 rn = bgp_route_next(rn))
2537 if ((table = (rn->info)) != NULL)
2538 bgp_announce_table (peer, afi, safi, table, 0);
2540 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2541 bgp_announce_table (peer, afi, safi, NULL, 1);
2544 void
2545 bgp_announce_route_all (struct peer *peer)
2547 afi_t afi;
2548 safi_t safi;
2550 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2551 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2552 bgp_announce_route (peer, afi, safi);
2555 static void
2556 bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2557 safi_t safi, struct bgp_table *table)
2559 struct bgp_node *rn;
2560 struct bgp_adj_in *ain;
2562 if (! table)
2563 table = rsclient->bgp->rib[afi][safi];
2565 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2566 for (ain = rn->adj_in; ain; ain = ain->next)
2568 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2569 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2573 void
2574 bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2576 struct bgp_table *table;
2577 struct bgp_node *rn;
2579 if (safi != SAFI_MPLS_VPN)
2580 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2582 else
2583 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2584 rn = bgp_route_next (rn))
2585 if ((table = rn->info) != NULL)
2586 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2589 static void
2590 bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2591 struct bgp_table *table)
2593 int ret;
2594 struct bgp_node *rn;
2595 struct bgp_adj_in *ain;
2597 if (! table)
2598 table = peer->bgp->rib[afi][safi];
2600 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2601 for (ain = rn->adj_in; ain; ain = ain->next)
2603 if (ain->peer == peer)
2605 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2606 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2607 NULL, NULL, 1);
2608 if (ret < 0)
2610 bgp_unlock_node (rn);
2611 return;
2613 continue;
2618 void
2619 bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2621 struct bgp_node *rn;
2622 struct bgp_table *table;
2624 if (peer->status != Established)
2625 return;
2627 if (safi != SAFI_MPLS_VPN)
2628 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2629 else
2630 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2631 rn = bgp_route_next (rn))
2632 if ((table = rn->info) != NULL)
2633 bgp_soft_reconfig_table (peer, afi, safi, table);
2636 static wq_item_status
2637 bgp_clear_route_node (struct work_queue *wq, void *data)
2639 struct bgp_node *rn = data;
2640 struct peer *peer = wq->spec.data;
2641 struct bgp_info *ri;
2642 afi_t afi = rn->table->afi;
2643 safi_t safi = rn->table->safi;
2645 assert (rn && peer);
2647 for (ri = rn->info; ri; ri = ri->next)
2648 if (ri->peer == peer)
2650 /* graceful restart STALE flag set. */
2651 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2652 && peer->nsf[afi][safi]
2653 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2654 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2655 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
2656 else
2657 bgp_rib_remove (rn, ri, peer, afi, safi);
2658 break;
2660 return WQ_SUCCESS;
2663 static void
2664 bgp_clear_node_queue_del (struct work_queue *wq, void *data)
2666 struct bgp_node *rn = data;
2668 bgp_unlock_node (rn);
2671 static void
2672 bgp_clear_node_complete (struct work_queue *wq)
2674 struct peer *peer = wq->spec.data;
2676 peer_unlock (peer); /* bgp_clear_node_complete */
2678 /* Tickle FSM to start moving again */
2679 BGP_EVENT_ADD (peer, Clearing_Completed);
2682 static void
2683 bgp_clear_node_queue_init (struct peer *peer)
2685 #define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2686 char wname[CLEAR_QUEUE_NAME_LEN];
2688 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2689 #undef CLEAR_QUEUE_NAME_LEN
2691 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
2693 zlog_err ("%s: Failed to allocate work queue", __func__);
2694 exit (1);
2696 peer->clear_node_queue->spec.hold = 10;
2697 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2698 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2699 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2700 peer->clear_node_queue->spec.max_retries = 0;
2702 /* we only 'lock' this peer reference when the queue is actually active */
2703 peer->clear_node_queue->spec.data = peer;
2706 static void
2707 bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
2708 struct bgp_table *table, struct peer *rsclient)
2710 struct bgp_node *rn;
2713 if (! table)
2714 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
2716 /* If still no table => afi/safi isn't configured at all or smth. */
2717 if (! table)
2718 return;
2720 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2722 struct bgp_info *ri;
2723 struct bgp_adj_in *ain;
2724 struct bgp_adj_out *aout;
2726 if (rn->info == NULL)
2727 continue;
2729 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2730 * queued for every clearing peer, regardless of whether it is
2731 * relevant to the peer at hand.
2733 * Overview: There are 3 different indices which need to be
2734 * scrubbed, potentially, when a peer is removed:
2736 * 1 peer's routes visible via the RIB (ie accepted routes)
2737 * 2 peer's routes visible by the (optional) peer's adj-in index
2738 * 3 other routes visible by the peer's adj-out index
2740 * 3 there is no hurry in scrubbing, once the struct peer is
2741 * removed from bgp->peer, we could just GC such deleted peer's
2742 * adj-outs at our leisure.
2744 * 1 and 2 must be 'scrubbed' in some way, at least made
2745 * invisible via RIB index before peer session is allowed to be
2746 * brought back up. So one needs to know when such a 'search' is
2747 * complete.
2749 * Ideally:
2751 * - there'd be a single global queue or a single RIB walker
2752 * - rather than tracking which route_nodes still need to be
2753 * examined on a peer basis, we'd track which peers still
2754 * aren't cleared
2756 * Given that our per-peer prefix-counts now should be reliable,
2757 * this may actually be achievable. It doesn't seem to be a huge
2758 * problem at this time,
2760 for (ri = rn->info; ri; ri = ri->next)
2761 if (ri->peer == peer)
2763 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2764 work_queue_add (peer->clear_node_queue, rn);
2767 for (ain = rn->adj_in; ain; ain = ain->next)
2768 if (ain->peer == peer)
2770 bgp_adj_in_remove (rn, ain);
2771 bgp_unlock_node (rn);
2772 break;
2774 for (aout = rn->adj_out; aout; aout = aout->next)
2775 if (aout->peer == peer)
2777 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2778 bgp_unlock_node (rn);
2779 break;
2782 return;
2785 void
2786 bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2788 struct bgp_node *rn;
2789 struct bgp_table *table;
2790 struct peer *rsclient;
2791 struct listnode *node, *nnode;
2793 if (peer->clear_node_queue == NULL)
2794 bgp_clear_node_queue_init (peer);
2796 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2797 * Idle until it receives a Clearing_Completed event. This protects
2798 * against peers which flap faster than we can we clear, which could
2799 * lead to:
2801 * a) race with routes from the new session being installed before
2802 * clear_route_node visits the node (to delete the route of that
2803 * peer)
2804 * b) resource exhaustion, clear_route_node likely leads to an entry
2805 * on the process_main queue. Fast-flapping could cause that queue
2806 * to grow and grow.
2808 if (!peer->clear_node_queue->thread)
2809 peer_lock (peer); /* bgp_clear_node_complete */
2811 if (safi != SAFI_MPLS_VPN)
2812 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
2813 else
2814 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2815 rn = bgp_route_next (rn))
2816 if ((table = rn->info) != NULL)
2817 bgp_clear_route_table (peer, afi, safi, table, NULL);
2819 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2821 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2822 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2825 /* If no routes were cleared, nothing was added to workqueue, the
2826 * completion function won't be run by workqueue code - call it here.
2827 * XXX: Actually, this assumption doesn't hold, see
2828 * bgp_clear_route_table(), we queue all non-empty nodes.
2830 * Additionally, there is a presumption in FSM that clearing is only
2831 * really needed if peer state is Established - peers in
2832 * pre-Established states shouldn't have any route-update state
2833 * associated with them (in or out).
2835 * We still can get here in pre-Established though, through
2836 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2837 * check to ensure the assumption above holds.
2839 * At some future point, this check could be move to the top of the
2840 * function, and do a quick early-return when state is
2841 * pre-Established, avoiding above list and table scans. Once we're
2842 * sure it is safe..
2844 if (!peer->clear_node_queue->thread)
2845 bgp_clear_node_complete (peer->clear_node_queue);
2846 else
2848 /* clearing queue scheduled. Normal if in Established state
2849 * (and about to transition out of it), but otherwise...
2851 if (peer->status != Established)
2853 plog_err (peer->log, "%s [Error] State %s is not Established,"
2854 " but routes were cleared - bug!",
2855 peer->host, LOOKUP (bgp_status_msg, peer->status));
2856 assert (peer->status == Established);
2861 void
2862 bgp_clear_route_all (struct peer *peer)
2864 afi_t afi;
2865 safi_t safi;
2867 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2868 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2869 bgp_clear_route (peer, afi, safi);
2872 void
2873 bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2875 struct bgp_table *table;
2876 struct bgp_node *rn;
2877 struct bgp_adj_in *ain;
2879 table = peer->bgp->rib[afi][safi];
2881 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2882 for (ain = rn->adj_in; ain ; ain = ain->next)
2883 if (ain->peer == peer)
2885 bgp_adj_in_remove (rn, ain);
2886 bgp_unlock_node (rn);
2887 break;
2891 void
2892 bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2894 struct bgp_node *rn;
2895 struct bgp_info *ri;
2896 struct bgp_table *table;
2898 table = peer->bgp->rib[afi][safi];
2900 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2902 for (ri = rn->info; ri; ri = ri->next)
2903 if (ri->peer == peer)
2905 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2906 bgp_rib_remove (rn, ri, peer, afi, safi);
2907 break;
2912 /* Delete all kernel routes. */
2913 void
2914 bgp_cleanup_routes (void)
2916 struct bgp *bgp;
2917 struct listnode *node, *nnode;
2918 struct bgp_node *rn;
2919 struct bgp_table *table;
2920 struct bgp_info *ri;
2922 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
2924 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2926 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2927 for (ri = rn->info; ri; ri = ri->next)
2928 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2929 && ri->type == ZEBRA_ROUTE_BGP
2930 && ri->sub_type == BGP_ROUTE_NORMAL)
2931 bgp_zebra_withdraw (&rn->p, ri);
2933 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2935 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2936 for (ri = rn->info; ri; ri = ri->next)
2937 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2938 && ri->type == ZEBRA_ROUTE_BGP
2939 && ri->sub_type == BGP_ROUTE_NORMAL)
2940 bgp_zebra_withdraw (&rn->p, ri);
2944 void
2945 bgp_reset (void)
2947 vty_reset ();
2948 bgp_zclient_reset ();
2949 access_list_reset ();
2950 prefix_list_reset ();
2953 /* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2954 value. */
2956 bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2958 u_char *pnt;
2959 u_char *lim;
2960 struct prefix p;
2961 int psize;
2962 int ret;
2964 /* Check peer status. */
2965 if (peer->status != Established)
2966 return 0;
2968 pnt = packet->nlri;
2969 lim = pnt + packet->length;
2971 for (; pnt < lim; pnt += psize)
2973 /* Clear prefix structure. */
2974 memset (&p, 0, sizeof (struct prefix));
2976 /* Fetch prefix length. */
2977 p.prefixlen = *pnt++;
2978 p.family = afi2family (packet->afi);
2980 /* Already checked in nlri_sanity_check(). We do double check
2981 here. */
2982 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2983 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2984 return -1;
2986 /* Packet size overflow check. */
2987 psize = PSIZE (p.prefixlen);
2989 /* When packet overflow occur return immediately. */
2990 if (pnt + psize > lim)
2991 return -1;
2993 /* Fetch prefix from NLRI packet. */
2994 memcpy (&p.u.prefix, pnt, psize);
2996 /* Check address. */
2997 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2999 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3002 * From draft-ietf-idr-bgp4-22, Section 6.3:
3003 * If a BGP router receives an UPDATE message with a
3004 * semantically incorrect NLRI field, in which a prefix is
3005 * semantically incorrect (eg. an unexpected multicast IP
3006 * address), it should ignore the prefix.
3008 zlog (peer->log, LOG_ERR,
3009 "IPv4 unicast NLRI is multicast address %s",
3010 inet_ntoa (p.u.prefix4));
3012 return -1;
3016 #ifdef HAVE_IPV6
3017 /* Check address. */
3018 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3020 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3022 char buf[BUFSIZ];
3024 zlog (peer->log, LOG_WARNING,
3025 "IPv6 link-local NLRI received %s ignore this NLRI",
3026 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3028 continue;
3031 #endif /* HAVE_IPV6 */
3033 /* Normal process. */
3034 if (attr)
3035 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3036 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3037 else
3038 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3039 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3041 /* Address family configuration mismatch or maximum-prefix count
3042 overflow. */
3043 if (ret < 0)
3044 return -1;
3047 /* Packet length consistency check. */
3048 if (pnt != lim)
3049 return -1;
3051 return 0;
3054 /* NLRI encode syntax check routine. */
3056 bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3057 bgp_size_t length)
3059 u_char *end;
3060 u_char prefixlen;
3061 int psize;
3063 end = pnt + length;
3065 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3066 syntactic validity. If the field is syntactically incorrect,
3067 then the Error Subcode is set to Invalid Network Field. */
3069 while (pnt < end)
3071 prefixlen = *pnt++;
3073 /* Prefix length check. */
3074 if ((afi == AFI_IP && prefixlen > 32)
3075 || (afi == AFI_IP6 && prefixlen > 128))
3077 plog_err (peer->log,
3078 "%s [Error] Update packet error (wrong prefix length %d)",
3079 peer->host, prefixlen);
3080 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3081 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3082 return -1;
3085 /* Packet size overflow check. */
3086 psize = PSIZE (prefixlen);
3088 if (pnt + psize > end)
3090 plog_err (peer->log,
3091 "%s [Error] Update packet error"
3092 " (prefix data overflow prefix size is %d)",
3093 peer->host, psize);
3094 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3095 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3096 return -1;
3099 pnt += psize;
3102 /* Packet length consistency check. */
3103 if (pnt != end)
3105 plog_err (peer->log,
3106 "%s [Error] Update packet error"
3107 " (prefix length mismatch with total length)",
3108 peer->host);
3109 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3110 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3111 return -1;
3113 return 0;
3116 static struct bgp_static *
3117 bgp_static_new (void)
3119 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3122 static void
3123 bgp_static_free (struct bgp_static *bgp_static)
3125 if (bgp_static->rmap.name)
3126 free (bgp_static->rmap.name);
3127 XFREE (MTYPE_BGP_STATIC, bgp_static);
3130 static void
3131 bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3132 struct prefix *p, afi_t afi, safi_t safi)
3134 struct bgp_node *rn;
3135 struct bgp_info *ri;
3137 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3139 /* Check selected route and self inserted route. */
3140 for (ri = rn->info; ri; ri = ri->next)
3141 if (ri->peer == bgp->peer_self
3142 && ri->type == ZEBRA_ROUTE_BGP
3143 && ri->sub_type == BGP_ROUTE_STATIC)
3144 break;
3146 /* Withdraw static BGP route from routing table. */
3147 if (ri)
3149 bgp_info_delete (rn, ri);
3150 bgp_process (bgp, rn, afi, safi);
3153 /* Unlock bgp_node_lookup. */
3154 bgp_unlock_node (rn);
3157 static void
3158 bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
3159 struct bgp_static *bgp_static,
3160 afi_t afi, safi_t safi)
3162 struct bgp_node *rn;
3163 struct bgp_info *ri;
3164 struct bgp_info *new;
3165 struct bgp_info info;
3166 struct attr *attr_new;
3167 struct attr attr = {0 };
3168 struct attr new_attr = { .extra = 0 };
3169 struct bgp *bgp;
3170 int ret;
3171 char buf[SU_ADDRSTRLEN];
3173 bgp = rsclient->bgp;
3175 assert (bgp_static);
3176 if (!bgp_static)
3177 return;
3179 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3181 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3183 attr.nexthop = bgp_static->igpnexthop;
3184 attr.med = bgp_static->igpmetric;
3185 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3187 if (bgp_static->ttl)
3189 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3190 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3191 attr.pathlimit.as = 0;
3192 attr.pathlimit.ttl = bgp_static->ttl;
3195 if (bgp_static->atomic)
3196 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3198 /* Apply network route-map for export to this rsclient. */
3199 if (bgp_static->rmap.name)
3201 struct attr attr_tmp = attr;
3202 info.peer = rsclient;
3203 info.attr = &attr_tmp;
3205 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3206 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3208 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3210 rsclient->rmap_type = 0;
3212 if (ret == RMAP_DENYMATCH)
3214 /* Free uninterned attribute. */
3215 bgp_attr_flush (&attr_tmp);
3217 /* Unintern original. */
3218 aspath_unintern (attr.aspath);
3219 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3220 bgp_attr_extra_free (&attr);
3222 return;
3224 attr_new = bgp_attr_intern (&attr_tmp);
3226 else
3227 attr_new = bgp_attr_intern (&attr);
3229 new_attr = *attr_new;
3231 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3233 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3234 == RMAP_DENY)
3236 /* This BGP update is filtered. Log the reason then update BGP entry. */
3237 if (BGP_DEBUG (update, UPDATE_IN))
3238 zlog (rsclient->log, LOG_DEBUG,
3239 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3240 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3241 p->prefixlen, rsclient->host);
3243 bgp->peer_self->rmap_type = 0;
3245 bgp_attr_unintern (attr_new);
3246 aspath_unintern (attr.aspath);
3247 bgp_attr_extra_free (&attr);
3249 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3251 return;
3254 bgp->peer_self->rmap_type = 0;
3256 bgp_attr_unintern (attr_new);
3257 attr_new = bgp_attr_intern (&new_attr);
3259 for (ri = rn->info; ri; ri = ri->next)
3260 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3261 && ri->sub_type == BGP_ROUTE_STATIC)
3262 break;
3264 if (ri)
3266 if (attrhash_cmp (ri->attr, attr_new) &&
3267 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3269 bgp_unlock_node (rn);
3270 bgp_attr_unintern (attr_new);
3271 aspath_unintern (attr.aspath);
3272 bgp_attr_extra_free (&attr);
3273 return;
3275 else
3277 /* The attribute is changed. */
3278 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3280 /* Rewrite BGP route information. */
3281 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3282 bgp_info_restore(rn, ri);
3283 bgp_attr_unintern (ri->attr);
3284 ri->attr = attr_new;
3285 ri->uptime = time (NULL);
3287 /* Process change. */
3288 bgp_process (bgp, rn, afi, safi);
3289 bgp_unlock_node (rn);
3290 aspath_unintern (attr.aspath);
3291 bgp_attr_extra_free (&attr);
3292 return;
3296 /* Make new BGP info. */
3297 new = bgp_info_new ();
3298 new->type = ZEBRA_ROUTE_BGP;
3299 new->sub_type = BGP_ROUTE_STATIC;
3300 new->peer = bgp->peer_self;
3301 SET_FLAG (new->flags, BGP_INFO_VALID);
3302 new->attr = attr_new;
3303 new->uptime = time (NULL);
3305 /* Register new BGP information. */
3306 bgp_info_add (rn, new);
3308 /* route_node_get lock */
3309 bgp_unlock_node (rn);
3311 /* Process change. */
3312 bgp_process (bgp, rn, afi, safi);
3314 /* Unintern original. */
3315 aspath_unintern (attr.aspath);
3316 bgp_attr_extra_free (&attr);
3319 static void
3320 bgp_static_update_main (struct bgp *bgp, struct prefix *p,
3321 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3323 struct bgp_node *rn;
3324 struct bgp_info *ri;
3325 struct bgp_info *new;
3326 struct bgp_info info;
3327 struct attr attr = { 0 };
3328 struct attr *attr_new;
3329 int ret;
3331 assert (bgp_static);
3332 if (!bgp_static)
3333 return;
3335 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3337 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3339 attr.nexthop = bgp_static->igpnexthop;
3340 attr.med = bgp_static->igpmetric;
3341 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3343 if (bgp_static->ttl)
3345 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3346 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3347 attr.pathlimit.as = 0;
3348 attr.pathlimit.ttl = bgp_static->ttl;
3351 if (bgp_static->atomic)
3352 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3354 /* Apply route-map. */
3355 if (bgp_static->rmap.name)
3357 struct attr attr_tmp = attr;
3358 info.peer = bgp->peer_self;
3359 info.attr = &attr_tmp;
3361 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3363 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3365 bgp->peer_self->rmap_type = 0;
3367 if (ret == RMAP_DENYMATCH)
3369 /* Free uninterned attribute. */
3370 bgp_attr_flush (&attr_tmp);
3372 /* Unintern original. */
3373 aspath_unintern (attr.aspath);
3374 bgp_attr_extra_free (&attr);
3375 bgp_static_withdraw (bgp, p, afi, safi);
3376 return;
3378 attr_new = bgp_attr_intern (&attr_tmp);
3380 else
3381 attr_new = bgp_attr_intern (&attr);
3383 for (ri = rn->info; ri; ri = ri->next)
3384 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3385 && ri->sub_type == BGP_ROUTE_STATIC)
3386 break;
3388 if (ri)
3390 if (attrhash_cmp (ri->attr, attr_new) &&
3391 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3393 bgp_unlock_node (rn);
3394 bgp_attr_unintern (attr_new);
3395 aspath_unintern (attr.aspath);
3396 bgp_attr_extra_free (&attr);
3397 return;
3399 else
3401 /* The attribute is changed. */
3402 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3404 /* Rewrite BGP route information. */
3405 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3406 bgp_info_restore(rn, ri);
3407 else
3408 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3409 bgp_attr_unintern (ri->attr);
3410 ri->attr = attr_new;
3411 ri->uptime = time (NULL);
3413 /* Process change. */
3414 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3415 bgp_process (bgp, rn, afi, safi);
3416 bgp_unlock_node (rn);
3417 aspath_unintern (attr.aspath);
3418 bgp_attr_extra_free (&attr);
3419 return;
3423 /* Make new BGP info. */
3424 new = bgp_info_new ();
3425 new->type = ZEBRA_ROUTE_BGP;
3426 new->sub_type = BGP_ROUTE_STATIC;
3427 new->peer = bgp->peer_self;
3428 SET_FLAG (new->flags, BGP_INFO_VALID);
3429 new->attr = attr_new;
3430 new->uptime = time (NULL);
3432 /* Aggregate address increment. */
3433 bgp_aggregate_increment (bgp, p, new, afi, safi);
3435 /* Register new BGP information. */
3436 bgp_info_add (rn, new);
3438 /* route_node_get lock */
3439 bgp_unlock_node (rn);
3441 /* Process change. */
3442 bgp_process (bgp, rn, afi, safi);
3444 /* Unintern original. */
3445 aspath_unintern (attr.aspath);
3446 bgp_attr_extra_free (&attr);
3449 void
3450 bgp_static_update (struct bgp *bgp, struct prefix *p,
3451 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3453 struct peer *rsclient;
3454 struct listnode *node, *nnode;
3456 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3458 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
3460 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3461 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3465 static void
3466 bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3467 u_char safi, struct prefix_rd *prd, u_char *tag)
3469 struct bgp_node *rn;
3470 struct bgp_info *new;
3472 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3474 /* Make new BGP info. */
3475 new = bgp_info_new ();
3476 new->type = ZEBRA_ROUTE_BGP;
3477 new->sub_type = BGP_ROUTE_STATIC;
3478 new->peer = bgp->peer_self;
3479 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3480 SET_FLAG (new->flags, BGP_INFO_VALID);
3481 new->uptime = time (NULL);
3482 new->extra = bgp_info_extra_new();
3483 memcpy (new->extra->tag, tag, 3);
3485 /* Aggregate address increment. */
3486 bgp_aggregate_increment (bgp, p, new, afi, safi);
3488 /* Register new BGP information. */
3489 bgp_info_add (rn, new);
3491 /* route_node_get lock */
3492 bgp_unlock_node (rn);
3494 /* Process change. */
3495 bgp_process (bgp, rn, afi, safi);
3498 void
3499 bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3500 safi_t safi)
3502 struct bgp_node *rn;
3503 struct bgp_info *ri;
3505 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
3507 /* Check selected route and self inserted route. */
3508 for (ri = rn->info; ri; ri = ri->next)
3509 if (ri->peer == bgp->peer_self
3510 && ri->type == ZEBRA_ROUTE_BGP
3511 && ri->sub_type == BGP_ROUTE_STATIC)
3512 break;
3514 /* Withdraw static BGP route from routing table. */
3515 if (ri)
3517 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3518 bgp_info_delete (rn, ri);
3519 bgp_process (bgp, rn, afi, safi);
3522 /* Unlock bgp_node_lookup. */
3523 bgp_unlock_node (rn);
3526 void
3527 bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3529 struct bgp_static *bgp_static;
3530 struct bgp *bgp;
3531 struct bgp_node *rn;
3532 struct prefix *p;
3534 bgp = rsclient->bgp;
3536 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3537 if ((bgp_static = rn->info) != NULL)
3539 p = &rn->p;
3541 bgp_static_update_rsclient (rsclient, p, bgp_static,
3542 afi, safi);
3546 static void
3547 bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3548 u_char safi, struct prefix_rd *prd, u_char *tag)
3550 struct bgp_node *rn;
3551 struct bgp_info *ri;
3553 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
3555 /* Check selected route and self inserted route. */
3556 for (ri = rn->info; ri; ri = ri->next)
3557 if (ri->peer == bgp->peer_self
3558 && ri->type == ZEBRA_ROUTE_BGP
3559 && ri->sub_type == BGP_ROUTE_STATIC)
3560 break;
3562 /* Withdraw static BGP route from routing table. */
3563 if (ri)
3565 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3566 bgp_info_delete (rn, ri);
3567 bgp_process (bgp, rn, afi, safi);
3570 /* Unlock bgp_node_lookup. */
3571 bgp_unlock_node (rn);
3574 static void
3575 bgp_pathlimit_update_parents (struct bgp *bgp, struct bgp_node *rn,
3576 int ttl_edge)
3578 struct bgp_node *parent = rn;
3579 struct bgp_static *sp;
3581 /* Existing static changed TTL, search parents and adjust their atomic */
3582 while ((parent = parent->parent))
3583 if ((sp = parent->info))
3585 int sp_level = (sp->atomic ? 1 : 0);
3586 ttl_edge ? sp->atomic++ : sp->atomic--;
3588 /* did we change state of parent whether atomic is set or not? */
3589 if (sp_level != (sp->atomic ? 1 : 0))
3591 bgp_static_update (bgp, &parent->p, sp,
3592 rn->table->afi, rn->table->safi);
3597 /* Configure static BGP network. When user don't run zebra, static
3598 route should be installed as valid. */
3599 static int
3600 bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3601 u_int16_t afi, u_char safi, const char *rmap, int backdoor,
3602 u_char ttl)
3604 int ret;
3605 struct prefix p;
3606 struct bgp_static *bgp_static;
3607 struct bgp_node *rn;
3608 u_char need_update = 0;
3609 u_char ttl_change = 0;
3610 u_char ttl_edge = (ttl ? 1 : 0);
3611 u_char new = 0;
3613 /* Convert IP prefix string to struct prefix. */
3614 ret = str2prefix (ip_str, &p);
3615 if (! ret)
3617 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3618 return CMD_WARNING;
3620 #ifdef HAVE_IPV6
3621 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3623 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3624 VTY_NEWLINE);
3625 return CMD_WARNING;
3627 #endif /* HAVE_IPV6 */
3629 apply_mask (&p);
3631 /* Set BGP static route configuration. */
3632 rn = bgp_node_get (bgp->route[afi][safi], &p);
3634 if (rn->info)
3636 /* Configuration change. */
3637 bgp_static = rn->info;
3639 /* Check previous routes are installed into BGP. */
3640 if (bgp_static->valid)
3642 if (bgp_static->backdoor != backdoor
3643 || bgp_static->ttl != ttl)
3644 need_update = 1;
3647 /* need to catch TTL set/unset transitions for handling of
3648 * ATOMIC_AGGREGATE
3650 if ((bgp_static->ttl ? 1 : 0) != ttl_edge)
3651 ttl_change = 1;
3653 bgp_static->backdoor = backdoor;
3654 bgp_static->ttl = ttl;
3656 if (rmap)
3658 if (bgp_static->rmap.name)
3659 free (bgp_static->rmap.name);
3660 bgp_static->rmap.name = strdup (rmap);
3661 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3663 else
3665 if (bgp_static->rmap.name)
3666 free (bgp_static->rmap.name);
3667 bgp_static->rmap.name = NULL;
3668 bgp_static->rmap.map = NULL;
3669 bgp_static->valid = 0;
3671 bgp_unlock_node (rn);
3673 else
3675 /* New configuration. */
3676 bgp_static = bgp_static_new ();
3677 bgp_static->backdoor = backdoor;
3678 bgp_static->valid = 0;
3679 bgp_static->igpmetric = 0;
3680 bgp_static->igpnexthop.s_addr = 0;
3681 bgp_static->ttl = ttl;
3682 ttl_change = ttl_edge;
3683 new = 1;
3685 if (rmap)
3687 if (bgp_static->rmap.name)
3688 free (bgp_static->rmap.name);
3689 bgp_static->rmap.name = strdup (rmap);
3690 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3692 rn->info = bgp_static;
3695 /* ".. sites that choose to advertise the
3696 * AS_PATHLIMIT path attribute SHOULD advertise the ATOMIC_AGGREGATE on
3697 * all less specific covering prefixes as well as the more specific
3698 * prefixes."
3700 * So:
3701 * Prefix that has just had pathlimit set/unset:
3702 * - Must bump ATOMIC refcount on all parents.
3704 * To catch less specific prefixes:
3705 * - Must search children for ones with TTL, bump atomic refcount
3706 * (we dont care if we're deleting a less specific prefix..)
3708 if (ttl_change)
3710 /* Existing static changed TTL, search parents and adjust their atomic */
3711 bgp_pathlimit_update_parents (bgp, rn, ttl_edge);
3714 if (new)
3716 struct bgp_node *child;
3717 struct bgp_static *sc;
3719 /* New static, search children and bump this statics atomic.. */
3720 child = bgp_lock_node (rn); /* route_next_until unlocks it.. */
3721 while ((child = bgp_route_next_until (child, rn)))
3723 if ((sc = child->info) && sc->ttl)
3724 bgp_static->atomic++;
3728 /* If BGP scan is not enabled, we should install this route here. */
3729 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3731 bgp_static->valid = 1;
3733 if (need_update)
3734 bgp_static_withdraw (bgp, &p, afi, safi);
3736 if (! bgp_static->backdoor)
3737 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3740 return CMD_SUCCESS;
3743 /* Configure static BGP network. */
3744 static int
3745 bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
3746 u_int16_t afi, u_char safi)
3748 int ret;
3749 struct prefix p;
3750 struct bgp_static *bgp_static;
3751 struct bgp_node *rn;
3753 /* Convert IP prefix string to struct prefix. */
3754 ret = str2prefix (ip_str, &p);
3755 if (! ret)
3757 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3758 return CMD_WARNING;
3760 #ifdef HAVE_IPV6
3761 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3763 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3764 VTY_NEWLINE);
3765 return CMD_WARNING;
3767 #endif /* HAVE_IPV6 */
3769 apply_mask (&p);
3771 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3772 if (! rn)
3774 vty_out (vty, "%% Can't find specified static route configuration.%s",
3775 VTY_NEWLINE);
3776 return CMD_WARNING;
3779 bgp_static = rn->info;
3781 /* decrement atomic in parents, see bgp_static_set */
3782 bgp_pathlimit_update_parents (bgp, rn, 0);
3784 /* Update BGP RIB. */
3785 if (! bgp_static->backdoor)
3786 bgp_static_withdraw (bgp, &p, afi, safi);
3788 /* Clear configuration. */
3789 bgp_static_free (bgp_static);
3790 rn->info = NULL;
3791 bgp_unlock_node (rn);
3792 bgp_unlock_node (rn);
3794 return CMD_SUCCESS;
3797 /* Called from bgp_delete(). Delete all static routes from the BGP
3798 instance. */
3799 void
3800 bgp_static_delete (struct bgp *bgp)
3802 afi_t afi;
3803 safi_t safi;
3804 struct bgp_node *rn;
3805 struct bgp_node *rm;
3806 struct bgp_table *table;
3807 struct bgp_static *bgp_static;
3809 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3810 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3811 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3812 if (rn->info != NULL)
3814 if (safi == SAFI_MPLS_VPN)
3816 table = rn->info;
3818 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3820 bgp_static = rn->info;
3821 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3822 AFI_IP, SAFI_MPLS_VPN,
3823 (struct prefix_rd *)&rn->p,
3824 bgp_static->tag);
3825 bgp_static_free (bgp_static);
3826 rn->info = NULL;
3827 bgp_unlock_node (rn);
3830 else
3832 bgp_static = rn->info;
3833 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3834 bgp_static_free (bgp_static);
3835 rn->info = NULL;
3836 bgp_unlock_node (rn);
3842 bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3843 const char *tag_str)
3845 int ret;
3846 struct prefix p;
3847 struct prefix_rd prd;
3848 struct bgp *bgp;
3849 struct bgp_node *prn;
3850 struct bgp_node *rn;
3851 struct bgp_table *table;
3852 struct bgp_static *bgp_static;
3853 u_char tag[3];
3855 bgp = vty->index;
3857 ret = str2prefix (ip_str, &p);
3858 if (! ret)
3860 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3861 return CMD_WARNING;
3863 apply_mask (&p);
3865 ret = str2prefix_rd (rd_str, &prd);
3866 if (! ret)
3868 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3869 return CMD_WARNING;
3872 ret = str2tag (tag_str, tag);
3873 if (! ret)
3875 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3876 return CMD_WARNING;
3879 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3880 (struct prefix *)&prd);
3881 if (prn->info == NULL)
3882 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3883 else
3884 bgp_unlock_node (prn);
3885 table = prn->info;
3887 rn = bgp_node_get (table, &p);
3889 if (rn->info)
3891 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3892 bgp_unlock_node (rn);
3894 else
3896 /* New configuration. */
3897 bgp_static = bgp_static_new ();
3898 bgp_static->valid = 1;
3899 memcpy (bgp_static->tag, tag, 3);
3900 rn->info = bgp_static;
3902 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3905 return CMD_SUCCESS;
3908 /* Configure static BGP network. */
3910 bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3911 const char *rd_str, const char *tag_str)
3913 int ret;
3914 struct bgp *bgp;
3915 struct prefix p;
3916 struct prefix_rd prd;
3917 struct bgp_node *prn;
3918 struct bgp_node *rn;
3919 struct bgp_table *table;
3920 struct bgp_static *bgp_static;
3921 u_char tag[3];
3923 bgp = vty->index;
3925 /* Convert IP prefix string to struct prefix. */
3926 ret = str2prefix (ip_str, &p);
3927 if (! ret)
3929 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3930 return CMD_WARNING;
3932 apply_mask (&p);
3934 ret = str2prefix_rd (rd_str, &prd);
3935 if (! ret)
3937 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3938 return CMD_WARNING;
3941 ret = str2tag (tag_str, tag);
3942 if (! ret)
3944 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3945 return CMD_WARNING;
3948 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3949 (struct prefix *)&prd);
3950 if (prn->info == NULL)
3951 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
3952 else
3953 bgp_unlock_node (prn);
3954 table = prn->info;
3956 rn = bgp_node_lookup (table, &p);
3958 if (rn)
3960 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3962 bgp_static = rn->info;
3963 bgp_static_free (bgp_static);
3964 rn->info = NULL;
3965 bgp_unlock_node (rn);
3966 bgp_unlock_node (rn);
3968 else
3969 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3971 return CMD_SUCCESS;
3974 DEFUN (bgp_network,
3975 bgp_network_cmd,
3976 "network A.B.C.D/M",
3977 "Specify a network to announce via BGP\n"
3978 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3980 u_char ttl = 0;
3982 if (argc == 2)
3983 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
3985 return bgp_static_set (vty, vty->index, argv[0],
3986 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
3989 ALIAS (bgp_network,
3990 bgp_network_ttl_cmd,
3991 "network A.B.C.D/M pathlimit <0-255>",
3992 "Specify a network to announce via BGP\n"
3993 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3994 "AS-Path hopcount limit attribute\n"
3995 "AS-Pathlimit TTL, in number of AS-Path hops\n")
3997 DEFUN (bgp_network_route_map,
3998 bgp_network_route_map_cmd,
3999 "network A.B.C.D/M route-map WORD",
4000 "Specify a network to announce via BGP\n"
4001 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4002 "Route-map to modify the attributes\n"
4003 "Name of the route map\n")
4005 return bgp_static_set (vty, vty->index, argv[0],
4006 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
4009 DEFUN (bgp_network_backdoor,
4010 bgp_network_backdoor_cmd,
4011 "network A.B.C.D/M backdoor",
4012 "Specify a network to announce via BGP\n"
4013 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4014 "Specify a BGP backdoor route\n")
4016 u_char ttl = 0;
4018 if (argc == 2)
4019 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4021 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4022 NULL, 1, ttl);
4025 ALIAS (bgp_network_backdoor,
4026 bgp_network_backdoor_ttl_cmd,
4027 "network A.B.C.D/M backdoor pathlimit <0-255>",
4028 "Specify a network to announce via BGP\n"
4029 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4030 "Specify a BGP backdoor route\n"
4031 "AS-Path hopcount limit attribute\n"
4032 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4034 DEFUN (bgp_network_mask,
4035 bgp_network_mask_cmd,
4036 "network A.B.C.D mask A.B.C.D",
4037 "Specify a network to announce via BGP\n"
4038 "Network number\n"
4039 "Network mask\n"
4040 "Network mask\n")
4042 int ret;
4043 char prefix_str[BUFSIZ];
4044 u_char ttl = 0;
4046 if (argc == 3)
4047 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4049 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4050 if (! ret)
4052 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4053 return CMD_WARNING;
4056 return bgp_static_set (vty, vty->index, prefix_str,
4057 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
4060 ALIAS (bgp_network_mask,
4061 bgp_network_mask_ttl_cmd,
4062 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4063 "Specify a network to announce via BGP\n"
4064 "Network number\n"
4065 "Network mask\n"
4066 "Network mask\n"
4067 "AS-Path hopcount limit attribute\n"
4068 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4070 DEFUN (bgp_network_mask_route_map,
4071 bgp_network_mask_route_map_cmd,
4072 "network A.B.C.D mask A.B.C.D route-map WORD",
4073 "Specify a network to announce via BGP\n"
4074 "Network number\n"
4075 "Network mask\n"
4076 "Network mask\n"
4077 "Route-map to modify the attributes\n"
4078 "Name of the route map\n")
4080 int ret;
4081 char prefix_str[BUFSIZ];
4083 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4084 if (! ret)
4086 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4087 return CMD_WARNING;
4090 return bgp_static_set (vty, vty->index, prefix_str,
4091 AFI_IP, bgp_node_safi (vty), argv[2], 0, 0);
4094 DEFUN (bgp_network_mask_backdoor,
4095 bgp_network_mask_backdoor_cmd,
4096 "network A.B.C.D mask A.B.C.D backdoor",
4097 "Specify a network to announce via BGP\n"
4098 "Network number\n"
4099 "Network mask\n"
4100 "Network mask\n"
4101 "Specify a BGP backdoor route\n")
4103 int ret;
4104 char prefix_str[BUFSIZ];
4105 u_char ttl = 0;
4107 if (argc == 3)
4108 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4110 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4111 if (! ret)
4113 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4114 return CMD_WARNING;
4117 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4118 NULL, 1, ttl);
4121 ALIAS (bgp_network_mask_backdoor,
4122 bgp_network_mask_backdoor_ttl_cmd,
4123 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4124 "Specify a network to announce via BGP\n"
4125 "Network number\n"
4126 "Network mask\n"
4127 "Network mask\n"
4128 "Specify a BGP backdoor route\n"
4129 "AS-Path hopcount limit attribute\n"
4130 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4132 DEFUN (bgp_network_mask_natural,
4133 bgp_network_mask_natural_cmd,
4134 "network A.B.C.D",
4135 "Specify a network to announce via BGP\n"
4136 "Network number\n")
4138 int ret;
4139 char prefix_str[BUFSIZ];
4140 u_char ttl = 0;
4142 if (argc == 2)
4143 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4145 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4146 if (! ret)
4148 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4149 return CMD_WARNING;
4152 return bgp_static_set (vty, vty->index, prefix_str,
4153 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
4156 ALIAS (bgp_network_mask_natural,
4157 bgp_network_mask_natural_ttl_cmd,
4158 "network A.B.C.D pathlimit <0-255>",
4159 "Specify a network to announce via BGP\n"
4160 "Network number\n"
4161 "AS-Path hopcount limit attribute\n"
4162 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4164 DEFUN (bgp_network_mask_natural_route_map,
4165 bgp_network_mask_natural_route_map_cmd,
4166 "network A.B.C.D route-map WORD",
4167 "Specify a network to announce via BGP\n"
4168 "Network number\n"
4169 "Route-map to modify the attributes\n"
4170 "Name of the route map\n")
4172 int ret;
4173 char prefix_str[BUFSIZ];
4175 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4176 if (! ret)
4178 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4179 return CMD_WARNING;
4182 return bgp_static_set (vty, vty->index, prefix_str,
4183 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
4186 DEFUN (bgp_network_mask_natural_backdoor,
4187 bgp_network_mask_natural_backdoor_cmd,
4188 "network A.B.C.D backdoor",
4189 "Specify a network to announce via BGP\n"
4190 "Network number\n"
4191 "Specify a BGP backdoor route\n")
4193 int ret;
4194 char prefix_str[BUFSIZ];
4195 u_char ttl = 0;
4197 if (argc == 2)
4198 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4200 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4201 if (! ret)
4203 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4204 return CMD_WARNING;
4207 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4208 NULL, 1, ttl);
4211 ALIAS (bgp_network_mask_natural_backdoor,
4212 bgp_network_mask_natural_backdoor_ttl_cmd,
4213 "network A.B.C.D backdoor pathlimit (1-255>",
4214 "Specify a network to announce via BGP\n"
4215 "Network number\n"
4216 "Specify a BGP backdoor route\n"
4217 "AS-Path hopcount limit attribute\n"
4218 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4220 DEFUN (no_bgp_network,
4221 no_bgp_network_cmd,
4222 "no network A.B.C.D/M",
4223 NO_STR
4224 "Specify a network to announce via BGP\n"
4225 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4227 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4228 bgp_node_safi (vty));
4231 ALIAS (no_bgp_network,
4232 no_bgp_network_ttl_cmd,
4233 "no network A.B.C.D/M pathlimit <0-255>",
4234 NO_STR
4235 "Specify a network to announce via BGP\n"
4236 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4237 "AS-Path hopcount limit attribute\n"
4238 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4240 ALIAS (no_bgp_network,
4241 no_bgp_network_route_map_cmd,
4242 "no network A.B.C.D/M route-map WORD",
4243 NO_STR
4244 "Specify a network to announce via BGP\n"
4245 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4246 "Route-map to modify the attributes\n"
4247 "Name of the route map\n")
4249 ALIAS (no_bgp_network,
4250 no_bgp_network_backdoor_cmd,
4251 "no network A.B.C.D/M backdoor",
4252 NO_STR
4253 "Specify a network to announce via BGP\n"
4254 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4255 "Specify a BGP backdoor route\n")
4257 ALIAS (no_bgp_network,
4258 no_bgp_network_backdoor_ttl_cmd,
4259 "no network A.B.C.D/M backdoor pathlimit <0-255>",
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"
4264 "AS-Path hopcount limit attribute\n"
4265 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4267 DEFUN (no_bgp_network_mask,
4268 no_bgp_network_mask_cmd,
4269 "no network A.B.C.D mask A.B.C.D",
4270 NO_STR
4271 "Specify a network to announce via BGP\n"
4272 "Network number\n"
4273 "Network mask\n"
4274 "Network mask\n")
4276 int ret;
4277 char prefix_str[BUFSIZ];
4279 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4280 if (! ret)
4282 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4283 return CMD_WARNING;
4286 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4287 bgp_node_safi (vty));
4290 ALIAS (no_bgp_network,
4291 no_bgp_network_mask_ttl_cmd,
4292 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4293 NO_STR
4294 "Specify a network to announce via BGP\n"
4295 "Network number\n"
4296 "Network mask\n"
4297 "Network mask\n"
4298 "AS-Path hopcount limit attribute\n"
4299 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4301 ALIAS (no_bgp_network_mask,
4302 no_bgp_network_mask_route_map_cmd,
4303 "no network A.B.C.D mask A.B.C.D route-map WORD",
4304 NO_STR
4305 "Specify a network to announce via BGP\n"
4306 "Network number\n"
4307 "Network mask\n"
4308 "Network mask\n"
4309 "Route-map to modify the attributes\n"
4310 "Name of the route map\n")
4312 ALIAS (no_bgp_network_mask,
4313 no_bgp_network_mask_backdoor_cmd,
4314 "no network A.B.C.D mask A.B.C.D backdoor",
4315 NO_STR
4316 "Specify a network to announce via BGP\n"
4317 "Network number\n"
4318 "Network mask\n"
4319 "Network mask\n"
4320 "Specify a BGP backdoor route\n")
4322 ALIAS (no_bgp_network_mask,
4323 no_bgp_network_mask_backdoor_ttl_cmd,
4324 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4325 NO_STR
4326 "Specify a network to announce via BGP\n"
4327 "Network number\n"
4328 "Network mask\n"
4329 "Network mask\n"
4330 "Specify a BGP backdoor route\n"
4331 "AS-Path hopcount limit attribute\n"
4332 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4334 DEFUN (no_bgp_network_mask_natural,
4335 no_bgp_network_mask_natural_cmd,
4336 "no network A.B.C.D",
4337 NO_STR
4338 "Specify a network to announce via BGP\n"
4339 "Network number\n")
4341 int ret;
4342 char prefix_str[BUFSIZ];
4344 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4345 if (! ret)
4347 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4348 return CMD_WARNING;
4351 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4352 bgp_node_safi (vty));
4355 ALIAS (no_bgp_network_mask_natural,
4356 no_bgp_network_mask_natural_route_map_cmd,
4357 "no network A.B.C.D route-map WORD",
4358 NO_STR
4359 "Specify a network to announce via BGP\n"
4360 "Network number\n"
4361 "Route-map to modify the attributes\n"
4362 "Name of the route map\n")
4364 ALIAS (no_bgp_network_mask_natural,
4365 no_bgp_network_mask_natural_backdoor_cmd,
4366 "no network A.B.C.D backdoor",
4367 NO_STR
4368 "Specify a network to announce via BGP\n"
4369 "Network number\n"
4370 "Specify a BGP backdoor route\n")
4372 ALIAS (no_bgp_network_mask_natural,
4373 no_bgp_network_mask_natural_ttl_cmd,
4374 "no network A.B.C.D pathlimit <0-255>",
4375 NO_STR
4376 "Specify a network to announce via BGP\n"
4377 "Network number\n"
4378 "AS-Path hopcount limit attribute\n"
4379 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4381 ALIAS (no_bgp_network_mask_natural,
4382 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4383 "no network A.B.C.D backdoor pathlimit <0-255>",
4384 NO_STR
4385 "Specify a network to announce via BGP\n"
4386 "Network number\n"
4387 "Specify a BGP backdoor route\n"
4388 "AS-Path hopcount limit attribute\n"
4389 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4391 #ifdef HAVE_IPV6
4392 DEFUN (ipv6_bgp_network,
4393 ipv6_bgp_network_cmd,
4394 "network X:X::X:X/M",
4395 "Specify a network to announce via BGP\n"
4396 "IPv6 prefix <network>/<length>\n")
4398 u_char ttl = 0;
4400 if (argc == 2)
4401 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4403 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
4404 NULL, 0, ttl);
4407 ALIAS (ipv6_bgp_network,
4408 ipv6_bgp_network_ttl_cmd,
4409 "network X:X::X:X/M pathlimit <0-255>",
4410 "Specify a network to announce via BGP\n"
4411 "IPv6 prefix <network>/<length>\n"
4412 "AS-Path hopcount limit attribute\n"
4413 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4415 DEFUN (ipv6_bgp_network_route_map,
4416 ipv6_bgp_network_route_map_cmd,
4417 "network X:X::X:X/M route-map WORD",
4418 "Specify a network to announce via BGP\n"
4419 "IPv6 prefix <network>/<length>\n"
4420 "Route-map to modify the attributes\n"
4421 "Name of the route map\n")
4423 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4424 bgp_node_safi (vty), argv[1], 0, 0);
4427 DEFUN (no_ipv6_bgp_network,
4428 no_ipv6_bgp_network_cmd,
4429 "no network X:X::X:X/M",
4430 NO_STR
4431 "Specify a network to announce via BGP\n"
4432 "IPv6 prefix <network>/<length>\n")
4434 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4437 ALIAS (no_ipv6_bgp_network,
4438 no_ipv6_bgp_network_route_map_cmd,
4439 "no network X:X::X:X/M route-map WORD",
4440 NO_STR
4441 "Specify a network to announce via BGP\n"
4442 "IPv6 prefix <network>/<length>\n"
4443 "Route-map to modify the attributes\n"
4444 "Name of the route map\n")
4446 ALIAS (no_ipv6_bgp_network,
4447 no_ipv6_bgp_network_ttl_cmd,
4448 "no network X:X::X:X/M pathlimit <0-255>",
4449 NO_STR
4450 "Specify a network to announce via BGP\n"
4451 "IPv6 prefix <network>/<length>\n"
4452 "AS-Path hopcount limit attribute\n"
4453 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4455 ALIAS (ipv6_bgp_network,
4456 old_ipv6_bgp_network_cmd,
4457 "ipv6 bgp network X:X::X:X/M",
4458 IPV6_STR
4459 BGP_STR
4460 "Specify a network to announce via BGP\n"
4461 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4463 ALIAS (no_ipv6_bgp_network,
4464 old_no_ipv6_bgp_network_cmd,
4465 "no ipv6 bgp network X:X::X:X/M",
4466 NO_STR
4467 IPV6_STR
4468 BGP_STR
4469 "Specify a network to announce via BGP\n"
4470 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4471 #endif /* HAVE_IPV6 */
4473 /* Aggreagete address:
4475 advertise-map Set condition to advertise attribute
4476 as-set Generate AS set path information
4477 attribute-map Set attributes of aggregate
4478 route-map Set parameters of aggregate
4479 summary-only Filter more specific routes from updates
4480 suppress-map Conditionally filter more specific routes from updates
4481 <cr>
4483 struct bgp_aggregate
4485 /* Summary-only flag. */
4486 u_char summary_only;
4488 /* AS set generation. */
4489 u_char as_set;
4491 /* Route-map for aggregated route. */
4492 struct route_map *map;
4494 /* Suppress-count. */
4495 unsigned long count;
4497 /* SAFI configuration. */
4498 safi_t safi;
4501 static struct bgp_aggregate *
4502 bgp_aggregate_new (void)
4504 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4507 static void
4508 bgp_aggregate_free (struct bgp_aggregate *aggregate)
4510 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4513 static void
4514 bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4515 afi_t afi, safi_t safi, struct bgp_info *del,
4516 struct bgp_aggregate *aggregate)
4518 struct bgp_table *table;
4519 struct bgp_node *top;
4520 struct bgp_node *rn;
4521 u_char origin;
4522 struct aspath *aspath = NULL;
4523 struct aspath *asmerge = NULL;
4524 struct community *community = NULL;
4525 struct community *commerge = NULL;
4526 struct in_addr nexthop;
4527 u_int32_t med = 0;
4528 struct bgp_info *ri;
4529 struct bgp_info *new;
4530 int first = 1;
4531 unsigned long match = 0;
4533 /* Record adding route's nexthop and med. */
4534 if (rinew)
4536 nexthop = rinew->attr->nexthop;
4537 med = rinew->attr->med;
4540 /* ORIGIN attribute: If at least one route among routes that are
4541 aggregated has ORIGIN with the value INCOMPLETE, then the
4542 aggregated route must have the ORIGIN attribute with the value
4543 INCOMPLETE. Otherwise, if at least one route among routes that
4544 are aggregated has ORIGIN with the value EGP, then the aggregated
4545 route must have the origin attribute with the value EGP. In all
4546 other case the value of the ORIGIN attribute of the aggregated
4547 route is INTERNAL. */
4548 origin = BGP_ORIGIN_IGP;
4550 table = bgp->rib[afi][safi];
4552 top = bgp_node_get (table, p);
4553 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4554 if (rn->p.prefixlen > p->prefixlen)
4556 match = 0;
4558 for (ri = rn->info; ri; ri = ri->next)
4560 if (BGP_INFO_HOLDDOWN (ri))
4561 continue;
4563 if (del && ri == del)
4564 continue;
4566 if (! rinew && first)
4568 nexthop = ri->attr->nexthop;
4569 med = ri->attr->med;
4570 first = 0;
4573 #ifdef AGGREGATE_NEXTHOP_CHECK
4574 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4575 || ri->attr->med != med)
4577 if (aspath)
4578 aspath_free (aspath);
4579 if (community)
4580 community_free (community);
4581 bgp_unlock_node (rn);
4582 bgp_unlock_node (top);
4583 return;
4585 #endif /* AGGREGATE_NEXTHOP_CHECK */
4587 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4589 if (aggregate->summary_only)
4591 (bgp_info_extra_get (ri))->suppress++;
4592 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4593 match++;
4596 aggregate->count++;
4598 if (aggregate->as_set)
4600 if (origin < ri->attr->origin)
4601 origin = ri->attr->origin;
4603 if (aspath)
4605 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4606 aspath_free (aspath);
4607 aspath = asmerge;
4609 else
4610 aspath = aspath_dup (ri->attr->aspath);
4612 if (ri->attr->community)
4614 if (community)
4616 commerge = community_merge (community,
4617 ri->attr->community);
4618 community = community_uniq_sort (commerge);
4619 community_free (commerge);
4621 else
4622 community = community_dup (ri->attr->community);
4627 if (match)
4628 bgp_process (bgp, rn, afi, safi);
4630 bgp_unlock_node (top);
4632 if (rinew)
4634 aggregate->count++;
4636 if (aggregate->summary_only)
4637 (bgp_info_extra_get (rinew))->suppress++;
4639 if (aggregate->as_set)
4641 if (origin < rinew->attr->origin)
4642 origin = rinew->attr->origin;
4644 if (aspath)
4646 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4647 aspath_free (aspath);
4648 aspath = asmerge;
4650 else
4651 aspath = aspath_dup (rinew->attr->aspath);
4653 if (rinew->attr->community)
4655 if (community)
4657 commerge = community_merge (community,
4658 rinew->attr->community);
4659 community = community_uniq_sort (commerge);
4660 community_free (commerge);
4662 else
4663 community = community_dup (rinew->attr->community);
4668 if (aggregate->count > 0)
4670 rn = bgp_node_get (table, p);
4671 new = bgp_info_new ();
4672 new->type = ZEBRA_ROUTE_BGP;
4673 new->sub_type = BGP_ROUTE_AGGREGATE;
4674 new->peer = bgp->peer_self;
4675 SET_FLAG (new->flags, BGP_INFO_VALID);
4676 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4677 new->uptime = time (NULL);
4679 bgp_info_add (rn, new);
4680 bgp_unlock_node (rn);
4681 bgp_process (bgp, rn, afi, safi);
4683 else
4685 if (aspath)
4686 aspath_free (aspath);
4687 if (community)
4688 community_free (community);
4692 void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4693 struct bgp_aggregate *);
4695 void
4696 bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4697 struct bgp_info *ri, afi_t afi, safi_t safi)
4699 struct bgp_node *child;
4700 struct bgp_node *rn;
4701 struct bgp_aggregate *aggregate;
4703 /* MPLS-VPN aggregation is not yet supported. */
4704 if (safi == SAFI_MPLS_VPN)
4705 return;
4707 if (p->prefixlen == 0)
4708 return;
4710 if (BGP_INFO_HOLDDOWN (ri))
4711 return;
4713 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4715 /* Aggregate address configuration check. */
4716 for (rn = child; rn; rn = rn->parent)
4717 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4719 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4720 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
4722 bgp_unlock_node (child);
4725 void
4726 bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4727 struct bgp_info *del, afi_t afi, safi_t safi)
4729 struct bgp_node *child;
4730 struct bgp_node *rn;
4731 struct bgp_aggregate *aggregate;
4733 /* MPLS-VPN aggregation is not yet supported. */
4734 if (safi == SAFI_MPLS_VPN)
4735 return;
4737 if (p->prefixlen == 0)
4738 return;
4740 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4742 /* Aggregate address configuration check. */
4743 for (rn = child; rn; rn = rn->parent)
4744 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4746 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
4747 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
4749 bgp_unlock_node (child);
4752 static void
4753 bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4754 struct bgp_aggregate *aggregate)
4756 struct bgp_table *table;
4757 struct bgp_node *top;
4758 struct bgp_node *rn;
4759 struct bgp_info *new;
4760 struct bgp_info *ri;
4761 unsigned long match;
4762 u_char origin = BGP_ORIGIN_IGP;
4763 struct aspath *aspath = NULL;
4764 struct aspath *asmerge = NULL;
4765 struct community *community = NULL;
4766 struct community *commerge = NULL;
4768 table = bgp->rib[afi][safi];
4770 /* Sanity check. */
4771 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4772 return;
4773 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4774 return;
4776 /* If routes exists below this node, generate aggregate routes. */
4777 top = bgp_node_get (table, p);
4778 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4779 if (rn->p.prefixlen > p->prefixlen)
4781 match = 0;
4783 for (ri = rn->info; ri; ri = ri->next)
4785 if (BGP_INFO_HOLDDOWN (ri))
4786 continue;
4788 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4790 /* summary-only aggregate route suppress aggregated
4791 route announcement. */
4792 if (aggregate->summary_only)
4794 (bgp_info_extra_get (ri))->suppress++;
4795 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4796 match++;
4798 /* as-set aggregate route generate origin, as path,
4799 community aggregation. */
4800 if (aggregate->as_set)
4802 if (origin < ri->attr->origin)
4803 origin = ri->attr->origin;
4805 if (aspath)
4807 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4808 aspath_free (aspath);
4809 aspath = asmerge;
4811 else
4812 aspath = aspath_dup (ri->attr->aspath);
4814 if (ri->attr->community)
4816 if (community)
4818 commerge = community_merge (community,
4819 ri->attr->community);
4820 community = community_uniq_sort (commerge);
4821 community_free (commerge);
4823 else
4824 community = community_dup (ri->attr->community);
4827 aggregate->count++;
4831 /* If this node is suppressed, process the change. */
4832 if (match)
4833 bgp_process (bgp, rn, afi, safi);
4835 bgp_unlock_node (top);
4837 /* Add aggregate route to BGP table. */
4838 if (aggregate->count)
4840 rn = bgp_node_get (table, p);
4842 new = bgp_info_new ();
4843 new->type = ZEBRA_ROUTE_BGP;
4844 new->sub_type = BGP_ROUTE_AGGREGATE;
4845 new->peer = bgp->peer_self;
4846 SET_FLAG (new->flags, BGP_INFO_VALID);
4847 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4848 new->uptime = time (NULL);
4850 bgp_info_add (rn, new);
4851 bgp_unlock_node (rn);
4853 /* Process change. */
4854 bgp_process (bgp, rn, afi, safi);
4858 void
4859 bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4860 safi_t safi, struct bgp_aggregate *aggregate)
4862 struct bgp_table *table;
4863 struct bgp_node *top;
4864 struct bgp_node *rn;
4865 struct bgp_info *ri;
4866 unsigned long match;
4868 table = bgp->rib[afi][safi];
4870 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4871 return;
4872 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4873 return;
4875 /* If routes exists below this node, generate aggregate routes. */
4876 top = bgp_node_get (table, p);
4877 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4878 if (rn->p.prefixlen > p->prefixlen)
4880 match = 0;
4882 for (ri = rn->info; ri; ri = ri->next)
4884 if (BGP_INFO_HOLDDOWN (ri))
4885 continue;
4887 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4889 if (aggregate->summary_only && ri->extra)
4891 ri->extra->suppress--;
4893 if (ri->extra->suppress == 0)
4895 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
4896 match++;
4899 aggregate->count--;
4903 /* If this node was suppressed, process the change. */
4904 if (match)
4905 bgp_process (bgp, rn, afi, safi);
4907 bgp_unlock_node (top);
4909 /* Delete aggregate route from BGP table. */
4910 rn = bgp_node_get (table, p);
4912 for (ri = rn->info; ri; ri = ri->next)
4913 if (ri->peer == bgp->peer_self
4914 && ri->type == ZEBRA_ROUTE_BGP
4915 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4916 break;
4918 /* Withdraw static BGP route from routing table. */
4919 if (ri)
4921 bgp_info_delete (rn, ri);
4922 bgp_process (bgp, rn, afi, safi);
4925 /* Unlock bgp_node_lookup. */
4926 bgp_unlock_node (rn);
4929 /* Aggregate route attribute. */
4930 #define AGGREGATE_SUMMARY_ONLY 1
4931 #define AGGREGATE_AS_SET 1
4933 static int
4934 bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4935 afi_t afi, safi_t safi,
4936 u_char summary_only, u_char as_set)
4938 int ret;
4939 struct prefix p;
4940 struct bgp_node *rn;
4941 struct bgp *bgp;
4942 struct bgp_aggregate *aggregate;
4944 /* Convert string to prefix structure. */
4945 ret = str2prefix (prefix_str, &p);
4946 if (!ret)
4948 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4949 return CMD_WARNING;
4951 apply_mask (&p);
4953 /* Get BGP structure. */
4954 bgp = vty->index;
4956 /* Old configuration check. */
4957 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4959 if (rn->info)
4961 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4962 bgp_unlock_node (rn);
4963 return CMD_WARNING;
4966 /* Make aggregate address structure. */
4967 aggregate = bgp_aggregate_new ();
4968 aggregate->summary_only = summary_only;
4969 aggregate->as_set = as_set;
4970 aggregate->safi = safi;
4971 rn->info = aggregate;
4973 /* Aggregate address insert into BGP routing table. */
4974 if (safi & SAFI_UNICAST)
4975 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4976 if (safi & SAFI_MULTICAST)
4977 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4979 return CMD_SUCCESS;
4982 static int
4983 bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4984 afi_t afi, safi_t safi)
4986 int ret;
4987 struct prefix p;
4988 struct bgp_node *rn;
4989 struct bgp *bgp;
4990 struct bgp_aggregate *aggregate;
4992 /* Convert string to prefix structure. */
4993 ret = str2prefix (prefix_str, &p);
4994 if (!ret)
4996 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4997 return CMD_WARNING;
4999 apply_mask (&p);
5001 /* Get BGP structure. */
5002 bgp = vty->index;
5004 /* Old configuration check. */
5005 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5006 if (! rn)
5008 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5009 VTY_NEWLINE);
5010 return CMD_WARNING;
5013 aggregate = rn->info;
5014 if (aggregate->safi & SAFI_UNICAST)
5015 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5016 if (aggregate->safi & SAFI_MULTICAST)
5017 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5019 /* Unlock aggregate address configuration. */
5020 rn->info = NULL;
5021 bgp_aggregate_free (aggregate);
5022 bgp_unlock_node (rn);
5023 bgp_unlock_node (rn);
5025 return CMD_SUCCESS;
5028 DEFUN (aggregate_address,
5029 aggregate_address_cmd,
5030 "aggregate-address A.B.C.D/M",
5031 "Configure BGP aggregate entries\n"
5032 "Aggregate prefix\n")
5034 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5037 DEFUN (aggregate_address_mask,
5038 aggregate_address_mask_cmd,
5039 "aggregate-address A.B.C.D A.B.C.D",
5040 "Configure BGP aggregate entries\n"
5041 "Aggregate address\n"
5042 "Aggregate mask\n")
5044 int ret;
5045 char prefix_str[BUFSIZ];
5047 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5049 if (! ret)
5051 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5052 return CMD_WARNING;
5055 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5056 0, 0);
5059 DEFUN (aggregate_address_summary_only,
5060 aggregate_address_summary_only_cmd,
5061 "aggregate-address A.B.C.D/M summary-only",
5062 "Configure BGP aggregate entries\n"
5063 "Aggregate prefix\n"
5064 "Filter more specific routes from updates\n")
5066 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5067 AGGREGATE_SUMMARY_ONLY, 0);
5070 DEFUN (aggregate_address_mask_summary_only,
5071 aggregate_address_mask_summary_only_cmd,
5072 "aggregate-address A.B.C.D A.B.C.D summary-only",
5073 "Configure BGP aggregate entries\n"
5074 "Aggregate address\n"
5075 "Aggregate mask\n"
5076 "Filter more specific routes from updates\n")
5078 int ret;
5079 char prefix_str[BUFSIZ];
5081 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5083 if (! ret)
5085 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5086 return CMD_WARNING;
5089 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5090 AGGREGATE_SUMMARY_ONLY, 0);
5093 DEFUN (aggregate_address_as_set,
5094 aggregate_address_as_set_cmd,
5095 "aggregate-address A.B.C.D/M as-set",
5096 "Configure BGP aggregate entries\n"
5097 "Aggregate prefix\n"
5098 "Generate AS set path information\n")
5100 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5101 0, AGGREGATE_AS_SET);
5104 DEFUN (aggregate_address_mask_as_set,
5105 aggregate_address_mask_as_set_cmd,
5106 "aggregate-address A.B.C.D A.B.C.D as-set",
5107 "Configure BGP aggregate entries\n"
5108 "Aggregate address\n"
5109 "Aggregate mask\n"
5110 "Generate AS set path information\n")
5112 int ret;
5113 char prefix_str[BUFSIZ];
5115 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5117 if (! ret)
5119 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5120 return CMD_WARNING;
5123 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5124 0, AGGREGATE_AS_SET);
5128 DEFUN (aggregate_address_as_set_summary,
5129 aggregate_address_as_set_summary_cmd,
5130 "aggregate-address A.B.C.D/M as-set summary-only",
5131 "Configure BGP aggregate entries\n"
5132 "Aggregate prefix\n"
5133 "Generate AS set path information\n"
5134 "Filter more specific routes from updates\n")
5136 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5137 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5140 ALIAS (aggregate_address_as_set_summary,
5141 aggregate_address_summary_as_set_cmd,
5142 "aggregate-address A.B.C.D/M summary-only as-set",
5143 "Configure BGP aggregate entries\n"
5144 "Aggregate prefix\n"
5145 "Filter more specific routes from updates\n"
5146 "Generate AS set path information\n")
5148 DEFUN (aggregate_address_mask_as_set_summary,
5149 aggregate_address_mask_as_set_summary_cmd,
5150 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5151 "Configure BGP aggregate entries\n"
5152 "Aggregate address\n"
5153 "Aggregate mask\n"
5154 "Generate AS set path information\n"
5155 "Filter more specific routes from updates\n")
5157 int ret;
5158 char prefix_str[BUFSIZ];
5160 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5162 if (! ret)
5164 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5165 return CMD_WARNING;
5168 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5169 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5172 ALIAS (aggregate_address_mask_as_set_summary,
5173 aggregate_address_mask_summary_as_set_cmd,
5174 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5175 "Configure BGP aggregate entries\n"
5176 "Aggregate address\n"
5177 "Aggregate mask\n"
5178 "Filter more specific routes from updates\n"
5179 "Generate AS set path information\n")
5181 DEFUN (no_aggregate_address,
5182 no_aggregate_address_cmd,
5183 "no aggregate-address A.B.C.D/M",
5184 NO_STR
5185 "Configure BGP aggregate entries\n"
5186 "Aggregate prefix\n")
5188 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5191 ALIAS (no_aggregate_address,
5192 no_aggregate_address_summary_only_cmd,
5193 "no aggregate-address A.B.C.D/M summary-only",
5194 NO_STR
5195 "Configure BGP aggregate entries\n"
5196 "Aggregate prefix\n"
5197 "Filter more specific routes from updates\n")
5199 ALIAS (no_aggregate_address,
5200 no_aggregate_address_as_set_cmd,
5201 "no aggregate-address A.B.C.D/M as-set",
5202 NO_STR
5203 "Configure BGP aggregate entries\n"
5204 "Aggregate prefix\n"
5205 "Generate AS set path information\n")
5207 ALIAS (no_aggregate_address,
5208 no_aggregate_address_as_set_summary_cmd,
5209 "no aggregate-address A.B.C.D/M as-set summary-only",
5210 NO_STR
5211 "Configure BGP aggregate entries\n"
5212 "Aggregate prefix\n"
5213 "Generate AS set path information\n"
5214 "Filter more specific routes from updates\n")
5216 ALIAS (no_aggregate_address,
5217 no_aggregate_address_summary_as_set_cmd,
5218 "no aggregate-address A.B.C.D/M summary-only as-set",
5219 NO_STR
5220 "Configure BGP aggregate entries\n"
5221 "Aggregate prefix\n"
5222 "Filter more specific routes from updates\n"
5223 "Generate AS set path information\n")
5225 DEFUN (no_aggregate_address_mask,
5226 no_aggregate_address_mask_cmd,
5227 "no aggregate-address A.B.C.D A.B.C.D",
5228 NO_STR
5229 "Configure BGP aggregate entries\n"
5230 "Aggregate address\n"
5231 "Aggregate mask\n")
5233 int ret;
5234 char prefix_str[BUFSIZ];
5236 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5238 if (! ret)
5240 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5241 return CMD_WARNING;
5244 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5247 ALIAS (no_aggregate_address_mask,
5248 no_aggregate_address_mask_summary_only_cmd,
5249 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5250 NO_STR
5251 "Configure BGP aggregate entries\n"
5252 "Aggregate address\n"
5253 "Aggregate mask\n"
5254 "Filter more specific routes from updates\n")
5256 ALIAS (no_aggregate_address_mask,
5257 no_aggregate_address_mask_as_set_cmd,
5258 "no aggregate-address A.B.C.D A.B.C.D as-set",
5259 NO_STR
5260 "Configure BGP aggregate entries\n"
5261 "Aggregate address\n"
5262 "Aggregate mask\n"
5263 "Generate AS set path information\n")
5265 ALIAS (no_aggregate_address_mask,
5266 no_aggregate_address_mask_as_set_summary_cmd,
5267 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5268 NO_STR
5269 "Configure BGP aggregate entries\n"
5270 "Aggregate address\n"
5271 "Aggregate mask\n"
5272 "Generate AS set path information\n"
5273 "Filter more specific routes from updates\n")
5275 ALIAS (no_aggregate_address_mask,
5276 no_aggregate_address_mask_summary_as_set_cmd,
5277 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5278 NO_STR
5279 "Configure BGP aggregate entries\n"
5280 "Aggregate address\n"
5281 "Aggregate mask\n"
5282 "Filter more specific routes from updates\n"
5283 "Generate AS set path information\n")
5285 #ifdef HAVE_IPV6
5286 DEFUN (ipv6_aggregate_address,
5287 ipv6_aggregate_address_cmd,
5288 "aggregate-address X:X::X:X/M",
5289 "Configure BGP aggregate entries\n"
5290 "Aggregate prefix\n")
5292 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5295 DEFUN (ipv6_aggregate_address_summary_only,
5296 ipv6_aggregate_address_summary_only_cmd,
5297 "aggregate-address X:X::X:X/M summary-only",
5298 "Configure BGP aggregate entries\n"
5299 "Aggregate prefix\n"
5300 "Filter more specific routes from updates\n")
5302 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5303 AGGREGATE_SUMMARY_ONLY, 0);
5306 DEFUN (no_ipv6_aggregate_address,
5307 no_ipv6_aggregate_address_cmd,
5308 "no aggregate-address X:X::X:X/M",
5309 NO_STR
5310 "Configure BGP aggregate entries\n"
5311 "Aggregate prefix\n")
5313 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5316 DEFUN (no_ipv6_aggregate_address_summary_only,
5317 no_ipv6_aggregate_address_summary_only_cmd,
5318 "no aggregate-address X:X::X:X/M summary-only",
5319 NO_STR
5320 "Configure BGP aggregate entries\n"
5321 "Aggregate prefix\n"
5322 "Filter more specific routes from updates\n")
5324 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5327 ALIAS (ipv6_aggregate_address,
5328 old_ipv6_aggregate_address_cmd,
5329 "ipv6 bgp aggregate-address X:X::X:X/M",
5330 IPV6_STR
5331 BGP_STR
5332 "Configure BGP aggregate entries\n"
5333 "Aggregate prefix\n")
5335 ALIAS (ipv6_aggregate_address_summary_only,
5336 old_ipv6_aggregate_address_summary_only_cmd,
5337 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5338 IPV6_STR
5339 BGP_STR
5340 "Configure BGP aggregate entries\n"
5341 "Aggregate prefix\n"
5342 "Filter more specific routes from updates\n")
5344 ALIAS (no_ipv6_aggregate_address,
5345 old_no_ipv6_aggregate_address_cmd,
5346 "no ipv6 bgp aggregate-address X:X::X:X/M",
5347 NO_STR
5348 IPV6_STR
5349 BGP_STR
5350 "Configure BGP aggregate entries\n"
5351 "Aggregate prefix\n")
5353 ALIAS (no_ipv6_aggregate_address_summary_only,
5354 old_no_ipv6_aggregate_address_summary_only_cmd,
5355 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5356 NO_STR
5357 IPV6_STR
5358 BGP_STR
5359 "Configure BGP aggregate entries\n"
5360 "Aggregate prefix\n"
5361 "Filter more specific routes from updates\n")
5362 #endif /* HAVE_IPV6 */
5364 /* Redistribute route treatment. */
5365 void
5366 bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5367 u_int32_t metric, u_char type)
5369 struct bgp *bgp;
5370 struct listnode *node, *nnode;
5371 struct bgp_info *new;
5372 struct bgp_info *bi;
5373 struct bgp_info info;
5374 struct bgp_node *bn;
5375 struct attr attr = { 0 };
5376 struct attr attr_new = { 0 };
5377 struct attr *new_attr;
5378 afi_t afi;
5379 int ret;
5381 /* Make default attribute. */
5382 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5383 if (nexthop)
5384 attr.nexthop = *nexthop;
5386 attr.med = metric;
5387 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5389 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5391 afi = family2afi (p->family);
5393 if (bgp->redist[afi][type])
5395 /* Copy attribute for modification. */
5396 bgp_attr_dup (&attr_new, &attr);
5398 if (bgp->redist_metric_flag[afi][type])
5399 attr_new.med = bgp->redist_metric[afi][type];
5401 /* Apply route-map. */
5402 if (bgp->rmap[afi][type].map)
5404 info.peer = bgp->peer_self;
5405 info.attr = &attr_new;
5407 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5409 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5410 &info);
5412 bgp->peer_self->rmap_type = 0;
5414 if (ret == RMAP_DENYMATCH)
5416 /* Free uninterned attribute. */
5417 bgp_attr_flush (&attr_new);
5418 bgp_attr_extra_free (&attr_new);
5420 /* Unintern original. */
5421 aspath_unintern (attr.aspath);
5422 bgp_attr_extra_free (&attr);
5423 bgp_redistribute_delete (p, type);
5424 return;
5428 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5429 afi, SAFI_UNICAST, p, NULL);
5431 new_attr = bgp_attr_intern (&attr_new);
5432 bgp_attr_extra_free (&attr_new);
5434 for (bi = bn->info; bi; bi = bi->next)
5435 if (bi->peer == bgp->peer_self
5436 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5437 break;
5439 if (bi)
5441 if (attrhash_cmp (bi->attr, new_attr) &&
5442 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5444 bgp_attr_unintern (new_attr);
5445 aspath_unintern (attr.aspath);
5446 bgp_attr_extra_free (&attr);
5447 bgp_unlock_node (bn);
5448 return;
5450 else
5452 /* The attribute is changed. */
5453 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
5455 /* Rewrite BGP route information. */
5456 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5457 bgp_info_restore(bn, bi);
5458 else
5459 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
5460 bgp_attr_unintern (bi->attr);
5461 bi->attr = new_attr;
5462 bi->uptime = time (NULL);
5464 /* Process change. */
5465 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5466 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5467 bgp_unlock_node (bn);
5468 aspath_unintern (attr.aspath);
5469 bgp_attr_extra_free (&attr);
5470 return;
5474 new = bgp_info_new ();
5475 new->type = type;
5476 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5477 new->peer = bgp->peer_self;
5478 SET_FLAG (new->flags, BGP_INFO_VALID);
5479 new->attr = new_attr;
5480 new->uptime = time (NULL);
5482 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5483 bgp_info_add (bn, new);
5484 bgp_unlock_node (bn);
5485 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5489 /* Unintern original. */
5490 aspath_unintern (attr.aspath);
5491 bgp_attr_extra_free (&attr);
5494 void
5495 bgp_redistribute_delete (struct prefix *p, u_char type)
5497 struct bgp *bgp;
5498 struct listnode *node, *nnode;
5499 afi_t afi;
5500 struct bgp_node *rn;
5501 struct bgp_info *ri;
5503 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
5505 afi = family2afi (p->family);
5507 if (bgp->redist[afi][type])
5509 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
5511 for (ri = rn->info; ri; ri = ri->next)
5512 if (ri->peer == bgp->peer_self
5513 && ri->type == type)
5514 break;
5516 if (ri)
5518 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
5519 bgp_info_delete (rn, ri);
5520 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5522 bgp_unlock_node (rn);
5527 /* Withdraw specified route type's route. */
5528 void
5529 bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5531 struct bgp_node *rn;
5532 struct bgp_info *ri;
5533 struct bgp_table *table;
5535 table = bgp->rib[afi][SAFI_UNICAST];
5537 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5539 for (ri = rn->info; ri; ri = ri->next)
5540 if (ri->peer == bgp->peer_self
5541 && ri->type == type)
5542 break;
5544 if (ri)
5546 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5547 bgp_info_delete (rn, ri);
5548 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5553 /* Static function to display route. */
5554 static void
5555 route_vty_out_route (struct prefix *p, struct vty *vty)
5557 int len;
5558 u_int32_t destination;
5559 char buf[BUFSIZ];
5561 if (p->family == AF_INET)
5563 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5564 destination = ntohl (p->u.prefix4.s_addr);
5566 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5567 || (IN_CLASSB (destination) && p->prefixlen == 16)
5568 || (IN_CLASSA (destination) && p->prefixlen == 8)
5569 || p->u.prefix4.s_addr == 0)
5571 /* When mask is natural, mask is not displayed. */
5573 else
5574 len += vty_out (vty, "/%d", p->prefixlen);
5576 else
5577 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5578 p->prefixlen);
5580 len = 17 - len;
5581 if (len < 1)
5582 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5583 else
5584 vty_out (vty, "%*s", len, " ");
5587 enum bgp_display_type
5589 normal_list,
5592 /* Print the short form route status for a bgp_info */
5593 static void
5594 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
5596 /* Route status display. */
5597 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5598 vty_out (vty, "R");
5599 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5600 vty_out (vty, "S");
5601 else if (binfo->extra && binfo->extra->suppress)
5602 vty_out (vty, "s");
5603 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5604 vty_out (vty, "*");
5605 else
5606 vty_out (vty, " ");
5608 /* Selected */
5609 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5610 vty_out (vty, "h");
5611 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5612 vty_out (vty, "d");
5613 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5614 vty_out (vty, ">");
5615 else
5616 vty_out (vty, " ");
5618 /* Internal route. */
5619 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5620 vty_out (vty, "i");
5621 else
5622 vty_out (vty, " ");
5625 /* called from terminal list command */
5626 void
5627 route_vty_out (struct vty *vty, struct prefix *p,
5628 struct bgp_info *binfo, int display, safi_t safi)
5630 struct attr *attr;
5632 /* short status lead text */
5633 route_vty_short_status_out (vty, binfo);
5635 /* print prefix and mask */
5636 if (! display)
5637 route_vty_out_route (p, vty);
5638 else
5639 vty_out (vty, "%*s", 17, " ");
5641 /* Print attribute */
5642 attr = binfo->attr;
5643 if (attr)
5645 if (p->family == AF_INET)
5647 if (safi == SAFI_MPLS_VPN)
5648 vty_out (vty, "%-16s",
5649 inet_ntoa (attr->extra->mp_nexthop_global_in));
5650 else
5651 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5653 #ifdef HAVE_IPV6
5654 else if (p->family == AF_INET6)
5656 int len;
5657 char buf[BUFSIZ];
5659 len = vty_out (vty, "%s",
5660 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5661 buf, BUFSIZ));
5662 len = 16 - len;
5663 if (len < 1)
5664 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5665 else
5666 vty_out (vty, "%*s", len, " ");
5668 #endif /* HAVE_IPV6 */
5670 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5671 vty_out (vty, "%10d", attr->med);
5672 else
5673 vty_out (vty, " ");
5675 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5676 vty_out (vty, "%7d", attr->local_pref);
5677 else
5678 vty_out (vty, " ");
5680 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
5682 /* Print aspath */
5683 if (attr->aspath)
5684 aspath_print_vty (vty, "%s", attr->aspath, " ");
5686 /* Print origin */
5687 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5689 vty_out (vty, "%s", VTY_NEWLINE);
5692 /* called from terminal list command */
5693 void
5694 route_vty_out_tmp (struct vty *vty, struct prefix *p,
5695 struct attr *attr, safi_t safi)
5697 /* Route status display. */
5698 vty_out (vty, "*");
5699 vty_out (vty, ">");
5700 vty_out (vty, " ");
5702 /* print prefix and mask */
5703 route_vty_out_route (p, vty);
5705 /* Print attribute */
5706 if (attr)
5708 if (p->family == AF_INET)
5710 if (safi == SAFI_MPLS_VPN)
5711 vty_out (vty, "%-16s",
5712 inet_ntoa (attr->extra->mp_nexthop_global_in));
5713 else
5714 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5716 #ifdef HAVE_IPV6
5717 else if (p->family == AF_INET6)
5719 int len;
5720 char buf[BUFSIZ];
5722 assert (attr->extra);
5724 len = vty_out (vty, "%s",
5725 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5726 buf, BUFSIZ));
5727 len = 16 - len;
5728 if (len < 1)
5729 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5730 else
5731 vty_out (vty, "%*s", len, " ");
5733 #endif /* HAVE_IPV6 */
5735 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5736 vty_out (vty, "%10d", attr->med);
5737 else
5738 vty_out (vty, " ");
5740 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5741 vty_out (vty, "%7d", attr->local_pref);
5742 else
5743 vty_out (vty, " ");
5745 vty_out (vty, "%7d ", (attr->extra ? attr->extra->weight : 0));
5747 /* Print aspath */
5748 if (attr->aspath)
5749 aspath_print_vty (vty, "%s", attr->aspath, " ");
5751 /* Print origin */
5752 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5755 vty_out (vty, "%s", VTY_NEWLINE);
5758 void
5759 route_vty_out_tag (struct vty *vty, struct prefix *p,
5760 struct bgp_info *binfo, int display, safi_t safi)
5762 struct attr *attr;
5763 u_int32_t label = 0;
5765 if (!binfo->extra)
5766 return;
5768 /* short status lead text */
5769 route_vty_short_status_out (vty, binfo);
5771 /* print prefix and mask */
5772 if (! display)
5773 route_vty_out_route (p, vty);
5774 else
5775 vty_out (vty, "%*s", 17, " ");
5777 /* Print attribute */
5778 attr = binfo->attr;
5779 if (attr)
5781 if (p->family == AF_INET)
5783 if (safi == SAFI_MPLS_VPN)
5784 vty_out (vty, "%-16s",
5785 inet_ntoa (attr->extra->mp_nexthop_global_in));
5786 else
5787 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5789 #ifdef HAVE_IPV6
5790 else if (p->family == AF_INET6)
5792 assert (attr->extra);
5793 char buf[BUFSIZ];
5794 char buf1[BUFSIZ];
5795 if (attr->extra->mp_nexthop_len == 16)
5796 vty_out (vty, "%s",
5797 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5798 buf, BUFSIZ));
5799 else if (attr->extra->mp_nexthop_len == 32)
5800 vty_out (vty, "%s(%s)",
5801 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5802 buf, BUFSIZ),
5803 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5804 buf1, BUFSIZ));
5807 #endif /* HAVE_IPV6 */
5810 label = decode_label (binfo->extra->tag);
5812 vty_out (vty, "notag/%d", label);
5814 vty_out (vty, "%s", VTY_NEWLINE);
5817 /* dampening route */
5818 static void
5819 damp_route_vty_out (struct vty *vty, struct prefix *p,
5820 struct bgp_info *binfo, int display, safi_t safi)
5822 struct attr *attr;
5823 int len;
5825 /* short status lead text */
5826 route_vty_short_status_out (vty, binfo);
5828 /* print prefix and mask */
5829 if (! display)
5830 route_vty_out_route (p, vty);
5831 else
5832 vty_out (vty, "%*s", 17, " ");
5834 len = vty_out (vty, "%s", binfo->peer->host);
5835 len = 17 - len;
5836 if (len < 1)
5837 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5838 else
5839 vty_out (vty, "%*s", len, " ");
5841 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5843 /* Print attribute */
5844 attr = binfo->attr;
5845 if (attr)
5847 /* Print aspath */
5848 if (attr->aspath)
5849 aspath_print_vty (vty, "%s", attr->aspath, " ");
5851 /* Print origin */
5852 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5854 vty_out (vty, "%s", VTY_NEWLINE);
5857 #define BGP_UPTIME_LEN 25
5859 /* flap route */
5860 static void
5861 flap_route_vty_out (struct vty *vty, struct prefix *p,
5862 struct bgp_info *binfo, int display, safi_t safi)
5864 struct attr *attr;
5865 struct bgp_damp_info *bdi;
5866 char timebuf[BGP_UPTIME_LEN];
5867 int len;
5869 if (!binfo->extra)
5870 return;
5872 bdi = binfo->extra->damp_info;
5874 /* short status lead text */
5875 route_vty_short_status_out (vty, binfo);
5877 /* print prefix and mask */
5878 if (! display)
5879 route_vty_out_route (p, vty);
5880 else
5881 vty_out (vty, "%*s", 17, " ");
5883 len = vty_out (vty, "%s", binfo->peer->host);
5884 len = 16 - len;
5885 if (len < 1)
5886 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5887 else
5888 vty_out (vty, "%*s", len, " ");
5890 len = vty_out (vty, "%d", bdi->flap);
5891 len = 5 - len;
5892 if (len < 1)
5893 vty_out (vty, " ");
5894 else
5895 vty_out (vty, "%*s ", len, " ");
5897 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5898 timebuf, BGP_UPTIME_LEN));
5900 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5901 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5902 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5903 else
5904 vty_out (vty, "%*s ", 8, " ");
5906 /* Print attribute */
5907 attr = binfo->attr;
5908 if (attr)
5910 /* Print aspath */
5911 if (attr->aspath)
5912 aspath_print_vty (vty, "%s", attr->aspath, " ");
5914 /* Print origin */
5915 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5917 vty_out (vty, "%s", VTY_NEWLINE);
5920 static void
5921 route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5922 struct bgp_info *binfo, afi_t afi, safi_t safi)
5924 char buf[INET6_ADDRSTRLEN];
5925 char buf1[BUFSIZ];
5926 struct attr *attr;
5927 int sockunion_vty_out (struct vty *, union sockunion *);
5929 attr = binfo->attr;
5931 if (attr)
5933 /* Line1 display AS-path, Aggregator */
5934 if (attr->aspath)
5936 vty_out (vty, " ");
5937 if (aspath_count_hops (attr->aspath) == 0)
5938 vty_out (vty, "Local");
5939 else
5940 aspath_print_vty (vty, "%s", attr->aspath, "");
5943 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5944 vty_out (vty, ", (removed)");
5945 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5946 vty_out (vty, ", (stale)");
5947 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5948 vty_out (vty, ", (aggregated by %u %s)",
5949 attr->extra->aggregator_as,
5950 inet_ntoa (attr->extra->aggregator_addr));
5951 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5952 vty_out (vty, ", (Received from a RR-client)");
5953 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5954 vty_out (vty, ", (Received from a RS-client)");
5955 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5956 vty_out (vty, ", (history entry)");
5957 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5958 vty_out (vty, ", (suppressed due to dampening)");
5959 vty_out (vty, "%s", VTY_NEWLINE);
5961 /* Line2 display Next-hop, Neighbor, Router-id */
5962 if (p->family == AF_INET)
5964 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5965 inet_ntoa (attr->extra->mp_nexthop_global_in) :
5966 inet_ntoa (attr->nexthop));
5968 #ifdef HAVE_IPV6
5969 else
5971 assert (attr->extra);
5972 vty_out (vty, " %s",
5973 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5974 buf, INET6_ADDRSTRLEN));
5976 #endif /* HAVE_IPV6 */
5978 if (binfo->peer == bgp->peer_self)
5980 vty_out (vty, " from %s ",
5981 p->family == AF_INET ? "0.0.0.0" : "::");
5982 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5984 else
5986 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5987 vty_out (vty, " (inaccessible)");
5988 else if (binfo->extra && binfo->extra->igpmetric)
5989 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
5990 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
5991 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5992 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
5993 else
5994 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5996 vty_out (vty, "%s", VTY_NEWLINE);
5998 #ifdef HAVE_IPV6
5999 /* display nexthop local */
6000 if (attr->extra && attr->extra->mp_nexthop_len == 32)
6002 vty_out (vty, " (%s)%s",
6003 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6004 buf, INET6_ADDRSTRLEN),
6005 VTY_NEWLINE);
6007 #endif /* HAVE_IPV6 */
6009 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6010 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6012 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6013 vty_out (vty, ", metric %d", attr->med);
6015 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6016 vty_out (vty, ", localpref %d", attr->local_pref);
6017 else
6018 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6020 if (attr->extra && attr->extra->weight != 0)
6021 vty_out (vty, ", weight %d", attr->extra->weight);
6023 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6024 vty_out (vty, ", valid");
6026 if (binfo->peer != bgp->peer_self)
6028 if (binfo->peer->as == binfo->peer->local_as)
6029 vty_out (vty, ", internal");
6030 else
6031 vty_out (vty, ", %s",
6032 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6034 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6035 vty_out (vty, ", aggregated, local");
6036 else if (binfo->type != ZEBRA_ROUTE_BGP)
6037 vty_out (vty, ", sourced");
6038 else
6039 vty_out (vty, ", sourced, local");
6041 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6042 vty_out (vty, ", atomic-aggregate");
6044 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6045 vty_out (vty, ", best");
6047 vty_out (vty, "%s", VTY_NEWLINE);
6049 /* Line 4 display Community */
6050 if (attr->community)
6051 vty_out (vty, " Community: %s%s", attr->community->str,
6052 VTY_NEWLINE);
6054 /* Line 5 display Extended-community */
6055 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
6056 vty_out (vty, " Extended Community: %s%s",
6057 attr->extra->ecommunity->str, VTY_NEWLINE);
6059 /* Line 6 display Originator, Cluster-id */
6060 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6061 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6063 assert (attr->extra);
6064 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
6065 vty_out (vty, " Originator: %s",
6066 inet_ntoa (attr->extra->originator_id));
6068 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6070 int i;
6071 vty_out (vty, ", Cluster list: ");
6072 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6073 vty_out (vty, "%s ",
6074 inet_ntoa (attr->extra->cluster->list[i]));
6076 vty_out (vty, "%s", VTY_NEWLINE);
6079 /* 7: AS Pathlimit */
6080 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6083 vty_out (vty, " AS-Pathlimit: %u",
6084 attr->pathlimit.ttl);
6085 if (attr->pathlimit.as)
6086 vty_out (vty, " (%u)", attr->pathlimit.as);
6087 vty_out (vty, "%s", VTY_NEWLINE);
6090 if (binfo->extra && binfo->extra->damp_info)
6091 bgp_damp_info_vty (vty, binfo);
6093 /* Line 7 display Uptime */
6094 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
6096 vty_out (vty, "%s", VTY_NEWLINE);
6099 #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"
6100 #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
6101 #define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6102 #define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6103 #define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6105 enum bgp_show_type
6107 bgp_show_type_normal,
6108 bgp_show_type_regexp,
6109 bgp_show_type_prefix_list,
6110 bgp_show_type_filter_list,
6111 bgp_show_type_route_map,
6112 bgp_show_type_neighbor,
6113 bgp_show_type_cidr_only,
6114 bgp_show_type_prefix_longer,
6115 bgp_show_type_community_all,
6116 bgp_show_type_community,
6117 bgp_show_type_community_exact,
6118 bgp_show_type_community_list,
6119 bgp_show_type_community_list_exact,
6120 bgp_show_type_flap_statistics,
6121 bgp_show_type_flap_address,
6122 bgp_show_type_flap_prefix,
6123 bgp_show_type_flap_cidr_only,
6124 bgp_show_type_flap_regexp,
6125 bgp_show_type_flap_filter_list,
6126 bgp_show_type_flap_prefix_list,
6127 bgp_show_type_flap_prefix_longer,
6128 bgp_show_type_flap_route_map,
6129 bgp_show_type_flap_neighbor,
6130 bgp_show_type_dampend_paths,
6131 bgp_show_type_damp_neighbor
6134 static int
6135 bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
6136 enum bgp_show_type type, void *output_arg)
6138 struct bgp_info *ri;
6139 struct bgp_node *rn;
6140 int header = 1;
6141 int display;
6142 unsigned long output_count;
6144 /* This is first entry point, so reset total line. */
6145 output_count = 0;
6147 /* Start processing of routes. */
6148 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6149 if (rn->info != NULL)
6151 display = 0;
6153 for (ri = rn->info; ri; ri = ri->next)
6155 if (type == bgp_show_type_flap_statistics
6156 || type == bgp_show_type_flap_address
6157 || type == bgp_show_type_flap_prefix
6158 || type == bgp_show_type_flap_cidr_only
6159 || type == bgp_show_type_flap_regexp
6160 || type == bgp_show_type_flap_filter_list
6161 || type == bgp_show_type_flap_prefix_list
6162 || type == bgp_show_type_flap_prefix_longer
6163 || type == bgp_show_type_flap_route_map
6164 || type == bgp_show_type_flap_neighbor
6165 || type == bgp_show_type_dampend_paths
6166 || type == bgp_show_type_damp_neighbor)
6168 if (!(ri->extra && ri->extra->damp_info))
6169 continue;
6171 if (type == bgp_show_type_regexp
6172 || type == bgp_show_type_flap_regexp)
6174 regex_t *regex = output_arg;
6176 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6177 continue;
6179 if (type == bgp_show_type_prefix_list
6180 || type == bgp_show_type_flap_prefix_list)
6182 struct prefix_list *plist = output_arg;
6184 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6185 continue;
6187 if (type == bgp_show_type_filter_list
6188 || type == bgp_show_type_flap_filter_list)
6190 struct as_list *as_list = output_arg;
6192 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6193 continue;
6195 if (type == bgp_show_type_route_map
6196 || type == bgp_show_type_flap_route_map)
6198 struct route_map *rmap = output_arg;
6199 struct bgp_info binfo;
6200 struct attr dummy_attr = { 0 };
6201 int ret;
6203 bgp_attr_dup (&dummy_attr, ri->attr);
6204 binfo.peer = ri->peer;
6205 binfo.attr = &dummy_attr;
6207 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
6209 bgp_attr_extra_free (&dummy_attr);
6211 if (ret == RMAP_DENYMATCH)
6212 continue;
6214 if (type == bgp_show_type_neighbor
6215 || type == bgp_show_type_flap_neighbor
6216 || type == bgp_show_type_damp_neighbor)
6218 union sockunion *su = output_arg;
6220 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6221 continue;
6223 if (type == bgp_show_type_cidr_only
6224 || type == bgp_show_type_flap_cidr_only)
6226 u_int32_t destination;
6228 destination = ntohl (rn->p.u.prefix4.s_addr);
6229 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6230 continue;
6231 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6232 continue;
6233 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6234 continue;
6236 if (type == bgp_show_type_prefix_longer
6237 || type == bgp_show_type_flap_prefix_longer)
6239 struct prefix *p = output_arg;
6241 if (! prefix_match (p, &rn->p))
6242 continue;
6244 if (type == bgp_show_type_community_all)
6246 if (! ri->attr->community)
6247 continue;
6249 if (type == bgp_show_type_community)
6251 struct community *com = output_arg;
6253 if (! ri->attr->community ||
6254 ! community_match (ri->attr->community, com))
6255 continue;
6257 if (type == bgp_show_type_community_exact)
6259 struct community *com = output_arg;
6261 if (! ri->attr->community ||
6262 ! community_cmp (ri->attr->community, com))
6263 continue;
6265 if (type == bgp_show_type_community_list)
6267 struct community_list *list = output_arg;
6269 if (! community_list_match (ri->attr->community, list))
6270 continue;
6272 if (type == bgp_show_type_community_list_exact)
6274 struct community_list *list = output_arg;
6276 if (! community_list_exact_match (ri->attr->community, list))
6277 continue;
6279 if (type == bgp_show_type_flap_address
6280 || type == bgp_show_type_flap_prefix)
6282 struct prefix *p = output_arg;
6284 if (! prefix_match (&rn->p, p))
6285 continue;
6287 if (type == bgp_show_type_flap_prefix)
6288 if (p->prefixlen != rn->p.prefixlen)
6289 continue;
6291 if (type == bgp_show_type_dampend_paths
6292 || type == bgp_show_type_damp_neighbor)
6294 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6295 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6296 continue;
6299 if (header)
6301 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6302 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6303 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6304 if (type == bgp_show_type_dampend_paths
6305 || type == bgp_show_type_damp_neighbor)
6306 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6307 else if (type == bgp_show_type_flap_statistics
6308 || type == bgp_show_type_flap_address
6309 || type == bgp_show_type_flap_prefix
6310 || type == bgp_show_type_flap_cidr_only
6311 || type == bgp_show_type_flap_regexp
6312 || type == bgp_show_type_flap_filter_list
6313 || type == bgp_show_type_flap_prefix_list
6314 || type == bgp_show_type_flap_prefix_longer
6315 || type == bgp_show_type_flap_route_map
6316 || type == bgp_show_type_flap_neighbor)
6317 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6318 else
6319 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
6320 header = 0;
6323 if (type == bgp_show_type_dampend_paths
6324 || type == bgp_show_type_damp_neighbor)
6325 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6326 else if (type == bgp_show_type_flap_statistics
6327 || type == bgp_show_type_flap_address
6328 || type == bgp_show_type_flap_prefix
6329 || type == bgp_show_type_flap_cidr_only
6330 || type == bgp_show_type_flap_regexp
6331 || type == bgp_show_type_flap_filter_list
6332 || type == bgp_show_type_flap_prefix_list
6333 || type == bgp_show_type_flap_prefix_longer
6334 || type == bgp_show_type_flap_route_map
6335 || type == bgp_show_type_flap_neighbor)
6336 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6337 else
6338 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
6339 display++;
6341 if (display)
6342 output_count++;
6345 /* No route is displayed */
6346 if (output_count == 0)
6348 if (type == bgp_show_type_normal)
6349 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6351 else
6352 vty_out (vty, "%sTotal number of prefixes %ld%s",
6353 VTY_NEWLINE, output_count, VTY_NEWLINE);
6355 return CMD_SUCCESS;
6358 static int
6359 bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
6360 enum bgp_show_type type, void *output_arg)
6362 struct bgp_table *table;
6364 if (bgp == NULL) {
6365 bgp = bgp_get_default ();
6368 if (bgp == NULL)
6370 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6371 return CMD_WARNING;
6375 table = bgp->rib[afi][safi];
6377 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
6380 /* Header of detailed BGP route information */
6381 static void
6382 route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6383 struct bgp_node *rn,
6384 struct prefix_rd *prd, afi_t afi, safi_t safi)
6386 struct bgp_info *ri;
6387 struct prefix *p;
6388 struct peer *peer;
6389 struct listnode *node, *nnode;
6390 char buf1[INET6_ADDRSTRLEN];
6391 char buf2[INET6_ADDRSTRLEN];
6392 int count = 0;
6393 int best = 0;
6394 int suppress = 0;
6395 int no_export = 0;
6396 int no_advertise = 0;
6397 int local_as = 0;
6398 int first = 0;
6400 p = &rn->p;
6401 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6402 (safi == SAFI_MPLS_VPN ?
6403 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6404 safi == SAFI_MPLS_VPN ? ":" : "",
6405 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6406 p->prefixlen, VTY_NEWLINE);
6408 for (ri = rn->info; ri; ri = ri->next)
6410 count++;
6411 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6413 best = count;
6414 if (ri->extra && ri->extra->suppress)
6415 suppress = 1;
6416 if (ri->attr->community != NULL)
6418 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6419 no_advertise = 1;
6420 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6421 no_export = 1;
6422 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6423 local_as = 1;
6428 vty_out (vty, "Paths: (%d available", count);
6429 if (best)
6431 vty_out (vty, ", best #%d", best);
6432 if (safi == SAFI_UNICAST)
6433 vty_out (vty, ", table Default-IP-Routing-Table");
6435 else
6436 vty_out (vty, ", no best path");
6437 if (no_advertise)
6438 vty_out (vty, ", not advertised to any peer");
6439 else if (no_export)
6440 vty_out (vty, ", not advertised to EBGP peer");
6441 else if (local_as)
6442 vty_out (vty, ", not advertised outside local AS");
6443 if (suppress)
6444 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6445 vty_out (vty, ")%s", VTY_NEWLINE);
6447 /* advertised peer */
6448 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
6450 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6452 if (! first)
6453 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6454 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6455 first = 1;
6458 if (! first)
6459 vty_out (vty, " Not advertised to any peer");
6460 vty_out (vty, "%s", VTY_NEWLINE);
6463 /* Display specified route of BGP table. */
6464 static int
6465 bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
6466 struct bgp_table *rib, const char *ip_str,
6467 afi_t afi, safi_t safi, struct prefix_rd *prd,
6468 int prefix_check)
6470 int ret;
6471 int header;
6472 int display = 0;
6473 struct prefix match;
6474 struct bgp_node *rn;
6475 struct bgp_node *rm;
6476 struct bgp_info *ri;
6477 struct bgp_table *table;
6479 /* Check IP address argument. */
6480 ret = str2prefix (ip_str, &match);
6481 if (! ret)
6483 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6484 return CMD_WARNING;
6487 match.family = afi2family (afi);
6489 if (safi == SAFI_MPLS_VPN)
6491 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
6493 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6494 continue;
6496 if ((table = rn->info) != NULL)
6498 header = 1;
6500 if ((rm = bgp_node_match (table, &match)) != NULL)
6502 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6503 continue;
6505 for (ri = rm->info; ri; ri = ri->next)
6507 if (header)
6509 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6510 AFI_IP, SAFI_MPLS_VPN);
6512 header = 0;
6514 display++;
6515 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6521 else
6523 header = 1;
6525 if ((rn = bgp_node_match (rib, &match)) != NULL)
6527 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6529 for (ri = rn->info; ri; ri = ri->next)
6531 if (header)
6533 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6534 header = 0;
6536 display++;
6537 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6543 if (! display)
6545 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6546 return CMD_WARNING;
6549 return CMD_SUCCESS;
6552 /* Display specified route of Main RIB */
6553 static int
6554 bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
6555 afi_t afi, safi_t safi, struct prefix_rd *prd,
6556 int prefix_check)
6558 struct bgp *bgp;
6560 /* BGP structure lookup. */
6561 if (view_name)
6563 bgp = bgp_lookup_by_name (view_name);
6564 if (bgp == NULL)
6566 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6567 return CMD_WARNING;
6570 else
6572 bgp = bgp_get_default ();
6573 if (bgp == NULL)
6575 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6576 return CMD_WARNING;
6580 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6581 afi, safi, prd, prefix_check);
6584 /* BGP route print out function. */
6585 DEFUN (show_ip_bgp,
6586 show_ip_bgp_cmd,
6587 "show ip bgp",
6588 SHOW_STR
6589 IP_STR
6590 BGP_STR)
6592 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6595 DEFUN (show_ip_bgp_ipv4,
6596 show_ip_bgp_ipv4_cmd,
6597 "show ip bgp ipv4 (unicast|multicast)",
6598 SHOW_STR
6599 IP_STR
6600 BGP_STR
6601 "Address family\n"
6602 "Address Family modifier\n"
6603 "Address Family modifier\n")
6605 if (strncmp (argv[0], "m", 1) == 0)
6606 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6607 NULL);
6609 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6612 DEFUN (show_ip_bgp_route,
6613 show_ip_bgp_route_cmd,
6614 "show ip bgp A.B.C.D",
6615 SHOW_STR
6616 IP_STR
6617 BGP_STR
6618 "Network in the BGP routing table to display\n")
6620 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6623 DEFUN (show_ip_bgp_ipv4_route,
6624 show_ip_bgp_ipv4_route_cmd,
6625 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6626 SHOW_STR
6627 IP_STR
6628 BGP_STR
6629 "Address family\n"
6630 "Address Family modifier\n"
6631 "Address Family modifier\n"
6632 "Network in the BGP routing table to display\n")
6634 if (strncmp (argv[0], "m", 1) == 0)
6635 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6637 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6640 DEFUN (show_ip_bgp_vpnv4_all_route,
6641 show_ip_bgp_vpnv4_all_route_cmd,
6642 "show ip bgp vpnv4 all A.B.C.D",
6643 SHOW_STR
6644 IP_STR
6645 BGP_STR
6646 "Display VPNv4 NLRI specific information\n"
6647 "Display information about all VPNv4 NLRIs\n"
6648 "Network in the BGP routing table to display\n")
6650 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6653 DEFUN (show_ip_bgp_vpnv4_rd_route,
6654 show_ip_bgp_vpnv4_rd_route_cmd,
6655 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6656 SHOW_STR
6657 IP_STR
6658 BGP_STR
6659 "Display VPNv4 NLRI specific information\n"
6660 "Display information for a route distinguisher\n"
6661 "VPN Route Distinguisher\n"
6662 "Network in the BGP routing table to display\n")
6664 int ret;
6665 struct prefix_rd prd;
6667 ret = str2prefix_rd (argv[0], &prd);
6668 if (! ret)
6670 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6671 return CMD_WARNING;
6673 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6676 DEFUN (show_ip_bgp_prefix,
6677 show_ip_bgp_prefix_cmd,
6678 "show ip bgp A.B.C.D/M",
6679 SHOW_STR
6680 IP_STR
6681 BGP_STR
6682 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6684 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6687 DEFUN (show_ip_bgp_ipv4_prefix,
6688 show_ip_bgp_ipv4_prefix_cmd,
6689 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6690 SHOW_STR
6691 IP_STR
6692 BGP_STR
6693 "Address family\n"
6694 "Address Family modifier\n"
6695 "Address Family modifier\n"
6696 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6698 if (strncmp (argv[0], "m", 1) == 0)
6699 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6701 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6704 DEFUN (show_ip_bgp_vpnv4_all_prefix,
6705 show_ip_bgp_vpnv4_all_prefix_cmd,
6706 "show ip bgp vpnv4 all A.B.C.D/M",
6707 SHOW_STR
6708 IP_STR
6709 BGP_STR
6710 "Display VPNv4 NLRI specific information\n"
6711 "Display information about all VPNv4 NLRIs\n"
6712 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6714 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6717 DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6718 show_ip_bgp_vpnv4_rd_prefix_cmd,
6719 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6720 SHOW_STR
6721 IP_STR
6722 BGP_STR
6723 "Display VPNv4 NLRI specific information\n"
6724 "Display information for a route distinguisher\n"
6725 "VPN Route Distinguisher\n"
6726 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6728 int ret;
6729 struct prefix_rd prd;
6731 ret = str2prefix_rd (argv[0], &prd);
6732 if (! ret)
6734 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6735 return CMD_WARNING;
6737 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6740 DEFUN (show_ip_bgp_view,
6741 show_ip_bgp_view_cmd,
6742 "show ip bgp view WORD",
6743 SHOW_STR
6744 IP_STR
6745 BGP_STR
6746 "BGP view\n"
6747 "BGP view name\n")
6749 struct bgp *bgp;
6751 /* BGP structure lookup. */
6752 bgp = bgp_lookup_by_name (argv[0]);
6753 if (bgp == NULL)
6755 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6756 return CMD_WARNING;
6759 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6762 DEFUN (show_ip_bgp_view_route,
6763 show_ip_bgp_view_route_cmd,
6764 "show ip bgp view WORD A.B.C.D",
6765 SHOW_STR
6766 IP_STR
6767 BGP_STR
6768 "BGP view\n"
6769 "BGP view name\n"
6770 "Network in the BGP routing table to display\n")
6772 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6775 DEFUN (show_ip_bgp_view_prefix,
6776 show_ip_bgp_view_prefix_cmd,
6777 "show ip bgp view WORD A.B.C.D/M",
6778 SHOW_STR
6779 IP_STR
6780 BGP_STR
6781 "BGP view\n"
6782 "BGP view name\n"
6783 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6785 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6788 #ifdef HAVE_IPV6
6789 DEFUN (show_bgp,
6790 show_bgp_cmd,
6791 "show bgp",
6792 SHOW_STR
6793 BGP_STR)
6795 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6796 NULL);
6799 ALIAS (show_bgp,
6800 show_bgp_ipv6_cmd,
6801 "show bgp ipv6",
6802 SHOW_STR
6803 BGP_STR
6804 "Address family\n")
6806 /* old command */
6807 DEFUN (show_ipv6_bgp,
6808 show_ipv6_bgp_cmd,
6809 "show ipv6 bgp",
6810 SHOW_STR
6811 IP_STR
6812 BGP_STR)
6814 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6815 NULL);
6818 DEFUN (show_bgp_route,
6819 show_bgp_route_cmd,
6820 "show bgp X:X::X:X",
6821 SHOW_STR
6822 BGP_STR
6823 "Network in the BGP routing table to display\n")
6825 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6828 ALIAS (show_bgp_route,
6829 show_bgp_ipv6_route_cmd,
6830 "show bgp ipv6 X:X::X:X",
6831 SHOW_STR
6832 BGP_STR
6833 "Address family\n"
6834 "Network in the BGP routing table to display\n")
6836 /* old command */
6837 DEFUN (show_ipv6_bgp_route,
6838 show_ipv6_bgp_route_cmd,
6839 "show ipv6 bgp X:X::X:X",
6840 SHOW_STR
6841 IP_STR
6842 BGP_STR
6843 "Network in the BGP routing table to display\n")
6845 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6848 DEFUN (show_bgp_prefix,
6849 show_bgp_prefix_cmd,
6850 "show bgp X:X::X:X/M",
6851 SHOW_STR
6852 BGP_STR
6853 "IPv6 prefix <network>/<length>\n")
6855 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6858 ALIAS (show_bgp_prefix,
6859 show_bgp_ipv6_prefix_cmd,
6860 "show bgp ipv6 X:X::X:X/M",
6861 SHOW_STR
6862 BGP_STR
6863 "Address family\n"
6864 "IPv6 prefix <network>/<length>\n")
6866 /* old command */
6867 DEFUN (show_ipv6_bgp_prefix,
6868 show_ipv6_bgp_prefix_cmd,
6869 "show ipv6 bgp X:X::X:X/M",
6870 SHOW_STR
6871 IP_STR
6872 BGP_STR
6873 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6875 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6878 DEFUN (show_bgp_view,
6879 show_bgp_view_cmd,
6880 "show bgp view WORD",
6881 SHOW_STR
6882 BGP_STR
6883 "BGP view\n"
6884 "View name\n")
6886 struct bgp *bgp;
6888 /* BGP structure lookup. */
6889 bgp = bgp_lookup_by_name (argv[0]);
6890 if (bgp == NULL)
6892 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6893 return CMD_WARNING;
6896 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6899 ALIAS (show_bgp_view,
6900 show_bgp_view_ipv6_cmd,
6901 "show bgp view WORD ipv6",
6902 SHOW_STR
6903 BGP_STR
6904 "BGP view\n"
6905 "View name\n"
6906 "Address family\n")
6908 DEFUN (show_bgp_view_route,
6909 show_bgp_view_route_cmd,
6910 "show bgp view WORD X:X::X:X",
6911 SHOW_STR
6912 BGP_STR
6913 "BGP view\n"
6914 "View name\n"
6915 "Network in the BGP routing table to display\n")
6917 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6920 ALIAS (show_bgp_view_route,
6921 show_bgp_view_ipv6_route_cmd,
6922 "show bgp view WORD ipv6 X:X::X:X",
6923 SHOW_STR
6924 BGP_STR
6925 "BGP view\n"
6926 "View name\n"
6927 "Address family\n"
6928 "Network in the BGP routing table to display\n")
6930 DEFUN (show_bgp_view_prefix,
6931 show_bgp_view_prefix_cmd,
6932 "show bgp view WORD X:X::X:X/M",
6933 SHOW_STR
6934 BGP_STR
6935 "BGP view\n"
6936 "View name\n"
6937 "IPv6 prefix <network>/<length>\n")
6939 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6942 ALIAS (show_bgp_view_prefix,
6943 show_bgp_view_ipv6_prefix_cmd,
6944 "show bgp view WORD ipv6 X:X::X:X/M",
6945 SHOW_STR
6946 BGP_STR
6947 "BGP view\n"
6948 "View name\n"
6949 "Address family\n"
6950 "IPv6 prefix <network>/<length>\n")
6952 /* old command */
6953 DEFUN (show_ipv6_mbgp,
6954 show_ipv6_mbgp_cmd,
6955 "show ipv6 mbgp",
6956 SHOW_STR
6957 IP_STR
6958 MBGP_STR)
6960 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6961 NULL);
6964 /* old command */
6965 DEFUN (show_ipv6_mbgp_route,
6966 show_ipv6_mbgp_route_cmd,
6967 "show ipv6 mbgp X:X::X:X",
6968 SHOW_STR
6969 IP_STR
6970 MBGP_STR
6971 "Network in the MBGP routing table to display\n")
6973 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6976 /* old command */
6977 DEFUN (show_ipv6_mbgp_prefix,
6978 show_ipv6_mbgp_prefix_cmd,
6979 "show ipv6 mbgp X:X::X:X/M",
6980 SHOW_STR
6981 IP_STR
6982 MBGP_STR
6983 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6985 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6987 #endif
6990 static int
6991 bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
6992 safi_t safi, enum bgp_show_type type)
6994 int i;
6995 struct buffer *b;
6996 char *regstr;
6997 int first;
6998 regex_t *regex;
6999 int rc;
7001 first = 0;
7002 b = buffer_new (1024);
7003 for (i = 0; i < argc; i++)
7005 if (first)
7006 buffer_putc (b, ' ');
7007 else
7009 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7010 continue;
7011 first = 1;
7014 buffer_putstr (b, argv[i]);
7016 buffer_putc (b, '\0');
7018 regstr = buffer_getstr (b);
7019 buffer_free (b);
7021 regex = bgp_regcomp (regstr);
7022 XFREE(MTYPE_TMP, regstr);
7023 if (! regex)
7025 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7026 VTY_NEWLINE);
7027 return CMD_WARNING;
7030 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7031 bgp_regex_free (regex);
7032 return rc;
7035 DEFUN (show_ip_bgp_regexp,
7036 show_ip_bgp_regexp_cmd,
7037 "show ip bgp regexp .LINE",
7038 SHOW_STR
7039 IP_STR
7040 BGP_STR
7041 "Display routes matching the AS path regular expression\n"
7042 "A regular-expression to match the BGP AS paths\n")
7044 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7045 bgp_show_type_regexp);
7048 DEFUN (show_ip_bgp_flap_regexp,
7049 show_ip_bgp_flap_regexp_cmd,
7050 "show ip bgp flap-statistics regexp .LINE",
7051 SHOW_STR
7052 IP_STR
7053 BGP_STR
7054 "Display flap statistics of routes\n"
7055 "Display routes matching the AS path regular expression\n"
7056 "A regular-expression to match the BGP AS paths\n")
7058 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7059 bgp_show_type_flap_regexp);
7062 DEFUN (show_ip_bgp_ipv4_regexp,
7063 show_ip_bgp_ipv4_regexp_cmd,
7064 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7065 SHOW_STR
7066 IP_STR
7067 BGP_STR
7068 "Address family\n"
7069 "Address Family modifier\n"
7070 "Address Family modifier\n"
7071 "Display routes matching the AS path regular expression\n"
7072 "A regular-expression to match the BGP AS paths\n")
7074 if (strncmp (argv[0], "m", 1) == 0)
7075 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7076 bgp_show_type_regexp);
7078 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7079 bgp_show_type_regexp);
7082 #ifdef HAVE_IPV6
7083 DEFUN (show_bgp_regexp,
7084 show_bgp_regexp_cmd,
7085 "show bgp regexp .LINE",
7086 SHOW_STR
7087 BGP_STR
7088 "Display routes matching the AS path regular expression\n"
7089 "A regular-expression to match the BGP AS paths\n")
7091 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7092 bgp_show_type_regexp);
7095 ALIAS (show_bgp_regexp,
7096 show_bgp_ipv6_regexp_cmd,
7097 "show bgp ipv6 regexp .LINE",
7098 SHOW_STR
7099 BGP_STR
7100 "Address family\n"
7101 "Display routes matching the AS path regular expression\n"
7102 "A regular-expression to match the BGP AS paths\n")
7104 /* old command */
7105 DEFUN (show_ipv6_bgp_regexp,
7106 show_ipv6_bgp_regexp_cmd,
7107 "show ipv6 bgp regexp .LINE",
7108 SHOW_STR
7109 IP_STR
7110 BGP_STR
7111 "Display routes matching the AS path regular expression\n"
7112 "A regular-expression to match the BGP AS paths\n")
7114 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7115 bgp_show_type_regexp);
7118 /* old command */
7119 DEFUN (show_ipv6_mbgp_regexp,
7120 show_ipv6_mbgp_regexp_cmd,
7121 "show ipv6 mbgp regexp .LINE",
7122 SHOW_STR
7123 IP_STR
7124 BGP_STR
7125 "Display routes matching the AS path regular expression\n"
7126 "A regular-expression to match the MBGP AS paths\n")
7128 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7129 bgp_show_type_regexp);
7131 #endif /* HAVE_IPV6 */
7133 static int
7134 bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
7135 safi_t safi, enum bgp_show_type type)
7137 struct prefix_list *plist;
7139 plist = prefix_list_lookup (afi, prefix_list_str);
7140 if (plist == NULL)
7142 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7143 prefix_list_str, VTY_NEWLINE);
7144 return CMD_WARNING;
7147 return bgp_show (vty, NULL, afi, safi, type, plist);
7150 DEFUN (show_ip_bgp_prefix_list,
7151 show_ip_bgp_prefix_list_cmd,
7152 "show ip bgp prefix-list WORD",
7153 SHOW_STR
7154 IP_STR
7155 BGP_STR
7156 "Display routes conforming to the prefix-list\n"
7157 "IP prefix-list name\n")
7159 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7160 bgp_show_type_prefix_list);
7163 DEFUN (show_ip_bgp_flap_prefix_list,
7164 show_ip_bgp_flap_prefix_list_cmd,
7165 "show ip bgp flap-statistics prefix-list WORD",
7166 SHOW_STR
7167 IP_STR
7168 BGP_STR
7169 "Display flap statistics of routes\n"
7170 "Display routes conforming to the prefix-list\n"
7171 "IP prefix-list name\n")
7173 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7174 bgp_show_type_flap_prefix_list);
7177 DEFUN (show_ip_bgp_ipv4_prefix_list,
7178 show_ip_bgp_ipv4_prefix_list_cmd,
7179 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7180 SHOW_STR
7181 IP_STR
7182 BGP_STR
7183 "Address family\n"
7184 "Address Family modifier\n"
7185 "Address Family modifier\n"
7186 "Display routes conforming to the prefix-list\n"
7187 "IP prefix-list name\n")
7189 if (strncmp (argv[0], "m", 1) == 0)
7190 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7191 bgp_show_type_prefix_list);
7193 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7194 bgp_show_type_prefix_list);
7197 #ifdef HAVE_IPV6
7198 DEFUN (show_bgp_prefix_list,
7199 show_bgp_prefix_list_cmd,
7200 "show bgp prefix-list WORD",
7201 SHOW_STR
7202 BGP_STR
7203 "Display routes conforming to the prefix-list\n"
7204 "IPv6 prefix-list name\n")
7206 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7207 bgp_show_type_prefix_list);
7210 ALIAS (show_bgp_prefix_list,
7211 show_bgp_ipv6_prefix_list_cmd,
7212 "show bgp ipv6 prefix-list WORD",
7213 SHOW_STR
7214 BGP_STR
7215 "Address family\n"
7216 "Display routes conforming to the prefix-list\n"
7217 "IPv6 prefix-list name\n")
7219 /* old command */
7220 DEFUN (show_ipv6_bgp_prefix_list,
7221 show_ipv6_bgp_prefix_list_cmd,
7222 "show ipv6 bgp prefix-list WORD",
7223 SHOW_STR
7224 IPV6_STR
7225 BGP_STR
7226 "Display routes matching the prefix-list\n"
7227 "IPv6 prefix-list name\n")
7229 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7230 bgp_show_type_prefix_list);
7233 /* old command */
7234 DEFUN (show_ipv6_mbgp_prefix_list,
7235 show_ipv6_mbgp_prefix_list_cmd,
7236 "show ipv6 mbgp prefix-list WORD",
7237 SHOW_STR
7238 IPV6_STR
7239 MBGP_STR
7240 "Display routes matching the prefix-list\n"
7241 "IPv6 prefix-list name\n")
7243 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7244 bgp_show_type_prefix_list);
7246 #endif /* HAVE_IPV6 */
7248 static int
7249 bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
7250 safi_t safi, enum bgp_show_type type)
7252 struct as_list *as_list;
7254 as_list = as_list_lookup (filter);
7255 if (as_list == NULL)
7257 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7258 return CMD_WARNING;
7261 return bgp_show (vty, NULL, afi, safi, type, as_list);
7264 DEFUN (show_ip_bgp_filter_list,
7265 show_ip_bgp_filter_list_cmd,
7266 "show ip bgp filter-list WORD",
7267 SHOW_STR
7268 IP_STR
7269 BGP_STR
7270 "Display routes conforming to the filter-list\n"
7271 "Regular expression access list name\n")
7273 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7274 bgp_show_type_filter_list);
7277 DEFUN (show_ip_bgp_flap_filter_list,
7278 show_ip_bgp_flap_filter_list_cmd,
7279 "show ip bgp flap-statistics filter-list WORD",
7280 SHOW_STR
7281 IP_STR
7282 BGP_STR
7283 "Display flap statistics of routes\n"
7284 "Display routes conforming to the filter-list\n"
7285 "Regular expression access list name\n")
7287 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7288 bgp_show_type_flap_filter_list);
7291 DEFUN (show_ip_bgp_ipv4_filter_list,
7292 show_ip_bgp_ipv4_filter_list_cmd,
7293 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7294 SHOW_STR
7295 IP_STR
7296 BGP_STR
7297 "Address family\n"
7298 "Address Family modifier\n"
7299 "Address Family modifier\n"
7300 "Display routes conforming to the filter-list\n"
7301 "Regular expression access list name\n")
7303 if (strncmp (argv[0], "m", 1) == 0)
7304 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7305 bgp_show_type_filter_list);
7307 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7308 bgp_show_type_filter_list);
7311 #ifdef HAVE_IPV6
7312 DEFUN (show_bgp_filter_list,
7313 show_bgp_filter_list_cmd,
7314 "show bgp filter-list WORD",
7315 SHOW_STR
7316 BGP_STR
7317 "Display routes conforming to the filter-list\n"
7318 "Regular expression access list name\n")
7320 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7321 bgp_show_type_filter_list);
7324 ALIAS (show_bgp_filter_list,
7325 show_bgp_ipv6_filter_list_cmd,
7326 "show bgp ipv6 filter-list WORD",
7327 SHOW_STR
7328 BGP_STR
7329 "Address family\n"
7330 "Display routes conforming to the filter-list\n"
7331 "Regular expression access list name\n")
7333 /* old command */
7334 DEFUN (show_ipv6_bgp_filter_list,
7335 show_ipv6_bgp_filter_list_cmd,
7336 "show ipv6 bgp filter-list WORD",
7337 SHOW_STR
7338 IPV6_STR
7339 BGP_STR
7340 "Display routes conforming to the filter-list\n"
7341 "Regular expression access list name\n")
7343 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7344 bgp_show_type_filter_list);
7347 /* old command */
7348 DEFUN (show_ipv6_mbgp_filter_list,
7349 show_ipv6_mbgp_filter_list_cmd,
7350 "show ipv6 mbgp filter-list WORD",
7351 SHOW_STR
7352 IPV6_STR
7353 MBGP_STR
7354 "Display routes conforming to the filter-list\n"
7355 "Regular expression access list name\n")
7357 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7358 bgp_show_type_filter_list);
7360 #endif /* HAVE_IPV6 */
7362 static int
7363 bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
7364 safi_t safi, enum bgp_show_type type)
7366 struct route_map *rmap;
7368 rmap = route_map_lookup_by_name (rmap_str);
7369 if (! rmap)
7371 vty_out (vty, "%% %s is not a valid route-map name%s",
7372 rmap_str, VTY_NEWLINE);
7373 return CMD_WARNING;
7376 return bgp_show (vty, NULL, afi, safi, type, rmap);
7379 DEFUN (show_ip_bgp_route_map,
7380 show_ip_bgp_route_map_cmd,
7381 "show ip bgp route-map WORD",
7382 SHOW_STR
7383 IP_STR
7384 BGP_STR
7385 "Display routes matching the route-map\n"
7386 "A route-map to match on\n")
7388 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7389 bgp_show_type_route_map);
7392 DEFUN (show_ip_bgp_flap_route_map,
7393 show_ip_bgp_flap_route_map_cmd,
7394 "show ip bgp flap-statistics route-map WORD",
7395 SHOW_STR
7396 IP_STR
7397 BGP_STR
7398 "Display flap statistics of routes\n"
7399 "Display routes matching the route-map\n"
7400 "A route-map to match on\n")
7402 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7403 bgp_show_type_flap_route_map);
7406 DEFUN (show_ip_bgp_ipv4_route_map,
7407 show_ip_bgp_ipv4_route_map_cmd,
7408 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7409 SHOW_STR
7410 IP_STR
7411 BGP_STR
7412 "Address family\n"
7413 "Address Family modifier\n"
7414 "Address Family modifier\n"
7415 "Display routes matching the route-map\n"
7416 "A route-map to match on\n")
7418 if (strncmp (argv[0], "m", 1) == 0)
7419 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7420 bgp_show_type_route_map);
7422 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7423 bgp_show_type_route_map);
7426 DEFUN (show_bgp_route_map,
7427 show_bgp_route_map_cmd,
7428 "show bgp route-map WORD",
7429 SHOW_STR
7430 BGP_STR
7431 "Display routes matching the route-map\n"
7432 "A route-map to match on\n")
7434 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7435 bgp_show_type_route_map);
7438 ALIAS (show_bgp_route_map,
7439 show_bgp_ipv6_route_map_cmd,
7440 "show bgp ipv6 route-map WORD",
7441 SHOW_STR
7442 BGP_STR
7443 "Address family\n"
7444 "Display routes matching the route-map\n"
7445 "A route-map to match on\n")
7447 DEFUN (show_ip_bgp_cidr_only,
7448 show_ip_bgp_cidr_only_cmd,
7449 "show ip bgp cidr-only",
7450 SHOW_STR
7451 IP_STR
7452 BGP_STR
7453 "Display only routes with non-natural netmasks\n")
7455 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7456 bgp_show_type_cidr_only, NULL);
7459 DEFUN (show_ip_bgp_flap_cidr_only,
7460 show_ip_bgp_flap_cidr_only_cmd,
7461 "show ip bgp flap-statistics cidr-only",
7462 SHOW_STR
7463 IP_STR
7464 BGP_STR
7465 "Display flap statistics of routes\n"
7466 "Display only routes with non-natural netmasks\n")
7468 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7469 bgp_show_type_flap_cidr_only, NULL);
7472 DEFUN (show_ip_bgp_ipv4_cidr_only,
7473 show_ip_bgp_ipv4_cidr_only_cmd,
7474 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7475 SHOW_STR
7476 IP_STR
7477 BGP_STR
7478 "Address family\n"
7479 "Address Family modifier\n"
7480 "Address Family modifier\n"
7481 "Display only routes with non-natural netmasks\n")
7483 if (strncmp (argv[0], "m", 1) == 0)
7484 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
7485 bgp_show_type_cidr_only, NULL);
7487 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7488 bgp_show_type_cidr_only, NULL);
7491 DEFUN (show_ip_bgp_community_all,
7492 show_ip_bgp_community_all_cmd,
7493 "show ip bgp community",
7494 SHOW_STR
7495 IP_STR
7496 BGP_STR
7497 "Display routes matching the communities\n")
7499 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7500 bgp_show_type_community_all, NULL);
7503 DEFUN (show_ip_bgp_ipv4_community_all,
7504 show_ip_bgp_ipv4_community_all_cmd,
7505 "show ip bgp ipv4 (unicast|multicast) community",
7506 SHOW_STR
7507 IP_STR
7508 BGP_STR
7509 "Address family\n"
7510 "Address Family modifier\n"
7511 "Address Family modifier\n"
7512 "Display routes matching the communities\n")
7514 if (strncmp (argv[0], "m", 1) == 0)
7515 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
7516 bgp_show_type_community_all, NULL);
7518 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
7519 bgp_show_type_community_all, NULL);
7522 #ifdef HAVE_IPV6
7523 DEFUN (show_bgp_community_all,
7524 show_bgp_community_all_cmd,
7525 "show bgp community",
7526 SHOW_STR
7527 BGP_STR
7528 "Display routes matching the communities\n")
7530 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
7531 bgp_show_type_community_all, NULL);
7534 ALIAS (show_bgp_community_all,
7535 show_bgp_ipv6_community_all_cmd,
7536 "show bgp ipv6 community",
7537 SHOW_STR
7538 BGP_STR
7539 "Address family\n"
7540 "Display routes matching the communities\n")
7542 /* old command */
7543 DEFUN (show_ipv6_bgp_community_all,
7544 show_ipv6_bgp_community_all_cmd,
7545 "show ipv6 bgp community",
7546 SHOW_STR
7547 IPV6_STR
7548 BGP_STR
7549 "Display routes matching the communities\n")
7551 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
7552 bgp_show_type_community_all, NULL);
7555 /* old command */
7556 DEFUN (show_ipv6_mbgp_community_all,
7557 show_ipv6_mbgp_community_all_cmd,
7558 "show ipv6 mbgp community",
7559 SHOW_STR
7560 IPV6_STR
7561 MBGP_STR
7562 "Display routes matching the communities\n")
7564 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
7565 bgp_show_type_community_all, NULL);
7567 #endif /* HAVE_IPV6 */
7569 static int
7570 bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7571 u_int16_t afi, u_char safi)
7573 struct community *com;
7574 struct buffer *b;
7575 int i;
7576 char *str;
7577 int first = 0;
7579 b = buffer_new (1024);
7580 for (i = 0; i < argc; i++)
7582 if (first)
7583 buffer_putc (b, ' ');
7584 else
7586 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7587 continue;
7588 first = 1;
7591 buffer_putstr (b, argv[i]);
7593 buffer_putc (b, '\0');
7595 str = buffer_getstr (b);
7596 buffer_free (b);
7598 com = community_str2com (str);
7599 XFREE (MTYPE_TMP, str);
7600 if (! com)
7602 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7603 return CMD_WARNING;
7606 return bgp_show (vty, NULL, afi, safi,
7607 (exact ? bgp_show_type_community_exact :
7608 bgp_show_type_community), com);
7611 DEFUN (show_ip_bgp_community,
7612 show_ip_bgp_community_cmd,
7613 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7614 SHOW_STR
7615 IP_STR
7616 BGP_STR
7617 "Display routes matching the communities\n"
7618 "community number\n"
7619 "Do not send outside local AS (well-known community)\n"
7620 "Do not advertise to any peer (well-known community)\n"
7621 "Do not export to next AS (well-known community)\n")
7623 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7626 ALIAS (show_ip_bgp_community,
7627 show_ip_bgp_community2_cmd,
7628 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7629 SHOW_STR
7630 IP_STR
7631 BGP_STR
7632 "Display routes matching the communities\n"
7633 "community number\n"
7634 "Do not send outside local AS (well-known community)\n"
7635 "Do not advertise to any peer (well-known community)\n"
7636 "Do not export to next AS (well-known community)\n"
7637 "community number\n"
7638 "Do not send outside local AS (well-known community)\n"
7639 "Do not advertise to any peer (well-known community)\n"
7640 "Do not export to next AS (well-known community)\n")
7642 ALIAS (show_ip_bgp_community,
7643 show_ip_bgp_community3_cmd,
7644 "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)",
7645 SHOW_STR
7646 IP_STR
7647 BGP_STR
7648 "Display routes matching the communities\n"
7649 "community number\n"
7650 "Do not send outside local AS (well-known community)\n"
7651 "Do not advertise to any peer (well-known community)\n"
7652 "Do not export to next AS (well-known community)\n"
7653 "community number\n"
7654 "Do not send outside local AS (well-known community)\n"
7655 "Do not advertise to any peer (well-known community)\n"
7656 "Do not export to next AS (well-known community)\n"
7657 "community number\n"
7658 "Do not send outside local AS (well-known community)\n"
7659 "Do not advertise to any peer (well-known community)\n"
7660 "Do not export to next AS (well-known community)\n")
7662 ALIAS (show_ip_bgp_community,
7663 show_ip_bgp_community4_cmd,
7664 "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)",
7665 SHOW_STR
7666 IP_STR
7667 BGP_STR
7668 "Display routes matching the communities\n"
7669 "community number\n"
7670 "Do not send outside local AS (well-known community)\n"
7671 "Do not advertise to any peer (well-known community)\n"
7672 "Do not export to next AS (well-known community)\n"
7673 "community number\n"
7674 "Do not send outside local AS (well-known community)\n"
7675 "Do not advertise to any peer (well-known community)\n"
7676 "Do not export to next AS (well-known community)\n"
7677 "community number\n"
7678 "Do not send outside local AS (well-known community)\n"
7679 "Do not advertise to any peer (well-known community)\n"
7680 "Do not export to next AS (well-known community)\n"
7681 "community number\n"
7682 "Do not send outside local AS (well-known community)\n"
7683 "Do not advertise to any peer (well-known community)\n"
7684 "Do not export to next AS (well-known community)\n")
7686 DEFUN (show_ip_bgp_ipv4_community,
7687 show_ip_bgp_ipv4_community_cmd,
7688 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7689 SHOW_STR
7690 IP_STR
7691 BGP_STR
7692 "Address family\n"
7693 "Address Family modifier\n"
7694 "Address Family modifier\n"
7695 "Display routes matching the communities\n"
7696 "community number\n"
7697 "Do not send outside local AS (well-known community)\n"
7698 "Do not advertise to any peer (well-known community)\n"
7699 "Do not export to next AS (well-known community)\n")
7701 if (strncmp (argv[0], "m", 1) == 0)
7702 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7704 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7707 ALIAS (show_ip_bgp_ipv4_community,
7708 show_ip_bgp_ipv4_community2_cmd,
7709 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7710 SHOW_STR
7711 IP_STR
7712 BGP_STR
7713 "Address family\n"
7714 "Address Family modifier\n"
7715 "Address Family modifier\n"
7716 "Display routes matching the communities\n"
7717 "community number\n"
7718 "Do not send outside local AS (well-known community)\n"
7719 "Do not advertise to any peer (well-known community)\n"
7720 "Do not export to next AS (well-known community)\n"
7721 "community number\n"
7722 "Do not send outside local AS (well-known community)\n"
7723 "Do not advertise to any peer (well-known community)\n"
7724 "Do not export to next AS (well-known community)\n")
7726 ALIAS (show_ip_bgp_ipv4_community,
7727 show_ip_bgp_ipv4_community3_cmd,
7728 "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)",
7729 SHOW_STR
7730 IP_STR
7731 BGP_STR
7732 "Address family\n"
7733 "Address Family modifier\n"
7734 "Address Family modifier\n"
7735 "Display routes matching the communities\n"
7736 "community number\n"
7737 "Do not send outside local AS (well-known community)\n"
7738 "Do not advertise to any peer (well-known community)\n"
7739 "Do not export to next AS (well-known community)\n"
7740 "community number\n"
7741 "Do not send outside local AS (well-known community)\n"
7742 "Do not advertise to any peer (well-known community)\n"
7743 "Do not export to next AS (well-known community)\n"
7744 "community number\n"
7745 "Do not send outside local AS (well-known community)\n"
7746 "Do not advertise to any peer (well-known community)\n"
7747 "Do not export to next AS (well-known community)\n")
7749 ALIAS (show_ip_bgp_ipv4_community,
7750 show_ip_bgp_ipv4_community4_cmd,
7751 "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)",
7752 SHOW_STR
7753 IP_STR
7754 BGP_STR
7755 "Address family\n"
7756 "Address Family modifier\n"
7757 "Address Family modifier\n"
7758 "Display routes matching the communities\n"
7759 "community number\n"
7760 "Do not send outside local AS (well-known community)\n"
7761 "Do not advertise to any peer (well-known community)\n"
7762 "Do not export to next AS (well-known community)\n"
7763 "community number\n"
7764 "Do not send outside local AS (well-known community)\n"
7765 "Do not advertise to any peer (well-known community)\n"
7766 "Do not export to next AS (well-known community)\n"
7767 "community number\n"
7768 "Do not send outside local AS (well-known community)\n"
7769 "Do not advertise to any peer (well-known community)\n"
7770 "Do not export to next AS (well-known community)\n"
7771 "community number\n"
7772 "Do not send outside local AS (well-known community)\n"
7773 "Do not advertise to any peer (well-known community)\n"
7774 "Do not export to next AS (well-known community)\n")
7776 DEFUN (show_ip_bgp_community_exact,
7777 show_ip_bgp_community_exact_cmd,
7778 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7779 SHOW_STR
7780 IP_STR
7781 BGP_STR
7782 "Display routes matching the communities\n"
7783 "community number\n"
7784 "Do not send outside local AS (well-known community)\n"
7785 "Do not advertise to any peer (well-known community)\n"
7786 "Do not export to next AS (well-known community)\n"
7787 "Exact match of the communities")
7789 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7792 ALIAS (show_ip_bgp_community_exact,
7793 show_ip_bgp_community2_exact_cmd,
7794 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7795 SHOW_STR
7796 IP_STR
7797 BGP_STR
7798 "Display routes matching the communities\n"
7799 "community number\n"
7800 "Do not send outside local AS (well-known community)\n"
7801 "Do not advertise to any peer (well-known community)\n"
7802 "Do not export to next AS (well-known community)\n"
7803 "community number\n"
7804 "Do not send outside local AS (well-known community)\n"
7805 "Do not advertise to any peer (well-known community)\n"
7806 "Do not export to next AS (well-known community)\n"
7807 "Exact match of the communities")
7809 ALIAS (show_ip_bgp_community_exact,
7810 show_ip_bgp_community3_exact_cmd,
7811 "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",
7812 SHOW_STR
7813 IP_STR
7814 BGP_STR
7815 "Display routes matching the communities\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n"
7824 "community number\n"
7825 "Do not send outside local AS (well-known community)\n"
7826 "Do not advertise to any peer (well-known community)\n"
7827 "Do not export to next AS (well-known community)\n"
7828 "Exact match of the communities")
7830 ALIAS (show_ip_bgp_community_exact,
7831 show_ip_bgp_community4_exact_cmd,
7832 "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",
7833 SHOW_STR
7834 IP_STR
7835 BGP_STR
7836 "Display routes matching the communities\n"
7837 "community number\n"
7838 "Do not send outside local AS (well-known community)\n"
7839 "Do not advertise to any peer (well-known community)\n"
7840 "Do not export to next AS (well-known community)\n"
7841 "community number\n"
7842 "Do not send outside local AS (well-known community)\n"
7843 "Do not advertise to any peer (well-known community)\n"
7844 "Do not export to next AS (well-known community)\n"
7845 "community number\n"
7846 "Do not send outside local AS (well-known community)\n"
7847 "Do not advertise to any peer (well-known community)\n"
7848 "Do not export to next AS (well-known community)\n"
7849 "community number\n"
7850 "Do not send outside local AS (well-known community)\n"
7851 "Do not advertise to any peer (well-known community)\n"
7852 "Do not export to next AS (well-known community)\n"
7853 "Exact match of the communities")
7855 DEFUN (show_ip_bgp_ipv4_community_exact,
7856 show_ip_bgp_ipv4_community_exact_cmd,
7857 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7858 SHOW_STR
7859 IP_STR
7860 BGP_STR
7861 "Address family\n"
7862 "Address Family modifier\n"
7863 "Address Family modifier\n"
7864 "Display routes matching the communities\n"
7865 "community number\n"
7866 "Do not send outside local AS (well-known community)\n"
7867 "Do not advertise to any peer (well-known community)\n"
7868 "Do not export to next AS (well-known community)\n"
7869 "Exact match of the communities")
7871 if (strncmp (argv[0], "m", 1) == 0)
7872 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7874 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7877 ALIAS (show_ip_bgp_ipv4_community_exact,
7878 show_ip_bgp_ipv4_community2_exact_cmd,
7879 "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",
7880 SHOW_STR
7881 IP_STR
7882 BGP_STR
7883 "Address family\n"
7884 "Address Family modifier\n"
7885 "Address Family modifier\n"
7886 "Display routes matching the communities\n"
7887 "community number\n"
7888 "Do not send outside local AS (well-known community)\n"
7889 "Do not advertise to any peer (well-known community)\n"
7890 "Do not export to next AS (well-known community)\n"
7891 "community number\n"
7892 "Do not send outside local AS (well-known community)\n"
7893 "Do not advertise to any peer (well-known community)\n"
7894 "Do not export to next AS (well-known community)\n"
7895 "Exact match of the communities")
7897 ALIAS (show_ip_bgp_ipv4_community_exact,
7898 show_ip_bgp_ipv4_community3_exact_cmd,
7899 "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",
7900 SHOW_STR
7901 IP_STR
7902 BGP_STR
7903 "Address family\n"
7904 "Address Family modifier\n"
7905 "Address Family modifier\n"
7906 "Display routes matching the communities\n"
7907 "community number\n"
7908 "Do not send outside local AS (well-known community)\n"
7909 "Do not advertise to any peer (well-known community)\n"
7910 "Do not export to next AS (well-known community)\n"
7911 "community number\n"
7912 "Do not send outside local AS (well-known community)\n"
7913 "Do not advertise to any peer (well-known community)\n"
7914 "Do not export to next AS (well-known community)\n"
7915 "community number\n"
7916 "Do not send outside local AS (well-known community)\n"
7917 "Do not advertise to any peer (well-known community)\n"
7918 "Do not export to next AS (well-known community)\n"
7919 "Exact match of the communities")
7921 ALIAS (show_ip_bgp_ipv4_community_exact,
7922 show_ip_bgp_ipv4_community4_exact_cmd,
7923 "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",
7924 SHOW_STR
7925 IP_STR
7926 BGP_STR
7927 "Address family\n"
7928 "Address Family modifier\n"
7929 "Address Family modifier\n"
7930 "Display routes matching the communities\n"
7931 "community number\n"
7932 "Do not send outside local AS (well-known community)\n"
7933 "Do not advertise to any peer (well-known community)\n"
7934 "Do not export to next AS (well-known community)\n"
7935 "community number\n"
7936 "Do not send outside local AS (well-known community)\n"
7937 "Do not advertise to any peer (well-known community)\n"
7938 "Do not export to next AS (well-known community)\n"
7939 "community number\n"
7940 "Do not send outside local AS (well-known community)\n"
7941 "Do not advertise to any peer (well-known community)\n"
7942 "Do not export to next AS (well-known community)\n"
7943 "community number\n"
7944 "Do not send outside local AS (well-known community)\n"
7945 "Do not advertise to any peer (well-known community)\n"
7946 "Do not export to next AS (well-known community)\n"
7947 "Exact match of the communities")
7949 #ifdef HAVE_IPV6
7950 DEFUN (show_bgp_community,
7951 show_bgp_community_cmd,
7952 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7953 SHOW_STR
7954 BGP_STR
7955 "Display routes matching the communities\n"
7956 "community number\n"
7957 "Do not send outside local AS (well-known community)\n"
7958 "Do not advertise to any peer (well-known community)\n"
7959 "Do not export to next AS (well-known community)\n")
7961 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7964 ALIAS (show_bgp_community,
7965 show_bgp_ipv6_community_cmd,
7966 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7967 SHOW_STR
7968 BGP_STR
7969 "Address family\n"
7970 "Display routes matching the communities\n"
7971 "community number\n"
7972 "Do not send outside local AS (well-known community)\n"
7973 "Do not advertise to any peer (well-known community)\n"
7974 "Do not export to next AS (well-known community)\n")
7976 ALIAS (show_bgp_community,
7977 show_bgp_community2_cmd,
7978 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7979 SHOW_STR
7980 BGP_STR
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"
7986 "community number\n"
7987 "Do not send outside local AS (well-known community)\n"
7988 "Do not advertise to any peer (well-known community)\n"
7989 "Do not export to next AS (well-known community)\n")
7991 ALIAS (show_bgp_community,
7992 show_bgp_ipv6_community2_cmd,
7993 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7994 SHOW_STR
7995 BGP_STR
7996 "Address family\n"
7997 "Display routes matching the communities\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n")
8007 ALIAS (show_bgp_community,
8008 show_bgp_community3_cmd,
8009 "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)",
8010 SHOW_STR
8011 BGP_STR
8012 "Display routes matching the communities\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"
8017 "community number\n"
8018 "Do not send outside local AS (well-known community)\n"
8019 "Do not advertise to any peer (well-known community)\n"
8020 "Do not export to next AS (well-known community)\n"
8021 "community number\n"
8022 "Do not send outside local AS (well-known community)\n"
8023 "Do not advertise to any peer (well-known community)\n"
8024 "Do not export to next AS (well-known community)\n")
8026 ALIAS (show_bgp_community,
8027 show_bgp_ipv6_community3_cmd,
8028 "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)",
8029 SHOW_STR
8030 BGP_STR
8031 "Address family\n"
8032 "Display routes matching the communities\n"
8033 "community number\n"
8034 "Do not send outside local AS (well-known community)\n"
8035 "Do not advertise to any peer (well-known community)\n"
8036 "Do not export to next AS (well-known community)\n"
8037 "community number\n"
8038 "Do not send outside local AS (well-known community)\n"
8039 "Do not advertise to any peer (well-known community)\n"
8040 "Do not export to next AS (well-known community)\n"
8041 "community number\n"
8042 "Do not send outside local AS (well-known community)\n"
8043 "Do not advertise to any peer (well-known community)\n"
8044 "Do not export to next AS (well-known community)\n")
8046 ALIAS (show_bgp_community,
8047 show_bgp_community4_cmd,
8048 "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)",
8049 SHOW_STR
8050 BGP_STR
8051 "Display routes matching the communities\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"
8056 "community number\n"
8057 "Do not send outside local AS (well-known community)\n"
8058 "Do not advertise to any peer (well-known community)\n"
8059 "Do not export to next AS (well-known community)\n"
8060 "community number\n"
8061 "Do not send outside local AS (well-known community)\n"
8062 "Do not advertise to any peer (well-known community)\n"
8063 "Do not export to next AS (well-known community)\n"
8064 "community number\n"
8065 "Do not send outside local AS (well-known community)\n"
8066 "Do not advertise to any peer (well-known community)\n"
8067 "Do not export to next AS (well-known community)\n")
8069 ALIAS (show_bgp_community,
8070 show_bgp_ipv6_community4_cmd,
8071 "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)",
8072 SHOW_STR
8073 BGP_STR
8074 "Address family\n"
8075 "Display routes matching the communities\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n"
8080 "community number\n"
8081 "Do not send outside local AS (well-known community)\n"
8082 "Do not advertise to any peer (well-known community)\n"
8083 "Do not export to next AS (well-known community)\n"
8084 "community number\n"
8085 "Do not send outside local AS (well-known community)\n"
8086 "Do not advertise to any peer (well-known community)\n"
8087 "Do not export to next AS (well-known community)\n"
8088 "community number\n"
8089 "Do not send outside local AS (well-known community)\n"
8090 "Do not advertise to any peer (well-known community)\n"
8091 "Do not export to next AS (well-known community)\n")
8093 /* old command */
8094 DEFUN (show_ipv6_bgp_community,
8095 show_ipv6_bgp_community_cmd,
8096 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8097 SHOW_STR
8098 IPV6_STR
8099 BGP_STR
8100 "Display routes matching the communities\n"
8101 "community number\n"
8102 "Do not send outside local AS (well-known community)\n"
8103 "Do not advertise to any peer (well-known community)\n"
8104 "Do not export to next AS (well-known community)\n")
8106 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8109 /* old command */
8110 ALIAS (show_ipv6_bgp_community,
8111 show_ipv6_bgp_community2_cmd,
8112 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8113 SHOW_STR
8114 IPV6_STR
8115 BGP_STR
8116 "Display routes matching the communities\n"
8117 "community number\n"
8118 "Do not send outside local AS (well-known community)\n"
8119 "Do not advertise to any peer (well-known community)\n"
8120 "Do not export to next AS (well-known community)\n"
8121 "community number\n"
8122 "Do not send outside local AS (well-known community)\n"
8123 "Do not advertise to any peer (well-known community)\n"
8124 "Do not export to next AS (well-known community)\n")
8126 /* old command */
8127 ALIAS (show_ipv6_bgp_community,
8128 show_ipv6_bgp_community3_cmd,
8129 "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)",
8130 SHOW_STR
8131 IPV6_STR
8132 BGP_STR
8133 "Display routes matching the communities\n"
8134 "community number\n"
8135 "Do not send outside local AS (well-known community)\n"
8136 "Do not advertise to any peer (well-known community)\n"
8137 "Do not export to next AS (well-known community)\n"
8138 "community number\n"
8139 "Do not send outside local AS (well-known community)\n"
8140 "Do not advertise to any peer (well-known community)\n"
8141 "Do not export to next AS (well-known community)\n"
8142 "community number\n"
8143 "Do not send outside local AS (well-known community)\n"
8144 "Do not advertise to any peer (well-known community)\n"
8145 "Do not export to next AS (well-known community)\n")
8147 /* old command */
8148 ALIAS (show_ipv6_bgp_community,
8149 show_ipv6_bgp_community4_cmd,
8150 "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)",
8151 SHOW_STR
8152 IPV6_STR
8153 BGP_STR
8154 "Display routes matching the communities\n"
8155 "community number\n"
8156 "Do not send outside local AS (well-known community)\n"
8157 "Do not advertise to any peer (well-known community)\n"
8158 "Do not export to next AS (well-known community)\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n"
8163 "community number\n"
8164 "Do not send outside local AS (well-known community)\n"
8165 "Do not advertise to any peer (well-known community)\n"
8166 "Do not export to next AS (well-known community)\n"
8167 "community number\n"
8168 "Do not send outside local AS (well-known community)\n"
8169 "Do not advertise to any peer (well-known community)\n"
8170 "Do not export to next AS (well-known community)\n")
8172 DEFUN (show_bgp_community_exact,
8173 show_bgp_community_exact_cmd,
8174 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8175 SHOW_STR
8176 BGP_STR
8177 "Display routes matching the communities\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"
8182 "Exact match of the communities")
8184 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8187 ALIAS (show_bgp_community_exact,
8188 show_bgp_ipv6_community_exact_cmd,
8189 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8190 SHOW_STR
8191 BGP_STR
8192 "Address family\n"
8193 "Display routes matching the communities\n"
8194 "community number\n"
8195 "Do not send outside local AS (well-known community)\n"
8196 "Do not advertise to any peer (well-known community)\n"
8197 "Do not export to next AS (well-known community)\n"
8198 "Exact match of the communities")
8200 ALIAS (show_bgp_community_exact,
8201 show_bgp_community2_exact_cmd,
8202 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8203 SHOW_STR
8204 BGP_STR
8205 "Display routes matching the communities\n"
8206 "community number\n"
8207 "Do not send outside local AS (well-known community)\n"
8208 "Do not advertise to any peer (well-known community)\n"
8209 "Do not export to next AS (well-known community)\n"
8210 "community number\n"
8211 "Do not send outside local AS (well-known community)\n"
8212 "Do not advertise to any peer (well-known community)\n"
8213 "Do not export to next AS (well-known community)\n"
8214 "Exact match of the communities")
8216 ALIAS (show_bgp_community_exact,
8217 show_bgp_ipv6_community2_exact_cmd,
8218 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8219 SHOW_STR
8220 BGP_STR
8221 "Address family\n"
8222 "Display routes matching the communities\n"
8223 "community number\n"
8224 "Do not send outside local AS (well-known community)\n"
8225 "Do not advertise to any peer (well-known community)\n"
8226 "Do not export to next AS (well-known community)\n"
8227 "community number\n"
8228 "Do not send outside local AS (well-known community)\n"
8229 "Do not advertise to any peer (well-known community)\n"
8230 "Do not export to next AS (well-known community)\n"
8231 "Exact match of the communities")
8233 ALIAS (show_bgp_community_exact,
8234 show_bgp_community3_exact_cmd,
8235 "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",
8236 SHOW_STR
8237 BGP_STR
8238 "Display routes matching the communities\n"
8239 "community number\n"
8240 "Do not send outside local AS (well-known community)\n"
8241 "Do not advertise to any peer (well-known community)\n"
8242 "Do not export to next AS (well-known community)\n"
8243 "community number\n"
8244 "Do not send outside local AS (well-known community)\n"
8245 "Do not advertise to any peer (well-known community)\n"
8246 "Do not export to next AS (well-known community)\n"
8247 "community number\n"
8248 "Do not send outside local AS (well-known community)\n"
8249 "Do not advertise to any peer (well-known community)\n"
8250 "Do not export to next AS (well-known community)\n"
8251 "Exact match of the communities")
8253 ALIAS (show_bgp_community_exact,
8254 show_bgp_ipv6_community3_exact_cmd,
8255 "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",
8256 SHOW_STR
8257 BGP_STR
8258 "Address family\n"
8259 "Display routes matching the communities\n"
8260 "community number\n"
8261 "Do not send outside local AS (well-known community)\n"
8262 "Do not advertise to any peer (well-known community)\n"
8263 "Do not export to next AS (well-known community)\n"
8264 "community number\n"
8265 "Do not send outside local AS (well-known community)\n"
8266 "Do not advertise to any peer (well-known community)\n"
8267 "Do not export to next AS (well-known community)\n"
8268 "community number\n"
8269 "Do not send outside local AS (well-known community)\n"
8270 "Do not advertise to any peer (well-known community)\n"
8271 "Do not export to next AS (well-known community)\n"
8272 "Exact match of the communities")
8274 ALIAS (show_bgp_community_exact,
8275 show_bgp_community4_exact_cmd,
8276 "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",
8277 SHOW_STR
8278 BGP_STR
8279 "Display routes matching the communities\n"
8280 "community number\n"
8281 "Do not send outside local AS (well-known community)\n"
8282 "Do not advertise to any peer (well-known community)\n"
8283 "Do not export to next AS (well-known community)\n"
8284 "community number\n"
8285 "Do not send outside local AS (well-known community)\n"
8286 "Do not advertise to any peer (well-known community)\n"
8287 "Do not export to next AS (well-known community)\n"
8288 "community number\n"
8289 "Do not send outside local AS (well-known community)\n"
8290 "Do not advertise to any peer (well-known community)\n"
8291 "Do not export to next AS (well-known community)\n"
8292 "community number\n"
8293 "Do not send outside local AS (well-known community)\n"
8294 "Do not advertise to any peer (well-known community)\n"
8295 "Do not export to next AS (well-known community)\n"
8296 "Exact match of the communities")
8298 ALIAS (show_bgp_community_exact,
8299 show_bgp_ipv6_community4_exact_cmd,
8300 "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",
8301 SHOW_STR
8302 BGP_STR
8303 "Address family\n"
8304 "Display routes matching the communities\n"
8305 "community number\n"
8306 "Do not send outside local AS (well-known community)\n"
8307 "Do not advertise to any peer (well-known community)\n"
8308 "Do not export to next AS (well-known community)\n"
8309 "community number\n"
8310 "Do not send outside local AS (well-known community)\n"
8311 "Do not advertise to any peer (well-known community)\n"
8312 "Do not export to next AS (well-known community)\n"
8313 "community number\n"
8314 "Do not send outside local AS (well-known community)\n"
8315 "Do not advertise to any peer (well-known community)\n"
8316 "Do not export to next AS (well-known community)\n"
8317 "community number\n"
8318 "Do not send outside local AS (well-known community)\n"
8319 "Do not advertise to any peer (well-known community)\n"
8320 "Do not export to next AS (well-known community)\n"
8321 "Exact match of the communities")
8323 /* old command */
8324 DEFUN (show_ipv6_bgp_community_exact,
8325 show_ipv6_bgp_community_exact_cmd,
8326 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8327 SHOW_STR
8328 IPV6_STR
8329 BGP_STR
8330 "Display routes matching the communities\n"
8331 "community number\n"
8332 "Do not send outside local AS (well-known community)\n"
8333 "Do not advertise to any peer (well-known community)\n"
8334 "Do not export to next AS (well-known community)\n"
8335 "Exact match of the communities")
8337 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8340 /* old command */
8341 ALIAS (show_ipv6_bgp_community_exact,
8342 show_ipv6_bgp_community2_exact_cmd,
8343 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8344 SHOW_STR
8345 IPV6_STR
8346 BGP_STR
8347 "Display routes matching the communities\n"
8348 "community number\n"
8349 "Do not send outside local AS (well-known community)\n"
8350 "Do not advertise to any peer (well-known community)\n"
8351 "Do not export to next AS (well-known community)\n"
8352 "community number\n"
8353 "Do not send outside local AS (well-known community)\n"
8354 "Do not advertise to any peer (well-known community)\n"
8355 "Do not export to next AS (well-known community)\n"
8356 "Exact match of the communities")
8358 /* old command */
8359 ALIAS (show_ipv6_bgp_community_exact,
8360 show_ipv6_bgp_community3_exact_cmd,
8361 "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",
8362 SHOW_STR
8363 IPV6_STR
8364 BGP_STR
8365 "Display routes matching the communities\n"
8366 "community number\n"
8367 "Do not send outside local AS (well-known community)\n"
8368 "Do not advertise to any peer (well-known community)\n"
8369 "Do not export to next AS (well-known community)\n"
8370 "community number\n"
8371 "Do not send outside local AS (well-known community)\n"
8372 "Do not advertise to any peer (well-known community)\n"
8373 "Do not export to next AS (well-known community)\n"
8374 "community number\n"
8375 "Do not send outside local AS (well-known community)\n"
8376 "Do not advertise to any peer (well-known community)\n"
8377 "Do not export to next AS (well-known community)\n"
8378 "Exact match of the communities")
8380 /* old command */
8381 ALIAS (show_ipv6_bgp_community_exact,
8382 show_ipv6_bgp_community4_exact_cmd,
8383 "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",
8384 SHOW_STR
8385 IPV6_STR
8386 BGP_STR
8387 "Display routes matching the communities\n"
8388 "community number\n"
8389 "Do not send outside local AS (well-known community)\n"
8390 "Do not advertise to any peer (well-known community)\n"
8391 "Do not export to next AS (well-known community)\n"
8392 "community number\n"
8393 "Do not send outside local AS (well-known community)\n"
8394 "Do not advertise to any peer (well-known community)\n"
8395 "Do not export to next AS (well-known community)\n"
8396 "community number\n"
8397 "Do not send outside local AS (well-known community)\n"
8398 "Do not advertise to any peer (well-known community)\n"
8399 "Do not export to next AS (well-known community)\n"
8400 "community number\n"
8401 "Do not send outside local AS (well-known community)\n"
8402 "Do not advertise to any peer (well-known community)\n"
8403 "Do not export to next AS (well-known community)\n"
8404 "Exact match of the communities")
8406 /* old command */
8407 DEFUN (show_ipv6_mbgp_community,
8408 show_ipv6_mbgp_community_cmd,
8409 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8410 SHOW_STR
8411 IPV6_STR
8412 MBGP_STR
8413 "Display routes matching the communities\n"
8414 "community number\n"
8415 "Do not send outside local AS (well-known community)\n"
8416 "Do not advertise to any peer (well-known community)\n"
8417 "Do not export to next AS (well-known community)\n")
8419 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8422 /* old command */
8423 ALIAS (show_ipv6_mbgp_community,
8424 show_ipv6_mbgp_community2_cmd,
8425 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8426 SHOW_STR
8427 IPV6_STR
8428 MBGP_STR
8429 "Display routes matching the communities\n"
8430 "community number\n"
8431 "Do not send outside local AS (well-known community)\n"
8432 "Do not advertise to any peer (well-known community)\n"
8433 "Do not export to next AS (well-known community)\n"
8434 "community number\n"
8435 "Do not send outside local AS (well-known community)\n"
8436 "Do not advertise to any peer (well-known community)\n"
8437 "Do not export to next AS (well-known community)\n")
8439 /* old command */
8440 ALIAS (show_ipv6_mbgp_community,
8441 show_ipv6_mbgp_community3_cmd,
8442 "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)",
8443 SHOW_STR
8444 IPV6_STR
8445 MBGP_STR
8446 "Display routes matching the communities\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n"
8455 "community number\n"
8456 "Do not send outside local AS (well-known community)\n"
8457 "Do not advertise to any peer (well-known community)\n"
8458 "Do not export to next AS (well-known community)\n")
8460 /* old command */
8461 ALIAS (show_ipv6_mbgp_community,
8462 show_ipv6_mbgp_community4_cmd,
8463 "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)",
8464 SHOW_STR
8465 IPV6_STR
8466 MBGP_STR
8467 "Display routes matching the communities\n"
8468 "community number\n"
8469 "Do not send outside local AS (well-known community)\n"
8470 "Do not advertise to any peer (well-known community)\n"
8471 "Do not export to next AS (well-known community)\n"
8472 "community number\n"
8473 "Do not send outside local AS (well-known community)\n"
8474 "Do not advertise to any peer (well-known community)\n"
8475 "Do not export to next AS (well-known community)\n"
8476 "community number\n"
8477 "Do not send outside local AS (well-known community)\n"
8478 "Do not advertise to any peer (well-known community)\n"
8479 "Do not export to next AS (well-known community)\n"
8480 "community number\n"
8481 "Do not send outside local AS (well-known community)\n"
8482 "Do not advertise to any peer (well-known community)\n"
8483 "Do not export to next AS (well-known community)\n")
8485 /* old command */
8486 DEFUN (show_ipv6_mbgp_community_exact,
8487 show_ipv6_mbgp_community_exact_cmd,
8488 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8489 SHOW_STR
8490 IPV6_STR
8491 MBGP_STR
8492 "Display routes matching the communities\n"
8493 "community number\n"
8494 "Do not send outside local AS (well-known community)\n"
8495 "Do not advertise to any peer (well-known community)\n"
8496 "Do not export to next AS (well-known community)\n"
8497 "Exact match of the communities")
8499 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8502 /* old command */
8503 ALIAS (show_ipv6_mbgp_community_exact,
8504 show_ipv6_mbgp_community2_exact_cmd,
8505 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8506 SHOW_STR
8507 IPV6_STR
8508 MBGP_STR
8509 "Display routes matching the communities\n"
8510 "community number\n"
8511 "Do not send outside local AS (well-known community)\n"
8512 "Do not advertise to any peer (well-known community)\n"
8513 "Do not export to next AS (well-known community)\n"
8514 "community number\n"
8515 "Do not send outside local AS (well-known community)\n"
8516 "Do not advertise to any peer (well-known community)\n"
8517 "Do not export to next AS (well-known community)\n"
8518 "Exact match of the communities")
8520 /* old command */
8521 ALIAS (show_ipv6_mbgp_community_exact,
8522 show_ipv6_mbgp_community3_exact_cmd,
8523 "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",
8524 SHOW_STR
8525 IPV6_STR
8526 MBGP_STR
8527 "Display routes matching the communities\n"
8528 "community number\n"
8529 "Do not send outside local AS (well-known community)\n"
8530 "Do not advertise to any peer (well-known community)\n"
8531 "Do not export to next AS (well-known community)\n"
8532 "community number\n"
8533 "Do not send outside local AS (well-known community)\n"
8534 "Do not advertise to any peer (well-known community)\n"
8535 "Do not export to next AS (well-known community)\n"
8536 "community number\n"
8537 "Do not send outside local AS (well-known community)\n"
8538 "Do not advertise to any peer (well-known community)\n"
8539 "Do not export to next AS (well-known community)\n"
8540 "Exact match of the communities")
8542 /* old command */
8543 ALIAS (show_ipv6_mbgp_community_exact,
8544 show_ipv6_mbgp_community4_exact_cmd,
8545 "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",
8546 SHOW_STR
8547 IPV6_STR
8548 MBGP_STR
8549 "Display routes matching the communities\n"
8550 "community number\n"
8551 "Do not send outside local AS (well-known community)\n"
8552 "Do not advertise to any peer (well-known community)\n"
8553 "Do not export to next AS (well-known community)\n"
8554 "community number\n"
8555 "Do not send outside local AS (well-known community)\n"
8556 "Do not advertise to any peer (well-known community)\n"
8557 "Do not export to next AS (well-known community)\n"
8558 "community number\n"
8559 "Do not send outside local AS (well-known community)\n"
8560 "Do not advertise to any peer (well-known community)\n"
8561 "Do not export to next AS (well-known community)\n"
8562 "community number\n"
8563 "Do not send outside local AS (well-known community)\n"
8564 "Do not advertise to any peer (well-known community)\n"
8565 "Do not export to next AS (well-known community)\n"
8566 "Exact match of the communities")
8567 #endif /* HAVE_IPV6 */
8569 static int
8570 bgp_show_community_list (struct vty *vty, const char *com, int exact,
8571 u_int16_t afi, u_char safi)
8573 struct community_list *list;
8575 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
8576 if (list == NULL)
8578 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8579 VTY_NEWLINE);
8580 return CMD_WARNING;
8583 return bgp_show (vty, NULL, afi, safi,
8584 (exact ? bgp_show_type_community_list_exact :
8585 bgp_show_type_community_list), list);
8588 DEFUN (show_ip_bgp_community_list,
8589 show_ip_bgp_community_list_cmd,
8590 "show ip bgp community-list (<1-500>|WORD)",
8591 SHOW_STR
8592 IP_STR
8593 BGP_STR
8594 "Display routes matching the community-list\n"
8595 "community-list number\n"
8596 "community-list name\n")
8598 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8601 DEFUN (show_ip_bgp_ipv4_community_list,
8602 show_ip_bgp_ipv4_community_list_cmd,
8603 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
8604 SHOW_STR
8605 IP_STR
8606 BGP_STR
8607 "Address family\n"
8608 "Address Family modifier\n"
8609 "Address Family modifier\n"
8610 "Display routes matching the community-list\n"
8611 "community-list number\n"
8612 "community-list name\n")
8614 if (strncmp (argv[0], "m", 1) == 0)
8615 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8617 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8620 DEFUN (show_ip_bgp_community_list_exact,
8621 show_ip_bgp_community_list_exact_cmd,
8622 "show ip bgp community-list (<1-500>|WORD) exact-match",
8623 SHOW_STR
8624 IP_STR
8625 BGP_STR
8626 "Display routes matching the community-list\n"
8627 "community-list number\n"
8628 "community-list name\n"
8629 "Exact match of the communities\n")
8631 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8634 DEFUN (show_ip_bgp_ipv4_community_list_exact,
8635 show_ip_bgp_ipv4_community_list_exact_cmd,
8636 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
8637 SHOW_STR
8638 IP_STR
8639 BGP_STR
8640 "Address family\n"
8641 "Address Family modifier\n"
8642 "Address Family modifier\n"
8643 "Display routes matching the community-list\n"
8644 "community-list number\n"
8645 "community-list name\n"
8646 "Exact match of the communities\n")
8648 if (strncmp (argv[0], "m", 1) == 0)
8649 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8651 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8654 #ifdef HAVE_IPV6
8655 DEFUN (show_bgp_community_list,
8656 show_bgp_community_list_cmd,
8657 "show bgp community-list (<1-500>|WORD)",
8658 SHOW_STR
8659 BGP_STR
8660 "Display routes matching the community-list\n"
8661 "community-list number\n"
8662 "community-list name\n")
8664 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8667 ALIAS (show_bgp_community_list,
8668 show_bgp_ipv6_community_list_cmd,
8669 "show bgp ipv6 community-list (<1-500>|WORD)",
8670 SHOW_STR
8671 BGP_STR
8672 "Address family\n"
8673 "Display routes matching the community-list\n"
8674 "community-list number\n"
8675 "community-list name\n")
8677 /* old command */
8678 DEFUN (show_ipv6_bgp_community_list,
8679 show_ipv6_bgp_community_list_cmd,
8680 "show ipv6 bgp community-list WORD",
8681 SHOW_STR
8682 IPV6_STR
8683 BGP_STR
8684 "Display routes matching the community-list\n"
8685 "community-list name\n")
8687 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8690 /* old command */
8691 DEFUN (show_ipv6_mbgp_community_list,
8692 show_ipv6_mbgp_community_list_cmd,
8693 "show ipv6 mbgp community-list WORD",
8694 SHOW_STR
8695 IPV6_STR
8696 MBGP_STR
8697 "Display routes matching the community-list\n"
8698 "community-list name\n")
8700 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8703 DEFUN (show_bgp_community_list_exact,
8704 show_bgp_community_list_exact_cmd,
8705 "show bgp community-list (<1-500>|WORD) exact-match",
8706 SHOW_STR
8707 BGP_STR
8708 "Display routes matching the community-list\n"
8709 "community-list number\n"
8710 "community-list name\n"
8711 "Exact match of the communities\n")
8713 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8716 ALIAS (show_bgp_community_list_exact,
8717 show_bgp_ipv6_community_list_exact_cmd,
8718 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
8719 SHOW_STR
8720 BGP_STR
8721 "Address family\n"
8722 "Display routes matching the community-list\n"
8723 "community-list number\n"
8724 "community-list name\n"
8725 "Exact match of the communities\n")
8727 /* old command */
8728 DEFUN (show_ipv6_bgp_community_list_exact,
8729 show_ipv6_bgp_community_list_exact_cmd,
8730 "show ipv6 bgp community-list WORD exact-match",
8731 SHOW_STR
8732 IPV6_STR
8733 BGP_STR
8734 "Display routes matching the community-list\n"
8735 "community-list name\n"
8736 "Exact match of the communities\n")
8738 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8741 /* old command */
8742 DEFUN (show_ipv6_mbgp_community_list_exact,
8743 show_ipv6_mbgp_community_list_exact_cmd,
8744 "show ipv6 mbgp community-list WORD exact-match",
8745 SHOW_STR
8746 IPV6_STR
8747 MBGP_STR
8748 "Display routes matching the community-list\n"
8749 "community-list name\n"
8750 "Exact match of the communities\n")
8752 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8754 #endif /* HAVE_IPV6 */
8756 static int
8757 bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
8758 safi_t safi, enum bgp_show_type type)
8760 int ret;
8761 struct prefix *p;
8763 p = prefix_new();
8765 ret = str2prefix (prefix, p);
8766 if (! ret)
8768 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8769 return CMD_WARNING;
8772 ret = bgp_show (vty, NULL, afi, safi, type, p);
8773 prefix_free(p);
8774 return ret;
8777 DEFUN (show_ip_bgp_prefix_longer,
8778 show_ip_bgp_prefix_longer_cmd,
8779 "show ip bgp A.B.C.D/M longer-prefixes",
8780 SHOW_STR
8781 IP_STR
8782 BGP_STR
8783 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8784 "Display route and more specific routes\n")
8786 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8787 bgp_show_type_prefix_longer);
8790 DEFUN (show_ip_bgp_flap_prefix_longer,
8791 show_ip_bgp_flap_prefix_longer_cmd,
8792 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8793 SHOW_STR
8794 IP_STR
8795 BGP_STR
8796 "Display flap statistics of routes\n"
8797 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8798 "Display route and more specific routes\n")
8800 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8801 bgp_show_type_flap_prefix_longer);
8804 DEFUN (show_ip_bgp_ipv4_prefix_longer,
8805 show_ip_bgp_ipv4_prefix_longer_cmd,
8806 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8807 SHOW_STR
8808 IP_STR
8809 BGP_STR
8810 "Address family\n"
8811 "Address Family modifier\n"
8812 "Address Family modifier\n"
8813 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8814 "Display route and more specific routes\n")
8816 if (strncmp (argv[0], "m", 1) == 0)
8817 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8818 bgp_show_type_prefix_longer);
8820 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8821 bgp_show_type_prefix_longer);
8824 DEFUN (show_ip_bgp_flap_address,
8825 show_ip_bgp_flap_address_cmd,
8826 "show ip bgp flap-statistics A.B.C.D",
8827 SHOW_STR
8828 IP_STR
8829 BGP_STR
8830 "Display flap statistics of routes\n"
8831 "Network in the BGP routing table to display\n")
8833 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8834 bgp_show_type_flap_address);
8837 DEFUN (show_ip_bgp_flap_prefix,
8838 show_ip_bgp_flap_prefix_cmd,
8839 "show ip bgp flap-statistics A.B.C.D/M",
8840 SHOW_STR
8841 IP_STR
8842 BGP_STR
8843 "Display flap statistics of routes\n"
8844 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8846 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8847 bgp_show_type_flap_prefix);
8849 #ifdef HAVE_IPV6
8850 DEFUN (show_bgp_prefix_longer,
8851 show_bgp_prefix_longer_cmd,
8852 "show bgp X:X::X:X/M longer-prefixes",
8853 SHOW_STR
8854 BGP_STR
8855 "IPv6 prefix <network>/<length>\n"
8856 "Display route and more specific routes\n")
8858 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8859 bgp_show_type_prefix_longer);
8862 ALIAS (show_bgp_prefix_longer,
8863 show_bgp_ipv6_prefix_longer_cmd,
8864 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8865 SHOW_STR
8866 BGP_STR
8867 "Address family\n"
8868 "IPv6 prefix <network>/<length>\n"
8869 "Display route and more specific routes\n")
8871 /* old command */
8872 DEFUN (show_ipv6_bgp_prefix_longer,
8873 show_ipv6_bgp_prefix_longer_cmd,
8874 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8875 SHOW_STR
8876 IPV6_STR
8877 BGP_STR
8878 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8879 "Display route and more specific routes\n")
8881 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8882 bgp_show_type_prefix_longer);
8885 /* old command */
8886 DEFUN (show_ipv6_mbgp_prefix_longer,
8887 show_ipv6_mbgp_prefix_longer_cmd,
8888 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8889 SHOW_STR
8890 IPV6_STR
8891 MBGP_STR
8892 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8893 "Display route and more specific routes\n")
8895 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8896 bgp_show_type_prefix_longer);
8898 #endif /* HAVE_IPV6 */
8900 static struct peer *
8901 peer_lookup_in_view (struct vty *vty, const char *view_name,
8902 const char *ip_str)
8904 int ret;
8905 struct bgp *bgp;
8906 struct peer *peer;
8907 union sockunion su;
8909 /* BGP structure lookup. */
8910 if (view_name)
8912 bgp = bgp_lookup_by_name (view_name);
8913 if (! bgp)
8915 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8916 return NULL;
8919 else
8921 bgp = bgp_get_default ();
8922 if (! bgp)
8924 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8925 return NULL;
8929 /* Get peer sockunion. */
8930 ret = str2sockunion (ip_str, &su);
8931 if (ret < 0)
8933 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8934 return NULL;
8937 /* Peer structure lookup. */
8938 peer = peer_lookup (bgp, &su);
8939 if (! peer)
8941 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8942 return NULL;
8945 return peer;
8948 enum bgp_stats
8950 BGP_STATS_MAXBITLEN = 0,
8951 BGP_STATS_RIB,
8952 BGP_STATS_PREFIXES,
8953 BGP_STATS_TOTPLEN,
8954 BGP_STATS_UNAGGREGATEABLE,
8955 BGP_STATS_MAX_AGGREGATEABLE,
8956 BGP_STATS_AGGREGATES,
8957 BGP_STATS_SPACE,
8958 BGP_STATS_ASPATH_COUNT,
8959 BGP_STATS_ASPATH_MAXHOPS,
8960 BGP_STATS_ASPATH_TOTHOPS,
8961 BGP_STATS_ASPATH_MAXSIZE,
8962 BGP_STATS_ASPATH_TOTSIZE,
8963 BGP_STATS_ASN_HIGHEST,
8964 BGP_STATS_MAX,
8967 static const char *table_stats_strs[] =
8969 [BGP_STATS_PREFIXES] = "Total Prefixes",
8970 [BGP_STATS_TOTPLEN] = "Average prefix length",
8971 [BGP_STATS_RIB] = "Total Advertisements",
8972 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8973 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8974 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8975 [BGP_STATS_SPACE] = "Address space advertised",
8976 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8977 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8978 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8979 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8980 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8981 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8982 [BGP_STATS_MAX] = NULL,
8985 struct bgp_table_stats
8987 struct bgp_table *table;
8988 unsigned long long counts[BGP_STATS_MAX];
8991 #if 0
8992 #define TALLY_SIGFIG 100000
8993 static unsigned long
8994 ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8996 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8997 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8998 unsigned long ret = newtot / count;
9000 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9001 return ret + 1;
9002 else
9003 return ret;
9005 #endif
9007 static int
9008 bgp_table_stats_walker (struct thread *t)
9010 struct bgp_node *rn;
9011 struct bgp_node *top;
9012 struct bgp_table_stats *ts = THREAD_ARG (t);
9013 unsigned int space = 0;
9015 if (!(top = bgp_table_top (ts->table)))
9016 return 0;
9018 switch (top->p.family)
9020 case AF_INET:
9021 space = IPV4_MAX_BITLEN;
9022 break;
9023 case AF_INET6:
9024 space = IPV6_MAX_BITLEN;
9025 break;
9028 ts->counts[BGP_STATS_MAXBITLEN] = space;
9030 for (rn = top; rn; rn = bgp_route_next (rn))
9032 struct bgp_info *ri;
9033 struct bgp_node *prn = rn->parent;
9034 unsigned int rinum = 0;
9036 if (rn == top)
9037 continue;
9039 if (!rn->info)
9040 continue;
9042 ts->counts[BGP_STATS_PREFIXES]++;
9043 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9045 #if 0
9046 ts->counts[BGP_STATS_AVGPLEN]
9047 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9048 ts->counts[BGP_STATS_AVGPLEN],
9049 rn->p.prefixlen);
9050 #endif
9052 /* check if the prefix is included by any other announcements */
9053 while (prn && !prn->info)
9054 prn = prn->parent;
9056 if (prn == NULL || prn == top)
9058 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9059 /* announced address space */
9060 if (space)
9061 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9063 else if (prn->info)
9064 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9066 for (ri = rn->info; ri; ri = ri->next)
9068 rinum++;
9069 ts->counts[BGP_STATS_RIB]++;
9071 if (ri->attr &&
9072 (CHECK_FLAG (ri->attr->flag,
9073 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9074 ts->counts[BGP_STATS_AGGREGATES]++;
9076 /* as-path stats */
9077 if (ri->attr && ri->attr->aspath)
9079 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9080 unsigned int size = aspath_size (ri->attr->aspath);
9081 as_t highest = aspath_highest (ri->attr->aspath);
9083 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9085 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9086 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9088 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9089 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9091 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9092 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9093 #if 0
9094 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9095 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9096 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9097 hops);
9098 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9099 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9100 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9101 size);
9102 #endif
9103 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9104 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9108 return 0;
9111 static int
9112 bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9114 struct bgp_table_stats ts;
9115 unsigned int i;
9117 if (!bgp->rib[afi][safi])
9119 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9120 return CMD_WARNING;
9123 memset (&ts, 0, sizeof (ts));
9124 ts.table = bgp->rib[afi][safi];
9125 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9127 vty_out (vty, "BGP %s RIB statistics%s%s",
9128 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9130 for (i = 0; i < BGP_STATS_MAX; i++)
9132 if (!table_stats_strs[i])
9133 continue;
9135 switch (i)
9137 #if 0
9138 case BGP_STATS_ASPATH_AVGHOPS:
9139 case BGP_STATS_ASPATH_AVGSIZE:
9140 case BGP_STATS_AVGPLEN:
9141 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9142 vty_out (vty, "%12.2f",
9143 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9144 break;
9145 #endif
9146 case BGP_STATS_ASPATH_TOTHOPS:
9147 case BGP_STATS_ASPATH_TOTSIZE:
9148 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9149 vty_out (vty, "%12.2f",
9150 ts.counts[i] ?
9151 (float)ts.counts[i] /
9152 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9153 : 0);
9154 break;
9155 case BGP_STATS_TOTPLEN:
9156 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9157 vty_out (vty, "%12.2f",
9158 ts.counts[i] ?
9159 (float)ts.counts[i] /
9160 (float)ts.counts[BGP_STATS_PREFIXES]
9161 : 0);
9162 break;
9163 case BGP_STATS_SPACE:
9164 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9165 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9166 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9167 break;
9168 vty_out (vty, "%30s: ", "%% announced ");
9169 vty_out (vty, "%12.2f%s",
9170 100 * (float)ts.counts[BGP_STATS_SPACE] /
9171 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
9172 VTY_NEWLINE);
9173 vty_out (vty, "%30s: ", "/8 equivalent ");
9174 vty_out (vty, "%12.2f%s",
9175 (float)ts.counts[BGP_STATS_SPACE] /
9176 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9177 VTY_NEWLINE);
9178 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9179 break;
9180 vty_out (vty, "%30s: ", "/24 equivalent ");
9181 vty_out (vty, "%12.2f",
9182 (float)ts.counts[BGP_STATS_SPACE] /
9183 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9184 break;
9185 default:
9186 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9187 vty_out (vty, "%12llu", ts.counts[i]);
9190 vty_out (vty, "%s", VTY_NEWLINE);
9192 return CMD_SUCCESS;
9195 static int
9196 bgp_table_stats_vty (struct vty *vty, const char *name,
9197 const char *afi_str, const char *safi_str)
9199 struct bgp *bgp;
9200 afi_t afi;
9201 safi_t safi;
9203 if (name)
9204 bgp = bgp_lookup_by_name (name);
9205 else
9206 bgp = bgp_get_default ();
9208 if (!bgp)
9210 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9211 return CMD_WARNING;
9213 if (strncmp (afi_str, "ipv", 3) == 0)
9215 if (strncmp (afi_str, "ipv4", 4) == 0)
9216 afi = AFI_IP;
9217 else if (strncmp (afi_str, "ipv6", 4) == 0)
9218 afi = AFI_IP6;
9219 else
9221 vty_out (vty, "%% Invalid address family %s%s",
9222 afi_str, VTY_NEWLINE);
9223 return CMD_WARNING;
9225 if (strncmp (safi_str, "m", 1) == 0)
9226 safi = SAFI_MULTICAST;
9227 else if (strncmp (safi_str, "u", 1) == 0)
9228 safi = SAFI_UNICAST;
9229 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9230 safi = BGP_SAFI_VPNV4;
9231 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9232 safi = BGP_SAFI_VPNV6;
9233 else
9235 vty_out (vty, "%% Invalid subsequent address family %s%s",
9236 safi_str, VTY_NEWLINE);
9237 return CMD_WARNING;
9240 else
9242 vty_out (vty, "%% Invalid address family %s%s",
9243 afi_str, VTY_NEWLINE);
9244 return CMD_WARNING;
9247 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9248 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9250 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9251 afi_str, safi_str, VTY_NEWLINE);
9252 return CMD_WARNING;
9254 return bgp_table_stats (vty, bgp, afi, safi);
9257 DEFUN (show_bgp_statistics,
9258 show_bgp_statistics_cmd,
9259 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9260 SHOW_STR
9261 BGP_STR
9262 "Address family\n"
9263 "Address family\n"
9264 "Address Family modifier\n"
9265 "Address Family modifier\n"
9266 "BGP RIB advertisement statistics\n")
9268 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9271 ALIAS (show_bgp_statistics,
9272 show_bgp_statistics_vpnv4_cmd,
9273 "show bgp (ipv4) (vpnv4) statistics",
9274 SHOW_STR
9275 BGP_STR
9276 "Address family\n"
9277 "Address Family modifier\n"
9278 "BGP RIB advertisement statistics\n")
9280 DEFUN (show_bgp_statistics_view,
9281 show_bgp_statistics_view_cmd,
9282 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9283 SHOW_STR
9284 BGP_STR
9285 "BGP view\n"
9286 "Address family\n"
9287 "Address family\n"
9288 "Address Family modifier\n"
9289 "Address Family modifier\n"
9290 "BGP RIB advertisement statistics\n")
9292 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9295 ALIAS (show_bgp_statistics_view,
9296 show_bgp_statistics_view_vpnv4_cmd,
9297 "show bgp view WORD (ipv4) (vpnv4) statistics",
9298 SHOW_STR
9299 BGP_STR
9300 "BGP view\n"
9301 "Address family\n"
9302 "Address Family modifier\n"
9303 "BGP RIB advertisement statistics\n")
9305 enum bgp_pcounts
9307 PCOUNT_ADJ_IN = 0,
9308 PCOUNT_DAMPED,
9309 PCOUNT_REMOVED,
9310 PCOUNT_HISTORY,
9311 PCOUNT_STALE,
9312 PCOUNT_VALID,
9313 PCOUNT_ALL,
9314 PCOUNT_COUNTED,
9315 PCOUNT_PFCNT, /* the figure we display to users */
9316 PCOUNT_MAX,
9319 static const char *pcount_strs[] =
9321 [PCOUNT_ADJ_IN] = "Adj-in",
9322 [PCOUNT_DAMPED] = "Damped",
9323 [PCOUNT_REMOVED] = "Removed",
9324 [PCOUNT_HISTORY] = "History",
9325 [PCOUNT_STALE] = "Stale",
9326 [PCOUNT_VALID] = "Valid",
9327 [PCOUNT_ALL] = "All RIB",
9328 [PCOUNT_COUNTED] = "PfxCt counted",
9329 [PCOUNT_PFCNT] = "Useable",
9330 [PCOUNT_MAX] = NULL,
9333 struct peer_pcounts
9335 unsigned int count[PCOUNT_MAX];
9336 const struct peer *peer;
9337 const struct bgp_table *table;
9340 static int
9341 bgp_peer_count_walker (struct thread *t)
9343 struct bgp_node *rn;
9344 struct peer_pcounts *pc = THREAD_ARG (t);
9345 const struct peer *peer = pc->peer;
9347 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
9349 struct bgp_adj_in *ain;
9350 struct bgp_info *ri;
9352 for (ain = rn->adj_in; ain; ain = ain->next)
9353 if (ain->peer == peer)
9354 pc->count[PCOUNT_ADJ_IN]++;
9356 for (ri = rn->info; ri; ri = ri->next)
9358 char buf[SU_ADDRSTRLEN];
9360 if (ri->peer != peer)
9361 continue;
9363 pc->count[PCOUNT_ALL]++;
9365 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
9366 pc->count[PCOUNT_DAMPED]++;
9367 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
9368 pc->count[PCOUNT_HISTORY]++;
9369 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
9370 pc->count[PCOUNT_REMOVED]++;
9371 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
9372 pc->count[PCOUNT_STALE]++;
9373 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
9374 pc->count[PCOUNT_VALID]++;
9375 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
9376 pc->count[PCOUNT_PFCNT]++;
9378 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9380 pc->count[PCOUNT_COUNTED]++;
9381 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
9382 plog_warn (peer->log,
9383 "%s [pcount] %s/%d is counted but flags 0x%x",
9384 peer->host,
9385 inet_ntop(rn->p.family, &rn->p.u.prefix,
9386 buf, SU_ADDRSTRLEN),
9387 rn->p.prefixlen,
9388 ri->flags);
9390 else
9392 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
9393 plog_warn (peer->log,
9394 "%s [pcount] %s/%d not 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);
9403 return 0;
9406 static int
9407 bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9409 struct peer_pcounts pcounts = { .peer = peer };
9410 unsigned int i;
9412 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9413 || !peer->bgp->rib[afi][safi])
9415 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9416 return CMD_WARNING;
9419 memset (&pcounts, 0, sizeof(pcounts));
9420 pcounts.peer = peer;
9421 pcounts.table = peer->bgp->rib[afi][safi];
9423 /* in-place call via thread subsystem so as to record execution time
9424 * stats for the thread-walk (i.e. ensure this can't be blamed on
9425 * on just vty_read()).
9427 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9429 vty_out (vty, "Prefix counts for %s, %s%s",
9430 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9431 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9432 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9433 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9435 for (i = 0; i < PCOUNT_MAX; i++)
9436 vty_out (vty, "%20s: %-10d%s",
9437 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
9439 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
9441 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9442 peer->host, VTY_NEWLINE);
9443 vty_out (vty, "Please report this bug, with the above command output%s",
9444 VTY_NEWLINE);
9447 return CMD_SUCCESS;
9450 DEFUN (show_ip_bgp_neighbor_prefix_counts,
9451 show_ip_bgp_neighbor_prefix_counts_cmd,
9452 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9453 SHOW_STR
9454 IP_STR
9455 BGP_STR
9456 "Detailed information on TCP and BGP neighbor connections\n"
9457 "Neighbor to display information about\n"
9458 "Neighbor to display information about\n"
9459 "Display detailed prefix count information\n")
9461 struct peer *peer;
9463 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9464 if (! peer)
9465 return CMD_WARNING;
9467 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9470 DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9471 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9472 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9473 SHOW_STR
9474 BGP_STR
9475 "Address family\n"
9476 "Detailed information on TCP and BGP neighbor connections\n"
9477 "Neighbor to display information about\n"
9478 "Neighbor to display information about\n"
9479 "Display detailed prefix count information\n")
9481 struct peer *peer;
9483 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9484 if (! peer)
9485 return CMD_WARNING;
9487 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9490 DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9491 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9492 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9493 SHOW_STR
9494 IP_STR
9495 BGP_STR
9496 "Address family\n"
9497 "Address Family modifier\n"
9498 "Address Family modifier\n"
9499 "Detailed information on TCP and BGP neighbor connections\n"
9500 "Neighbor to display information about\n"
9501 "Neighbor to display information about\n"
9502 "Display detailed prefix count information\n")
9504 struct peer *peer;
9506 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9507 if (! peer)
9508 return CMD_WARNING;
9510 if (strncmp (argv[0], "m", 1) == 0)
9511 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9513 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9516 DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9517 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9518 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9519 SHOW_STR
9520 IP_STR
9521 BGP_STR
9522 "Address family\n"
9523 "Address Family modifier\n"
9524 "Address Family modifier\n"
9525 "Detailed information on TCP and BGP neighbor connections\n"
9526 "Neighbor to display information about\n"
9527 "Neighbor to display information about\n"
9528 "Display detailed prefix count information\n")
9530 struct peer *peer;
9532 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9533 if (! peer)
9534 return CMD_WARNING;
9536 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9540 static void
9541 show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9542 int in)
9544 struct bgp_table *table;
9545 struct bgp_adj_in *ain;
9546 struct bgp_adj_out *adj;
9547 unsigned long output_count;
9548 struct bgp_node *rn;
9549 int header1 = 1;
9550 struct bgp *bgp;
9551 int header2 = 1;
9553 bgp = peer->bgp;
9555 if (! bgp)
9556 return;
9558 table = bgp->rib[afi][safi];
9560 output_count = 0;
9562 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9563 PEER_STATUS_DEFAULT_ORIGINATE))
9565 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
9566 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9567 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9569 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9570 VTY_NEWLINE, VTY_NEWLINE);
9571 header1 = 0;
9574 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9575 if (in)
9577 for (ain = rn->adj_in; ain; ain = ain->next)
9578 if (ain->peer == peer)
9580 if (header1)
9582 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
9583 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9584 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9585 header1 = 0;
9587 if (header2)
9589 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9590 header2 = 0;
9592 if (ain->attr)
9594 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9595 output_count++;
9599 else
9601 for (adj = rn->adj_out; adj; adj = adj->next)
9602 if (adj->peer == peer)
9604 if (header1)
9606 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
9607 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9608 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9609 header1 = 0;
9611 if (header2)
9613 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9614 header2 = 0;
9616 if (adj->attr)
9618 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9619 output_count++;
9624 if (output_count != 0)
9625 vty_out (vty, "%sTotal number of prefixes %ld%s",
9626 VTY_NEWLINE, output_count, VTY_NEWLINE);
9629 static int
9630 peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9632 if (! peer || ! peer->afc[afi][safi])
9634 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9635 return CMD_WARNING;
9638 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9640 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9641 VTY_NEWLINE);
9642 return CMD_WARNING;
9645 show_adj_route (vty, peer, afi, safi, in);
9647 return CMD_SUCCESS;
9650 DEFUN (show_ip_bgp_neighbor_advertised_route,
9651 show_ip_bgp_neighbor_advertised_route_cmd,
9652 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9653 SHOW_STR
9654 IP_STR
9655 BGP_STR
9656 "Detailed information on TCP and BGP neighbor connections\n"
9657 "Neighbor to display information about\n"
9658 "Neighbor to display information about\n"
9659 "Display the routes advertised to a BGP neighbor\n")
9661 struct peer *peer;
9663 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9664 if (! peer)
9665 return CMD_WARNING;
9667 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9670 DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9671 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9672 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9673 SHOW_STR
9674 IP_STR
9675 BGP_STR
9676 "Address family\n"
9677 "Address Family modifier\n"
9678 "Address Family modifier\n"
9679 "Detailed information on TCP and BGP neighbor connections\n"
9680 "Neighbor to display information about\n"
9681 "Neighbor to display information about\n"
9682 "Display the routes advertised to a BGP neighbor\n")
9684 struct peer *peer;
9686 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9687 if (! peer)
9688 return CMD_WARNING;
9690 if (strncmp (argv[0], "m", 1) == 0)
9691 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9693 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9696 #ifdef HAVE_IPV6
9697 DEFUN (show_bgp_view_neighbor_advertised_route,
9698 show_bgp_view_neighbor_advertised_route_cmd,
9699 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9700 SHOW_STR
9701 BGP_STR
9702 "BGP view\n"
9703 "View name\n"
9704 "Detailed information on TCP and BGP neighbor connections\n"
9705 "Neighbor to display information about\n"
9706 "Neighbor to display information about\n"
9707 "Display the routes advertised to a BGP neighbor\n")
9709 struct peer *peer;
9711 if (argc == 2)
9712 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9713 else
9714 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9716 if (! peer)
9717 return CMD_WARNING;
9719 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9722 ALIAS (show_bgp_view_neighbor_advertised_route,
9723 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9724 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9725 SHOW_STR
9726 BGP_STR
9727 "BGP view\n"
9728 "View name\n"
9729 "Address family\n"
9730 "Detailed information on TCP and BGP neighbor connections\n"
9731 "Neighbor to display information about\n"
9732 "Neighbor to display information about\n"
9733 "Display the routes advertised to a BGP neighbor\n")
9735 DEFUN (show_bgp_view_neighbor_received_routes,
9736 show_bgp_view_neighbor_received_routes_cmd,
9737 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9738 SHOW_STR
9739 BGP_STR
9740 "BGP view\n"
9741 "View name\n"
9742 "Detailed information on TCP and BGP neighbor connections\n"
9743 "Neighbor to display information about\n"
9744 "Neighbor to display information about\n"
9745 "Display the received routes from neighbor\n")
9747 struct peer *peer;
9749 if (argc == 2)
9750 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9751 else
9752 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9754 if (! peer)
9755 return CMD_WARNING;
9757 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9760 ALIAS (show_bgp_view_neighbor_received_routes,
9761 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9762 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9763 SHOW_STR
9764 BGP_STR
9765 "BGP view\n"
9766 "View name\n"
9767 "Address family\n"
9768 "Detailed information on TCP and BGP neighbor connections\n"
9769 "Neighbor to display information about\n"
9770 "Neighbor to display information about\n"
9771 "Display the received routes from neighbor\n")
9773 ALIAS (show_bgp_view_neighbor_advertised_route,
9774 show_bgp_neighbor_advertised_route_cmd,
9775 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9776 SHOW_STR
9777 BGP_STR
9778 "Detailed information on TCP and BGP neighbor connections\n"
9779 "Neighbor to display information about\n"
9780 "Neighbor to display information about\n"
9781 "Display the routes advertised to a BGP neighbor\n")
9783 ALIAS (show_bgp_view_neighbor_advertised_route,
9784 show_bgp_ipv6_neighbor_advertised_route_cmd,
9785 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9786 SHOW_STR
9787 BGP_STR
9788 "Address family\n"
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 /* old command */
9795 ALIAS (show_bgp_view_neighbor_advertised_route,
9796 ipv6_bgp_neighbor_advertised_route_cmd,
9797 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9798 SHOW_STR
9799 IPV6_STR
9800 BGP_STR
9801 "Detailed information on TCP and BGP neighbor connections\n"
9802 "Neighbor to display information about\n"
9803 "Neighbor to display information about\n"
9804 "Display the routes advertised to a BGP neighbor\n")
9806 /* old command */
9807 DEFUN (ipv6_mbgp_neighbor_advertised_route,
9808 ipv6_mbgp_neighbor_advertised_route_cmd,
9809 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9810 SHOW_STR
9811 IPV6_STR
9812 MBGP_STR
9813 "Detailed information on TCP and BGP neighbor connections\n"
9814 "Neighbor to display information about\n"
9815 "Neighbor to display information about\n"
9816 "Display the routes advertised to a BGP neighbor\n")
9818 struct peer *peer;
9820 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9821 if (! peer)
9822 return CMD_WARNING;
9824 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
9826 #endif /* HAVE_IPV6 */
9828 DEFUN (show_ip_bgp_neighbor_received_routes,
9829 show_ip_bgp_neighbor_received_routes_cmd,
9830 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9831 SHOW_STR
9832 IP_STR
9833 BGP_STR
9834 "Detailed information on TCP and BGP neighbor connections\n"
9835 "Neighbor to display information about\n"
9836 "Neighbor to display information about\n"
9837 "Display the received routes from neighbor\n")
9839 struct peer *peer;
9841 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9842 if (! peer)
9843 return CMD_WARNING;
9845 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9848 DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9849 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9850 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9851 SHOW_STR
9852 IP_STR
9853 BGP_STR
9854 "Address family\n"
9855 "Address Family modifier\n"
9856 "Address Family modifier\n"
9857 "Detailed information on TCP and BGP neighbor connections\n"
9858 "Neighbor to display information about\n"
9859 "Neighbor to display information about\n"
9860 "Display the received routes from neighbor\n")
9862 struct peer *peer;
9864 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9865 if (! peer)
9866 return CMD_WARNING;
9868 if (strncmp (argv[0], "m", 1) == 0)
9869 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9871 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9874 DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9875 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9876 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9877 SHOW_STR
9878 IP_STR
9879 BGP_STR
9880 "Detailed information on TCP and BGP neighbor connections\n"
9881 "Neighbor to display information about\n"
9882 "Neighbor to display information about\n"
9883 "Display information received from a BGP neighbor\n"
9884 "Display the prefixlist filter\n")
9886 char name[BUFSIZ];
9887 union sockunion *su;
9888 struct peer *peer;
9889 int count;
9891 su = sockunion_str2su (argv[0]);
9892 if (su == NULL)
9893 return CMD_WARNING;
9895 peer = peer_lookup (NULL, su);
9896 if (! peer)
9897 return CMD_WARNING;
9899 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9900 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9901 if (count)
9903 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9904 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9907 return CMD_SUCCESS;
9910 DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9911 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9912 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9913 SHOW_STR
9914 IP_STR
9915 BGP_STR
9916 "Address family\n"
9917 "Address Family modifier\n"
9918 "Address Family modifier\n"
9919 "Detailed information on TCP and BGP neighbor connections\n"
9920 "Neighbor to display information about\n"
9921 "Neighbor to display information about\n"
9922 "Display information received from a BGP neighbor\n"
9923 "Display the prefixlist filter\n")
9925 char name[BUFSIZ];
9926 union sockunion *su;
9927 struct peer *peer;
9928 int count;
9930 su = sockunion_str2su (argv[1]);
9931 if (su == NULL)
9932 return CMD_WARNING;
9934 peer = peer_lookup (NULL, su);
9935 if (! peer)
9936 return CMD_WARNING;
9938 if (strncmp (argv[0], "m", 1) == 0)
9940 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9941 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9942 if (count)
9944 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9945 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9948 else
9950 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9951 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9952 if (count)
9954 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9955 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9959 return CMD_SUCCESS;
9963 #ifdef HAVE_IPV6
9964 ALIAS (show_bgp_view_neighbor_received_routes,
9965 show_bgp_neighbor_received_routes_cmd,
9966 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9967 SHOW_STR
9968 BGP_STR
9969 "Detailed information on TCP and BGP neighbor connections\n"
9970 "Neighbor to display information about\n"
9971 "Neighbor to display information about\n"
9972 "Display the received routes from neighbor\n")
9974 ALIAS (show_bgp_view_neighbor_received_routes,
9975 show_bgp_ipv6_neighbor_received_routes_cmd,
9976 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9977 SHOW_STR
9978 BGP_STR
9979 "Address family\n"
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 DEFUN (show_bgp_neighbor_received_prefix_filter,
9986 show_bgp_neighbor_received_prefix_filter_cmd,
9987 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9988 SHOW_STR
9989 BGP_STR
9990 "Detailed information on TCP and BGP neighbor connections\n"
9991 "Neighbor to display information about\n"
9992 "Neighbor to display information about\n"
9993 "Display information received from a BGP neighbor\n"
9994 "Display the prefixlist filter\n")
9996 char name[BUFSIZ];
9997 union sockunion *su;
9998 struct peer *peer;
9999 int count;
10001 su = sockunion_str2su (argv[0]);
10002 if (su == NULL)
10003 return CMD_WARNING;
10005 peer = peer_lookup (NULL, su);
10006 if (! peer)
10007 return CMD_WARNING;
10009 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10010 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10011 if (count)
10013 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10014 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10017 return CMD_SUCCESS;
10020 ALIAS (show_bgp_neighbor_received_prefix_filter,
10021 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10022 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10023 SHOW_STR
10024 BGP_STR
10025 "Address family\n"
10026 "Detailed information on TCP and BGP neighbor connections\n"
10027 "Neighbor to display information about\n"
10028 "Neighbor to display information about\n"
10029 "Display information received from a BGP neighbor\n"
10030 "Display the prefixlist filter\n")
10032 /* old command */
10033 ALIAS (show_bgp_view_neighbor_received_routes,
10034 ipv6_bgp_neighbor_received_routes_cmd,
10035 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10036 SHOW_STR
10037 IPV6_STR
10038 BGP_STR
10039 "Detailed information on TCP and BGP neighbor connections\n"
10040 "Neighbor to display information about\n"
10041 "Neighbor to display information about\n"
10042 "Display the received routes from neighbor\n")
10044 /* old command */
10045 DEFUN (ipv6_mbgp_neighbor_received_routes,
10046 ipv6_mbgp_neighbor_received_routes_cmd,
10047 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10048 SHOW_STR
10049 IPV6_STR
10050 MBGP_STR
10051 "Detailed information on TCP and BGP neighbor connections\n"
10052 "Neighbor to display information about\n"
10053 "Neighbor to display information about\n"
10054 "Display the received routes from neighbor\n")
10056 struct peer *peer;
10058 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10059 if (! peer)
10060 return CMD_WARNING;
10062 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
10065 DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10066 show_bgp_view_neighbor_received_prefix_filter_cmd,
10067 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10068 SHOW_STR
10069 BGP_STR
10070 "BGP view\n"
10071 "View name\n"
10072 "Detailed information on TCP and BGP neighbor connections\n"
10073 "Neighbor to display information about\n"
10074 "Neighbor to display information about\n"
10075 "Display information received from a BGP neighbor\n"
10076 "Display the prefixlist filter\n")
10078 char name[BUFSIZ];
10079 union sockunion *su;
10080 struct peer *peer;
10081 struct bgp *bgp;
10082 int count;
10084 /* BGP structure lookup. */
10085 bgp = bgp_lookup_by_name (argv[0]);
10086 if (bgp == NULL)
10088 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10089 return CMD_WARNING;
10092 su = sockunion_str2su (argv[1]);
10093 if (su == NULL)
10094 return CMD_WARNING;
10096 peer = peer_lookup (bgp, su);
10097 if (! peer)
10098 return CMD_WARNING;
10100 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10101 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10102 if (count)
10104 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10105 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10108 return CMD_SUCCESS;
10111 ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10112 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10113 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10114 SHOW_STR
10115 BGP_STR
10116 "BGP view\n"
10117 "View name\n"
10118 "Address family\n"
10119 "Detailed information on TCP and BGP neighbor connections\n"
10120 "Neighbor to display information about\n"
10121 "Neighbor to display information about\n"
10122 "Display information received from a BGP neighbor\n"
10123 "Display the prefixlist filter\n")
10124 #endif /* HAVE_IPV6 */
10126 static int
10127 bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
10128 safi_t safi, enum bgp_show_type type)
10130 if (! peer || ! peer->afc[afi][safi])
10132 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10133 return CMD_WARNING;
10136 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
10139 DEFUN (show_ip_bgp_neighbor_routes,
10140 show_ip_bgp_neighbor_routes_cmd,
10141 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10142 SHOW_STR
10143 IP_STR
10144 BGP_STR
10145 "Detailed information on TCP and BGP neighbor connections\n"
10146 "Neighbor to display information about\n"
10147 "Neighbor to display information about\n"
10148 "Display routes learned from neighbor\n")
10150 struct peer *peer;
10152 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10153 if (! peer)
10154 return CMD_WARNING;
10156 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10157 bgp_show_type_neighbor);
10160 DEFUN (show_ip_bgp_neighbor_flap,
10161 show_ip_bgp_neighbor_flap_cmd,
10162 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10163 SHOW_STR
10164 IP_STR
10165 BGP_STR
10166 "Detailed information on TCP and BGP neighbor connections\n"
10167 "Neighbor to display information about\n"
10168 "Neighbor to display information about\n"
10169 "Display flap statistics of the routes learned from neighbor\n")
10171 struct peer *peer;
10173 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10174 if (! peer)
10175 return CMD_WARNING;
10177 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10178 bgp_show_type_flap_neighbor);
10181 DEFUN (show_ip_bgp_neighbor_damp,
10182 show_ip_bgp_neighbor_damp_cmd,
10183 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10184 SHOW_STR
10185 IP_STR
10186 BGP_STR
10187 "Detailed information on TCP and BGP neighbor connections\n"
10188 "Neighbor to display information about\n"
10189 "Neighbor to display information about\n"
10190 "Display the dampened routes received from neighbor\n")
10192 struct peer *peer;
10194 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10195 if (! peer)
10196 return CMD_WARNING;
10198 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10199 bgp_show_type_damp_neighbor);
10202 DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10203 show_ip_bgp_ipv4_neighbor_routes_cmd,
10204 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10205 SHOW_STR
10206 IP_STR
10207 BGP_STR
10208 "Address family\n"
10209 "Address Family modifier\n"
10210 "Address Family modifier\n"
10211 "Detailed information on TCP and BGP neighbor connections\n"
10212 "Neighbor to display information about\n"
10213 "Neighbor to display information about\n"
10214 "Display routes learned from neighbor\n")
10216 struct peer *peer;
10218 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10219 if (! peer)
10220 return CMD_WARNING;
10222 if (strncmp (argv[0], "m", 1) == 0)
10223 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
10224 bgp_show_type_neighbor);
10226 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
10227 bgp_show_type_neighbor);
10230 DEFUN (show_ip_bgp_view_rsclient,
10231 show_ip_bgp_view_rsclient_cmd,
10232 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10233 SHOW_STR
10234 IP_STR
10235 BGP_STR
10236 "BGP view\n"
10237 "BGP view name\n"
10238 "Information about Route Server Client\n"
10239 NEIGHBOR_ADDR_STR)
10241 struct bgp_table *table;
10242 struct peer *peer;
10244 if (argc == 2)
10245 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10246 else
10247 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10249 if (! peer)
10250 return CMD_WARNING;
10252 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10254 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10255 VTY_NEWLINE);
10256 return CMD_WARNING;
10259 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10260 PEER_FLAG_RSERVER_CLIENT))
10262 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10263 VTY_NEWLINE);
10264 return CMD_WARNING;
10267 table = peer->rib[AFI_IP][SAFI_UNICAST];
10269 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10272 ALIAS (show_ip_bgp_view_rsclient,
10273 show_ip_bgp_rsclient_cmd,
10274 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10275 SHOW_STR
10276 IP_STR
10277 BGP_STR
10278 "Information about Route Server Client\n"
10279 NEIGHBOR_ADDR_STR)
10281 DEFUN (show_ip_bgp_view_rsclient_route,
10282 show_ip_bgp_view_rsclient_route_cmd,
10283 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10284 SHOW_STR
10285 IP_STR
10286 BGP_STR
10287 "BGP view\n"
10288 "BGP view name\n"
10289 "Information about Route Server Client\n"
10290 NEIGHBOR_ADDR_STR
10291 "Network in the BGP routing table to display\n")
10293 struct bgp *bgp;
10294 struct peer *peer;
10296 /* BGP structure lookup. */
10297 if (argc == 3)
10299 bgp = bgp_lookup_by_name (argv[0]);
10300 if (bgp == NULL)
10302 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10303 return CMD_WARNING;
10306 else
10308 bgp = bgp_get_default ();
10309 if (bgp == NULL)
10311 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10312 return CMD_WARNING;
10316 if (argc == 3)
10317 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10318 else
10319 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10321 if (! peer)
10322 return CMD_WARNING;
10324 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10326 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10327 VTY_NEWLINE);
10328 return CMD_WARNING;
10331 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10332 PEER_FLAG_RSERVER_CLIENT))
10334 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10335 VTY_NEWLINE);
10336 return CMD_WARNING;
10339 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10340 (argc == 3) ? argv[2] : argv[1],
10341 AFI_IP, SAFI_UNICAST, NULL, 0);
10344 ALIAS (show_ip_bgp_view_rsclient_route,
10345 show_ip_bgp_rsclient_route_cmd,
10346 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10347 SHOW_STR
10348 IP_STR
10349 BGP_STR
10350 "Information about Route Server Client\n"
10351 NEIGHBOR_ADDR_STR
10352 "Network in the BGP routing table to display\n")
10354 DEFUN (show_ip_bgp_view_rsclient_prefix,
10355 show_ip_bgp_view_rsclient_prefix_cmd,
10356 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10357 SHOW_STR
10358 IP_STR
10359 BGP_STR
10360 "BGP view\n"
10361 "BGP view name\n"
10362 "Information about Route Server Client\n"
10363 NEIGHBOR_ADDR_STR
10364 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10366 struct bgp *bgp;
10367 struct peer *peer;
10369 /* BGP structure lookup. */
10370 if (argc == 3)
10372 bgp = bgp_lookup_by_name (argv[0]);
10373 if (bgp == NULL)
10375 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10376 return CMD_WARNING;
10379 else
10381 bgp = bgp_get_default ();
10382 if (bgp == NULL)
10384 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10385 return CMD_WARNING;
10389 if (argc == 3)
10390 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10391 else
10392 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10394 if (! peer)
10395 return CMD_WARNING;
10397 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10399 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10400 VTY_NEWLINE);
10401 return CMD_WARNING;
10404 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10405 PEER_FLAG_RSERVER_CLIENT))
10407 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10408 VTY_NEWLINE);
10409 return CMD_WARNING;
10412 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10413 (argc == 3) ? argv[2] : argv[1],
10414 AFI_IP, SAFI_UNICAST, NULL, 1);
10417 ALIAS (show_ip_bgp_view_rsclient_prefix,
10418 show_ip_bgp_rsclient_prefix_cmd,
10419 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10420 SHOW_STR
10421 IP_STR
10422 BGP_STR
10423 "Information about Route Server Client\n"
10424 NEIGHBOR_ADDR_STR
10425 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10428 #ifdef HAVE_IPV6
10429 DEFUN (show_bgp_view_neighbor_routes,
10430 show_bgp_view_neighbor_routes_cmd,
10431 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10432 SHOW_STR
10433 BGP_STR
10434 "BGP view\n"
10435 "BGP view name\n"
10436 "Detailed information on TCP and BGP neighbor connections\n"
10437 "Neighbor to display information about\n"
10438 "Neighbor to display information about\n"
10439 "Display routes learned from neighbor\n")
10441 struct peer *peer;
10443 if (argc == 2)
10444 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10445 else
10446 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10448 if (! peer)
10449 return CMD_WARNING;
10451 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10452 bgp_show_type_neighbor);
10455 ALIAS (show_bgp_view_neighbor_routes,
10456 show_bgp_view_ipv6_neighbor_routes_cmd,
10457 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10458 SHOW_STR
10459 BGP_STR
10460 "BGP view\n"
10461 "BGP view name\n"
10462 "Address family\n"
10463 "Detailed information on TCP and BGP neighbor connections\n"
10464 "Neighbor to display information about\n"
10465 "Neighbor to display information about\n"
10466 "Display routes learned from neighbor\n")
10468 DEFUN (show_bgp_view_neighbor_damp,
10469 show_bgp_view_neighbor_damp_cmd,
10470 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10471 SHOW_STR
10472 BGP_STR
10473 "BGP view\n"
10474 "BGP view name\n"
10475 "Detailed information on TCP and BGP neighbor connections\n"
10476 "Neighbor to display information about\n"
10477 "Neighbor to display information about\n"
10478 "Display the dampened routes received from neighbor\n")
10480 struct peer *peer;
10482 if (argc == 2)
10483 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10484 else
10485 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10487 if (! peer)
10488 return CMD_WARNING;
10490 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10491 bgp_show_type_damp_neighbor);
10494 ALIAS (show_bgp_view_neighbor_damp,
10495 show_bgp_view_ipv6_neighbor_damp_cmd,
10496 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10497 SHOW_STR
10498 BGP_STR
10499 "BGP view\n"
10500 "BGP view name\n"
10501 "Address family\n"
10502 "Detailed information on TCP and BGP neighbor connections\n"
10503 "Neighbor to display information about\n"
10504 "Neighbor to display information about\n"
10505 "Display the dampened routes received from neighbor\n")
10507 DEFUN (show_bgp_view_neighbor_flap,
10508 show_bgp_view_neighbor_flap_cmd,
10509 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10510 SHOW_STR
10511 BGP_STR
10512 "BGP view\n"
10513 "BGP view name\n"
10514 "Detailed information on TCP and BGP neighbor connections\n"
10515 "Neighbor to display information about\n"
10516 "Neighbor to display information about\n"
10517 "Display flap statistics of the routes learned from neighbor\n")
10519 struct peer *peer;
10521 if (argc == 2)
10522 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10523 else
10524 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10526 if (! peer)
10527 return CMD_WARNING;
10529 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10530 bgp_show_type_flap_neighbor);
10533 ALIAS (show_bgp_view_neighbor_flap,
10534 show_bgp_view_ipv6_neighbor_flap_cmd,
10535 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10536 SHOW_STR
10537 BGP_STR
10538 "BGP view\n"
10539 "BGP view name\n"
10540 "Address family\n"
10541 "Detailed information on TCP and BGP neighbor connections\n"
10542 "Neighbor to display information about\n"
10543 "Neighbor to display information about\n"
10544 "Display flap statistics of the routes learned from neighbor\n")
10546 ALIAS (show_bgp_view_neighbor_routes,
10547 show_bgp_neighbor_routes_cmd,
10548 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10549 SHOW_STR
10550 BGP_STR
10551 "Detailed information on TCP and BGP neighbor connections\n"
10552 "Neighbor to display information about\n"
10553 "Neighbor to display information about\n"
10554 "Display routes learned from neighbor\n")
10557 ALIAS (show_bgp_view_neighbor_routes,
10558 show_bgp_ipv6_neighbor_routes_cmd,
10559 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10560 SHOW_STR
10561 BGP_STR
10562 "Address family\n"
10563 "Detailed information on TCP and BGP neighbor connections\n"
10564 "Neighbor to display information about\n"
10565 "Neighbor to display information about\n"
10566 "Display routes learned from neighbor\n")
10568 /* old command */
10569 ALIAS (show_bgp_view_neighbor_routes,
10570 ipv6_bgp_neighbor_routes_cmd,
10571 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10572 SHOW_STR
10573 IPV6_STR
10574 BGP_STR
10575 "Detailed information on TCP and BGP neighbor connections\n"
10576 "Neighbor to display information about\n"
10577 "Neighbor to display information about\n"
10578 "Display routes learned from neighbor\n")
10580 /* old command */
10581 DEFUN (ipv6_mbgp_neighbor_routes,
10582 ipv6_mbgp_neighbor_routes_cmd,
10583 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10584 SHOW_STR
10585 IPV6_STR
10586 MBGP_STR
10587 "Detailed information on TCP and BGP neighbor connections\n"
10588 "Neighbor to display information about\n"
10589 "Neighbor to display information about\n"
10590 "Display routes learned from neighbor\n")
10592 struct peer *peer;
10594 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10595 if (! peer)
10596 return CMD_WARNING;
10598 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
10599 bgp_show_type_neighbor);
10602 ALIAS (show_bgp_view_neighbor_flap,
10603 show_bgp_neighbor_flap_cmd,
10604 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10605 SHOW_STR
10606 BGP_STR
10607 "Detailed information on TCP and BGP neighbor connections\n"
10608 "Neighbor to display information about\n"
10609 "Neighbor to display information about\n"
10610 "Display flap statistics of the routes learned from neighbor\n")
10612 ALIAS (show_bgp_view_neighbor_flap,
10613 show_bgp_ipv6_neighbor_flap_cmd,
10614 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10615 SHOW_STR
10616 BGP_STR
10617 "Address family\n"
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_damp,
10624 show_bgp_neighbor_damp_cmd,
10625 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10626 SHOW_STR
10627 BGP_STR
10628 "Detailed information on TCP and BGP neighbor connections\n"
10629 "Neighbor to display information about\n"
10630 "Neighbor to display information about\n"
10631 "Display the dampened routes received from neighbor\n")
10633 ALIAS (show_bgp_view_neighbor_damp,
10634 show_bgp_ipv6_neighbor_damp_cmd,
10635 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10636 SHOW_STR
10637 BGP_STR
10638 "Address family\n"
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 DEFUN (show_bgp_view_rsclient,
10645 show_bgp_view_rsclient_cmd,
10646 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10647 SHOW_STR
10648 BGP_STR
10649 "BGP view\n"
10650 "BGP view name\n"
10651 "Information about Route Server Client\n"
10652 NEIGHBOR_ADDR_STR)
10654 struct bgp_table *table;
10655 struct peer *peer;
10657 if (argc == 2)
10658 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10659 else
10660 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10662 if (! peer)
10663 return CMD_WARNING;
10665 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10667 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10668 VTY_NEWLINE);
10669 return CMD_WARNING;
10672 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10673 PEER_FLAG_RSERVER_CLIENT))
10675 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10676 VTY_NEWLINE);
10677 return CMD_WARNING;
10680 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10682 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10685 ALIAS (show_bgp_view_rsclient,
10686 show_bgp_rsclient_cmd,
10687 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10688 SHOW_STR
10689 BGP_STR
10690 "Information about Route Server Client\n"
10691 NEIGHBOR_ADDR_STR)
10693 DEFUN (show_bgp_view_rsclient_route,
10694 show_bgp_view_rsclient_route_cmd,
10695 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10696 SHOW_STR
10697 BGP_STR
10698 "BGP view\n"
10699 "BGP view name\n"
10700 "Information about Route Server Client\n"
10701 NEIGHBOR_ADDR_STR
10702 "Network in the BGP routing table to display\n")
10704 struct bgp *bgp;
10705 struct peer *peer;
10707 /* BGP structure lookup. */
10708 if (argc == 3)
10710 bgp = bgp_lookup_by_name (argv[0]);
10711 if (bgp == NULL)
10713 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10714 return CMD_WARNING;
10717 else
10719 bgp = bgp_get_default ();
10720 if (bgp == NULL)
10722 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10723 return CMD_WARNING;
10727 if (argc == 3)
10728 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10729 else
10730 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10732 if (! peer)
10733 return CMD_WARNING;
10735 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10737 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10738 VTY_NEWLINE);
10739 return CMD_WARNING;
10742 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10743 PEER_FLAG_RSERVER_CLIENT))
10745 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10746 VTY_NEWLINE);
10747 return CMD_WARNING;
10750 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10751 (argc == 3) ? argv[2] : argv[1],
10752 AFI_IP6, SAFI_UNICAST, NULL, 0);
10755 ALIAS (show_bgp_view_rsclient_route,
10756 show_bgp_rsclient_route_cmd,
10757 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10758 SHOW_STR
10759 BGP_STR
10760 "Information about Route Server Client\n"
10761 NEIGHBOR_ADDR_STR
10762 "Network in the BGP routing table to display\n")
10764 DEFUN (show_bgp_view_rsclient_prefix,
10765 show_bgp_view_rsclient_prefix_cmd,
10766 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10767 SHOW_STR
10768 BGP_STR
10769 "BGP view\n"
10770 "BGP view name\n"
10771 "Information about Route Server Client\n"
10772 NEIGHBOR_ADDR_STR
10773 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10775 struct bgp *bgp;
10776 struct peer *peer;
10778 /* BGP structure lookup. */
10779 if (argc == 3)
10781 bgp = bgp_lookup_by_name (argv[0]);
10782 if (bgp == NULL)
10784 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10785 return CMD_WARNING;
10788 else
10790 bgp = bgp_get_default ();
10791 if (bgp == NULL)
10793 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10794 return CMD_WARNING;
10798 if (argc == 3)
10799 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10800 else
10801 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10803 if (! peer)
10804 return CMD_WARNING;
10806 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10808 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10809 VTY_NEWLINE);
10810 return CMD_WARNING;
10813 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10814 PEER_FLAG_RSERVER_CLIENT))
10816 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10817 VTY_NEWLINE);
10818 return CMD_WARNING;
10821 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10822 (argc == 3) ? argv[2] : argv[1],
10823 AFI_IP6, SAFI_UNICAST, NULL, 1);
10826 ALIAS (show_bgp_view_rsclient_prefix,
10827 show_bgp_rsclient_prefix_cmd,
10828 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10829 SHOW_STR
10830 BGP_STR
10831 "Information about Route Server Client\n"
10832 NEIGHBOR_ADDR_STR
10833 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10835 #endif /* HAVE_IPV6 */
10837 struct bgp_table *bgp_distance_table;
10839 struct bgp_distance
10841 /* Distance value for the IP source prefix. */
10842 u_char distance;
10844 /* Name of the access-list to be matched. */
10845 char *access_list;
10848 static struct bgp_distance *
10849 bgp_distance_new (void)
10851 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
10854 static void
10855 bgp_distance_free (struct bgp_distance *bdistance)
10857 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10860 static int
10861 bgp_distance_set (struct vty *vty, const char *distance_str,
10862 const char *ip_str, const char *access_list_str)
10864 int ret;
10865 struct prefix_ipv4 p;
10866 u_char distance;
10867 struct bgp_node *rn;
10868 struct bgp_distance *bdistance;
10870 ret = str2prefix_ipv4 (ip_str, &p);
10871 if (ret == 0)
10873 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10874 return CMD_WARNING;
10877 distance = atoi (distance_str);
10879 /* Get BGP distance node. */
10880 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10881 if (rn->info)
10883 bdistance = rn->info;
10884 bgp_unlock_node (rn);
10886 else
10888 bdistance = bgp_distance_new ();
10889 rn->info = bdistance;
10892 /* Set distance value. */
10893 bdistance->distance = distance;
10895 /* Reset access-list configuration. */
10896 if (bdistance->access_list)
10898 free (bdistance->access_list);
10899 bdistance->access_list = NULL;
10901 if (access_list_str)
10902 bdistance->access_list = strdup (access_list_str);
10904 return CMD_SUCCESS;
10907 static int
10908 bgp_distance_unset (struct vty *vty, const char *distance_str,
10909 const char *ip_str, const char *access_list_str)
10911 int ret;
10912 struct prefix_ipv4 p;
10913 u_char distance;
10914 struct bgp_node *rn;
10915 struct bgp_distance *bdistance;
10917 ret = str2prefix_ipv4 (ip_str, &p);
10918 if (ret == 0)
10920 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10921 return CMD_WARNING;
10924 distance = atoi (distance_str);
10926 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10927 if (! rn)
10929 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10930 return CMD_WARNING;
10933 bdistance = rn->info;
10935 if (bdistance->access_list)
10936 free (bdistance->access_list);
10937 bgp_distance_free (bdistance);
10939 rn->info = NULL;
10940 bgp_unlock_node (rn);
10941 bgp_unlock_node (rn);
10943 return CMD_SUCCESS;
10946 static void
10947 bgp_distance_reset (void)
10949 struct bgp_node *rn;
10950 struct bgp_distance *bdistance;
10952 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10953 if ((bdistance = rn->info) != NULL)
10955 if (bdistance->access_list)
10956 free (bdistance->access_list);
10957 bgp_distance_free (bdistance);
10958 rn->info = NULL;
10959 bgp_unlock_node (rn);
10963 /* Apply BGP information to distance method. */
10964 u_char
10965 bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10967 struct bgp_node *rn;
10968 struct prefix_ipv4 q;
10969 struct peer *peer;
10970 struct bgp_distance *bdistance;
10971 struct access_list *alist;
10972 struct bgp_static *bgp_static;
10974 if (! bgp)
10975 return 0;
10977 if (p->family != AF_INET)
10978 return 0;
10980 peer = rinfo->peer;
10982 if (peer->su.sa.sa_family != AF_INET)
10983 return 0;
10985 memset (&q, 0, sizeof (struct prefix_ipv4));
10986 q.family = AF_INET;
10987 q.prefix = peer->su.sin.sin_addr;
10988 q.prefixlen = IPV4_MAX_BITLEN;
10990 /* Check source address. */
10991 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10992 if (rn)
10994 bdistance = rn->info;
10995 bgp_unlock_node (rn);
10997 if (bdistance->access_list)
10999 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11000 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11001 return bdistance->distance;
11003 else
11004 return bdistance->distance;
11007 /* Backdoor check. */
11008 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11009 if (rn)
11011 bgp_static = rn->info;
11012 bgp_unlock_node (rn);
11014 if (bgp_static->backdoor)
11016 if (bgp->distance_local)
11017 return bgp->distance_local;
11018 else
11019 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11023 if (peer_sort (peer) == BGP_PEER_EBGP)
11025 if (bgp->distance_ebgp)
11026 return bgp->distance_ebgp;
11027 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11029 else
11031 if (bgp->distance_ibgp)
11032 return bgp->distance_ibgp;
11033 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11037 DEFUN (bgp_distance,
11038 bgp_distance_cmd,
11039 "distance bgp <1-255> <1-255> <1-255>",
11040 "Define an administrative distance\n"
11041 "BGP distance\n"
11042 "Distance for routes external to the AS\n"
11043 "Distance for routes internal to the AS\n"
11044 "Distance for local routes\n")
11046 struct bgp *bgp;
11048 bgp = vty->index;
11050 bgp->distance_ebgp = atoi (argv[0]);
11051 bgp->distance_ibgp = atoi (argv[1]);
11052 bgp->distance_local = atoi (argv[2]);
11053 return CMD_SUCCESS;
11056 DEFUN (no_bgp_distance,
11057 no_bgp_distance_cmd,
11058 "no distance bgp <1-255> <1-255> <1-255>",
11059 NO_STR
11060 "Define an administrative distance\n"
11061 "BGP distance\n"
11062 "Distance for routes external to the AS\n"
11063 "Distance for routes internal to the AS\n"
11064 "Distance for local routes\n")
11066 struct bgp *bgp;
11068 bgp = vty->index;
11070 bgp->distance_ebgp= 0;
11071 bgp->distance_ibgp = 0;
11072 bgp->distance_local = 0;
11073 return CMD_SUCCESS;
11076 ALIAS (no_bgp_distance,
11077 no_bgp_distance2_cmd,
11078 "no distance bgp",
11079 NO_STR
11080 "Define an administrative distance\n"
11081 "BGP distance\n")
11083 DEFUN (bgp_distance_source,
11084 bgp_distance_source_cmd,
11085 "distance <1-255> A.B.C.D/M",
11086 "Define an administrative distance\n"
11087 "Administrative distance\n"
11088 "IP source prefix\n")
11090 bgp_distance_set (vty, argv[0], argv[1], NULL);
11091 return CMD_SUCCESS;
11094 DEFUN (no_bgp_distance_source,
11095 no_bgp_distance_source_cmd,
11096 "no distance <1-255> A.B.C.D/M",
11097 NO_STR
11098 "Define an administrative distance\n"
11099 "Administrative distance\n"
11100 "IP source prefix\n")
11102 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11103 return CMD_SUCCESS;
11106 DEFUN (bgp_distance_source_access_list,
11107 bgp_distance_source_access_list_cmd,
11108 "distance <1-255> A.B.C.D/M WORD",
11109 "Define an administrative distance\n"
11110 "Administrative distance\n"
11111 "IP source prefix\n"
11112 "Access list name\n")
11114 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11115 return CMD_SUCCESS;
11118 DEFUN (no_bgp_distance_source_access_list,
11119 no_bgp_distance_source_access_list_cmd,
11120 "no distance <1-255> A.B.C.D/M WORD",
11121 NO_STR
11122 "Define an administrative distance\n"
11123 "Administrative distance\n"
11124 "IP source prefix\n"
11125 "Access list name\n")
11127 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11128 return CMD_SUCCESS;
11131 DEFUN (bgp_damp_set,
11132 bgp_damp_set_cmd,
11133 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11134 "BGP Specific commands\n"
11135 "Enable route-flap dampening\n"
11136 "Half-life time for the penalty\n"
11137 "Value to start reusing a route\n"
11138 "Value to start suppressing a route\n"
11139 "Maximum duration to suppress a stable route\n")
11141 struct bgp *bgp;
11142 int half = DEFAULT_HALF_LIFE * 60;
11143 int reuse = DEFAULT_REUSE;
11144 int suppress = DEFAULT_SUPPRESS;
11145 int max = 4 * half;
11147 if (argc == 4)
11149 half = atoi (argv[0]) * 60;
11150 reuse = atoi (argv[1]);
11151 suppress = atoi (argv[2]);
11152 max = atoi (argv[3]) * 60;
11154 else if (argc == 1)
11156 half = atoi (argv[0]) * 60;
11157 max = 4 * half;
11160 bgp = vty->index;
11161 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11162 half, reuse, suppress, max);
11165 ALIAS (bgp_damp_set,
11166 bgp_damp_set2_cmd,
11167 "bgp dampening <1-45>",
11168 "BGP Specific commands\n"
11169 "Enable route-flap dampening\n"
11170 "Half-life time for the penalty\n")
11172 ALIAS (bgp_damp_set,
11173 bgp_damp_set3_cmd,
11174 "bgp dampening",
11175 "BGP Specific commands\n"
11176 "Enable route-flap dampening\n")
11178 DEFUN (bgp_damp_unset,
11179 bgp_damp_unset_cmd,
11180 "no bgp dampening",
11181 NO_STR
11182 "BGP Specific commands\n"
11183 "Enable route-flap dampening\n")
11185 struct bgp *bgp;
11187 bgp = vty->index;
11188 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11191 ALIAS (bgp_damp_unset,
11192 bgp_damp_unset2_cmd,
11193 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11194 NO_STR
11195 "BGP Specific commands\n"
11196 "Enable route-flap dampening\n"
11197 "Half-life time for the penalty\n"
11198 "Value to start reusing a route\n"
11199 "Value to start suppressing a route\n"
11200 "Maximum duration to suppress a stable route\n")
11202 DEFUN (show_ip_bgp_dampened_paths,
11203 show_ip_bgp_dampened_paths_cmd,
11204 "show ip bgp dampened-paths",
11205 SHOW_STR
11206 IP_STR
11207 BGP_STR
11208 "Display paths suppressed due to dampening\n")
11210 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11211 NULL);
11214 DEFUN (show_ip_bgp_flap_statistics,
11215 show_ip_bgp_flap_statistics_cmd,
11216 "show ip bgp flap-statistics",
11217 SHOW_STR
11218 IP_STR
11219 BGP_STR
11220 "Display flap statistics of routes\n")
11222 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11223 bgp_show_type_flap_statistics, NULL);
11226 /* Display specified route of BGP table. */
11227 static int
11228 bgp_clear_damp_route (struct vty *vty, const char *view_name,
11229 const char *ip_str, afi_t afi, safi_t safi,
11230 struct prefix_rd *prd, int prefix_check)
11232 int ret;
11233 struct prefix match;
11234 struct bgp_node *rn;
11235 struct bgp_node *rm;
11236 struct bgp_info *ri;
11237 struct bgp_info *ri_temp;
11238 struct bgp *bgp;
11239 struct bgp_table *table;
11241 /* BGP structure lookup. */
11242 if (view_name)
11244 bgp = bgp_lookup_by_name (view_name);
11245 if (bgp == NULL)
11247 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11248 return CMD_WARNING;
11251 else
11253 bgp = bgp_get_default ();
11254 if (bgp == NULL)
11256 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11257 return CMD_WARNING;
11261 /* Check IP address argument. */
11262 ret = str2prefix (ip_str, &match);
11263 if (! ret)
11265 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11266 return CMD_WARNING;
11269 match.family = afi2family (afi);
11271 if (safi == SAFI_MPLS_VPN)
11273 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11275 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11276 continue;
11278 if ((table = rn->info) != NULL)
11279 if ((rm = bgp_node_match (table, &match)) != NULL)
11280 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11282 ri = rm->info;
11283 while (ri)
11285 if (ri->extra && ri->extra->damp_info)
11287 ri_temp = ri->next;
11288 bgp_damp_info_free (ri->extra->damp_info, 1);
11289 ri = ri_temp;
11291 else
11292 ri = ri->next;
11297 else
11299 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11300 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11302 ri = rn->info;
11303 while (ri)
11305 if (ri->extra && ri->extra->damp_info)
11307 ri_temp = ri->next;
11308 bgp_damp_info_free (ri->extra->damp_info, 1);
11309 ri = ri_temp;
11311 else
11312 ri = ri->next;
11317 return CMD_SUCCESS;
11320 DEFUN (clear_ip_bgp_dampening,
11321 clear_ip_bgp_dampening_cmd,
11322 "clear ip bgp dampening",
11323 CLEAR_STR
11324 IP_STR
11325 BGP_STR
11326 "Clear route flap dampening information\n")
11328 bgp_damp_info_clean ();
11329 return CMD_SUCCESS;
11332 DEFUN (clear_ip_bgp_dampening_prefix,
11333 clear_ip_bgp_dampening_prefix_cmd,
11334 "clear ip bgp dampening A.B.C.D/M",
11335 CLEAR_STR
11336 IP_STR
11337 BGP_STR
11338 "Clear route flap dampening information\n"
11339 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11341 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11342 SAFI_UNICAST, NULL, 1);
11345 DEFUN (clear_ip_bgp_dampening_address,
11346 clear_ip_bgp_dampening_address_cmd,
11347 "clear ip bgp dampening A.B.C.D",
11348 CLEAR_STR
11349 IP_STR
11350 BGP_STR
11351 "Clear route flap dampening information\n"
11352 "Network to clear damping information\n")
11354 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11355 SAFI_UNICAST, NULL, 0);
11358 DEFUN (clear_ip_bgp_dampening_address_mask,
11359 clear_ip_bgp_dampening_address_mask_cmd,
11360 "clear ip bgp dampening A.B.C.D A.B.C.D",
11361 CLEAR_STR
11362 IP_STR
11363 BGP_STR
11364 "Clear route flap dampening information\n"
11365 "Network to clear damping information\n"
11366 "Network mask\n")
11368 int ret;
11369 char prefix_str[BUFSIZ];
11371 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11372 if (! ret)
11374 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11375 return CMD_WARNING;
11378 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11379 SAFI_UNICAST, NULL, 0);
11382 static int
11383 bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11384 afi_t afi, safi_t safi, int *write)
11386 struct bgp_node *prn;
11387 struct bgp_node *rn;
11388 struct bgp_table *table;
11389 struct prefix *p;
11390 struct prefix_rd *prd;
11391 struct bgp_static *bgp_static;
11392 u_int32_t label;
11393 char buf[SU_ADDRSTRLEN];
11394 char rdbuf[RD_ADDRSTRLEN];
11396 /* Network configuration. */
11397 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11398 if ((table = prn->info) != NULL)
11399 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11400 if ((bgp_static = rn->info) != NULL)
11402 p = &rn->p;
11403 prd = (struct prefix_rd *) &prn->p;
11405 /* "address-family" display. */
11406 bgp_config_write_family_header (vty, afi, safi, write);
11408 /* "network" configuration display. */
11409 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11410 label = decode_label (bgp_static->tag);
11412 vty_out (vty, " network %s/%d rd %s tag %d",
11413 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11414 p->prefixlen,
11415 rdbuf, label);
11416 vty_out (vty, "%s", VTY_NEWLINE);
11418 return 0;
11421 /* Configuration of static route announcement and aggregate
11422 information. */
11424 bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11425 afi_t afi, safi_t safi, int *write)
11427 struct bgp_node *rn;
11428 struct prefix *p;
11429 struct bgp_static *bgp_static;
11430 struct bgp_aggregate *bgp_aggregate;
11431 char buf[SU_ADDRSTRLEN];
11433 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11434 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11436 /* Network configuration. */
11437 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11438 if ((bgp_static = rn->info) != NULL)
11440 p = &rn->p;
11442 /* "address-family" display. */
11443 bgp_config_write_family_header (vty, afi, safi, write);
11445 /* "network" configuration display. */
11446 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11448 u_int32_t destination;
11449 struct in_addr netmask;
11451 destination = ntohl (p->u.prefix4.s_addr);
11452 masklen2ip (p->prefixlen, &netmask);
11453 vty_out (vty, " network %s",
11454 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11456 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11457 || (IN_CLASSB (destination) && p->prefixlen == 16)
11458 || (IN_CLASSA (destination) && p->prefixlen == 8)
11459 || p->u.prefix4.s_addr == 0)
11461 /* Natural mask is not display. */
11463 else
11464 vty_out (vty, " mask %s", inet_ntoa (netmask));
11466 else
11468 vty_out (vty, " network %s/%d",
11469 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11470 p->prefixlen);
11473 if (bgp_static->rmap.name)
11474 vty_out (vty, " route-map %s", bgp_static->rmap.name);
11475 else
11477 if (bgp_static->backdoor)
11478 vty_out (vty, " backdoor");
11479 if (bgp_static->ttl)
11480 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11483 vty_out (vty, "%s", VTY_NEWLINE);
11486 /* Aggregate-address configuration. */
11487 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11488 if ((bgp_aggregate = rn->info) != NULL)
11490 p = &rn->p;
11492 /* "address-family" display. */
11493 bgp_config_write_family_header (vty, afi, safi, write);
11495 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11497 struct in_addr netmask;
11499 masklen2ip (p->prefixlen, &netmask);
11500 vty_out (vty, " aggregate-address %s %s",
11501 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11502 inet_ntoa (netmask));
11504 else
11506 vty_out (vty, " aggregate-address %s/%d",
11507 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11508 p->prefixlen);
11511 if (bgp_aggregate->as_set)
11512 vty_out (vty, " as-set");
11514 if (bgp_aggregate->summary_only)
11515 vty_out (vty, " summary-only");
11517 vty_out (vty, "%s", VTY_NEWLINE);
11520 return 0;
11524 bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11526 struct bgp_node *rn;
11527 struct bgp_distance *bdistance;
11529 /* Distance configuration. */
11530 if (bgp->distance_ebgp
11531 && bgp->distance_ibgp
11532 && bgp->distance_local
11533 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11534 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11535 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11536 vty_out (vty, " distance bgp %d %d %d%s",
11537 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11538 VTY_NEWLINE);
11540 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11541 if ((bdistance = rn->info) != NULL)
11543 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11544 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11545 bdistance->access_list ? bdistance->access_list : "",
11546 VTY_NEWLINE);
11549 return 0;
11552 /* Allocate routing table structure and install commands. */
11553 void
11554 bgp_route_init (void)
11556 /* Init BGP distance table. */
11557 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
11559 /* IPv4 BGP commands. */
11560 install_element (BGP_NODE, &bgp_network_cmd);
11561 install_element (BGP_NODE, &bgp_network_mask_cmd);
11562 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11563 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11564 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11565 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11566 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11567 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11568 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
11569 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11570 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11571 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11572 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11573 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11574 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
11575 install_element (BGP_NODE, &no_bgp_network_cmd);
11576 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11577 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11578 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11579 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11580 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11581 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11582 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11583 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
11584 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11585 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11586 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11587 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11588 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11589 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
11591 install_element (BGP_NODE, &aggregate_address_cmd);
11592 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11593 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11594 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11595 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11596 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11597 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11598 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11599 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11600 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11601 install_element (BGP_NODE, &no_aggregate_address_cmd);
11602 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11603 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11604 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11605 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11606 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11607 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11608 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11609 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11610 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11612 /* IPv4 unicast configuration. */
11613 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11614 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11615 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11616 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11617 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11618 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
11619 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11620 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11621 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11622 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11623 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11624 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11625 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11626 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11627 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11628 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11629 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11630 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11631 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11632 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11633 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11634 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11635 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11636 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11637 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11638 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11639 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11640 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11641 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11642 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11643 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11644 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11645 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11646 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11647 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11648 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11649 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11650 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11651 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11652 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11653 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11654 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11655 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11657 /* IPv4 multicast configuration. */
11658 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11659 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11660 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11661 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11662 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11663 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
11664 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11665 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11666 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11667 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11668 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11669 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11670 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11671 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11672 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11673 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11674 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11675 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11676 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11677 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11678 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11679 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11680 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11681 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11682 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11683 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11684 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11685 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11686 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11687 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11688 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11689 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11690 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11691 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11692 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11693 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11694 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11695 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11696 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11697 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11698 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11699 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11700 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11701 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11703 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11704 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11705 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11706 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11707 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11708 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11709 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11710 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11711 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11712 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11713 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11714 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11715 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11716 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11717 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11718 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11719 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11720 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11721 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11722 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11723 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11724 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11725 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11726 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11727 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11728 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11729 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11730 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11731 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11732 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11733 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11734 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11735 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11736 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11737 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11738 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11739 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11740 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11741 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11742 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11743 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11744 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11745 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11746 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11747 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11748 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11749 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11750 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11751 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11752 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11753 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11754 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11755 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11756 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11757 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11758 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11759 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11760 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11761 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11762 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11763 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11764 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11765 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11766 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11767 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11768 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11769 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
11770 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11771 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11772 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11773 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11774 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11775 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
11777 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11778 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11779 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11780 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11781 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11782 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11783 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11784 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11785 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11786 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11787 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11788 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11789 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11790 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11791 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11792 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11793 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11794 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11795 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11796 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11797 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11798 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11799 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11800 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11801 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11802 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11803 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11804 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11805 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11806 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
11808 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11809 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11810 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11811 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11812 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11813 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11814 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11815 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11816 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11817 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11818 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11819 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11820 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11821 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11822 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11823 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11824 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11825 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11826 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11827 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11828 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11829 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11830 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11831 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11832 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11833 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11834 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11835 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11836 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11837 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11838 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11839 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11840 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11841 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11842 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11843 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11844 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11845 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11846 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11847 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11848 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11849 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11850 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11851 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11852 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11853 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11854 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11855 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11856 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11857 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11858 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11859 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11860 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11861 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11862 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11863 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11864 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11865 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11866 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11867 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11868 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11869 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11870 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11871 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11872 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11873 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11874 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
11875 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11876 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11877 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11878 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11879 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11880 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
11882 /* BGP dampening clear commands */
11883 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11884 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11885 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11886 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11888 /* prefix count */
11889 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11890 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11891 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
11892 #ifdef HAVE_IPV6
11893 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11895 /* New config IPv6 BGP commands. */
11896 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11897 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
11898 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
11899 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11900 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
11901 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
11903 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11904 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11905 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11906 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11908 /* Old config IPv6 BGP commands. */
11909 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11910 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11912 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11913 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11914 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11915 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11917 install_element (VIEW_NODE, &show_bgp_cmd);
11918 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11919 install_element (VIEW_NODE, &show_bgp_route_cmd);
11920 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11921 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11922 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11923 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11924 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11925 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11926 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11927 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11928 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11929 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11930 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11931 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11932 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11933 install_element (VIEW_NODE, &show_bgp_community_cmd);
11934 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11935 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11936 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11937 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11938 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11939 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11940 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11941 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11942 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11943 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11944 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11945 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11946 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11947 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11948 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11949 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11950 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11951 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11952 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11953 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11954 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11955 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11956 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11957 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11958 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11959 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11960 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11961 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11962 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
11963 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11964 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11965 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11966 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
11967 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11968 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11969 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
11970 install_element (VIEW_NODE, &show_bgp_view_cmd);
11971 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11972 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11973 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11974 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11975 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11976 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11977 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11978 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11979 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11980 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11981 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11982 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11983 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11984 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11985 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11986 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11987 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
11988 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11989 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11990 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
11992 /* Restricted:
11993 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
11995 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
11996 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
11997 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
11998 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
11999 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12000 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12001 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12002 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12003 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12004 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12005 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12006 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12007 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12008 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12009 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12010 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12011 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12012 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12013 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12014 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12015 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
12016 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
12017 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12018 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12019 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12020 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12021 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12022 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12023 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
12024 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
12026 install_element (ENABLE_NODE, &show_bgp_cmd);
12027 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
12028 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12029 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
12030 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12031 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
12032 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12033 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12034 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12035 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12036 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12037 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12038 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12039 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12040 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12041 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12042 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12043 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12044 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12045 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12046 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12047 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12048 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12049 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12050 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12051 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12052 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12053 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12054 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12055 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12056 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12057 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12058 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12059 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12060 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12061 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12062 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12063 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12064 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12065 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12066 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12067 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12068 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12069 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12070 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12071 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
12072 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12073 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12074 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12075 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
12076 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12077 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12078 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
12079 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12080 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12081 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12082 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12083 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12084 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12085 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12086 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12087 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12088 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12089 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12090 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12091 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12092 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12093 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12094 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12095 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12096 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
12097 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12098 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12099 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
12101 /* Statistics */
12102 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12103 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12104 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12105 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12107 /* old command */
12108 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12109 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12110 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12111 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12112 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12113 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12114 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12115 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12116 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12117 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12118 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12119 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12120 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12121 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12122 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12123 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12124 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12125 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12126 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12127 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12128 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12129 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12130 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12131 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12132 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12133 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12134 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12135 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12136 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12137 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12138 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12139 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12140 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12141 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12142 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12143 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12145 /* old command */
12146 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12147 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12148 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12149 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12150 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12151 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12152 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12153 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12154 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12155 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12156 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12157 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12158 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12159 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12160 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12161 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12162 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12163 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12164 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12165 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12166 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12167 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12168 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12169 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12170 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12171 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12172 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12173 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12174 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12175 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12176 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12177 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12178 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12179 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12180 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12181 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12183 /* old command */
12184 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12185 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12186 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12187 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12189 /* old command */
12190 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12191 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12192 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12193 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12195 /* old command */
12196 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12197 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12198 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12199 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12200 #endif /* HAVE_IPV6 */
12202 install_element (BGP_NODE, &bgp_distance_cmd);
12203 install_element (BGP_NODE, &no_bgp_distance_cmd);
12204 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12205 install_element (BGP_NODE, &bgp_distance_source_cmd);
12206 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12207 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12208 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12210 install_element (BGP_NODE, &bgp_damp_set_cmd);
12211 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12212 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12213 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12214 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12215 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12216 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12217 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12218 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12219 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);